• 2019 SDN上机第6次作业


    1.实验拓扑


    (1)实验拓扑如下

    (2)使用Python脚本完成拓扑搭建

    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):
    
            # initilaize topology
            Topo.__init__(self)
    
            # add hosts and switches
            h1 = self.addHost('h1')
            h2 = self.addHost('h2')
            h3 = self.addHost('h3')
            h4 = self.addHost('h4')
            h5 = self.addHost('h5')
            h6 = self.addHost('h6')
            s1 = self.addSwitch('s1')
            s2 = self.addSwitch('s2')
    
            # add links
            self.addLink(h1, s1, 1, 1)
            self.addLink(h2, s1, 1, 2)
            self.addLink(h3, s1, 1, 3)
            self.addLink(s1, s2, 4, 4)
            self.addLink(h4, s2, 1, 1)
            self.addLink(h5, s2, 1, 2)
            self.addLink(h6, s2, 1, 3)
            
    topos = {'mytopo': (lambda: MyTopo())}
    

    (3)连通性测试

    2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN


    (1)开启ryu restful服务器

    ryu-manager ofctl_rest.py
    

    (2)下载curl

    sudo apt-get install curl
    

    (3)编写如下JSON文件:dpid根据交换机s1,s2分别为1,2(共12条)

    #端口号1发来数据
    curl -X POST -d '{
        "dpid": 1,
        "priority":1,
        "match":{
            "in_port":1
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # s1将从主机发来的数据包打上vlan_tag
                "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # 设置VLAN ID
                "value": 4096            # 设置vlan_id的值
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
    }' http://127.0.0.1:8080/stats/flowentry/add
    
    #端口号2发来数据
    curl -X POST -d '{
        "dpid": 1,
        "priority":1,
        "match":{
            "in_port":2
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # s1将从主机发来的数据包打上vlan_tag
                "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # 设置VLAN ID
                "value": 4097            # 设置vlan_id的值
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
    }' http://127.0.0.1:8080/stats/flowentry/add
    
    #端口号3发来数据
    curl -X POST -d '{
        "dpid": 1,
        "priority":1,
        "match":{
            "in_port":3
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # s1将从主机发来的数据包打上vlan_tag
                "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # 设置VLAN ID
                "value": 4098            # 设置vlan_id的值
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
    }' http://127.0.0.1:8080/stats/flowentry/add
    
    #向端口1转发
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "dl_vlan": "0"
        },
        "actions":[
            {
                "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "type": "OUTPUT",
                "port": 1
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    
    #向端口2转发
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "dl_vlan": "1"
        },
        "actions":[
            {
                "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "type": "OUTPUT",
                "port": 2
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    
    #向端口3转发
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "dl_vlan": "2"
        },
        "actions":[
            {
                "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "type": "OUTPUT",
                "port": 3
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    
    
    #反向再来一遍
    #端口号1发来数据
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "in_port":1
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # s1将从主机发来的数据包打上vlan_tag
                "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # 设置VLAN ID
                "value": 4096            # 设置vlan_id的值
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
    }' http://127.0.0.1:8080/stats/flowentry/add
    
    #端口号2发来数据
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "in_port":2
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # s1将从主机发来的数据包打上vlan_tag
                "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # 设置VLAN ID
                "value": 4097            # 设置vlan_id的值
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
    }' http://127.0.0.1:8080/stats/flowentry/add
    
    #端口号3发来数据
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "in_port":3
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # s1将从主机发来的数据包打上vlan_tag
                "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # 设置VLAN ID
                "value": 4098            # 设置vlan_id的值
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
    }' http://127.0.0.1:8080/stats/flowentry/add
    
    #向端口1转发
    curl -X POST -d '{
        "dpid": 1,
        "priority":1,
        "match":{
            "dl_vlan": "0"
        },
        "actions":[
            {
                "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "type": "OUTPUT",
                "port": 1
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    
    #向端口2转发
    curl -X POST -d '{
        "dpid": 1,
        "priority":1,
        "match":{
            "dl_vlan": "1"
        },
        "actions":[
            {
                "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "type": "OUTPUT",
                "port": 2
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    
    #向端口3转发
    curl -X POST -d '{
        "dpid": 1,
        "priority":1,
        "match":{
            "dl_vlan": "2"
        },
        "actions":[
            {
                "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "type": "OUTPUT",
                "port": 3
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    

    (4)使用curl发送流表,运行.sh脚本

    sudo sh ./all.sh
    

    (5)控制器端显示下发的流表已被接收

    (200即为接收成功,404则失败)

    (6)查看交换机s1, s2流表

    (7)使用pingall查看其连通性

    3.对比两种方法,写出你的实验体会


    相比实验二中在终端手动下发流表,本实验中,使用Ryu的REST API的下发方式,一个.sh文件,以代码的方式汇总所有,更加直观,且易于理解,文件可保存, 方便修改,虽然代码略长,但优点很多,更具有灵活性。

  • 相关阅读:
    线程池的项目参考
    一文了解模型量化中的QAT和PTQ
    cookie 、 session、token分别是什么
    Browser storage limits and eviction criteria
    PropertyGridControl for dynamic properties
    Chrome 允许浏览器使用多达 80% 的总磁盘空间。一个来源最多可以使用总磁盘空间的 60%。
    Windbg查看调用堆栈(k*)
    ToDoList是一款非常实用的任务管理软件
    Windbg调试Unity3d 卡死 无响应等问题测试
    加密国密非对称SM2
  • 原文地址:https://www.cnblogs.com/0717fei/p/11984641.html
Copyright © 2020-2023  润新知