blob: e16565c85ac87a3c5d889f687f61f87311d83025 [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 Greysond1a22d92013-03-19 12:15:19 -07008 flows: results.flows,
9 controllers: results.controllers,
10 links: results.links
Paul Greyson6f86d1e2013-03-18 14:40:39 -070011 }
12
13
14 // identify switch types
15 var coreSwitchDPIDs = {};
16 results.configuration.core.forEach(function (dpid) {
17 coreSwitchDPIDs[dpid] = true;
18 });
19
20 var aggregationSwitchDPIDs = {};
21 results.configuration.aggregation.forEach(function (dpid) {
22 aggregationSwitchDPIDs[dpid] = true;
23 });
24
25 results.switches.forEach(function (s) {
Paul Greysond1a22d92013-03-19 12:15:19 -070026 s.controller = results.mapping[s.dpid][0].controllerId
27
Paul Greyson6f86d1e2013-03-18 14:40:39 -070028 if (coreSwitchDPIDs[s.dpid]) {
29 model.coreSwitches.push(s);
30 } else if (aggregationSwitchDPIDs[s.dpid]) {
31 model.aggregationSwitches.push(s);
32 } else {
Paul Greyson740bdaf2013-03-18 16:10:48 -070033 model.edgeSwitches.push(s);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070034 }
35 });
36
37 return model;
38}
39
40function updateModel(cb) {
41 async.parallel({
42 links: function(cb) {
43 d3.json('data/wm_core_topology_links_json.json', function (error, result) {
44 cb(error, result);
45 });
46 },
47 switches: function(cb) {
48 d3.json('data/wm_core_topology_switches_all_json.json', function (error, result) {
49 cb(error, result);
50 });
51 },
52 flows: function(cb) {
53 d3.json('data/wm_flow_getall_json.json', function (error, result) {
54 cb(error, result);
55 });
56 },
57 controllers: function(cb) {
58 d3.json('data/wm_registry_controllers_json.json', function (error, result) {
59 cb(error, result);
60 });
61 },
62 mapping: function(cb) {
63 d3.json('data/wm_registry_switches_json.json', function (error, result) {
64 cb(error, result);
65 });
66 },
67 configuration: function(cb) {
68 d3.json('data/configuration.json', function (error, result) {
69 cb(error, result);
70 });
71 },
72 },
73 function(err, results) {
74 var model = toD3(results);
75 model.timestamp = new Date();
76 cb(model);
77 });
78}