Added new REST API for ONOS to get group stats of specfic group, Added CLI command 'show switch <dpid> group <groupId>' to stats of specified group
diff --git a/cli/cli/desc/version200/policy.py b/cli/cli/desc/version200/policy.py
index 57c29ae..eac0209 100644
--- a/cli/cli/desc/version200/policy.py
+++ b/cli/cli/desc/version200/policy.py
@@ -254,7 +254,7 @@
'proc' : 'create-policy',
},
),
- 'completion' : 'tunnel-id-completion',
+ 'completion' : 'tunnelid-completion',
'field' : 'tunnel-id',
'type' : 'identifier',
'syntax-help' : 'Enter tunnel id',
diff --git a/cli/cli/desc/version200/switch.py b/cli/cli/desc/version200/switch.py
index 7857329..a78b184 100755
--- a/cli/cli/desc/version200/switch.py
+++ b/cli/cli/desc/version200/switch.py
@@ -211,13 +211,6 @@
'short-help' : 'Show requested item by querying switch',
'doc' : 'switch|realtime-+',
},
- #{
- # 'field' : 'detail',
- # 'optional' : True,
- # 'type' : 'enum',
- # 'values' : ('details','brief'),
- # 'doc' : 'format|+',
- #},
),
(
{
@@ -261,18 +254,27 @@
'format' : 'realtime_%(realtimestats)s_%(tabletype)s_flow',
'doc' : 'format|+',
},
- #{
- # 'field' : 'tableflow',
- # 'type' : 'enum',
- # 'values' : ('flow',
- # ),
- # 'action' : 'display-rest',
- # 'url' : 'realtimestats/%(realtimestats)s/%(tabletype)s/%(tableflow)s/%(dpid)s/',
- # 'rest-type' : 'dict-of-list-of-switch',
- # 'format' : 'realtime_%(realtimestats)s_%(tabletype)s_flow',
- # 'short-help' : 'Show requested item by querying switch',
- # 'doc' : 'switch|realtime-+',
- # },
+ ),
+ (
+ {
+ 'field' : 'realtimestats',
+ 'type' : 'enum',
+ 'values' : 'group',
+ },
+ {
+ 'field' : 'groupId',
+ #'data' : {
+ # 'dpid' : '$dpid',
+ # },
+ #'type' : 'groupId',
+ 'completion' : 'group-id-completion',
+ #'sort' : ['mplsLabel','priority',],
+ 'action' : 'display-rest',
+ 'url' : 'realtimestats/%(realtimestats)s/%(groupId)s/%(dpid)s/',
+ 'rest-type' : 'dict-of-list-of-switch',
+ 'format' : 'realtime_group',
+ 'doc' : 'format|+',
+ },
),
)
}
@@ -1189,3 +1191,23 @@
},
}
"""
+
+def group_id_completion(prefix, data, completions):
+ dpid = data.get('dpid')
+ #print dpid
+ query_url = "http://127.0.0.1:8000/rest/v1/realtimestats/group/%s/" %(dpid)
+ result = command.sdnsh.store.rest_simple_request(query_url)
+ entries = json.loads(result)
+ entries = entries[dpid]
+ #print "result", entries
+ for entry in entries:
+ #print entry['groupId']
+ if str(entry['groupId']).startswith(prefix):
+ completions[str(entry['groupId'])+' '] = entry['groupId']
+ return
+
+command.add_completion('group-id-completion', group_id_completion,
+ {'kwargs': { 'prefix' : '$text',
+ 'data' : '$data',
+ 'completions' : '$completions',
+ }})
diff --git a/cli/sdncon/rest/views.py b/cli/sdncon/rest/views.py
index 41b0acb..66dc75a 100755
--- a/cli/sdncon/rest/views.py
+++ b/cli/sdncon/rest/views.py
@@ -416,6 +416,21 @@
return get_sdnplatform_response(url)
@safe_rest_view
+def do_realtimegroupstats(request, groupId, dpid ):
+ """
+ This returns realtime group statistics for specified groupId
+ for a dpid by calling the localhost sdnplatform
+ """
+ #raise RestInvalidMethodException()
+ if request.method != 'GET':
+ raise RestInvalidMethodException()
+ #url = controller_url('core', 'switch', dpid, stattype, 'json')
+ #import error
+ #raise error.ArgumentValidationError('\n\n\n %s' % (groupId))
+ url = "http://localhost:8080/wm/floodlight/core/switch/%s/groupStats/%s/json" % (dpid, groupId)
+ return get_sdnplatform_response(url)
+
+@safe_rest_view
def do_tablerealtimestats(request, tabletype, dpid):
"""
This returns realtime statistics per table (flows (only)
diff --git a/cli/sdncon/urls.py b/cli/sdncon/urls.py
index 211f3d0..8478eab 100755
--- a/cli/sdncon/urls.py
+++ b/cli/sdncon/urls.py
@@ -62,6 +62,7 @@
(r'^rest/v1/realtimestats/counter/(?P<stattype>[A-Za-z0-9_:.\-]+)/?$', 'sdncon.rest.views.do_sdnplatform_realtimestats'),
(r'^rest/v1/realtimestats/counter/(?P<dpid>[A-Za-z0-9_:.\-]+)/(?P<stattype>[A-Za-z]+)/?$', 'sdncon.rest.views.do_sdnplatform_realtimestats'),
(r'^rest/v1/realtimestats/table/(?P<tabletype>[A-Za-z]+)/flow/(?P<dpid>[A-Za-z0-9_:./\-]+)/?$', 'sdncon.rest.views.do_tablerealtimestats'),
+ (r'^rest/v1/realtimestats/group/(?P<groupId>[0-9]+)/(?P<dpid>[A-Za-z0-9_:./\-]+)/?$', 'sdncon.rest.views.do_realtimegroupstats'),
(r'^rest/v1/realtimestats/(?P<stattype>[A-Za-z]+)/(?P<dpid>[A-Za-z0-9_:./\-]+)/?$', 'sdncon.rest.views.do_realtimestats'),
(r'^rest/v1/controller/stats/(?P<stattype>[A-Za-z]+)/?$', 'sdncon.rest.views.do_controller_stats'),
(r'^rest/v1/controller/storage/tables/?$', 'sdncon.rest.views.do_controller_storage_table_list'),