blob: 29a3773886f8337cbac47bdf1eb71dce5a9540ba [file] [log] [blame]
Simon Hunt195cb382014-11-03 17:50:51 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
Simon Hunt142d0032014-11-04 20:13:09 -080018 ONOS network topology viewer - version 1.1
Simon Hunt195cb382014-11-03 17:50:51 -080019
20 @author Simon Hunt
Simon Hunta6a9fe72014-11-20 11:17:12 -080021 @author Thomas Vachuska
Simon Hunt195cb382014-11-03 17:50:51 -080022 */
23
24(function (onos) {
25 'use strict';
26
Simon Hunt1a9eff92014-11-07 11:06:34 -080027 // shorter names for library APIs
Simon Huntbb282f52014-11-10 11:08:19 -080028 var d3u = onos.lib.d3util,
Simon Hunta6a9fe72014-11-20 11:17:12 -080029 gly = onos.lib.glyphs;
Simon Hunt1a9eff92014-11-07 11:06:34 -080030
Simon Hunt195cb382014-11-03 17:50:51 -080031 // configuration data
32 var config = {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -080033 useLiveData: true,
Simon Huntfc274c92014-11-11 11:05:46 -080034 fnTrace: true,
Simon Hunt195cb382014-11-03 17:50:51 -080035 debugOn: false,
36 debug: {
Simon Hunt99c13842014-11-06 18:23:12 -080037 showNodeXY: true,
38 showKeyHandler: false
Simon Hunt195cb382014-11-03 17:50:51 -080039 },
Simon Hunt12ce12e2014-11-15 21:13:19 -080040 birdDim: 400,
Simon Hunt195cb382014-11-03 17:50:51 -080041 options: {
42 layering: true,
43 collisionPrevention: true,
Simon Hunt142d0032014-11-04 20:13:09 -080044 showBackground: true
Simon Hunt195cb382014-11-03 17:50:51 -080045 },
46 backgroundUrl: 'img/us-map.png',
Thomas Vachuska7d638d32014-11-07 10:24:43 -080047 webSockUrl: 'ws/topology',
Simon Hunt195cb382014-11-03 17:50:51 -080048 data: {
49 live: {
50 jsonUrl: 'rs/topology/graph',
51 detailPrefix: 'rs/topology/graph/',
52 detailSuffix: ''
53 },
54 fake: {
55 jsonUrl: 'json/network2.json',
56 detailPrefix: 'json/',
57 detailSuffix: '.json'
58 }
59 },
Simon Hunt99c13842014-11-06 18:23:12 -080060 labels: {
61 imgPad: 16,
62 padLR: 4,
63 padTB: 3,
64 marginLR: 3,
65 marginTB: 2,
66 port: {
67 gap: 3,
68 width: 18,
69 height: 14
70 }
71 },
Simon Hunt1a9eff92014-11-07 11:06:34 -080072 topo: {
Thomas Vachuska89543292014-11-19 11:28:33 -080073 linkBaseColor: '#666',
Simon Hunt1a9eff92014-11-07 11:06:34 -080074 linkInColor: '#66f',
Thomas Vachuska9edca302014-11-22 17:06:42 -080075 linkInWidth: 12,
Thomas Vachuska89543292014-11-19 11:28:33 -080076 linkOutColor: '#f00',
Thomas Vachuska9edca302014-11-22 17:06:42 -080077 linkOutWidth: 10
Simon Hunt1a9eff92014-11-07 11:06:34 -080078 },
Paul Greyson29cd58f2014-11-18 13:14:57 -080079 icons: {
Thomas Vachuskaece59ee2014-11-19 19:06:11 -080080 w: 30,
81 h: 30,
82 xoff: -16,
Simon Huntc72967b2014-11-20 09:21:42 -080083 yoff: -14,
84
85 device: {
86 dim: 30,
87 rx: 4
88 }
Thomas Vachuska89543292014-11-19 11:28:33 -080089 },
90 iconUrl: {
91 device: 'img/device.png',
92 host: 'img/host.png',
93 pkt: 'img/pkt.png',
94 opt: 'img/opt.png'
Simon Hunt195cb382014-11-03 17:50:51 -080095 },
Simon Hunt195cb382014-11-03 17:50:51 -080096 force: {
Simon Hunt7cd48f32014-11-09 23:42:50 -080097 note_for_links: 'link.type is used to differentiate',
Simon Huntc7ee0662014-11-05 16:44:37 -080098 linkDistance: {
Simon Hunt7cd48f32014-11-09 23:42:50 -080099 direct: 100,
100 optical: 120,
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800101 hostLink: 3
Simon Huntc7ee0662014-11-05 16:44:37 -0800102 },
103 linkStrength: {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800104 direct: 1.0,
105 optical: 1.0,
106 hostLink: 1.0
Simon Huntc7ee0662014-11-05 16:44:37 -0800107 },
Simon Hunt7cd48f32014-11-09 23:42:50 -0800108 note_for_nodes: 'node.class is used to differentiate',
Simon Huntc7ee0662014-11-05 16:44:37 -0800109 charge: {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800110 device: -8000,
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800111 host: -5000
Simon Huntc7ee0662014-11-05 16:44:37 -0800112 },
113 pad: 20,
Simon Hunt195cb382014-11-03 17:50:51 -0800114 translate: function() {
115 return 'translate(' +
Simon Huntc7ee0662014-11-05 16:44:37 -0800116 config.force.pad + ',' +
117 config.force.pad + ')';
Simon Hunt195cb382014-11-03 17:50:51 -0800118 }
Paul Greyson6cb8ca02014-11-12 18:09:02 -0800119 },
120 // see below in creation of viewBox on main svg
121 logicalSize: 1000
Simon Hunt195cb382014-11-03 17:50:51 -0800122 };
123
Simon Hunt142d0032014-11-04 20:13:09 -0800124 // radio buttons
Simon Hunt9462e8c2014-11-14 17:28:09 -0800125 var layerButtons = [
126 { text: 'All Layers', id: 'all', cb: showAllLayers },
127 { text: 'Packet Only', id: 'pkt', cb: showPacketLayer },
128 { text: 'Optical Only', id: 'opt', cb: showOpticalLayer }
129 ],
130 layerBtnSet,
131 layerBtnDispatch = {
132 all: showAllLayers,
133 pkt: showPacketLayer,
134 opt: showOpticalLayer
135 };
Simon Hunt934c3ce2014-11-05 11:45:07 -0800136
137 // key bindings
138 var keyDispatch = {
Simon Hunt988c6fc2014-11-20 17:43:03 -0800139 // TODO: remove these "development only" bindings
140 M: testMe,
141 S: injectStartupEvents,
142 space: injectTestEvent,
Simon Hunt99c13842014-11-06 18:23:12 -0800143
Thomas Vachuska47635c62014-11-22 01:21:36 -0800144 O: [toggleSummary, 'Toggle ONOS summary pane'],
145 I: [toggleInstances, 'Toggle ONOS instances pane'],
Simon Hunt988c6fc2014-11-20 17:43:03 -0800146 B: [toggleBg, 'Toggle background image'],
147 L: [cycleLabels, 'Cycle Device labels'],
Simon Hunt934c3ce2014-11-05 11:45:07 -0800148 P: togglePorts,
Simon Hunt56ef0fe2014-11-21 08:24:43 -0800149 U: [unpin, 'Unpin node'],
150 R: [resetZoomPan, 'Reset zoom/pan'],
Thomas Vachuska9edca302014-11-22 17:06:42 -0800151 V: [showTrafficAction, 'Show related traffic'],
Simon Hunt56ef0fe2014-11-21 08:24:43 -0800152 A: [showAllTrafficAction, 'Show all traffic'],
153 F: [showDeviceLinkFlowsAction, 'Show device link flows'],
Simon Hunt9462e8c2014-11-14 17:28:09 -0800154 esc: handleEscape
Simon Hunt934c3ce2014-11-05 11:45:07 -0800155 };
Simon Hunt142d0032014-11-04 20:13:09 -0800156
Simon Hunt195cb382014-11-03 17:50:51 -0800157 // state variables
Simon Hunt99c13842014-11-06 18:23:12 -0800158 var network = {
Simon Hunt50128c02014-11-08 13:36:15 -0800159 view: null, // view token reference
Simon Hunt99c13842014-11-06 18:23:12 -0800160 nodes: [],
161 links: [],
Simon Hunt269670f2014-11-17 16:17:43 -0800162 lookup: {},
163 revLinkToKey: {}
Simon Hunt99c13842014-11-06 18:23:12 -0800164 },
Simon Hunt56d51852014-11-09 13:03:35 -0800165 scenario = {
166 evDir: 'json/ev/',
167 evScenario: '/scenario.json',
168 evPrefix: '/ev_',
169 evOnos: '_onos.json',
170 evUi: '_ui.json',
171 ctx: null,
172 params: {},
173 evNumber: 0,
174 view: null,
175 debug: false
176 },
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800177 webSock,
Simon Hunt0c6d4192014-11-12 12:07:10 -0800178 sid = 0,
Thomas Vachuska60d72bf2014-11-21 13:02:00 -0800179 deviceLabelCount = 3,
Simon Hunt209155e2014-11-21 12:16:09 -0800180 hostLabelCount = 2,
Simon Hunt56d51852014-11-09 13:03:35 -0800181 deviceLabelIndex = 0,
182 hostLabelIndex = 0,
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800183 selections = {},
Simon Hunta5e89142014-11-14 07:00:33 -0800184 selectOrder = [],
Simon Hunt6ac93f32014-11-13 12:17:27 -0800185 hovered = null,
Thomas Vachuska47635c62014-11-22 01:21:36 -0800186 summaryPane,
Simon Hunta5e89142014-11-14 07:00:33 -0800187 detailPane,
Simon Hunta255a2c2014-11-13 22:29:35 -0800188 antTimer = null,
Simon Hunta5e89142014-11-14 07:00:33 -0800189 onosInstances = {},
190 onosOrder = [],
191 oiBox,
Simon Hunt9462e8c2014-11-14 17:28:09 -0800192 oiShowMaster = false,
Simon Hunt195cb382014-11-03 17:50:51 -0800193 portLabelsOn = false;
194
Thomas Vachuska9edca302014-11-22 17:06:42 -0800195 var hoverModeAll = 1,
196 hoverModeFlows = 2,
197 hoverModeIntents = 3,
198 hoverMode = hoverModeFlows;
199
Simon Hunt934c3ce2014-11-05 11:45:07 -0800200 // D3 selections
201 var svg,
Paul Greysonfcba0e82014-11-13 10:21:16 -0800202 zoomPanContainer,
Simon Hunt934c3ce2014-11-05 11:45:07 -0800203 bgImg,
Simon Huntc7ee0662014-11-05 16:44:37 -0800204 topoG,
205 nodeG,
206 linkG,
Simon Hunte2575b62014-11-18 15:25:53 -0800207 linkLabelG,
Simon Huntc7ee0662014-11-05 16:44:37 -0800208 node,
Simon Hunt0c6d4192014-11-12 12:07:10 -0800209 link,
Simon Hunte2575b62014-11-18 15:25:53 -0800210 linkLabel,
Simon Hunt0c6d4192014-11-12 12:07:10 -0800211 mask;
Simon Hunt195cb382014-11-03 17:50:51 -0800212
Paul Greyson6cb8ca02014-11-12 18:09:02 -0800213 // the projection for the map background
214 var geoMapProjection;
215
Paul Greysonfcba0e82014-11-13 10:21:16 -0800216 // the zoom function
217 var zoom;
218
Simon Hunt142d0032014-11-04 20:13:09 -0800219 // ==============================
Simon Hunt934c3ce2014-11-05 11:45:07 -0800220 // For Debugging / Development
Simon Hunt195cb382014-11-03 17:50:51 -0800221
Simon Hunt99c13842014-11-06 18:23:12 -0800222 function note(label, msg) {
223 console.log('NOTE: ' + label + ': ' + msg);
Simon Hunt195cb382014-11-03 17:50:51 -0800224 }
225
Simon Hunt99c13842014-11-06 18:23:12 -0800226 function debug(what) {
227 return config.debugOn && config.debug[what];
Simon Hunt934c3ce2014-11-05 11:45:07 -0800228 }
229
Simon Huntfc274c92014-11-11 11:05:46 -0800230 function fnTrace(msg, id) {
231 if (config.fnTrace) {
232 console.log('FN: ' + msg + ' [' + id + ']');
233 }
234 }
Simon Hunt99c13842014-11-06 18:23:12 -0800235
Simon Hunta5e89142014-11-14 07:00:33 -0800236 function evTrace(data) {
237 fnTrace(data.event, data.payload.id);
238 }
239
Simon Hunt934c3ce2014-11-05 11:45:07 -0800240 // ==============================
241 // Key Callbacks
242
Simon Hunt99c13842014-11-06 18:23:12 -0800243 function testMe(view) {
Simon Hunta3dd9572014-11-20 15:22:41 -0800244 //view.alert('Theme is ' + view.theme());
245 //view.flash('This is some text');
Simon Hunt99c13842014-11-06 18:23:12 -0800246 }
247
Simon Hunt56d51852014-11-09 13:03:35 -0800248 function abortIfLive() {
Simon Hunt50128c02014-11-08 13:36:15 -0800249 if (config.useLiveData) {
Simon Huntb53e0682014-11-12 13:32:01 -0800250 network.view.alert("Sorry, currently using live data..");
Simon Hunt56d51852014-11-09 13:03:35 -0800251 return true;
Simon Hunt50128c02014-11-08 13:36:15 -0800252 }
Simon Hunt56d51852014-11-09 13:03:35 -0800253 return false;
254 }
Simon Hunt50128c02014-11-08 13:36:15 -0800255
Simon Hunt56d51852014-11-09 13:03:35 -0800256 function testDebug(msg) {
257 if (scenario.debug) {
258 scenario.view.alert(msg);
259 }
260 }
Simon Hunt99c13842014-11-06 18:23:12 -0800261
Simon Hunt56d51852014-11-09 13:03:35 -0800262 function injectTestEvent(view) {
263 if (abortIfLive()) { return; }
264 var sc = scenario,
265 evn = ++sc.evNumber,
266 pfx = sc.evDir + sc.ctx + sc.evPrefix + evn,
267 onosUrl = pfx + sc.evOnos,
Simon Hunt7cd48f32014-11-09 23:42:50 -0800268 uiUrl = pfx + sc.evUi,
269 stack = [
270 { url: onosUrl, cb: handleServerEvent },
271 { url: uiUrl, cb: handleUiEvent }
272 ];
273 recurseFetchEvent(stack, evn);
Simon Hunt56d51852014-11-09 13:03:35 -0800274 }
275
Simon Hunt7cd48f32014-11-09 23:42:50 -0800276 function recurseFetchEvent(stack, evn) {
277 var v = scenario.view,
278 frame;
279 if (stack.length === 0) {
Simon Huntfc274c92014-11-11 11:05:46 -0800280 v.alert('Oops!\n\nNo event #' + evn + ' found.');
Simon Hunt7cd48f32014-11-09 23:42:50 -0800281 return;
282 }
283 frame = stack.shift();
284
285 d3.json(frame.url, function (err, data) {
Simon Hunt99c13842014-11-06 18:23:12 -0800286 if (err) {
Simon Hunt56d51852014-11-09 13:03:35 -0800287 if (err.status === 404) {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800288 // if we didn't find the data, try the next stack frame
289 recurseFetchEvent(stack, evn);
Simon Hunt56d51852014-11-09 13:03:35 -0800290 } else {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800291 v.alert('non-404 error:\n\n' + frame.url + '\n\n' + err);
Simon Hunt56d51852014-11-09 13:03:35 -0800292 }
Simon Hunt99c13842014-11-06 18:23:12 -0800293 } else {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800294 testDebug('loaded: ' + frame.url);
Simon Hunt1712ed82014-11-17 12:56:00 -0800295 wsTrace('test', JSON.stringify(data));
Simon Hunt7cd48f32014-11-09 23:42:50 -0800296 frame.cb(data);
Simon Hunt99c13842014-11-06 18:23:12 -0800297 }
298 });
Simon Hunt934c3ce2014-11-05 11:45:07 -0800299
Simon Hunt56d51852014-11-09 13:03:35 -0800300 }
Simon Hunt50128c02014-11-08 13:36:15 -0800301
Simon Hunt56d51852014-11-09 13:03:35 -0800302 function handleUiEvent(data) {
Simon Huntbb282f52014-11-10 11:08:19 -0800303 scenario.view.alert('UI Tx: ' + data.event + '\n\n' +
304 JSON.stringify(data));
Simon Hunt56d51852014-11-09 13:03:35 -0800305 }
306
307 function injectStartupEvents(view) {
308 var last = scenario.params.lastAuto || 0;
309 if (abortIfLive()) { return; }
310
311 while (scenario.evNumber < last) {
Simon Hunt1a9eff92014-11-07 11:06:34 -0800312 injectTestEvent(view);
313 }
314 }
315
Simon Hunt934c3ce2014-11-05 11:45:07 -0800316 function toggleBg() {
317 var vis = bgImg.style('visibility');
318 bgImg.style('visibility', (vis === 'hidden') ? 'visible' : 'hidden');
319 }
320
Simon Hunt99c13842014-11-06 18:23:12 -0800321 function cycleLabels() {
Thomas Vachuska60d72bf2014-11-21 13:02:00 -0800322 deviceLabelIndex = (deviceLabelIndex === 2)
Simon Huntbb282f52014-11-10 11:08:19 -0800323 ? 0 : deviceLabelIndex + 1;
Simon Hunt5f36d342014-11-08 21:33:14 -0800324
Simon Hunt99c13842014-11-06 18:23:12 -0800325 network.nodes.forEach(function (d) {
Simon Huntbb282f52014-11-10 11:08:19 -0800326 if (d.class === 'device') {
327 updateDeviceLabel(d);
328 }
Simon Hunt99c13842014-11-06 18:23:12 -0800329 });
Simon Hunt934c3ce2014-11-05 11:45:07 -0800330 }
331
332 function togglePorts(view) {
Simon Hunt50128c02014-11-08 13:36:15 -0800333 view.alert('togglePorts() callback')
Simon Hunt934c3ce2014-11-05 11:45:07 -0800334 }
335
Simon Hunt6ac93f32014-11-13 12:17:27 -0800336 function unpin() {
337 if (hovered) {
338 hovered.fixed = false;
339 hovered.el.classed('fixed', false);
340 network.force.resume();
341 }
Simon Hunt934c3ce2014-11-05 11:45:07 -0800342 }
343
Simon Hunt9462e8c2014-11-14 17:28:09 -0800344 function handleEscape(view) {
345 if (oiShowMaster) {
346 cancelAffinity();
Thomas Vachuska47635c62014-11-22 01:21:36 -0800347 } else if (detailPane.isVisible()) {
Simon Hunt9462e8c2014-11-14 17:28:09 -0800348 deselectAll();
Thomas Vachuska47635c62014-11-22 01:21:36 -0800349 } else if (oiBox.isVisible()) {
350 oiBox.hide();
351 } else if (summaryPane.isVisible()) {
352 cancelSummary();
Simon Hunt9462e8c2014-11-14 17:28:09 -0800353 }
354 }
355
Simon Hunt934c3ce2014-11-05 11:45:07 -0800356 // ==============================
357 // Radio Button Callbacks
358
Simon Hunta5e89142014-11-14 07:00:33 -0800359 var layerLookup = {
360 host: {
Simon Hunt209155e2014-11-21 12:16:09 -0800361 endstation: 'pkt', // default, if host event does not define type
Thomas Vachuska89543292014-11-19 11:28:33 -0800362 router: 'pkt',
Simon Hunta5e89142014-11-14 07:00:33 -0800363 bgpSpeaker: 'pkt'
364 },
365 device: {
366 switch: 'pkt',
367 roadm: 'opt'
368 },
369 link: {
370 hostLink: 'pkt',
371 direct: 'pkt',
Simon Hunt8257f4c2014-11-16 19:34:54 -0800372 indirect: '',
373 tunnel: '',
Simon Hunta5e89142014-11-14 07:00:33 -0800374 optical: 'opt'
375 }
376 };
377
378 function inLayer(d, layer) {
Simon Hunt8257f4c2014-11-16 19:34:54 -0800379 var type = d.class === 'link' ? d.type() : d.type,
380 look = layerLookup[d.class],
381 lyr = look && look[type];
Simon Hunta5e89142014-11-14 07:00:33 -0800382 return lyr === layer;
383 }
384
385 function unsuppressLayer(which) {
386 node.each(function (d) {
387 var node = d.el;
388 if (inLayer(d, which)) {
389 node.classed('suppressed', false);
390 }
391 });
392
393 link.each(function (d) {
394 var link = d.el;
395 if (inLayer(d, which)) {
396 link.classed('suppressed', false);
397 }
398 });
399 }
400
Simon Hunt9462e8c2014-11-14 17:28:09 -0800401 function suppressLayers(b) {
402 node.classed('suppressed', b);
403 link.classed('suppressed', b);
Simon Hunt142d0032014-11-04 20:13:09 -0800404// d3.selectAll('svg .port').classed('inactive', false);
405// d3.selectAll('svg .portText').classed('inactive', false);
Simon Hunt195cb382014-11-03 17:50:51 -0800406 }
407
Simon Hunt9462e8c2014-11-14 17:28:09 -0800408 function showAllLayers() {
409 suppressLayers(false);
410 }
411
Simon Hunt195cb382014-11-03 17:50:51 -0800412 function showPacketLayer() {
Simon Hunta5e89142014-11-14 07:00:33 -0800413 node.classed('suppressed', true);
414 link.classed('suppressed', true);
415 unsuppressLayer('pkt');
Simon Hunt195cb382014-11-03 17:50:51 -0800416 }
417
418 function showOpticalLayer() {
Simon Hunta5e89142014-11-14 07:00:33 -0800419 node.classed('suppressed', true);
420 link.classed('suppressed', true);
421 unsuppressLayer('opt');
Simon Hunt195cb382014-11-03 17:50:51 -0800422 }
423
Simon Hunt9462e8c2014-11-14 17:28:09 -0800424 function restoreLayerState() {
425 layerBtnDispatch[layerBtnSet.selected()]();
426 }
427
Simon Hunt142d0032014-11-04 20:13:09 -0800428 // ==============================
Simon Hunt934c3ce2014-11-05 11:45:07 -0800429 // Private functions
430
Simon Hunt99c13842014-11-06 18:23:12 -0800431 function safeId(s) {
432 return s.replace(/[^a-z0-9]/gi, '-');
433 }
434
Simon Huntc7ee0662014-11-05 16:44:37 -0800435 // set the size of the given element to that of the view (reduced if padded)
436 function setSize(el, view, pad) {
437 var padding = pad ? pad * 2 : 0;
Simon Hunt934c3ce2014-11-05 11:45:07 -0800438 el.attr({
Simon Huntc7ee0662014-11-05 16:44:37 -0800439 width: view.width() - padding,
440 height: view.height() - padding
Simon Hunt934c3ce2014-11-05 11:45:07 -0800441 });
442 }
443
Simon Hunt8257f4c2014-11-16 19:34:54 -0800444 function makeNodeKey(d, what) {
445 var port = what + 'Port';
446 return d[what] + '/' + d[port];
447 }
448
449 function makeLinkKey(d, flipped) {
450 var one = flipped ? makeNodeKey(d, 'dst') : makeNodeKey(d, 'src'),
451 two = flipped ? makeNodeKey(d, 'src') : makeNodeKey(d, 'dst');
452 return one + '-' + two;
453 }
454
Simon Hunt269670f2014-11-17 16:17:43 -0800455 function findLinkById(id) {
456 // check to see if this is a reverse lookup, else default to given id
457 var key = network.revLinkToKey[id] || id;
458 return key && network.lookup[key];
459 }
460
Simon Hunt8257f4c2014-11-16 19:34:54 -0800461 function findLink(linkData, op) {
462 var key = makeLinkKey(linkData),
463 keyrev = makeLinkKey(linkData, 1),
464 link = network.lookup[key],
465 linkRev = network.lookup[keyrev],
466 result = {},
467 ldata = link || linkRev,
468 rawLink;
469
470 if (op === 'add') {
471 if (link) {
472 // trying to add a link that we already know about
473 result.ldata = link;
474 result.badLogic = 'addLink: link already added';
475
476 } else if (linkRev) {
477 // we found the reverse of the link to be added
478 result.ldata = linkRev;
479 if (linkRev.fromTarget) {
480 result.badLogic = 'addLink: link already added';
481 }
482 }
483 } else if (op === 'update') {
484 if (!ldata) {
485 result.badLogic = 'updateLink: link not found';
486 } else {
487 rawLink = link ? ldata.fromSource : ldata.fromTarget;
488 result.updateWith = function (data) {
489 $.extend(rawLink, data);
490 restyleLinkElement(ldata);
491 }
492 }
493 } else if (op === 'remove') {
494 if (!ldata) {
495 result.badLogic = 'removeLink: link not found';
496 } else {
497 rawLink = link ? ldata.fromSource : ldata.fromTarget;
498
499 if (!rawLink) {
500 result.badLogic = 'removeLink: link not found';
501
502 } else {
503 result.removeRawLink = function () {
504 if (link) {
505 // remove fromSource
506 ldata.fromSource = null;
507 if (ldata.fromTarget) {
508 // promote target into source position
509 ldata.fromSource = ldata.fromTarget;
510 ldata.fromTarget = null;
511 ldata.key = keyrev;
512 delete network.lookup[key];
513 network.lookup[keyrev] = ldata;
Simon Hunt269670f2014-11-17 16:17:43 -0800514 delete network.revLinkToKey[keyrev];
Simon Hunt8257f4c2014-11-16 19:34:54 -0800515 }
516 } else {
517 // remove fromTarget
518 ldata.fromTarget = null;
Simon Hunt269670f2014-11-17 16:17:43 -0800519 delete network.revLinkToKey[keyrev];
Simon Hunt8257f4c2014-11-16 19:34:54 -0800520 }
521 if (ldata.fromSource) {
522 restyleLinkElement(ldata);
523 } else {
524 removeLinkElement(ldata);
525 }
526 }
527 }
528 }
529 }
530 return result;
531 }
532
533 function addLinkUpdate(ldata, link) {
534 // add link event, but we already have the reverse link installed
535 ldata.fromTarget = link;
Simon Hunt269670f2014-11-17 16:17:43 -0800536 network.revLinkToKey[link.id] = ldata.key;
Simon Hunt8257f4c2014-11-16 19:34:54 -0800537 restyleLinkElement(ldata);
538 }
539
540 var allLinkTypes = 'direct indirect optical tunnel',
541 defaultLinkType = 'direct';
542
543 function restyleLinkElement(ldata) {
544 // this fn's job is to look at raw links and decide what svg classes
545 // need to be applied to the line element in the DOM
546 var el = ldata.el,
547 type = ldata.type(),
548 lw = ldata.linkWidth(),
549 online = ldata.online();
550
551 el.classed('link', true);
552 el.classed('inactive', !online);
553 el.classed(allLinkTypes, false);
554 if (type) {
555 el.classed(type, true);
556 }
557 el.transition()
558 .duration(1000)
Thomas Vachuska89543292014-11-19 11:28:33 -0800559 .attr('stroke-width', linkScale(lw))
560 .attr('stroke', config.topo.linkBaseColor);
Simon Hunt8257f4c2014-11-16 19:34:54 -0800561 }
Simon Hunt934c3ce2014-11-05 11:45:07 -0800562
Simon Hunt99c13842014-11-06 18:23:12 -0800563 // ==============================
564 // Event handlers for server-pushed events
565
Simon Huntbb282f52014-11-10 11:08:19 -0800566 function logicError(msg) {
567 // TODO, report logic error to server, via websock, so it can be logged
Simon Huntcb56cff2014-11-17 11:42:26 -0800568 //network.view.alert('Logic Error:\n\n' + msg);
Simon Huntfc274c92014-11-11 11:05:46 -0800569 console.warn(msg);
Simon Huntbb282f52014-11-10 11:08:19 -0800570 }
571
Simon Hunt99c13842014-11-06 18:23:12 -0800572 var eventDispatch = {
Simon Hunta5e89142014-11-14 07:00:33 -0800573 addInstance: addInstance,
Simon Hunt99c13842014-11-06 18:23:12 -0800574 addDevice: addDevice,
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800575 addLink: addLink,
Simon Hunt56d51852014-11-09 13:03:35 -0800576 addHost: addHost,
Simon Huntb53e0682014-11-12 13:32:01 -0800577
Simon Huntfcfb46c2014-11-19 12:53:38 -0800578 updateInstance: updateInstance,
Simon Huntbb282f52014-11-10 11:08:19 -0800579 updateDevice: updateDevice,
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800580 updateLink: updateLink,
Simon Hunt7cd48f32014-11-09 23:42:50 -0800581 updateHost: updateHost,
Simon Huntb53e0682014-11-12 13:32:01 -0800582
Simon Hunt7b403bc2014-11-22 19:01:00 -0800583 removeInstance: removeInstance,
Simon Huntbb282f52014-11-10 11:08:19 -0800584 removeDevice: stillToImplement,
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800585 removeLink: removeLink,
Simon Hunt44031102014-11-11 13:20:36 -0800586 removeHost: removeHost,
Simon Huntb53e0682014-11-12 13:32:01 -0800587
Simon Hunt61d04042014-11-11 17:27:16 -0800588 showDetails: showDetails,
Thomas Vachuska47635c62014-11-22 01:21:36 -0800589 showSummary: showSummary,
Simon Huntb53e0682014-11-12 13:32:01 -0800590 showTraffic: showTraffic
Simon Hunt99c13842014-11-06 18:23:12 -0800591 };
592
Simon Hunta5e89142014-11-14 07:00:33 -0800593 function addInstance(data) {
594 evTrace(data);
595 var inst = data.payload,
596 id = inst.id;
597 if (onosInstances[id]) {
598 logicError('ONOS instance already added: ' + id);
599 return;
600 }
601 onosInstances[id] = inst;
602 onosOrder.push(inst);
603 updateInstances();
604 }
605
Simon Hunt99c13842014-11-06 18:23:12 -0800606 function addDevice(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800607 evTrace(data);
Simon Hunt99c13842014-11-06 18:23:12 -0800608 var device = data.payload,
Simon Hunt7cd48f32014-11-09 23:42:50 -0800609 nodeData = createDeviceNode(device);
Simon Hunt7cd48f32014-11-09 23:42:50 -0800610 network.nodes.push(nodeData);
611 network.lookup[nodeData.id] = nodeData;
Simon Hunt99c13842014-11-06 18:23:12 -0800612 updateNodes();
613 network.force.start();
614 }
615
Simon Hunt99c13842014-11-06 18:23:12 -0800616 function addLink(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800617 evTrace(data);
Simon Hunt99c13842014-11-06 18:23:12 -0800618 var link = data.payload,
Simon Hunt8257f4c2014-11-16 19:34:54 -0800619 result = findLink(link, 'add'),
620 bad = result.badLogic,
621 ldata = result.ldata;
622
623 if (bad) {
624 logicError(bad + ': ' + link.id);
625 return;
626 }
627
628 if (ldata) {
629 // we already have a backing store link for src/dst nodes
630 addLinkUpdate(ldata, link);
631 return;
632 }
633
634 // no backing store link yet
635 ldata = createLink(link);
636 if (ldata) {
637 network.links.push(ldata);
638 network.lookup[ldata.key] = ldata;
Simon Hunt99c13842014-11-06 18:23:12 -0800639 updateLinks();
640 network.force.start();
641 }
642 }
643
Simon Hunt56d51852014-11-09 13:03:35 -0800644 function addHost(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800645 evTrace(data);
Simon Hunt56d51852014-11-09 13:03:35 -0800646 var host = data.payload,
647 node = createHostNode(host),
648 lnk;
Simon Hunt56d51852014-11-09 13:03:35 -0800649 network.nodes.push(node);
650 network.lookup[host.id] = node;
651 updateNodes();
652
653 lnk = createHostLink(host);
654 if (lnk) {
Simon Hunt44031102014-11-11 13:20:36 -0800655 node.linkData = lnk; // cache ref on its host
Simon Hunt56d51852014-11-09 13:03:35 -0800656 network.links.push(lnk);
Thomas Vachuska4830d392014-11-09 17:09:56 -0800657 network.lookup[host.ingress] = lnk;
658 network.lookup[host.egress] = lnk;
Simon Hunt56d51852014-11-09 13:03:35 -0800659 updateLinks();
660 }
661 network.force.start();
662 }
663
Simon Hunt44031102014-11-11 13:20:36 -0800664 // TODO: fold updateX(...) methods into one base method; remove duplication
Simon Hunt56a2ea42014-11-19 12:39:31 -0800665
666 function updateInstance(data) {
667 evTrace(data);
668 var inst = data.payload,
669 id = inst.id,
670 instData = onosInstances[id];
671 if (instData) {
672 $.extend(instData, inst);
673 updateInstances();
Simon Hunt56a2ea42014-11-19 12:39:31 -0800674 } else {
675 logicError('updateInstance lookup fail. ID = "' + id + '"');
676 }
677 }
678
Simon Huntbb282f52014-11-10 11:08:19 -0800679 function updateDevice(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800680 evTrace(data);
Simon Huntbb282f52014-11-10 11:08:19 -0800681 var device = data.payload,
682 id = device.id,
683 nodeData = network.lookup[id];
684 if (nodeData) {
685 $.extend(nodeData, device);
686 updateDeviceState(nodeData);
687 } else {
688 logicError('updateDevice lookup fail. ID = "' + id + '"');
689 }
690 }
691
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800692 function updateLink(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800693 evTrace(data);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800694 var link = data.payload,
Simon Hunt8257f4c2014-11-16 19:34:54 -0800695 result = findLink(link, 'update'),
696 bad = result.badLogic;
697 if (bad) {
698 logicError(bad + ': ' + link.id);
699 return;
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800700 }
Simon Hunt8257f4c2014-11-16 19:34:54 -0800701 result.updateWith(link);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800702 }
703
Simon Hunt7cd48f32014-11-09 23:42:50 -0800704 function updateHost(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800705 evTrace(data);
Simon Hunt7cd48f32014-11-09 23:42:50 -0800706 var host = data.payload,
Simon Huntbb282f52014-11-10 11:08:19 -0800707 id = host.id,
708 hostData = network.lookup[id];
709 if (hostData) {
710 $.extend(hostData, host);
711 updateHostState(hostData);
712 } else {
713 logicError('updateHost lookup fail. ID = "' + id + '"');
714 }
Simon Hunt7cd48f32014-11-09 23:42:50 -0800715 }
716
Simon Hunt44031102014-11-11 13:20:36 -0800717 // TODO: fold removeX(...) methods into base method - remove dup code
Simon Hunt7b403bc2014-11-22 19:01:00 -0800718 function removeInstance(data) {
719 evTrace(data);
720 var inst = data.payload,
721 id = inst.id,
722 instData = onosInstances[id];
723 if (instData) {
724 var idx = find(id, onosOrder, 'id');
725 if (idx >= 0) {
726 onosOrder.splice(idx, 1);
727 }
728 delete onosInstances[id];
729 updateInstances();
730 } else {
731 logicError('updateInstance lookup fail. ID = "' + id + '"');
732 }
733 }
734
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800735 function removeLink(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800736 evTrace(data);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800737 var link = data.payload,
Simon Hunt8257f4c2014-11-16 19:34:54 -0800738 result = findLink(link, 'remove'),
739 bad = result.badLogic;
740 if (bad) {
741 logicError(bad + ': ' + link.id);
742 return;
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800743 }
Simon Hunt8257f4c2014-11-16 19:34:54 -0800744 result.removeRawLink();
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800745 }
746
Simon Hunt44031102014-11-11 13:20:36 -0800747 function removeHost(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800748 evTrace(data);
Simon Hunt44031102014-11-11 13:20:36 -0800749 var host = data.payload,
750 id = host.id,
751 hostData = network.lookup[id];
752 if (hostData) {
753 removeHostElement(hostData);
754 } else {
755 logicError('removeHost lookup fail. ID = "' + id + '"');
756 }
757 }
758
Thomas Vachuska47635c62014-11-22 01:21:36 -0800759 function showSummary(data) {
760 evTrace(data);
761 populateSummary(data.payload);
762 summaryPane.show();
763 }
764
Simon Hunt61d04042014-11-11 17:27:16 -0800765 function showDetails(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800766 evTrace(data);
Simon Hunt61d04042014-11-11 17:27:16 -0800767 populateDetails(data.payload);
768 detailPane.show();
769 }
770
Simon Huntb53e0682014-11-12 13:32:01 -0800771 function showTraffic(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800772 evTrace(data);
Thomas Vachuska4731f122014-11-20 04:56:19 -0800773 var paths = data.payload.paths,
774 hasTraffic = false;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800775
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800776 // Revert any links hilighted previously.
Thomas Vachuska4731f122014-11-20 04:56:19 -0800777 link.style('stroke-width', null)
Thomas Vachuskaa3148a72014-11-19 21:38:35 -0800778 .classed('primary secondary animated optical', false);
Simon Hunte2575b62014-11-18 15:25:53 -0800779 // Remove all previous labels.
780 removeLinkLabels();
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800781
Simon Hunte2575b62014-11-18 15:25:53 -0800782 // Now hilight all links in the paths payload, and attach
783 // labels to them, if they are defined.
Simon Hunta255a2c2014-11-13 22:29:35 -0800784 paths.forEach(function (p) {
Simon Hunte2575b62014-11-18 15:25:53 -0800785 var n = p.links.length,
786 i,
787 ldata;
788
Thomas Vachuska4731f122014-11-20 04:56:19 -0800789 hasTraffic = hasTraffic || p.traffic;
Simon Hunte2575b62014-11-18 15:25:53 -0800790 for (i=0; i<n; i++) {
791 ldata = findLinkById(p.links[i]);
Thomas Vachuska4731f122014-11-20 04:56:19 -0800792 if (ldata && ldata.el) {
Simon Hunte2575b62014-11-18 15:25:53 -0800793 ldata.el.classed(p.class, true);
794 ldata.label = p.labels[i];
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800795 }
Simon Hunte2575b62014-11-18 15:25:53 -0800796 }
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800797 });
Thomas Vachuska4731f122014-11-20 04:56:19 -0800798
Simon Hunte2575b62014-11-18 15:25:53 -0800799 updateLinks();
Thomas Vachuska4731f122014-11-20 04:56:19 -0800800
801 if (hasTraffic && !antTimer) {
802 startAntTimer();
803 } else if (!hasTraffic && antTimer) {
804 stopAntTimer();
805 }
Simon Huntb53e0682014-11-12 13:32:01 -0800806 }
807
Simon Hunt56d51852014-11-09 13:03:35 -0800808 // ...............................
809
810 function stillToImplement(data) {
811 var p = data.payload;
812 note(data.event, p.id);
Simon Hunt7b403bc2014-11-22 19:01:00 -0800813 if (!config.useLiveData) {
814 network.view.alert('Not yet implemented: "' + data.event + '"');
815 }
Simon Hunt56d51852014-11-09 13:03:35 -0800816 }
Simon Hunt99c13842014-11-06 18:23:12 -0800817
818 function unknownEvent(data) {
Simon Hunt50128c02014-11-08 13:36:15 -0800819 network.view.alert('Unknown event type: "' + data.event + '"');
Simon Hunt99c13842014-11-06 18:23:12 -0800820 }
821
822 function handleServerEvent(data) {
823 var fn = eventDispatch[data.event] || unknownEvent;
824 fn(data);
825 }
826
827 // ==============================
Simon Hunt61d04042014-11-11 17:27:16 -0800828 // Out-going messages...
829
Simon Huntb53e0682014-11-12 13:32:01 -0800830 function userFeedback(msg) {
831 // for now, use the alert pane as is. Maybe different alert style in
832 // the future (centered on view; dismiss button?)
833 network.view.alert(msg);
834 }
835
836 function nSel() {
837 return selectOrder.length;
838 }
Simon Hunt61d04042014-11-11 17:27:16 -0800839 function getSel(idx) {
840 return selections[selectOrder[idx]];
841 }
Simon Huntb53e0682014-11-12 13:32:01 -0800842 function getSelId(idx) {
843 return getSel(idx).obj.id;
844 }
Thomas Vachuska9edca302014-11-22 17:06:42 -0800845 function getSelIds(start, endOffset) {
846 var end = selectOrder.length - endOffset;
847 var ids = [];
848 selectOrder.slice(start, end).forEach(function (d) {
849 ids.push(getSelId(d));
850 });
851 return ids;
852 }
Simon Huntb53e0682014-11-12 13:32:01 -0800853 function allSelectionsClass(cls) {
854 for (var i=0, n=nSel(); i<n; i++) {
855 if (getSel(i).obj.class !== cls) {
856 return false;
857 }
858 }
859 return true;
860 }
Simon Hunt61d04042014-11-11 17:27:16 -0800861
Thomas Vachuska47635c62014-11-22 01:21:36 -0800862
863 function toggleInstances() {
864 if (!oiBox.isVisible()) {
865 oiBox.show();
866 } else {
867 oiBox.hide();
868 }
869 }
870
871 function toggleSummary() {
872 if (!summaryPane.isVisible()) {
873 requestSummary();
874 } else {
875 cancelSummary();
876 }
877 }
878
879 // request overall summary data
880 function requestSummary() {
881 sendMessage('requestSummary', {});
882 }
883
884 function cancelSummary() {
885 sendMessage('cancelSummary', {});
886 summaryPane.hide();
887 }
888
Simon Hunt61d04042014-11-11 17:27:16 -0800889 // request details for the selected element
Simon Huntd72bc702014-11-13 18:38:04 -0800890 // invoked from selection of a single node.
Simon Hunt61d04042014-11-11 17:27:16 -0800891 function requestDetails() {
892 var data = getSel(0).obj,
893 payload = {
894 id: data.id,
895 class: data.class
896 };
897 sendMessage('requestDetails', payload);
898 }
899
Thomas Vachuska9edca302014-11-22 17:06:42 -0800900 function addHostIntentAction() {
Simon Huntd72bc702014-11-13 18:38:04 -0800901 sendMessage('addHostIntent', {
Thomas Vachuska9edca302014-11-22 17:06:42 -0800902 one: selectOrder[0],
903 two: selectOrder[1],
904 ids: selectOrder
Simon Huntd72bc702014-11-13 18:38:04 -0800905 });
Thomas Vachuska9edca302014-11-22 17:06:42 -0800906 network.view.flash('Host-to-Host flow added');
Simon Huntd72bc702014-11-13 18:38:04 -0800907 }
908
Thomas Vachuska9edca302014-11-22 17:06:42 -0800909 function addMultiSourceIntentAction() {
910 sendMessage('addMultiSourceIntent', {
911 src: selectOrder.slice(0, selectOrder.length - 1),
912 dst: selectOrder[selectOrder.length - 1],
913 ids: selectOrder
914 });
915 network.view.flash('Multi-Source flow added');
Thomas Vachuska29617e52014-11-20 03:17:46 -0800916 }
917
Thomas Vachuska9edca302014-11-22 17:06:42 -0800918
Thomas Vachuska47635c62014-11-22 01:21:36 -0800919 function cancelTraffic() {
920 sendMessage('cancelTraffic', {});
921 }
922
Thomas Vachuska9edca302014-11-22 17:06:42 -0800923 function requestTrafficForMode() {
924 if (hoverMode === hoverModeAll) {
925 requestAllTraffic();
926 } else if (hoverMode === hoverModeFlows) {
927 requestDeviceLinkFlows();
928 } else if (hoverMode === hoverModeIntents) {
929 requestSelectTraffic();
Simon Huntd72bc702014-11-13 18:38:04 -0800930 }
Thomas Vachuska9edca302014-11-22 17:06:42 -0800931 }
Simon Huntd72bc702014-11-13 18:38:04 -0800932
Thomas Vachuska9edca302014-11-22 17:06:42 -0800933 function showTrafficAction() {
934 hoverMode = hoverModeIntents;
935 requestSelectTraffic();
936 network.view.flash('Related Traffic');
937 }
938
939 function requestSelectTraffic() {
940 if (validateSelectionContext()) {
941 var hoverId = (hoverMode === hoverModeIntents && hovered &&
942 (hovered.class === 'host' || hovered.class === 'device'))
Simon Huntd72bc702014-11-13 18:38:04 -0800943 ? hovered.id : '';
Thomas Vachuska9edca302014-11-22 17:06:42 -0800944 sendMessage('requestTraffic', {
945 ids: selectOrder,
946 hover: hoverId
947 });
948 }
Simon Huntd72bc702014-11-13 18:38:04 -0800949 }
950
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800951
Thomas Vachuska29617e52014-11-20 03:17:46 -0800952 function showDeviceLinkFlowsAction() {
Thomas Vachuska9edca302014-11-22 17:06:42 -0800953 hoverMode = hoverModeFlows;
954 requestDeviceLinkFlows();
Thomas Vachuskac59658c2014-11-21 13:13:36 -0800955 network.view.flash('Device Flows');
Thomas Vachuska29617e52014-11-20 03:17:46 -0800956 }
957
Thomas Vachuska9edca302014-11-22 17:06:42 -0800958 function requestDeviceLinkFlows() {
959 if (validateSelectionContext()) {
960 var hoverId = (hoverMode === hoverModeFlows && hovered &&
961 (hovered.class === 'device')) ? hovered.id : '';
962 sendMessage('requestDeviceLinkFlows', {
963 ids: selectOrder,
964 hover: hoverId
965 });
966 }
967 }
968
969
970 function showAllTrafficAction() {
971 hoverMode = hoverModeAll;
972 requestAllTraffic();
973 network.view.flash('All Traffic');
974 }
975
976 function requestAllTraffic() {
977 sendMessage('requestAllTraffic', {});
978 }
979
980 function validateSelectionContext() {
Thomas Vachuska29617e52014-11-20 03:17:46 -0800981 if (!hovered && nSel() === 0) {
Thomas Vachuska47635c62014-11-22 01:21:36 -0800982 cancelTraffic();
Thomas Vachuska9edca302014-11-22 17:06:42 -0800983 return false;
Thomas Vachuska29617e52014-11-20 03:17:46 -0800984 }
Thomas Vachuska9edca302014-11-22 17:06:42 -0800985 return true;
Thomas Vachuska29617e52014-11-20 03:17:46 -0800986 }
Simon Huntd72bc702014-11-13 18:38:04 -0800987
Simon Hunta6a9fe72014-11-20 11:17:12 -0800988
Simon Hunt61d04042014-11-11 17:27:16 -0800989 // ==============================
Simon Hunta5e89142014-11-14 07:00:33 -0800990 // onos instance panel functions
Simon Huntb82f6902014-11-22 11:53:15 -0800991
Simon Hunt7b403bc2014-11-22 19:01:00 -0800992 var instCfg = {
993 rectPad: 8,
994 nodeOx: 9,
995 nodeOy: 9,
996 nodeDim: 40,
997 birdOx: 19,
998 birdOy: 21,
999 birdDim: 21,
1000 uiDy: 45,
1001 titleDy: 30,
1002 textYOff: 20,
1003 textYSpc: 15
1004 };
1005
1006 function viewBox(dim) {
1007 return '0 0 ' + dim.w + ' ' + dim.h;
1008 }
1009
1010 function instRectAttr(dim) {
1011 var pad = instCfg.rectPad;
1012 return {
1013 x: pad,
1014 y: pad,
1015 width: dim.w - pad*2,
1016 height: dim.h - pad*2,
1017 rx: 12
1018 };
1019 }
1020
1021 function computeDim(self) {
1022 var css = window.getComputedStyle(self);
1023 return {
1024 w: stripPx(css.width),
1025 h: stripPx(css.height)
1026 };
Simon Huntb82f6902014-11-22 11:53:15 -08001027 }
Simon Hunta5e89142014-11-14 07:00:33 -08001028
1029 function updateInstances() {
1030 var onoses = oiBox.el.selectAll('.onosInst')
Simon Huntb82f6902014-11-22 11:53:15 -08001031 .data(onosOrder, function (d) { return d.id; }),
Simon Hunt7b403bc2014-11-22 19:01:00 -08001032 instDim = {w:0,h:0},
1033 c = instCfg;
Simon Hunta5e89142014-11-14 07:00:33 -08001034
Simon Hunt7b403bc2014-11-22 19:01:00 -08001035 function nSw(n) {
1036 return '# Switches: ' + n;
1037 }
Simon Hunta5e89142014-11-14 07:00:33 -08001038
Simon Huntb82f6902014-11-22 11:53:15 -08001039 // operate on existing onos instances if necessary
1040 onoses.each(function (d) {
1041 var el = d3.select(this),
1042 svg = el.select('svg');
Simon Hunt7b403bc2014-11-22 19:01:00 -08001043 instDim = computeDim(this);
Simon Huntb82f6902014-11-22 11:53:15 -08001044
1045 // update online state
1046 el.classed('online', d.online);
1047
1048 // update ui-attached state
1049 svg.select('use.uiBadge').remove();
1050 if (d.uiAttached) {
1051 attachUiBadge(svg);
1052 }
1053
Simon Hunt7b403bc2014-11-22 19:01:00 -08001054 function updAttr(id, value) {
1055 svg.select('text.instLabel.'+id).text(value);
1056 }
1057
1058 updAttr('ip', d.ip);
1059 updAttr('ns', nSw(d.switches));
Simon Huntb82f6902014-11-22 11:53:15 -08001060 });
1061
1062
1063 // operate on new onos instances
Simon Hunta5e89142014-11-14 07:00:33 -08001064 var entering = onoses.enter()
1065 .append('div')
1066 .attr('class', 'onosInst')
1067 .classed('online', function (d) { return d.online; })
Simon Hunt9c15eca2014-11-15 18:37:59 -08001068 .on('click', clickInst);
1069
Simon Huntb82f6902014-11-22 11:53:15 -08001070 entering.each(function (d) {
Simon Hunt9c15eca2014-11-15 18:37:59 -08001071 var el = d3.select(this),
Simon Hunt7b403bc2014-11-22 19:01:00 -08001072 rectAttr,
1073 svg;
1074 instDim = computeDim(this);
1075 rectAttr = instRectAttr(instDim);
Simon Hunt9c15eca2014-11-15 18:37:59 -08001076
Simon Hunt7b403bc2014-11-22 19:01:00 -08001077 svg = el.append('svg').attr({
1078 width: instDim.w,
1079 height: instDim.h,
1080 viewBox: viewBox(instDim)
Simon Hunt95908012014-11-20 10:20:26 -08001081 });
Simon Huntb82f6902014-11-22 11:53:15 -08001082
Simon Hunt7b403bc2014-11-22 19:01:00 -08001083 svg.append('rect').attr(rectAttr);
Simon Hunt9c15eca2014-11-15 18:37:59 -08001084
Simon Hunt7b403bc2014-11-22 19:01:00 -08001085 appendGlyph(svg, c.nodeOx, c.nodeOy, c.nodeDim, '#node');
1086 appendBadge(svg, c.birdOx, c.birdOy, c.birdDim, '#bird');
Simon Huntb82f6902014-11-22 11:53:15 -08001087
1088 if (d.uiAttached) {
1089 attachUiBadge(svg);
1090 }
1091
Simon Hunt7b403bc2014-11-22 19:01:00 -08001092 var left = c.nodeOx + c.nodeDim,
1093 len = rectAttr.width - left,
1094 hlen = len / 2,
1095 midline = hlen + left;
Simon Hunt9c15eca2014-11-15 18:37:59 -08001096
Simon Hunt7b403bc2014-11-22 19:01:00 -08001097 // title
1098 svg.append('text')
1099 .attr({
1100 class: 'instTitle',
1101 x: midline,
1102 y: c.titleDy
1103 })
1104 .text(d.id);
1105
1106 // a couple of attributes
1107 var ty = c.titleDy + c.textYOff;
1108
1109 function addAttr(id, label) {
1110 svg.append('text').attr({
1111 class: 'instLabel ' + id,
1112 x: midline,
1113 y: ty
1114 }).text(label);
1115 ty += c.textYSpc;
1116 }
1117
1118 addAttr('ip', d.ip);
1119 addAttr('ns', nSw(d.switches));
Simon Hunt9c15eca2014-11-15 18:37:59 -08001120 });
Simon Hunta5e89142014-11-14 07:00:33 -08001121
1122 // operate on existing + new onoses here
1123
Simon Hunt7b403bc2014-11-22 19:01:00 -08001124 // adjust the panel size appropriately...
1125 oiBox.width(instDim.w * onosOrder.length);
1126 oiBox.height(instDim.h);
1127
1128 // remove any outgoing instances
1129 onoses.exit().remove();
Simon Hunta5e89142014-11-14 07:00:33 -08001130 }
1131
Simon Hunt9462e8c2014-11-14 17:28:09 -08001132 function clickInst(d) {
1133 var el = d3.select(this),
1134 aff = el.classed('affinity');
1135 if (!aff) {
1136 setAffinity(el, d);
1137 } else {
1138 cancelAffinity();
1139 }
1140 }
1141
1142 function setAffinity(el, d) {
1143 d3.selectAll('.onosInst')
1144 .classed('mastership', true)
1145 .classed('affinity', false);
1146 el.classed('affinity', true);
1147
1148 suppressLayers(true);
1149 node.each(function (n) {
1150 if (n.master === d.id) {
1151 n.el.classed('suppressed', false);
1152 }
1153 });
1154 oiShowMaster = true;
1155 }
1156
1157 function cancelAffinity() {
1158 d3.selectAll('.onosInst')
1159 .classed('mastership affinity', false);
1160 restoreLayerState();
1161 oiShowMaster = false;
1162 }
1163
Simon Hunt7b403bc2014-11-22 19:01:00 -08001164 // TODO: these should be moved out to utility module.
1165 function stripPx(s) {
1166 return s.replace(/px$/,'');
1167 }
1168
1169 function appendUse(svg, ox, oy, dim, iid, cls) {
1170 var use = svg.append('use').attr({
1171 transform: translate(ox,oy),
1172 'xlink:href': iid,
1173 width: dim,
1174 height: dim
1175 });
1176 if (cls) {
1177 use.classed(cls, true);
1178 }
1179 return use;
1180 }
1181
1182 function appendGlyph(svg, ox, oy, dim, iid, cls) {
1183 appendUse(svg, ox, oy, dim, iid, cls).classed('glyphIcon', true);
1184 }
1185
1186 function appendBadge(svg, ox, oy, dim, iid, cls) {
1187 appendUse(svg, ox, oy, dim, iid,cls ).classed('badgeIcon', true);
1188 }
1189
1190 function attachUiBadge(svg) {
1191 appendBadge(svg, 12, instCfg.uiDy, 30, '#uiAttached', 'uiBadge');
1192 }
1193
Simon Hunta5e89142014-11-14 07:00:33 -08001194 // ==============================
Simon Hunt99c13842014-11-06 18:23:12 -08001195 // force layout modification functions
1196
1197 function translate(x, y) {
1198 return 'translate(' + x + ',' + y + ')';
1199 }
1200
Simon Hunte2575b62014-11-18 15:25:53 -08001201 function rotate(deg) {
1202 return 'rotate(' + deg + ')';
1203 }
1204
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001205 function missMsg(what, id) {
1206 return '\n[' + what + '] "' + id + '" missing ';
1207 }
1208
1209 function linkEndPoints(srcId, dstId) {
1210 var srcNode = network.lookup[srcId],
1211 dstNode = network.lookup[dstId],
1212 sMiss = !srcNode ? missMsg('src', srcId) : '',
1213 dMiss = !dstNode ? missMsg('dst', dstId) : '';
1214
1215 if (sMiss || dMiss) {
1216 logicError('Node(s) not on map for link:\n' + sMiss + dMiss);
1217 return null;
1218 }
1219 return {
1220 source: srcNode,
1221 target: dstNode,
1222 x1: srcNode.x,
1223 y1: srcNode.y,
1224 x2: dstNode.x,
1225 y2: dstNode.y
1226 };
1227 }
1228
Simon Hunt56d51852014-11-09 13:03:35 -08001229 function createHostLink(host) {
1230 var src = host.id,
1231 dst = host.cp.device,
Simon Hunt7cd48f32014-11-09 23:42:50 -08001232 id = host.ingress,
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001233 lnk = linkEndPoints(src, dst);
Simon Hunt56d51852014-11-09 13:03:35 -08001234
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001235 if (!lnk) {
Simon Hunt56d51852014-11-09 13:03:35 -08001236 return null;
1237 }
1238
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001239 // Synthesize link ...
1240 $.extend(lnk, {
Simon Hunt8257f4c2014-11-16 19:34:54 -08001241 key: id,
Simon Hunt56d51852014-11-09 13:03:35 -08001242 class: 'link',
Simon Hunt8257f4c2014-11-16 19:34:54 -08001243
1244 type: function () { return 'hostLink'; },
1245 // TODO: ideally, we should see if our edge switch is online...
1246 online: function () { return true; },
1247 linkWidth: function () { return 1; }
Simon Hunt7cd48f32014-11-09 23:42:50 -08001248 });
Simon Hunt99c13842014-11-06 18:23:12 -08001249 return lnk;
1250 }
1251
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001252 function createLink(link) {
Simon Hunta6a9fe72014-11-20 11:17:12 -08001253 var lnk = linkEndPoints(link.src, link.dst);
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001254
1255 if (!lnk) {
1256 return null;
1257 }
1258
Simon Hunt8257f4c2014-11-16 19:34:54 -08001259 $.extend(lnk, {
1260 key: link.id,
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001261 class: 'link',
Simon Hunt8257f4c2014-11-16 19:34:54 -08001262 fromSource: link,
1263
1264 // functions to aggregate dual link state
1265 type: function () {
1266 var s = lnk.fromSource,
1267 t = lnk.fromTarget;
1268 return (s && s.type) || (t && t.type) || defaultLinkType;
1269 },
1270 online: function () {
1271 var s = lnk.fromSource,
1272 t = lnk.fromTarget;
1273 return (s && s.online) || (t && t.online);
1274 },
1275 linkWidth: function () {
1276 var s = lnk.fromSource,
1277 t = lnk.fromTarget,
1278 ws = (s && s.linkWidth) || 0,
1279 wt = (t && t.linkWidth) || 0;
1280 return Math.max(ws, wt);
1281 }
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001282 });
1283 return lnk;
Simon Hunt1a9eff92014-11-07 11:06:34 -08001284 }
1285
Simon Hunte2575b62014-11-18 15:25:53 -08001286 function removeLinkLabels() {
1287 network.links.forEach(function (d) {
1288 d.label = '';
1289 });
1290 }
1291
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001292 var widthRatio = 1.4,
1293 linkScale = d3.scale.linear()
1294 .domain([1, 12])
1295 .range([widthRatio, 12 * widthRatio])
1296 .clamp(true);
1297
Simon Hunt99c13842014-11-06 18:23:12 -08001298 function updateLinks() {
1299 link = linkG.selectAll('.link')
Simon Hunt8257f4c2014-11-16 19:34:54 -08001300 .data(network.links, function (d) { return d.key; });
Simon Hunt99c13842014-11-06 18:23:12 -08001301
1302 // operate on existing links, if necessary
1303 // link .foo() .bar() ...
1304
1305 // operate on entering links:
1306 var entering = link.enter()
1307 .append('line')
1308 .attr({
Simon Hunt99c13842014-11-06 18:23:12 -08001309 x1: function (d) { return d.x1; },
1310 y1: function (d) { return d.y1; },
1311 x2: function (d) { return d.x2; },
1312 y2: function (d) { return d.y2; },
Simon Hunt1a9eff92014-11-07 11:06:34 -08001313 stroke: config.topo.linkInColor,
1314 'stroke-width': config.topo.linkInWidth
Simon Hunt99c13842014-11-06 18:23:12 -08001315 });
1316
1317 // augment links
Simon Hunt7cd48f32014-11-09 23:42:50 -08001318 entering.each(function (d) {
1319 var link = d3.select(this);
1320 // provide ref to element selection from backing data....
1321 d.el = link;
Simon Hunt8257f4c2014-11-16 19:34:54 -08001322 restyleLinkElement(d);
Simon Hunt7cd48f32014-11-09 23:42:50 -08001323 });
Thomas Vachuska4830d392014-11-09 17:09:56 -08001324
1325 // operate on both existing and new links, if necessary
1326 //link .foo() .bar() ...
1327
Simon Hunte2575b62014-11-18 15:25:53 -08001328 // apply or remove labels
1329 var labelData = getLabelData();
1330 applyLinkLabels(labelData);
1331
Thomas Vachuska4830d392014-11-09 17:09:56 -08001332 // operate on exiting links:
Thomas Vachuska4830d392014-11-09 17:09:56 -08001333 link.exit()
Simon Hunt13bf9c82014-11-18 07:26:44 -08001334 .attr('stroke-dasharray', '3, 3')
1335 .style('opacity', 0.5)
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001336 .transition()
Simon Huntea80eb42014-11-11 13:46:57 -08001337 .duration(1500)
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001338 .attr({
Simon Hunt13bf9c82014-11-18 07:26:44 -08001339 'stroke-dasharray': '3, 12',
1340 stroke: config.topo.linkOutColor,
1341 'stroke-width': config.topo.linkOutWidth
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001342 })
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001343 .style('opacity', 0.0)
Thomas Vachuska4830d392014-11-09 17:09:56 -08001344 .remove();
Simon Hunte2575b62014-11-18 15:25:53 -08001345
1346 // NOTE: invoke a single tick to force the labels to position
1347 // onto their links.
1348 tick();
1349 }
1350
1351 function getLabelData() {
1352 // create the backing data for showing labels..
1353 var data = [];
1354 link.each(function (d) {
1355 if (d.label) {
1356 data.push({
1357 id: 'lab-' + d.key,
1358 key: d.key,
1359 label: d.label,
1360 ldata: d
1361 });
1362 }
1363 });
1364 return data;
1365 }
1366
1367 var linkLabelOffset = '0.3em';
1368
1369 function applyLinkLabels(data) {
1370 var entering;
1371
1372 linkLabel = linkLabelG.selectAll('.linkLabel')
1373 .data(data, function (d) { return d.id; });
1374
Simon Hunt56a2ea42014-11-19 12:39:31 -08001375 // for elements already existing, we need to update the text
1376 // and adjust the rectangle size to fit
1377 linkLabel.each(function (d) {
1378 var el = d3.select(this),
1379 rect = el.select('rect'),
1380 text = el.select('text');
1381 text.text(d.label);
1382 rect.attr(rectAroundText(el));
1383 });
Thomas Vachuskaf75b7ab2014-11-19 12:15:55 -08001384
Simon Hunte2575b62014-11-18 15:25:53 -08001385 entering = linkLabel.enter().append('g')
1386 .classed('linkLabel', true)
1387 .attr('id', function (d) { return d.id; });
1388
1389 entering.each(function (d) {
1390 var el = d3.select(this),
1391 rect,
1392 text,
1393 parms = {
1394 x1: d.ldata.x1,
1395 y1: d.ldata.y1,
1396 x2: d.ldata.x2,
1397 y2: d.ldata.y2
1398 };
1399
1400 d.el = el;
1401 rect = el.append('rect');
1402 text = el.append('text').text(d.label);
1403 rect.attr(rectAroundText(el));
1404 text.attr('dy', linkLabelOffset);
1405
1406 el.attr('transform', transformLabel(parms));
1407 });
1408
1409 // Remove any links that are no longer required.
1410 linkLabel.exit().remove();
1411 }
1412
1413 function rectAroundText(el) {
1414 var text = el.select('text'),
1415 box = text.node().getBBox();
1416
1417 // translate the bbox so that it is centered on [x,y]
1418 box.x = -box.width / 2;
1419 box.y = -box.height / 2;
1420
1421 // add padding
1422 box.x -= 1;
1423 box.width += 2;
1424 return box;
1425 }
1426
1427 function transformLabel(p) {
1428 var dx = p.x2 - p.x1,
1429 dy = p.y2 - p.y1,
1430 xMid = dx/2 + p.x1,
1431 yMid = dy/2 + p.y1;
Simon Hunte2575b62014-11-18 15:25:53 -08001432 return translate(xMid, yMid);
Simon Hunt99c13842014-11-06 18:23:12 -08001433 }
1434
1435 function createDeviceNode(device) {
1436 // start with the object as is
1437 var node = device,
Simon Huntbb282f52014-11-10 11:08:19 -08001438 type = device.type,
Simon Huntc72967b2014-11-20 09:21:42 -08001439 svgCls = type ? 'node device ' + type : 'node device',
1440 labels = device.labels || [];
1441
Simon Hunt99c13842014-11-06 18:23:12 -08001442 // Augment as needed...
1443 node.class = 'device';
Simon Huntbb282f52014-11-10 11:08:19 -08001444 node.svgClass = device.online ? svgCls + ' online' : svgCls;
Simon Hunt99c13842014-11-06 18:23:12 -08001445 positionNode(node);
Simon Hunt99c13842014-11-06 18:23:12 -08001446 return node;
1447 }
1448
Simon Hunt56d51852014-11-09 13:03:35 -08001449 function createHostNode(host) {
1450 // start with the object as is
1451 var node = host;
1452
1453 // Augment as needed...
1454 node.class = 'host';
Simon Hunt7cd48f32014-11-09 23:42:50 -08001455 if (!node.type) {
Simon Hunt209155e2014-11-21 12:16:09 -08001456 node.type = 'endstation';
Simon Hunt7cd48f32014-11-09 23:42:50 -08001457 }
Simon Hunt7fa116d2014-11-17 14:16:55 -08001458 node.svgClass = 'node host ' + node.type;
Simon Hunt56d51852014-11-09 13:03:35 -08001459 positionNode(node);
Simon Hunt56d51852014-11-09 13:03:35 -08001460 return node;
1461 }
1462
Simon Hunt99c13842014-11-06 18:23:12 -08001463 function positionNode(node) {
1464 var meta = node.metaUi,
Simon Huntac9e24f2014-11-12 10:12:21 -08001465 x = meta && meta.x,
1466 y = meta && meta.y,
1467 xy;
Simon Hunt99c13842014-11-06 18:23:12 -08001468
Simon Huntac9e24f2014-11-12 10:12:21 -08001469 // If we have [x,y] already, use that...
Simon Hunt99c13842014-11-06 18:23:12 -08001470 if (x && y) {
1471 node.fixed = true;
Simon Huntac9e24f2014-11-12 10:12:21 -08001472 node.x = x;
1473 node.y = y;
1474 return;
Simon Hunt99c13842014-11-06 18:23:12 -08001475 }
Simon Huntac9e24f2014-11-12 10:12:21 -08001476
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001477 var location = node.location;
1478 if (location && location.type === 'latlng') {
1479 var coord = geoMapProjection([location.lng, location.lat]);
1480 node.fixed = true;
1481 node.x = coord[0];
1482 node.y = coord[1];
1483 return;
1484 }
1485
Simon Huntac9e24f2014-11-12 10:12:21 -08001486 // Note: Placing incoming unpinned nodes at exactly the same point
1487 // (center of the view) causes them to explode outwards when
1488 // the force layout kicks in. So, we spread them out a bit
1489 // initially, to provide a more serene layout convergence.
1490 // Additionally, if the node is a host, we place it near
1491 // the device it is connected to.
1492
1493 function spread(s) {
1494 return Math.floor((Math.random() * s) - s/2);
1495 }
1496
1497 function randDim(dim) {
1498 return dim / 2 + spread(dim * 0.7071);
1499 }
1500
1501 function rand() {
1502 return {
1503 x: randDim(network.view.width()),
1504 y: randDim(network.view.height())
1505 };
1506 }
1507
1508 function near(node) {
1509 var min = 12,
1510 dx = spread(12),
1511 dy = spread(12);
1512 return {
1513 x: node.x + min + dx,
1514 y: node.y + min + dy
1515 };
1516 }
1517
1518 function getDevice(cp) {
1519 var d = network.lookup[cp.device];
1520 return d || rand();
1521 }
1522
1523 xy = (node.class === 'host') ? near(getDevice(node.cp)) : rand();
1524 $.extend(node, xy);
Simon Hunt99c13842014-11-06 18:23:12 -08001525 }
1526
Thomas Vachuska89543292014-11-19 11:28:33 -08001527 function iconUrl(d) {
1528 return 'img/' + d.type + '.png';
Simon Hunt99c13842014-11-06 18:23:12 -08001529 }
1530
Simon Huntc72967b2014-11-20 09:21:42 -08001531 function iconGlyphUrl(d) {
1532 var which = d.type || 'unknown';
1533 return '#' + which;
1534 }
1535
Simon Hunt99c13842014-11-06 18:23:12 -08001536 // returns the newly computed bounding box of the rectangle
1537 function adjustRectToFitText(n) {
1538 var text = n.select('text'),
1539 box = text.node().getBBox(),
1540 lab = config.labels;
1541
1542 text.attr('text-anchor', 'middle')
1543 .attr('y', '-0.8em')
1544 .attr('x', lab.imgPad/2);
1545
1546 // translate the bbox so that it is centered on [x,y]
1547 box.x = -box.width / 2;
1548 box.y = -box.height / 2;
1549
1550 // add padding
1551 box.x -= (lab.padLR + lab.imgPad/2);
1552 box.width += lab.padLR * 2 + lab.imgPad;
1553 box.y -= lab.padTB;
1554 box.height += lab.padTB * 2;
1555
1556 return box;
1557 }
1558
Simon Hunt1a9eff92014-11-07 11:06:34 -08001559 function mkSvgClass(d) {
1560 return d.fixed ? d.svgClass + ' fixed' : d.svgClass;
1561 }
1562
Simon Hunt7cd48f32014-11-09 23:42:50 -08001563 function hostLabel(d) {
1564 var idx = (hostLabelIndex < d.labels.length) ? hostLabelIndex : 0;
1565 return d.labels[idx];
1566 }
1567 function deviceLabel(d) {
1568 var idx = (deviceLabelIndex < d.labels.length) ? deviceLabelIndex : 0;
1569 return d.labels[idx];
1570 }
Simon Huntc72967b2014-11-20 09:21:42 -08001571 function trimLabel(label) {
1572 return (label && label.trim()) || '';
1573 }
1574
1575 function emptyBox() {
1576 return {
1577 x: -2,
1578 y: -2,
1579 width: 4,
1580 height: 4
1581 };
Simon Hunt7cd48f32014-11-09 23:42:50 -08001582 }
1583
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001584 function updateDeviceLabel(d) {
Simon Huntc72967b2014-11-20 09:21:42 -08001585 var label = trimLabel(deviceLabel(d)),
1586 noLabel = !label,
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001587 node = d.el,
Simon Huntc72967b2014-11-20 09:21:42 -08001588 box,
1589 dx,
1590 dy;
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001591
1592 node.select('text')
1593 .text(label)
1594 .style('opacity', 0)
1595 .transition()
1596 .style('opacity', 1);
1597
Simon Huntc72967b2014-11-20 09:21:42 -08001598 if (noLabel) {
1599 box = emptyBox();
1600 dx = -config.icons.device.dim/2;
1601 dy = -config.icons.device.dim/2;
1602 } else {
1603 box = adjustRectToFitText(node);
1604 dx = box.x + config.icons.xoff;
1605 dy = box.y + config.icons.yoff;
1606 }
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001607
1608 node.select('rect')
1609 .transition()
1610 .attr(box);
1611
Simon Huntc72967b2014-11-20 09:21:42 -08001612 node.select('g.deviceIcon')
Thomas Vachuska89543292014-11-19 11:28:33 -08001613 .transition()
Simon Huntc72967b2014-11-20 09:21:42 -08001614 .attr('transform', translate(dx, dy));
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001615 }
1616
1617 function updateHostLabel(d) {
1618 var label = hostLabel(d),
1619 host = d.el;
1620
1621 host.select('text').text(label);
1622 }
1623
Simon Hunta6a9fe72014-11-20 11:17:12 -08001624 // TODO: should be using updateNodes() to do the upates!
Simon Huntbb282f52014-11-10 11:08:19 -08001625 function updateDeviceState(nodeData) {
1626 nodeData.el.classed('online', nodeData.online);
1627 updateDeviceLabel(nodeData);
1628 // TODO: review what else might need to be updated
1629 }
1630
1631 function updateHostState(hostData) {
1632 updateHostLabel(hostData);
1633 // TODO: review what else might need to be updated
1634 }
1635
Simon Hunt6ac93f32014-11-13 12:17:27 -08001636 function nodeMouseOver(d) {
Simon Hunt6ac93f32014-11-13 12:17:27 -08001637 hovered = d;
Thomas Vachuska9edca302014-11-22 17:06:42 -08001638 requestTrafficForMode();
Simon Hunt6ac93f32014-11-13 12:17:27 -08001639 }
1640
1641 function nodeMouseOut(d) {
Simon Hunt6ac93f32014-11-13 12:17:27 -08001642 hovered = null;
Thomas Vachuska9edca302014-11-22 17:06:42 -08001643 requestTrafficForMode();
Simon Hunt6ac93f32014-11-13 12:17:27 -08001644 }
Simon Huntbb282f52014-11-10 11:08:19 -08001645
Simon Hunteb1514d2014-11-20 09:57:29 -08001646 function addHostIcon(node, radius, iid) {
Thomas Vachuska89543292014-11-19 11:28:33 -08001647 var dim = radius * 1.5,
1648 xlate = -dim / 2;
1649
Simon Hunteb1514d2014-11-20 09:57:29 -08001650 node.append('use').attr({
1651 class: 'glyphIcon hostIcon',
1652 transform: translate(xlate,xlate),
1653 'xlink:href': iid,
1654 width: dim,
1655 height: dim
1656 });
Thomas Vachuska89543292014-11-19 11:28:33 -08001657 }
1658
Simon Hunt99c13842014-11-06 18:23:12 -08001659 function updateNodes() {
1660 node = nodeG.selectAll('.node')
1661 .data(network.nodes, function (d) { return d.id; });
1662
Simon Huntc72967b2014-11-20 09:21:42 -08001663 // TODO: operate on existing nodes
Simon Hunt7cd48f32014-11-09 23:42:50 -08001664 // update host labels
Simon Hunt99c13842014-11-06 18:23:12 -08001665 //node .foo() .bar() ...
1666
1667 // operate on entering nodes:
1668 var entering = node.enter()
1669 .append('g')
1670 .attr({
1671 id: function (d) { return safeId(d.id); },
Simon Hunt1a9eff92014-11-07 11:06:34 -08001672 class: mkSvgClass,
Simon Hunt99c13842014-11-06 18:23:12 -08001673 transform: function (d) { return translate(d.x, d.y); },
1674 opacity: 0
1675 })
Simon Hunt1a9eff92014-11-07 11:06:34 -08001676 .call(network.drag)
Simon Hunt6ac93f32014-11-13 12:17:27 -08001677 .on('mouseover', nodeMouseOver)
1678 .on('mouseout', nodeMouseOut)
Simon Hunt99c13842014-11-06 18:23:12 -08001679 .transition()
1680 .attr('opacity', 1);
1681
1682 // augment device nodes...
1683 entering.filter('.device').each(function (d) {
1684 var node = d3.select(this),
Simon Huntc72967b2014-11-20 09:21:42 -08001685 label = trimLabel(deviceLabel(d)),
1686 noLabel = !label,
Simon Hunt99c13842014-11-06 18:23:12 -08001687 box;
1688
Simon Hunt7cd48f32014-11-09 23:42:50 -08001689 // provide ref to element from backing data....
1690 d.el = node;
1691
Simon Hunt99c13842014-11-06 18:23:12 -08001692 node.append('rect')
1693 .attr({
Simon Hunta3dd9572014-11-20 15:22:41 -08001694 rx: 5,
1695 ry: 5
Simon Hunt99c13842014-11-06 18:23:12 -08001696 });
1697
1698 node.append('text')
Simon Hunt7cd48f32014-11-09 23:42:50 -08001699 .text(label)
Simon Hunt99c13842014-11-06 18:23:12 -08001700 .attr('dy', '1.1em');
1701
1702 box = adjustRectToFitText(node);
Simon Hunta3dd9572014-11-20 15:22:41 -08001703 node.select('rect').attr(box);
Simon Huntc72967b2014-11-20 09:21:42 -08001704 addDeviceIcon(node, box, noLabel, iconGlyphUrl(d));
Simon Huntc7ee0662014-11-05 16:44:37 -08001705 });
Simon Hunt934c3ce2014-11-05 11:45:07 -08001706
Thomas Vachuska89543292014-11-19 11:28:33 -08001707 // TODO: better place for this configuration state
1708 var defaultHostRadius = 9,
1709 hostRadius = {
1710 bgpSpeaker: 14,
1711 router: 14,
Thomas Vachuska60d72bf2014-11-21 13:02:00 -08001712 endstation: 14
Thomas Vachuska89543292014-11-19 11:28:33 -08001713 },
Simon Hunteb1514d2014-11-20 09:57:29 -08001714 hostGlyphId = {
Thomas Vachuska89543292014-11-19 11:28:33 -08001715 bgpSpeaker: 'bgpSpeaker',
1716 router: 'router',
Thomas Vachuska60d72bf2014-11-21 13:02:00 -08001717 endstation: 'endstation'
Thomas Vachuska89543292014-11-19 11:28:33 -08001718 };
1719
1720
Simon Hunt56d51852014-11-09 13:03:35 -08001721 // augment host nodes...
1722 entering.filter('.host').each(function (d) {
1723 var node = d3.select(this),
Thomas Vachuska89543292014-11-19 11:28:33 -08001724 r = hostRadius[d.type] || defaultHostRadius,
1725 textDy = r + 10,
Simon Hunteb1514d2014-11-20 09:57:29 -08001726 iid = iconGlyphUrl(d);
Simon Hunt56d51852014-11-09 13:03:35 -08001727
Simon Hunt7cd48f32014-11-09 23:42:50 -08001728 // provide ref to element from backing data....
1729 d.el = node;
1730
Thomas Vachuska89543292014-11-19 11:28:33 -08001731 node.append('circle')
1732 .attr('r', r);
Simon Hunt7fa116d2014-11-17 14:16:55 -08001733
Simon Hunteb1514d2014-11-20 09:57:29 -08001734 if (iid) {
1735 addHostIcon(node, r, iid);
Simon Hunt7fa116d2014-11-17 14:16:55 -08001736 }
Simon Hunt56d51852014-11-09 13:03:35 -08001737
Simon Hunt56d51852014-11-09 13:03:35 -08001738 node.append('text')
Simon Hunt7cd48f32014-11-09 23:42:50 -08001739 .text(hostLabel)
Thomas Vachuska89543292014-11-19 11:28:33 -08001740 .attr('dy', textDy)
Simon Hunt7cd48f32014-11-09 23:42:50 -08001741 .attr('text-anchor', 'middle');
Simon Hunt56d51852014-11-09 13:03:35 -08001742
1743 // debug function to show the modelled x,y coordinates of nodes...
1744 if (debug('showNodeXY')) {
1745 node.select('circle').attr('fill-opacity', 0.5);
1746 node.append('circle')
1747 .attr({
1748 class: 'debug',
1749 cx: 0,
1750 cy: 0,
1751 r: '3px'
1752 });
1753 }
1754 });
Simon Huntc7ee0662014-11-05 16:44:37 -08001755
Simon Hunt99c13842014-11-06 18:23:12 -08001756 // operate on both existing and new nodes, if necessary
1757 //node .foo() .bar() ...
Simon Huntc7ee0662014-11-05 16:44:37 -08001758
Simon Hunt99c13842014-11-06 18:23:12 -08001759 // operate on exiting nodes:
Simon Huntea80eb42014-11-11 13:46:57 -08001760 // Note that the node is removed after 2 seconds.
1761 // Sub element animations should be shorter than 2 seconds.
1762 var exiting = node.exit()
Simon Hunt44031102014-11-11 13:20:36 -08001763 .transition()
1764 .duration(2000)
Simon Huntea80eb42014-11-11 13:46:57 -08001765 .style('opacity', 0)
Simon Hunt99c13842014-11-06 18:23:12 -08001766 .remove();
Simon Huntea80eb42014-11-11 13:46:57 -08001767
1768 // host node exits....
1769 exiting.filter('.host').each(function (d) {
1770 var node = d3.select(this);
1771
1772 node.select('text')
1773 .style('opacity', 0.5)
1774 .transition()
1775 .duration(1000)
1776 .style('opacity', 0);
1777 // note, leave <g>.remove to remove this element
1778
Thomas Vachuska89543292014-11-19 11:28:33 -08001779 node.select('circle')
1780 .style('stroke-fill', '#555')
1781 .style('fill', '#888')
Simon Huntea80eb42014-11-11 13:46:57 -08001782 .style('opacity', 0.5)
1783 .transition()
1784 .duration(1500)
1785 .attr('r', 0);
1786 // note, leave <g>.remove to remove this element
1787
1788 });
1789
1790 // TODO: device node exits
Simon Huntc7ee0662014-11-05 16:44:37 -08001791 }
1792
Simon Huntc72967b2014-11-20 09:21:42 -08001793 function addDeviceIcon(node, box, noLabel, iid) {
1794 var cfg = config.icons.device,
1795 dx,
1796 dy,
1797 g;
1798
1799 if (noLabel) {
1800 box = emptyBox();
1801 dx = -cfg.dim/2;
1802 dy = -cfg.dim/2;
1803 } else {
1804 box = adjustRectToFitText(node);
1805 dx = box.x + config.icons.xoff;
1806 dy = box.y + config.icons.yoff;
1807 }
1808
Simon Hunteb1514d2014-11-20 09:57:29 -08001809 g = node.append('g')
1810 .attr('class', 'glyphIcon deviceIcon')
Simon Huntc72967b2014-11-20 09:21:42 -08001811 .attr('transform', translate(dx, dy));
1812
1813 g.append('rect').attr({
1814 x: 0,
1815 y: 0,
1816 rx: cfg.rx,
1817 width: cfg.dim,
1818 height: cfg.dim
1819 });
1820
1821 g.append('use').attr({
1822 'xlink:href': iid,
1823 width: cfg.dim,
1824 height: cfg.dim
1825 });
1826
Simon Huntc72967b2014-11-20 09:21:42 -08001827 }
1828
Simon Hunt7b403bc2014-11-22 19:01:00 -08001829 function find(key, array, tag) {
1830 var _tag = tag || 'key',
1831 idx, n, d;
1832 for (idx = 0, n = array.length; idx < n; idx++) {
1833 d = array[idx];
1834 if (d[_tag] === key) {
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001835 return idx;
1836 }
1837 }
1838 return -1;
1839 }
1840
1841 function removeLinkElement(linkData) {
Simon Hunt8257f4c2014-11-16 19:34:54 -08001842 var idx = find(linkData.key, network.links),
1843 removed;
1844 if (idx >=0) {
1845 // remove from links array
1846 removed = network.links.splice(idx, 1);
1847 // remove from lookup cache
1848 delete network.lookup[removed[0].key];
1849 updateLinks();
1850 network.force.resume();
1851 }
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001852 }
Simon Huntc7ee0662014-11-05 16:44:37 -08001853
Simon Hunt44031102014-11-11 13:20:36 -08001854 function removeHostElement(hostData) {
1855 // first, remove associated hostLink...
1856 removeLinkElement(hostData.linkData);
1857
1858 // remove from lookup cache
1859 delete network.lookup[hostData.id];
1860 // remove from nodes array
1861 var idx = find(hostData.id, network.nodes);
1862 network.nodes.splice(idx, 1);
1863 // remove from SVG
1864 updateNodes();
1865 network.force.resume();
1866 }
1867
1868
Simon Huntc7ee0662014-11-05 16:44:37 -08001869 function tick() {
1870 node.attr({
Simon Hunt99c13842014-11-06 18:23:12 -08001871 transform: function (d) { return translate(d.x, d.y); }
Simon Huntc7ee0662014-11-05 16:44:37 -08001872 });
1873
1874 link.attr({
1875 x1: function (d) { return d.source.x; },
1876 y1: function (d) { return d.source.y; },
1877 x2: function (d) { return d.target.x; },
1878 y2: function (d) { return d.target.y; }
1879 });
Simon Hunte2575b62014-11-18 15:25:53 -08001880
1881 linkLabel.each(function (d) {
1882 var el = d3.select(this);
Thomas Vachuska4731f122014-11-20 04:56:19 -08001883 var lnk = findLinkById(d.key);
1884
1885 if (lnk) {
1886 var parms = {
Simon Hunte2575b62014-11-18 15:25:53 -08001887 x1: lnk.source.x,
1888 y1: lnk.source.y,
1889 x2: lnk.target.x,
1890 y2: lnk.target.y
1891 };
Thomas Vachuska4731f122014-11-20 04:56:19 -08001892 el.attr('transform', transformLabel(parms));
1893 }
Simon Hunte2575b62014-11-18 15:25:53 -08001894 });
Simon Huntc7ee0662014-11-05 16:44:37 -08001895 }
Simon Hunt934c3ce2014-11-05 11:45:07 -08001896
1897 // ==============================
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001898 // Web-Socket for live data
1899
1900 function webSockUrl() {
1901 return document.location.toString()
1902 .replace(/\#.*/, '')
1903 .replace('http://', 'ws://')
1904 .replace('https://', 'wss://')
1905 .replace('index2.html', config.webSockUrl);
1906 }
1907
1908 webSock = {
1909 ws : null,
1910
1911 connect : function() {
1912 webSock.ws = new WebSocket(webSockUrl());
1913
1914 webSock.ws.onopen = function() {
Simon Hunt0c6d4192014-11-12 12:07:10 -08001915 noWebSock(false);
Thomas Vachuska47635c62014-11-22 01:21:36 -08001916 requestSummary();
1917 oiBox.show();
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001918 };
1919
1920 webSock.ws.onmessage = function(m) {
1921 if (m.data) {
Simon Huntbb282f52014-11-10 11:08:19 -08001922 wsTraceRx(m.data);
Thomas Vachuskad472c6e2014-11-07 19:11:05 -08001923 handleServerEvent(JSON.parse(m.data));
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001924 }
1925 };
1926
1927 webSock.ws.onclose = function(m) {
1928 webSock.ws = null;
Simon Hunt0c6d4192014-11-12 12:07:10 -08001929 noWebSock(true);
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001930 };
1931 },
1932
1933 send : function(text) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001934 if (text != null) {
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001935 webSock._send(text);
1936 }
1937 },
1938
1939 _send : function(message) {
1940 if (webSock.ws) {
1941 webSock.ws.send(message);
Simon Hunta255a2c2014-11-13 22:29:35 -08001942 } else if (config.useLiveData) {
Simon Hunt56d51852014-11-09 13:03:35 -08001943 network.view.alert('no web socket open\n\n' + message);
Simon Hunta255a2c2014-11-13 22:29:35 -08001944 } else {
1945 console.log('WS Send: ' + JSON.stringify(message));
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001946 }
1947 }
1948
1949 };
1950
Simon Hunt0c6d4192014-11-12 12:07:10 -08001951 function noWebSock(b) {
1952 mask.style('display',b ? 'block' : 'none');
1953 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001954
1955 function sendMessage(evType, payload) {
1956 var toSend = {
Simon Huntbb282f52014-11-10 11:08:19 -08001957 event: evType,
1958 sid: ++sid,
1959 payload: payload
1960 },
1961 asText = JSON.stringify(toSend);
1962 wsTraceTx(asText);
1963 webSock.send(asText);
Simon Huntc76ae892014-11-18 17:31:51 -08001964
1965 // Temporary measure for debugging UI behavior ...
1966 if (!config.useLiveData) {
1967 handleTestSend(toSend);
1968 }
Simon Huntbb282f52014-11-10 11:08:19 -08001969 }
1970
1971 function wsTraceTx(msg) {
1972 wsTrace('tx', msg);
1973 }
1974 function wsTraceRx(msg) {
1975 wsTrace('rx', msg);
1976 }
1977 function wsTrace(rxtx, msg) {
Simon Huntbb282f52014-11-10 11:08:19 -08001978 console.log('[' + rxtx + '] ' + msg);
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001979 }
1980
Simon Huntc76ae892014-11-18 17:31:51 -08001981 // NOTE: Temporary hardcoded example for showing detail pane
1982 // while we fine-
1983 // Probably should not merge this change...
1984 function handleTestSend(msg) {
1985 if (msg.event === 'requestDetails') {
1986 showDetails({
1987 event: 'showDetails',
1988 sid: 1001,
1989 payload: {
1990 "id": "of:0000ffffffffff09",
1991 "type": "roadm",
1992 "propOrder": [
1993 "Name",
1994 "Vendor",
1995 "H/W Version",
1996 "S/W Version",
1997 "-",
1998 "Latitude",
1999 "Longitude",
2000 "Ports"
2001 ],
2002 "props": {
2003 "Name": null,
2004 "Vendor": "Linc",
2005 "H/W Version": "OE",
2006 "S/W Version": "?",
2007 "-": "",
2008 "Latitude": "40.8",
2009 "Longitude": "73.1",
2010 "Ports": "2"
2011 }
2012 }
2013 });
2014 }
2015 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002016
2017 // ==============================
2018 // Selection stuff
2019
2020 function selectObject(obj, el) {
2021 var n,
Simon Hunt01095ff2014-11-13 16:37:29 -08002022 srcEv = d3.event.sourceEvent,
2023 meta = srcEv.metaKey,
2024 shift = srcEv.shiftKey;
2025
Simon Huntdeab4322014-11-13 18:49:07 -08002026 if ((panZoom() && !meta) || (!panZoom() && meta)) {
Simon Hunt01095ff2014-11-13 16:37:29 -08002027 return;
2028 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002029
2030 if (el) {
2031 n = d3.select(el);
2032 } else {
2033 node.each(function(d) {
2034 if (d == obj) {
2035 n = d3.select(el = this);
2036 }
2037 });
2038 }
2039 if (!n) return;
2040
Simon Hunt01095ff2014-11-13 16:37:29 -08002041 if (shift && n.classed('selected')) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002042 deselectObject(obj.id);
Simon Hunt61d04042014-11-11 17:27:16 -08002043 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002044 return;
2045 }
2046
Simon Hunt01095ff2014-11-13 16:37:29 -08002047 if (!shift) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002048 deselectAll();
2049 }
2050
Simon Huntc31d5692014-11-12 13:27:18 -08002051 selections[obj.id] = { obj: obj, el: el };
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002052 selectOrder.push(obj.id);
2053
2054 n.classed('selected', true);
Simon Hunt61d04042014-11-11 17:27:16 -08002055 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002056 }
2057
2058 function deselectObject(id) {
Simon Huntc31d5692014-11-12 13:27:18 -08002059 var obj = selections[id],
2060 idx;
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002061 if (obj) {
2062 d3.select(obj.el).classed('selected', false);
Simon Hunt61d04042014-11-11 17:27:16 -08002063 delete selections[id];
Simon Huntc31d5692014-11-12 13:27:18 -08002064 idx = $.inArray(id, selectOrder);
2065 if (idx >= 0) {
2066 selectOrder.splice(idx, 1);
2067 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002068 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002069 }
2070
2071 function deselectAll() {
2072 // deselect all nodes in the network...
2073 node.classed('selected', false);
2074 selections = {};
2075 selectOrder = [];
Simon Hunt61d04042014-11-11 17:27:16 -08002076 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002077 }
2078
Thomas Vachuska47635c62014-11-22 01:21:36 -08002079 // update the state of the sumary pane
2080 function updateSummaryPane() {
2081
2082 }
2083
Simon Hunt61d04042014-11-11 17:27:16 -08002084 // update the state of the detail pane, based on current selections
2085 function updateDetailPane() {
2086 var nSel = selectOrder.length;
2087 if (!nSel) {
Thomas Vachuska9edca302014-11-22 17:06:42 -08002088 emptySelect();
Simon Hunt61d04042014-11-11 17:27:16 -08002089 } else if (nSel === 1) {
2090 singleSelect();
Thomas Vachuska9edca302014-11-22 17:06:42 -08002091 requestTrafficForMode();
Simon Hunt61d04042014-11-11 17:27:16 -08002092 } else {
2093 multiSelect();
2094 }
2095 }
2096
Thomas Vachuska9edca302014-11-22 17:06:42 -08002097 function emptySelect() {
2098 detailPane.hide();
2099 cancelTraffic();
2100 }
2101
Simon Hunt61d04042014-11-11 17:27:16 -08002102 function singleSelect() {
Thomas Vachuska9edca302014-11-22 17:06:42 -08002103 // NOTE: detail is shown from showDetails event callback
Simon Hunt61d04042014-11-11 17:27:16 -08002104 requestDetails();
Thomas Vachuska9edca302014-11-22 17:06:42 -08002105 requestTrafficForMode();
Simon Hunt61d04042014-11-11 17:27:16 -08002106 }
2107
2108 function multiSelect() {
Simon Huntb53e0682014-11-12 13:32:01 -08002109 populateMultiSelect();
Thomas Vachuska9edca302014-11-22 17:06:42 -08002110 requestTrafficForMode();
Simon Huntb53e0682014-11-12 13:32:01 -08002111 }
2112
2113 function addSep(tbody) {
2114 var tr = tbody.append('tr');
2115 $('<hr>').appendTo(tr.append('td').attr('colspan', 2));
2116 }
2117
2118 function addProp(tbody, label, value) {
2119 var tr = tbody.append('tr');
2120
2121 tr.append('td')
2122 .attr('class', 'label')
2123 .text(label + ' :');
2124
2125 tr.append('td')
2126 .attr('class', 'value')
2127 .text(value);
2128 }
2129
2130 function populateMultiSelect() {
2131 detailPane.empty();
2132
Simon Hunta3dd9572014-11-20 15:22:41 -08002133 var title = detailPane.append('h3'),
2134 table = detailPane.append('table'),
2135 tbody = table.append('tbody');
Simon Huntb53e0682014-11-12 13:32:01 -08002136
Thomas Vachuska4731f122014-11-20 04:56:19 -08002137 title.text('Selected Nodes');
Simon Huntb53e0682014-11-12 13:32:01 -08002138
2139 selectOrder.forEach(function (d, i) {
2140 addProp(tbody, i+1, d);
2141 });
Simon Huntd72bc702014-11-13 18:38:04 -08002142
2143 addMultiSelectActions();
Simon Hunt61d04042014-11-11 17:27:16 -08002144 }
2145
Thomas Vachuska47635c62014-11-22 01:21:36 -08002146 // TODO: refactor to consolidate with populateDetails
2147 function populateSummary(data) {
2148 summaryPane.empty();
2149
2150 var svg = summaryPane.append('svg'),
2151 iid = iconGlyphUrl(data);
2152
2153 var title = summaryPane.append('h2'),
2154 table = summaryPane.append('table'),
2155 tbody = table.append('tbody');
2156
2157 appendGlyph(svg, 0, 0, 40, iid);
2158
2159 svg.append('use')
2160 .attr({
2161 class: 'birdBadge',
2162 transform: translate(8,12),
2163 'xlink:href': '#bird',
2164 width: 24,
2165 height: 24,
2166 fill: '#fff'
2167 });
2168
2169 title.text('ONOS Summary');
2170
2171 data.propOrder.forEach(function(p) {
2172 if (p === '-') {
2173 addSep(tbody);
2174 } else {
2175 addProp(tbody, p, data.props[p]);
2176 }
2177 });
2178 }
2179
Simon Hunt61d04042014-11-11 17:27:16 -08002180 function populateDetails(data) {
2181 detailPane.empty();
2182
Simon Hunta6a9fe72014-11-20 11:17:12 -08002183 var svg = detailPane.append('svg'),
2184 iid = iconGlyphUrl(data);
2185
Simon Hunta3dd9572014-11-20 15:22:41 -08002186 var title = detailPane.append('h2'),
2187 table = detailPane.append('table'),
2188 tbody = table.append('tbody');
Simon Hunt61d04042014-11-11 17:27:16 -08002189
Simon Hunta6a9fe72014-11-20 11:17:12 -08002190 appendGlyph(svg, 0, 0, 40, iid);
2191 title.text(data.id);
Simon Hunt61d04042014-11-11 17:27:16 -08002192
2193 data.propOrder.forEach(function(p) {
2194 if (p === '-') {
2195 addSep(tbody);
2196 } else {
2197 addProp(tbody, p, data.props[p]);
2198 }
2199 });
Simon Huntd72bc702014-11-13 18:38:04 -08002200
Thomas Vachuska4731f122014-11-20 04:56:19 -08002201 addSingleSelectActions(data);
Simon Hunt61d04042014-11-11 17:27:16 -08002202 }
2203
Thomas Vachuska4731f122014-11-20 04:56:19 -08002204 function addSingleSelectActions(data) {
Simon Huntd72bc702014-11-13 18:38:04 -08002205 detailPane.append('hr');
2206 // always want to allow 'show traffic'
Thomas Vachuska4731f122014-11-20 04:56:19 -08002207 addAction(detailPane, 'Show Related Traffic', showTrafficAction);
2208
2209 if (data.type === 'switch') {
2210 addAction(detailPane, 'Show Device Flows', showDeviceLinkFlowsAction);
2211 }
Simon Huntd72bc702014-11-13 18:38:04 -08002212 }
2213
2214 function addMultiSelectActions() {
2215 detailPane.append('hr');
2216 // always want to allow 'show traffic'
Thomas Vachuska4731f122014-11-20 04:56:19 -08002217 addAction(detailPane, 'Show Related Traffic', showTrafficAction);
Simon Huntd72bc702014-11-13 18:38:04 -08002218 // if exactly two hosts are selected, also want 'add host intent'
2219 if (nSel() === 2 && allSelectionsClass('host')) {
Thomas Vachuska9edca302014-11-22 17:06:42 -08002220 addAction(detailPane, 'Create Host-to-Host Flow', addHostIntentAction);
2221 } else if (nSel() >= 2 && allSelectionsClass('host')) {
2222 addAction(detailPane, 'Create Multi-Source Flow', addMultiSourceIntentAction);
Simon Huntd72bc702014-11-13 18:38:04 -08002223 }
2224 }
2225
Simon Hunta5e89142014-11-14 07:00:33 -08002226 function addAction(panel, text, cb) {
2227 panel.append('div')
Simon Huntd72bc702014-11-13 18:38:04 -08002228 .classed('actionBtn', true)
2229 .text(text)
2230 .on('click', cb);
2231 }
2232
2233
Paul Greysonfcba0e82014-11-13 10:21:16 -08002234 function zoomPan(scale, translate) {
2235 zoomPanContainer.attr("transform", "translate(" + translate + ")scale(" + scale + ")");
2236 // keep the map lines constant width while zooming
Thomas Vachuska89543292014-11-19 11:28:33 -08002237 bgImg.style("stroke-width", 2.0 / scale + "px");
Paul Greysonfcba0e82014-11-13 10:21:16 -08002238 }
2239
2240 function resetZoomPan() {
2241 zoomPan(1, [0,0]);
2242 zoom.scale(1).translate([0,0]);
2243 }
2244
2245 function setupZoomPan() {
2246 function zoomed() {
Simon Huntdeab4322014-11-13 18:49:07 -08002247 if (!panZoom() ^ !d3.event.sourceEvent.metaKey) {
Paul Greysonfcba0e82014-11-13 10:21:16 -08002248 zoomPan(d3.event.scale, d3.event.translate);
2249 }
2250 }
2251
2252 zoom = d3.behavior.zoom()
2253 .translate([0, 0])
2254 .scale(1)
2255 .scaleExtent([1, 8])
2256 .on("zoom", zoomed);
2257
2258 svg.call(zoom);
2259 }
2260
Simon Hunt61d04042014-11-11 17:27:16 -08002261 // ==============================
2262 // Test harness code
Simon Hunt56d51852014-11-09 13:03:35 -08002263
2264 function prepareScenario(view, ctx, dbg) {
2265 var sc = scenario,
2266 urlSc = sc.evDir + ctx + sc.evScenario;
2267
2268 if (!ctx) {
2269 view.alert("No scenario specified (null ctx)");
2270 return;
2271 }
2272
2273 sc.view = view;
2274 sc.ctx = ctx;
2275 sc.debug = dbg;
2276 sc.evNumber = 0;
2277
2278 d3.json(urlSc, function(err, data) {
Simon Huntbb282f52014-11-10 11:08:19 -08002279 var p = data && data.params || {},
2280 desc = data && data.description || null,
Simon Huntfc274c92014-11-11 11:05:46 -08002281 intro = data && data.title;
Simon Huntbb282f52014-11-10 11:08:19 -08002282
Simon Hunt56d51852014-11-09 13:03:35 -08002283 if (err) {
2284 view.alert('No scenario found:\n\n' + urlSc + '\n\n' + err);
2285 } else {
2286 sc.params = p;
Simon Huntbb282f52014-11-10 11:08:19 -08002287 if (desc) {
2288 intro += '\n\n ' + desc.join('\n ');
2289 }
2290 view.alert(intro);
Simon Hunt56d51852014-11-09 13:03:35 -08002291 }
2292 });
2293
2294 }
2295
Simon Hunt01095ff2014-11-13 16:37:29 -08002296 // ==============================
2297 // Toggle Buttons in masthead
Simon Hunt0c6d4192014-11-12 12:07:10 -08002298
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002299 // TODO: toggle button (and other widgets in the masthead) should be provided
2300 // by the framework; not generated by the view.
2301
Thomas Vachuska47635c62014-11-22 01:21:36 -08002302 //var showInstances;
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002303
2304 function addButtonBar(view) {
2305 var bb = d3.select('#mast')
2306 .append('span').classed('right', true).attr('id', 'bb');
2307
Simon Hunta5e89142014-11-14 07:00:33 -08002308 function mkTogBtn(text, cb) {
2309 return bb.append('span')
2310 .classed('btn', true)
2311 .text(text)
2312 .on('click', cb);
2313 }
Simon Hunt01095ff2014-11-13 16:37:29 -08002314
Thomas Vachuska47635c62014-11-22 01:21:36 -08002315 //showInstances = mkTogBtn('Show Instances', toggleInst);
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002316 }
2317
Thomas Vachuska47635c62014-11-22 01:21:36 -08002318 //function instShown() {
2319 // return showInstances.classed('active');
2320 //}
2321 //function toggleInst() {
2322 // showInstances.classed('active', !instShown());
2323 // if (instShown()) {
2324 // oiBox.show();
2325 // } else {
2326 // oiBox.hide();
2327 // }
2328 //}
Simon Hunt01095ff2014-11-13 16:37:29 -08002329
Simon Huntdeab4322014-11-13 18:49:07 -08002330 function panZoom() {
Simon Hunte5b71752014-11-18 20:06:07 -08002331 return false;
Simon Hunta5e89142014-11-14 07:00:33 -08002332 }
2333
Simon Hunt7fa116d2014-11-17 14:16:55 -08002334 function loadGlyphs(svg) {
2335 var defs = svg.append('defs');
2336 gly.defBird(defs);
Simon Huntc72967b2014-11-20 09:21:42 -08002337 gly.defGlyphs(defs);
Simon Huntb82f6902014-11-22 11:53:15 -08002338 gly.defBadges(defs);
Simon Hunt7fa116d2014-11-17 14:16:55 -08002339 }
Simon Hunt01095ff2014-11-13 16:37:29 -08002340
Thomas Vachuska7d638d32014-11-07 10:24:43 -08002341 // ==============================
Simon Hunt142d0032014-11-04 20:13:09 -08002342 // View life-cycle callbacks
Simon Hunt195cb382014-11-03 17:50:51 -08002343
Simon Huntf67722a2014-11-10 09:32:06 -08002344 function preload(view, ctx, flags) {
Simon Hunt142d0032014-11-04 20:13:09 -08002345 var w = view.width(),
2346 h = view.height(),
Simon Huntc7ee0662014-11-05 16:44:37 -08002347 fcfg = config.force,
2348 fpad = fcfg.pad,
2349 forceDim = [w - 2*fpad, h - 2*fpad];
Simon Hunt195cb382014-11-03 17:50:51 -08002350
Simon Hunt142d0032014-11-04 20:13:09 -08002351 // NOTE: view.$div is a D3 selection of the view's div
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002352 var viewBox = '0 0 ' + config.logicalSize + ' ' + config.logicalSize;
2353 svg = view.$div.append('svg').attr('viewBox', viewBox);
Simon Hunt934c3ce2014-11-05 11:45:07 -08002354 setSize(svg, view);
2355
Simon Hunt7fa116d2014-11-17 14:16:55 -08002356 loadGlyphs(svg);
Simon Hunt12ce12e2014-11-15 21:13:19 -08002357
Paul Greysonfcba0e82014-11-13 10:21:16 -08002358 zoomPanContainer = svg.append('g').attr('id', 'zoomPanContainer');
Paul Greysonfcba0e82014-11-13 10:21:16 -08002359 setupZoomPan();
2360
Simon Hunt1a9eff92014-11-07 11:06:34 -08002361 // add blue glow filter to svg layer
Paul Greysonfcba0e82014-11-13 10:21:16 -08002362 d3u.appendGlow(zoomPanContainer);
Simon Hunt1a9eff92014-11-07 11:06:34 -08002363
Simon Huntc7ee0662014-11-05 16:44:37 -08002364 // group for the topology
Paul Greysonfcba0e82014-11-13 10:21:16 -08002365 topoG = zoomPanContainer.append('g')
Simon Huntd3b7d512014-11-12 15:48:41 -08002366 .attr('id', 'topo-G')
Simon Huntc7ee0662014-11-05 16:44:37 -08002367 .attr('transform', fcfg.translate());
2368
Simon Hunte2575b62014-11-18 15:25:53 -08002369 // subgroups for links, link labels, and nodes
Simon Huntc7ee0662014-11-05 16:44:37 -08002370 linkG = topoG.append('g').attr('id', 'links');
Simon Hunte2575b62014-11-18 15:25:53 -08002371 linkLabelG = topoG.append('g').attr('id', 'linkLabels');
Simon Huntc7ee0662014-11-05 16:44:37 -08002372 nodeG = topoG.append('g').attr('id', 'nodes');
2373
Simon Hunte2575b62014-11-18 15:25:53 -08002374 // selection of links, linkLabels, and nodes
Simon Huntc7ee0662014-11-05 16:44:37 -08002375 link = linkG.selectAll('.link');
Simon Hunte2575b62014-11-18 15:25:53 -08002376 linkLabel = linkLabelG.selectAll('.linkLabel');
Simon Huntc7ee0662014-11-05 16:44:37 -08002377 node = nodeG.selectAll('.node');
2378
Simon Hunt7cd48f32014-11-09 23:42:50 -08002379 function chrg(d) {
2380 return fcfg.charge[d.class] || -12000;
2381 }
Simon Hunt99c13842014-11-06 18:23:12 -08002382 function ldist(d) {
Simon Hunt7cd48f32014-11-09 23:42:50 -08002383 return fcfg.linkDistance[d.type] || 50;
Simon Hunt99c13842014-11-06 18:23:12 -08002384 }
2385 function lstrg(d) {
Simon Hunt7cd48f32014-11-09 23:42:50 -08002386 // 0.0 - 1.0
2387 return fcfg.linkStrength[d.type] || 1.0;
Simon Hunt99c13842014-11-06 18:23:12 -08002388 }
2389
Simon Hunt1a9eff92014-11-07 11:06:34 -08002390 function selectCb(d, self) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002391 selectObject(d, self);
Simon Hunt1a9eff92014-11-07 11:06:34 -08002392 }
2393
2394 function atDragEnd(d, self) {
Simon Hunt56d51852014-11-09 13:03:35 -08002395 // once we've finished moving, pin the node in position
2396 d.fixed = true;
2397 d3.select(self).classed('fixed', true);
2398 if (config.useLiveData) {
Simon Hunt902c9922014-11-11 11:59:31 -08002399 sendUpdateMeta(d);
Simon Hunta255a2c2014-11-13 22:29:35 -08002400 } else {
2401 console.log('Moving node ' + d.id + ' to [' + d.x + ',' + d.y + ']');
Simon Hunt1a9eff92014-11-07 11:06:34 -08002402 }
2403 }
2404
Simon Hunt902c9922014-11-11 11:59:31 -08002405 function sendUpdateMeta(d) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002406 sendMessage('updateMeta', {
2407 id: d.id,
2408 'class': d.class,
Simon Hunt902c9922014-11-11 11:59:31 -08002409 'memento': {
Simon Hunt01095ff2014-11-13 16:37:29 -08002410 x: d.x,
2411 y: d.y
Simon Hunt902c9922014-11-11 11:59:31 -08002412 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002413 });
2414 }
2415
Simon Huntc7ee0662014-11-05 16:44:37 -08002416 // set up the force layout
2417 network.force = d3.layout.force()
2418 .size(forceDim)
2419 .nodes(network.nodes)
2420 .links(network.links)
Simon Hunt7cd48f32014-11-09 23:42:50 -08002421 .gravity(0.4)
2422 .friction(0.7)
2423 .charge(chrg)
Simon Hunt99c13842014-11-06 18:23:12 -08002424 .linkDistance(ldist)
2425 .linkStrength(lstrg)
Simon Huntc7ee0662014-11-05 16:44:37 -08002426 .on('tick', tick);
Simon Hunt195cb382014-11-03 17:50:51 -08002427
Simon Hunt01095ff2014-11-13 16:37:29 -08002428 network.drag = d3u.createDragBehavior(network.force,
Simon Huntdeab4322014-11-13 18:49:07 -08002429 selectCb, atDragEnd, panZoom);
Simon Hunt0c6d4192014-11-12 12:07:10 -08002430
2431 // create mask layer for when we lose connection to server.
Simon Hunta5e89142014-11-14 07:00:33 -08002432 // TODO: this should be part of the framework
Simon Hunt0c6d4192014-11-12 12:07:10 -08002433 mask = view.$div.append('div').attr('id','topo-mask');
2434 para(mask, 'Oops!');
2435 para(mask, 'Web-socket connection to server closed...');
2436 para(mask, 'Try refreshing the page.');
Simon Hunt12ce12e2014-11-15 21:13:19 -08002437
2438 mask.append('svg')
2439 .attr({
2440 id: 'mask-bird',
2441 width: w,
2442 height: h
2443 })
2444 .append('g')
2445 .attr('transform', birdTranslate(w, h))
2446 .style('opacity', 0.3)
2447 .append('use')
2448 .attr({
2449 'xlink:href': '#bird',
2450 width: config.birdDim,
2451 height: config.birdDim,
2452 fill: '#111'
Thomas Vachuska89543292014-11-19 11:28:33 -08002453 })
Simon Hunt1a9eff92014-11-07 11:06:34 -08002454 }
Simon Hunt195cb382014-11-03 17:50:51 -08002455
Simon Hunt01095ff2014-11-13 16:37:29 -08002456 function para(sel, text) {
2457 sel.append('p').text(text);
2458 }
2459
2460
Simon Hunt56d51852014-11-09 13:03:35 -08002461 function load(view, ctx, flags) {
Simon Huntf67722a2014-11-10 09:32:06 -08002462 // resize, in case the window was resized while we were not loaded
2463 resize(view, ctx, flags);
2464
Simon Hunt99c13842014-11-06 18:23:12 -08002465 // cache the view token, so network topo functions can access it
2466 network.view = view;
Simon Hunt56d51852014-11-09 13:03:35 -08002467 config.useLiveData = !flags.local;
2468
2469 if (!config.useLiveData) {
2470 prepareScenario(view, ctx, flags.debug);
2471 }
Simon Hunt99c13842014-11-06 18:23:12 -08002472
2473 // set our radio buttons and key bindings
Simon Hunt9462e8c2014-11-14 17:28:09 -08002474 layerBtnSet = view.setRadio(layerButtons);
Simon Hunt934c3ce2014-11-05 11:45:07 -08002475 view.setKeys(keyDispatch);
Simon Hunt195cb382014-11-03 17:50:51 -08002476
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002477 // patch in our "button bar" for now
2478 // TODO: implement a more official frameworky way of doing this..
2479 addButtonBar(view);
2480
Simon Huntd3b7d512014-11-12 15:48:41 -08002481 // Load map data asynchronously; complete startup after that..
2482 loadGeoJsonData();
Simon Hunta255a2c2014-11-13 22:29:35 -08002483 }
2484
Thomas Vachuskaa3148a72014-11-19 21:38:35 -08002485 function startAntTimer() {
Thomas Vachuska4731f122014-11-20 04:56:19 -08002486 if (!antTimer) {
2487 var pulses = [5, 3, 1.2, 3],
2488 pulse = 0;
2489 antTimer = setInterval(function () {
2490 pulse = pulse + 1;
2491 pulse = pulse === pulses.length ? 0 : pulse;
2492 d3.selectAll('.animated').style('stroke-width', pulses[pulse]);
2493 }, 200);
2494 }
Thomas Vachuskaa3148a72014-11-19 21:38:35 -08002495 }
2496
2497 function stopAntTimer() {
Simon Hunta255a2c2014-11-13 22:29:35 -08002498 if (antTimer) {
2499 clearInterval(antTimer);
2500 antTimer = null;
2501 }
Simon Huntd3b7d512014-11-12 15:48:41 -08002502 }
2503
Thomas Vachuskaa3148a72014-11-19 21:38:35 -08002504 function unload(view, ctx, flags) {
2505 stopAntTimer();
2506 }
2507
Simon Huntd3b7d512014-11-12 15:48:41 -08002508 // TODO: move these to config/state portion of script
Simon Hunta6a9fe72014-11-20 11:17:12 -08002509 var geoJsonUrl = 'json/map/continental_us.json',
Simon Huntd3b7d512014-11-12 15:48:41 -08002510 geoJson;
2511
2512 function loadGeoJsonData() {
2513 d3.json(geoJsonUrl, function (err, data) {
2514 if (err) {
2515 // fall back to USA map background
2516 loadStaticMap();
2517 } else {
2518 geoJson = data;
2519 loadGeoMap();
2520 }
2521
2522 // finally, connect to the server...
2523 if (config.useLiveData) {
2524 webSock.connect();
2525 }
2526 });
2527 }
2528
2529 function showBg() {
2530 return config.options.showBackground ? 'visible' : 'hidden';
2531 }
2532
2533 function loadStaticMap() {
2534 fnTrace('loadStaticMap', config.backgroundUrl);
2535 var w = network.view.width(),
2536 h = network.view.height();
2537
2538 // load the background image
2539 bgImg = svg.insert('svg:image', '#topo-G')
2540 .attr({
2541 id: 'topo-bg',
2542 width: w,
2543 height: h,
2544 'xlink:href': config.backgroundUrl
2545 })
2546 .style({
2547 visibility: showBg()
2548 });
2549 }
2550
2551 function loadGeoMap() {
2552 fnTrace('loadGeoMap', geoJsonUrl);
Simon Huntd3b7d512014-11-12 15:48:41 -08002553
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002554 // extracts the topojson data into geocoordinate-based geometry
2555 var topoData = topojson.feature(geoJson, geoJson.objects.states);
Simon Huntd3b7d512014-11-12 15:48:41 -08002556
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002557 // see: http://bl.ocks.org/mbostock/4707858
2558 geoMapProjection = d3.geo.mercator();
2559 var path = d3.geo.path().projection(geoMapProjection);
Simon Huntd3b7d512014-11-12 15:48:41 -08002560
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002561 geoMapProjection
2562 .scale(1)
2563 .translate([0, 0]);
Simon Huntd3b7d512014-11-12 15:48:41 -08002564
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002565 // [[x1,y1],[x2,y2]]
2566 var b = path.bounds(topoData);
Paul Greysonfcba0e82014-11-13 10:21:16 -08002567 // size map to 95% of minimum dimension to fill space
2568 var s = .95 / Math.min((b[1][0] - b[0][0]) / config.logicalSize, (b[1][1] - b[0][1]) / config.logicalSize);
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002569 var t = [(config.logicalSize - s * (b[1][0] + b[0][0])) / 2, (config.logicalSize - s * (b[1][1] + b[0][1])) / 2];
Simon Huntd3b7d512014-11-12 15:48:41 -08002570
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002571 geoMapProjection
2572 .scale(s)
2573 .translate(t);
2574
Paul Greysonfcba0e82014-11-13 10:21:16 -08002575 bgImg = zoomPanContainer.insert("g", '#topo-G');
Thomas Vachuska89543292014-11-19 11:28:33 -08002576 bgImg.attr('id', 'map').selectAll('path')
2577 .data(topoData.features)
2578 .enter()
2579 .append('path')
2580 .attr('d', path);
Simon Hunt195cb382014-11-03 17:50:51 -08002581 }
2582
Simon Huntf67722a2014-11-10 09:32:06 -08002583 function resize(view, ctx, flags) {
Simon Hunt12ce12e2014-11-15 21:13:19 -08002584 var w = view.width(),
2585 h = view.height();
2586
Simon Hunt934c3ce2014-11-05 11:45:07 -08002587 setSize(svg, view);
Simon Hunt12ce12e2014-11-15 21:13:19 -08002588
2589 d3.select('#mask-bird').attr({ width: w, height: h})
2590 .select('g').attr('transform', birdTranslate(w, h));
Simon Hunt142d0032014-11-04 20:13:09 -08002591 }
2592
Simon Hunt12ce12e2014-11-15 21:13:19 -08002593 function birdTranslate(w, h) {
2594 var bdim = config.birdDim;
2595 return 'translate('+((w-bdim)*.4)+','+((h-bdim)*.1)+')';
2596 }
Simon Hunt142d0032014-11-04 20:13:09 -08002597
2598 // ==============================
2599 // View registration
Simon Hunt195cb382014-11-03 17:50:51 -08002600
Simon Hunt25248912014-11-04 11:25:48 -08002601 onos.ui.addView('topo', {
Simon Hunt142d0032014-11-04 20:13:09 -08002602 preload: preload,
2603 load: load,
Simon Hunta255a2c2014-11-13 22:29:35 -08002604 unload: unload,
Simon Hunt142d0032014-11-04 20:13:09 -08002605 resize: resize
Simon Hunt195cb382014-11-03 17:50:51 -08002606 });
2607
Thomas Vachuska47635c62014-11-22 01:21:36 -08002608 summaryPane = onos.ui.addFloatingPanel('topo-summary');
Simon Hunt61d04042014-11-11 17:27:16 -08002609 detailPane = onos.ui.addFloatingPanel('topo-detail');
Simon Hunta5e89142014-11-14 07:00:33 -08002610 oiBox = onos.ui.addFloatingPanel('topo-oibox', 'TL');
Simon Huntb82f6902014-11-22 11:53:15 -08002611 oiBox.width(20);
Simon Hunt61d04042014-11-11 17:27:16 -08002612
Simon Hunt195cb382014-11-03 17:50:51 -08002613}(ONOS));