参考资料网址:https://www.cnblogs.com/TITIN24/p/11794970.html
利用mininet创建如下拓扑
要求拓扑支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确,请给出拓扑Mininet执行结果,展示端口连接情况
创建PY文档:
from mininet.topo import Topo
class Topo2( Topo ):
def __init__( self ):
# Initialize topology
Topo.__init__( self )
# add switches and hosts
sw1 = self.addSwitch('s1')
sw2 = self.addSwitch('s2')
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')
h5 = self.addHost('h5')
h6 = self.addHost('h6')
# add links
self.addLink(h1,sw1,1,1)
self.addLink(h2,sw1,1,2)
self.addLink(h3,sw1,1,3)
self.addLink(sw1,sw2,4,4)
self.addLink(h4,sw2,1,1)
self.addLink(h5,sw2,1,2)
self.addLink(h6,sw2,1,3)
topos = { 'mytopo': ( lambda: Topo2() ) }
在终端内输入:
sudo mn --custom ./SDN1.py --topo mytopo --switch ovsk,protocols=OpenFlow13
使用PINGALL命令查看:
结果Results: 100% dropped
为互不连通状态
使用net命令:
在Open vSwitch下发流表
实现如下连通性要求,请逐条说明所下发的流表含义
h1 -- h4互通
h2 -- h5互通
h3 -- h6互通
其余主机不通
OVS下发流表的命令:
- sw1
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
//将主机1进入sw1的包打上vlan tag,转发端口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
//将主机2进入sw1的包打上vlan tag,转发端口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
//将主机3进入sw1的包打上vlan tag,转发端口4
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:1
//将从端口4的包去除vlan tag, 并根据tag进行转发端口1
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:2
//将从端口4的包去除vlan tag, 并根据tag进行转发端口2
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=2,actions=pop_vlan,output:3
//将从端口4的包去除vlan tag, 并根据tag进行转发端口3
- sw2
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
//与上面类似,将主机4进入sw2的包打上vlan tag,转发端口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
//将主机5进入sw2的包打上vlan tag,转发端口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
//将主机6进入sw2的包打上vlan tag,转发端口4
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:1
//将从端口4的包去除vlan tag, 并根据tag进行转发端口1
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:2
//将从端口4的包去除vlan tag, 并根据tag进行转发端口2
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=2,actions=pop_vlan,output:3
//将从端口4的包去除vlan tag, 并根据tag进行转发端口3
将所有命令输入到终端中:
验证流表的有效性
回到mininet使用PINGALL命令:
回到mininet使用net命令:
利用Wireshark抓包
启动WireShark:
sudo wireshark
选择需要验证的端口
端口不连通:
只会捕获到ARP协议的报文
端口连通时:
会捕获到ICMP报文