gpt4 book ai didi

python - 类型错误 :__init__() got an unexpected keyword argument 'delay'

转载 作者:太空狗 更新时间:2023-10-29 21:16:02 26 4
gpt4 key购买 nike

我在调用构造函数的以下 python 程序中收到 TypeError。如果我删除延迟参数,我会得到与“bw”相同的错误。我无法弄清楚错误。请帮忙。

我正在尝试使用 python 创建网络拓扑。

#!/usr/bin/python

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import irange,dumpNodeConnections
from mininet.log import setLogLevel

class CustomTopo(Topo):

def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)

# Add your logic here ...
switch=self.addSwitch('c1')

self.linkopts1=linkopts1
self.linkopts2=linkopts2
self.linkopts3=linkopts3

self.fanout=fanout
n=0

for i in irange(1,fanout):
s=self.addSwitch('a%s' % i)
self.addLink(switch,s,**linkopts1)

if i==1:
n=0
else:
n=1
for j in irange(1,fanout):
if n==0:
sw=self.addSwitch('e%s' % j) #To generate labels e1, e2, e3 and e4:
else: #if n=0, edge switches e1 and e2 are added to a1
sw=self.addSwitch('e%s' % (j+2)) #if n=1, edge switched e3 and e4 are added to a2
self.addLink(s,sw,**linkopts2)

for k in irange(1,fanout):
if ((j==1)&(n==0)):
host=self.addHost('h%s' % k) #For edge switch e1, j=1,n=0. End-hosts are h1 and h2.
elif ((j==2)&(n==0)):
host=self.addHost('h%s' % (k+2)) #For edge switch e2, j=2,n=0. End-hosts are h3 and h4.
elif ((j==1)&(n==1)):
host=self.addHost('h%s' % (k+4)) #For edge switch e3, j=1,n=1. End-hosts are h5 and h6.
elif ((j==2)&(n==1)):
host=self.addHost('h%s' % (k+6)) #For edge switch e4, j=2,n=1. End-hosts are h7 and h8.
self.addLink(sw,host,**linkopts3)


def treeTest():
linkopts1=dict(bw=10, delay='5ms')
linkopts2=dict(bw=10, delay='5ms')
linkopts3=dict(bw=10, delay='5ms')
topo=CustomTopo(linkopts1,linkopts2,linkopts3,fanout=2)
net=Mininet(topo)
net.start()
print "Dumping node connections"
dumpNodeConnections(net.hosts)
print "Testing network connectivity"
net.pingAll()
net.stop()

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



topos = { 'custom': ( lambda: CustomTopo() ) }

我得到的错误跟踪是:

Traceback (most recent call last):
File "CustomTopo.py", line 70, in <module>
treeTest()
File "CustomTopo.py", line 60, in treeTest
net=Mininet(topo)
File "/usr/local/lib/python2.7/dist-packages/mininet-2.1.0-py2.7.egg/mininet/net.py", line 164, in __init__
self.build()
File "/usr/local/lib/python2.7/dist-packages/mininet-2.1.0-py2.7.egg/mininet/net.py", line 357, in build
self.buildFromTopo( self.topo )
File "/usr/local/lib/python2.7/dist-packages/mininet-2.1.0-py2.7.egg/mininet/net.py", line 344, in buildFromTopo
self.addLink( src, dst, srcPort, dstPort, **params )
File "/usr/local/lib/python2.7/dist-packages/mininet-2.1.0-py2.7.egg/mininet/net.py", line 287, in addLink
return cls( node1, node2, **defaults )
TypeError: __init__() got an unexpected keyword argument 'delay'

最佳答案

记得将链接类型设置为tc。

在您的脚本中指定它,如下所示:

net = Mininet(topo=topo, link=TCLink)

请记住在您的 python 脚本中导入 TCLink:

from mininet.link import TCLink

相反,如果您想从命令提示符调用 mininet,则按如下方式设置 --link 参数:

sudo mn --custom custom.py --topo customtopo --link tc

关于python - 类型错误 :__init__() got an unexpected keyword argument 'delay' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24130398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com