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

实验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) 利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;
    img

    • 搭建拓扑

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

    • del.py

  • 结果

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

  • put.py

  • ODL_flowtable.json

  • 结果

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

  • get.py

  • 结果

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

  • put1.py

  • flowtable2.json

  • 结果

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

  • topo.py

  • 搭建拓扑

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

VLAN_ID Hosts
0 h1 h3
1 h2 h4
  • 删除流表
  • shell.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
+ 结果

四、实验心得

通过这次实验,进一步学习了用OpenDaylight和Ryu的rest API来实现特定的网络功能,除此之外还进一步学习了python的request库,为接下来做大作业打下了基础。同时在实验中遇到问题查看了相关文档,锻炼了阅读文档的能力。这次实验中是由几个小实验组成的,做完一个做下一个的时候,要记得把前一次的拓扑清空。实验中要记得先把流表清空。本次实验的实验内容主要内容在先前实验的基础上进行,因此兼顾综合之前大部分的实验内容与知识。也因此,实验内容的难度也相应有所提升,所以本次实验所耗费时间相对较久。但同时也让我对于Open DayLight 和 Ryu的使用和北向API都有了更加深刻的了解,对于request包的使用也有了一定量的复习。

posted @ 2021-10-26 21:43  0lwx  阅读(38)  评论(0编辑  收藏  举报