• 2019 SDN上机第6次作业


    1.实验拓扑

    Python脚本:

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

    查看拓扑端口连接情况:

    连接ryu控制器:

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

    #端口号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": 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
    


    查看流表:


    连通性测试:

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

    使用Ryu的REST API下发流表可视化比较好,只需要在body里面按照python字典的格式书写流表,然后下发即可

  • 相关阅读:
    来看看面试必问的HashMap,一次彻底帮你搞定HashMap源码
    深入浅出!springboot从入门到精通,实战开发全套教程!
    讲一讲Java的字符串常量池,看完你的思路就清晰了
    面向对象的这些核心技术,你掌握后包你面试无忧
    他凭借这70份PDF,3170页文件,成功斩获了含BATJ所有的offer
    springboot实战开发全套教程,让开发像搭积木一样简单!Github星标已上10W+!
    这行代码告诉你!为什么你地下城与勇士(DNF)的装备强化老是失败?
    精益求精!Spring Boot 知识点全面回顾,带你重新细读源码!
    太妙了!Spring boot 整合 Mybatis Druid,还能配置监控?
    putchar(".:-=+*#%@"[(int)(d * 5.0f)])
  • 原文地址:https://www.cnblogs.com/fzuzh/p/11984764.html
Copyright © 2020-2023  润新知