blob: 94bbdfefc02c8c6cb02b444efb3693f32c1f20fa [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 Greysonc17278a2013-03-23 10:17:12 -070011 links: results.links,
12 configuration: results.configuration
Paul Greyson6f86d1e2013-03-18 14:40:39 -070013 }
14
Paul Greysonde7fad52013-03-19 12:47:32 -070015 // sort the switches
16 results.switches.sort(function (a, b) {
17 var aA = a.dpid.split(':');
18 var bB = b.dpid.split(':');
19 for (var i=0; i<aA.length; i+=1) {
20 if (aA[i] != bB[i]) {
Paul Greyson832d2202013-03-21 13:27:56 -070021 return parseInt(aA[i], 16) - parseInt(bB[i], 16);
Paul Greysonde7fad52013-03-19 12:47:32 -070022 }
23 }
24 return 0;
25 });
Paul Greyson6f86d1e2013-03-18 14:40:39 -070026
27 // identify switch types
28 var coreSwitchDPIDs = {};
29 results.configuration.core.forEach(function (dpid) {
30 coreSwitchDPIDs[dpid] = true;
31 });
32
33 var aggregationSwitchDPIDs = {};
34 results.configuration.aggregation.forEach(function (dpid) {
35 aggregationSwitchDPIDs[dpid] = true;
36 });
37
38 results.switches.forEach(function (s) {
Paul Greysonc17278a2013-03-23 10:17:12 -070039 var mapping = results.mapping[s.dpid]
40 if (mapping) {
41 s.controller = mapping[0].controllerId;
42 }
Paul Greysond1a22d92013-03-19 12:15:19 -070043
Paul Greyson6f86d1e2013-03-18 14:40:39 -070044 if (coreSwitchDPIDs[s.dpid]) {
45 model.coreSwitches.push(s);
46 } else if (aggregationSwitchDPIDs[s.dpid]) {
47 model.aggregationSwitches.push(s);
48 } else {
Paul Greyson740bdaf2013-03-18 16:10:48 -070049 model.edgeSwitches.push(s);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070050 }
51 });
52
53 return model;
54}
55
Paul Greysonbcd3c772013-03-21 13:16:44 -070056var urls = {
57 links: '/wm/core/topology/links/json',
58 switches: '/wm/core/topology/switches/all/json',
59 flows: '/wm/flow/getall/json',
60 activeControllers: '/wm/registry/controllers/json',
Ubuntue23620c2013-03-23 01:14:43 +000061 controllers: 'data/controllers.json',
Paul Greysonbcd3c772013-03-21 13:16:44 -070062 mapping: '/wm/registry/switches/json',
63 configuration: 'data/configuration.json'
64}
65
66var mockURLs = {
67 links: 'data/wm_core_topology_links_json.json',
68 switches: 'data/wm_core_topology_switches_all_json.json',
69 flows: 'data/wm_flow_getall_json.json',
70 activeControllers: 'data/wm_registry_controllers_json.json',
Paul Greysonc3e21a02013-03-21 13:56:05 -070071 controllers: 'data/controllers.json',
Paul Greysonbcd3c772013-03-21 13:16:44 -070072 mapping: 'data/wm_registry_switches_json.json',
73 configuration: 'data/configuration.json'
74}
75
76var proxyURLs = {
Paul Greyson985bb652013-03-22 21:39:04 -070077 links: '/wm/core/topology/links/json?proxy',
78 switches: '/wm/core/topology/switches/all/json?proxy',
79 flows: '/wm/flow/getall/json?proxy',
80 activeControllers: '/wm/registry/controllers/json?proxy',
Paul Greysonbcd3c772013-03-21 13:16:44 -070081 controllers: 'data/controllers.json',
Paul Greyson985bb652013-03-22 21:39:04 -070082 mapping: '/wm/registry/switches/json?proxy',
Paul Greysonbcd3c772013-03-21 13:16:44 -070083 configuration: 'data/configuration.json'
84}
85
86var params = parseURLParameters();
87if (params.mock) {
88 urls = mockURLs;
89}
90if (params.proxy) {
91 urls = proxyURLs;
92}
93
94function makeRequest(url) {
95 return function (cb) {
96 d3.json(url, function (error, result) {
97 if (error) {
98 error = url + ' : ' + error.status;
99 }
100
101 cb(error, result);
102 });
103 }
104}
105
106
Paul Greyson6f86d1e2013-03-18 14:40:39 -0700107function updateModel(cb) {
108 async.parallel({
Paul Greysonbcd3c772013-03-21 13:16:44 -0700109 links: makeRequest(urls.links),
110 switches: makeRequest(urls.switches),
111 controllers: makeRequest(urls.controllers),
112 activeControllers: makeRequest(urls.activeControllers),
113 mapping: makeRequest(urls.mapping),
114 configuration: makeRequest(urls.configuration)
115// flows: makeRequest(urls.flows),
Paul Greyson6f86d1e2013-03-18 14:40:39 -0700116 },
117 function(err, results) {
Paul Greysonbcd3c772013-03-21 13:16:44 -0700118 if (!err) {
119 var model = toD3(results);
120 cb(model);
121 } else {
122 alert(JSON.stringify(err));
123 }
Paul Greyson6f86d1e2013-03-18 14:40:39 -0700124 });
Ubuntue23620c2013-03-23 01:14:43 +0000125}