ryu.app.ofctl

ryu.app.ofctl provides a convenient way to use OpenFlow messages synchronously.

OfctlService ryu application is automatically loaded if your Ryu application imports ofctl.api module.

Example:

import ryu.app.ofctl.api

OfctlService application internally uses OpenFlow barrier messages to ensure message boundaries. As OpenFlow messages are asynchronous and some of messages does not have any replies on success, barriers are necessary for correct error handling.

api module

ryu.app.ofctl.api.get_datapath(app, dpid)

Get datapath object by dpid.

Parameters:
  • app – Client RyuApp instance
  • dpid – Datapath-id (in integer)

Returns None on error.

ryu.app.ofctl.api.send_msg(app, msg, reply_cls=None, reply_multi=False)

Send an OpenFlow message and wait for reply messages.

Parameters:
  • app – Client RyuApp instance
  • msg – An OpenFlow controller-to-switch message to send
  • reply_cls – OpenFlow message class for expected replies. None means no replies are expected. The default is None.
  • reply_multi – True if multipart replies are expected. The default is False.

If no replies, returns None. If reply_multi=False, returns OpenFlow switch-to-controller message. If reply_multi=True, returns a list of OpenFlow switch-to-controller messages.

Raise an exception on error.

Example:

import ryu.app.ofctl.api as api

msg = parser.OFPPortDescStatsRequest(datapath=datapath)
result = api.send_msg(self, msg,
                            reply_cls=parser.OFPPortDescStatsReply,
                            reply_multi=True)

exceptions

exception ryu.app.ofctl.exception.InvalidDatapath(result)

Datapath is invalid.

This can happen when the bridge disconnects.

exception ryu.app.ofctl.exception.OFError(result)

OFPErrorMsg is received.

exception ryu.app.ofctl.exception.UnexpectedMultiReply(result)

Two or more replies are received for reply_muiti=False request.