blob: 6577fea2797aeda244f0b68ec53b64dfb7ac0cfb [file] [log] [blame]
Paul Greyson6f86d1e2013-03-18 14:40:39 -07001/*global async, d3*/
2
3function toD3(results) {
4 var model = {
Paul Greyson740bdaf2013-03-18 16:10:48 -07005 edgeSwitches: [],
Paul Greyson6f86d1e2013-03-18 14:40:39 -07006 aggregationSwitches: [],
Paul Greyson952ccb62013-03-18 22:22:08 -07007 coreSwitches: [],
Paul Greysonbcd3c772013-03-21 13:16:44 -07008 flows: [],
Paul Greysond1a22d92013-03-19 12:15:19 -07009 controllers: results.controllers,
Paul Greysonbcd3c772013-03-21 13:16:44 -070010 activeControllers: results.activeControllers,
Paul Greysond1a22d92013-03-19 12:15:19 -070011 links: results.links
Paul Greyson6f86d1e2013-03-18 14:40:39 -070012 }
13
Paul Greysonde7fad52013-03-19 12:47:32 -070014 // sort the switches
15 results.switches.sort(function (a, b) {
16 var aA = a.dpid.split(':');
17 var bB = b.dpid.split(':');
18 for (var i=0; i<aA.length; i+=1) {
19 if (aA[i] != bB[i]) {
Paul Greyson832d2202013-03-21 13:27:56 -070020 return parseInt(aA[i], 16) - parseInt(bB[i], 16);
Paul Greysonde7fad52013-03-19 12:47:32 -070021 }
22 }
23 return 0;
24 });
Paul Greyson6f86d1e2013-03-18 14:40:39 -070025
26 // identify switch types
27 var coreSwitchDPIDs = {};
28 results.configuration.core.forEach(function (dpid) {
29 coreSwitchDPIDs[dpid] = true;
30 });
31
32 var aggregationSwitchDPIDs = {};
33 results.configuration.aggregation.forEach(function (dpid) {
34 aggregationSwitchDPIDs[dpid] = true;
35 });
36
37 results.switches.forEach(function (s) {
Paul Greysonde7fad52013-03-19 12:47:32 -070038 s.controller = results.mapping[s.dpid][0].controllerId;
Paul Greysond1a22d92013-03-19 12:15:19 -070039
Paul Greyson6f86d1e2013-03-18 14:40:39 -070040 if (coreSwitchDPIDs[s.dpid]) {
41 model.coreSwitches.push(s);
42 } else if (aggregationSwitchDPIDs[s.dpid]) {
43 model.aggregationSwitches.push(s);
44 } else {
Paul Greyson740bdaf2013-03-18 16:10:48 -070045 model.edgeSwitches.push(s);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070046 }
47 });
48
49 return model;
50}
51
Paul Greysonbcd3c772013-03-21 13:16:44 -070052var urls = {
53 links: '/wm/core/topology/links/json',
54 switches: '/wm/core/topology/switches/all/json',
55 flows: '/wm/flow/getall/json',
56 activeControllers: '/wm/registry/controllers/json',
Ubuntue23620c2013-03-23 01:14:43 +000057 controllers: 'data/controllers.json',
Paul Greysonbcd3c772013-03-21 13:16:44 -070058 mapping: '/wm/registry/switches/json',
59 configuration: 'data/configuration.json'
60}
61
62var mockURLs = {
63 links: 'data/wm_core_topology_links_json.json',
64 switches: 'data/wm_core_topology_switches_all_json.json',
65 flows: 'data/wm_flow_getall_json.json',
66 activeControllers: 'data/wm_registry_controllers_json.json',
Paul Greysonc3e21a02013-03-21 13:56:05 -070067 controllers: 'data/controllers.json',
Paul Greysonbcd3c772013-03-21 13:16:44 -070068 mapping: 'data/wm_registry_switches_json.json',
69 configuration: 'data/configuration.json'
70}
71
72var proxyURLs = {
73 links: '/proxy/wm/core/topology/links/json',
74 switches: '/proxy/wm/core/topology/switches/all/json',
75 flows: '/proxy/wm/flow/getall/json',
76 activeControllers: '/proxy/wm/registry/controllers/json',
77 controllers: 'data/controllers.json',
78 mapping: '/proxy/wm/registry/switches/json',
79 configuration: 'data/configuration.json'
80}
81
82var params = parseURLParameters();
83if (params.mock) {
84 urls = mockURLs;
85}
86if (params.proxy) {
87 urls = proxyURLs;
88}
89
90function makeRequest(url) {
91 return function (cb) {
92 d3.json(url, function (error, result) {
93 if (error) {
94 error = url + ' : ' + error.status;
95 }
96
97 cb(error, result);
98 });
99 }
100}
101
102
Paul Greyson6f86d1e2013-03-18 14:40:39 -0700103function updateModel(cb) {
104 async.parallel({
Paul Greysonbcd3c772013-03-21 13:16:44 -0700105 links: makeRequest(urls.links),
106 switches: makeRequest(urls.switches),
107 controllers: makeRequest(urls.controllers),
108 activeControllers: makeRequest(urls.activeControllers),
109 mapping: makeRequest(urls.mapping),
110 configuration: makeRequest(urls.configuration)
111// flows: makeRequest(urls.flows),
Paul Greyson6f86d1e2013-03-18 14:40:39 -0700112 },
113 function(err, results) {
Paul Greysonbcd3c772013-03-21 13:16:44 -0700114 if (!err) {
115 var model = toD3(results);
116 cb(model);
117 } else {
118 alert(JSON.stringify(err));
119 }
Paul Greyson6f86d1e2013-03-18 14:40:39 -0700120 });
Ubuntue23620c2013-03-23 01:14:43 +0000121}