diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-01-15 13:51:01 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-01-17 08:46:52 +0900 |
commit | 37c73db7b1b1c98bd000d4f813423702d73a0c8c (patch) | |
tree | e627e15ebdfd568daa8e682c8f1316209580c6ac | |
parent | 81cdd4f0d76952c16d6e65e6af8da82702175220 (diff) |
confroller/dpset: Add usage example of instantiation
This patch adds the example to explain how to register dpset.DPSet
service and how to get DPSet instance from user application in order to
call the API of DPSet.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/controller/dpset.py | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/ryu/controller/dpset.py b/ryu/controller/dpset.py index 8004b2a8..45ead0e0 100644 --- a/ryu/controller/dpset.py +++ b/ryu/controller/dpset.py @@ -165,10 +165,33 @@ class DPSet(app_manager.RyuApp): """ 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) """ def __init__(self, *args, **kwargs): - super(DPSet, self).__init__() + super(DPSet, self).__init__(*args, **kwargs) self.name = 'dpset' self.dps = {} # datapath_id => class Datapath @@ -238,9 +261,10 @@ class DPSet(app_manager.RyuApp): """ 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 + The tuple consists of a Datapath ID and an instance of ryu.controller.controller.Datapath. - A return value looks like the following: + + A return value looks like the following:: [ (dpid_A, Datapath_A), (dpid_B, Datapath_B), ... ] """ |