blob: be7cf53076ef4b405e7a3eefc3cb952cc9b412c6 [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());
Paul Greysonbbd708b2013-04-09 22:37:31 -070083
84 var count = 0;
85 model.edgeSwitches.forEach(function (s) {
86 if (s.state === 'ACTIVE') {
87 count += 1;
88 }
89 });
90 model.aggregationSwitches.forEach(function (s) {
91 if (s.state === 'ACTIVE') {
92 count += 1;
93 }
94 });
95 model.coreSwitches.forEach(function (s) {
96 if (s.state === 'ACTIVE') {
97 count += 1;
98 }
99 });
100
101 d3.select('#activeSwitches').text(count);
Paul Greyson7a300822013-04-09 12:57:49 -0700102 d3.select('#activeFlows').text(model.flows.length);
103}
104
Paul Greysone15c4392013-04-09 15:05:31 -0700105/***************************************************************************************************
106update the global linkmap
107***************************************************************************************************/
108function updateLinkMap(links) {
109 linkMap = {};
110 links.forEach(function (link) {
111 var srcDPID = link['src-switch'];
112 var dstDPID = link['dst-switch'];
113
114 var srcMap = linkMap[srcDPID] || {};
115
116 srcMap[dstDPID] = link;
117
118 linkMap[srcDPID] = srcMap;
119 });
120}
121
122/***************************************************************************************************
123// removes links from the pending list that are now in the model
124***************************************************************************************************/
125function reconcilePendingLinks(model) {
126 links = [];
127 model.links.forEach(function (link) {
128 links.push(link);
129 delete pendingLinks[makeLinkKey(link)]
130 })
131 var linkId;
132 for (linkId in pendingLinks) {
133 links.push(pendingLinks[linkId]);
134 }
135}
136
Paul Greyson981e8c22013-04-09 17:43:59 -0700137/***************************************************************************************************
138used by both ring and map models
139***************************************************************************************************/
140function createRootSVG() {
141 var svg = d3.select('#svg-container').append('svg:svg');
142
143 svg.append("svg:defs").append("svg:marker")
144 .attr("id", "arrow")
145 .attr("viewBox", "0 -5 10 10")
146 .attr("refX", -1)
147 .attr("markerWidth", 5)
148 .attr("markerHeight", 5)
149 .attr("orient", "auto")
150 .append("svg:path")
151 .attr("d", "M0,-3L10,0L0,3");
152
153 return svg;
154}
155
Paul Greyson7a300822013-04-09 12:57:49 -0700156