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: [], |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame^] | 8 | flows: results.flows, |
| 9 | controllers: results.controllers, |
| 10 | links: results.links |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 11 | } |
| 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 Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame^] | 26 | s.controller = results.mapping[s.dpid][0].controllerId |
| 27 | |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 28 | if (coreSwitchDPIDs[s.dpid]) { |
| 29 | model.coreSwitches.push(s); |
| 30 | } else if (aggregationSwitchDPIDs[s.dpid]) { |
| 31 | model.aggregationSwitches.push(s); |
| 32 | } else { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 33 | model.edgeSwitches.push(s); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 34 | } |
| 35 | }); |
| 36 | |
| 37 | return model; |
| 38 | } |
| 39 | |
| 40 | function 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 | } |