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

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