无法访问嵌套字典中的值以在网络中添加 link

Unable to access values in nested dictionary for adding link in network

我有以下词典

d={'s1': {'s2': {}, 's3': {}, 's4': {}}, 's2': {'s5': {'bw': 20, 'delay': '1ms'}}, 's3': {'s6': {'bw': 20, 'delay': '1ms'}}, 's4': {'s7': {'bw': 20, 'delay': '1ms'}}, 's5': {'h1': {'bw': 10, 'delay': '5ms'}, 'h2': {'bw': 10, 'delay': '5ms'}}, 's6': {'h3': {'bw': 10, 'delay': '5ms'}, 'h4': {'bw': 10, 'delay': '5ms'}}, 's7': {'h5': {'bw': 10, 'delay': '5ms'}, 'h6': {'bw': 10, 'delay': '5ms'}}}

我想访问 link 的 bw 和延迟值。对于 ex- 我希望 addLink(s7,h6,bw=10,delay=5ms) 工作。

我正在使用下面的代码 #!/usr/bin/python

import yaml
#from ruamel import yaml
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink
def myNetwork():

# Create an instance of Mininet class i.e. the network with default values
net = Mininet(autoStaticArp=True, autoSetMacs=True)

a_yaml_file = open("Complex_Topology.yaml")
parsed_yaml_file = yaml.load(a_yaml_file, Loader=yaml.FullLoader)
parsed_yaml_file["Controllers"]
parsed_yaml_file["Hosts"]
print(parsed_yaml_file["Links"])
parsed_yaml_file["Switches"]

for i in parsed_yaml_file["Controllers"]:
    net.addController(i)
for i in parsed_yaml_file["Hosts"]:
    net.addHost(i)
for i in parsed_yaml_file["Switches"]:
    net.addSwitch(i) 
d=parsed_yaml_file["Links"]
def freeze(x):
    if isinstance(x, dict):
        return frozenset(freeze(items) for items in x.items())
    elif isinstance(x, list):
        return tuple(freeze(value) for value in x)
    return x

for i in d.keys():
    for j in d[i].keys():
        k=freeze(d[i].values) 
        net.addLink(i,j,k)
info( '*** Starting network\n')
net.start()
# Start the Mininet CLI to run commands
CLI(net)
# Stop the network
net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    myNetwork()

我遇到以下错误

Traceback (most recent call last):

File "new.py", line 83, in <module>
myNetwork()
File "new.py", line 73, in myNetwork
net.addLink(i,j,k)
File "/home/sudhanshu/Desktop/SDN/mininet/net.py", line 400, in addLink
link = cls( node1, node2, **options )
File "/home/sudhanshu/Desktop/SDN/mininet/link.py", line 450, in __init__
self.makeIntfPair( intfName1, intfName2, addr1, addr2,
File "/home/sudhanshu/Desktop/SDN/mininet/link.py", line 495, in makeIntfPair
return makeIntfPair( intfname1, intfname2, addr1, addr2, node1, node2,
File "/home/sudhanshu/Desktop/SDN/mininet/util.py", line 266, in makeIntfPair
raise Exception( "Error creating interface pair (%s,%s): %s " %
Exception: Error creating interface pair (s1-eth<built-in method values of dict object at 0x7f1f6b6035c0>,s2-eth1): bash: built-in: No such file or directory

我曾尝试操纵我的代码但失败了。

谁能帮我解决这个问题?

如果您想将方法调用为 addLink(s7, h6, bw=10, delay=5ms),则可以使用以下方法创建链接:

for i in d:
    for j in d[i]:
        net.addLink(i, j, **d[i][j])