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 | e6266b9 | 2013-04-09 23:15:27 -0700 | [diff] [blame] | 53 | }, |
| 54 | switchControllerCmd: function (cmd) { |
| 55 | var url = '/proxy/gui/switchctrl/' + cmd; |
| 56 | callURL(url); |
Paul Greyson | b14d40d | 2013-04-11 12:37:30 -0700 | [diff] [blame] | 57 | }, |
| 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 Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 65 | } |
| 66 | }; |
| 67 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 68 | function linkUp(link) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 69 | controllerFunctions.linkCmd('up', link); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 72 | function linkDown(link) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 73 | controllerFunctions.linkCmd('down', link); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | function switchUp(s) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 77 | controllerFunctions.switchCmd('up', s); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | function switchDown(s) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 81 | controllerFunctions.switchCmd('down', s); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 84 | function controllerUp(c) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 85 | controllerFunctions.ctrlCmd('up', c); |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | function controllerDown(c) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 89 | controllerFunctions.ctrlCmd('down', c); |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 92 | function addFlow(src, dst) { |
| 93 | controllerFunctions.addFlowCmd(src, dst); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame] | 96 | function deleteFlow(flow) { |
| 97 | controllerFunctions.delFlowCmd(flow); |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | function startIPerf(flow, duration, numSamples) { |
| 101 | controllerFunctions.startIPerfCmd(flow, duration, numSamples); |
| 102 | } |
| 103 | |
| 104 | function getIPerfData(flow, cb) { |
| 105 | controllerFunctions.getIPerfDataCmd(flow, cb); |
Jonathan Hart | 4cf35b8 | 2013-04-04 20:55:49 -0700 | [diff] [blame] | 106 | } |
Paul Greyson | e6266b9 | 2013-04-09 23:15:27 -0700 | [diff] [blame] | 107 | |
| 108 | function switchLocal() { |
| 109 | controllerFunctions.switchControllerCmd('local'); |
| 110 | } |
Tim Lindberg | d812fee | 2013-04-12 01:47:40 -0700 | [diff] [blame] | 111 | function switchAll() { |
| 112 | controllerFunctions.switchControllerCmd('all'); |
| 113 | } |
Paul Greyson | e6266b9 | 2013-04-09 23:15:27 -0700 | [diff] [blame] | 114 | |
Paul Greyson | b14d40d | 2013-04-11 12:37:30 -0700 | [diff] [blame] | 115 | function resetNetwork() { |
| 116 | controllerFunctions.resetCmd(); |
| 117 | } |
| 118 | |
| 119 | function scaleNetwork() { |
| 120 | controllerFunctions.scaleCmd();; |
Paul Greyson | e6266b9 | 2013-04-09 23:15:27 -0700 | [diff] [blame] | 121 | } |
| 122 | |