三、实验报告
3.1 基础要求提交
a) /home/用户名/学号/lab2/目录下执行ovs-vsctl show命令、以及p0和p1连通性测试的执行结果截图;
b) /home/用户名/学号/lab2/目录下开启Mininet CLI并执行pingall命令的截图、上述目录下查看OVS流表的命令结果截图,wireshark抓包截图,其余文字请勿赘述,否则扣分;
from mininet.topo import Topo
class MyTopo(Topo):
def __init__(self):
# initulaize topology
Topo.__init__(self)
# add hosts
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')
# add switches
s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')
# add links
self.addLink(h1, s1, 1, 1)
self.addLink(h2, s1, 1, 2)
self.addLink(h3, s2, 1, 1)
self.addLink(h4, s2, 1, 2)
self.addLink(h1, s2, 3, 3)
topos = {'mytopo':(lambda: MyTopo())}
- 开启Mininet CLI并执行pingall命令的截图
- 上述目录下查看OVS流表的命令结果截图
- wireshark抓包截图
3.2 进阶要求为选做,有完成的同学请提交代码和执行结果截图,有完成比未完成的上机分数更高。
#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Node
from mininet.link import Link
from mininet.log import setLogLevel, info
# 定义myNet模块
def myNet():
"Create network from scratch using Open vSwitch."
info( "*** Creating nodes\n" )
#添加交换机s1与s2
switch1 = Node( 's1', inNamespace=False )
switch2 = Node( 's2', inNamespace=False )
#添加主机h1-h4
h1 = Node( 'h1' )
h2 = Node( 'h2' )
h3 = Node( 'h3' )
h4 = Node( 'h4' )
#在主机h1-h4与交换机s1-s2,交换机s1与s2内按固定端口添加连接
info( "*** Creating links\n" )
Link( h1, switch1, 1, 1)
Link( h2, switch1, 1, 2)
Link( h3, switch2, 1, 1)
Link( h4, switch2, 1, 2)
Link( switch1, switch2, 3, 3)
#设置h1-h4主机ip地址
info( "*** Configuring hosts\n" )
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' )
#创建OVS交换机,命名为ovs-212106651
info( "*** Starting network using Open vSwitch\n" )
switch0.cmd( 'ovs-vsctl del-br ovs-212106651' ) #创建前先删除已有相同命名的交换机,防止后续操作中断
switch0.cmd( 'ovs-vsctl add-br ovs-212106651' )
for intf in switch0.intfs.values():
print intf
print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
# Note: controller and switch are in root namespace, and we
# can connect via loopback interface
#switch0.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
print switch0.cmd(r'ovs-vsctl show')
print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=1,actions=flood' )
print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=2,actions=flood' )
print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=3,actions=flood' )
print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1' )
print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:2' )
print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.3,actions=output:3')
#switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
#h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
info( "*** Running test\n" )
h0.cmdPrint( 'ping -c 3 ' + h1.IP() )
h0.cmdPrint( 'ping -c 3 ' + h2.IP() )
#print switch0.cmd( 'ovs-ofctl show dp0' )
#print switch0.cmd( 'ovs-ofctl dump-tables dp0' )
#print switch0.cmd( 'ovs-ofctl dump-ports dp0' )
#print switch0.cmd( 'ovs-ofctl dump-flows dp0' )
#print switch0.cmd( 'ovs-ofctl dump-aggregate dp0' )
#print switch0.cmd( 'ovs-ofctl queue-stats dp0' )
info( "*** Stopping network\n" )
switch0.cmd( 'ovs-vsctl del-br dp0' )
switch0.deleteIntfs()
info( '\n' )
#主函数执行 myNet模块
if __name__ == '__main__':
setLogLevel( 'info' )
info( '*** Scratch network demo (kernel datapath)\n' )
Mininet.init()
myNet()
3.3 个人总结,包括但不限于实验难度、实验过程遇到的困难及解决办法,个人感想,不少于200字。
3.3.1 执行脚本py文件,提示错误
ubuntu@ubuntu-VirtualBox:~/212106651/lab2$ sudo python3 ovsSingleBr.py
*** Scratch network demo (kernel datapath)
*** Creating nodes
*** Creating links
Traceback (most recent call last):
File "ovsSingleBr.py", line 46, in <module>
myNet()
File "ovsSingleBr.py", line 30, in myNet
Link( switch1, switch2, 3, 3)
File "/usr/local/lib/python3.8/dist-packages/mininet/link.py", line 456, in __init__
self.makeIntfPair( intfName1, intfName2, addr1, addr2,
File "/usr/local/lib/python3.8/dist-packages/mininet/link.py", line 501, in makeIntfPair
return makeIntfPair( intfname1, intfname2, addr1, addr2, node1, node2,
File "/usr/local/lib/python3.8/dist-packages/mininet/util.py", line 270, in makeIntfPair
raise Exception( "Error creating interface pair (%s,%s): %s " %
Exception: Error creating interface pair (s1-eth3,s2-eth3): RTNETLINK answers: File exists
- 错误出现位置在于创建s1与s2交换机端口33连接,在执行代码sudo mn -c 清除之前留下的缓存后,脚本正常执行
ubuntu@ubuntu-VirtualBox:~/212106651/lab2$ sudo mn --clean
*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes
killall controller ofprotocol ofdatapath ping nox_corelt-nox_core ovs-openflowd ovs-controllerovs-testcontroller udpbwtest mnexec ivs ryu-manager 2> /dev/null
killall -9 controller ofprotocol ofdatapath ping nox_corelt-nox_core ovs-openflowd ovs-controllerovs-testcontroller udpbwtest mnexec ivs ryu-manager 2> /dev/null
pkill -9 -f "sudo mnexec"
*** Removing junk from /tmp
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
*** Removing old X11 tunnels
*** Removing excess kernel datapaths
ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'
*** Removing OVS datapaths
ovs-vsctl --timeout=1 list-br
ovs-vsctl --if-exists del-br ovs-212106651
ovs-vsctl --timeout=1 list-br
*** Removing all links of the pattern foo-ethX
ip link show | egrep -o '([-_.[:alnum:]]+-eth[[:digit:]]+)'
( ip link del s2-eth3;ip link del s1-eth3;ip link del s1-eth3;ip link del s2-eth3 ) 2> /dev/null
ip link show
*** Killing stale mininet node processes
pkill -9 -f mininet:
*** Shutting down stale tunnels
pkill -9 -f Tunnel=Ethernet
pkill -9 -f .ssh/mn
rm -f ~/.ssh/mn/*
*** Cleanup complete.
ubuntu@ubuntu-VirtualBox:~/212106651/lab2$ sudo python3 ovsSingleBr.py
*** Scratch network demo (kernel datapath)
*** Creating nodes
*** Creating links
*** Configuring hosts
*** Starting network using Open vSwitch
ubuntu@ubuntu-VirtualBox:~/212106651/lab2$
标签:ovs,switch0,dp0,self,cmd,交换机,print,vSwitch,Open
From: https://www.cnblogs.com/lyf5446/p/16724215.html