1. 利用mininet创建如下拓扑,要求拓扑支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确,请给出拓扑Mininet执行结果,展示端口连接情况
使用python代码创建拓扑
网络信息:
连接情况:
python代码如下:
from mininet.topo import Topo
class Topo2( Topo ):
def __init__( self ):
Topo.__init__( self )
s1 = self.addSwitch('s1')
s2 = 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')
self.addLink(h1,s1,1,1)
self.addLink(h2,s1,1,2)
self.addLink(h3,s1,1,3)
self.addLink(h4,s2,1,1)
self.addLink(h5,s2,1,2)
self.addLink(h6,s2,1,3)
self.addLink(s1,s2,4,4)
topos = { 'mytopo': ( lambda: Topo2() ) }
2. 直接在Open vSwitch下发流表,用vlan得到下列虚拟网段,请逐条说明所下发的流表含义
s1:
#s1将从端口号为1,2,3的主机发来的数据贴上相同的vlan tag,然后从4端口发往s2(vlan_id从0开始)
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
#s1将接收到的数据包去除vlan tag,然后根据dl_vlan(数据包原始的vlan_id),向指定端口转发
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
s2:
#s2将从端口号为1,2,3的主机发来的数据贴上相同的vlan tag,然后从4端口发往s1(vlan_id从0开始)
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
#s2将接收到的数据包去除vlan tag,然后根据dl_vlan(数据包原始的vlan_id),向指定端口转发
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
终端执行图: