1. 使用RYU做mininet的控制器

1.1 RYU介绍与安装

RYU是一款基于python的控制器,你可用Ryu实现各种想要实现的网络功能,它可以下发或接收流表进行各种路由运算。

  • 建议使用高版本的Ubuntu系统安装ryu,否则会有各种错误,安装过程比较简单,如下:
apt install gcc libffi-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev
pip3 install ryu
  • 安装完成之后查看版本号:
ryu --version

如果正确输出版本信息,则说明安装成功。
.

1.2 使用RYU做mininet的控制器

  • 先启动mininet,设置为远程控制器,配置IP和端口:
sudo mn --controller=remote,ip=127.0.0.1,port=6653

注:从OpenFlow 1.3.3 (EXT-133)版本以后,IANA 分配给 OpenFlow 的端口号是 6653,但有些应用仍然使用6633,所以设置监听端口为6653和6633都行

  • 进入ryu/ryu/app目录,然后启动相应模块,
ryu-manager --verbose simple_switch_13.py ofctl_rest.py rest_topology.py

simple_switch_13.py模块是一个简单的交换机,是openflow1.3的交换机。后面的两个文件是为了进行restapi的调用加载的,方便直接用浏览器查看。

在浏览器中调用ryu的api

  • 得到某台交换机状态信息

http://127.0.0.1:8080/stats/desc/1

{"1":(DPID) {"dp_desc": "None",(datapath的描述信息)"sw_desc": "2.0.2",(软件机的描述信息)"hw_desc": "Open vSwitch",(交换机描述信息)"serial_num": "None",(序列号)"mfr_desc": "Nicira, Inc."(生产商信息)}
}
  • 查看交换机当前的流表:

http://127.0.0.1:8080/stats/flow/1

