-
Notifications
You must be signed in to change notification settings - Fork 0
Each Ryu application is single-threaded.
Ryu applications send asynchronous messages called events each other. Besides that, there are some Ryu-internal event sources which are not 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 keep draining the receive queue by dequeueing an event and calling 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 for blocking. I.e. while an event handler is blocked, no events for the Ryu application will be processed. While synchronous requests uses the same machinary as ordinary events, their replies use another queue dedicated to replies to avoid deadlock. (Because, unlike erlang, our queue doesn't have selective receive.) It's assumed that the number of in-flight synchronous requests from a Ryu application is at most 1.
While threads and queues is currently implemented with gevent/greenlet, a direct use of them in a Ryu application is strongly discouraged.
Contexts are ordinary python objects shared among Ryu applications. The use of contexts are discouraged for new code.
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.
A Ryu application can register itself to listen for specific events using ryu.controller.handler.set_ev_cls decorator.
A Ryu application can raise events using RyuApp.send_event or RyuApp.send_event_to_observers method.
Event classes describes Ryu event generated in the system. By convention, event class names are prefixed by "Event". Events are generateed 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 decorated by ryu.controller.handler.set_ev_cls decorator.
ryu.controller.ofp_event module exports event classes which describes receptions of OpenFlow messages from connected switches. By convention, they are named as 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 set_ev_cls. OpenFlow event classes have at least the following attributes.
An object which describes the corresponding OpenFlow message.
A ryu.controller.controller.Datapath instance which describes an OpenFlow switch from which we receive this OpenFlow message.
The msg object has some more additional members whose values are extracted from the original OpenFlow message. For example, OFPPacketIn has the following attributes.
- msg.buffer_id
- msg.total_len
- msg.in_port
- msg.in_reason
- msg.data
A base class for synchronous request for RyuApp.send_request.
A base class for synchronous request reply for RyuApp.send_reply.
The base class for Ryu applications.
A RyuApp subclass can have class attributes with the following special names, which are recognized by app_manager.
A dictionary to specify contexts which this Ryu application wants to use. Its key is a name of context and its value is an ordinary class which implements the context. The class is instantiated by app_manager and the instance is shared among RyuApp subclasses which has _CONTEXTS member with the same key. A RyuApp subclass can obtain a reference to the instance via its __init__'s kwargs as the following.
_CONTEXTS = {
'network': network.Network
}
def __init__(self, *args, *kwargs):
self.network = kwargs['network']
A list of event classes which this RyuApp subclass would generate. This should be specified if and only if event classes are defined in a different python module from the RyuApp subclass is.
A list of supported OpenFlow versions for this RyuApp. For example:
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION,
ofproto_v1_2.OFP_VERSION]
A RyuApp instance provides the following attributes.
RyuApp subclasses are instantiated after ryu-manager loaded all requested Ryu application modules. __init__ should call RyuApp.init with the same arguments. It's illegal to send any events in __init__.
The name of the class used for message routing among Ryu applications. (Cf. send_event) It's set to class.name by RyuApp.init. It's discouraged to override this value.
Make a synchronous request. Set req.sync to True, send it to a Ryu application specified by req.dst, and block until receiving a reply. Returns the received reply. The argument should be an instance of EventRequestBase.
Send a reply for a synchronous request sent by send_request. The argument should be an instance of EventReplyBase.
Send the specified event to the RyuApp instance specified by name. name is a name of the RyuApp subclass. (in the sense of class.name)
Send the specified event to all observers of this RyuApp.
A decorator for Ryu application to declare an event handler. Decorated method will become an event handler. ev_cls is an event class whose instances this RyuApp wants to receive. dispatchers argument specifies one of the following negotiation phases (or a list of them) for which events should be generated for this handler.
Negotiation phase | Description |
---|---|
ryu.controller.handler.HANDSHAKE_DISPATCHER | Sending and waiting for hello message |
ryu.controller.handler.CONFIG_DISPATCHER | Version negotiated and sent features-request message |
ryu.controller.handler.MAIN_DISPATCHER | Switch-features message received and sent set-config message |
A class to describe an OpenFlow switch connected to this controller. An instance has the following attributes.
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.
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.
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.
Generate an OpenFlow XID and put it in msg.xid.
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.
deprecated
deprecated
deprecated
deprecated
Queue an OpenFlow barrier message to send to the switch.
deprecated
deprecated