Documentacion agregada - previo a la presentacion
[VSoRC/.git] / js / topology / topology.js
index 0f6e1f1ba426019396ffcf5359281ef406f0cd9a..7808f33e749c1669a366302c2c42f9b66bfb6e13 100644 (file)
@@ -43,6 +43,14 @@ $(function () {
     //          "port": {"source": "00000003", "target": "00000002"}, "value": 4},
     //       ...
     //     ]}
+function displayMessage(msg) {
+    var $x = $("#snackbar");
+    $x.text(msg)
+    $x.toggleClass("show");
+    setTimeout(function () { $x.toggleClass("show"); }, 3000);
+}
+
+
     function toGraph(top) {
         var nodes = [];
         var links = [];
@@ -74,8 +82,9 @@ $(function () {
         }
 
         lst = top.hosts;
+        console.log(top.hosts);
         for (var i = 0; i < lst.length; i++) {
-            nodes.push({ "id": lst[i].mac, "type": "host" });
+            nodes.push({ "id": lst[i].mac, "type": "host","ip": lst[i].ipv4});
             links.push({
                 "source": lst[i].port.dpid, "target": lst[i].mac, "value": 2,
                 "port": { "source": lst[i].port.port_no, "target": 0 }
@@ -153,6 +162,12 @@ $(function () {
             .attr("class", "label")
             .attr("dy", size + 14)
             .text(function (d) { return d.id; });
+
+
+       node.append("text")
+            .attr("class", "label")
+            .attr("dy", size + 26)
+            .text(function (d) { if (d.type === "host")return (d.ip); });
             // .text(function (d) { return d.id.replace(/^0+/, ''); });
 
 
@@ -287,22 +302,21 @@ $(function () {
 // La funcion jsonget fue creada para sustituir el metodo json de D3
 
         function jsonget() {
-
           let xhr = new XMLHttpRequest();
           xhr.open('GET', "/gettopo" , true);
           //console.log(xhr); //para ver en la consola
           xhr.onload = function() {
             if (xhr.status == 200) { //can use this.status instead
               //console.log(xhr.responseText);// para ver en la consola
-
-              listTopology(JSON.parse(xhr.responseText));
+               if(xhr.response === null || xhr.response === ""){
+               displayMessage("No response from controller")
+               }
               plotGraph(toGraph(JSON.parse(xhr.responseText)));
             }
           }
           xhr.send();
         }
-
-        jsonget();
+      jsonget();