mininet+RYU环境安装

安装mininet


apt-get install mininet

运行mininet


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
root@controller-VirtualBox:~# mn

*** No default OpenFlow controller found for default switch!

*** Falling back to OVS Bridge

*** Creating network

*** Adding controller

*** Adding hosts:

h1 h2

*** Adding switches:

s1

*** Adding links:

(h1, s1) (h2, s1)

*** Configuring hosts

h1 h2

*** Starting controller



*** Starting 1 switches

s1 ...

*** Starting CLI:

mininet> nodes

available nodes are:

h1 h2 s1

mininet> net

h1 h1-eth0:s1-eth1

h2 h2-eth0:s1-eth2

s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0

mininet> dump

<Host h1: h1-eth0:10.0.0.1 pid=1961>

<Host h2: h2-eth0:10.0.0.2 pid=1963>

<OVSBridge s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=1968>

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=1.81 ms

64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.072 ms

^C

--- 10.0.0.2 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1002ms

rtt min/avg/max/mdev = 0.072/0.942/1.812/0.870 ms

mininet>

ryu1

下载安装RYU


1
2
3
4
git clone git://github.com/osrg/ryu.git
cd ryu
sudo pip install -r tools/pip-requires
sudo python setup.py install

开启默认mininet环境,启动controller控制ip和端口

mn –controller remote,ip=127.0.0.1,port=6633

执行外上述命令后,在一个窗口执行ovs-vsctl show 命令,查看配置情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@controller-VirtualBox:~/ryu# ovs-vsctl show
73065536-d00b-440c-a02f-b8d33ef05ee1
Bridge "s1"
Controller "ptcp:6634"
Controller "tcp:127.0.0.1:6633"
fail_mode: secure
Port "s1"
Interface "s1"
type: internal
Port "s1-eth1"
Interface "s1-eth1"
Port "s1-eth2"
Interface "s1-eth2"
ovs_version: "2.5.2"
root@controller-VirtualBox:~/ryu#

如上显示,controller控制ip:port信息如上,默认mininet环境启动了两个客户端分别通过s1-eth1和s1-eth2接入到ovs s1上,二层相连

未执行任何ping动作时候查查看默认流表

root@controller-VirtualBox:~/ryu# ovs-ofctl dump-flows s1 -O openflow13

OFPST_FLOW reply (OF1.3) (xid=0x2):

开启simple_switch_13.py RYU控制器demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
root@controller-VirtualBox:/usr/local/lib/python2.7/dist-packages/ryu/app#  ryu-manager --verbose simple_switch_13.py 
loading app simple_switch_13.py
loading app ryu.controller.ofp_handler
instantiating app simple_switch_13.py of SimpleSwitch13
instantiating app ryu.controller.ofp_handler of OFPHandler
BRICK SimpleSwitch13
CONSUMES EventOFPPacketIn
CONSUMES EventOFPSwitchFeatures
BRICK ofp_event
PROVIDES EventOFPPacketIn TO {'SimpleSwitch13': set(['main'])}
PROVIDES EventOFPSwitchFeatures TO {'SimpleSwitch13': set(['config'])}
CONSUMES EventOFPPortStatus
CONSUMES EventOFPSwitchFeatures
CONSUMES EventOFPHello
CONSUMES EventOFPErrorMsg
CONSUMES EventOFPEchoRequest
CONSUMES EventOFPPortDescStatsReply
CONSUMES EventOFPEchoReply

connected socket:<eventlet.greenio.base.GreenSocket object at 0x7fcef67e5cd0> address:('127.0.0.1', 53604)
hello ev <ryu.controller.ofp_event.EventOFPHello object at 0x7fcef67e56d0>
move onto config mode
EVENT ofp_event->SimpleSwitch13 EventOFPSwitchFeatures
switch features ev version=0x4,msg_type=0x6,msg_len=0x20,xid=0xc20757d2,OFPSwitchFeatures(auxiliary_id=0,capabilities=79,datapath_id=1,n_buffers=256,n_tables=254)
move onto main mode
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 82:06:4f:42:09:6c 33:33:00:00:00:02 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 82:06:4f:42:09:6c ff:ff:ff:ff:ff:ff 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 76:db:0f:62:67:5e 82:06:4f:42:09:6c 2
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 82:06:4f:42:09:6c 76:db:0f:62:67:5e 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 76:db:0f:62:67:5e 33:33:00:00:00:02 2
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 82:06:4f:42:09:6c 33:33:00:00:00:02 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 76:db:0f:62:67:5e 33:33:00:00:00:02 2

开启完simple_switch_13.py 后查看流表项,经过s1所有的流量都会通过127.0.0.1:6633发给控制器,交给simple_switch_13.py 处理

root@controller-VirtualBox:~/ryu# ovs-ofctl dump-flows s1 -O openflow13

OFPST_FLOW reply (OF1.3) (xid=0x2):

cookie=0x0, duration=2.782s, table=0, n_packets=0, n_bytes=0, priority=0 actions=CONTROLLER:65535

h1 ping h2,流表新增两条

1
2
3
4
5
6
7
8
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=6.59 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.228 ms
^C
--- 10.0.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.228/3.412/6.597/3.185 ms
1
2
3
4
5
root@controller-VirtualBox:~/ryu# ovs-ofctl dump-flows s1 -O openflow13
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x0, duration=12.970s, table=0, n_packets=4, n_bytes=280, priority=1,in_port=2,dl_dst=0a:30:ba:ff:9b:80 actions=output:1
cookie=0x0, duration=12.967s, table=0, n_packets=3, n_bytes=238, priority=1,in_port=1,dl_dst=ee:78:58:36:2b:06 actions=output:2
cookie=0x0, duration=224.026s, table=0, n_packets=5, n_bytes=322, priority=0 actions=CONTROLLER:65535
1
2
3
4
5
6
7
8
9
10
11
12
packet in 1 ee:78:58:36:2b:06 33:33:00:00:00:02 2
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn

packet in 1 0a:30:ba:ff:9b:80 ff:ff:ff:ff:ff:ff 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn

packet in 1 ee:78:58:36:2b:06 0a:30:ba:ff:9b:80 2
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn

packet in 1 0a:30:ba:ff:9b:80 ee:78:58:36:2b:06 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 0a:30:ba:ff:9b:80 33:33:00:00:00:02 1

通过rest api查找相关信息

1
进入:/usr/local/lib/python2.7/dist-packages/ryu/app

ryu-manager –verbose simple_switch_13.py ofctl_rest.py rest_topology.py

rest-api查看ovs流表

ryu2