问题描述
看下面的命令-
$ sudo mn --controller=remote,ip=127.0.0.1,port=6653 --switch=ovsk,protocols=OpenFlow13 --topo=tree,depth=2,fanout=4
我想使用 Python 代码来实现这种拓扑结构。
到目前为止,我在 python 中得到了以下几行,它们部分地实现了上述命令的结果 -
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.topolib import TreeTopo
controller = RemoteController('c0',ip='127.0.0.1',port=6653)
topo = TreeTopo(2,4)
net = Mininet(topo=topo,controller=controller)
net.start()
如何在此 Python 代码中包含 switch 和 protocols 部分?
解决方法
请参考 mininet documentation
在你的情况下:
from mininet.net import Mininet
from mininet.node import RemoteController,OVSSwitch
from mininet.topolib import TreeTopo
from mininet.cli import CLI
controller = RemoteController('c0',ip='127.0.0.1',port=6653,protocols="OpenFlow13")
topo = TreeTopo(2,4)
net = Mininet(topo=topo,controller=controller,switch=OVSSwitch)
net.start()
#IF you want to start the CLI
CLI(net)
#If you want to clean the environment
net.stop()