blob: fb516aed2fece213b19e07d49629654ef2822bea [file] [log] [blame]
Paul Greyson8d1c6362013-03-27 13:05:24 -07001/*global d3*/
2
Paul Greyson4b4c8af2013-04-04 09:02:09 -07003function callURL(url, cb) {
Paul Greyson8d1c6362013-03-27 13:05:24 -07004 d3.text(url, function (error, result) {
5 if (error) {
Paul Greysonf7a77db2013-04-04 18:48:20 -07006 console.log(url + ' : ' + error.status);
Paul Greyson8d1c6362013-03-27 13:05:24 -07007 } else {
Paul Greyson4b4c8af2013-04-04 09:02:09 -07008 if (cb) {
9 cb(result);
10 }
Paul Greyson95db7a12013-04-04 14:57:58 -070011// console.log(result);
Paul Greyson8d1c6362013-03-27 13:05:24 -070012 }
13 });
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070014}
15
Paul Greyson472da4c2013-03-28 11:43:17 -070016function MAC(dpid) {
17 var cmps = dpid.split(':');
18 var MAC = '00:00:c0:a8:' + [cmps[6], cmps[7]].join(':');
19 return MAC;
20}
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070021
Paul Greyson8d1c6362013-03-27 13:05:24 -070022var controllerFunctions = {
Paul Greyson13f02b92013-03-28 11:29:35 -070023 linkCmd: function (cmd, link) {
Paul Greyson8d1c6362013-03-27 13:05:24 -070024 var url = '/proxy/gui/link/' + [cmd, link['src-switch'], link['src-port'], link['dst-switch'], link['dst-port']].join('/');
25 callURL(url);
26
27 },
Paul Greyson13f02b92013-03-28 11:29:35 -070028 switchCmd: function (cmd, s) {
Paul Greyson8d1c6362013-03-27 13:05:24 -070029 var url = '/proxy/gui/switch/' + [cmd, s.dpid].join('/');
30 callURL(url);
Paul Greyson2913af82013-03-27 14:53:17 -070031 },
Paul Greyson13f02b92013-03-28 11:29:35 -070032 ctrlCmd: function (cmd, c) {
Paul Greyson2913af82013-03-27 14:53:17 -070033 var url = '/proxy/gui/controller/' + [cmd, c].join('/');
34 callURL(url);
Paul Greyson13f02b92013-03-28 11:29:35 -070035 },
36 addFlowCmd: function (src, dst) {
Paul Greyson472da4c2013-03-28 11:43:17 -070037 var url = '/proxy/gui/addflow/' + [src.dpid, 1, dst.dpid, 1, MAC(src.dpid), MAC(dst.dpid)].join('/');
38 callURL(url);
Paul Greyson13f02b92013-03-28 11:29:35 -070039 },
40 delFlowCmd: function (flow) {
Jonathan Hart3888b042013-04-04 20:04:26 -070041 var url = '/proxy/gui/delflow/' + flow.flowId;
Paul Greyson6f918402013-03-28 12:18:30 -070042 callURL(url);
Paul Greyson4b4c8af2013-04-04 09:02:09 -070043 },
44 startIPerfCmd: function (flow, duration, numSamples) {
Jonathan Hart4cf35b82013-04-04 20:55:49 -070045 var flowId = parseInt(flow.flowId, 16);
Paul Greyson95db7a12013-04-04 14:57:58 -070046 var url = '/proxy/gui/iperf/start/' + [flowId, duration, numSamples].join('/');
Paul Greyson4b4c8af2013-04-04 09:02:09 -070047 callURL(url)
48 },
49 getIPerfDataCmd: function (flow, cb) {
Jonathan Hart4cf35b82013-04-04 20:55:49 -070050 var flowId = parseInt(flow.flowId, 16);
Paul Greyson4b4c8af2013-04-04 09:02:09 -070051 var url = '/proxy/gui/iperf/rate/' + flowId;
52 callURL(url, cb);
Paul Greysone6266b92013-04-09 23:15:27 -070053 },
54 switchControllerCmd: function (cmd) {
55 var url = '/proxy/gui/switchctrl/' + cmd;
56 callURL(url);
Paul Greysonb14d40d2013-04-11 12:37:30 -070057 },
58 resetCmd: function () {
59 var url = '/proxy/gui/reset';
60 callURL(url);
61 },
62 scaleCmd: function () {
63 var url = '/proxy/gui/scale';
64 callURL(url);
Paul Greyson8d1c6362013-03-27 13:05:24 -070065 }
66};
67
Paul Greyson8d1c6362013-03-27 13:05:24 -070068function linkUp(link) {
Paul Greyson13f02b92013-03-28 11:29:35 -070069 controllerFunctions.linkCmd('up', link);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070070}
71
Paul Greyson8d1c6362013-03-27 13:05:24 -070072function linkDown(link) {
Paul Greyson13f02b92013-03-28 11:29:35 -070073 controllerFunctions.linkCmd('down', link);
Paul Greyson8d1c6362013-03-27 13:05:24 -070074}
75
76function switchUp(s) {
Paul Greyson13f02b92013-03-28 11:29:35 -070077 controllerFunctions.switchCmd('up', s);
Paul Greyson8d1c6362013-03-27 13:05:24 -070078}
79
80function switchDown(s) {
Paul Greyson13f02b92013-03-28 11:29:35 -070081 controllerFunctions.switchCmd('down', s);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070082}
83
Paul Greyson2913af82013-03-27 14:53:17 -070084function controllerUp(c) {
Paul Greyson13f02b92013-03-28 11:29:35 -070085 controllerFunctions.ctrlCmd('up', c);
Paul Greyson2913af82013-03-27 14:53:17 -070086}
87
88function controllerDown(c) {
Paul Greyson13f02b92013-03-28 11:29:35 -070089 controllerFunctions.ctrlCmd('down', c);
Paul Greyson2913af82013-03-27 14:53:17 -070090}
91
Paul Greyson13f02b92013-03-28 11:29:35 -070092function addFlow(src, dst) {
93 controllerFunctions.addFlowCmd(src, dst);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070094}
95
Paul Greyson13f02b92013-03-28 11:29:35 -070096function deleteFlow(flow) {
97 controllerFunctions.delFlowCmd(flow);
Paul Greyson4b4c8af2013-04-04 09:02:09 -070098}
99
100function startIPerf(flow, duration, numSamples) {
101 controllerFunctions.startIPerfCmd(flow, duration, numSamples);
102}
103
104function getIPerfData(flow, cb) {
105 controllerFunctions.getIPerfDataCmd(flow, cb);
Jonathan Hart4cf35b82013-04-04 20:55:49 -0700106}
Paul Greysone6266b92013-04-09 23:15:27 -0700107
108function switchLocal() {
109 controllerFunctions.switchControllerCmd('local');
110}
Tim Lindbergd812fee2013-04-12 01:47:40 -0700111function switchAll() {
112 controllerFunctions.switchControllerCmd('all');
113}
Paul Greysone6266b92013-04-09 23:15:27 -0700114
Paul Greysonb14d40d2013-04-11 12:37:30 -0700115function resetNetwork() {
116 controllerFunctions.resetCmd();
117}
118
119function scaleNetwork() {
120 controllerFunctions.scaleCmd();;
Paul Greysone6266b92013-04-09 23:15:27 -0700121}
122