其他分享
首页 > 其他分享> > OpenvSwitch实现简单VLAN

OpenvSwitch实现简单VLAN

作者:互联网

需求:

现有拓扑结构如下的网络结构(s1-s4为交换机,h1-h9为主机),现欲让单数主机(h1、h3、h5、h7、h9)之间互相能ping通,双数主机之间互相能够ping通,但单数和双数主机之间不能访问。

# 拓扑结构:
------------------------------------------------------
-------------------------s1---------------------------
---------------------/---|---\-------------------------
-----------------/-------|------\---------------------
--------------/----------|---------\------------------
------------/------------|------------\---------------
---------s2--------------s3--------------s4-----------
-------/--|--\---------/--|--\---------/--|--\--------
------h1--h2--h3------h4--h5--h6------h7--h8--h9------
------------------------------------------------------
------------------------------------------------------

OpenvSwitch实现VLAN

第一步,打开mininet 连接控制器

打开控制器

这里选择任意控制器均可,但是控制器要支持openflow1.3协议

打开mininet

mn --controller=remote,ip=127.0.0.1--mac --nat --topo=tree,depth=2,fanout=3 --switch ovs,protocols=OpenFlow13

第二步:

先在mininet里面pingall

用来生成初始流表

然后删除除了s1以外 其它控制器的流表

ovs-ofctl -O OpenFlow13 del-flows s2
ovs-ofctl -O OpenFlow13 del-flows s3
ovs-ofctl -O OpenFlow13 del-flows s4

第三步,添加流表:

自定义转发规则,单数主机和双数主机分别添加进入不同的VLAN组内,交换机分发报文时根据来源的组判断发往的端口。

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

含义:
从sx的in_port对应的机器分到set_field/vlan_id,通过4号口(对应s1)发出去
来自dl_vlan的数据包发送给output端口。

目前存在的问题:

同一个交换机内部的组内总是ping不通,例如s2下的h1和h3 ping不通
可以通过继续添加流表(交换机内部节点之间的转发规则)解决

标签:ovs,vlan,OpenFlow13,VLAN,OpenvSwitch,actions,简单,output,ofctl
来源: https://blog.csdn.net/weixin_46291251/article/details/121133018