[英]How to run sudo mn --custom option in Mininet?
我正在尝试使用 --custom 选项在 Mininet 中运行 .py 脚本。 我的代码如下:
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.util import irange
class LinearTopo( Topo ):
"Linear topology of k switches, with n hosts per switch."
def build( self, k=2, n=1, **_opts):
"""k: number of switches
n: number of hosts per switch"""
self.k = k
self.n = n
if n == 1:
genHostName = lambda i, j: 'h%s' % i
else:
genHostName = lambda i, j: 'h%ss%d' % ( j, i )
lastSwitch = None
for i in irange( 1, k ):
# Add switch
switch = self.addSwitch( 's%s' % i )
# Add hosts to switch
for j in irange( 1, n ):
host = self.addHost( genHostName( i, j ) )
self.addLink( host, switch )
# Connect switch to previous
if lastSwitch:
self.addLink( switch, lastSwitch )
lastSwitch = switch
def simpleTest():
"Create and test a simple network"
topo = LinearTopo(k=4,n=8)
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()
当我尝试:
sudo mn --custom topo.py --topo LinearTopo
我收到以下错误:
*** Cleanup complete.
mininet@mininet-vm:~$ sudo mn --custom topo.py --topo LinearTopo
--------------------------------------------------------------------------------
Caught exception. Cleaning up...
Exception: Invalid topo name LinearTopo
--------------------------------------------------------------------------------
*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes
killall controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs-openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
killall -9 controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs-openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
pkill -9 -f "sudo mnexec"
*** Removing junk from /tmp
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
*** Removing old X11 tunnels
*** Removing excess kernel datapaths
ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'
*** Removing OVS datapaths
ovs-vsctl --timeout=1 list-br
ovs-vsctl --timeout=1 list-br
*** Removing all links of the pattern foo-ethX
ip link show | egrep -o '([-_.[:alnum:]]+-eth[[:digit:]]+)'
ip link show
*** Killing stale mininet node processes
pkill -9 -f mininet:
*** Shutting down stale tunnels
pkill -9 -f Tunnel=Ethernet
pkill -9 -f .ssh/mn
rm -f ~/.ssh/mn/*
*** Cleanup complete.
你能告诉我为什么会出现错误:无效的拓扑名称?
在def
前添加一行,不应缩进
TOPOS = {'LinearTopo' : (lambda : LinearTopo())}
现在你可以执行
sudo mn --custom topo.py --topo LinearTopo
上面你写的程序可以直接使用
sudo python <file_name>.py
如果您需要使用带值的sudo mn
运行,请按如下所示更新代码
TOPOS = {'LinearTopo' : (lambda : LinearTopo(4,5))}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.