无效的地形名称mytopo

问题描述 投票:0回答:1

我尝试在mininet上运行我的服装拓扑时出现以下错误。我正在运行命令:

sudo mn --custom Q1_a.py --topo=mytopo

我收到错误:

捕获的异常。打扫干净...例外:无效的topo名称mytopo

这是我的python文件Q1_a.py

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

TOPOS = {'mytopo' : (lambda : mytopo(4))}

class mytopo(Topo):
    "Single switch connected to n hosts."
    def build(self, n=4):
        switch1 = self.addSwitch('s1')
	switch2=self.addSwitch('s2')
        host1 = self.addHost('h%s' % (1))
        self.addLink(host1, switch1)
        host2 = self.addHost('h%s' % (2))
        self.addLink(host2, switch1)
        host3 = self.addHost('h%s' % (3))
        self.addLink(host3, switch2)
        host4 = self.addHost('h%s' % (4))
        self.addLink(host4, switch2)	
    
def Q1_a():
    "Create and test a simple network"
    topo = mytopo(n=4)
    net = Mininet(topo)
    //net.start()
    //net.stop()

if __name__ == '__main__':
    # Tell mininet to print useful information
    setLogLevel('info')
    Q1_a()

我很乐意为您提供帮助

mininet
1个回答
0
投票

我叫文件test.py,并使用了您编写的代码,除了第26和27行,我使用#进行注释。

如果我运行,它将起作用:

mn --custom  test.py --topo=mytopo

test.py

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

TOPOS = {'mytopo' : (lambda : mytopo(4))}

class mytopo(Topo):
    "Single switch connected to n hosts."
    def build(self, n=4):
        switch1 = self.addSwitch('s1')
    switch2=self.addSwitch('s2')
        host1 = self.addHost('h%s' % (1))
        self.addLink(host1, switch1)
        host2 = self.addHost('h%s' % (2))
        self.addLink(host2, switch1)
        host3 = self.addHost('h%s' % (3))
        self.addLink(host3, switch2)
        host4 = self.addHost('h%s' % (4))
        self.addLink(host4, switch2)

def Q1_a():
    "Create and test a simple network"
    topo = mytopo(n=4)
    net = Mininet(topo)
    #net.start()
    #net.stop()

if __name__ == '__main__':
    # Tell mininet to print useful information
    setLogLevel('info')
    Q1_a()
© www.soinside.com 2019 - 2024. All rights reserved.