SDN ryu.app.ofctl_rest操作实践

发布时间 2023-06-08 20:37:20作者: 幻非

安装 Postman

启动 Ryu 控制器

切换到自己的 ryu 目录

cd /home/ubuntu/ryu/ryu/app
sudo ryu-manager simple_switch.py

再开一个终端

cd /home/ubuntu/ryu/ryu/app
sudo ryu-manager ofctl_rest.py

如果遇到端口报错

image

扫一下接口 kill 掉

sudo lsof -i :6633
sudo lsof -i :6653

image

启动 Mininet

切换到自己的 Mininet 目录

cd /usr/share/doc/mininet/examples/
python miniedit.py 

如果报这个错,请不要用 SSH 连接,请使用系统自带的终端

image

按图操作

image

image

image

image

image

python sd6.py

Postman 操作

打开 Postman ,GET http://192.168.1.50:8080/stats/switches 链接

image

GET http://192.168.1.50:8080/stats/flow/1

image

GET http://192.168.1.50:8080/stats/flow/2

image

终端内输入 dpctl dump-flows

image

添加 S1

POST http://192.168.1.50:8080/stats/flowentry/add body 内填下面的 json 数据

{
    "dpid": 1,
    "priority": 11111,
    "flags": 1,
    "match": {
        "in_port": 1
    },
    "actions": [
        {
            "type": "OUTPUT",
            "port": 2
        },
    ]
}

image

在终端内再次输入 dpctl dump-flows 查看流表

image

输入 pingall 查看联通情况

image

再次 POST http://192.168.1.50:8080/stats/flowentry/add

{
    "dpid": 1,
    "priority": 11111,
    "flags": 1,
    "match": {
        "in_port": 2
    },
    "actions": [
        {
            "type": "OUTPUT",
            "port": 1
        },
    ]
}

image

再次输入 dpctl dump-flows 查看流表

image

S1 共添加 2 条流表

添加 S2

再次 POST http://192.168.1.50:8080/stats/flowentry/add

{
    "dpid": 2,
    "priority": 11111,
    "flags": 1,
    "match": {
        "in_port": 1
    },
    "actions": [
        {
            "type": "OUTPUT",
            "port": 2
        },
        {
            "type": "OUTPUT",
            "port": 3
        },
    ]
}

image

再次输入 dpctl dump-flows 查看流表

image

再次 POST http://192.168.1.50:8080/stats/flowentry/add

{
    "dpid": 2,
    "priority": 11111,
    "flags": 1,
    "match": {
        "in_port": 2
    },
    "actions": [
        {
            "type": "OUTPUT",
            "port": 1
        },
        {
            "type": "OUTPUT",
            "port": 3
        },
    ]
}

image

再次 POST http://192.168.1.50:8080/stats/flowentry/add

{
    "dpid": 2,
    "priority": 11111,
    "flags": 1,
    "match": {
        "in_port": 3
    },
    "actions": [
        {
            "type": "OUTPUT",
            "port": 1
        },
        {
            "type": "OUTPUT",
            "port": 2
        },
    ]
}

image

image

S2 共添加 3 条流表

执行 pingall

image

清空 S2

清空 Body

向下面两条连接发送 delete 请求

http://192.168.1.50:8080/stats/flowentry/clear/1
http://192.168.1.50:8080/stats/flowentry/clear/2

image

输入 dpctl dump-flows 查看流表

image