summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShinpei Muraoka <shinpei.muraoka@gmail.com>2016-03-22 09:51:44 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-03-23 22:43:56 +0900
commit3e180d850450c83428a649423e1d72be494f87d3 (patch)
treee1f09a601b2f0f8d80b5e68f19e1179ac322232d
parentc39b9d57f8b8e64c9a6658f85ae2d05f50665719 (diff)
ofctl_rest: Support meter id in get_meter_config()
This patch enables to specify the meter id to get the meter config. Usage) $ curl -X GET http://localhost:8080/stats/meterconfig/<dpid>[/<meter_id>] Note: Specification of meter 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.py16
-rw-r--r--ryu/lib/ofctl_v1_3.py9
2 files changed, 20 insertions, 5 deletions
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
index 500434fe..5513e470 100644
--- a/ryu/app/ofctl_rest.py
+++ b/ryu/app/ofctl_rest.py
@@ -91,7 +91,8 @@ supported_ofctl = {
# GET /stats/meterfeatures/<dpid>
#
# get meter config stats of the switch
-# GET /stats/meterconfig/<dpid>
+# GET /stats/meterconfig/<dpid>[/<meter_id>]
+# Note: Specification of meter id is optional
#
# get meters stats of the switch
# GET /stats/meter/<dpid>[/<meter_id>]
@@ -448,12 +449,16 @@ class StatsController(ControllerBase):
body = json.dumps(meters)
return Response(content_type='application/json', body=body)
- def get_meter_config(self, req, dpid, **_kwargs):
+ def get_meter_config(self, req, dpid, meter_id=None, **_kwargs):
if type(dpid) == str and not dpid.isdigit():
LOG.debug('invalid dpid %s', dpid)
return Response(status=400)
+ if type(meter_id) == str and not meter_id.isdigit():
+ LOG.debug('invalid meter_id %s', memter_id)
+ return Response(status=400)
+
dp = self.dpset.get(int(dpid))
if dp is None:
@@ -463,7 +468,7 @@ class StatsController(ControllerBase):
_ofctl = supported_ofctl.get(_ofp_version, None)
if _ofctl is not None and hasattr(_ofctl, 'get_meter_config'):
- meters = _ofctl.get_meter_config(dp, self.waiters)
+ meters = _ofctl.get_meter_config(dp, self.waiters, meter_id)
else:
LOG.debug('Unsupported OF protocol or \
@@ -929,6 +934,11 @@ class RestStatsApi(app_manager.RyuApp):
controller=StatsController, action='get_meter_config',
conditions=dict(method=['GET']))
+ uri = path + '/meterconfig/{dpid}/{meter_id}'
+ mapper.connect('stats', uri,
+ controller=StatsController, action='get_meter_config',
+ conditions=dict(method=['GET']))
+
uri = path + '/meter/{dpid}'
mapper.connect('stats', uri,
controller=StatsController, action='get_meter_stats',
diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py
index 04a732de..286c4e66 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -824,7 +824,7 @@ def get_meter_features(dp, waiters):
return features
-def get_meter_config(dp, waiters):
+def get_meter_config(dp, waiters, meter_id=None):
flags = {dp.ofproto.OFPMF_KBPS: 'KBPS',
dp.ofproto.OFPMF_PKTPS: 'PKTPS',
dp.ofproto.OFPMF_BURST: 'BURST',
@@ -834,8 +834,13 @@ def get_meter_config(dp, waiters):
dp.ofproto.OFPMBT_DSCP_REMARK: 'DSCP_REMARK',
dp.ofproto.OFPMBT_EXPERIMENTER: 'EXPERIMENTER'}
+ if meter_id is None:
+ meter_id = dp.ofproto.OFPM_ALL
+ else:
+ meter_id = int(str(meter_id), 0)
+
stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(
- dp, 0, dp.ofproto.OFPM_ALL)
+ dp, 0, meter_id)
msgs = []
send_stats_request(dp, stats, waiters, msgs)