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