RYU REST API-應用實踐

1.啓動Mininet創建並啓動任意拓撲

2.運行ryu程序,並加載ryu的restapi

如:

 ryu-manager --verbose simple_switch_13.py ofctl_rest.py rest_topology.py

3.命令行獲取信息

• 得到拓撲中的交換機信息

   curl http://localhost:8080/stats/switches

• 得到交換機的狀態描述

    curl http://localhost:8080/stats/desc/1 

結果如下:

{“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

• 得到交換機的流表

curl http://localhost:8080/stats/flow/1

結果如下:

{“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

curl http://localhost:8080/stats/aggregateflow/1

結果如下

{“1”: [{“packet_count”: 92, “byte_count”: 14484, “flow_count”: 1}]}

• 得到交換機端口統計的狀態信息get ports stats of the switch

curl http://localhost:8080/stats/port/1

結果如下

{“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

4.使用瀏覽器插件操作REST API

推薦使用chrome的插件POSTMAN和Firefox的RESTClient(HttpRequester已停用)來操作RESTAPI,取代終端的curl命令。 在插件中輸入相應內容就可以下發請求信息。如:

  • 請求dpid爲1的交換機上的流表信息:
http://localhost:8080/stats/flow/1

選擇動作爲GET,點擊send,可以獲得交換機1上的流表信息。
這裏寫圖片描述
查看經過美化的JSON流表信息:
這裏寫圖片描述
- 對流表進行修改
使用POST動作類型,下發一個flow_mod消息,對現有流表進行操作。輸入URI如下:

http://localhost:8080/stats/flowentry/modify

具體body內容示例:
{
“dpid”: 1,
“cookie”: 1,
“cookie_mask”: 1,
“table_id”: 0,
“idle_timeout”: 30,
“hard_timeout”: 30,
“priority”: 2,
“flags”: 1,
“match”:{
“in_port”: 1,
“dl_dst”: “00:00:00:00:00:02”
},
“actions”:[
{
“type”:”OUTPUT”,
“port”: 3
}
]
}

send之後,返回200狀態碼,表明成功修改流表。

這裏寫圖片描述

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