'added show router <dpid> port'
diff --git a/cli/cli/c_actions.py b/cli/cli/c_actions.py
index a5aed26..00582cf 100755
--- a/cli/cli/c_actions.py
+++ b/cli/cli/c_actions.py
@@ -2004,26 +2004,13 @@
print "command_display_rest: result ", result
entries = json.loads(result)
- if 'router' in data and data['router'] == 'router':
- combResult = []
- for entry in entries:
- attributes = entry.get('stringAttributes')
- #raise error.ArgumentValidationError('\n\n\n %s' % (attributes))
- combResult.append({
- 'dpid' : entry.get('dpid'),
- 'routerIP' : attributes['routerIp'],
- 'name' : attributes['name'],
- 'isEdgeRouter' : attributes['isEdgeRouter'],
- 'routerMac' : attributes['routerMac'],
- 'nodeSId' : attributes['nodeSid'],
- })
- entries = combResult
+ #rest_type = None
#raise error.ArgumentValidationError('\n\n\n %s' % (attributes))
#if 'realtimestats' in data and data['realtimestats'] == 'group':
entries2 = None
-
-
+
+
if 'realtimestats' in data and data['realtimestats'] == 'group':
url2 = "http://%s/rest/v1/" % sdnsh.controller + ("realtimestats/groupdesc/%(dpid)s/" % data)
result2 = sdnsh.store.rest_simple_request(url2)
@@ -2047,6 +2034,38 @@
data,
entries2)
+ if 'router' in data and data['router'] == 'router':
+ combResult = []
+ for entry in entries:
+ attributes = entry.get('stringAttributes')
+ #raise error.ArgumentValidationError('\n\n\n %s' % (attributes))
+ combResult.append({
+ 'dpid' : entry.get('dpid'),
+ 'routerIP' : attributes['routerIp'],
+ 'name' : attributes['name'],
+ 'isEdgeRouter' : attributes['isEdgeRouter'],
+ 'routerMac' : attributes['routerMac'],
+ 'nodeSId' : attributes['nodeSid'],
+ },)
+ entries = combResult
+ #raise error.ArgumentValidationError('\n\n\n %s' % (entries))
+ if 'routerrealtimestats' in data and data['routerrealtimestats'] == 'port':
+ #raise error.ArgumentValidationError('\n\n\n %s' % (data))
+ combResult = []
+ portList = entries
+ for port in portList:
+ portData = port.get("port")
+ name = portData.get("stringAttributes").get('name')
+ portNo = portData.get("portNumber")
+ subnetIp = port.get("subnetIp")
+ combResult.append({
+ 'name' :name,
+ 'portNo' : portNo,
+ 'subnetIp' : subnetIp,
+ })
+ entries = combResult
+
+
if 'realtimestats' in data and 'tabletype' in data and data['realtimestats'] == 'table':
combResult = []
if data['tabletype'] == 'ip':
diff --git a/cli/cli/desc/version200/core.py b/cli/cli/desc/version200/core.py
index 20e888b..df2b3f0 100755
--- a/cli/cli/desc/version200/core.py
+++ b/cli/cli/desc/version200/core.py
@@ -2526,6 +2526,21 @@
},
}
+
+ROUTER_PORT_FORMAT = {
+ 'router_port' : {
+ 'field-orderings' : {
+ 'default' : [ 'Idx', 'name', 'portNo', 'subnetIp','adjacencySid'],
+ 'scoped' : [ 'Idx', 'name', 'portNo', 'subnetIp','adjacencySid'],
+ },
+ #'fields': {
+ # 'switch' : { 'verbose-name' : 'Switch',
+ # 'formatter' : fmtcnv.replace_switch_with_alias
+ # },
+
+ },
+}
+
"""
SWITCH_CLUSTER_FORMAT = {
'switch-cluster' : {
diff --git a/cli/cli/desc/version200/router.py b/cli/cli/desc/version200/router.py
index c1f9728..c68f3cc 100644
--- a/cli/cli/desc/version200/router.py
+++ b/cli/cli/desc/version200/router.py
@@ -36,3 +36,66 @@
},
)
}
+
+
+
+ROUTER_SHOW_REALTIME_STATS_COMMAND_DESCRIPTION = {
+ 'name' : 'show',
+ 'mode' : 'login',
+ 'short-help' : 'Show router stats via direct query to switch',
+ 'no-supported' : False,
+ 'short-help' : 'Show realtime stats for router',
+ 'parent-field' : None,
+ 'obj-type' : 'switches',
+ 'args' : (
+ {
+ 'token' : 'router',
+ 'obj-type' : 'switches',
+ 'command-type' : 'display-table',
+ # 'command-type' : 'display-rest',
+ },
+ {
+ 'choices' : (
+ {
+ 'field' : 'dpid',
+ 'completion' : 'complete-alias-choice',
+ 'type' : 'dpid',
+ 'help-name' : 'switch dpid or alias',
+ 'data-handler' : 'alias-to-value',
+ 'data' : { 'detail' : 'scoped' },
+ },
+ {
+ 'token' : 'all',
+ 'doc' : 'reserved|all',
+ },
+ ),
+ },
+ {
+ 'choices' : (
+ (
+ {
+ 'field' : 'routerrealtimestats',
+ 'type' : 'enum',
+ 'values' : (
+ 'port',
+ ),
+ 'action' : 'display-rest',
+ 'url' : 'router/%(dpid)s/%(routerrealtimestats)s',
+ 'rest-type' : 'dict-of-list-of-switch',
+ 'format' : 'router_port',
+ 'short-help' : 'Show requested item by querying router/switch',
+ 'doc' : 'switch|realtime-+',
+ },
+ {
+ 'field' : 'detail',
+ 'optional' : True,
+ 'type' : 'enum',
+ 'values' : ('details','brief'),
+ 'doc' : 'format|+',
+ },
+ ),
+
+ )
+ }
+ )
+}
diff --git a/cli/sdncon/rest/views.py b/cli/sdncon/rest/views.py
index f8d15a2..e7ba572 100755
--- a/cli/sdncon/rest/views.py
+++ b/cli/sdncon/rest/views.py
@@ -732,6 +732,21 @@
return get_sdnplatform_response(url)
@safe_rest_view
+def do_router_stats(request, stattype, dpid):
+ """
+ This returns the subnets info about the specifed
+ router dpid. statetype should be 'port'.
+ """
+ #raise RestInvalidMethodException()
+ if request.method != 'GET':
+ raise RestInvalidMethodException()
+ #url = controller_url('core', 'switch', dpid, stattype, 'json')
+ url = "http://localhost:8080/wm/onos/segmentrouting/router/%s/%s" % (dpid, stattype)
+ #raise RestInvalidMethodException(url)
+ #url = "http://localhost:8080/wm/onos/segementrouting/router/00:00:00:00:00:00:00:01/port"
+ return get_sdnplatform_response(url)
+
+@safe_rest_view
def do_mastership(request):
url = controller_url("onos", "registry", "switches" ,"json")
#url = "http://127.0.0.1:8080/wm/onos/registry/switches/json"
diff --git a/cli/sdncon/urls.py b/cli/sdncon/urls.py
index a850a10..329dc7d 100755
--- a/cli/sdncon/urls.py
+++ b/cli/sdncon/urls.py
@@ -71,6 +71,7 @@
(r'^rest/v1/device', 'sdncon.rest.views.do_device'),
(r'^rest/v1/switches', 'sdncon.rest.views.do_switches'),
(r'^rest/v1/routers', 'sdncon.rest.views.do_routers'),
+ (r'^rest/v1/router/(?P<dpid>[A-Za-z0-9_:.\-]+)/(?P<stattype>[A-Za-z]+)', 'sdncon.rest.views.do_router_stats'),
(r'^rest/v1/links', 'sdncon.rest.views.do_links'),
(r'^rest/v1/mastership', 'sdncon.rest.views.do_mastership'),
(r'^rest/v1/vns/device-interface', 'sdncon.rest.views.do_vns_device_interface'),
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java
index 944bf1c..12ee18c 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java
@@ -1,23 +1,27 @@
package net.onrc.onos.apps.segmentrouting.web;
-import java.util.List;
-import java.util.concurrent.Future;
-import net.floodlightcontroller.core.IFloodlightProviderService;
-import net.floodlightcontroller.core.IOFSwitch;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import net.onrc.onos.core.topology.ITopologyService;
import net.onrc.onos.core.topology.MutableTopology;
+import net.onrc.onos.core.topology.Port;
+import net.onrc.onos.core.topology.Switch;
import net.onrc.onos.core.util.Dpid;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
-import org.apache.commons.codec.binary.Hex;
import org.projectfloodlight.openflow.util.HexString;
import org.restlet.resource.ServerResource;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
-import com.esotericsoftware.minlog.Log;
-
import static net.onrc.onos.core.topology.web.TopologyResource.eval;
/**
* Base class for return router statistics
@@ -34,7 +38,6 @@
public Representation retrieve() {
String routerId = (String) getRequestAttributes().get("routerId");
String statsType = (String) getRequestAttributes().get("statsType");
- //if (routerId == null && statsType == null){
ITopologyService topologyService =
(ITopologyService) getContext().getAttributes()
.get(ITopologyService.class.getCanonicalName());
@@ -45,31 +48,53 @@
if (routerId == null && statsType == null){
return eval(toRepresentation(mutableTopology.getSwitches(), null));
}
- else if(routerId != null && statsType == "port"){
- Log.debug("\n\n\nGot router port stats request\n\n\n");
- System.out.println("\n\n\nGot router port stats request\n\n\n");
- Long rId = HexString.toLong(routerId);
- return eval(toRepresentation(mutableTopology.getSwitch(new Dpid(rId)), null));
+ else if(routerId != null && statsType.equals("port")){
+ Switch sw = mutableTopology
+ .getSwitch(new Dpid(HexString.toLong(routerId)));
+ if(sw ==null){
+ //TODO: Add exception
+ return null;
+ }
+ Map <String, List<SegmentRouterPortInfo>> result = new HashMap <String, List<SegmentRouterPortInfo>>();
+ List<SegmentRouterPortInfo> listPortInfo = new ArrayList<SegmentRouterPortInfo>();
+ Collection<Port> portList =sw.getPorts();
+ String subnets = null;
+ if (sw.getAllStringAttributes().containsKey("subnets")){
+ subnets = sw.getAllStringAttributes().get("subnets");
+ JSONArray subnetArray = JSONArray.fromObject(subnets);
+ Iterator pI = portList.iterator();
+ while(pI.hasNext()){
+ Port p = (Port) pI.next();
+ Iterator sI = subnetArray.iterator();
+ String subnet = null;
+ while(sI.hasNext()){
+ JSONObject portSubnetIp = (JSONObject) sI.next();
+ subnet = null;
+ if(portSubnetIp.getString("portNo").equals(p.getNumber().toString())){
+ subnet = portSubnetIp.getString("subnetIp");
+ break;
+ }
+ }
+ listPortInfo.add( new SegmentRouterPortInfo(subnet,p));
+ }
+ result.put(routerId, listPortInfo);
+ return eval(toRepresentation(result,null));
+ }
+ else{
+ Iterator pI = portList.iterator();
+ while(pI.hasNext()){
+ Port p = (Port) pI.next();
+ String subnet = null;
+ listPortInfo.add( new SegmentRouterPortInfo(subnet,p));
+ }
+ result.put(routerId, listPortInfo);
+ return eval(toRepresentation(result,null));
+ }
}
} finally {
mutableTopology.releaseReadLock();
}
- // }
- /*else if(routerId != null && statsType == "port"){
- Long rId = HexString.toLong(routerId);
- IFloodlightProviderService floodlightProvider =
- (IFloodlightProviderService) getContext().getAttributes().
- get(IFloodlightProviderService.class.getCanonicalName());
- IOFSwitch sw = floodlightProvider.getSwitches().get(rId);
- Future<List<OFStatsReply>> future;
- List<OFStatsReply> values = null;
-
- }*/
+ //Should Never get to this point.
return null;
}
-
-
-
-
-
}
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java
new file mode 100644
index 0000000..a25d4de
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java
@@ -0,0 +1,31 @@
+package net.onrc.onos.apps.segmentrouting.web;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import net.onrc.onos.core.topology.Port;
+
+/**
+ * This class represent the the port info of the segmentRouter
+ * for rest output.
+ */
+
+public class SegmentRouterPortInfo {
+ //TODO set attributes to private and provide setter and getter.
+ public String subnetIp= null;
+ //private int portNo;
+ public Port port = null;
+
+ public SegmentRouterPortInfo(String ssubnets, Port pport){
+ this.port = pport;
+ //this.portNo = portNo;
+ this.subnetIp = ssubnets;
+ }
+
+ public void setInfo(String subnetIp, Port p) {
+ this.port = p;
+ this.subnetIp = subnetIp;
+
+ }
+
+}