setting up mock data fetch and model building on client
blocked by sample JSON data not matching switch configuration specification
diff --git a/web/ons-demo/js/model.js b/web/ons-demo/js/model.js
new file mode 100644
index 0000000..27a03b2
--- /dev/null
+++ b/web/ons-demo/js/model.js
@@ -0,0 +1,73 @@
+/*global async, d3*/
+
+function toD3(results) {
+ var model = {
+ edgeSwitchs: [],
+ aggregationSwitches: [],
+ coreSwitches: []
+ }
+
+
+ // identify switch types
+ var coreSwitchDPIDs = {};
+ results.configuration.core.forEach(function (dpid) {
+ coreSwitchDPIDs[dpid] = true;
+ });
+
+ var aggregationSwitchDPIDs = {};
+ results.configuration.aggregation.forEach(function (dpid) {
+ aggregationSwitchDPIDs[dpid] = true;
+ });
+
+ results.switches.forEach(function (s) {
+ if (coreSwitchDPIDs[s.dpid]) {
+ model.coreSwitches.push(s);
+ } else if (aggregationSwitchDPIDs[s.dpid]) {
+ model.aggregationSwitches.push(s);
+ } else {
+ model.edgeSwitchs.push(s);
+ }
+ });
+
+ return model;
+}
+
+function updateModel(cb) {
+ async.parallel({
+ links: function(cb) {
+ d3.json('data/wm_core_topology_links_json.json', function (error, result) {
+ cb(error, result);
+ });
+ },
+ switches: function(cb) {
+ d3.json('data/wm_core_topology_switches_all_json.json', function (error, result) {
+ cb(error, result);
+ });
+ },
+ flows: function(cb) {
+ d3.json('data/wm_flow_getall_json.json', function (error, result) {
+ cb(error, result);
+ });
+ },
+ controllers: function(cb) {
+ d3.json('data/wm_registry_controllers_json.json', function (error, result) {
+ cb(error, result);
+ });
+ },
+ mapping: function(cb) {
+ d3.json('data/wm_registry_switches_json.json', function (error, result) {
+ cb(error, result);
+ });
+ },
+ configuration: function(cb) {
+ d3.json('data/configuration.json', function (error, result) {
+ cb(error, result);
+ });
+ },
+ },
+ function(err, results) {
+ var model = toD3(results);
+ model.timestamp = new Date();
+ cb(model);
+ });
+}
\ No newline at end of file