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

sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13

 

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

 

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

 

 

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

 

Ryu

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

 

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

 

sudo sudo mn --custom mytopo.py --topo mytopo --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13

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

 

命令行运行

curl -X DELETE http://localhost:8080/stats/flowentry/clear/1
curl -X DELETE http://localhost:8080/stats/flowentry/clear/2

shell脚本:

# 将主机1,2发送来的数据包打上vlan标记
curl -X POST -d '{
    "dpid": 1,
    "priority": 1,
    "match":{
        "in_port": 1
    },
    "actions":[
        {
            "type": "PUSH_VLAN",     
            "ethertype": 33024       
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",    
            "value": 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",    
            "ethertype": 33024      
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     
            "value": 4097           
        },
        {
            "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",    
            "ethertype": 33024       
        },
        {
            "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",    
            "ethertype": 33024      
        },
        {
            "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",    
            "ethertype": 33024      
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",    
            "value": 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",    
            "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": 2,
    "priority": 1,
    "match":{
        "vlan_vid": 0
    },
    "actions":[
        {
            "type": "POP_VLAN",    
            "ethertype": 33024      
        },
        {
            "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",    
            "ethertype": 33024      
        },
        {
            "type": "OUTPUT",
            "port": 2
        }
    ]
 }' http://localhost:8080/stats/flowentry/add


四、实验结果

  • 实验难度:很难

  • 实验过程遇到的困难及解决办法:   

       1、在删除流表的时候报错     刚打开的时候服务器没有流表,没有东西需要删除。

       2、在运行ryu时不能ping通     查看同学的步骤发现  curl -X GET http://localhost:8080/stats/flow/1查看流表,将OpenFlow协议由1.0改为1.3以后可以ping通

  • 个人感想:

              这次实验对我来说难度还是很大的,中途出了各种各样的错误,花费了很久的时间,相较于前几次实验感觉难度突然加大了。本次实验我也取得了一些收获,学会了编写程序调用OpenDaylight REST API实现特定网络功能,对ryu有了更深刻的了解,能够编写程序调用Ryu REST API实现特定网络功能。

 



posted @ 2021-10-27 11:28  whxxx  阅读(45)  评论(0编辑  收藏  举报