Mininet报错:Error creating interface pair (s1-eth1,s2-eth1): RTNETLINK answers: File exists
以下一段代码为例:
#!/usr/bin/env python
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call
def myNetwork():
net = Mininet( topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=Controller,
protocol='tcp',
port=6633)
info( '*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
info( '*** Add links\n')
net.addLink(s1,h1,1,1)
net.addLink(h2,s1,1,2)
net.addLink(s1,s2,1,1)
net.addLink(s2,h3,1,2)
net.addLink(s2,h4,3,3)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
保存为test.py执行命令:
sudo python test.py
报错:
分析错误提示:“Exception: Error creating interface pair (s1-eth1,s2-eth1): RTNETLINK answers: File exists”,发现代码38行
net.addLink(s1, s2, 1, 1)
端口错误,s1的1端口已经和h1的1端口建立链路,所以需要修改addLink部分的端口号:
info( '*** Add links\n')
net.addLink(s1, h1, 1, 1)
net.addLink(h2, s1, 1, 2)
net.addLink(s1, s2, 3, 3)
net.addLink(s2, h3, 1, 1)
net.addLink(s2, h4, 2, 1)
修改后重新执行成功