我正在使用树手动创建低级 API,但是当我运行代码时出现异常:创建接口对时出错。我该如何修复错误?

问题描述 投票:0回答:0

这是我的代码:

#!/usr/bin/python

from mininet.node import Host, OVSSwitch, Controller
from mininet.link import Link, TCLink, Intf
from mininet.net import Mininet
from mininet.cli import CLI


net = Mininet(controller=OVSSwitch)
#Creating Nodes:
h1 = net.addHost( 'h1', mac = '00:00:00:00:00:01', ip='10.0.0.1/24' )
h2 = net.addHost( 'h2', mac = '00:00:00:00:00:02', ip='10.0.0.2/24' )
h3 = net.addHost( 'h3', mac = '00:00:00:00:00:03', ip='10.0.0.3/24' )
h4 = net.addHost( 'h4', mac = '00:00:00:00:00:04', ip='10.0.0.4/24' )
h5 = net.addHost( 'h5', mac = '00:00:00:00:00:05', ip='10.0.0.5/24' )
h6 = net.addHost( 'h6', mac = '00:00:00:00:00:06', ip='10.0.0.6/24' )
h7 = net.addHost( 'h7', mac = '00:00:00:00:00:07', ip='10.0.0.7/24' )
h8 = net.addHost( 'h8', mac = '00:00:00:00:00:08', ip='10.0.0.8/24' )
e1 = net.addSwitch( 's1', cls = OVSSwitch, protocols = 'OpenFlow13' )
e2 = net.addSwitch( 'e2', cls = OVSSwitch, protocols = 'OpenFlow13' )
e3 = net.addSwitch( 'e3', cls = OVSSwitch, protocols = 'OpenFlow13' )
e4 = net.addSwitch( 'e4', cls = OVSSwitch, protocols = 'OpenFlow13' )
a1 = net.addSwitch( 'a1', cls = OVSSwitch, protocols = 'OpenFlow13' )
a2 = net.addSwitch( 'a2', cls = OVSSwitch, protocols = 'OpenFlow13' )
c0 = net.addController( 'c0' )
c1 = net.addController( 'c0' )

#Linking Nodes
net.addLink( h1, e1, cls=TCLink )
net.addLink( h2, e1, cls=TCLink )
net.addLink( h3, e2, cls=TCLink )
net.addLink( h4, e2, cls=TCLink )
net.addLink( h5, e3, cls=TCLink )
net.addLink( h6, e3, cls=TCLink )
net.addLink( h7, e4, cls=TCLink )
net.addLink( h8, e4, cls=TCLink )
net.addLink( e1, a1, port1=1, port2=3, cls=TCLink )
net.addLink( e2, a1, port1=1, port2=2, cls=TCLink )
net.addLink( e3, a2, port1=1, port2=3, cls=TCLink )
net.addLink( e4, a2, port1=1, port2=2, cls=TCLink )
net.addLink( a1, c1, port1=1, port2=2, cls=TCLink )
net.addLink( a2, c1, port1=1, port2=1, cls=TCLink )

#Set IP Address
h1.setIP( '10.0.0.1/24' )
h2.setIP( '10.0.0.2/24' )
h3.setIP( '10.0.0.3/24' )
h4.setIP( '10.0.0.4/24' )
h5.setIP( '10.0.0.5/24' )
h6.setIP( '10.0.0.6/24' )
h7.setIP( '10.0.0.7/24' )
h8.setIP( '10.0.0.8/24' )

OVSSwitch.start(Controller) 
net.start() 
#printing IP addresses
print (h1.IP)
print (h2.IP)
print (h3.IP)
print (h4.IP)
print (h5.IP)
print (h6.IP)
print (h7.IP)
print (h8.IP)

print ('Pinging ...')
print (h1.cmd( 'ping -c1 ', h2.IP() ))
print (h1.cmd( 'ping -c1 ', h3.IP() ))
print (h1.cmd( 'ping -c1 ', h4.IP() ))
print (h1.cmd( 'ping -c1 ', h5.IP() ))
print (h1.cmd( 'ping -c1 ', h6.IP() ))
print (h1.cmd( 'ping -c1 ', h7.IP() ))
print (h1.cmd( 'ping -c1 ', h8.IP() ))

CLI(net)
net.stop()

This the error is get

我确实运行了 sudo mn -c 命令,但我仍然异常:创建接口对时出错(s1-eth1,a1-eth3):RTNETLINK 回答:文件存在。看起来我正在创建重复项,但我不知道这是在哪里发生的。非常感谢任何帮助。

我应该能够成功ping通所有主机

This is a visual of the topology I'm creating

python network-programming mininet
© www.soinside.com 2019 - 2024. All rights reserved.