基于OVS命令的VLAN实现

利用mininet创建如下拓扑,要求支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确

基于OVS命令的VLAN实现_第1张图片

直接在Open vSwitch下发流表,实现如下连通性要求

  • h1 -- h4互通
  • h2 -- h5互通
  • h3 -- h6互通
  • 其余主机不通

OVS流表

sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4098-\>vlan_vid,output:4
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 add-flow s1 priority=1,dl_vlan=2,actions=pop_vlan,output:3

sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4098-\>vlan_vid,output:4
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:1
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:2
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=2,actions=pop_vlan,output:3

//set field值为4096+vlan_id,并且vlan优先级为0,即4096-8191,对应的vlan_id为0-4095

实验结果

基于OVS命令的VLAN实现_第2张图片

也可以换一个vlan号
基于OVS命令的VLAN实现_第3张图片

直接在Open vSwitch查看流表

基于OVS命令的VLAN实现_第4张图片

抓包验证

基于OVS命令的VLAN实现_第5张图片
基于OVS命令的VLAN实现_第6张图片
基于OVS命令的VLAN实现_第7张图片

你可能感兴趣的:(基于OVS命令的VLAN实现)