Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 1 | /*global d3*/ |
| 2 | |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 3 | function callURL(url, cb) { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 4 | d3.text(url, function (error, result) { |
| 5 | if (error) { |
Paul Greyson | f7a77db | 2013-04-04 18:48:20 -0700 | [diff] [blame] | 6 | console.log(url + ' : ' + error.status); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 7 | } else { |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 8 | if (cb) { |
| 9 | cb(result); |
| 10 | } |
Paul Greyson | 95db7a1 | 2013-04-04 14:57:58 -0700 | [diff] [blame] | 11 | // console.log(result); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 12 | } |
| 13 | }); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 14 | } |
| 15 | |
Paul Greyson | 472da4c | 2013-03-28 11:43:17 -0700 | [diff] [blame] | 16 | function MAC(dpid) { |
| 17 | var cmps = dpid.split(':'); |
| 18 | var MAC = '00:00:c0:a8:' + [cmps[6], cmps[7]].join(':'); |
| 19 | return MAC; |
| 20 | } |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 21 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 22 | var controllerFunctions = { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 23 | linkCmd: function (cmd, link) { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 24 | 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 Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 28 | switchCmd: function (cmd, s) { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 29 | var url = '/proxy/gui/switch/' + [cmd, s.dpid].join('/'); |
| 30 | callURL(url); |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 31 | }, |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 32 | ctrlCmd: function (cmd, c) { |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 33 | var url = '/proxy/gui/controller/' + [cmd, c].join('/'); |
| 34 | callURL(url); |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 35 | }, |
| 36 | addFlowCmd: function (src, dst) { |
Paul Greyson | 472da4c | 2013-03-28 11:43:17 -0700 | [diff] [blame] | 37 | var url = '/proxy/gui/addflow/' + [src.dpid, 1, dst.dpid, 1, MAC(src.dpid), MAC(dst.dpid)].join('/'); |
| 38 | callURL(url); |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 39 | }, |
| 40 | delFlowCmd: function (flow) { |
Jonathan Hart | 3888b04 | 2013-04-04 20:04:26 -0700 | [diff] [blame] | 41 | var url = '/proxy/gui/delflow/' + flow.flowId; |
Paul Greyson | 6f91840 | 2013-03-28 12:18:30 -0700 | [diff] [blame] | 42 | callURL(url); |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 43 | }, |
| 44 | startIPerfCmd: function (flow, duration, numSamples) { |
Jonathan Hart | 4cf35b8 | 2013-04-04 20:55:49 -0700 | [diff] [blame] | 45 | var flowId = parseInt(flow.flowId, 16); |
Paul Greyson | 95db7a1 | 2013-04-04 14:57:58 -0700 | [diff] [blame] | 46 | var url = '/proxy/gui/iperf/start/' + [flowId, duration, numSamples].join('/'); |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 47 | callURL(url) |
| 48 | }, |
| 49 | getIPerfDataCmd: function (flow, cb) { |
Jonathan Hart | 4cf35b8 | 2013-04-04 20:55:49 -0700 | [diff] [blame] | 50 | var flowId = parseInt(flow.flowId, 16); |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 51 | var url = '/proxy/gui/iperf/rate/' + flowId; |
| 52 | callURL(url, cb); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 56 | function linkUp(link) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 57 | controllerFunctions.linkCmd('up', link); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 60 | function linkDown(link) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 61 | controllerFunctions.linkCmd('down', link); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | function switchUp(s) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 65 | controllerFunctions.switchCmd('up', s); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | function switchDown(s) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 69 | controllerFunctions.switchCmd('down', s); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 72 | function controllerUp(c) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 73 | controllerFunctions.ctrlCmd('up', c); |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | function controllerDown(c) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 77 | controllerFunctions.ctrlCmd('down', c); |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 80 | function addFlow(src, dst) { |
| 81 | controllerFunctions.addFlowCmd(src, dst); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 84 | function deleteFlow(flow) { |
| 85 | controllerFunctions.delFlowCmd(flow); |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | function startIPerf(flow, duration, numSamples) { |
| 89 | controllerFunctions.startIPerfCmd(flow, duration, numSamples); |
| 90 | } |
| 91 | |
| 92 | function getIPerfData(flow, cb) { |
| 93 | controllerFunctions.getIPerfDataCmd(flow, cb); |
Jonathan Hart | 4cf35b8 | 2013-04-04 20:55:49 -0700 | [diff] [blame] | 94 | } |