SDN第七次上机作业

发布时间:2022-07-02 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了SDN第七次上机作业脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

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

  • OPEnDaylight

任务

利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;

SDN第七次上机作业

任务二

编写Python程序,调用OpenDaylight的北向接口下发指令删除s1上的流表数据。

SDN第七次上机作业

#!/usr/bin/python
import requests
From requests.auth import HTTPBasicAuth

def http_detele(url):
    url = url
    headers = {'Content-type': 'application/json'}
    resp = requests.delete(url, 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/'
    resp = http_detele(url)
    PRint(resp.content)

SDN第七次上机作业

任务三

编写Python程序,调用OpenDaylight的北向接口下发硬超时流表,实现拓扑内主机h1和h3网络中断20s。

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('oal_3.json') as f:
        jstr = f.read()
    resp = http_put(url,jstr)
    print (resp.content)

SDN第七次上机作业

任务四

编写Python程序,调用OpenDaylight的北向接口获取s1上活动的流表数。

#!/usr/bin/python
import requests
from requests.auth import HTTPBasicAuth

def http_get(url):
	url = url
	headers = {'Content-Type':'application/json'}
	resp = requests.get(url,headers=headers,auth=HTTPBasicAuth('admin','admin'))
	return resp

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'
	resp = http_get(url)
	print(resp.content)

SDN第七次上机作业

  • Ryu

任务一

编写Python程序,调用Ryu的北向接口,实现上述OpenDaylight实验拓扑上相同的硬超时流表下发。

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('ryu_1.json') as f:
        jstr = f.read()
    resp = http_post(url,jstr)
    print (resp.content)

SDN第七次上机作业

任务二

用Mininet平台搭建下图所示网络拓扑,要求支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确。拓扑生成后需连接Ryu,且Ryu应能够提供REST API服务。

SDN第七次上机作业

SDN第七次上机作业

SDN第七次上机作业

SDN第七次上机作业

任务三

整理一个Shell脚本,参考Ryu REST API的文档,利用curl命令,实现和实验2相同的VLAN。

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

@H_946_126@

编程实现基本要求第2部分Ryu(3)中的VLAN划分。

import requests

def http_post(url, js):
    headers = {'Content-Type': 'application/json'}
    resp = requests.post(url, jstr, headers=headers)
    print(resp.content)


if __name__ == '__main__':
    url = 'http://localhost:8080/stats/flowentry/add'
    for i in range(1, 9):
        with open('%s.json' % i) as f:
            jstr = f.read()
        http_post(url, jstr)

  • 总结

  • 上次ryu实验后面重新装了一遍发现是py文件的问题。
  • 开始ODL的界面没有node,请教了同学知道,ODL要安装功能组件 https://blog.csdn.net/zengxiaosen/article/details/72864594、https://bLOG.csdn.net/u011412226/article/details/80243612
  • ODL其他部分一些小问题和同学讨论一下就出来了
  • miniedit连接ryu时要设置这个

    SDN第七次上机作业

  • ryu任务三查看了 https://ryu.readthedocs.io/en/latest/app/ofctl_rest.htML 的Update the switch stats一节,又查找了其他资料才搞出来。

脚本宝典总结

以上是脚本宝典为你收集整理的SDN第七次上机作业全部内容,希望文章能够帮你解决SDN第七次上机作业所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。