Ryu控制器教程

发布时间 2023-07-01 11:37:24作者: Eustia_Lv

RYU不要使用apt的方法安装,这样的安装是不完整的, 并且相关文件不易查找。

1.下载ryu源码
cd
cd Desktop
git clone https://gitee.com/lpm-123/ryu

image.png

2.安装RYU环境

安装PIP
cd ryu
pip install -r pip-requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

安装依赖
pip install -r tools/pip-requires -i https://pypi.tuna.tsinghua.edu.cn/simple

安装ryu并配置到环境变量中
sudo python setup.py install

出现最后两行Installing即为成功
image.png

3.开启ryu

开启ryu并启动简单二层交换功能(ryu的app可以在ryu/ryu/app文件夹内找到并自定义)

ryu run ryu.app.simple_switch

image.png

开启mininet并指向远程控制器ryu (需要另外开一个终端,注意不同的人路径可能不同,在输入指令的同时要注意路径是否正确)

sudo mn --topo=tree,fanout=2,depth=2 --controller=remote,ip=127.0.0.1
sudo mn --custom ./123123.py --topo=mytopo --controller=remote,ip=127.0.0.1

开启后在mininet内进行pingall,全部连通,且ryu中有packet说明连接成功。
image.png

4.Ryu的REST API

ryu运行正常之后,通过加载ryu.app.ofctl_rest等app,可以使用ryu的该app提供的api进行一些数据的获取,具体api可以到官网的docs里去寻找。(不同的app有不同的api,app文件夹下的py文件中带有rest字样的都有api,打开py文件也能看到使用方法)
https://ryu.readthedocs.io/en/stable/app/ofctl_rest.html?
image.png
GET即为API地址,GET方法可以用浏览器直接访问,返回结果为JSON或者List格式。