我刚刚设置了mininet拓扑。但是现在我想通过ubuntu中的接口将mininet中的一个端口连接到外部端口。 Ubuntu服务器有两个端口:ens33连接到真实网络,ens38连接到VMnet2。我的python脚本如下:
from mininet.net import Mininet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import Intf
from mininet.log import setLogLevel, info
from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
# Add hosts and switches
'*** Add switches\n'
s1 = self.addSwitch('s1')
Intf( 'ens38', node=s1 )
s2 = self.addSwitch('s2')
'*** Add hosts\n'
h2 = self.addHost( 'h2' )
# Add links
'*** Add links\n'
self.addLink(h2, s2)
topos = { 'mytopo': ( lambda: MyTopo() ) }
但是当我使用commnad行时:mn --custom qtho-topo.py --topo mytopo --controller = remote,ip = 192.168.1.128,port = 6633 --switch ovsk,protocols = OpenFlow13。有错误:
抓到了异常。清理......
任何人都有关于此的exp。请帮帮我!!!
答案 0 :(得分:0)
这个问题是在不久前问的,但是我希望我的建议会有用。 self.addSwitch()函数返回一个字符串,因此s1是一个字符串,而Intf函数则需要一个Node类型。
如果要使用命令行运行,一个简单的解决方案是创建网络,然后使用添加接口的测试功能,就像我的示例一样。
from mininet.net import Mininet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import Intf
from mininet.log import setLogLevel, info
from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def build( self ):
"Create custom topo."
# Add hosts and switches
'*** Add switches\n'
s1 = self.addSwitch('s1')
info("**type s1 --> ",type(s1),"\n")
s2 = self.addSwitch('s2')
'*** Add hosts\n'
h2 = self.addHost( 'h2' )
# Add links
'*** Add links\n'
self.addLink(h2, s2)
def addIface(mn):
s1_node = mn.getNodeByName("s1")
Intf("ens38",node=s1_node)
CLI(mn)
tests = {'addIf': addIface}
topos = { 'mytopo': ( lambda: MyTopo() ) }
在命令行中运行它,假设您已将文件命名为test.py:
mn --custom=test.py --topo=mytopo --test=addIf
答案 1 :(得分:0)
添加到 Giuseppe 的回复中,这段代码对我有用:
def addIface(mn):
s1_node = mn.getNodeByName("s1")
s1_node.attach("ens38")
CLI(mn)