2019 SDN上机第2次作业

喜你入骨 提交于 2019-12-04 01:58:26

1. 利用mininet创建如下拓扑,要求拓扑支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确,请给出拓扑Mininet执行结果,展示端口连接情况


编写如下python脚本后运行,得到与预期端口号相符的网络拓扑:

#!/usr/bin/python
#Creating Inernet Topo

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections

class MyTopo(Topo):
    def __init__(self):
        #Initialize Topology
        Topo.__init__(self)
        L1 = 2
        L3 = 3
        c = []

        #add core ovs
        for i in range(L1):
            sw = self.addSwitch('s{}'.format(i+1))
            c.append(sw)
        
        #add Hosts
        count = 1
        for sw1 in c:
            for i in range(0, 3):
                host = self.addHost('h{}'.format(count))
                count+=1
                self.addLink(sw1,host,i+1,1)

        #add Links
        sw3=c[0]
        sw4=c[1]
        self.addLink(sw3,sw4,4,4)
        
topos = {'mytopo':(lambda:MyTopo())}
    

运行以下代码创建拓扑:

sudo mn -custom 2.1.py --topo mytopo --switch ovsk,protocols=OpenFlow13
pingall测试主机连通性:

2. 直接在Open vSwitch下发流表,实现如下连通性要求,请逐条说明所下发的流表含义

实现:

  • h1--h4互通
  • h2--h5互通
  • h3--h6互通
  • 其余不通

步骤:

  • Step1:给s1添加流表

    将进入s1 1、2、3端口的数据包打上vlan_tag从端口4向s2转发:

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

​ 将接收到的数据包去除vlan_tag,根据数据包的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
  • Step2:给s2添加流表

    将进入s2 1、2、3端口的数据包打上vlan_tag从端口4向s1转发:

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

​ 将接收到的数据包去除vlan_tag,根据数据包的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

3. 直接在Open vSwitch查看流表,提交OVS命令执行结果

输入命令:

sudo ovs-ofctl -O Openflow13 dump-flows s1

sudo ovs-ofctl -O Openflow13 dump-flows s2

4. 提交主机连通性测试结果,验证流表的有效性

5. 利用Wireshark抓包,分析验证特定报文

输入命令:
sudo wireshark &打开界面,选择s1的4端口进行抓包:


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!