• 2019 SDN上机第六次作业


    1.实验拓扑

    • python代码
    from mininet.topo import Topo
    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())}
    
    • 运行命令创建拓扑
    • pingall测试连通性
    • 连接ryu控制器

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

    • sh格式脚本下发流表(以s1为例,s2将"dpid"改为2)
    #端口号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
    
    • 执行sh格式文件
    • 控制器端显示下发的流表已被接收

    • 使用命令查看流表

    • pingall查看连通性

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

    相比第二次作业中手动下发流表,使用脚本更加直观,可一次性操作,但所需要求也更多,注意事项比较复杂;而手动下发流表更为简洁

  • 相关阅读:
    l2tp ubuntu
    my emacs fav config
    2048小游戏源码(vue自定义指令使用)
    Vue 脚手架新建项目
    vue中修改router定义的name值
    只能输入金额格式的input
    前端开发中UI问题处理
    form表单提交Ajax请求后不跳转
    小程序中代替v-html用法
    小程序中分页加载问题
  • 原文地址:https://www.cnblogs.com/wuyahong/p/11984770.html
Copyright © 2020-2023  润新知