2019 SDN上机第2次作业
2019 SDN上机第2次作业
1. 利用mininet创建如下拓扑,要求拓扑支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确,请给出拓扑Mininet执行结果,展示端口连接情况
python代码编写拓扑的代码:
from mininet.topo import Topo
class Topo2( Topo ):
def __init__( self ):
# 初始化拓扑
Topo.__init__( self )
# 添加两台SDN交换机和六台主机
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')
h5 = self.addHost('h5')
h6 = self.addHost('h6')
sw1 = self.addSwitch('s1')
sw2 = self.addSwitch('s2')
# 添加连接
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 ./second.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6653 --switch ovsk,protocols=OpenFlow13
2. 直接在Open vSwitch下发流表,用vlan得到下列虚拟网段,请逐条说明所下发的流表含义
- h1 -- h4互通
- h2 -- h5互通
- h3 -- h6互通
- 其余主机不通
让mininet在原来的终端继续运行,另开一个终端执行以下操作
s1:
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接收到的报文加上VLAN标签0,往端口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接收到的报文加上VLAN标签1,往端口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接收到的报文加上VLAN标签2,往端口4转发
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:1
将端口4接收到的带有VLAN标签0的报文除去VLAN标签并往端口1转发
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:2
将端口4接收到的带有VLAN标签1的报文除去VLAN标签并往端口2转发
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=2,actions=pop_vlan,output:3
将端口4接收到的带有VLAN标签2的报文除去VLAN标签并往端口3转发
s2:
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:4
将端口1接收到的报文加上VLAN标签0,往端口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
将端口2接收到的报文加上VLAN标签1,往端口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
将端口3接收到的报文加上VLAN标签2,往端口4转发
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:1
将端口4接收到的带有VLAN标签0的报文除去VLAN标签并往端口1转发
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:2
将端口4接收到的带有VLAN标签1的报文除去VLAN标签并往端口2转发
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=2,actions=pop_vlan,output:3
将端口4接收到的带有VLAN标签2的报文除去VLAN标签并往端口3转发
3. 直接在Open vSwitch查看流表,提交OVS命令执行结果
查看s1流表:
sudo ovs-ofctl -O OpenFlow13 dump-flows s1
同理,查看s2流表:
sudo ovs-ofctl -O OpenFlow13 dump-flows s2