blob: 354299fea44db91c7ce1fadc56130dda032dac71 [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
Paul Greysonde7fad52013-03-19 12:47:32 -070013 // sort the switches
14 results.switches.sort(function (a, b) {
15 var aA = a.dpid.split(':');
16 var bB = b.dpid.split(':');
17 for (var i=0; i<aA.length; i+=1) {
18 if (aA[i] != bB[i]) {
19 return aA[i] - bB[i];
20 }
21 }
22 return 0;
23 });
Paul Greyson6f86d1e2013-03-18 14:40:39 -070024
25 // identify switch types
26 var coreSwitchDPIDs = {};
27 results.configuration.core.forEach(function (dpid) {
28 coreSwitchDPIDs[dpid] = true;
29 });
30
31 var aggregationSwitchDPIDs = {};
32 results.configuration.aggregation.forEach(function (dpid) {
33 aggregationSwitchDPIDs[dpid] = true;
34 });
35
36 results.switches.forEach(function (s) {
Paul Greysonde7fad52013-03-19 12:47:32 -070037 s.controller = results.mapping[s.dpid][0].controllerId;
Paul Greysond1a22d92013-03-19 12:15:19 -070038
Paul Greyson6f86d1e2013-03-18 14:40:39 -070039 if (coreSwitchDPIDs[s.dpid]) {
40 model.coreSwitches.push(s);
41 } else if (aggregationSwitchDPIDs[s.dpid]) {
42 model.aggregationSwitches.push(s);
43 } else {
Paul Greyson740bdaf2013-03-18 16:10:48 -070044 model.edgeSwitches.push(s);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070045 }
46 });
47
48 return model;
49}
50
51function updateModel(cb) {
52 async.parallel({
53 links: function(cb) {
54 d3.json('data/wm_core_topology_links_json.json', function (error, result) {
55 cb(error, result);
56 });
57 },
58 switches: function(cb) {
59 d3.json('data/wm_core_topology_switches_all_json.json', function (error, result) {
60 cb(error, result);
61 });
62 },
63 flows: function(cb) {
64 d3.json('data/wm_flow_getall_json.json', function (error, result) {
65 cb(error, result);
66 });
67 },
68 controllers: function(cb) {
69 d3.json('data/wm_registry_controllers_json.json', function (error, result) {
70 cb(error, result);
71 });
72 },
73 mapping: function(cb) {
74 d3.json('data/wm_registry_switches_json.json', function (error, result) {
75 cb(error, result);
76 });
77 },
78 configuration: function(cb) {
79 d3.json('data/configuration.json', function (error, result) {
80 cb(error, result);
81 });
82 },
83 },
84 function(err, results) {
85 var model = toD3(results);
86 model.timestamp = new Date();
87 cb(model);
88 });
89}