实验目的
成功ping通
实验2 Mininet下发流表1. 自定义拓扑
运行拓扑
2. 划分VLAN
需求: VLAN划分:
联通性要求: h1-h3 h2-h4,其余不通
为s1配置流表项:
查看下发的流表项:
这四条命令原理: 1、2条命令:
为s2配置流表项: 原理与s1配置类似
符合h1和h3联通,h2和h4联通,其余不连通要求。
wireshark验证:
(二)进阶实验
要求:利用Python代码实现VlAN划分
#!/usr/bin/python from mininet.net import Mininet from mininet.node import Node from mininet.link import Link from mininet.log import setLogLevel, info def myNet(): "Create network from scratch using Open vSwitch." info( "*** Creating nodesn" ) switch1 = Node( 's1', inNamespace=False ) switch2 = Node( 's2', inNamespace=False ) h1 = Node( 'h1' ) h2 = Node( 'h2' ) h3 = Node( 'h3' ) h4 = Node( 'h4' ) info( "*** Creating linksn" ) Link( h1, switch1) Link( h2, switch1) Link( h3, switch2) Link( h4, switch2) Link( switch1, switch2) info( "*** Configuring hostsn" ) h1.setIP( '192.168.123.1/24' ) h2.setIP( '192.168.124.1/24' ) h3.setIP( '192.168.123.2/24' ) h4.setIP( '192.168.124.2/24' ) info( "*** Starting network using Open vSwitchn" ) switch1.cmd( 'ovs-vsctl del-br dp0' ) switch1.cmd( 'ovs-vsctl add-br dp0' ) switch2.cmd( 'ovs-vsctl del-br dp1' ) switch2.cmd( 'ovs-vsctl add-br dp1' ) for intf in switch1.intfs.values(): print (intf) print (switch1.cmd( 'ovs-vsctl add-port dp0 %s' % intf )) for intf in switch2.intfs.values(): print (intf) print (switch2.cmd( 'ovs-vsctl add-port dp1 %s' % intf )) print (switch1.cmd(r'ovs-vsctl show')) print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096->vlan_vid,output:3')) print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097->vlan_vid,output:3')) print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,dl_vlan=0,actions=pop_vlan,output:1')) print (switch1.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp0 priority=1,dl_vlan=1,actions=pop_vlan,output:2')) print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096->vlan_vid,output:3')) print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097->vlan_vid,output:3')) print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,dl_vlan=0,actions=pop_vlan,output:1')) print (switch2.cmd(r'ovs-ofctl -O OpenFlow13 add-flow dp1 priority=1,dl_vlan=1,actions=pop_vlan,output:2')) #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &') #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &') info( "*** Running testn" ) h1.cmdPrint( 'ping -c 3 ' + h3.IP() ) h2.cmdPrint( 'ping -c 3 ' + h4.IP() ) h1.cmdPrint( 'ping -c 3 ' + h4.IP() ) h2.cmdPrint( 'ping -c 3 ' + h3.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 networkn" ) switch1.cmd( 'ovs-vsctl del-br dp0' ) switch1.deleteIntfs() switch2.cmd( 'ovs-vsctl del-br dp1' ) switch2.deleteIntfs() info( 'n' ) if __name__ == '__mAIn__': setLogLevel( 'info' ) info( '*** Scratch network demo (kernel datapath)n' ) Mininet.init() myNet()
结果符合要求 验证2:通过wireshark验证
成功打上Vlan标签
1)此次实验我学习了如何使用OvS命令让数据包打上Vlan标签,并学习了如何使用控制行实现流表下发。 2)通过进阶实验,我学习了如何使用python文件实现流表下发,并能在python文件中进行测试。编写python文件的过程中遇到不少bug,但通过不断尝试最终进行了解决,提升了我的问题解决能力及创新能力。
附:知识总结
实验原理:用VLAN技术可以设计广播域构成,交换机收到广播帧后,从而防止广播风暴
命令总结
创建ovs交换机过程
sudo ovs-vsctl add-port ovs-switch000 p0
(通过ovs-vsctl show解决报错) 2. 查询p0网口相关信息
sudo ethtool -i p0
sudo ip netns add ns0 sudo ip link set p0 netns ns0 sudo ip netns exec ns0 ip addr add 192.168.1.100/24 dev p0 sudo ip netns exec ns0 ifconfig p0 promisc up
sudo ip netns exec ns0 ping 192.168.1.101
sudo ovs-ofctl show ovs-switch000
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096->vlan_vid,output:3 sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097->vlan_vid,output:3 sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:1 sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:2
查看流表项命令:
sudo ovs-ofctl -O OpenFlow13 dump-flows s1
原文链接:https://www.cnblogs.com/hhhf/p/16702352.html 原文作者:盒什么饭