diff options
author | Shinpei Muraoka <shinpei.muraoka@gmail.com> | 2016-03-22 09:51:42 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-23 22:43:45 +0900 |
commit | ba1535b4b31ce223ec93ba292881868eb3be4d9a (patch) | |
tree | fbe0ea62580f244cedfe467cfb9c1e2abd2168bd | |
parent | 294d24183085ca6834160c6ae8ef0a6d0e168fd7 (diff) |
ofctl_rest: Support group id in get_group_stats()
This patch enables to specify the group id to get the group stats.
Usage)
$ curl -X GET http://localhost:8080/stats/group/<dpid>[/<group_id>]
Note: Specification of group id is optional
Signed-off-by: Shinpei Muraoka <shinpei.muraoka@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/ofctl_rest.py | 16 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_2.py | 9 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_3.py | 9 |
3 files changed, 27 insertions, 7 deletions
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py index b999f5a5..b776387c 100644 --- a/ryu/app/ofctl_rest.py +++ b/ryu/app/ofctl_rest.py @@ -103,7 +103,8 @@ supported_ofctl = { # GET /stats/groupdesc/<dpid> # # get groups stats of the switch -# GET /stats/group/<dpid> +# GET /stats/group/<dpid>[/<group_id>] +# Note: Specification of group id is optional # # get ports description of the switch # GET /stats/portdesc/<dpid> @@ -546,12 +547,16 @@ class StatsController(ControllerBase): body = json.dumps(groups) return Response(content_type='application/json', body=body) - def get_group_stats(self, req, dpid, **_kwargs): + def get_group_stats(self, req, dpid, group_id=None, **_kwargs): if type(dpid) == str and not dpid.isdigit(): LOG.debug('invalid dpid %s', dpid) return Response(status=400) + if type(group_id) == str and not group_id.isdigit(): + LOG.debug('invalid group_id %s', group_id) + return Response(status=400) + dp = self.dpset.get(int(dpid)) if dp is None: @@ -561,7 +566,7 @@ class StatsController(ControllerBase): _ofctl = supported_ofctl.get(_ofp_version, None) if _ofctl is not None and hasattr(_ofctl, 'get_group_stats'): - groups = _ofctl.get_group_stats(dp, self.waiters) + groups = _ofctl.get_group_stats(dp, self.waiters, group_id) else: LOG.debug('Unsupported OF protocol or \ @@ -939,6 +944,11 @@ class RestStatsApi(app_manager.RyuApp): controller=StatsController, action='get_group_stats', conditions=dict(method=['GET'])) + uri = path + '/group/{dpid}/{group_id}' + mapper.connect('stats', uri, + controller=StatsController, action='get_group_stats', + conditions=dict(method=['GET'])) + uri = path + '/portdesc/{dpid}' mapper.connect('stats', uri, controller=StatsController, action='get_port_desc', diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py index be0f2753..c25dee8d 100644 --- a/ryu/lib/ofctl_v1_2.py +++ b/ryu/lib/ofctl_v1_2.py @@ -718,9 +718,14 @@ def get_port_stats(dp, waiters, port=None): return ports -def get_group_stats(dp, waiters): +def get_group_stats(dp, waiters, group_id=None): + if group_id is None: + group_id = dp.ofproto.OFPG_ALL + else: + group_id = int(str(group_id), 0) + stats = dp.ofproto_parser.OFPGroupStatsRequest( - dp, dp.ofproto.OFPG_ALL, 0) + dp, group_id, 0) msgs = [] send_stats_request(dp, stats, waiters, msgs) diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py index 35a15a21..01882128 100644 --- a/ryu/lib/ofctl_v1_3.py +++ b/ryu/lib/ofctl_v1_3.py @@ -859,9 +859,14 @@ def get_meter_config(dp, waiters): return configs -def get_group_stats(dp, waiters): +def get_group_stats(dp, waiters, group_id=None): + if group_id is None: + group_id = dp.ofproto.OFPG_ALL + else: + group_id = int(str(group_id), 0) + stats = dp.ofproto_parser.OFPGroupStatsRequest( - dp, 0, dp.ofproto.OFPG_ALL) + dp, 0, group_id) msgs = [] send_stats_request(dp, stats, waiters, msgs) |