blob: e85eeaee618267f175f4d76919054a88a4150663 [file] [log] [blame]
Paul Greyson7a300822013-04-09 12:57:49 -07001/***************************************************************************************************
2extract url parameters into a map
3***************************************************************************************************/
Paul Greysonbcd3c772013-03-21 13:16:44 -07004function parseURLParameters() {
5 var parameters = {};
6
7 var search = location.href.split('?')[1];
8 if (search) {
9 search.split('&').forEach(function (param) {
10 var key = param.split('=')[0];
11 var value = param.split('=')[1];
12 parameters[key] = decodeURIComponent(value);
13 });
14 }
15
16 return parameters;
Paul Greyson5cc35f02013-03-28 10:07:36 -070017}
18
Paul Greyson7a300822013-04-09 12:57:49 -070019/***************************************************************************************************
20convenience function for moving an SVG element to the front so that it draws on top
21***************************************************************************************************/
22d3.selection.prototype.moveToFront = function() {
23 return this.each(function(){
24 this.parentNode.appendChild(this);
25 });
26};
27
28/***************************************************************************************************
29standard function for generating the 'd' attribute for a path from an array of points
30***************************************************************************************************/
31var line = d3.svg.line()
32 .x(function(d) {
33 return d.x;
34 })
35 .y(function(d) {
36 return d.y;
37 });
38
39
40/***************************************************************************************************
41starts the "pending" animation
42***************************************************************************************************/
43function setPending(selection) {
44 selection.classed('pending', false);
45 setTimeout(function () {
46 selection.classed('pending', true);
47 }, 0);
48}
49
50/***************************************************************************************************
51convert angle in degrees to radians
52***************************************************************************************************/
53function toRadians (degrees) {
54 return degrees * (Math.PI / 180);
55}
56
57/***************************************************************************************************
58used to generate DOM element id for this link
59***************************************************************************************************/
60function makeLinkKey(link) {
61 return link['src-switch'] + '=>' + link['dst-switch'];
62}
63
64/***************************************************************************************************
65used to generate DOM element id for this flow in the topology view
66***************************************************************************************************/
67function makeFlowKey(flow) {
68 return flow.srcDpid + '=>' + flow.dstDpid;
69}
70
71/***************************************************************************************************
72used to generate DOM element id for this flow in the selected flows table
73***************************************************************************************************/
74function makeSelectedFlowKey(flow) {
75 return 'S' + makeFlowKey(flow);
76}
77
78/***************************************************************************************************
79update the app header using the current model
80***************************************************************************************************/
81function updateHeader() {
82 d3.select('#lastUpdate').text(new Date());
83 d3.select('#activeSwitches').text(model.edgeSwitches.length + model.aggregationSwitches.length + model.coreSwitches.length);
84 d3.select('#activeFlows').text(model.flows.length);
85}
86
Paul Greysone15c4392013-04-09 15:05:31 -070087/***************************************************************************************************
88update the global linkmap
89***************************************************************************************************/
90function updateLinkMap(links) {
91 linkMap = {};
92 links.forEach(function (link) {
93 var srcDPID = link['src-switch'];
94 var dstDPID = link['dst-switch'];
95
96 var srcMap = linkMap[srcDPID] || {};
97
98 srcMap[dstDPID] = link;
99
100 linkMap[srcDPID] = srcMap;
101 });
102}
103
104/***************************************************************************************************
105// removes links from the pending list that are now in the model
106***************************************************************************************************/
107function reconcilePendingLinks(model) {
108 links = [];
109 model.links.forEach(function (link) {
110 links.push(link);
111 delete pendingLinks[makeLinkKey(link)]
112 })
113 var linkId;
114 for (linkId in pendingLinks) {
115 links.push(pendingLinks[linkId]);
116 }
117}
118
Paul Greyson7a300822013-04-09 12:57:49 -0700119