实验基础要求:
a) /home/用户名/学号/lab2/目录下执行ovs-vsctl show命令、以及p0和p1连通性测试的执行结果截图;
b) /home/用户名/学号/lab2/目录下开启Mininet CLI并执行pingall命令的截图、上述目录下查看OVS流表的命令结果截图,wireshark抓包截图
进阶要求:
有完成的同学请提交代码和执行结果截图
#!/usr/bin/env python
from mininet.net import Mininet
from mininet.node import Node
from mininet.link import TCLink
from mininet.log import setLogLevel, info
def myNet():
"Create network from scratch using Open vSwitch."
info( "*** Creating nodes\n" )
s1 = Node( 's1', inNamespace=False )
s2 = Node( 's2', inNamespace=False )
h1 = Node( 'h1' )
h2 = Node( 'h2' )
h3 = Node( 'h3' )
h4 = Node( 'h4' )
info( "*** Creating links\n" )
linkopts1=dict(bw=100, delay='1ms', loss=0)
linkopts2=dict(bw=1, delay='100ms', loss=0)
TCLink( h1, s1, **linkopts1)
TCLink( h2, s1, **linkopts1)
TCLink( h3, s2, **linkopts1)
TCLink( h4, s2, **linkopts1)
TCLink( s1, s2, **linkopts2)
info( "*** Configuring hosts\n" )
h1.setIP( '192.168.123.1/24' )
h2.setIP( '192.168.123.2/24' )
h3.setIP( '192.168.123.3/24' )
h4.setIP( '192.168.123.4/24' )
info( str( h1 ) + '\n' )
info( str( h2 ) + '\n' )
info( str( h3 ) + '\n' )
info( str( h4 ) + '\n' )
info( "*** Starting network using Open vSwitch\n" )
s1.cmd( 'ovs-vsctl del-br dp1' )
s1.cmd( 'ovs-vsctl add-br dp1' )
s2.cmd( 'ovs-vsctl del-br dp2' )
s2.cmd( 'ovs-vsctl add-br dp2' )
for intf in s1.intfs.values():
intf
s1.cmd('ovs-vsctl add-port dp1 %s' % intf)
for intf in s2.intfs.values():
intf
s2.cmd('ovs-vsctl add-port dp2 %s' % intf)
s1.cmd('ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3' )
s1.cmd('ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3' )
s1.cmd('ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,dl_vlan=0,actions=pop_vlan,output:1' )
s1.cmd('ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,dl_vlan=1,actions=pop_vlan,output:2' )
s2.cmd('ovs-ofctl -O OpenFlow13 add-flow dp2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3' )
s2.cmd('ovs-ofctl -O OpenFlow13 add-flow dp2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3' )
s2.cmd('ovs-ofctl -O OpenFlow13 add-flow dp2 priority=1,dl_vlan=0,actions=pop_vlan,output:1' )
s2.cmd('ovs-ofctl -O OpenFlow13 add-flow dp2 priority=1,dl_vlan=1,actions=pop_vlan,output:2' )
info( "*** Running test\n" )
h1.cmdPrint( 'ping -c 3 ' + h2.IP() )
h1.cmdPrint( 'ping -c 3 ' + h3.IP() )
h1.cmdPrint( 'ping -c 3 ' + h4.IP() )
h2.cmdPrint( 'ping -c 3 ' + h3.IP() )
h2.cmdPrint( 'ping -c 3 ' + h4.IP() )
h3.cmdPrint( 'ping -c 3 ' + h4.IP() )
info( "*** Stopping network\n" )
s1.cmd( 'ovs-vsctl del-br dp1' )
s1.deleteIntfs()
s2.cmd( 'ovs-vsctl del-br dp2' )
s2.deleteIntfs()
info( '\n' )
if __name__ == '__main__':
setLogLevel( 'info' )
info( '*** Scratch network demo (kernel datapath)\n' )
Mininet.init()
myNet()
个人总结
个人感想
在这次实验中我学习使用Open vSwitch进行基本操作,通过命令行终端使用OVS命令操作Open vSwitch交换机,管理流表,以及通过Mininet的Python代码运行OVS命令,控制网络拓扑中的Open vSwitch交换机。整个实验基于上次实验进行,操作起来并不难,而在实验过程中遇到的问题,我也通过在网上查找将这些问题解决了。在基础部分上,通过实验使我进一步的了解了Open vSwitch的相关命令和操作,简单掌握了用OVS命令来操作Open vSwitch交换机以及对其进行抓包操作;在进阶部分上,我学习了如何用Python脚本运行OVS命令控制Open vSwitch交换机,但是对于这部分的Python代码,我是基于老师提供的参考资料简单的进行了修改,期间还有将不该删除的代码删掉导致实验出错,之后慢慢进行更正,完成代码。