首页 > 其他分享 >SDN-实验7:基于REST API的SDN北向应用实践

SDN-实验7:基于REST API的SDN北向应用实践

时间:2022-11-27 22:55:07浏览次数:44  
标签:url REST headers json API timeout requests ryu SDN

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
 实现硬超时功能

标签:url,REST,headers,json,API,timeout,requests,ryu,SDN
From: https://www.cnblogs.com/xyvuu/p/16930940.html

相关文章

  • ApiJSON简单使用示例
    1{2"[]":{3"query":2,4"User":{5"@column":"id,name"6},7"count":5,8"@order":......
  • .NET6之MiniAPI(十七):缓存
    缓存是空间换时间的一种做法,可以有效的提升响应时间,asp.netcore引入了本地内存缓存和分布式缓存。先看一下本地内存缓存:usingMicrosoft.Extensions.Caching.M......
  • .NET6之MiniAPI(十七):缓存
    缓存是空间换时间的一种做法,可以有效的提升响应时间,asp.netcore引入了本地内存缓存和分布式缓存。先看一下本地内存缓存:usingMicrosoft.Extensions.Caching.M......
  • .NET6之MiniAPI(十六):数据保护
    对于web,安全是一个永久的话题,所以ASP.NETCore数据保护提供了一个简单,易用的加密API,可以用来保护数据,密钥管理和轮换。ASP.NETCore的数据保护是根据本机的一个ke......
  • .NET6之MiniAPI(十六):数据保护
    对于web,安全是一个永久的话题,所以ASP.NETCore数据保护提供了一个简单,易用的加密API,可以用来保护数据,密钥管理和轮换。ASP.NETCore的数据保护是根据本机的一个ke......
  • SDN-实验5:开源控制器实践-POX
    1.搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)2.阅读Hub模块代码,使用tcpdump验证Hub模块;打开pox控制器打开终端,h2,h3开启......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 第16章-Spring AOP中的基础API
    目录一、概述二、切点(Pointcut)三、通知(Advice)1.环绕通知2.前置通知3.异常通知4.后置通知四、通知者(Advisor)五、附录1.常用接口2.示例代码前面我们讲了基于XML和注......
  • (5条消息) map干掉两个for循环案例,空间复杂度优化_学习微站的博客-CSDN博客_map空间复
    map干掉两个for循环,​​空间复杂度​​优化//分组遍历if(CollectionUtils.isNotEmpty(dictGroupList)){dictGroupList.forEach(dicGroup->......
  • 使用 SAP UI5 sap.ui.export.Spreadsheet API 进行 Excel 导出的一些限制
    开发人员只能导出sap.ui.export.EdmType中列出的原始单元格数据类型,如下图所示:ExcelExportAPI不支持UI5表格单元格中的图标、图像、复选框和复杂控件。也不支持......