summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShinpei Muraoka <shinpei.muraoka@gmail.com>2016-03-22 09:51:45 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-03-23 22:44:01 +0900
commit32f5c622b3de0ffde6d5f0a3a0ecec8c17d71083 (patch)
tree7d06662c611472cebcb5fb6b82c6c672bc7fc29b
parent3e180d850450c83428a649423e1d72be494f87d3 (diff)
ofctl_rest: Support port number and queue id in get_queue_stats()
This patch enables to specify the port number and the queue id to get the queue stats. Usage) $ curl -X GET http://localhost:8080/stats/queue/<dpid>[/<port>[/<queue_id>]] Note: Specification of port number and queue id are optional. If you want to omitting the port number and setting the queue id, please specify the keyword "ALL" to the port number. e.g. GET /stats/queue/1/ALL/1 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.py34
-rw-r--r--ryu/lib/ofctl_v1_0.py16
-rw-r--r--ryu/lib/ofctl_v1_2.py17
-rw-r--r--ryu/lib/ofctl_v1_3.py17
4 files changed, 72 insertions, 12 deletions
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
index 5513e470..8ed4e832 100644
--- a/ryu/app/ofctl_rest.py
+++ b/ryu/app/ofctl_rest.py
@@ -79,7 +79,11 @@ supported_ofctl = {
# Note: Specification of port number is optional
#
# get queues stats of the switch
-# GET /stats/queue/<dpid>
+# GET /stats/queue/<dpid>[/<port>[/<queue_id>]]
+# Note: Specification of port number and queue id are optional
+# If you want to omitting the port number and setting the queue id,
+# please specify the keyword "ALL" to the port number
+# e.g. GET /stats/queue/1/ALL/1
#
# get queues config stats of the switch
# GET /stats/queueconfig/<dpid>/<port>
@@ -338,12 +342,26 @@ class StatsController(ControllerBase):
body = json.dumps(ports)
return Response(content_type='application/json', body=body)
- def get_queue_stats(self, req, dpid, **_kwargs):
+ def get_queue_stats(self, req, dpid, port=None, queue_id=None, **_kwargs):
if type(dpid) == str and not dpid.isdigit():
LOG.debug('invalid dpid %s', dpid)
return Response(status=400)
+ if port == "ALL":
+ port = None
+
+ if type(port) == str and not port.isdigit():
+ LOG.debug('invalid port %s', port)
+ return Response(status=400)
+
+ if queue_id == "ALL":
+ queue_id = None
+
+ if type(queue_id) == str and not queue_id.isdigit():
+ LOG.debug('invalid queue_id %s', queue_id)
+ return Response(status=400)
+
dp = self.dpset.get(int(dpid))
if dp is None:
@@ -353,7 +371,7 @@ class StatsController(ControllerBase):
_ofctl = supported_ofctl.get(_ofp_version, None)
if _ofctl is not None:
- queues = _ofctl.get_queue_stats(dp, self.waiters)
+ queues = _ofctl.get_queue_stats(dp, self.waiters, port, queue_id)
else:
LOG.debug('Unsupported OF protocol')
@@ -914,6 +932,16 @@ class RestStatsApi(app_manager.RyuApp):
controller=StatsController, action='get_queue_stats',
conditions=dict(method=['GET']))
+ uri = path + '/queue/{dpid}/{port}'
+ mapper.connect('stats', uri,
+ controller=StatsController, action='get_queue_stats',
+ conditions=dict(method=['GET']))
+
+ uri = path + '/queue/{dpid}/{port}/{queue_id}'
+ mapper.connect('stats', uri,
+ controller=StatsController, action='get_queue_stats',
+ conditions=dict(method=['GET']))
+
uri = path + '/queueconfig/{dpid}/{port}'
mapper.connect('stats', uri,
controller=StatsController, action='get_queue_config',
diff --git a/ryu/lib/ofctl_v1_0.py b/ryu/lib/ofctl_v1_0.py
index c085070e..5fe5778d 100644
--- a/ryu/lib/ofctl_v1_0.py
+++ b/ryu/lib/ofctl_v1_0.py
@@ -314,9 +314,19 @@ def get_desc_stats(dp, waiters):
return desc
-def get_queue_stats(dp, waiters):
- stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, dp.ofproto.OFPP_ALL,
- dp.ofproto.OFPQ_ALL)
+def get_queue_stats(dp, waiters, port=None, queue_id=None):
+ if port is None:
+ port = dp.ofproto.OFPP_ALL
+ else:
+ port = int(str(port), 0)
+
+ if queue_id is None:
+ queue_id = dp.ofproto.OFPQ_ALL
+ else:
+ queue_id = int(str(queue_id), 0)
+
+ stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
+ queue_id)
msgs = []
send_stats_request(dp, stats, waiters, msgs)
diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
index c25dee8d..cd643781 100644
--- a/ryu/lib/ofctl_v1_2.py
+++ b/ryu/lib/ofctl_v1_2.py
@@ -432,10 +432,21 @@ def get_desc_stats(dp, waiters):
return desc
-def get_queue_stats(dp, waiters):
+def get_queue_stats(dp, waiters, port=None, queue_id=None):
ofp = dp.ofproto
- stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, ofp.OFPP_ANY,
- ofp.OFPQ_ALL, 0)
+
+ if port is None:
+ port = ofp.OFPP_ANY
+ else:
+ port = int(str(port), 0)
+
+ if queue_id is None:
+ queue_id = ofp.OFPQ_ALL
+ else:
+ queue_id = int(str(queue_id), 0)
+
+ stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, port,
+ queue_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 286c4e66..d94a9dc4 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -470,10 +470,21 @@ def get_desc_stats(dp, waiters):
return desc
-def get_queue_stats(dp, waiters):
+def get_queue_stats(dp, waiters, port=None, queue_id=None):
ofp = dp.ofproto
- stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, ofp.OFPP_ANY,
- ofp.OFPQ_ALL)
+
+ if port is None:
+ port = ofp.OFPP_ANY
+ else:
+ port = int(str(port), 0)
+
+ if queue_id is None:
+ queue_id = ofp.OFPQ_ALL
+ else:
+ queue_id = int(str(queue_id), 0)
+
+ stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
+ queue_id)
msgs = []
send_stats_request(dp, stats, waiters, msgs)