hooking up to real test bed
diff --git a/web/ons-demo/js/app.js b/web/ons-demo/js/app.js
index 068eb79..3eb2e7d 100644
--- a/web/ons-demo/js/app.js
+++ b/web/ons-demo/js/app.js
@@ -90,7 +90,11 @@
// rings[1].angles[i] = k * i;
var range = aggRanges[s.dpid];
- rings[1].angles[i] = (range.min + range.max)/2;
+ if (range) {
+ rings[1].angles[i] = (range.min + range.max)/2;
+ } else {
+ rings[1].angles[i] = 0;
+ }
});
// arrange core switches at equal increments
@@ -213,11 +217,18 @@
var controllers = d3.select('#controllerList').selectAll('.controller').data(model.controllers);
controllers.enter().append('div')
.attr('class', function (d) {
- var color = controllerColorMap[d];
- if (!color) {
- color = controllerColorMap[d] = colors.pop();
+
+ var color = 'color0';
+ if (model.activeControllers.indexOf(d) != -1) {
+ color = controllerColorMap[d];
+ if (!color) {
+ color = controllerColorMap[d] = colors.pop();
+ }
+ } else {
+ controllerColorMap[d] = color;
}
- return 'controller ' + color;
+ var className = 'controller ' + color;
+ return className;
});
controllers.text(function (d) {
return d;
@@ -236,7 +247,9 @@
var oldModel;
function sync(svg) {
+ var d = Date.now();
updateModel(function (newModel) {
+ console.log('Update time: ' + (Date.now() - d)/1000 + 's');
if (!oldModel && JSON.stringify(oldModel) != JSON.stringify(newModel)) {
updateControllers(newModel);
diff --git a/web/ons-demo/js/model.js b/web/ons-demo/js/model.js
index ad45469..82e66c1 100644
--- a/web/ons-demo/js/model.js
+++ b/web/ons-demo/js/model.js
@@ -5,8 +5,9 @@
edgeSwitches: [],
aggregationSwitches: [],
coreSwitches: [],
- flows: results.flows,
+ flows: [],
controllers: results.controllers,
+ activeControllers: results.activeControllers,
links: results.links
}
@@ -48,41 +49,73 @@
return model;
}
+var urls = {
+ links: '/wm/core/topology/links/json',
+ switches: '/wm/core/topology/switches/all/json',
+ flows: '/wm/flow/getall/json',
+ activeControllers: '/wm/registry/controllers/json',
+ controllers: '/data/controllers.json',
+ mapping: '/wm/registry/switches/json',
+ configuration: 'data/configuration.json'
+}
+
+var mockURLs = {
+ links: 'data/wm_core_topology_links_json.json',
+ switches: 'data/wm_core_topology_switches_all_json.json',
+ flows: 'data/wm_flow_getall_json.json',
+ activeControllers: 'data/wm_registry_controllers_json.json',
+ controllers: '/data/controllers.json',
+ mapping: 'data/wm_registry_switches_json.json',
+ configuration: 'data/configuration.json'
+}
+
+var proxyURLs = {
+ links: '/proxy/wm/core/topology/links/json',
+ switches: '/proxy/wm/core/topology/switches/all/json',
+ flows: '/proxy/wm/flow/getall/json',
+ activeControllers: '/proxy/wm/registry/controllers/json',
+ controllers: 'data/controllers.json',
+ mapping: '/proxy/wm/registry/switches/json',
+ configuration: 'data/configuration.json'
+}
+
+var params = parseURLParameters();
+if (params.mock) {
+ urls = mockURLs;
+}
+if (params.proxy) {
+ urls = proxyURLs;
+}
+
+function makeRequest(url) {
+ return function (cb) {
+ d3.json(url, function (error, result) {
+ if (error) {
+ error = url + ' : ' + error.status;
+ }
+
+ cb(error, result);
+ });
+ }
+}
+
+
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);
- });
- },
+ links: makeRequest(urls.links),
+ switches: makeRequest(urls.switches),
+ controllers: makeRequest(urls.controllers),
+ activeControllers: makeRequest(urls.activeControllers),
+ mapping: makeRequest(urls.mapping),
+ configuration: makeRequest(urls.configuration)
+// flows: makeRequest(urls.flows),
},
function(err, results) {
- var model = toD3(results);
- cb(model);
+ if (!err) {
+ var model = toD3(results);
+ cb(model);
+ } else {
+ alert(JSON.stringify(err));
+ }
});
}
\ No newline at end of file
diff --git a/web/ons-demo/js/utils.js b/web/ons-demo/js/utils.js
new file mode 100644
index 0000000..17100b1
--- /dev/null
+++ b/web/ons-demo/js/utils.js
@@ -0,0 +1,14 @@
+function parseURLParameters() {
+ var parameters = {};
+
+ var search = location.href.split('?')[1];
+ if (search) {
+ search.split('&').forEach(function (param) {
+ var key = param.split('=')[0];
+ var value = param.split('=')[1];
+ parameters[key] = decodeURIComponent(value);
+ });
+ }
+
+ return parameters;
+}
\ No newline at end of file