blob: fd3f6ae092229d8c2d198e7ffa7be50b0e1b5558 [file] [log] [blame]
Paul Greyson8d1c6362013-03-27 13:05:24 -07001/*global d3*/
2
3function callURL(url) {
4 d3.text(url, function (error, result) {
5 if (error) {
6 alert(url + ' : ' + error.status);
7 } else {
8 console.log(result);
9 }
10 });
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070011}
12
Paul Greyson472da4c2013-03-28 11:43:17 -070013function MAC(dpid) {
14 var cmps = dpid.split(':');
15 var MAC = '00:00:c0:a8:' + [cmps[6], cmps[7]].join(':');
16 return MAC;
17}
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070018
Paul Greyson8d1c6362013-03-27 13:05:24 -070019var controllerFunctions = {
Paul Greyson13f02b92013-03-28 11:29:35 -070020 linkCmd: function (cmd, link) {
Paul Greyson8d1c6362013-03-27 13:05:24 -070021 var url = '/proxy/gui/link/' + [cmd, link['src-switch'], link['src-port'], link['dst-switch'], link['dst-port']].join('/');
22 callURL(url);
23
24 },
Paul Greyson13f02b92013-03-28 11:29:35 -070025 switchCmd: function (cmd, s) {
Paul Greyson8d1c6362013-03-27 13:05:24 -070026 var url = '/proxy/gui/switch/' + [cmd, s.dpid].join('/');
27 callURL(url);
Paul Greyson2913af82013-03-27 14:53:17 -070028 },
Paul Greyson13f02b92013-03-28 11:29:35 -070029 ctrlCmd: function (cmd, c) {
Paul Greyson2913af82013-03-27 14:53:17 -070030 var url = '/proxy/gui/controller/' + [cmd, c].join('/');
31 callURL(url);
Paul Greyson13f02b92013-03-28 11:29:35 -070032 },
33 addFlowCmd: function (src, dst) {
Paul Greyson472da4c2013-03-28 11:43:17 -070034 var url = '/proxy/gui/addflow/' + [src.dpid, 1, dst.dpid, 1, MAC(src.dpid), MAC(dst.dpid)].join('/');
35 callURL(url);
Paul Greyson13f02b92013-03-28 11:29:35 -070036 },
37 delFlowCmd: function (flow) {
Paul Greyson6f918402013-03-28 12:18:30 -070038 var url = '/proxy/gui/delflow/' + flow.flowId.value;
39 callURL(url);
Paul Greyson8d1c6362013-03-27 13:05:24 -070040 }
41};
42
Paul Greyson8d1c6362013-03-27 13:05:24 -070043function linkUp(link) {
Paul Greyson13f02b92013-03-28 11:29:35 -070044 controllerFunctions.linkCmd('up', link);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070045}
46
Paul Greyson8d1c6362013-03-27 13:05:24 -070047function linkDown(link) {
Paul Greyson13f02b92013-03-28 11:29:35 -070048 controllerFunctions.linkCmd('down', link);
Paul Greyson8d1c6362013-03-27 13:05:24 -070049}
50
51function switchUp(s) {
Paul Greyson13f02b92013-03-28 11:29:35 -070052 controllerFunctions.switchCmd('up', s);
Paul Greyson8d1c6362013-03-27 13:05:24 -070053}
54
55function switchDown(s) {
Paul Greyson13f02b92013-03-28 11:29:35 -070056 controllerFunctions.switchCmd('down', s);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070057}
58
Paul Greyson2913af82013-03-27 14:53:17 -070059function controllerUp(c) {
Paul Greyson13f02b92013-03-28 11:29:35 -070060 controllerFunctions.ctrlCmd('up', c);
Paul Greyson2913af82013-03-27 14:53:17 -070061}
62
63function controllerDown(c) {
Paul Greyson13f02b92013-03-28 11:29:35 -070064 controllerFunctions.ctrlCmd('down', c);
Paul Greyson2913af82013-03-27 14:53:17 -070065}
66
Paul Greyson13f02b92013-03-28 11:29:35 -070067function addFlow(src, dst) {
68 controllerFunctions.addFlowCmd(src, dst);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070069}
70
Paul Greyson13f02b92013-03-28 11:29:35 -070071function deleteFlow(flow) {
72 controllerFunctions.delFlowCmd(flow);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070073}