参考:
ryu/ryu Structure
-ryu/ryu
app
base
cmd
contrib
controller
lib
ofproto
services
tests
topology
ryu/ryu/app
基于ryu控制器开发的app,内含ryu的图形界面、北向防火墙、北向QoS、简易L2交换机、L3路由器等。
ryu/ryu/base
内含app_manager.py脚本,用于加载ryu应用程序,接受从APP发送过来的信息,同时也完成消息的路由。
定义了两大基类:RyuApp和AppManager。RyuApp定义了App的基本属性,AppManager则定义了用于管理多个App的方法和属性。
ryu/ryu/controller
该文件夹中含有许多关键的ryu源码文件,这里提一下controller.py,该文件中含有两个十分重要的类:
class OpenFlowController(object)
class Datapath(ofproto_protocol.ProtocolDesc)
其中类OpenFlowController定义了构建一个控制器的基本方法和属性,DataPath是用于描述OpenFlow控制器和交换机是如何连接的类:
A class to describe an OpenFlow switch connected to this controller.
An instance has the following attributes.
.. tabularcolumns:: |l|L|
==================================== ======================================
Attribute Description
==================================== ======================================
id 64-bit OpenFlow Datapath ID.
Only available for
ryu.controller.handler.MAIN_DISPATCHER
phase.
ofproto A module which exports OpenFlow
definitions, mainly constants appeared
in the specification, for the
negotiated OpenFlow version. For
example, ryu.ofproto.ofproto_v1_0 for
OpenFlow 1.0.
ofproto_parser A module which exports OpenFlow wire
message encoder and decoder for the
negotiated OpenFlow version.
For example,
ryu.ofproto.ofproto_v1_0_parser
for OpenFlow 1.0.
ofproto_parser.OFPxxxx(datapath,...) A callable to prepare an OpenFlow
message for the given switch. It can
be sent with Datapath.send_msg later.
xxxx is a name of the message. For
example OFPFlowMod for flow-mod
message. Arguemnts depend on the
message.
set_xid(self, msg) Generate an OpenFlow XID and put it
in msg.xid.
send_msg(self, msg) Queue an OpenFlow message to send to
the corresponding switch. If msg.xid
is None, set_xid is automatically
called on the message before queueing.
send_packet_out deprecated
send_flow_mod deprecated
send_flow_del deprecated
send_delete_all_flows deprecated
send_barrier Queue an OpenFlow barrier message to
send to the switch.
send_nxt_set_flow_format deprecated
is_reserved_port deprecated
==================================== ======================================
ryu/ryu/cmd
定义了ryu的命令系统。
ryu/ryu/contrib
社区贡献者的代码。
ryu/ryu/lib
该目录下定义了一些数据报的格式和数据结构,及诸多网络协议。
ryu/ryu/ofproto
该目录下的文件分为两类,一类定义协议的数据结构,另外一类用于协议报文解析。
ryu/ryu/services
完成了bgp、vrrp协议及ovsdb的实现。
ryu/ryu/tests
用于测试。
ryu/ryu/topology
定义了自定义拓扑文件中需要的一些模块和方法,其中的关键文件是switches.py,完成了对一整套交换机处理流程的定义。
Hi Ryu
Env:
Mac OS X.
0.pre:
python-eventlet
python-routes
python-webob
python-paramiko
1.install it:
git clone git://github.com/osrg/ryu.git
cd ryu
sudo pip3 install -r tools/pip-requires
sudo python setup.py install
2.执行:
ryu-manager simple_switch.py
2017/2/29