[英]Traceback (most recent call last) error in RYU Software Defined Network
I get the following error: 我收到以下错误:
Traceback (most recent call last): 追溯(最近一次通话):
File "./ryuLinearTopo.py", line 6, in 文件“ ./ryuLinearTopo.py”,第6行,在
class LinearTopo(Topo): class LinearTopo(Topo):
File "./ryuLinearTopo.py", line 32, in LinearTopo 在LinearTopo中的文件“ ./ryuLinearTopo.py”,第32行
simpleTest() simpleTest()
File "./ryuLinearTopo.py", line 21, in simpleTest 在simpleTest中,文件“ ./ryuLinearTopo.py”,第21行
topo = LinearTopo(k=4) 拓扑= LinearTopo(k = 4)
NameError: global name 'LinearTopo' is not defined NameError:全局名称“ LinearTopo”未定义
When I run the following code: 当我运行以下代码时:
#!/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 LinearTopo(Topo):
def __init__(self, k=2, **opts):
super(LinearTopo, self).__init__(**opts)
self.k = k
lastSwitch = None
for i in irange(1, k):
host = self.addHost('h%s' % i)
switch = self.addSwitch('s%s' % i)
self.addLink( host, switch)
if lastSwitch:
self.addLink( switch, lastSwitch)
lastSwitch = switch
def simpleTest():
topo = LinearTopo(k=4)
net = Mininet(topo)
net.start()
print "Dumping host connections"
dumpNodeConnections(net.hosts)
print "Testing network connectivity"
net.pingAll()
net.stop()
if __name__ == '__main__':
# Tell mininet to print useful information
setLogLevel('info')
simpleTest()
You are having a problem with identation. 您的身份有问题。 In your code, all the methods are defined inside your LinearTopo class. 在您的代码中,所有方法都在LinearTopo类内部定义。 You want to define them outside the scope of the class like this: 您想像这样在类范围之外定义它们:
#!/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 LinearTopo(Topo):
def __init__(self, k=2, **opts):
super(LinearTopo, self).__init__(**opts)
self.k = k
lastSwitch = None
for i in irange(1, k):
host = self.addHost('h%s' % i)
switch = self.addSwitch('s%s' % i)
self.addLink( host, switch)
if lastSwitch:
self.addLink( switch, lastSwitch)
lastSwitch = switch
def simpleTest():
topo = LinearTopo(k=4)
net = Mininet(topo)
net.start()
print "Dumping host connections"
dumpNodeConnections(net.hosts)
print "Testing network connectivity"
net.pingAll()
net.stop()
if __name__ == '__main__':
# Tell mininet to print useful information
simpleTest()
setLogLevel('info')
This question should have been tagged mininet, not Ryu, as it is strictly a mininet related question. 这个问题应该被标记为mininet,而不是Ryu,因为它严格是与mininet相关的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.