OS-Ken API Reference¶
-
class
os_ken.base.app_manager.
OSKenApp
(*_args, **_kwargs)¶ The base class for OSKen applications.
OSKenApp subclasses are instantiated after osken-manager loaded all requested OSKen application modules. __init__ should call OSKenApp.__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 OSKen applications. (Cf. send_event) It's set to __class__.__name__ by OSKenApp.__init__. It's discouraged for subclasses to override this.
-
OFP_VERSIONS
= None¶ A list of supported OpenFlow versions for this OSKenApp. The default is all versions supported by the framework.
Examples:
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION, ofproto_v1_2.OFP_VERSION]
If multiple OSKen applications are loaded in the system, the intersection of their OFP_VERSIONS is used.
-
_CONTEXTS
= {}¶ A dictionary to specify contexts which this OSKen 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 OSKenApp subclasses which has _CONTEXTS member with the same key. A OSKenApp 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 OSKenApp subclass would generate. This should be specified if and only if event classes are defined in a different python module from the OSKenApp 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 OSKenApp instance specified by name.
-
send_event_to_observers
(ev, state=None)¶ Send the specified event to all observers of this OSKenApp.
-
send_request
(req)¶ Make a synchronous request. Set req.sync to True, send it to a OSKen 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
os_ken.controller.dpset.
DPSet
(*args, **kwargs)¶ DPSet application manages a set of switches (datapaths) connected to this controller.
Usage Example:
# ...(snip)... from os_ken.controller import dpset class MyApp(app_manager.OSKenApp): _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)
-
get
(dp_id)¶ This method returns the os_ken.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 os_ken.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 os_ken.controller.dpset.PortState instance for the given Datapath ID and the port number. Raises os_ken_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 os_ken.controller.dpset.PortState instances for the given Datapath ID. Raises KeyError if no such a datapath connected to this controller.
-