看起来这个问题更多地与 Python 而不是 Mininet 相关。
我正在尝试使用 mininet 构建客户网络拓扑,但卡在这里。
当我运行以下代码时,出现以下错误。
Traceback (most recent call last):
File "CustomTopo_Router2.py", line 37, in <module>
customTopo = NetworkTopo()
File "CustomTopo_Router2.py", line 28, in __init__
r1_obj = MininetRouter('122.1.1.1')
File "CustomTopo_Router2.py", line 12, in __init__
self.cmd('sysctl net.ipv4.ip_forward=1')
File "build/bdist.linux-x86_64/egg/mininet/node.py", line 353, in cmd
AttributeError: 'MininetRouter' object has no attribute 'name'
我什name至在MininetRouter课堂上没有任何属性。
7 class MininetRouter ( Node ):
8
9 def __init__( self , loo_addr):
10
11 #Enable IP forwarding on the ROuter
12 self.cmd('sysctl net.ipv4.ip_forward=1')
13
14 # Create Loopback Interface and Assign Loopback Address to the Router
15 # All loopback addresses have mask 32
16 loo_config = 'ifconfig lo:1 ' + loo_addr + ' netmask 255.255.255.255 up'
17 self.cmd(loo_config)
18
19
20 class NetworkTopo( Topo ):
21
22 def __init__( self ):
23
24 # Initialize topology
25 Topo.__init__( self )
26
27 # Create a Router Object
28 r1_obj = MininetRouter('122.1.1.1')
29
30 # Add Router object to the topology
31 r1 = self.addNode('r1', r1_obj)
32
33
34
35 if __name__ == '__main__':
36
37 customTopo = NetworkTopo()
38
39 #Get handle to net to manage your topology
40 net = Mininet(topo=customTopo)
41
42 #start/deploy the Topology
43 net.start()
44
45 #Get Halt at Mininet CLI prompt
46 CLI(net)
47
48 #Destroy and stop the topology
49 net.stop()
50
51 # program ends here
我在这里做错了什么?我有交叉检查的缩进。PS:几年后我正在编写python代码。