Also, updates the API document of ryu.app.ofctl.api.
Signed-off-by: IWASE Yusuke <[email protected]>
---
ryu/app/ofctl/api.py | 38 ++++++++++++++++++++++++++++++--------
ryu/app/ofctl/event.py | 4 ++--
ryu/app/ofctl/service.py | 16 +++++++---------
3 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/ryu/app/ofctl/api.py b/ryu/app/ofctl/api.py
index 466b331..fe76b80 100644
--- a/ryu/app/ofctl/api.py
+++ b/ryu/app/ofctl/api.py
@@ -16,22 +16,37 @@
# client for ryu.app.ofctl.service
-import numbers
-
from ryu.base import app_manager
from . import event
-def get_datapath(app, dpid):
+def get_datapath(app, dpid=None):
"""
Get datapath object by dpid.
:param app: Client RyuApp instance
- :param dpid: Datapath-id (in integer)
+ :param dpid: Datapath ID (int type) or None to get all datapath objects
+
+ Returns a object of datapath, a list of datapath objects when no dpid
+ given or None when error.
+
+ Raises an exception if any of the given values is invalid.
+
+ Example::
+
+ # ...(snip)...
+ import ryu.app.ofctl.api as ofctl_api
- Returns None on error.
+
+ class MyApp(app_manager.RyuApp):
+
+ def _my_handler(self, ev):
+ # Get all datapath objects
+ result = ofctl_api.get_datapath(self)
+
+ # Get the datapath object which has the given dpid
+ result = ofctl_api.get_datapath(self, dpid=1)
"""
- assert isinstance(dpid, numbers.Integral)
return app.send_request(event.GetDatapathRequest(dpid=dpid))()
@@ -55,10 +70,17 @@ def send_msg(app, msg, reply_cls=None, reply_multi=False):
Example::
- import ryu.app.ofctl.api as api
+ # ...(snip)...
+ import ryu.app.ofctl.api as ofctl_api
+
+
+ class MyApp(app_manager.RyuApp):
+ def _my_handler(self, ev):
+ # ...(snip)...
msg = parser.OFPPortDescStatsRequest(datapath=datapath)
- result = api.send_msg(self, msg,
+ result = ofctl_api.send_msg(
+ self, msg,
reply_cls=parser.OFPPortDescStatsReply,
reply_multi=True)
"""
diff --git a/ryu/app/ofctl/event.py b/ryu/app/ofctl/event.py
index 8919452..dfb0024 100644
--- a/ryu/app/ofctl/event.py
+++ b/ryu/app/ofctl/event.py
@@ -33,8 +33,8 @@ class _ReplyBase(event.EventReplyBase):
# get datapath
class GetDatapathRequest(_RequestBase):
- def __init__(self, dpid):
- assert isinstance(dpid, numbers.Integral)
+ def __init__(self, dpid=None):
+ assert dpid is None or isinstance(dpid, numbers.Integral)
super(GetDatapathRequest, self).__init__()
self.dpid = dpid
diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py
index 2a2e97d..ce60495 100644
--- a/ryu/app/ofctl/service.py
+++ b/ryu/app/ofctl/service.py
@@ -99,15 +99,13 @@ class OfctlService(app_manager.RyuApp):
@set_ev_cls(event.GetDatapathRequest, MAIN_DISPATCHER)
def _handle_get_datapath(self, req):
- id = req.dpid
- assert isinstance(id, numbers.Integral)
- try:
- datapath = self._switches[id].datapath
- except KeyError:
- datapath = None
- self.logger.debug('dpid %s -> datapath %s', id, datapath)
- rep = event.Reply(result=datapath)
- self.reply_to_request(req, rep)
+ result = None
+ if req.dpid is None:
+ result = [v.datapath for v in self._switches.values()]
+ else:
+ if req.dpid in self._switches:
+ result = self._switches[req.dpid].datapath
+ self.reply_to_request(req, event.Reply(result=result))
@set_ev_cls(event.SendMsgRequest, MAIN_DISPATCHER)
def _handle_send_msg(self, req):
--
2.7.4
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel