1.编写Python程序,调用OpenDaylight的北向接口实现以下功能
(1) 利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;


(2) 下发指令删除s1上的流表数据。
编写delete.py,调用OpenDaylight的北向接口下发指令删除s1上的流表数据
`import requests
from requests.auth import HTTPBasicAuth

if name == ‘main‘:
url = ‘http://127.0.0.1:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:1/
headers = {‘Content-Type’: ‘application/json’}
response = requests.delete(url=url, headers=headers, auth=HTTPBasicAuth(‘admin’, ‘admin’))
print(response.content)(3) 下发硬超时流表,实现拓扑内主机h1和h3网络中断20s。 编写timeout.py及timeout.json,调用OpenDaylight的北向接口下发硬超时流表,实现拓扑内主机h1和h3网络中断20s timeout.py#!/usr/bin/python
import requests
from requests.auth import HTTPBasicAuth
if name == “main“:
url = ‘http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1
with open(“./timeout.json”) as file:
str = file.read()
headers = {‘Content-Type’: ‘application/json’}
res = requests.put(url, str, headers=headers, auth=HTTPBasicAuth(‘admin’, ‘admin’))
print (res.content)timeout.json{
“flow”: [
{
“id”: “1”,
“match”: {
“in-port”: “1”,
“ethernet-match”: {
“ethernet-type”: {
“type”: “0x0800”
}
},
“ipv4-destination”: “10.0.0.3/32”
},
“instructions”: {
“instruction”: [
{
“order”: “0”,
“apply-actions”: {
“action”: [
{
“order”: “0”,
“drop-action”: {}
}
]
}
}
]
},
“flow-name”: “flow”,
“priority”: “65535”,
“hard-timeout”: “20”,
“cookie”: “2”,
“table_id”: “0”
}
]
}(4) 获取s1上活动的流表数。 编写get_flows.py,调用OpenDaylight的北向接口获取s1上活动的流表数 get_flows.pyimport requests
from requests.auth import HTTPBasicAuth

if name == ‘main‘:
url = ‘http://127.0.0.1:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:1/
‘flow-node-inventory:table/0/opendaylight-flow-table-statistics:flow-table-statistics’
headers = {‘Content-Type’: ‘application/json’}
response = requests.get(url=url, headers=headers, auth=HTTPBasicAuth(‘admin’, ‘admin’))
print(response.content)2.编写Python程序,调用Ryu的北向接口实现以下功能 (1) 实现上述OpenDaylight实验拓扑上相同的硬超时流表下发。 编写ryu_timeout.py及ryu_timeout.json,调用Ryu的北向接口实现硬超时流表下发 ryu_timeout.pyimport requests
from requests.auth import HTTPBasicAuth

if name == ‘main‘:
url = ‘http://127.0.0.1:8080/stats/flowentry/add
headers = {‘Content-Type’: ‘application/json’}
json = open(‘ryu_timeout.json’).read()
response = requests.post(url, data=json, headers=headers)
print(response.content)ryu_timeout.json{
“dpid”: 1,
“cookie”: 1,
“cookie_mask”: 1,
“table_id”: 0,
“hard_timeout”: 20,
“priority”: 65535,
“flags”: 1,
“match”:{
“in_port”:1
},
“actions”:[]
}`
打开ryu
ryu-manager ryu.app.simple_switch_13 ryu.app.ofctl_rest
创建拓扑
sudo mn –topo=single,3 –mac –controller=remote,ip=127.0.0.1,port=6633 –switch ovsk,protocols=OpenFlow13
运行ryu_timeout.py
 实现硬超时功能

原文地址:http://www.cnblogs.com/xyvuu/p/16930940.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性