blob: fbc381e1c23310f470bd34f53b68189f49c51b8c [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 Greyson8d1c6362013-03-27 13:05:24 -070053 }
54};
55
Paul Greyson8d1c6362013-03-27 13:05:24 -070056function linkUp(link) {
Paul Greyson13f02b92013-03-28 11:29:35 -070057 controllerFunctions.linkCmd('up', link);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070058}
59
Paul Greyson8d1c6362013-03-27 13:05:24 -070060function linkDown(link) {
Paul Greyson13f02b92013-03-28 11:29:35 -070061 controllerFunctions.linkCmd('down', link);
Paul Greyson8d1c6362013-03-27 13:05:24 -070062}
63
64function switchUp(s) {
Paul Greyson13f02b92013-03-28 11:29:35 -070065 controllerFunctions.switchCmd('up', s);
Paul Greyson8d1c6362013-03-27 13:05:24 -070066}
67
68function switchDown(s) {
Paul Greyson13f02b92013-03-28 11:29:35 -070069 controllerFunctions.switchCmd('down', s);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070070}
71
Paul Greyson2913af82013-03-27 14:53:17 -070072function controllerUp(c) {
Paul Greyson13f02b92013-03-28 11:29:35 -070073 controllerFunctions.ctrlCmd('up', c);
Paul Greyson2913af82013-03-27 14:53:17 -070074}
75
76function controllerDown(c) {
Paul Greyson13f02b92013-03-28 11:29:35 -070077 controllerFunctions.ctrlCmd('down', c);
Paul Greyson2913af82013-03-27 14:53:17 -070078}
79
Paul Greyson13f02b92013-03-28 11:29:35 -070080function addFlow(src, dst) {
81 controllerFunctions.addFlowCmd(src, dst);
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070082}
83
Paul Greyson13f02b92013-03-28 11:29:35 -070084function deleteFlow(flow) {
85 controllerFunctions.delFlowCmd(flow);
Paul Greyson4b4c8af2013-04-04 09:02:09 -070086}
87
88function startIPerf(flow, duration, numSamples) {
89 controllerFunctions.startIPerfCmd(flow, duration, numSamples);
90}
91
92function getIPerfData(flow, cb) {
93 controllerFunctions.getIPerfDataCmd(flow, cb);
Jonathan Hart4cf35b82013-04-04 20:55:49 -070094}