Improvement In 'show router port', added 'show router adjacency', renamed some diplay name in CLI
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
deleted file mode 100644
index 00c2f15..0000000
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package net.onrc.onos.apps.segmentrouting.web;
-
-
-
-import static net.onrc.onos.core.topology.web.TopologyResource.eval;
-
-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.projectfloodlight.openflow.util.HexString;
-import org.restlet.representation.Representation;
-import org.restlet.resource.Get;
-import org.restlet.resource.ServerResource;
-/**
- * Base class for return router statistics
- *
- */
-public class RouterStatisticsResource extends ServerResource {
-    /**
-     * Gets the switches/routers and ports information from the network topology.
-     *
-     * @return a Representation of a Collection of switches/routers from the network
-     * topology. Each switch contains the switch ports.
-     */
-    @Get("json")
-    public Representation retrieve() {
-        String routerId = (String) getRequestAttributes().get("routerId");
-        String statsType = (String) getRequestAttributes().get("statsType");
-        ITopologyService topologyService =
-                (ITopologyService) getContext().getAttributes()
-                .get(ITopologyService.class.getCanonicalName());
-
-        MutableTopology mutableTopology = topologyService.getTopology();
-        mutableTopology.acquireReadLock();
-        try {
-            if (routerId == null && statsType == null){
-                return eval(toRepresentation(mutableTopology.getSwitches(), 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<Port> pI = portList.iterator();
-                    while(pI.hasNext()){
-                        Port p = 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<Port> pI = portList.iterator();
-                    while(pI.hasNext()){
-                        Port p = pI.next();
-                        String subnet = null;
-                        listPortInfo.add( new SegmentRouterPortInfo(subnet,p));
-                    }
-                    result.put(routerId, listPortInfo);
-                    return eval(toRepresentation(result,null));
-                }
-            }
-        } finally {
-            mutableTopology.releaseReadLock();
-        }
-    //Should Never get to this point.
-    return null;
-    }
-}
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterAdjacencyInfo.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterAdjacencyInfo.java
new file mode 100644
index 0000000..1c47e74
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterAdjacencyInfo.java
@@ -0,0 +1,26 @@
+package net.onrc.onos.apps.segmentrouting.web;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Contain the adjacency port info, which is exposed to REST
+ *
+ */
+
+public class SegmentRouterAdjacencyInfo {
+    private Integer adjacencySid =null;
+    private List<Integer>  ports = null;
+    
+    public SegmentRouterAdjacencyInfo(Integer adj, List<Integer> pList){
+        this.adjacencySid = adj;
+        this.ports = pList;
+    }
+    
+    public Integer getAdjacencySid(){
+        return this.adjacencySid;
+    }
+    public List<Integer> getPorts(){
+        return this.ports;
+    }
+}
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
index 73c1334..104ad13 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java
@@ -1,7 +1,6 @@
 package net.onrc.onos.apps.segmentrouting.web;
 
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.List;
 
 import net.onrc.onos.core.topology.Port;
 
@@ -12,18 +11,23 @@
 
 public class SegmentRouterPortInfo {
     //TODO set attributes to private and provide setter and getter.
-    public String subnetIp= null;
-    public Port  port = null;
+    private String subnetIp= null;
+    private Port  port = null;
+    private List<Integer> adjacency = null;
     
-    public SegmentRouterPortInfo(String ssubnets, Port pport){
+    public SegmentRouterPortInfo(String ssubnets, Port pport, List<Integer> adj){
         this.port = pport;
         this.subnetIp = ssubnets;
+        this.adjacency = adj;
     }
-
-    public void setInfo(String subnetIp, Port p) {
-        this.port = p;
-        this.subnetIp = subnetIp;
-        
+    public String getSubnetIp(){
+        return this.subnetIp;
+    }
+    public Port getPort(){
+        return this.port;
+    }
+    public List<Integer> getAdjacency(){
+        return this.adjacency;
     }
 
 }
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterResource.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterResource.java
new file mode 100644
index 0000000..a34f47a
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterResource.java
@@ -0,0 +1,154 @@
+package net.onrc.onos.apps.segmentrouting.web;
+
+
+
+import static net.onrc.onos.core.topology.web.TopologyResource.eval;
+
+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.apps.segmentrouting.ISegmentRoutingService;
+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.projectfloodlight.openflow.util.HexString;
+import org.restlet.representation.Representation;
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+/**
+ * Base class for return router statistics
+ *
+ */
+public class SegmentRouterResource extends ServerResource {
+    /**
+     * Gets the switches/routers and ports information from the network topology.
+     *
+     * @return a Representation of a Collection of switches/routers from the network
+     * topology. Each switch contains the switch ports.
+     */
+    @Get("json")
+    public Object retrieve() {
+        String routerId = (String) getRequestAttributes().get("routerId");
+        String statsType = (String) getRequestAttributes().get("statsType");
+        ITopologyService topologyService =
+                (ITopologyService) getContext().getAttributes()
+                .get(ITopologyService.class.getCanonicalName());
+
+        MutableTopology mutableTopology = topologyService.getTopology();
+        mutableTopology.acquireReadLock();
+        try {
+            if (routerId == null && statsType == null){
+                return eval(toRepresentation(mutableTopology.getSwitches(), 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;
+                }
+                ISegmentRoutingService segmentRoutingService =
+                        (ISegmentRoutingService) getContext().getAttributes().
+                                get(ISegmentRoutingService.class.getCanonicalName());
+                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<Port> pI = portList.iterator();
+                    int nodeSid = Integer.parseInt(sw.getStringAttribute("nodeSid"));
+                    HashMap<Integer, List<Integer>> adjPortInfo = segmentRoutingService.getAdjacencyInfo(nodeSid);
+                    while(pI.hasNext()){
+                        Port p = pI.next();
+                        Iterator<Integer> keyIt = adjPortInfo.keySet().iterator();
+                        Iterator<?> sI = subnetArray.iterator();
+                        List<Integer> adjacency = new ArrayList<Integer>();
+                        while(keyIt.hasNext()){
+                            Integer adj = keyIt.next();
+                            List<Integer> adjPortList = adjPortInfo.get(adj);
+                            if(adjPortList.contains(Integer.valueOf(p.getNumber().shortValue()))){
+                                adjacency.add(adj);
+                            }
+                        }
+                        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, adjacency));
+                    }
+                    result.put(routerId, listPortInfo);
+                    return eval(toRepresentation(result,null));
+                }
+                else{
+                    Iterator<Port> pI = portList.iterator();
+                    int nodeSid = Integer.parseInt(sw.getStringAttribute("nodeSid"));
+                    HashMap<Integer, List<Integer>> adjPortInfo = segmentRoutingService.getAdjacencyInfo(nodeSid);
+                    while(pI.hasNext()){
+                        Port p = pI.next();
+                        String subnet = null;
+                        Iterator<Integer> keyIt = adjPortInfo.keySet().iterator();
+                        List<Integer> adjacency = new ArrayList<Integer>();
+                        while(keyIt.hasNext()){
+                            Integer adj = keyIt.next();
+                            List<Integer> adjPortList = adjPortInfo.get(adj);
+                            if(adjPortList.contains(Integer.valueOf(p.getNumber().shortValue()))){
+                                adjacency.add(adj);
+                            }
+                        }
+                        listPortInfo.add( new SegmentRouterPortInfo(subnet,p, adjacency));
+                    }
+                    result.put(routerId, listPortInfo);
+                    return eval(toRepresentation(result,null));
+                }
+            }
+            else if(routerId != null && statsType.equals("adjacency")){
+                ISegmentRoutingService segmentRoutingService =
+                        (ISegmentRoutingService) getContext().getAttributes().
+                                get(ISegmentRoutingService.class.getCanonicalName());
+                Switch sw = mutableTopology
+                .getSwitch(new Dpid(HexString.toLong(routerId)));
+                if(sw ==null){
+                    //TODO: Add exception
+                    return null;
+                }
+                int nodeSid = Integer.parseInt(sw.getStringAttribute("nodeSid"));
+                HashMap<Integer, List<Integer>> adjPortInfo = segmentRoutingService.getAdjacencyInfo(nodeSid);
+                Iterator<Integer> aPIt = adjPortInfo.keySet().iterator();
+                List<SegmentRouterAdjacencyInfo> result= new ArrayList<SegmentRouterAdjacencyInfo>();
+                while(aPIt.hasNext()){
+                    Integer adj = aPIt.next();
+                    result.add( new SegmentRouterAdjacencyInfo(adj,
+                            adjPortInfo.get(adj)));
+                }
+                /*HashMap<String,HashMap<Integer, List<Integer>>> dpidAdjPortMap = 
+                        new HashMap<String,HashMap<Integer, List<Integer>>>();
+                dpidAdjPortMap.put(routerId, adjPortInfo);
+                List<HashMap<String,HashMap<Integer, List<Integer>>>> result = 
+                        new ArrayList<HashMap<String,HashMap<Integer, List<Integer>>>>();
+                result.add(dpidAdjPortMap);*/
+                
+                return  result;
+            }
+        } finally {
+            mutableTopology.releaseReadLock();
+        }
+    //Should Never get to this point.
+    return null;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRoutingWebRoutable.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRoutingWebRoutable.java
index e19df8d..f06473c 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRoutingWebRoutable.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRoutingWebRoutable.java
@@ -19,8 +19,8 @@
     public Restlet getRestlet(Context context) {
         Router router = new Router(context);
         //TODO: rewrite Router/SwitchesResource for router specific info.
-        router.attach("/routers",  RouterStatisticsResource.class);
-        router.attach("/router/{routerId}/{statsType}",  RouterStatisticsResource.class);
+        router.attach("/routers",  SegmentRouterResource.class);
+        router.attach("/router/{routerId}/{statsType}",  SegmentRouterResource.class);
         router.attach("/tunnel", SegmentRouterTunnelResource.class);
         router.attach("/policy", SegmentRouterPolicyResource.class);
         // SegmentRouterTunnelResource.class);