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