如:
ryu-manager --verbose simple_switch_13.py ofctl_rest.py rest_topology.py
• 得到拓扑中的交换机信息
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
推荐使用chrome的插件POSTMAN和Firefox的RESTClient(HttpRequester已停用)来操作RESTAPI,取代终端的curl命令。 在插件中输入相应内容就可以下发请求信息。如:
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状态码,表明成功修改流表。