zoukankan      html  css  js  c++  java
  • 基于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.实验结果


  • 相关阅读:
    store的应用
    创建简单的SimpleStore
    设置间隔一周的算法
    C#里缓存的使用
    javaFileWrite,FileReader
    javaArrayList
    java函数方法
    java学生管理系统(简易版)
    Tensorflow框架
    java日期
  • 原文地址:https://www.cnblogs.com/fjlinww/p/11975229.html
Copyright © 2011-2022 走看看