zoukankan      html  css  js  c++  java
  • 2019 SDN上机第6次作业

    1.实验拓扑

    拓扑图:

    python脚本:

    运行python脚本:

    连接ryu控制器:

    输入net,查看各主机与交换机之间的端口情况:

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

    按实验二编写sh脚本

    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
    
    
    
    
    
    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
    
    
    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
    
    
    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
    
    
    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
    
    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
    
    
    
    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
    
    
    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
    
    
    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
    
    
    
    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
    
    
    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
    
    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
    

    执行脚本:

    查看s1,s2下发流表:

    使用pingall检查连接完整性:

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

    相比于第二次实验,这次试验使用Ryu的REST API下发流表实现VLAN,代码的可视性更好,条理清晰,便于修改,不会像实验二一般错了就要需要重新编写。

  • 相关阅读:
    Unity中的shadows(一)
    位1的个数
    Lua的协程
    安装SQL Server 2016时报0x84b10001生成XML文档时出错
    pcl registeration
    SO3和SE3的使用
    save_obj
    vulkan
    gcc编译选项
    全局函数与全局变量 多次使用、引用
  • 原文地址:https://www.cnblogs.com/qingke1314/p/12002224.html
Copyright © 2011-2022 走看看