2014-06-09 16 views
6

Tôi nhận được một TypeError trong chương trình python sau đây, nơi hàm tạo đang được gọi. Nếu tôi loại bỏ các đối số chậm trễ, tôi nhận được cùng một lỗi với "bw". Tôi không thể tìm ra sai lầm. Hãy giúp tôi.TypeError: __ init __() nhận được đối số từ khóa không mong muốn 'delay'

Tôi đang cố gắng tạo cấu trúc liên kết mạng bằng 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()) } 

Dấu vết lỗi Tôi nhận được là:

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' 
+0

Vui lòng đăng theo dõi Python thực tế. –

+0

Dấu vết lỗi đã được thêm vào. – user3033194

+1

lỗi là một nơi nào đó trong phương pháp 'addLink', nhưng nó không có trong mã bạn dán – yedpodtrzitko

Trả lời

0

Hoặc trong mininet hoặc tôi nghi ngờ OpenVswitch một đối tượng đang được thông qua một trong linkopts của bạn với bw và trì hoãn lập luận như từ khóa. Tuy nhiên, đối tượng đó không mong đợi các thông số từ khóa bạn đang sử dụng. Có lẽ bạn có phiên bản không khớp giữa mininet và openvswitch? Tôi thấy các bw và chậm trễ được liệt kê trong ví dụ hiện tại nhưng tôi không có kinh nghiệm miền để biết nếu họ là tài liệu tham khảo cũ hoặc bạn có thư viện cũ.

Thật không may khi thử đoạn mã của bạn đòi hỏi cấu hình nhiều hơn tôi có thời gian. Tôi đã thử chỉ đơn giản là "apt-get openvswitch-controller python-openvswitch" nhưng tôi không thể làm cho nó chạy.

15

Hãy nhớ đặt loại liên kết là tc.

Chỉ định nó trong kịch bản của bạn như hình dưới đây:

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

Ghi nhập khẩu TCLink trong kịch bản python của bạn:

from mininet.link import TCLink 

Nếu, thay vào đó, bạn muốn gọi mininet từ dấu nhắc lệnh, sau đó đặt tham số --link như sau:

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

bạn da man! ;) @Jefferson – RageAgainstTheMachine

Các vấn đề liên quan