summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShinpei Muraoka <shinpei.muraoka@gmail.com>2016-03-22 09:51:41 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-03-23 22:43:40 +0900
commit294d24183085ca6834160c6ae8ef0a6d0e168fd7 (patch)
treee6cd5647d57d403dbfb160ef9fb3bda3200042a2
parent545645eef89b205c8b53def424d6163d9cf8e896 (diff)
ofctl_rest: Support port number in get_port_stats()
This patch enables to specify the port number to get the port stats. Usage) $ curl -X GET http://localhost:8080/stats/port/<dpid>[/<port>] Note: Specification of port number 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_0.py9
-rw-r--r--ryu/lib/ofctl_v1_2.py9
-rw-r--r--ryu/lib/ofctl_v1_3.py9
4 files changed, 34 insertions, 9 deletions
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
index 7c39e3b1..b999f5a5 100644
--- a/ryu/app/ofctl_rest.py
+++ b/ryu/app/ofctl_rest.py
@@ -75,7 +75,8 @@ supported_ofctl = {
# GET /stats/tablefeatures/<dpid>
#
# get ports stats of the switch
-# GET /stats/port/<dpid>
+# GET /stats/port/<dpid>[/<port>]
+# Note: Specification of port number is optional
#
# get queues stats of the switch
# GET /stats/queue/<dpid>
@@ -306,12 +307,16 @@ class StatsController(ControllerBase):
body = json.dumps(ports)
return Response(content_type='application/json', body=body)
- def get_port_stats(self, req, dpid, **_kwargs):
+ def get_port_stats(self, req, dpid, port=None, **_kwargs):
if type(dpid) == str and not dpid.isdigit():
LOG.debug('invalid dpid %s', dpid)
return Response(status=400)
+ if type(port) == str and not port.isdigit():
+ LOG.debug('invalid port %s', port)
+ return Response(status=400)
+
dp = self.dpset.get(int(dpid))
if dp is None:
@@ -321,7 +326,7 @@ class StatsController(ControllerBase):
_ofctl = supported_ofctl.get(_ofp_version, None)
if _ofctl is not None:
- ports = _ofctl.get_port_stats(dp, self.waiters)
+ ports = _ofctl.get_port_stats(dp, self.waiters, port)
else:
LOG.debug('Unsupported OF protocol')
@@ -884,6 +889,11 @@ class RestStatsApi(app_manager.RyuApp):
controller=StatsController, action='get_port_stats',
conditions=dict(method=['GET']))
+ uri = path + '/port/{dpid}/{port}'
+ mapper.connect('stats', uri,
+ controller=StatsController, action='get_port_stats',
+ conditions=dict(method=['GET']))
+
uri = path + '/queue/{dpid}'
mapper.connect('stats', uri,
controller=StatsController, action='get_queue_stats',
diff --git a/ryu/lib/ofctl_v1_0.py b/ryu/lib/ofctl_v1_0.py
index 97ffa7b2..c085070e 100644
--- a/ryu/lib/ofctl_v1_0.py
+++ b/ryu/lib/ofctl_v1_0.py
@@ -447,9 +447,14 @@ def get_table_stats(dp, waiters):
return desc
-def get_port_stats(dp, waiters):
+def get_port_stats(dp, waiters, port=None):
+ if port is None:
+ port = dp.ofproto.OFPP_NONE
+ else:
+ port = int(str(port), 0)
+
stats = dp.ofproto_parser.OFPPortStatsRequest(
- dp, 0, dp.ofproto.OFPP_NONE)
+ dp, 0, port)
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 23ba30c2..be0f2753 100644
--- a/ryu/lib/ofctl_v1_2.py
+++ b/ryu/lib/ofctl_v1_2.py
@@ -686,9 +686,14 @@ def get_table_stats(dp, waiters):
return desc
-def get_port_stats(dp, waiters):
+def get_port_stats(dp, waiters, port=None):
+ if port is None:
+ port = dp.ofproto.OFPP_ANY
+ else:
+ port = int(str(port), 0)
+
stats = dp.ofproto_parser.OFPPortStatsRequest(
- dp, dp.ofproto.OFPP_ANY, 0)
+ dp, port, 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 ad2760bb..35a15a21 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -722,9 +722,14 @@ def get_table_features(dp, waiters):
return desc
-def get_port_stats(dp, waiters):
+def get_port_stats(dp, waiters, port=None):
+ if port is None:
+ port = dp.ofproto.OFPP_ANY
+ else:
+ port = int(str(port), 0)
+
stats = dp.ofproto_parser.OFPPortStatsRequest(
- dp, 0, dp.ofproto.OFPP_ANY)
+ dp, 0, port)
msgs = []
send_stats_request(dp, stats, waiters, msgs)