3 } = require('express');
4 const router = new Router();
8 //renders de las paginas web
9 router.get("/", (req, res) => {
13 router.get("/access", (req, res) => {
17 router.get("/starter", (req, res) => {
21 router.get("/stats", (req, res) => {
25 router.get("/topology", (req, res) => {
26 res.render("topology")
28 let isVsorcUP = false;
29 let isControllerUP = false;
30 router.get("/topologyMaker", (req, res) => {
31 res.render("topologyMaker")
33 //en lo adelante se encuentran las peticiones de datos
34 router.get('/free', (req, res) => {
35 var sys = require('sys')
36 var exec = require('child_process').exec;
38 child = exec("free -b | grep Mem | awk '{print $3}'", function(error, stdout, stderr) {
44 router.post('/flowdel', (req, res) => {
45 var sys = require('sys')
46 var exec = require('child_process').exec;
48 var flow = JSON.stringify(req.body);
49 child = exec("curl -X POST -d "+req.body+"localhost:8080/flowdel", function(error, stdout, stderr) {
51 console.log(req.body);
57 router.get('/mpstat', (req, res) => {
58 var sys = require('sys')
59 var exec = require('child_process').exec;
61 child = exec("mpstat 1 1| grep all | grep Average | awk '{print $12}'", function(error, stdout, stderr) {
62 console.log("mpstat");
67 router.get('/ifstat', (req, res) => {
68 var sys = require('sys')
69 var exec = require('child_process').exec;
71 child = exec("ifstat -n -b -i eth0 0.3 1 | grep [0-9]$", function(error, stdout, stderr) {
72 console.log("ifstat");
77 router.get('/showtemp', (req, res) => {
78 var sys = require('sys')
79 var exec = require('child_process').exec;
81 child = exec("cd /home/pi/scripts && (./multissh.sh \"$(echo $(cat geteverything.sh))\" |grep -v rpi | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4)", function(error, stdout, stderr) {
82 console.log("show temp");//this was modified
86 router.get('/gettopo', (req, res) => {
87 var sys = require('sys')
88 var exec = require('child_process').exec;
90 child = exec("curl localhost:8080/topology", function(error, stdout, stderr) {
91 console.log("gettopo");
96 router.get('/net', (req, res) => {
97 var sys = require('sys')
98 var exec = require('child_process').exec;
100 child = exec("cd /home/pi/scripts && echo net > fifo", function(error, stdout, stderr) {
106 router.get('/rpiping', (req, res) => {
107 var sys = require('sys')
108 var exec = require('child_process').exec;
110 child = exec("cd /home/pi/scripts && ./rpiping.sh", function(error, stdout, stderr) {
111 console.log("rpiping");
116 router.get('/nodes', (req, res) => {
117 var sys = require('sys')
118 var exec = require('child_process').exec;
120 child = exec("cd /home/pi/scripts && echo nodes > fifo", function(error, stdout, stderr) {
121 console.log("nodes");
126 router.get('/statusnodes', (req, res) => {
127 var sys = require('sys')
128 var exec = require('child_process').exec;
130 child = exec("cd /home/pi/scripts && echo status > fifo", function(error, stdout, stderr) {
131 console.log("status");
136 router.get('/intfs', (req, res) => {
137 var sys = require('sys')
138 var exec = require('child_process').exec;
140 child = exec("cd /home/pi/scripts && echo intfs > fifo", function(error, stdout, stderr) {
141 console.log("interfaces");
146 router.get('/iperf', (req, res) => {
147 var sys = require('sys')
148 var exec = require('child_process').exec;
150 child = exec("cd /home/pi/scripts && echo iperf > fifo", function(error, stdout, stderr) {
151 console.log("pingall");
156 router.get('/pingall', (req, res) => {
157 var sys = require('sys')
158 var exec = require('child_process').exec;
160 child = exec("cd /home/pi/scripts && echo pingall > fifo", function(error, stdout, stderr) {
161 console.log("pingall");
165 router.get('/placement', (req, res) => {
166 var sys = require('sys')
167 var exec = require('child_process').exec;
169 child = exec("cd /home/pi/scripts && echo placement > fifo", function(error, stdout, stderr) {
170 console.log("placement");
175 router.get('/getvsorcdata', (req, res) => {
177 var sys = require('sys')
178 var exec = require('child_process').exec;
181 child2 = exec("ps aux | grep GRE| grep sudo | grep -v tail| awk {'print $2'}", function(error, stdout, stderr) {
182 console.log("view status vsorc");
189 child = exec("cd /home/pi/scripts && cat aichivo 2>/dev/null", function(error, stdout, stderr) {
190 console.log("getting vsorc data");
191 res.send(stdout+"^"+isVsorcUP);
194 router.get('/getcontrollerdata', (req, res) => {
195 var sys = require('sys')
196 var exec = require('child_process').exec;
199 child2 = exec("ps aux | grep python | grep ryu | grep -v grep |awk {'print $2'}", function(error, stdout, stderr) {
201 console.log("view status controller");
203 isControllerUP = false;
205 isControllerUP = true;
208 child = exec("cd /home/pi/scripts && cat controllerout 2>/dev/null", function(error, stdout, stderr) {
209 console.log("getting controller data");
210 res.send(stdout+"^"+isControllerUP);//Send controller data and UP or DOWN separate by ^
216 router.get('/resetflows', (req, res) => {
217 var sys = require('sys')
218 var exec = require('child_process').exec;
222 child = exec("curl localhost:8080/data?list=switches", function(error, stdout, stderr) {
225 value = JSON.parse(stdout);
227 child2 = exec("cd /home/pi/scripts && ./resetflows.sh "+key, function(err, out, stder){
233 if (stdout === undifined){
234 res.send("Switches not found");
240 //console.error(error);
241 console.log("no response from server");
242 // expected output: ReferenceError: nonExistentFunction is not def$
243 // Note - error messages will vary depending on browser
244 res.send("No response from server");
250 router.get('/listswitch', (req, res) => {
251 var sys = require('sys')
252 var exec = require('child_process').exec;
254 child = exec("curl localhost:8080/data?list=switches", function(error, stdout, stderr) {
255 console.log("listswitch");
259 value = JSON.parse(stdout)
263 //console.error(error);
264 console.log("no response from controller");
265 // expected output: ReferenceError: nonExistentFunction is not defined
266 // Note - error messages will vary depending on browser
272 router.get('/status', (req, res) => {
273 var sys = require('sys')
274 var exec = require('child_process').exec;
276 console.log(req.query.status+req.query.dpid);
277 child = exec("curl \"localhost:8080/status?status="+req.query.status+"&dpid="+req.query.dpid+"\"", function(error, stdout, stderr) {
278 console.log("statusFlows");
280 let value = JSON.parse(stdout)
286 router.get('/tablestatus', (req, res) => {
287 var sys = require('sys')
288 var exec = require('child_process').exec;
290 console.log(req.query);
291 child = exec("curl \"localhost:8080/data?tablestat="+req.query.tablestat+"\"", function(error, stdout, stderr) {
292 console.log("table status");
296 value = JSON.parse(stdout)
300 //console.error(error);
301 console.log("no response from server");
302 // expected output: ReferenceError: nonExistentFunction is not defined
303 // Note - error messages will vary depending on browser
304 let er = "No response from server";
305 res.send(JSON.stringify(er));
310 router.get('/portsdesc', (req, res) => {
311 var sys = require('sys')
312 var exec = require('child_process').exec;
314 console.log(req.query);
315 child = exec("curl \"localhost:8080/data?portdesc="+req.query.portdesc+"\"", function(error, stdout, stderr) {
316 console.log("port desc");
319 value = JSON.parse(stdout)
323 //console.error(error);
324 console.log("no response from server");
325 // expected output: ReferenceError: nonExistentFunction is not defined
326 // Note - error messages will vary depending on browser
327 let er = "No response from server";
328 res.send(JSON.stringify(er));
333 router.get('/portsstat', (req, res) => {
334 var sys = require('sys')
335 var exec = require('child_process').exec;
337 console.log(req.query);
338 child = exec("curl \"localhost:8080/data?portstat="+req.query.portstat+"\"", function(error, stdout, stderr) {
339 console.log("port status");
343 value = JSON.parse(stdout)
347 //console.error(error);
348 console.log("no response from server");
349 // expected output: ReferenceError: nonExistentFunction is not defined
350 // Note - error messages will vary depending on browser
351 let er = "No response from server";
352 res.send(JSON.stringify(er));
357 router.get('/startcontroller', (req, res) => {
358 isControllerUP = true;
359 var sys = require('sys')
360 var exec = require('child_process').exec;
362 //cd /home/pi && setsid $(cat /home/pi/ejecutarcontroller.sh | grep sudo) >/dev/null 2>&1 < /dev/null &
363 //cd /home/pi && ./ejecutarcontroller.sh > /dev/null 2>&1 < /dev/null & //comando anterior
364 child = exec("cd /home/pi/scripts && touch controllerout && ./ejecutarcontroller.sh > controllerout 2>&1 &", function(error, stdout, stderr) {
365 console.log("controller started");
370 router.get('/startcontrollerrouter', (req, res) => {
371 isControllerUP = true;
372 var sys = require('sys')
373 var exec = require('child_process').exec;
375 child = exec("cd /home/pi/scripts && touch controllerout && ./ryurouter.sh > controllerout 2>&1 &", function(error, stdout, stderr) {
376 console.log("controller REST Router started");
381 router.get('/stopcontroller', (req, res) => {
382 isControllerUP = false;
383 var sys = require('sys')
384 var exec = require('child_process').exec;
386 child = exec("cd /home/pi/scripts && rm controllerout && sudo kill $(ps aux | grep python | grep ryu | awk {'print $2'})", function(error, stdout, stderr) {
387 console.log("controller stopped");
391 router.get('/sendcommand', (req, res) => {
392 var sys = require('sys')
393 var exec = require('child_process').exec;
395 console.log(req.query);
396 // request = JSON.parse(req.query.cmd); //recibiendo el comando
398 // console.log(request);
399 child = exec("cd /home/pi/scripts && echo "+req.query.cmd+" > fifo", function(error, stdout, stderr) {
400 console.log("command received \n" + req.query.cmd+"\n");
404 router.get('/cancel', (req, res) => {
405 var sys = require('sys')
406 var exec = require('child_process').exec;
408 child = exec("sudo kill -2 $(ps aux | grep GRE| grep sudo|awk {'print $2'})", function(error, stdout, stderr) {
409 console.log("cancelled");
413 router.get('/startvsorc', (req, res) => {
415 var sys = require('sys')
416 var exec = require('child_process').exec;
417 var child0;//needs a mkfifo named fifo to exist
423 request = JSON.parse(req.query.topology)
424 console.log("Topology is : \n"+ request);
425 //controlar que solo se haga un arranque por vez y agregar el exec 3>fifo
426 child0 = exec("cd /home/pi/scripts && echo \""+request+"\" > data", function(error, stdout, stderr) {
427 console.log(stdout + stderr);
430 child1 = exec("cd /home/pi/scripts && mkfifo fifo && rm aichivo && touch aichivo", function(error, stdout, stderr) {
431 console.log(stdout + stderr);
434 child2 = exec("cd /home/pi/scripts && exec 3>fifo", function(error, stdout, stderr) {
435 console.log(stdout + stderr);
440 //child3 uses tail so it can read from fifo even after a EOF
441 child3 = exec("cd /home/pi/scripts && tail -n +1 -f fifo | sudo ./clusterGRE.py > aichivo 2>&1 &", function(error, stdout, stderr) {
442 console.log(stdout + stderr);
448 router.get('/stopvsorc', (req,res) =>{
450 var sys = require('sys')
451 var exec = require('child_process').exec;
456 console.log("erasing...");
457 child1 = exec("cd /home/pi/scripts && exec 3>&- ", function(error, stdout, stderr) {
460 payload+="rm done\n\n"+stdout;
461 });//esto cierra el fifo, lo cual cierra el programa
463 //antes, en ves de echo exit > fifo, estaba sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'})
464 console.log("Exiting...");
465 child2 = exec("cd /home/pi/scripts && echo exit > fifo && rm fifo && sudo killall tail", function(error, stdout, stderr) {
467 payload+="killed\n\n"+stdout;
469 // console.log("Multisshing and cleaning...");
470 // child3 = exec("cd /home/pi/scripts && ./multissh.sh sudo -E mn -c; sudo -E mn -c", function(error, stdout, stderr) {
471 // console.log(stdout);
472 // console.log("multisshed");
473 // payload+="Multisshed\n\n"+stdout;
478 module.exports = router;