"1": [{"actions": [ "OUTPUT:3" ],(动作,转发到3 号端口)"idle_timeout": 0,(空闲后存活时间)"cookie": 0,"packet_count": 2,(包计数)"hard_timeout": 0,(存活时间)"byte_count": 140,(比特计数)"duration_nsec": 111000000,"priority": 32768,(优先级)"duration_sec": 985,(已经存活时间)"table_id": 0,(在流表1)"match": (匹配字段){"dl_dst": "02:28:7c:93:27:af",(过滤目的地址为02:28:7c:93:27:af的包,就是去主机3的包)"in_port": 2(从2号端口进入)}(作用:从2号端口进入,要到h3主机的报文都从3号端口转发)}
  • 查询指定交换机上所有流表的统计信息

    http://127.0.0.1:8080/stats/table/1

  • 得到端口的统计信息

    http://127.0.0.1:8080/stats/port/1/1

  • 得到端口配置信息:

    http://127.0.0.1:8080/stats/portdesc/1

在浏览器中除了可以查询流表信息外,还可以对流表进行操作,但需要支持构造post、delete等请求的浏览器插件,如httprequester、restclient等,具体操作如下:

获取交换机流表

# 获取交换机列表
GET /stats/switches# 获取某台交换机的设备信息
GET /stats/desc/<dpid># get flows desc stats of the switch
GET /stats/flowdesc/<dpid># get flows desc stats of the switch filtered by the fields
POST /stats/flowdesc/<dpid># 得到指定交换机的所有flow的状态信息
GET /stats/flow/<dpid># 有条件地查询某台交换机的流表
POST /stats/flow/<dpid># 查询指定交换机的全局统计流表的字段
GET /stats/aggregateflow/<dpid># 有条件的查询指定交换机的全局统计流表的字段
POST /stats/aggregateflow/<dpid>#  查询指定交换机上所有流表的统计信息
GET /stats/table/<dpid># get table features stats of the switch
GET /stats/tablefeatures/<dpid># 得到端口的统计信息
GET /stats/port/<dpid>[/<port>]
# Note: Specification of port number is optional# get queues stats of the switch
GET /stats/queue/<dpid>[/<port>[/<queue_id>]]
# Note: Specification of port number and queue id are optional
#       If you want to omitting the port number and setting the queue id,
#       please specify the keyword "ALL" to the port number
#       e.g. GET /stats/queue/1/ALL/1# get queues config stats of the switch
GET /stats/queueconfig/<dpid>[/<port>]
# Note: Specification of port number is optional# get queues desc stats of the switch
GET /stats/queuedesc/<dpid>[/<port>[/<queue_id>]]
# Note: Specification of port number and queue id are optional
#       If you want to omitting the port number and setting the queue id,
#       please specify the keyword "ALL" to the port number
#       e.g. GET /stats/queuedesc/1/ALL/1# get meter features stats of the switch
GET /stats/meterfeatures/<dpid># get meter config stats of the switch
GET /stats/meterconfig/<dpid>[/<meter_id>]
# Note: Specification of meter id is optional# get meter desc stats of the switch
GET /stats/meterdesc/<dpid>[/<meter_id>]
# Note: Specification of meter id is optional# get meters stats of the switch
GET /stats/meter/<dpid>[/<meter_id>]
# Note: Specification of meter id is optional# get group features stats of the switch
GET /stats/groupfeatures/<dpid># get groups desc stats of the switch
GET /stats/groupdesc/<dpid>[/<group_id>]
# Note: Specification of group id is optional (OpenFlow 1.5 or later)# get groups stats of the switch
GET /stats/group/<dpid>[/<group_id>]
# Note: Specification of group id is optional# get ports description of the switch
GET /stats/portdesc/<dpid>[/<port_no>]
# Note: Specification of port number is optional (OpenFlow 1.5 or later)

更新交换机流表项

# 添加流表项
POST /stats/flowentry/add# 修改所有匹配的流表项
POST /stats/flowentry/modify# modify flow entry strictly matching wildcards and priority
POST /stats/flowentry/modify_strict# delete all matching flow entries
POST /stats/flowentry/delete# delete flow entry strictly matching wildcards and priority
POST /stats/flowentry/delete_strict# delete all flow entries of the switch
DELETE /stats/flowentry/clear/<dpid># add a meter entry
POST /stats/meterentry/add# modify a meter entry
POST /stats/meterentry/modify# delete a meter entry
POST /stats/meterentry/delete# add a group entry
POST /stats/groupentry/add# modify a group entry
POST /stats/groupentry/modify# delete a group entry
POST /stats/groupentry/delete# modify behavior of the physical port
POST /stats/portdesc/modify# modify role of controller
POST /stats/role# send a experimeter message
POST /stats/experimenter/<dpid>

具体操作方法见RYU实战,REST API流表控制1,RYU实战,REST API流表控制2
.

2.3 网络拓扑的可视化

Ryu自带了网络拓扑可视化的app,名称为gui_topology.py,在ryu/ryu/app/gui_topology/gui_topology.py下。使用方法同其他的app,可以和其他app一起运行。同样进入ryu/ryu/app/目录,运行:

ryu-manager gui_topology/gui_topology.py

启动成功后,将交换机连接到Ryu,用浏览器访问ryu运行的主机ip:8080即可看到当前的网络拓扑,一般是http://localhost:8080。

但这样只能看到所有的交换机,但看不到它们之间的连接,启动ryu时加上
–observe-links参数,就可以看到交换机之间的连接,即:

ryu-manager gui_topology/gui_topology.py --observe-links

不仅有交换机,他们之间的连接也都显示出来了。同时,在这个界面,我们还可以点击某个交换机来查看当中的流表项。

这样做的一个问题是,带上–observe-links启动ryu之后,Ryu会收到非常大量的包含LLDP协议报文的PacketIn消息,如果不对这一PacketIn消息进行特殊处理的话,很容易导致Ryu奔溃,无法正常工作!为了避免这一问题,当使用–observe-links启动Ryu时,在你处理PacketIn消息的函数开头,建议包含如下代码,即可解决问题:

 if eth.ethertype == ether_types.ETH_TYPE_LLDP:# ignore lldp packetreturn

本节内容转自Ryu网络拓扑可视化app使用简介,具体可参考原博客。

RYU+mininet——RYU相关推荐

  1. 基本中型网络的仿真(RYU+Mininet的SDN架构)-以校园为例

    目录 ​​​​​​​具体问题可以私聊博主 一.设计目标 1.1应用场景介绍 1.2应用场景设计要求 网络配置方式 网络技术要求 网络拓扑要求 互联互通 二.课程设计内容与原理 (1)预期网络拓扑结构和 ...

  2. RYU+Mininet的SDN架构-设计校园网络(三)

    这是基于RYU+Mininet的SDN架构设计仿真校园网络的第一部分 总体详见:[基本中型网络的仿真(RYU+Mininet的SDN架构)-以校园为例]​​​​​​ 章节: [RYU+Mininet的 ...

  3. RYU+Mininet的SDN架构-设计校园网络(四)

    这是基于RYU+Mininet的SDN架构设计仿真校园网络的第四部分 总体详见:[基本中型网络的仿真(RYU+Mininet的SDN架构)-以校园为例]​​​​​​ 上一章:[RYU+Mininet的 ...

  4. RYU+Mininet实现Hub泛洪

    RYU+Mininet实现Hub泛洪 系统:Ubuntu20.10 ,已安装 ryu 和 mininet 在ryu/ryu/app下创建了文件hub.py,代码如下: hub.py(含注释) from ...

  5. RYU+Mininet的SDN架构-设计校园网络(五)

    这是整个项目的代码部分,对大家来说都很重要 总体详见:[基本中型网络的仿真(RYU+Mininet的SDN架构)-以校园为例]​​​​​​ 章:[RYU+Mininet的SDN架构-设计校园网络(一) ...

  6. RYU+Mininet的SDN架构-设计校园网络(一)

    这是基于RYU+Mininet的SDN架构设计仿真校园网络的第一部分 总体详见:[基本中型网络的仿真(RYU+Mininet的SDN架构)-以校园为例] 前言: 本次设计基于虚拟机以及Ubuntu18 ...

  7. The Road to Ryu: Hi Ryu

    参考: ryu入门教程 ryu ryu/ryu Structure -ryu/ryuappbasecmdcontribcontrollerlibofprotoservicesteststopology ...

  8. 利用mininet模拟SDN架构并进行DDoS攻击与防御模拟(Ryu+mininet+sflow+postman)

    1.知识概述 (1)软件定义网络: (2)mininet: Mininet是一个强大的网络仿真平台,通过这个平台,我们可以很方便的模拟真实环境中的网络操作与架构.特别是SDN,在真实网络中进行相关的网 ...

  9. Ubuntu18.04 安装SDN ryu+mininet

    一.安装Mininet apt-get install git 这是最好的方式.git下载方式安装容易出错. 二.安装并测试Ryu控制器 1.安装并更新pip sudo apt-get update ...

最新文章

  1. oracle中显示周,oracle中得到一段时间内天,月,周列表
  2. NEW关键字的三种用法
  3. Ubuntu系统环境变量配置文件(转)
  4. 喜欢产品小师妹?你必须知道的一点产品知识,竞品分析:流利说雅思
  5. 警惕python中的*重复符(运算符)
  6. php apache win7,win7安装apache+php
  7. Python进制转换(利用栈)
  8. java post加密_使用Java和PHP的BCrypt,发送加密的密码并对其进行解码 - java
  9. 东莞理工学院计算机学院论文,东莞理工学院本科生毕业设计(论文)重复率检测实施办法(试行)...
  10. IOS最新新浪微博开放平台Oauth2.0授权获取Access_Token
  11. 代码检查工具!从 TSLint 到 ESLint
  12. android微信摇一摇(抽奖)
  13. 未来已来 云上安全SaaS化势不可挡
  14. ps 利用马赛克滤镜制作方格背景
  15. android 酷狗demo_在Android上使用酷狗歌词API
  16. 计算机网络与多媒体技术内容,计算机网络多媒体技术应用
  17. 海康、大华网络摄像机RTSP流接入流媒体实现WEB无插件直播通过视频广场观看实时直播
  18. MoviePy - 中文文档4-MoviePy实战案例-重新构建15世纪舞蹈视频
  19. 我们常说祖宗十八代,到底是哪十八代?这个称呼又是怎么来的?
  20. 利用vs将cs文件编译成dll文件

热门文章

  1. Linux命令——修改root密码
  2. 谈谈Eureka的自我保护模式
  3. 项目奖金要不要与合同额直接相关?
  4. 新手怎样学好SEO搜索引擎优化
  5. 什么是继承python_面向对象继承
  6. [Kubic] Lines
  7. 谷歌验证码recaptcha接入
  8. k-means聚类算法——c语言
  9. linux安装TBase v2.5
  10. steam无法连接到更新服务器的问题