• 基于Ryu REST API的VLAN实现


    0.预备知识

    ryu控制器的API文档:ryu.app.ofctl_rest
    根据博客基于RYU restful api实现的VLAN网络虚拟化完成最后的自动化脚本编写,实现RYU REST API的VLAN实现

    1.实验内容

    参加博客基于OVS命令的VLAN实现
    启动RYU

    ~/ryu/ryu/app$ ryu-manager ofctl_rest.py 
    

    如果同时要看拓扑:

    ~/ryu/ryu/app$ ryu-manager ~/ryu/ryu/app/gui_topology/gui_topology.py --observe-links
    

    gui_topology应用包含了ofctl_rest的功能,同时可以查看拓扑

    2.编写脚本addflow.sh一步实现流表下发

     curl -X POST -d '{
        "dpid": 1,
        "match":{
            "in_port": 1
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # Set VLAN ID
                "value": 4096            # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 1,
        "match":{
            "in_port": 2
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # Set VLAN ID
                "value": 4097            # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 1,
        "match":{
            "in_port": 3
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # Set VLAN ID
                "value": 4098            # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 1,
        "match":{
            "vlan_vid": 0
        },
        "actions":[
            {
                "type": "POP_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "OUTPUT",
                "port": 1
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 1,
        "match":{
            "vlan_vid": 1
        },
        "actions":[
            {
                "type": "POP_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "OUTPUT",
                "port": 2
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 1,
        "match":{
            "vlan_vid": 2
        },
        "actions":[
            {
                "type": "POP_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "OUTPUT",
                "port": 3
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
    
     curl -X POST -d '{
        "dpid": 2,
        "match":{
            "in_port": 1
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # Set VLAN ID
                "value": 4096            # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 2,
        "match":{
            "in_port": 2
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # Set VLAN ID
                "value": 4097            # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 2,
        "match":{
            "in_port": 3
        },
        "actions":[
            {
                "type": "PUSH_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "SET_FIELD",
                "field": "vlan_vid",     # Set VLAN ID
                "value": 4098            # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
            },
            {
                "type": "OUTPUT",
                "port": 4
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 2,
        "match":{
            "vlan_vid": 0
        },
        "actions":[
            {
                "type": "POP_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "OUTPUT",
                "port": 1
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 2,
        "match":{
            "vlan_vid": 1
        },
        "actions":[
            {
                "type": "POP_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "OUTPUT",
                "port": 2
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    
     curl -X POST -d '{
        "dpid": 2,
        "match":{
            "vlan_vid": 2
        },
        "actions":[
            {
                "type": "POP_VLAN",     # Push a new VLAN tag if a input frame is non-VLAN-tagged
                "ethertype": 33024       # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
            },
            {
                "type": "OUTPUT",
                "port": 3
            }
        ]
     }' http://localhost:8080/stats/flowentry/add
    

    3.使用api查看流表

    $ curl -X GET http://localhost:8080/stats/flow/<dpid>
    


    4.实验结果


  • 相关阅读:
    TopCoder<SRM>上的一道1100分的题目解析附代码
    《算法导论》思考题15-2 整齐打印
    《算法导论》思考题15-1 双调欧几里得旅行商问题(动态规划)
    <ReversingEngineering>关于windows32位系统下的dll注入技术经验汇
    实现一个EventEmitter类,这个类包含以下方法: on/ once/fire/off
    [Jquery 插件]活动倒计时,可同步服务器时间,倒计时格式随意设置
    阻止a标签跳转四种方法 兼容各大浏览器(包括IE)
    git常用操作 配置用户信息、拉取项目、提交代码、分支操作、版本回退...
    nrm npm源管理利器
    Element UI 框架搭建
  • 原文地址:https://www.cnblogs.com/fjlinww/p/11975229.html
Copyright © 2020-2023  润新知