SDN控制器RYU基本功能验证详解

时间:2022-02-01 01:50:35

1、环境说明

RYU+mininet,分别在2台虚机;RYU 192.168.0.110,mininet 192.168.0.109

2、执行RYU脚本simple_switch.py       

zqg@bogon:~/ryu/ryu/app$ ryu-manager simple_switch.py
loading app simple_switch.py
loading app ryu.controller.ofp_handler
instantiating app simple_switch.py of SimpleSwitch
instantiating app ryu.controller.ofp_handler of OFPHandler

3、在mininet生成模拟交换机s1,主机h1、h2,选择控制器为RYU

mininet@mininet-vm:~$ sudo mn --controller remote,ip=192.168.0.109,port=6633 
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 
*** Adding switches:
s1 
*** Adding links:
(h1, s1) (h2, s1) 
*** Configuring hosts
h1 h2 
*** Starting controller
c0 
*** Starting 1 switches
s1 ...
*** Starting CLI:

可以查看到如下环境信息

mininet@mininet-vm:~$ sudo ovs-vsctl show
0b8ed0aa-67ac-4405-af13-70249a7e8a96
    Bridge "s1"
        Controller "tcp:192.168.0.109:6633"
            is_connected: true
        Controller "ptcp:6634"
        fail_mode: secure
        Port "s1-eth1"
            Interface "s1-eth1"
        Port "s1"
            Interface "s1"
                type: internal
        Port "s1-eth2"
            Interface "s1-eth2"
    ovs_version: "2.0.2"

mininet> h1 ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: h1-eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 9a:51:69:03:1b:4b brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.1/8 brd 10.255.255.255 scope global h1-eth0
       valid_lft forever preferred_lft forever
mininet> 
mininet> 
mininet> h2 ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: h2-eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether d6:05:7b:3b:99:2e brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.2/8 brd 10.255.255.255 scope global h2-eth0
       valid_lft forever preferred_lft forever

mininet> links
h1-eth0<->s1-eth1 (OK OK)
h2-eth0<->s1-eth2 (OK OK)

4、在mininet环境,执行h1 ping h2

mininet> h1 ping h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=54.0 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.256 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.055 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=0.055 ms
64 bytes from 10.0.0.2: icmp_seq=5 ttl=64 time=0.055 ms

h1 ping h2后,控制器打印如下蓝色字体信息         
zqg@bogon:~/ryu/ryu/app$ ryu-manager simple_switch.py
loading app simple_switch.py
loading app ryu.controller.ofp_handler
instantiating app simple_switch.py of SimpleSwitch
instantiating app ryu.controller.ofp_handler of OFPHandler
packet in 1 2e:3f:96:33:67:13 ff:ff:ff:ff:ff:ff 1
packet in 1 fa:a2:b8:bf:5e:b4 2e:3f:96:33:67:13 2
packet in 1 2e:3f:96:33:67:13 fa:a2:b8:bf:5e:b4 1

查看交换机增加如下流表

mininet@mininet-vm:~$ sudo ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=700.092s, table=0, n_packets=13, n_bytes=1218, idle_age=688, in_port=1,dl_dst=d6:05:7b:3b:99:2e actions=output:2
 cookie=0x0, duration=700.099s, table=0, n_packets=14, n_bytes=1316, idle_age=688, in_port=2,dl_dst=9a:51:69:03:1b:4b actions=output:1
mininet@mininet-vm:~$ 

在控制器抓包截图

SDN控制器RYU基本功能验证详解