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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
*******************
Ryu application API
*******************
Ryu application programming model
=================================
Threads, events, and event queues
---------------------------------
Ryu applications are single-threaded entities which implement
various functionalities in Ryu. Events are messages between them.
Ryu applications send asynchronous events to each other.
Besides that, there are some Ryu-internal event sources which
are not Ryu applications. One of examples of such event sources
is OpenFlow controller.
While an event can currently contain arbitrary python objects,
it's discouraged to pass complex objects (eg. unpickleable objects)
between Ryu applications.
Each Ryu application has a receive queue for events.
The queue is FIFO and preserves the order of events.
Each Ryu application has a thread for event processing.
The thread keeps draining the receive queue by dequeueing an event
and calling the appropritate event handler for the event type.
Because the event handler is called in the context of
the event processing thread, it should be careful when blocking.
While an event handler is blocked, no further events for
the Ryu application will be processed.
There are kinds of events which are used to implement synchronous
inter-application calls between Ryu applications.
While such requests uses the same machinary as ordinary
events, their replies are put on a queue dedicated to the transaction
to avoid deadlock.
While threads and queues is currently implemented with eventlet/greenlet,
a direct use of them in a Ryu application is strongly discouraged.
Contexts
--------
Contexts are ordinary python objects shared among Ryu applications.
The use of contexts are discouraged for new code.
Create a Ryu application
========================
A Ryu application is a python module which defines a subclass of
ryu.base.app_manager.RyuApp.
If two or more such classes are defined in a module, the first one
(by name order) will be picked by app_manager.
Ryu application is singleton: only single instance of a given Ryu
application is supported.
Observe events
==============
A Ryu application can register itself to listen for specific events
using ryu.controller.handler.set_ev_cls decorator.
Generate events
===============
A Ryu application can raise events by calling appropriate
ryu.base.app_manager.RyuApp's methods like send_event or
send_event_to_observers.
Event classes
=============
An event class describes a Ryu event generated in the system.
By convention, event class names are prefixed by "Event".
Events are generated either by the core part of Ryu or Ryu applications.
A Ryu application can register its interest for a specific type of
event by providing a handler method using
ryu.controller.handler.set_ev_cls decorator.
OpenFlow event classes
----------------------
ryu.controller.ofp_event module exports event classes which describe
receptions of OpenFlow messages from connected switches.
By convention, they are named as ryu.controller.ofp_event.EventOFPxxxx
where xxxx is the name of the corresponding OpenFlow message.
For example, EventOFPPacketIn for packet-in message.
The OpenFlow controller part of Ryu automatically decodes OpenFlow messages
received from switches and send these events to Ryu applications which
expressed an interest using ryu.controller.handler.set_ev_cls.
OpenFlow event classes are subclasses of the following class.
.. autoclass:: ryu.controller.ofp_event.EventOFPMsgBase
See :ref:`ofproto_ref` for more info about OpenFlow messages.
ryu.base.app_manager.RyuApp
===========================
See :ref:`api_ref`.
ryu.controller.handler.set_ev_cls
=================================
.. autofunction:: ryu.controller.handler.set_ev_cls
ryu.controller.controller.Datapath
==================================
.. autoclass:: ryu.controller.controller.Datapath
ryu.controller.event.EventBase
==============================
.. autoclass:: ryu.controller.event.EventBase
ryu.controller.event.EventRequestBase
=====================================
.. autoclass:: ryu.controller.event.EventRequestBase
ryu.controller.event.EventReplyBase
===================================
.. autoclass:: ryu.controller.event.EventReplyBase
ryu.controller.ofp_event.EventOFPStateChange
============================================
.. autoclass:: ryu.controller.ofp_event.EventOFPStateChange
ryu.controller.ofp_event.EventOFPPortStateChange
================================================
.. autoclass:: ryu.controller.ofp_event.EventOFPPortStateChange
ryu.controller.dpset.EventDP
============================
.. autoclass:: ryu.controller.dpset.EventDP
ryu.controller.dpset.EventPortAdd
=================================
.. autoclass:: ryu.controller.dpset.EventPortAdd
ryu.controller.dpset.EventPortDelete
====================================
.. autoclass:: ryu.controller.dpset.EventPortDelete
ryu.controller.dpset.EventPortModify
====================================
.. autoclass:: ryu.controller.dpset.EventPortModify
ryu.controller.network.EventNetworkPort
=======================================
.. autoclass:: ryu.controller.network.EventNetworkPort
ryu.controller.network.EventNetworkDel
======================================
.. autoclass:: ryu.controller.network.EventNetworkDel
ryu.controller.network.EventMacAddress
======================================
.. autoclass:: ryu.controller.network.EventMacAddress
ryu.controller.tunnels.EventTunnelKeyAdd
========================================
.. autoclass:: ryu.controller.tunnels.EventTunnelKeyAdd
ryu.controller.tunnels.EventTunnelKeyDel
========================================
.. autoclass:: ryu.controller.tunnels.EventTunnelKeyDel
ryu.controller.tunnels.EventTunnelPort
======================================
.. autoclass:: ryu.controller.tunnels.EventTunnelPort
|