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.


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



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


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.


    '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.


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.


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.


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.

Usage Example:

# ...(snip)...
from ryu.controller import dpset

class MyApp(app_manager.RyuApp):
    _CONTEXTS = {
        'dpset': dpset.DPSet,

    def __init__(self, *args, **kwargs):
        super(MyApp, self).__init__(*args, **kwargs)
        # Stores DPSet instance to call its API in this app
        self.dpset = kwargs['dpset']

    def _my_handler(self):
        # Get the datapath object which has the given dpid
        dpid = 1
        dp = self.dpset.get(dpid)
        if dp is None:
            self.logger.info('No such datapath: dpid=%d', dpid)

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


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.


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.