Ryu API Reference

class ryu.base.app_manager.RyuApp(*_args, **_kwargs)

The base class for Ryu applications.

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 instance attribute ‘name’ is 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 for subclasses to override this.

OFP_VERSIONS = None

A list of supported OpenFlow versions for this RyuApp. The default is all versions supported by the framework.

Examples:

OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION,
                ofproto_v1_2.OFP_VERSION]

If multiple Ryu applications are loaded in the system, the intersection of their OFP_VERSIONS is used.

_CONTEXTS = {}

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.

Example:

_CONTEXTS = {
    'network': network.Network
}

def __init__(self, *args, *kwargs):
    self.network = kwargs['network']
_EVENTS = []

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.

close()

teardown method. The method name, close, is chosen for python context manager

classmethod context_iteritems()

Return iterator over the (key, contxt class) of application context

reply_to_request(req, rep)

Send a reply for a synchronous request sent by send_request. The first argument should be an instance of EventRequestBase. The second argument should be an instance of EventReplyBase.

send_event(name, ev, state=None)

Send the specified event to the RyuApp instance specified by name.

send_event_to_observers(ev, state=None)

Send the specified event to all observers of this RyuApp.

send_request(req)

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.

start()

Hook that is called after startup initialization is done.

class ryu.controller.dpset.DPSet(*args, **kwargs)

DPSet application manages a set of switches (datapaths) connected to this controller.

get(dp_id)

This method returns the ryu.controller.controller.Datapath instance for the given Datapath ID.

get_all()

This method returns a list of tuples which represents instances for switches connected to this controller. The tuple consists of a Datapath Id and an instance of ryu.controller.controller.Datapath. A return value looks like the following:

[ (dpid_A, Datapath_A), (dpid_B, Datapath_B), ... ]
get_port(dpid, port_no)

This method returns the ryu.controller.dpset.PortState instance for the given Datapath ID and the port number. Raises ryu_exc.PortNotFound if no such a datapath connected to this controller or no such a port exists.

get_ports(dpid)

This method returns a list of ryu.controller.dpset.PortState instances for the given Datapath ID. Raises KeyError if no such a datapath connected to this controller.