RYU的restapi的使用


要调用Rest API,必须事先使用ryu-manager 加载一些与之相关的Rest模块。

ryu/ryu/app目录下,主要有如下一些类型的Rest模块。

ofctl_rest.py  rest_topology.py  rest_firewall.py  rest_qos.py   rest_router.py
1.加载restapi
cd ryu/ryu/app && ryu-manager --verbose simple_switch.py ofctl_rest.py rest_topology.py(需要哪些py下的restapi调用即可)
2.启动mn
3.一些命令
ofctl_rest.py中的
  
  
得到拓扑中的交换机
[1]

得到交换机的状态描述
curl  http://localhost:8080/stats/desc/1 /desc/交换机的编号
{"1": {"dp_desc": "OpenFlow 1.3 Reference Userspace Switch Datapath", "sw_desc": "Oct 16 2016 18:53:53", "hw_desc": "OpenFlow 1.3 Reference Userspace Switch", "serial_num": "1", "mfr_desc": "Stanford University, Ericsson Research and CPqD R
得到交换机的流表
{"1": [{"actions": ["OUTPUT:CONTROLLER"], "idle_timeout": 0, "cookie": 0, "packet_count": 92, "hard_timeout": 0, "byte_count": 14484, "length": 80, "duration_nsec": 95000000, "priority": 0, "duration_sec": 1602, "table_id": 0, "flags": 0, "

get aggregate flows stats of the switch
{"1": [{"packet_count": 92, "byte_count": 14484, "flow_count": 1}]}

get ports stats of the switch
{"1": [{"tx_dropped": 0, "rx_packets": 28, "rx_crc_err": 0, "tx_bytes": 9724, "rx_dropped": 0, "port_no": 1, "rx_over_err": 0, "rx_frame_err": 0, "rx_bytes": 4760, "tx_errors": 0, "duration_nsec": 970000000, "collisions": 0, "duration_sec": 1730, "rx_errors": 0, "tx_packets": 64}, {"tx_dropped": 0, "rx_packets": 34, "rx_crc_err": 0, "tx_bytes": 9256, "rx_dropped": 0, "port_no": 2, "rx_over_err": 0, "rx_frame_err": 0, "rx_bytes": 5228, "tx_errors": 0, "duration_nsec": 970000000, "collisions": 0, "duration_sec": 1730, "rx_errors": 0, "tx_packets": 58}, {"tx_dropped": 0, "rx_packets": 30, "rx_crc_err": 0, "tx_bytes": 9988, "rx_dropped": 0, "port_no": "LOCAL", "rx_over_err": 0, "rx_frame_err": 0, "rx_bytes": 4496, "tx_errors": 0, "duration_nsec": 970000000, "collisions": 0, "duration_sec": 173

流表的操作还是可以参考 http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html#add-a-flow-entry 的官方文档
# add a flow entry
# POST /stats/flowentry/add
#

修改现有流表项
 modify all matching flow entries
# POST /stats/flowentry/modify
curl -X POST -d'{
"dpid": 1,
"match":{
    "dl_dst": "00:00:00:00:00:02",
    "in_port":1
        },
"actions":[]
('和url之间一定要有一个空格)

# modify flow entry strictly matching wildcards and priority
# POST /stats/flowentry/modify_strict
#
# delete all matching flow entries
# POST /stats/flowentry/delete
#
# delete flow entry strictly matching wildcards and priority
# POST /stats/flowentry/delete_strict
#
# delete all flow entries of the switch
# DELETE /stats/flowentry/clear/<dpid>
#
# add a meter entry
# POST /stats/meterentry/add
#
# modify a meter entry
# POST /stats/meterentry/modify
#
# delete a meter entry
# POST /stats/meterentry/delete
#
# add a group entry
# POST /stats/groupentry/add
#
# modify a group entry
# POST /stats/groupentry/modify
#
# delete a group entry
# POST /stats/groupentry/delete
#
# modify behavior of the physical port
# POST /stats/portdesc/modify
#
#
# send a experimeter message
# POST /stats/experimenter/<dpid>



rest_topology.py中的
# REST API for switch configuration
#
# get all the switches
# GET /v1.0/topology/switches
#
# get the switch
# GET /v1.0/topology/switches/<dpid>
#
# get all the links
# GET /v1.0/topology/links
#
# get the links of a switch
# GET /v1.0/topology/links/<dpid>
#
# get all the hosts
# GET /v1.0/topology/hosts
#
# get the hosts of a switch
# GET /v1.0/topology/hosts/<dpid>
#
# where
# <dpid>: datapath id in 16 hex


除了使用curl之外,还可以使用 POSTMAN,火狐浏览器上还有httprequester这个插件,通过post或者get来完成相应的命令
查询流表,点击get



修改流表,使用post,可以看到右侧返回了200 ok字样,代表提交成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值