RYU连接ovs方法举例

基本概念介绍

执行mn命令后,主机监听6633和6634端口


1
2
3
4
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6633 0.0.0.0:* LISTEN 23871/controller
tcp 0 0 0.0.0.0:6634 0.0.0.0:* LISTEN 1131/ovs-vswitchd

命令执行记录如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@controller-VirtualBox:~# mn
*** 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>

端口6633 是ovs连接的控制器端口,且该端口是mn自己启动的

端口6634是被动连接端口

1
2
3
4
5
6
7
8
9
10
11
12
13
Bridge "s1"
Controller "tcp:127.0.0.1:6633"
is_connected: true
Controller "ptcp:6634"
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"

端口6634是ovs-vswitchd监听端口是被动连接管理的端口

所谓的被动连接端口是指,控制器可以主动连接此端口,控制此ovs,下面就是设置被动端口的 方式

ovs-vsctl set-controller s1 ptcp:8888

特别说明:相对应被动端口,主动端口(ovs主动连接并和控制器通信的端口)设置方式如下:

ovs-vsctl set-controller s1 tcp:127.0.0.1:8887

主动连接本地控制器127.0.0.1:8887端口

主动连接也可以设置多个,设置方法如下

通过通信数据包得知,该ovs会和本地控制器6636和6637通信,如果有packet in事件时候会将该事件分别发一份给这两个控制器,至于两个控制器间的关系协作暂无研究。

ovs-vsctl set-controller s1 tcp:127.0.0.1:6636 tcp:127.0.0.1:6637

1
2
3
4
5
6
7
8
9
10
11
12
Bridge "s1"
Controller "tcp:127.0.0.1:6637"
Controller "tcp:127.0.0.1:6636"
fail_mode: secure
Port "s1-eth1"
Interface "s1-eth1"
Port "s1-eth2"
Interface "s1-eth2"
Port "s1"
Interface "s1"
type: internal
ovs_version: "2.5.2"

RYU控制器连接ovs步骤


  • 设置ovs s1 主动连接6666端口

ovs-vsctl set-controller s1 tcp:127.0.0.1:6666

  • 设置RYU启动服务端口6666

root@controller-VirtualBox:/usr/local/lib/python2.7/dist-packages/ryu/app# ryu-manager –ofp-tcp-listen-port 6666 –verbose simple_switch_13.py

1
tcp        0      0 0.0.0.0:6666            0.0.0.0:*               LISTEN      24665/python

通过上述设置ovs连接本机127.0.0.1:6666端口走openflow协议连接控制器simple_switch_13.py