我刚刚建立了mininet的拓扑结构,但现在我想通过ubuntu的接口将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。有错误。
Caught exception. 正在清理...
有谁有这方面的经验。请帮助我!!!
这个问题前段时间有人问过,但我希望我的建议能有用。self.addSwitch()函数返回的是一个字符串,所以s1是一个字符串,而Intf函数需要一个Node类型。
如果你想用命令行运行,一个简单的解决方案是创建网络,然后使用一个添加Interface的测试函数,就像我做的例子。
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