Merge branch 'master' of github.com:OPENNETWORKINGLAB/ONOS
diff --git a/web/js/controller-status.js b/web/js/controller-status.js
index 75cc5cc..1cca38f 100644
--- a/web/js/controller-status.js
+++ b/web/js/controller-status.js
@@ -24,6 +24,15 @@
 	attr("height", 50);
 
     d3.json(data_source, draw);
+    setInterval(function() {
+        $.ajax({
+	    url: data_source,
+	    success: function(json) {
+		draw(json)
+	    },
+	    dataType: "json"
+        });
+    }, 5000); 
 
     function draw(json){
 //	var data = json.data;
@@ -159,15 +168,6 @@
 	cassandra_rect.exit().remove();
 	cassandra_text.exit().remove();
 
-	setInterval(function() {
-            $.ajax({
-		url: data_source,
-		success: function(json) {
-		    draw(json)
-		},
-		dataType: "json"
-            });
-	}, 3000); 
     }
 /*
     $("#more").click( function() {
diff --git a/web/js/onos-topology-route.js b/web/js/onos-topology-route.js
index 3b13b9c..cca644b 100644
--- a/web/js/onos-topology-route.js
+++ b/web/js/onos-topology-route.js
@@ -374,8 +374,7 @@
 	    return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
 	});
 
-	path
-	    .attr("stroke", function(d) {
+	path.attr("stroke", function(d) {
 	    if(d.type == 1){
 		return "red"
 	    } else {
diff --git a/web/js/onos-topology.js b/web/js/onos-topology.js
index 8573f7c..062d37b 100644
--- a/web/js/onos-topology.js
+++ b/web/js/onos-topology.js
@@ -208,23 +208,50 @@
 		}
 	    }
 	}
+	for (var i = 0; i < links.length; i++) {
+            for (var j = 0; j < json.links.length; j++) {
+		if (links[i].target.name == json.nodes[json.links[j].target].name && 
+		    links[i].source.name == json.nodes[json.links[j].source].name ){
+		    if (links[i].type != json.links[j].type){
+			links[i].type = json.links[j].type;
+			changed = true;
+		    }
+		}
+	    }
+	}
 	return changed
     }
 
     function draw(force, path, circle, text){
 	force.stop();
         path.enter().append("svg:path")
-	    .attr("class", function(d) { return "link"; });
+	    .attr("class", function(d) { return "link"; })
+	    .attr("marker-end", function(d) {
+		if(d.type == 1){
+		    return "url(#TriangleRed)";
+		} else {
+		    return "url(#Triangle)";
+		}
+	    });
 
         circle.enter().append("svg:circle")
-	    .attr("r", radius)
+	    .attr("r", function(d) { 
+		if (d.group == 1000){
+		    return radius/2;
+		}else{
+		    return radius;
+		}
+	    })
 	    .call(node_drag);
 //            .call(force.drag);
 
 	text.enter().append("svg:text")
 	    .attr("x", radius)
 	    .attr("y", ".31em")
-	    .text(function(d) { return d.name.split(":")[5] + d.name.split(":")[6] + d.name.split(":")[7] });
+	    .text(function(d) { 
+		l=d.name.split(":").length
+		return d.name.split(":")[l-3] + ":" + d.name.split(":")[l-2] + ":" + d.name.split(":")[l-1]
+	    });
 
         circle.append("title")
 	    .text(function(d) { return d.name; });
@@ -234,6 +261,7 @@
 	    else if (d.group == 2){return "blue";}
 	    else if (d.group == 3){return "green";}
 	    else if (d.group == 4){return "orange";}
+	    else if (d.group == 1000){return "black";}
 	    else{ return "gray"; }
 	});
 
@@ -245,7 +273,7 @@
 	    }
 	}).attr("stroke-width", function(d) {
 	    if(d.type == 1){
-		return "4px";
+		return "2px";
 	    } else {
 		return "1.5px";
 	    }
@@ -271,13 +299,13 @@
 	var changed = cdiff(json);
 
 	console.log("changed? " + changed);
+        path = svg.selectAll("path").data(links)
+        circle = svg.selectAll("circle").data(nodes);
+	text = svg.selectAll("text").data(nodes);
 
+	console.log(path)
 	if (changed){
 
-            path = svg.selectAll("path").data(links)
-            circle = svg.selectAll("circle").data(nodes);
-	    text = svg.selectAll("text").data(nodes);
-
 	    draw(force, path, circle, text);
 	}
     }
@@ -299,8 +327,6 @@
             });
 	}, 3000); 
     }
-
-
     function tick() {
 	path.attr("d", function(d) {
 	    var dx = d.target.x - d.source.x,
@@ -309,6 +335,26 @@
 	    dr = 0;  // 0 for direct line
 	    return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
 	});
+	path.attr("stroke", function(d) {
+	    if(d.type == 1){
+		return "red"
+	    } else {
+		return "black"
+	    }
+	}).attr("stroke-width", function(d) {
+	    if(d.type == 1){
+		return "3px";
+	    } else {
+		return "1.5px";
+	    }
+	}).attr("marker-end", function(d) {
+	    if(d.type == 1){
+		return "url(#TriangleRed)";
+	    } else {
+		return "url(#Triangle)";
+	    }
+	});
+
 //	circle.attr("cx", function(d) { return d.x; }).attr("cy", function(d) { return d.y; });
 	circle.attr("transform", function(d) {
 	    x = Math.max(radius, Math.min(width - radius, d.x));
@@ -322,6 +368,7 @@
 	    else if (d.group == 2){return "blue";}
 	    else if (d.group == 3){return "green";}
 	    else if (d.group == 4){return "orange";}
+	    else if (d.group == 1000){return "black";}
 	    else{ return "gray"; }
 	});
 //	text.attr("x", function(d) { return d.x; }).attr("y", function(d) { return d.y; });
diff --git a/web/onos-topology-route.html b/web/onos-topology-route.html
index 860a096..6c167c7 100644
--- a/web/onos-topology-route.html
+++ b/web/onos-topology-route.html
@@ -42,7 +42,7 @@
     </marker>
   </defs>
 <script type="text/javascript">
-gui("http://onosnat.onlab.us:8080/wm/topology/toporoute/00:00:00:00:00:a1/2/00:00:00:00:00:c1/3/json");
+gui("http://onosnat.onlab.us:8080/wm/topology/toporoute/00:00:00:0d:00:d1/2/00:00:00:0d:00:d3/3/json");
 </script>
 </svg>
 </body>
diff --git a/web/onos-topology.html b/web/onos-topology.html
index b0614c9..9d90ea4 100644
--- a/web/onos-topology.html
+++ b/web/onos-topology.html
@@ -2,11 +2,6 @@
 <html>
 <meta charset="utf-8">
 <style>
-path.link {
-  fill: none;
-  stroke: #666;
-  stroke-width: 1.5px;
-}
 circle {
   stroke: #333;
   stroke-width: 1.5px;
@@ -40,6 +35,13 @@
       orient="auto">
       <path d="M0,-5L10,0L0,5"/>
     </marker>
+    <marker id="TriangleRed"
+      viewBox="0 -5 10 10" refX="10" refY="-0.2" 
+      markerUnits="strokeWidth"
+      markerWidth="6" markerHeight="6"
+      orient="auto">
+      <path d="M0,-5L10,0L0,5" fill="red" stroke="red"/>
+    </marker>
   </defs>
 <h1>ONOS Sprint 4 Demo GUI</h1>
 <h2>Controller Status</h2>
diff --git a/web/topology_rest.py b/web/topology_rest.py
index 5eaed03..b109ccc 100755
--- a/web/topology_rest.py
+++ b/web/topology_rest.py
@@ -114,6 +114,7 @@
   topo = {}
   switches = []
   links = []
+  devices = []
 
   for v in parsedResult:
     if v.has_key('dpid'):
@@ -123,19 +124,45 @@
       sw = {}
       sw['name']=dpid
       sw['group']= -1
-      if state == "ACTIVE":
-        if dpid.split(":")[5] == "0a":
-          sw['group']=1
-        if dpid.split(":")[5] == "0b":
-          sw['group']=2
-        if dpid.split(":")[5] == "0c":
-          sw['group']=3
-        if dpid.split(":")[5] == "0d":
-          sw['group']=4
+
+#      if state == "ACTIVE":
+#        if dpid.split(":")[5] == "0a":
+#          sw['group']=1
+#        if dpid.split(":")[5] == "0b":
+#          sw['group']=2
+#        if dpid.split(":")[5] == "0c":
+#          sw['group']=3
+#        if dpid.split(":")[5] == "0d":
+#          sw['group']=4
       if state == "INACTIVE":
         sw['group']=0
       switches.append(sw)
 
+## Comment in if we need devies
+#      sw_index = len(switches) - 1
+#      for p in v['ports']:
+#        for d in p['devices']:
+#          device = {}
+#          device['attached_switch']=dpid
+#          device['name']=d['mac']
+#          if d['state'] == "ACTIVE":
+#            device['group']=1000
+#          else:
+#            device['group']=1001
+#
+#          switches.append(device)
+#          device_index = len (switches) -1
+#          link = {}
+#          link['source'] = device_index
+#          link['target'] = sw_index
+#          link['type'] = -1
+#          links.append(link)
+#          link = {}
+#          link['source'] = sw_index
+#          link['target'] = device_index
+#          link['type'] = -1
+#          links.append(link)
+
 #  try:
 #    command = "curl -s \'http://%s:%s/wm/registry/controllers/json\'" % (RestIP, RestPort)
 #    result = os.popen(command).read()
@@ -162,23 +189,26 @@
 
   try:
     v1 = "00:00:00:00:00:0a:0d:00"
+#    v1 = "00:00:00:00:00:0d:00:d1"
     p1=1
     v2 = "00:00:00:00:00:0b:0d:03"
-    p1=2
+#    v2 = "00:00:00:00:00:0d:00:d3"
+    p2=1
     command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2)
     result = os.popen(command).read()
     parsedResult = json.loads(result)
   except:
     log_error("No route")
-    parsedResult = []
+    parsedResult = {}
 
-  path = [];    
-  for i, v in enumerate(parsedResult):
-    if i < len(parsedResult) - 1:
-      sdpid= parsedResult[i]['switch']
-      ddpid = parsedResult[i+1]['switch']
-      path.append( (sdpid, ddpid))  
-
+  path = []
+  if parsedResult.has_key('flowEntries'):
+    flowEntries= parsedResult['flowEntries']
+    for i, v in enumerate(flowEntries):
+      if i < len(flowEntries) - 1:
+        sdpid= flowEntries[i]['dpid']['value']
+        ddpid = flowEntries[i+1]['dpid']['value']
+        path.append( (sdpid, ddpid))  
 
   try:
     command = "curl -s \'http://%s:%s/wm/core/topology/links/json\'" % (RestIP, RestPort)
@@ -212,12 +242,11 @@
   topo['nodes'] = switches
   topo['links'] = links
 
-#  pp.pprint(topo)
+  pp.pprint(topo)
   js = json.dumps(topo)
   resp = Response(js, status=200, mimetype='application/json')
   return resp
 
-
 #@app.route("/wm/topology/toporoute/00:00:00:00:00:a1/2/00:00:00:00:00:c1/3/json")
 #@app.route("/wm/topology/toporoute/<srcdpid>/<srcport>/<destdpid>/<destport>/json")
 @app.route("/wm/topology/toporoute/<v1>/<p1>/<v2>/<p2>/json")