pooipo  
# 实验7:基于REST API的SDN北向应用实践
## 一、实验目的
1. 能够编写程序调用OpenDaylight REST API实现特定网络功能;
2. 能够编写程序调用Ryu REST API实现特定网络功能。
## 二、实验环境
1. 下载虚拟机软件Oracle VisualBox或VMware;
2. 在虚拟机中安装Ubuntu 20.04 Desktop amd64,并完整安装Mininet、OpenDaylight(Carbon版本)、Postman和Ryu;
## 三、实验要求
### (一)基本要求
1. OpenDaylight
(1)

| (2) |
| |
|

                                                                                                      |

| (3) |
| |
|

| |
|
| |
| (4) |
| |
| |

                                                                                                       |

| 2. Ryu |
| (1) |
| |
|
|
|
|
|

                                                                                                      |

| (2) |
|
|

                                                                                                       |

|
| |
| (3) |
| |
| | 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 |
| |
| 四、进阶任务 |
| |
| 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) |
| |
| 五、实验总结 |
| |
| ODL要安装功能组件,组件如下: |
| |
| https://blog.csdn.net/zengxiaosen/article/details/72864594 |
| |
| https://blog.csdn.net/u011412226/article/details/80243612 |

posted on 2021-10-26 17:03  pooipo  阅读(12)  评论(0)    收藏  举报