实验7:基于REST API的SDN北向应用实践
一、实验目的
- 能够编写程序调用OpenDaylight REST API实现特定网络功能;
- 能够编写程序调用Ryu REST API实现特定网络功能。
二、实验环境
- 下载虚拟机软件Oracle VisualBox或VMware;
- 在虚拟机中安装Ubuntu 20.04 Desktop amd64,并完整安装Mininet、OpenDaylight(Carbon版本)、Postman和Ryu;
三、实验要求
(一)基本要求
- 编写Python程序,调用OpenDaylight的北向接口实现以下功能
(1) 利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;
使用命令./distribution-karaf-0.6.4-Carbon/bin/karaf打开ODL控制器
使用命令sudo mn --topo=single,3 --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13创建拓扑并连接控制器
(2) 下发指令删除s1上的流表数据。
(3) 下发硬超时流表,实现拓扑内主机h1和h3网络中断20s。
(4) 获取s1上活动的流表数。
- 编写Python程序,调用Ryu的北向接口实现以下功能
(1) 实现上述OpenDaylight实验拓扑上相同的硬超时流表下发。
(2) 参考Ryu REST API的文档,基于VLAN实验的网络拓扑,编程实现相同的VLAN配置。
提示:拓扑生成后需连接Ryu,且Ryu应能够提供REST API服务
VLAN_ID |
Hosts |
0 |
h1 h3 |
1 |
h2 h4 |
拓扑代码topo.py
# 将主机1,2发送来的包打上vlan标记 curl -X POST -d '{ "dpid": 1, "priority": 1, "match":{ "in_port": 1 }, "actions":[ { "type": "PUSH_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "SET_FIELD", "field": "vlan_vid", # Set VLAN ID "value": 4096 # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096) }, { "type": "OUTPUT", "port": 3 } ] }' http://localhost:8080/stats/flowentry/add curl -X POST -d '{ "dpid": 1, "priority": 1, "match":{ "in_port": 2 }, "actions":[ { "type": "PUSH_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "SET_FIELD", "field": "vlan_vid", # Set VLAN ID "value": 4097 # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096) }, { "type": "OUTPUT", "port": 3 } ] }' http://localhost:8080/stats/flowentry/add # 将主机3,4发送来的包取出vlan标记 curl -X POST -d '{ "dpid": 1, "priority": 1, "match":{ "vlan_vid": 0 }, "actions":[ { "type": "POP_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "OUTPUT", "port": 1 } ] }' http://localhost:8080/stats/flowentry/add curl -X POST -d '{ "dpid": 1, "priority": 1, "match":{ "vlan_vid": 1 }, "actions":[ { "type": "POP_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "OUTPUT", "port": 2 } ] }' http://localhost:8080/stats/flowentry/add # 将主机3,4发送来的包打上vlan标记 curl -X POST -d '{ "dpid": 2, "priority": 1, "match":{ "in_port": 1 }, "actions":[ { "type": "PUSH_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "SET_FIELD", "field": "vlan_vid", # Set VLAN ID "value": 4096 # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096) }, { "type": "OUTPUT", "port": 3 } ] }' http://localhost:8080/stats/flowentry/add curl -X POST -d '{ "dpid": 2, "priority": 1, "match":{ "in_port": 2 }, "actions":[ { "type": "PUSH_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "SET_FIELD", "field": "vlan_vid", # Set VLAN ID "value": 4097 # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096) }, { "type": "OUTPUT", "port": 3 } ] }' http://localhost:8080/stats/flowentry/add curl -X POST -d '{ "dpid": 2, "priority": 1, "match":{ "vlan_vid": 0 }, "actions":[ { "type": "POP_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "OUTPUT", "port": 1 } ] }' http://localhost:8080/stats/flowentry/add curl -X POST -d '{ "dpid": 2, "priority": 1, "match":{ "vlan_vid": 1 }, "actions":[ { "type": "POP_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged "ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame }, { "type": "OUTPUT", "port": 2 } ] }' http://localhost:8080/stats/flowentry/add
(二)实验报告
个人总结,本次实验难度较大很多部分和代码都不理解,通过请教同学查阅资料的情况下勉强完成。作为最后的总结实验还是让我学到了非常多关于SDN的知识内容,还遇到了python版本不对一直报错的问题,使用curl命令时发现未安装。
标签:tagged,vlan,frame,VLAN,REST,API,33024,SDN,type From: https://www.cnblogs.com/212106602zyx/p/16845677.html