基于RYU restful api实现的VLAN网络虚拟化

基于RYU restful api实现的VLAN网络虚拟化

前言

本次实验是基于OVS的VLAN虚拟化简易实践方案的进一步的实验,采用RYU restful api进行配置。本质上和上次实验没什么差,究其原因还是因为上次不能较好使用RYU的restful api,现在学会了就实践一把吧。

RESTFUL API 下发流表

工具

  • postman
  • ryu/app/gui_topolog/gui_topology.py
  • ovs
  • mininet

实验步骤

之前的实验步骤不在赘述,主要是用RYU的restful api下发push_vlan

ACTION

tip:记得一定要大写

ActionsDescriptionExample
OUTPUTOutput packet from "port"{"type": "OUTPUT", "port": 3}
COPY_TTL_OUTCopy TTL outwards{"type": "COPY_TTL_OUT"}
COPY_TTL_INCopy TTL inwards{"type": "COPY_TTL_IN"}
SET_MPLS_TTLSet MPLS TTL using "mpls_ttl"{"type": "SET_MPLS_TTL", "mpls_ttl": 64}
DEC_MPLS_TTLDecrement MPLS TTL{"type": "DEC_MPLS_TTL"}
PUSH_VLANPush a new VLAN tag with "ethertype"{"type": "PUSH_VLAN", "ethertype": 33024}
POP_VLANPop the outer VLAN tag{"type": "POP_VLAN"}
PUSH_MPLSPush a new MPLS tag with "ethertype"{"type": "PUSH_MPLS", "ethertype": 34887}
POP_MPLSPop the outer MPLS tag with "ethertype"{"type": "POP_MPLS", "ethertype": 2054}
SET_QUEUESet queue id using "queue_id" when outputting to a port{"type": "SET_QUEUE", "queue_id": 7}
GROUPApply group identified by "group_id"{"type": "GROUP", "group_id": 5}
SET_NW_TTLSet IP TTL using "nw_ttl"{"type": "SET_NW_TTL", "nw_ttl": 64}
DEC_NW_TTLDecrement IP TTL{"type": "DEC_NW_TTL"}
SET_FIELDSet a "field" using "value"(The set of keywords available for "field" is the same as match field)See Example of set-field action
PUSH_PBBPush a new PBB service tag with "ethertype"(Openflow1.3+){"type": "PUSH_PBB", "ethertype": 35047}
POP_PBBPop the outer PBB service tag(Openflow1.3+){"type": "POP_PBB"}
COPY_FIELDCopy value between header and register(Openflow1.5+){"type": "COPY_FIELD", "n_bits": 32, "src_offset": 1, "dst_offset": 2, "src_oxm_id": "eth_src", "dst_oxm_id": "eth_dst"}
METERApply meter identified by "meter_id"(Openflow1.5+){"type": "METER", "meter_id": 3}
EXPERIMENTERExtensible action for the experimenter(Set "base64" or "ascii" to "data_type" field){"type": "EXPERIMENTER", "experimenter": 101, "data": "AAECAwQFBgc=", "data_type": "base64"}
GOTO_TABLE(Instruction) Setup the next table identified by "table_id"{"type": "GOTO_TABLE", "table_id": 8}
WRITE_METADATA(Instruction) Setup the metadata field using "metadata" and "metadata_mask"{"type": "WRITE_METADATA", "metadata": 0x3, "metadata_mask": 0x3}
METER(Instruction) Apply meter identified by "meter_id"(deprecated in Openflow1.5){"type": "METER", "meter_id": 3}
WRITE_ACTIONS(Instruction) Write the action(s) onto the datapath action set{"type": "WRITE_ACTIONS", actions":[{"type":"POP_VLAN",},{ "type":"OUTPUT", "port": 2}]}
CLEAR_ACTIONS(Instruction) Clears all actions from the datapath action set

Example of set-field action

$ curl -X POST -d '{
    "dpid": 1,
    "match":{
        "dl_type": "0x8000"
    },
    "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": 4102            # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
        },
        {
            "type": "OUTPUT",
            "port": 2
        }
    ]
 }' http://localhost:8080/stats/flowentry/add

postman

990007-20170315220317604-829973162.png

ovs

sudo ovs-ofctl -O OpenFlow13 dump-flows s1

得到结果

OFPST_FLOW reply (OF1.3) (xid=0x2):
 cookie=0x0, duration=2350.981s, table=0, n_packets=0, n_bytes=0, priority=1,in_port=1 actions=push_vlan:0x8100,set_field:4096->vlan_vid,output:2

总结

可以基于此写自动化脚本,不过还是有通过restful api层面,感觉还不是太好。下面搞一个不通过restful api层面的下发过程。

参考链接

RYU手册中的restapi之match+action页

转载于:https://www.cnblogs.com/wpqwpq/p/6556942.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值