Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 1 | /*global async, d3*/ |
| 2 | |
| 3 | function toD3(results) { |
| 4 | var model = { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 5 | edgeSwitches: [], |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 6 | aggregationSwitches: [], |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame^] | 7 | coreSwitches: [], |
| 8 | flows: results.flows |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 9 | } |
| 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 Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 29 | model.edgeSwitches.push(s); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 30 | } |
| 31 | }); |
| 32 | |
| 33 | return model; |
| 34 | } |
| 35 | |
| 36 | function 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 | } |