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 | |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 13 | // 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 Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 24 | |
| 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 Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 37 | s.controller = results.mapping[s.dpid][0].controllerId; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 38 | |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 39 | if (coreSwitchDPIDs[s.dpid]) { |
| 40 | model.coreSwitches.push(s); |
| 41 | } else if (aggregationSwitchDPIDs[s.dpid]) { |
| 42 | model.aggregationSwitches.push(s); |
| 43 | } else { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 44 | model.edgeSwitches.push(s); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 45 | } |
| 46 | }); |
| 47 | |
| 48 | return model; |
| 49 | } |
| 50 | |
| 51 | function 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); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 86 | cb(model); |
| 87 | }); |
| 88 | } |