脚本宝典收集整理的这篇文章主要介绍了第七次SDN上机实验,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.OpenDaylight (1) 利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;
搭建拓扑:@H_777_27@
连接OpenDaylight(ODL目录下): (2) 编写Python程序,调用OpenDaylight的北向接口下发指令删除s1上的流表数据。#!/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/'
headers = {'Content-type': 'application/json'}
res = requests.delete(url, headers=headers, auth=HTTPBasicAuth('admin', 'admin'))
PRint (res.content)
import requests
from requests.auth import HTTPBasicAuth
def http_put(url,jstr):
url= url
headers = {'Content-Type':'application/json'}
resp = requests.put(url,jstr,headers=headers,auth=HTTPBasicAuth('admin', 'admin'))
return resp
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 f:
jstr = f.read()
resp = http_put(url,jstr)
print (resp.content)
#!/usr/bin/python
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/flow-node-inventory:table/0/opendaylight-flow-table-statistics:flow-table-statistics'
headers = {'Content-Type': 'application/json'}
res = requests.get(url,headers=headers, auth=HTTPBasicAuth('admin', 'admin'))
print (res.content)
import requests
from requests.auth import HTTPBasicAuth
def http_post(url,jstr):
url= url
headers = {'Content-Type':'application/json'}
resp = requests.post(url,jstr,headers=headers)
return resp
if __name__ == "__main__":
url='http://127.0.0.1:8080/stats/flowentry/add'
with open('timeout2.json') as f:
jstr = f.read()
resp = http_post(url,jstr)
print (resp.content)
VLAN_ID | Hosts |
---|---|
0 | h1 h3 |
1 | h2 h4 |
curl -X POST -d '{
"dpid": 1,
"match": {
"in_port": 1
},
"actions": [
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4096
},
{
"type":"OUTPUT",
"port": 3
}
],
"priority":5
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '
{
"dpid": 1,
"priority":5,
"match": {
"in_port": 2
},
"actions": [
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4097
},
{
"type":"OUTPUT",
"port": 3
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '
{
"dpid": 1,
"match": {
"vlan_vid": 0
},
"actions": [
{
"type": "POP_VLAN",
"ethertype": 33024
},
{
"type":"OUTPUT",
"port": 1
}
],
"priority":5
}
' http://localhost:8080/stats/flowentry/add
curl -X POST -d'
{
"dpid": 1,
"match": {
"vlan_vid": 1
},
"actions": [
{
"type": "POP_VLAN",
"ethertype": 33024
},
{
"type":"OUTPUT",
"port": 2
}
],
"priority":5
}
' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 2,
"match": {
"in_port": 1
},
"actions": [
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4096
},
{
"type":"OUTPUT",
"port": 3
}
],
"priority":5
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '
{
"dpid": 2,
"match": {
"in_port": 2
},
"actions": [
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4097
},
{
"type":"OUTPUT",
"port": 3
}
],
"priority":5
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '
{
"dpid": 2,
"match": {
"vlan_vid": 0
},
"actions": [
{
"type": "POP_VLAN",
"ethertype": 33024
},
{
"type":"OUTPUT",
"port": 1
}
],
"priority":5
}
' http://localhost:8080/stats/flowentry/add
curl -X POST -d'
{
"dpid": 2,
"match": {
"vlan_vid": 1
},
"actions": [
{
"type": "POP_VLAN",
"ethertype": 33024
},
{
"type":"OUTPUT",
"port": 2
}
],
"priority":5
}' http://localhost:8080/stats/flowentry/add
编程实现基本要求第2部分Ryu(3)中的VLAN划分。
这次实验相比于之前的那些实验来说难度增大,这次的实验大部分都是代码的编写。 Python编写:一开始Python的编写或多或少都出现了问题,后来通过参考几位已经提交同学的代码,才慢慢摸索的写出来; Json:刚开始都不懂怎么写,参考了诗文同学的链接,以及自己上网搜索慢慢写出来; 实验环境:运行期间,实验结果一直不成功,运行./distribution-karaf-0.6.4-Carbon/bin/karaf这条代码的时候,出现error,后来经同学提醒可能是实验环境配置有问题,后来又重新装一遍,后来可以成功运行下去。
以上是脚本宝典为你收集整理的第七次SDN上机实验全部内容,希望文章能够帮你解决第七次SDN上机实验所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。