1.利用mininet创建如下拓扑,要求拓扑支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确,请给出拓扑Mininet执行结果,展示端口连接情况
(1)搭建如下拓扑
(2)python脚本代码
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() ) }
(3)执行python脚本创建mininet网络拓扑
sudo mn --custom ./fattree2.py --topo mytopo --switch ovsk,protocols=OpenFlow13
输入net查看网络拓扑
输入pingall查看节点连接情况
2. 直接在Open vSwitch下发流表,实现如下连通性要求,请逐条说明所下发的流表含义
下面三条命令分别是将h1,h2,h3三个主机进入的包转打上vlan tag,转发到s1的四号端口号,in_port是指进来的端口号,actions指的是要进行的动作,set field值为4096+vlan_id,priority是优先级。
sudo ovs-ofctl add-flow -O OpenFlow13 s1 in_port=1,priority=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
sudo ovs-ofctl add-flow -O OpenFlow13 s1 in_port=2,priority=1,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:4
sudo ovs-ofctl add-flow -O OpenFlow13 s1 in_port=3,priority=1,actions=push_vlan:0x8100,set_field:4098-\>vlan_vid,output:4
下面三条命令分别是将h4,h5,h6三个主机进入的包转打上vlan tag,转发到s2的四号端口号,in_port是指进来的端口号,actions指的是要进行的动作,set field值为4096+vlan_id,priority是优先级。
sudo ovs-ofctl add-flow -O OpenFlow13 s2 in_port=1,priority=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
sudo ovs-ofctl add-flow -O OpenFlow13 s2 in_port=2,priority=1,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:4
sudo ovs-ofctl add-flow -O OpenFlow13 s2 in_port=3,priority=1,actions=push_vlan:0x8100,set_field:4098-\>vlan_vid,output:4
下面三条命令是将从之前打上的包vlan tag的包去除vlan tag,然后根据tag进行转发
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
3. 直接在Open vSwitch查看流表,提交OVS命令执行结果
输入sudo ovs-ofctl -O OpenFlow13 dump-flows s1命令查看s1流表
同样,输入sudo ovs-ofctl -O OpenFlow13 dump-flows s2命令查看s2流表
4. 提交主机连通性测试结果,验证流表的有效性
输入pingall命令查看连通性测试结果,如下图可知h1仅和h4相连,h2仅和h5相连,h3仅和h6相连,流表有效