简体   繁体   English

RYU软件定义的网络中的回溯(最近一次通话最近)错误

[英]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.

相关问题 解释“回溯(最近一次调用最后一次):”错误 - Interpreting a “Traceback (most recent call last):” error Traceback(最近一次通话最后一次)Python 错误 - Traceback (most recent call last) Python Error 修复回溯(最近一次通话最近)错误? - Fixing Traceback (most recent call last) error? Python 错误回溯(最后一次调用): - Python Error Traceback (most recent call last): Python追踪(最近一次通话)错误 - Python Traceback (most recent call last) error 追溯(最近一次通话最后一次):NameError:未定义名称“路径” - Traceback (most recent call last):NameError: name 'path' is not defined 在 AWS lambda [ERROR] NameError: name 'filecontent' is not defined Traceback(最近一次调用最后)中运行的 Py 脚本: - Py Script running in AWS lambda [ERROR] NameError: name 'filecontent' is not defined Traceback (most recent call last): Pip 错误:错误:异常:回溯(最近一次通话): - Pip ERROR: ERROR: Exception: Traceback (most recent call last): Python未处理错误回溯(最近一次调用): - Python Unhandled Error Traceback (most recent call last): 我的 discord 机器人出现错误“回溯(最近一次通话最后一次):” - My discord bot have a error “Traceback (most recent call last):”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM