Ryu基本操作的REST API调用演示样例
import urllib2
import json def get_all_switches():
url = "http://127.0.0.1:8080/v1.0/topology/switches"
req = urllib2.Request(url)
res_data = urllib2.urlopen(req)
res = res_data.read()
res = json.loads(res)
return res def get_all_links():
url = "http://127.0.0.1:8080/v1.0/topology/links"
req = urllib2.Request(url)
res_data = urllib2.urlopen(req)
res = res_data.read()
res = json.loads(res)
return res
def get_switch(dpid):
url = "http://127.0.0.1:8080/v1.0/topology/switches/" + dpid
req = urllib2.Request(url)
res_data = urllib2.urlopen(req)
res = res_data.read()
res = json.loads(res)
return res def get_flow_entries(dpid):
url = "http://127.0.0.1:8080/stats/flow/" + dpid
req = urllib2.Request(url)
res_data = urllib2.urlopen(req)
res = res_data.read()
res = json.loads(res)
return res def add_flow_entry(dpid,match,priority,actions):
url = "http://127.0.0.1:8080/stats/flowentry/add"
post_data = "{'dpid':%s,'match':%s,'priority':%s,'actions':%s}" % (dpid,str(match),priority,str(actions))
req = urllib2.Request(url,post_data)
res = urllib2.urlopen(req)
return res.getcode() def delete_flow_entry(dpid, match=None, priority=None, actions=None):
url = "http://127.0.0.1:8080/stats/flowentry/delete"
post_data = "{'dpid':%s" % dpid
if match is not None:
post_data += ",'match':%s" % str(match)
if priority is not None:
post_data += ",'priority':%s" % priority
if actions is not None:
post_data += ",'actions':%s" % str(actions)
post_data += "}" req = urllib2.Request(url,post_data)
res = urllib2.urlopen(req)
return res.getcode()
函数说明:
#get_all_switches()
參数:无
返回结果:一个包括全部交换机信息的列表
结果演示样例:
[{"ports": [{"hw_addr": "12:ad:47:17:6d:1d", "name": "s1-eth1", "port_no": "00000001", "dpid": "0000000000000001"}, {"hw_addr": "62:bf:89:79:68:67", "name": "s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"}], "dpid": "0000000000000001"}, {"ports":
[{"hw_addr": "da:d7:cb:f8:a4:7f", "name": "s2-eth1", "port_no": "00000001", "dpid": "0000000000000002"}, {"hw_addr": "ce:31:74:a1:c1:2d", "name": "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}], "dpid": "0000000000000002"}, {"ports": [{"hw_addr":
"ea:c5:e8:ee:72:f7", "name": "s3-eth1", "port_no": "00000001", "dpid": "0000000000000003"}, {"hw_addr": "da:57:80:b2:74:67", "name": "s3-eth2", "port_no": "00000002", "dpid": "0000000000000003"}], "dpid": "0000000000000003"}]
#get_all_links()
參数:无
返回结果:一个包括全部链路信息的列表
结果演示样例:
[{"src": {"hw_addr": "12:ad:47:17:6d:1d", "name": "s1-eth1", "port_no": "00000001", "dpid": "0000000000000001"}, "dst": {"hw_addr": "da:d7:cb:f8:a4:7f", "name": "s2-eth1", "port_no": "00000001", "dpid": "0000000000000002"}}, {"src": {"hw_addr": "ea:c5:e8:ee:72:f7",
"name": "s3-eth1", "port_no": "00000001", "dpid": "0000000000000003"}, "dst": {"hw_addr": "ce:31:74:a1:c1:2d", "name": "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}}, {"src": {"hw_addr": "da:d7:cb:f8:a4:7f", "name": "s2-eth1", "port_no": "00000001",
"dpid": "0000000000000002"}, "dst": {"hw_addr": "12:ad:47:17:6d:1d", "name": "s1-eth1", "port_no": "00000001", "dpid": "0000000000000001"}}, {"src": {"hw_addr": "ce:31:74:a1:c1:2d", "name": "s2-eth2", "port_no": "00000002", "dpid": "0000000000000002"}, "dst":
{"hw_addr": "ea:c5:e8:ee:72:f7", "name": "s3-eth1", "port_no": "00000001", "dpid": "0000000000000003"}}]
#get_switch(dpid)
參数:dpid为字符串,比方"0000000000000001"
返回结果:一个包括dpid相应的交换机的信息的列表
结果演示样例:
[{"ports": [{"hw_addr": "12:ad:47:17:6d:1d", "name": "s1-eth1", "port_no": "00000001", "dpid": "0000000000000001"}, {"hw_addr": "62:bf:89:79:68:67", "name": "s1-eth2", "port_no": "00000002", "dpid": "0000000000000001"}], "dpid": "0000000000000001"}]
#get_flow_entries(dpid)
參数:dpid为字符串,比方"0000000000000001"
返回结果:一个包括流表项的字典
结果演示样例:
{"1": [{"actions": ["OUTPUT:65533"], "idle_timeout": 0, "cookie": 0, "packet_count": 2252, "hard_timeout": 0, "byte_count": 114852, "duration_nsec": 370000000, "priority": 65535, "duration_sec": 2026, "table_id": 0, "match": {"dl_type": 35020, "nw_dst": "0.0.0.0",
"dl_vlan_pcp": 0, "dl_src": "00:00:00:00:00:00", "nw_tos": 0, "tp_src": 0, "dl_vlan": 0, "nw_src": "0.0.0.0", "nw_proto": 0, "tp_dst": 0, "dl_dst": "01:80:c2:00:00:0e", "in_port": 0}}, {"actions": ["OUTPUT:2"], "idle_timeout": 0, "cookie": 0, "packet_count":
0, "hard_timeout": 0, "byte_count": 0, "duration_nsec": 864000000, "priority": 1111, "duration_sec": 104, "table_id": 0, "match": {"dl_type": 0, "nw_dst": "0.0.0.0", "dl_vlan_pcp": 0, "dl_src": "00:00:00:00:00:00", "nw_tos": 0, "tp_src": 0, "dl_vlan": 0, "nw_src":
"0.0.0.0", "nw_proto": 0, "tp_dst": 0, "dl_dst": "00:00:00:00:00:00", "in_port": 1}}]}
当中开头的“1”表示dpid号
#add_flow_entry(dpid,match,priority,actions)
參数:
dpid为字符串,比方"0000000000000001"
match为字典。比方match = {"in_port":00000001},其它键的名称见《ryu Documentation》P161的Flow Match Structure
priority为字符串,比方"1111"
actions为列表,比方actions = [{"type":"OUTPUT","port":00000002}]。其它元素名称见《ryu Documentation》P282的actions
返回结果:整数,HTTP状态码,200表示加入流表项成功
结果演示样例:200,403,404
#delete_flow_entry(dpid,match,priority,actions)
參数:
dpid为字符串。比方"0000000000000001"
match为字典,比方match = {"in_port":00000001},其它键的名称见《ryu Documentation》P161的Flow Match Structure
priority为字符串,比方"1111"
actions为列表。比方actions = [{"type":"OUTPUT","port":00000002}],其它元素名称见《ryu Documentation》P282的actions
返回结果:整数,HTTP状态码。200表示删除流表项成功
结果演示样例:200,403,404
Ryu基本操作的REST API调用演示样例的更多相关文章
- 跨域JSONP原理及调用详细演示样例
上篇博客介绍了同源策略和跨域訪问概念,当中提到跨域经常使用的基本方式:JSONP和CORS. 那这篇博客就介绍JSONP方式. JSONP原理 在同源策略下,在某个server下的页面 ...
- 通过Canvas及File API缩放并上传图片完整演示样例
创建一个只管的用户界面,并同意你控制图片的大小.上传到server端的数据,并不须要处理enctype为 multi-part/form-data 的情况.只一个简单的POST表单处理程序就能够了. ...
- PHPCMS中GET标签概述、 get 标签语法、get 标签创建工具、get 调用本系统演示样例、get 调用其它系统演示样例
一.get 标签概述 通俗来讲,get 标签是Phpcms定义的能直接调用数据库里面内容的简单化.友好化代码,她可调用本系统和外部数据,仅仅有你对SQL有一定的了解,她就是你的绝世好剑!也就是适合熟悉 ...
- 在.Net MVC结构API接口中推断http头信息实现公共的权限验证过滤器演示样例
//control action public class TestController : ApiController { [MyAuthFilter] public string test(s ...
- HBase总结(十一)hbase Java API 介绍及使用演示样例
几个相关类与HBase数据模型之间的相应关系 java类 HBase数据模型 HBaseAdmin 数据库(DataBase) HBaseConfiguration HTable 表(Table) H ...
- JDBC连接MySQL数据库及演示样例
JDBC是Sun公司制定的一个能够用Java语言连接数据库的技术. 一.JDBC基础知识 JDBC(Java Data Base Connectivity,java数据库连接)是一种用 ...
- 最简单的视音频播放演示样例4:Direct3D播放RGB(通过Texture)
===================================================== 最简单的视音频播放演示样例系列文章列表: 最简单的视音频播放演示样例1:总述 最简单的视音频 ...
- 最简单的视音频播放演示样例5:OpenGL播放RGB/YUV
===================================================== 最简单的视音频播放演示样例系列文章列表: 最简单的视音频播放演示样例1:总述 最简单的视音频 ...
- WebGL自学教程——WebGL演示样例:開始
最终開始WebGL的演示样例了,...... 開始 使用WebGL的步骤,非常easy: 1. 获得WebGL的渲染环境(也叫渲染上下文). 2. 发挥你的想象力,利用<WebGL參考手冊> ...
随机推荐
- Vue框架Element UI教程-axios请求数据
Element UI手册:https://cloud.tencent.com/developer/doc/1270 中文文档:http://element-cn.eleme.io/#/zh-CN gi ...
- js 学习思维导图
- 【【henuacm2016级暑期训练】动态规划专题 F】Physics Practical
[链接] 我是链接,点我呀:) [题意] 给你n个数字 让你删掉最小的数字 使得: 剩余的数字中 "最大的数字"小于等于"最小的数字*2" [题解] 把数据从小 ...
- java中的接口中的方法
题目如下:(多选题)请选择以下接口定义正确的方法() A:public static void main (String[] args); B:private void test(); C:publi ...
- ASP.NET-服务器客户端的信息保持
ASP.NET客户端和服务器端的信息保持方案 来自为知笔记(Wiz)
- linux svn命令具体解释
检測是否安装svn:svnserve --version svn服务的关闭:killall svnserve 创建svn库:svnadmin create /opt/svn/repos 配置自己主动启 ...
- 玩转Android Camera开发(三):国内首发---使用GLSurfaceView预览Camera 基础拍照demo
GLSurfaceView是OpenGL中的一个类,也是能够预览Camera的,并且在预览Camera上有其独到之处. 独到之处在哪?当使用Surfaceview无能为力.痛不欲生时就仅仅有使用GLS ...
- m_Orchestrate learning system---八、下拉列表(select标签)如何实现链接功能
m_Orchestrate learning system---八.下拉列表(select标签)如何实现链接功能 一.总结 一句话总结:option的值就是链接地址,选择事件为指向选中的option的 ...
- ElasticSearch Shard——本质上是做分布式扩展,副本对于集群的稳定性有很强的影响
什么是一个Shard? Shard就是一个Lucene Index,参照文章(深入理解Shard和Lucene Index). Index需要多少个Shard? 回答这个问题,我们需要先谈谈节点,一个 ...
- nyoj--18--The Triangle(dp水题)
The Triangle 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure ...