3 } = require('express');
4 const router = new Router();
7 //renders de las paginas web
8 router.get("/", (req, res) => {
12 router.get("/access", (req, res) => {
16 router.get("/starter", (req, res) => {
20 router.get("/stats", (req, res) => {
24 router.get("/topology", (req, res) => {
25 res.render("topology")
28 router.get("/topologyMaker", (req, res) => {
29 res.render("topologyMaker")
31 //en lo adelante se encuentran las peticiones de datos
32 router.get('/free', (req, res) => {
33 var sys = require('sys')
34 var exec = require('child_process').exec;
36 child = exec("free -b | grep Mem | awk '{print $3}'", function(error, stdout, stderr) {
43 router.get('/mpstat', (req, res) => {
44 var sys = require('sys')
45 var exec = require('child_process').exec;
47 child = exec("mpstat 1 1| grep all | grep Average | awk '{print $12}'", function(error, stdout, stderr) {
48 console.log("mpstat");
54 router.get('/ifstat', (req, res) => {
55 var sys = require('sys')
56 var exec = require('child_process').exec;
58 child = exec("ifstat -n -b -i eth0 0.3 1 | grep [0-9]$", function(error, stdout, stderr) {
59 console.log("ifstat");
64 router.get('/showtemp', (req, res) => {
65 var sys = require('sys')
66 var exec = require('child_process').exec;
68 child = exec("cd /home/pi/scripts && ./gettemp.sh", function(error, stdout, stderr) {
69 console.log("show temp");
73 router.get('/gettopo', (req, res) => {
74 var sys = require('sys')
75 var exec = require('child_process').exec;
77 child = exec("curl localhost:8080/topology", function(error, stdout, stderr) {
78 console.log("gettopo");
83 router.get('/net', (req, res) => {
84 var sys = require('sys')
85 var exec = require('child_process').exec;
87 child = exec("cd /home/pi/scripts && echo net > fifo", function(error, stdout, stderr) {
93 router.get('/nodes', (req, res) => {
94 var sys = require('sys')
95 var exec = require('child_process').exec;
97 child = exec("cd /home/pi/scripts && echo nodes > fifo", function(error, stdout, stderr) {
103 router.get('/statusnodes', (req, res) => {
104 var sys = require('sys')
105 var exec = require('child_process').exec;
107 child = exec("cd /home/pi/scripts && echo status > fifo", function(error, stdout, stderr) {
108 console.log("status");
113 router.get('/intfs', (req, res) => {
114 var sys = require('sys')
115 var exec = require('child_process').exec;
117 child = exec("cd /home/pi/scripts && echo intfs > fifo", function(error, stdout, stderr) {
118 console.log("interfaces");
123 router.get('/iperf', (req, res) => {
124 var sys = require('sys')
125 var exec = require('child_process').exec;
127 child = exec("cd /home/pi/scripts && echo iperf > fifo", function(error, stdout, stderr) {
128 console.log("pingall");
133 router.get('/pingall', (req, res) => {
134 var sys = require('sys')
135 var exec = require('child_process').exec;
137 child = exec("cd /home/pi/scripts && echo pingall > fifo", function(error, stdout, stderr) {
138 console.log("pingall");
142 router.get('/placement', (req, res) => {
143 var sys = require('sys')
144 var exec = require('child_process').exec;
146 child = exec("cd /home/pi/scripts && echo placement > fifo", function(error, stdout, stderr) {
147 console.log("placement");
152 router.get('/getvsorcdata', (req, res) => {
153 var sys = require('sys')
154 var exec = require('child_process').exec;
156 child = exec("cd /home/pi/scripts && cat aichivo 2>&1", function(error, stdout, stderr) {
157 console.log("getting vsorc data");
161 router.get('/getcontrollerdata', (req, res) => {
162 var sys = require('sys')
163 var exec = require('child_process').exec;
165 child = exec("cd /home/pi/scripts && cat controllerout 2>&1", function(error, stdout, stderr) {
166 console.log("getting controller data");
170 router.get('/listswitch', (req, res) => {
171 var sys = require('sys')
172 var exec = require('child_process').exec;
174 child = exec("curl localhost:8080/data?list=switches", function(error, stdout, stderr) {
175 console.log("listswitch");
179 value = JSON.parse(stdout)
182 console.error(error);
183 console.log("no response from server");
184 // expected output: ReferenceError: nonExistentFunction is not defined
185 // Note - error messages will vary depending on browser
192 router.get('/status', (req, res) => {
193 var sys = require('sys')
194 var exec = require('child_process').exec;
196 console.log(req.query.status+req.query.dpid);
197 child = exec("curl \"localhost:8080/status?status="+req.query.status+"&dpid="+req.query.dpid+"\"", function(error, stdout, stderr) {
198 console.log("statusFlows");
200 let value = JSON.parse(stdout)
207 router.get('/startcontroller', (req, res) => {
208 var sys = require('sys')
209 var exec = require('child_process').exec;
211 //cd /home/pi && setsid $(cat /home/pi/ejecutarcontroller.sh | grep sudo) >/dev/null 2>&1 < /dev/null &
212 //cd /home/pi && ./ejecutarcontroller.sh > /dev/null 2>&1 < /dev/null & //comando anterior
213 child = exec("cd /home/pi/scripts && touch controllerout && ./ejecutarcontroller.sh > controllerout 2>&1 &", function(error, stdout, stderr) {
214 console.log("controller started");
219 router.get('/stopcontroller', (req, res) => {
220 var sys = require('sys')
221 var exec = require('child_process').exec;
223 child = exec("cd /home/pi/scripts && rm controllerout && sudo kill $(ps aux | grep python | grep ryu | awk {'print $2'})", function(error, stdout, stderr) {
224 console.log("controller stopped");
229 router.get('/startvsorc', (req, res) => {
230 var sys = require('sys')
231 var exec = require('child_process').exec;
232 var child0;//needs a mkfifo named fifo to exist
237 request = JSON.parse(req.query.topology)
238 console.log("Topology is : \n"+ request);
239 //controlar que solo se haga un arranque por vez y agregar el exec 3>fifo
240 child0 = exec("cd /home/pi/scripts && echo \""+request+"\" > data", function(error, stdout, stderr) {
241 console.log(stdout + stderr);
244 child1 = exec("cd /home/pi/scripts && mkfifo fifo && touch aichivo", function(error, stdout, stderr) {
245 console.log(stdout + stderr);
248 child2 = exec("cd /home/pi/scripts && exec 3>fifo", function(error, stdout, stderr) {
249 console.log(stdout + stderr);
252 //child3 uses tail so it can read from fifo even after a EOF
253 child3 = exec("cd /home/pi/scripts && tail -n +1 -f fifo | sudo ./clusterGRE.py > aichivo 2>&1 &", function(error, stdout, stderr) {
254 console.log(stdout + stderr);
260 router.get('/stopvsorc', (req,res) =>{
261 var sys = require('sys')
262 var exec = require('child_process').exec;
267 console.log("erasing...");
268 child1 = exec("cd /home/pi/scripts && exec 3>&- && rm fifo && rm aichivo", function(error, stdout, stderr) {
271 payload+="rm done\n\n"+stdout;
272 });//esto cierra el fifo, lo cual cierra el programa
274 //sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'}) && cd /home/pi && ./multissh.sh sudo -E mn -c; sudo -E mn -c
275 console.log("killing all...");
276 child2 = exec("sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'})", function(error, stdout, stderr) {
278 payload+="killed\n\n"+stdout;
280 console.log("Multisshing and cleaning...");
281 child3 = exec("cd /home/pi/scripts && ./multissh.sh sudo -E mn -c; sudo -E mn -c", function(error, stdout, stderr) {
283 console.log("multisshed");
284 payload+="Multisshed\n\n"+stdout;
289 module.exports = router;