New buttons added on starter page
[VSoRC/.git] / src / routes / index.js
index 762d14bb364dbf2bea2c3e0ea3b329b0f4d168cb..51f81466c032defce62f7f0eb50113ad219a620f 100644 (file)
@@ -33,7 +33,7 @@ router.get('/free', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
   var child;
-  child = exec("free -b | grep Mem |  awk  '{print $7}'", function(error, stdout, stderr) {
+  child = exec("free -b | grep Mem |  awk  '{print $3}'", function(error, stdout, stderr) {
     console.log("free");
     res.send(stdout);
   });
@@ -44,7 +44,7 @@ router.get('/mpstat', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
   var child;
-  child = exec("mpstat 1 1| grep all | awk '{print $13}'", function(error, stdout, stderr) {
+  child = exec("mpstat 1 1| grep all | grep Average | awk '{print $12}'", function(error, stdout, stderr) {
     console.log("mpstat");
     res.send(stdout);
   });
@@ -55,7 +55,7 @@ router.get('/ifstat', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
   var child;
-  child = exec("ifstat -n -b -i wlp2s0  0.3 1 | grep [0-9]$", function(error, stdout, stderr) {
+  child = exec("ifstat -n -b -i eth0  0.3 1 | grep [0-9]$", function(error, stdout, stderr) {
     console.log("ifstat");
     res.send(stdout);
   });
@@ -71,6 +71,93 @@ router.get('/gettopo', (req, res) => {
   });
 });
 
+router.get('/net', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && echo net > fifo", function(error, stdout, stderr) {
+    console.log("pingall");
+    res.send(stdout);
+  });
+});
+
+router.get('/nodes', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && echo nodes > fifo", function(error, stdout, stderr) {
+    console.log("pingall");
+    res.send(stdout);
+  });
+});
+
+router.get('/status', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && echo status > fifo", function(error, stdout, stderr) {
+    console.log("pingall");
+    res.send(stdout);
+  });
+});
+
+router.get('/intfs', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && echo intfs > fifo", function(error, stdout, stderr) {
+    console.log("pingall");
+    res.send(stdout);
+  });
+});
+
+router.get('/iperf', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && echo iperf > fifo", function(error, stdout, stderr) {
+    console.log("pingall");
+    res.send(stdout);
+  });
+});
+
+router.get('/pingall', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && echo pingall > fifo", function(error, stdout, stderr) {
+    console.log("pingall");
+    res.send(stdout);
+  });
+});
+router.get('/placement', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && echo placement > fifo", function(error, stdout, stderr) {
+    console.log("placement");
+    res.send(stdout);
+  });
+});
+
+router.get('/getvsorcdata', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && cat aichivo 2>&1", function(error, stdout, stderr) {
+    console.log("getting vsorc data");
+    res.send(stdout);
+  });
+});
+router.get('/getcontrollerdata', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi/scripts && cat controllerout 2>&1", function(error, stdout, stderr) {
+    console.log("getting controller data");
+    res.send(stdout);
+  });
+});
 router.get('/listswitch', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
@@ -78,7 +165,16 @@ router.get('/listswitch', (req, res) => {
   child = exec("curl localhost:8080/data?list=switches", function(error, stdout, stderr) {
     console.log("listswitch");
     console.log(stdout);
-    let value = JSON.parse(stdout)
+    let value = '';
+    try {
+      value = JSON.parse(stdout)
+    }
+    catch(error) {
+      console.error(error);
+      console.log("no response from server");
+      // expected output: ReferenceError: nonExistentFunction is not defined
+      // Note - error messages will vary depending on browser
+    }
 
     res.send(value);
   });
@@ -104,7 +200,8 @@ router.get('/startcontroller', (req, res) => {
   var exec = require('child_process').exec;
   var child;
   //cd /home/pi && setsid $(cat /home/pi/ejecutarcontroller.sh | grep sudo) >/dev/null 2>&1 < /dev/null &
-  child = exec("cd /home/pi && ./ejecutarcontroller.sh > /dev/null 2>&1 < /dev/null &", function(error, stdout, stderr) {
+  //cd /home/pi && ./ejecutarcontroller.sh > /dev/null 2>&1 < /dev/null &  //comando anterior
+  child = exec("cd /home/pi/scripts && touch controllerout && ./ejecutarcontroller.sh > controllerout 2>&1 &", function(error, stdout, stderr) {
     console.log("controller started");
     res.send(stdout);
   });
@@ -114,7 +211,7 @@ router.get('/stopcontroller', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
   var child;
-  child = exec("sudo kill $(ps aux | grep python | grep ryu | awk {'print $2'})", function(error, stdout, stderr) {
+  child = exec("cd /home/pi/scripts && rm controllerout && sudo kill $(ps aux | grep python | grep ryu | awk {'print $2'})", function(error, stdout, stderr) {
     console.log("controller stopped");
     res.send(stdout);
   });
@@ -131,20 +228,20 @@ router.get('/startvsorc', (req, res) => {
   request = JSON.parse(req.query.topology)
   console.log("Topology is : \n"+ request);
   //controlar que solo se haga un arranque por vez y agregar el exec 3>fifo
-  child0 = exec("cd /home/pi && echo \""+request+"\" > data", function(error, stdout, stderr) {
+  child0 = exec("cd /home/pi/scripts && echo \""+request+"\" > data", function(error, stdout, stderr) {
     console.log(stdout + stderr);
     answer+=stdout;
   });
-  child1 = exec("cd /home/pi && mkfifo fifo && rm aichivo && touch aichivo", function(error, stdout, stderr) {
+  child1 = exec("cd /home/pi/scripts && mkfifo fifo && touch aichivo", function(error, stdout, stderr) {
     console.log(stdout + stderr);
     answer+=stdout;
   });
-  child2 = exec("exec 3>fifo", function(error, stdout, stderr) {
+  child2 = exec("cd /home/pi/scripts && exec 3>fifo", function(error, stdout, stderr) {
     console.log(stdout + stderr);
     answer+=stdout;
   });
   //child3 uses tail so it can read from fifo even after a EOF
-  child3 = exec("cd /home/pi && tail -n +1 -f fifo | sudo ./clusterGRE.py > aichivo 2>&1 &", function(error, stdout, stderr) {
+  child3 = exec("cd /home/pi/scripts && tail -n +1 -f fifo | sudo ./clusterGRE.py > aichivo 2>&1 &", function(error, stdout, stderr) {
     console.log(stdout + stderr);
     answer+=stdout;
   });
@@ -158,23 +255,25 @@ router.get('/stopvsorc', (req,res) =>{
   var child2;
   var child3;
   var payload
-  child1 = exec("cd /home/pi && exec 3>&- && rm fifo", function(error, stdout, stderr) {
+  console.log("erasing...");
+  child1 = exec("cd /home/pi/scripts && exec 3>&- && rm fifo && rm aichivo", function(error, stdout, stderr) {
     console.log(stdout);
-    console.log("rm done");
-    payload+="rm done\n\n"+stdout;
 
+    payload+="rm done\n\n"+stdout;
   });//esto cierra el fifo, lo cual cierra el programa
 
   //sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'}) && cd /home/pi && ./multissh.sh sudo -E mn -c; sudo -E mn -c
+  console.log("killing all...");
   child2 = exec("sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'})", function(error, stdout, stderr) {
     console.log(stdout);
-    console.log("killed");
     payload+="killed\n\n"+stdout;
   });
-  child3 = exec("cd /home/pi && ./multissh.sh sudo -E mn -c; sudo -E mn -c", function(error, stdout, stderr) {
+  console.log("Multisshing and cleaning...");
+  child3 = exec("cd /home/pi/scripts && ./multissh.sh sudo -E mn -c; sudo -E mn -c", function(error, stdout, stderr) {
     console.log(stdout);
     console.log("multisshed");
     payload+="Multisshed\n\n"+stdout;
+
   });
   res.send(payload);
 });