RYU REST API-基本概念

1. Rest API简介

REST即表述性状态传递(RepreSentational State Transfer),是一种针对网络应用的设计和开发方式,可以降低开发的复杂性,提高系统的可伸缩性。

表述性状态转移是一组构架约束条件和原则,满足这些约束和原则的应用程序或设计就是RESTful,REST是设计风格而不是标准,它通常基于使用HTTP,URI,XML以及HTML这些现有的广泛流行的协议和标准。

REST定义了一组体系构架原则,可以根据这些原则设计以系统资源为中心的Web服务,包括使用不同语言编写的客户端如何通过HTTP处理和传输资源状态。

2.ryu中REST API简介

ryu提供了一些RESTAPI的定义,在ryu/app目录下可以找到相关的文件:

ofctl_rest.py rest_topology.py rest_firewall.py rest_qos.py rest_router.py

它们分别提供了与OpenFlow协议、拓扑等相关的信息查询和配置,查询的结果以json格式返回。

最常用RESTAPI是ofctl_rest.py提供的RESTAPI,它提供了与OpenFlow相关的接口,如查看交换机,查看、添加、修改流表等。在oftcl_rest.py文件的前面注释部分可以看到接口的使用方法,列举如下:

  • get the list of all switches
    GET /stats/switches

  • get the desc stats of the switch
    GET /stats/desc/

  • get flows stats of the switch
    GET /stats/flow/

  • get flows stats of the switch filtered by the fields
    POST /stats/flow/

  • get aggregate flows stats of the switch
    GET /stats/aggregateflow/

  • get aggregate flows stats of the switch filtered by the fields
    POST /stats/aggregateflow/

  • get table stats of the switch
    GET /stats/table/

3.ryu中RESTAPI的三种使用方式

在浏览器中输入类似http://ip:port/stats/switches命令来发送GET请求,获取信息,ip为控制器的IP,ryu提供的port为8080。

用curl(curl是利用URL语法在命令行方式下工作的开源文件传输工具)代替浏览器,在终端输入如下命令来传输内容。

curl http://ip:port/stats/switches 

利用chrome等浏览器提供的插件Postman,或者FIrefox浏览器的HttpRequester。它们提供了Pretty结果展示方法,可视性和便读性良好。

官方给出的API列表http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html如下:

ryu.app.ofctl_rest

Retrieve the switch stats

Get all switches
Get the desc stats
Get all flows stats
Get flows stats filtered by fields
Get aggregate flow stats
Get aggregate flow stats filtered by fields
Get table stats
Get table features
Get ports stats
Get ports description
Get queues stats
Get queues config
Get queues description
Get groups stats
Get group description stats
Get group features stats
Get meters stats
Get meter config stats
Get meter description stats
Get meter features stats
Get role

Update the switch stats

Add a flow entry
Modify all matching flow entries
Modify flow entry strictly
Delete all matching flow entries
Delete flow entry strictly
Delete all flow entries
Add a group entry
Modify a group entry
Delete a group entry

Modify the behavior of the port

Add a meter entry
Modify a meter entry
Delete a meter entry

Modify role

Support for experimenter multipart
Send a experimenter message

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章