blob: 67311bd7a3d873bf0368bd78743f2b40d6034082 [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,
Simon Hunt62c47542014-11-22 22:16:32 -0800683 d = network.lookup[id];
684 if (d) {
685 $.extend(d, device);
686 if (positionNode(d, true)) {
687 sendUpdateMeta(d);
688 }
689 updateNodes();
Simon Huntbb282f52014-11-10 11:08:19 -0800690 } else {
691 logicError('updateDevice lookup fail. ID = "' + id + '"');
692 }
693 }
694
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800695 function updateLink(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800696 evTrace(data);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800697 var link = data.payload,
Simon Hunt8257f4c2014-11-16 19:34:54 -0800698 result = findLink(link, 'update'),
699 bad = result.badLogic;
700 if (bad) {
701 logicError(bad + ': ' + link.id);
702 return;
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800703 }
Simon Hunt8257f4c2014-11-16 19:34:54 -0800704 result.updateWith(link);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800705 }
706
Simon Hunt7cd48f32014-11-09 23:42:50 -0800707 function updateHost(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800708 evTrace(data);
Simon Hunt7cd48f32014-11-09 23:42:50 -0800709 var host = data.payload,
Simon Huntbb282f52014-11-10 11:08:19 -0800710 id = host.id,
711 hostData = network.lookup[id];
712 if (hostData) {
713 $.extend(hostData, host);
714 updateHostState(hostData);
715 } else {
716 logicError('updateHost lookup fail. ID = "' + id + '"');
717 }
Simon Hunt7cd48f32014-11-09 23:42:50 -0800718 }
719
Simon Hunt44031102014-11-11 13:20:36 -0800720 // TODO: fold removeX(...) methods into base method - remove dup code
Simon Hunt7b403bc2014-11-22 19:01:00 -0800721 function removeInstance(data) {
722 evTrace(data);
723 var inst = data.payload,
724 id = inst.id,
725 instData = onosInstances[id];
726 if (instData) {
727 var idx = find(id, onosOrder, 'id');
728 if (idx >= 0) {
729 onosOrder.splice(idx, 1);
730 }
731 delete onosInstances[id];
732 updateInstances();
733 } else {
734 logicError('updateInstance lookup fail. ID = "' + id + '"');
735 }
736 }
737
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800738 function removeLink(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800739 evTrace(data);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800740 var link = data.payload,
Simon Hunt8257f4c2014-11-16 19:34:54 -0800741 result = findLink(link, 'remove'),
742 bad = result.badLogic;
743 if (bad) {
744 logicError(bad + ': ' + link.id);
745 return;
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800746 }
Simon Hunt8257f4c2014-11-16 19:34:54 -0800747 result.removeRawLink();
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800748 }
749
Simon Hunt44031102014-11-11 13:20:36 -0800750 function removeHost(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800751 evTrace(data);
Simon Hunt44031102014-11-11 13:20:36 -0800752 var host = data.payload,
753 id = host.id,
754 hostData = network.lookup[id];
755 if (hostData) {
756 removeHostElement(hostData);
757 } else {
758 logicError('removeHost lookup fail. ID = "' + id + '"');
759 }
760 }
761
Thomas Vachuska47635c62014-11-22 01:21:36 -0800762 function showSummary(data) {
763 evTrace(data);
764 populateSummary(data.payload);
765 summaryPane.show();
766 }
767
Simon Hunt61d04042014-11-11 17:27:16 -0800768 function showDetails(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800769 evTrace(data);
Simon Hunt61d04042014-11-11 17:27:16 -0800770 populateDetails(data.payload);
771 detailPane.show();
772 }
773
Simon Huntb53e0682014-11-12 13:32:01 -0800774 function showTraffic(data) {
Simon Hunta5e89142014-11-14 07:00:33 -0800775 evTrace(data);
Thomas Vachuska4731f122014-11-20 04:56:19 -0800776 var paths = data.payload.paths,
777 hasTraffic = false;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800778
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800779 // Revert any links hilighted previously.
Thomas Vachuska4731f122014-11-20 04:56:19 -0800780 link.style('stroke-width', null)
Thomas Vachuskaa3148a72014-11-19 21:38:35 -0800781 .classed('primary secondary animated optical', false);
Simon Hunte2575b62014-11-18 15:25:53 -0800782 // Remove all previous labels.
783 removeLinkLabels();
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800784
Simon Hunte2575b62014-11-18 15:25:53 -0800785 // Now hilight all links in the paths payload, and attach
786 // labels to them, if they are defined.
Simon Hunta255a2c2014-11-13 22:29:35 -0800787 paths.forEach(function (p) {
Simon Hunte2575b62014-11-18 15:25:53 -0800788 var n = p.links.length,
789 i,
790 ldata;
791
Thomas Vachuska4731f122014-11-20 04:56:19 -0800792 hasTraffic = hasTraffic || p.traffic;
Simon Hunte2575b62014-11-18 15:25:53 -0800793 for (i=0; i<n; i++) {
794 ldata = findLinkById(p.links[i]);
Thomas Vachuska4731f122014-11-20 04:56:19 -0800795 if (ldata && ldata.el) {
Simon Hunte2575b62014-11-18 15:25:53 -0800796 ldata.el.classed(p.class, true);
797 ldata.label = p.labels[i];
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800798 }
Simon Hunte2575b62014-11-18 15:25:53 -0800799 }
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800800 });
Thomas Vachuska4731f122014-11-20 04:56:19 -0800801
Simon Hunte2575b62014-11-18 15:25:53 -0800802 updateLinks();
Thomas Vachuska4731f122014-11-20 04:56:19 -0800803
804 if (hasTraffic && !antTimer) {
805 startAntTimer();
806 } else if (!hasTraffic && antTimer) {
807 stopAntTimer();
808 }
Simon Huntb53e0682014-11-12 13:32:01 -0800809 }
810
Simon Hunt56d51852014-11-09 13:03:35 -0800811 // ...............................
812
813 function stillToImplement(data) {
814 var p = data.payload;
815 note(data.event, p.id);
Simon Hunt7b403bc2014-11-22 19:01:00 -0800816 if (!config.useLiveData) {
817 network.view.alert('Not yet implemented: "' + data.event + '"');
818 }
Simon Hunt56d51852014-11-09 13:03:35 -0800819 }
Simon Hunt99c13842014-11-06 18:23:12 -0800820
821 function unknownEvent(data) {
Simon Hunt50128c02014-11-08 13:36:15 -0800822 network.view.alert('Unknown event type: "' + data.event + '"');
Simon Hunt99c13842014-11-06 18:23:12 -0800823 }
824
825 function handleServerEvent(data) {
826 var fn = eventDispatch[data.event] || unknownEvent;
827 fn(data);
828 }
829
830 // ==============================
Simon Hunt61d04042014-11-11 17:27:16 -0800831 // Out-going messages...
832
Simon Huntb53e0682014-11-12 13:32:01 -0800833 function userFeedback(msg) {
834 // for now, use the alert pane as is. Maybe different alert style in
835 // the future (centered on view; dismiss button?)
836 network.view.alert(msg);
837 }
838
839 function nSel() {
840 return selectOrder.length;
841 }
Simon Hunt61d04042014-11-11 17:27:16 -0800842 function getSel(idx) {
843 return selections[selectOrder[idx]];
844 }
Simon Huntb53e0682014-11-12 13:32:01 -0800845 function getSelId(idx) {
846 return getSel(idx).obj.id;
847 }
Thomas Vachuska9edca302014-11-22 17:06:42 -0800848 function getSelIds(start, endOffset) {
849 var end = selectOrder.length - endOffset;
850 var ids = [];
851 selectOrder.slice(start, end).forEach(function (d) {
852 ids.push(getSelId(d));
853 });
854 return ids;
855 }
Simon Huntb53e0682014-11-12 13:32:01 -0800856 function allSelectionsClass(cls) {
857 for (var i=0, n=nSel(); i<n; i++) {
858 if (getSel(i).obj.class !== cls) {
859 return false;
860 }
861 }
862 return true;
863 }
Simon Hunt61d04042014-11-11 17:27:16 -0800864
Thomas Vachuska47635c62014-11-22 01:21:36 -0800865
866 function toggleInstances() {
867 if (!oiBox.isVisible()) {
868 oiBox.show();
869 } else {
870 oiBox.hide();
871 }
872 }
873
874 function toggleSummary() {
875 if (!summaryPane.isVisible()) {
876 requestSummary();
877 } else {
878 cancelSummary();
879 }
880 }
881
882 // request overall summary data
883 function requestSummary() {
884 sendMessage('requestSummary', {});
885 }
886
887 function cancelSummary() {
888 sendMessage('cancelSummary', {});
889 summaryPane.hide();
890 }
891
Simon Hunt61d04042014-11-11 17:27:16 -0800892 // request details for the selected element
Simon Huntd72bc702014-11-13 18:38:04 -0800893 // invoked from selection of a single node.
Simon Hunt61d04042014-11-11 17:27:16 -0800894 function requestDetails() {
895 var data = getSel(0).obj,
896 payload = {
897 id: data.id,
898 class: data.class
899 };
900 sendMessage('requestDetails', payload);
901 }
902
Thomas Vachuska9edca302014-11-22 17:06:42 -0800903 function addHostIntentAction() {
Simon Huntd72bc702014-11-13 18:38:04 -0800904 sendMessage('addHostIntent', {
Thomas Vachuska9edca302014-11-22 17:06:42 -0800905 one: selectOrder[0],
906 two: selectOrder[1],
907 ids: selectOrder
Simon Huntd72bc702014-11-13 18:38:04 -0800908 });
Thomas Vachuska9edca302014-11-22 17:06:42 -0800909 network.view.flash('Host-to-Host flow added');
Simon Huntd72bc702014-11-13 18:38:04 -0800910 }
911
Thomas Vachuska9edca302014-11-22 17:06:42 -0800912 function addMultiSourceIntentAction() {
913 sendMessage('addMultiSourceIntent', {
914 src: selectOrder.slice(0, selectOrder.length - 1),
915 dst: selectOrder[selectOrder.length - 1],
916 ids: selectOrder
917 });
918 network.view.flash('Multi-Source flow added');
Thomas Vachuska29617e52014-11-20 03:17:46 -0800919 }
920
Thomas Vachuska9edca302014-11-22 17:06:42 -0800921
Thomas Vachuska47635c62014-11-22 01:21:36 -0800922 function cancelTraffic() {
923 sendMessage('cancelTraffic', {});
924 }
925
Thomas Vachuska9edca302014-11-22 17:06:42 -0800926 function requestTrafficForMode() {
927 if (hoverMode === hoverModeAll) {
928 requestAllTraffic();
929 } else if (hoverMode === hoverModeFlows) {
930 requestDeviceLinkFlows();
931 } else if (hoverMode === hoverModeIntents) {
932 requestSelectTraffic();
Simon Huntd72bc702014-11-13 18:38:04 -0800933 }
Thomas Vachuska9edca302014-11-22 17:06:42 -0800934 }
Simon Huntd72bc702014-11-13 18:38:04 -0800935
Thomas Vachuska9edca302014-11-22 17:06:42 -0800936 function showTrafficAction() {
937 hoverMode = hoverModeIntents;
938 requestSelectTraffic();
939 network.view.flash('Related Traffic');
940 }
941
942 function requestSelectTraffic() {
943 if (validateSelectionContext()) {
944 var hoverId = (hoverMode === hoverModeIntents && hovered &&
945 (hovered.class === 'host' || hovered.class === 'device'))
Simon Huntd72bc702014-11-13 18:38:04 -0800946 ? hovered.id : '';
Thomas Vachuska9edca302014-11-22 17:06:42 -0800947 sendMessage('requestTraffic', {
948 ids: selectOrder,
949 hover: hoverId
950 });
951 }
Simon Huntd72bc702014-11-13 18:38:04 -0800952 }
953
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800954
Thomas Vachuska29617e52014-11-20 03:17:46 -0800955 function showDeviceLinkFlowsAction() {
Thomas Vachuska9edca302014-11-22 17:06:42 -0800956 hoverMode = hoverModeFlows;
957 requestDeviceLinkFlows();
Thomas Vachuskac59658c2014-11-21 13:13:36 -0800958 network.view.flash('Device Flows');
Thomas Vachuska29617e52014-11-20 03:17:46 -0800959 }
960
Thomas Vachuska9edca302014-11-22 17:06:42 -0800961 function requestDeviceLinkFlows() {
962 if (validateSelectionContext()) {
963 var hoverId = (hoverMode === hoverModeFlows && hovered &&
964 (hovered.class === 'device')) ? hovered.id : '';
965 sendMessage('requestDeviceLinkFlows', {
966 ids: selectOrder,
967 hover: hoverId
968 });
969 }
970 }
971
972
973 function showAllTrafficAction() {
974 hoverMode = hoverModeAll;
975 requestAllTraffic();
976 network.view.flash('All Traffic');
977 }
978
979 function requestAllTraffic() {
980 sendMessage('requestAllTraffic', {});
981 }
982
983 function validateSelectionContext() {
Thomas Vachuska29617e52014-11-20 03:17:46 -0800984 if (!hovered && nSel() === 0) {
Thomas Vachuska47635c62014-11-22 01:21:36 -0800985 cancelTraffic();
Thomas Vachuska9edca302014-11-22 17:06:42 -0800986 return false;
Thomas Vachuska29617e52014-11-20 03:17:46 -0800987 }
Thomas Vachuska9edca302014-11-22 17:06:42 -0800988 return true;
Thomas Vachuska29617e52014-11-20 03:17:46 -0800989 }
Simon Huntd72bc702014-11-13 18:38:04 -0800990
Simon Hunta6a9fe72014-11-20 11:17:12 -0800991
Simon Hunt61d04042014-11-11 17:27:16 -0800992 // ==============================
Simon Hunta5e89142014-11-14 07:00:33 -0800993 // onos instance panel functions
Simon Huntb82f6902014-11-22 11:53:15 -0800994
Simon Hunt7b403bc2014-11-22 19:01:00 -0800995 var instCfg = {
996 rectPad: 8,
997 nodeOx: 9,
998 nodeOy: 9,
999 nodeDim: 40,
1000 birdOx: 19,
1001 birdOy: 21,
1002 birdDim: 21,
1003 uiDy: 45,
1004 titleDy: 30,
1005 textYOff: 20,
1006 textYSpc: 15
1007 };
1008
1009 function viewBox(dim) {
1010 return '0 0 ' + dim.w + ' ' + dim.h;
1011 }
1012
1013 function instRectAttr(dim) {
1014 var pad = instCfg.rectPad;
1015 return {
1016 x: pad,
1017 y: pad,
1018 width: dim.w - pad*2,
1019 height: dim.h - pad*2,
1020 rx: 12
1021 };
1022 }
1023
1024 function computeDim(self) {
1025 var css = window.getComputedStyle(self);
1026 return {
1027 w: stripPx(css.width),
1028 h: stripPx(css.height)
1029 };
Simon Huntb82f6902014-11-22 11:53:15 -08001030 }
Simon Hunta5e89142014-11-14 07:00:33 -08001031
1032 function updateInstances() {
1033 var onoses = oiBox.el.selectAll('.onosInst')
Simon Huntb82f6902014-11-22 11:53:15 -08001034 .data(onosOrder, function (d) { return d.id; }),
Simon Hunt7b403bc2014-11-22 19:01:00 -08001035 instDim = {w:0,h:0},
1036 c = instCfg;
Simon Hunta5e89142014-11-14 07:00:33 -08001037
Simon Hunt7b403bc2014-11-22 19:01:00 -08001038 function nSw(n) {
1039 return '# Switches: ' + n;
1040 }
Simon Hunta5e89142014-11-14 07:00:33 -08001041
Simon Huntb82f6902014-11-22 11:53:15 -08001042 // operate on existing onos instances if necessary
1043 onoses.each(function (d) {
1044 var el = d3.select(this),
1045 svg = el.select('svg');
Simon Hunt7b403bc2014-11-22 19:01:00 -08001046 instDim = computeDim(this);
Simon Huntb82f6902014-11-22 11:53:15 -08001047
1048 // update online state
1049 el.classed('online', d.online);
1050
1051 // update ui-attached state
1052 svg.select('use.uiBadge').remove();
1053 if (d.uiAttached) {
1054 attachUiBadge(svg);
1055 }
1056
Simon Hunt7b403bc2014-11-22 19:01:00 -08001057 function updAttr(id, value) {
1058 svg.select('text.instLabel.'+id).text(value);
1059 }
1060
1061 updAttr('ip', d.ip);
1062 updAttr('ns', nSw(d.switches));
Simon Huntb82f6902014-11-22 11:53:15 -08001063 });
1064
1065
1066 // operate on new onos instances
Simon Hunta5e89142014-11-14 07:00:33 -08001067 var entering = onoses.enter()
1068 .append('div')
1069 .attr('class', 'onosInst')
1070 .classed('online', function (d) { return d.online; })
Simon Hunt9c15eca2014-11-15 18:37:59 -08001071 .on('click', clickInst);
1072
Simon Huntb82f6902014-11-22 11:53:15 -08001073 entering.each(function (d) {
Simon Hunt9c15eca2014-11-15 18:37:59 -08001074 var el = d3.select(this),
Simon Hunt7b403bc2014-11-22 19:01:00 -08001075 rectAttr,
1076 svg;
1077 instDim = computeDim(this);
1078 rectAttr = instRectAttr(instDim);
Simon Hunt9c15eca2014-11-15 18:37:59 -08001079
Simon Hunt7b403bc2014-11-22 19:01:00 -08001080 svg = el.append('svg').attr({
1081 width: instDim.w,
1082 height: instDim.h,
1083 viewBox: viewBox(instDim)
Simon Hunt95908012014-11-20 10:20:26 -08001084 });
Simon Huntb82f6902014-11-22 11:53:15 -08001085
Simon Hunt7b403bc2014-11-22 19:01:00 -08001086 svg.append('rect').attr(rectAttr);
Simon Hunt9c15eca2014-11-15 18:37:59 -08001087
Simon Hunt7b403bc2014-11-22 19:01:00 -08001088 appendGlyph(svg, c.nodeOx, c.nodeOy, c.nodeDim, '#node');
1089 appendBadge(svg, c.birdOx, c.birdOy, c.birdDim, '#bird');
Simon Huntb82f6902014-11-22 11:53:15 -08001090
1091 if (d.uiAttached) {
1092 attachUiBadge(svg);
1093 }
1094
Simon Hunt7b403bc2014-11-22 19:01:00 -08001095 var left = c.nodeOx + c.nodeDim,
1096 len = rectAttr.width - left,
1097 hlen = len / 2,
1098 midline = hlen + left;
Simon Hunt9c15eca2014-11-15 18:37:59 -08001099
Simon Hunt7b403bc2014-11-22 19:01:00 -08001100 // title
1101 svg.append('text')
1102 .attr({
1103 class: 'instTitle',
1104 x: midline,
1105 y: c.titleDy
1106 })
1107 .text(d.id);
1108
1109 // a couple of attributes
1110 var ty = c.titleDy + c.textYOff;
1111
1112 function addAttr(id, label) {
1113 svg.append('text').attr({
1114 class: 'instLabel ' + id,
1115 x: midline,
1116 y: ty
1117 }).text(label);
1118 ty += c.textYSpc;
1119 }
1120
1121 addAttr('ip', d.ip);
1122 addAttr('ns', nSw(d.switches));
Simon Hunt9c15eca2014-11-15 18:37:59 -08001123 });
Simon Hunta5e89142014-11-14 07:00:33 -08001124
1125 // operate on existing + new onoses here
1126
Simon Hunt7b403bc2014-11-22 19:01:00 -08001127 // adjust the panel size appropriately...
1128 oiBox.width(instDim.w * onosOrder.length);
1129 oiBox.height(instDim.h);
1130
1131 // remove any outgoing instances
1132 onoses.exit().remove();
Simon Hunta5e89142014-11-14 07:00:33 -08001133 }
1134
Simon Hunt9462e8c2014-11-14 17:28:09 -08001135 function clickInst(d) {
1136 var el = d3.select(this),
1137 aff = el.classed('affinity');
1138 if (!aff) {
1139 setAffinity(el, d);
1140 } else {
1141 cancelAffinity();
1142 }
1143 }
1144
1145 function setAffinity(el, d) {
1146 d3.selectAll('.onosInst')
1147 .classed('mastership', true)
1148 .classed('affinity', false);
1149 el.classed('affinity', true);
1150
1151 suppressLayers(true);
1152 node.each(function (n) {
1153 if (n.master === d.id) {
1154 n.el.classed('suppressed', false);
1155 }
1156 });
1157 oiShowMaster = true;
1158 }
1159
1160 function cancelAffinity() {
1161 d3.selectAll('.onosInst')
1162 .classed('mastership affinity', false);
1163 restoreLayerState();
1164 oiShowMaster = false;
1165 }
1166
Simon Hunt7b403bc2014-11-22 19:01:00 -08001167 // TODO: these should be moved out to utility module.
1168 function stripPx(s) {
1169 return s.replace(/px$/,'');
1170 }
1171
1172 function appendUse(svg, ox, oy, dim, iid, cls) {
1173 var use = svg.append('use').attr({
1174 transform: translate(ox,oy),
1175 'xlink:href': iid,
1176 width: dim,
1177 height: dim
1178 });
1179 if (cls) {
1180 use.classed(cls, true);
1181 }
1182 return use;
1183 }
1184
1185 function appendGlyph(svg, ox, oy, dim, iid, cls) {
1186 appendUse(svg, ox, oy, dim, iid, cls).classed('glyphIcon', true);
1187 }
1188
1189 function appendBadge(svg, ox, oy, dim, iid, cls) {
1190 appendUse(svg, ox, oy, dim, iid,cls ).classed('badgeIcon', true);
1191 }
1192
1193 function attachUiBadge(svg) {
1194 appendBadge(svg, 12, instCfg.uiDy, 30, '#uiAttached', 'uiBadge');
1195 }
1196
Simon Hunta5e89142014-11-14 07:00:33 -08001197 // ==============================
Simon Hunt99c13842014-11-06 18:23:12 -08001198 // force layout modification functions
1199
1200 function translate(x, y) {
1201 return 'translate(' + x + ',' + y + ')';
1202 }
1203
Simon Hunte2575b62014-11-18 15:25:53 -08001204 function rotate(deg) {
1205 return 'rotate(' + deg + ')';
1206 }
1207
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001208 function missMsg(what, id) {
1209 return '\n[' + what + '] "' + id + '" missing ';
1210 }
1211
1212 function linkEndPoints(srcId, dstId) {
1213 var srcNode = network.lookup[srcId],
1214 dstNode = network.lookup[dstId],
1215 sMiss = !srcNode ? missMsg('src', srcId) : '',
1216 dMiss = !dstNode ? missMsg('dst', dstId) : '';
1217
1218 if (sMiss || dMiss) {
1219 logicError('Node(s) not on map for link:\n' + sMiss + dMiss);
1220 return null;
1221 }
1222 return {
1223 source: srcNode,
1224 target: dstNode,
1225 x1: srcNode.x,
1226 y1: srcNode.y,
1227 x2: dstNode.x,
1228 y2: dstNode.y
1229 };
1230 }
1231
Simon Hunt56d51852014-11-09 13:03:35 -08001232 function createHostLink(host) {
1233 var src = host.id,
1234 dst = host.cp.device,
Simon Hunt7cd48f32014-11-09 23:42:50 -08001235 id = host.ingress,
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001236 lnk = linkEndPoints(src, dst);
Simon Hunt56d51852014-11-09 13:03:35 -08001237
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001238 if (!lnk) {
Simon Hunt56d51852014-11-09 13:03:35 -08001239 return null;
1240 }
1241
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001242 // Synthesize link ...
1243 $.extend(lnk, {
Simon Hunt8257f4c2014-11-16 19:34:54 -08001244 key: id,
Simon Hunt56d51852014-11-09 13:03:35 -08001245 class: 'link',
Simon Hunt8257f4c2014-11-16 19:34:54 -08001246
1247 type: function () { return 'hostLink'; },
1248 // TODO: ideally, we should see if our edge switch is online...
1249 online: function () { return true; },
1250 linkWidth: function () { return 1; }
Simon Hunt7cd48f32014-11-09 23:42:50 -08001251 });
Simon Hunt99c13842014-11-06 18:23:12 -08001252 return lnk;
1253 }
1254
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001255 function createLink(link) {
Simon Hunta6a9fe72014-11-20 11:17:12 -08001256 var lnk = linkEndPoints(link.src, link.dst);
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001257
1258 if (!lnk) {
1259 return null;
1260 }
1261
Simon Hunt8257f4c2014-11-16 19:34:54 -08001262 $.extend(lnk, {
1263 key: link.id,
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001264 class: 'link',
Simon Hunt8257f4c2014-11-16 19:34:54 -08001265 fromSource: link,
1266
1267 // functions to aggregate dual link state
1268 type: function () {
1269 var s = lnk.fromSource,
1270 t = lnk.fromTarget;
1271 return (s && s.type) || (t && t.type) || defaultLinkType;
1272 },
1273 online: function () {
1274 var s = lnk.fromSource,
1275 t = lnk.fromTarget;
1276 return (s && s.online) || (t && t.online);
1277 },
1278 linkWidth: function () {
1279 var s = lnk.fromSource,
1280 t = lnk.fromTarget,
1281 ws = (s && s.linkWidth) || 0,
1282 wt = (t && t.linkWidth) || 0;
1283 return Math.max(ws, wt);
1284 }
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001285 });
1286 return lnk;
Simon Hunt1a9eff92014-11-07 11:06:34 -08001287 }
1288
Simon Hunte2575b62014-11-18 15:25:53 -08001289 function removeLinkLabels() {
1290 network.links.forEach(function (d) {
1291 d.label = '';
1292 });
1293 }
1294
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001295 var widthRatio = 1.4,
1296 linkScale = d3.scale.linear()
1297 .domain([1, 12])
1298 .range([widthRatio, 12 * widthRatio])
1299 .clamp(true);
1300
Simon Hunt99c13842014-11-06 18:23:12 -08001301 function updateLinks() {
1302 link = linkG.selectAll('.link')
Simon Hunt8257f4c2014-11-16 19:34:54 -08001303 .data(network.links, function (d) { return d.key; });
Simon Hunt99c13842014-11-06 18:23:12 -08001304
1305 // operate on existing links, if necessary
1306 // link .foo() .bar() ...
1307
1308 // operate on entering links:
1309 var entering = link.enter()
1310 .append('line')
1311 .attr({
Simon Hunt99c13842014-11-06 18:23:12 -08001312 x1: function (d) { return d.x1; },
1313 y1: function (d) { return d.y1; },
1314 x2: function (d) { return d.x2; },
1315 y2: function (d) { return d.y2; },
Simon Hunt1a9eff92014-11-07 11:06:34 -08001316 stroke: config.topo.linkInColor,
1317 'stroke-width': config.topo.linkInWidth
Simon Hunt99c13842014-11-06 18:23:12 -08001318 });
1319
1320 // augment links
Simon Hunt7cd48f32014-11-09 23:42:50 -08001321 entering.each(function (d) {
1322 var link = d3.select(this);
1323 // provide ref to element selection from backing data....
1324 d.el = link;
Simon Hunt8257f4c2014-11-16 19:34:54 -08001325 restyleLinkElement(d);
Simon Hunt7cd48f32014-11-09 23:42:50 -08001326 });
Thomas Vachuska4830d392014-11-09 17:09:56 -08001327
1328 // operate on both existing and new links, if necessary
1329 //link .foo() .bar() ...
1330
Simon Hunte2575b62014-11-18 15:25:53 -08001331 // apply or remove labels
1332 var labelData = getLabelData();
1333 applyLinkLabels(labelData);
1334
Thomas Vachuska4830d392014-11-09 17:09:56 -08001335 // operate on exiting links:
Thomas Vachuska4830d392014-11-09 17:09:56 -08001336 link.exit()
Simon Hunt13bf9c82014-11-18 07:26:44 -08001337 .attr('stroke-dasharray', '3, 3')
1338 .style('opacity', 0.5)
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001339 .transition()
Simon Huntea80eb42014-11-11 13:46:57 -08001340 .duration(1500)
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001341 .attr({
Simon Hunt13bf9c82014-11-18 07:26:44 -08001342 'stroke-dasharray': '3, 12',
1343 stroke: config.topo.linkOutColor,
1344 'stroke-width': config.topo.linkOutWidth
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001345 })
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001346 .style('opacity', 0.0)
Thomas Vachuska4830d392014-11-09 17:09:56 -08001347 .remove();
Simon Hunte2575b62014-11-18 15:25:53 -08001348
1349 // NOTE: invoke a single tick to force the labels to position
1350 // onto their links.
1351 tick();
1352 }
1353
1354 function getLabelData() {
1355 // create the backing data for showing labels..
1356 var data = [];
1357 link.each(function (d) {
1358 if (d.label) {
1359 data.push({
1360 id: 'lab-' + d.key,
1361 key: d.key,
1362 label: d.label,
1363 ldata: d
1364 });
1365 }
1366 });
1367 return data;
1368 }
1369
1370 var linkLabelOffset = '0.3em';
1371
1372 function applyLinkLabels(data) {
1373 var entering;
1374
1375 linkLabel = linkLabelG.selectAll('.linkLabel')
1376 .data(data, function (d) { return d.id; });
1377
Simon Hunt56a2ea42014-11-19 12:39:31 -08001378 // for elements already existing, we need to update the text
1379 // and adjust the rectangle size to fit
1380 linkLabel.each(function (d) {
1381 var el = d3.select(this),
1382 rect = el.select('rect'),
1383 text = el.select('text');
1384 text.text(d.label);
1385 rect.attr(rectAroundText(el));
1386 });
Thomas Vachuskaf75b7ab2014-11-19 12:15:55 -08001387
Simon Hunte2575b62014-11-18 15:25:53 -08001388 entering = linkLabel.enter().append('g')
1389 .classed('linkLabel', true)
1390 .attr('id', function (d) { return d.id; });
1391
1392 entering.each(function (d) {
1393 var el = d3.select(this),
1394 rect,
1395 text,
1396 parms = {
1397 x1: d.ldata.x1,
1398 y1: d.ldata.y1,
1399 x2: d.ldata.x2,
1400 y2: d.ldata.y2
1401 };
1402
1403 d.el = el;
1404 rect = el.append('rect');
1405 text = el.append('text').text(d.label);
1406 rect.attr(rectAroundText(el));
1407 text.attr('dy', linkLabelOffset);
1408
1409 el.attr('transform', transformLabel(parms));
1410 });
1411
1412 // Remove any links that are no longer required.
1413 linkLabel.exit().remove();
1414 }
1415
1416 function rectAroundText(el) {
1417 var text = el.select('text'),
1418 box = text.node().getBBox();
1419
1420 // translate the bbox so that it is centered on [x,y]
1421 box.x = -box.width / 2;
1422 box.y = -box.height / 2;
1423
1424 // add padding
1425 box.x -= 1;
1426 box.width += 2;
1427 return box;
1428 }
1429
1430 function transformLabel(p) {
1431 var dx = p.x2 - p.x1,
1432 dy = p.y2 - p.y1,
1433 xMid = dx/2 + p.x1,
1434 yMid = dy/2 + p.y1;
Simon Hunte2575b62014-11-18 15:25:53 -08001435 return translate(xMid, yMid);
Simon Hunt99c13842014-11-06 18:23:12 -08001436 }
1437
1438 function createDeviceNode(device) {
1439 // start with the object as is
1440 var node = device,
Simon Huntbb282f52014-11-10 11:08:19 -08001441 type = device.type,
Simon Huntc72967b2014-11-20 09:21:42 -08001442 svgCls = type ? 'node device ' + type : 'node device',
1443 labels = device.labels || [];
1444
Simon Hunt99c13842014-11-06 18:23:12 -08001445 // Augment as needed...
1446 node.class = 'device';
Simon Huntbb282f52014-11-10 11:08:19 -08001447 node.svgClass = device.online ? svgCls + ' online' : svgCls;
Simon Hunt99c13842014-11-06 18:23:12 -08001448 positionNode(node);
Simon Hunt99c13842014-11-06 18:23:12 -08001449 return node;
1450 }
1451
Simon Hunt56d51852014-11-09 13:03:35 -08001452 function createHostNode(host) {
1453 // start with the object as is
1454 var node = host;
1455
1456 // Augment as needed...
1457 node.class = 'host';
Simon Hunt7cd48f32014-11-09 23:42:50 -08001458 if (!node.type) {
Simon Hunt209155e2014-11-21 12:16:09 -08001459 node.type = 'endstation';
Simon Hunt7cd48f32014-11-09 23:42:50 -08001460 }
Simon Hunt7fa116d2014-11-17 14:16:55 -08001461 node.svgClass = 'node host ' + node.type;
Simon Hunt56d51852014-11-09 13:03:35 -08001462 positionNode(node);
Simon Hunt56d51852014-11-09 13:03:35 -08001463 return node;
1464 }
1465
Simon Hunt62c47542014-11-22 22:16:32 -08001466 function positionNode(node, forUpdate) {
Simon Hunt99c13842014-11-06 18:23:12 -08001467 var meta = node.metaUi,
Simon Huntac9e24f2014-11-12 10:12:21 -08001468 x = meta && meta.x,
1469 y = meta && meta.y,
1470 xy;
Simon Hunt99c13842014-11-06 18:23:12 -08001471
Simon Huntac9e24f2014-11-12 10:12:21 -08001472 // If we have [x,y] already, use that...
Simon Hunt99c13842014-11-06 18:23:12 -08001473 if (x && y) {
1474 node.fixed = true;
Simon Hunt62c47542014-11-22 22:16:32 -08001475 node.px = node.x = x;
1476 node.py = node.y = y;
1477 //node.px = x;
1478 //node.py = y;
Simon Huntac9e24f2014-11-12 10:12:21 -08001479 return;
Simon Hunt99c13842014-11-06 18:23:12 -08001480 }
Simon Huntac9e24f2014-11-12 10:12:21 -08001481
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001482 var location = node.location;
1483 if (location && location.type === 'latlng') {
1484 var coord = geoMapProjection([location.lng, location.lat]);
1485 node.fixed = true;
Simon Hunt62c47542014-11-22 22:16:32 -08001486 node.px = node.x = coord[0];
1487 node.py = node.y = coord[1];
1488 //node.x = coord[0];
1489 //node.y = coord[1];
1490 return true;
1491 }
1492
1493 // if this is a node update (not a node add).. skip randomizer
1494 if (forUpdate) {
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001495 return;
1496 }
1497
Simon Huntac9e24f2014-11-12 10:12:21 -08001498 // Note: Placing incoming unpinned nodes at exactly the same point
1499 // (center of the view) causes them to explode outwards when
1500 // the force layout kicks in. So, we spread them out a bit
1501 // initially, to provide a more serene layout convergence.
1502 // Additionally, if the node is a host, we place it near
1503 // the device it is connected to.
1504
1505 function spread(s) {
1506 return Math.floor((Math.random() * s) - s/2);
1507 }
1508
1509 function randDim(dim) {
1510 return dim / 2 + spread(dim * 0.7071);
1511 }
1512
1513 function rand() {
1514 return {
1515 x: randDim(network.view.width()),
1516 y: randDim(network.view.height())
1517 };
1518 }
1519
1520 function near(node) {
1521 var min = 12,
1522 dx = spread(12),
1523 dy = spread(12);
1524 return {
1525 x: node.x + min + dx,
1526 y: node.y + min + dy
1527 };
1528 }
1529
1530 function getDevice(cp) {
1531 var d = network.lookup[cp.device];
1532 return d || rand();
1533 }
1534
1535 xy = (node.class === 'host') ? near(getDevice(node.cp)) : rand();
1536 $.extend(node, xy);
Simon Hunt99c13842014-11-06 18:23:12 -08001537 }
1538
Simon Hunt99c13842014-11-06 18:23:12 -08001539
Simon Huntc72967b2014-11-20 09:21:42 -08001540 function iconGlyphUrl(d) {
1541 var which = d.type || 'unknown';
1542 return '#' + which;
1543 }
1544
Simon Hunt99c13842014-11-06 18:23:12 -08001545 // returns the newly computed bounding box of the rectangle
1546 function adjustRectToFitText(n) {
1547 var text = n.select('text'),
1548 box = text.node().getBBox(),
1549 lab = config.labels;
1550
1551 text.attr('text-anchor', 'middle')
1552 .attr('y', '-0.8em')
1553 .attr('x', lab.imgPad/2);
1554
1555 // translate the bbox so that it is centered on [x,y]
1556 box.x = -box.width / 2;
1557 box.y = -box.height / 2;
1558
1559 // add padding
1560 box.x -= (lab.padLR + lab.imgPad/2);
1561 box.width += lab.padLR * 2 + lab.imgPad;
1562 box.y -= lab.padTB;
1563 box.height += lab.padTB * 2;
1564
1565 return box;
1566 }
1567
Simon Hunt1a9eff92014-11-07 11:06:34 -08001568 function mkSvgClass(d) {
1569 return d.fixed ? d.svgClass + ' fixed' : d.svgClass;
1570 }
1571
Simon Hunt7cd48f32014-11-09 23:42:50 -08001572 function hostLabel(d) {
1573 var idx = (hostLabelIndex < d.labels.length) ? hostLabelIndex : 0;
1574 return d.labels[idx];
1575 }
1576 function deviceLabel(d) {
1577 var idx = (deviceLabelIndex < d.labels.length) ? deviceLabelIndex : 0;
1578 return d.labels[idx];
1579 }
Simon Huntc72967b2014-11-20 09:21:42 -08001580 function trimLabel(label) {
1581 return (label && label.trim()) || '';
1582 }
1583
1584 function emptyBox() {
1585 return {
1586 x: -2,
1587 y: -2,
1588 width: 4,
1589 height: 4
1590 };
Simon Hunt7cd48f32014-11-09 23:42:50 -08001591 }
1592
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001593 function updateDeviceLabel(d) {
Simon Huntc72967b2014-11-20 09:21:42 -08001594 var label = trimLabel(deviceLabel(d)),
1595 noLabel = !label,
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001596 node = d.el,
Simon Huntc72967b2014-11-20 09:21:42 -08001597 box,
1598 dx,
1599 dy;
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001600
1601 node.select('text')
1602 .text(label)
1603 .style('opacity', 0)
1604 .transition()
1605 .style('opacity', 1);
1606
Simon Huntc72967b2014-11-20 09:21:42 -08001607 if (noLabel) {
1608 box = emptyBox();
1609 dx = -config.icons.device.dim/2;
1610 dy = -config.icons.device.dim/2;
1611 } else {
1612 box = adjustRectToFitText(node);
1613 dx = box.x + config.icons.xoff;
1614 dy = box.y + config.icons.yoff;
1615 }
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001616
1617 node.select('rect')
1618 .transition()
1619 .attr(box);
1620
Simon Huntc72967b2014-11-20 09:21:42 -08001621 node.select('g.deviceIcon')
Thomas Vachuska89543292014-11-19 11:28:33 -08001622 .transition()
Simon Huntc72967b2014-11-20 09:21:42 -08001623 .attr('transform', translate(dx, dy));
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001624 }
1625
1626 function updateHostLabel(d) {
1627 var label = hostLabel(d),
1628 host = d.el;
1629
1630 host.select('text').text(label);
1631 }
1632
Simon Hunt62c47542014-11-22 22:16:32 -08001633 // FIXME : fold this into updateNodes.
Simon Huntbb282f52014-11-10 11:08:19 -08001634 function updateHostState(hostData) {
1635 updateHostLabel(hostData);
Simon Huntbb282f52014-11-10 11:08:19 -08001636 }
1637
Simon Hunt6ac93f32014-11-13 12:17:27 -08001638 function nodeMouseOver(d) {
Simon Hunt6ac93f32014-11-13 12:17:27 -08001639 hovered = d;
Thomas Vachuska9edca302014-11-22 17:06:42 -08001640 requestTrafficForMode();
Simon Hunt6ac93f32014-11-13 12:17:27 -08001641 }
1642
1643 function nodeMouseOut(d) {
Simon Hunt6ac93f32014-11-13 12:17:27 -08001644 hovered = null;
Thomas Vachuska9edca302014-11-22 17:06:42 -08001645 requestTrafficForMode();
Simon Hunt6ac93f32014-11-13 12:17:27 -08001646 }
Simon Huntbb282f52014-11-10 11:08:19 -08001647
Simon Hunteb1514d2014-11-20 09:57:29 -08001648 function addHostIcon(node, radius, iid) {
Thomas Vachuska89543292014-11-19 11:28:33 -08001649 var dim = radius * 1.5,
1650 xlate = -dim / 2;
1651
Simon Hunteb1514d2014-11-20 09:57:29 -08001652 node.append('use').attr({
1653 class: 'glyphIcon hostIcon',
1654 transform: translate(xlate,xlate),
1655 'xlink:href': iid,
1656 width: dim,
1657 height: dim
1658 });
Thomas Vachuska89543292014-11-19 11:28:33 -08001659 }
1660
Simon Hunt99c13842014-11-06 18:23:12 -08001661 function updateNodes() {
1662 node = nodeG.selectAll('.node')
1663 .data(network.nodes, function (d) { return d.id; });
1664
Simon Hunt62c47542014-11-22 22:16:32 -08001665 // operate on existing nodes...
1666 node.filter('.device').each(function (d) {
1667 //var node = d3.select(this);
1668 var node = d.el;
1669 node.classed('online', d.online);
1670 updateDeviceLabel(d);
1671 positionNode(d, true);
1672 });
1673
1674 node.filter('.host').each(function (d) {
1675 //var node = d3.select(this);
1676 var node = d.el;
1677 // TODO: appropriate update of host visuals
1678 });
Simon Hunt99c13842014-11-06 18:23:12 -08001679
1680 // operate on entering nodes:
1681 var entering = node.enter()
1682 .append('g')
1683 .attr({
1684 id: function (d) { return safeId(d.id); },
Simon Hunt1a9eff92014-11-07 11:06:34 -08001685 class: mkSvgClass,
Simon Hunt99c13842014-11-06 18:23:12 -08001686 transform: function (d) { return translate(d.x, d.y); },
1687 opacity: 0
1688 })
Simon Hunt1a9eff92014-11-07 11:06:34 -08001689 .call(network.drag)
Simon Hunt6ac93f32014-11-13 12:17:27 -08001690 .on('mouseover', nodeMouseOver)
1691 .on('mouseout', nodeMouseOut)
Simon Hunt99c13842014-11-06 18:23:12 -08001692 .transition()
1693 .attr('opacity', 1);
1694
1695 // augment device nodes...
1696 entering.filter('.device').each(function (d) {
1697 var node = d3.select(this),
Simon Huntc72967b2014-11-20 09:21:42 -08001698 label = trimLabel(deviceLabel(d)),
1699 noLabel = !label,
Simon Hunt99c13842014-11-06 18:23:12 -08001700 box;
1701
Simon Hunt7cd48f32014-11-09 23:42:50 -08001702 // provide ref to element from backing data....
1703 d.el = node;
1704
Simon Hunt62c47542014-11-22 22:16:32 -08001705 node.append('rect').attr({ rx: 5, ry: 5 });
1706 node.append('text').text(label).attr('dy', '1.1em');
Simon Hunt99c13842014-11-06 18:23:12 -08001707 box = adjustRectToFitText(node);
Simon Hunta3dd9572014-11-20 15:22:41 -08001708 node.select('rect').attr(box);
Simon Huntc72967b2014-11-20 09:21:42 -08001709 addDeviceIcon(node, box, noLabel, iconGlyphUrl(d));
Simon Huntc7ee0662014-11-05 16:44:37 -08001710 });
Simon Hunt934c3ce2014-11-05 11:45:07 -08001711
Thomas Vachuska89543292014-11-19 11:28:33 -08001712 // TODO: better place for this configuration state
1713 var defaultHostRadius = 9,
1714 hostRadius = {
1715 bgpSpeaker: 14,
1716 router: 14,
Thomas Vachuska60d72bf2014-11-21 13:02:00 -08001717 endstation: 14
Thomas Vachuska89543292014-11-19 11:28:33 -08001718 };
1719
Simon Hunt56d51852014-11-09 13:03:35 -08001720 // augment host nodes...
1721 entering.filter('.host').each(function (d) {
1722 var node = d3.select(this),
Thomas Vachuska89543292014-11-19 11:28:33 -08001723 r = hostRadius[d.type] || defaultHostRadius,
1724 textDy = r + 10,
Simon Hunteb1514d2014-11-20 09:57:29 -08001725 iid = iconGlyphUrl(d);
Simon Hunt56d51852014-11-09 13:03:35 -08001726
Simon Hunt7cd48f32014-11-09 23:42:50 -08001727 // provide ref to element from backing data....
1728 d.el = node;
1729
Simon Hunt62c47542014-11-22 22:16:32 -08001730 node.append('circle').attr('r', r);
Simon Hunt7fa116d2014-11-17 14:16:55 -08001731
Simon Hunteb1514d2014-11-20 09:57:29 -08001732 if (iid) {
1733 addHostIcon(node, r, iid);
Simon Hunt7fa116d2014-11-17 14:16:55 -08001734 }
Simon Hunt56d51852014-11-09 13:03:35 -08001735
Simon Hunt56d51852014-11-09 13:03:35 -08001736 node.append('text')
Simon Hunt7cd48f32014-11-09 23:42:50 -08001737 .text(hostLabel)
Thomas Vachuska89543292014-11-19 11:28:33 -08001738 .attr('dy', textDy)
Simon Hunt7cd48f32014-11-09 23:42:50 -08001739 .attr('text-anchor', 'middle');
Simon Hunt56d51852014-11-09 13:03:35 -08001740 });
Simon Huntc7ee0662014-11-05 16:44:37 -08001741
Simon Hunt99c13842014-11-06 18:23:12 -08001742 // operate on both existing and new nodes, if necessary
1743 //node .foo() .bar() ...
Simon Huntc7ee0662014-11-05 16:44:37 -08001744
Simon Hunt99c13842014-11-06 18:23:12 -08001745 // operate on exiting nodes:
Simon Huntea80eb42014-11-11 13:46:57 -08001746 // Note that the node is removed after 2 seconds.
1747 // Sub element animations should be shorter than 2 seconds.
1748 var exiting = node.exit()
Simon Hunt44031102014-11-11 13:20:36 -08001749 .transition()
1750 .duration(2000)
Simon Huntea80eb42014-11-11 13:46:57 -08001751 .style('opacity', 0)
Simon Hunt99c13842014-11-06 18:23:12 -08001752 .remove();
Simon Huntea80eb42014-11-11 13:46:57 -08001753
1754 // host node exits....
1755 exiting.filter('.host').each(function (d) {
1756 var node = d3.select(this);
1757
1758 node.select('text')
1759 .style('opacity', 0.5)
1760 .transition()
1761 .duration(1000)
1762 .style('opacity', 0);
1763 // note, leave <g>.remove to remove this element
1764
Thomas Vachuska89543292014-11-19 11:28:33 -08001765 node.select('circle')
1766 .style('stroke-fill', '#555')
1767 .style('fill', '#888')
Simon Huntea80eb42014-11-11 13:46:57 -08001768 .style('opacity', 0.5)
1769 .transition()
1770 .duration(1500)
1771 .attr('r', 0);
1772 // note, leave <g>.remove to remove this element
1773
1774 });
1775
Simon Hunt62c47542014-11-22 22:16:32 -08001776 // TODO: device node exit animation
1777
1778 network.force.resume();
Simon Huntc7ee0662014-11-05 16:44:37 -08001779 }
1780
Simon Huntc72967b2014-11-20 09:21:42 -08001781 function addDeviceIcon(node, box, noLabel, iid) {
1782 var cfg = config.icons.device,
1783 dx,
1784 dy,
1785 g;
1786
1787 if (noLabel) {
1788 box = emptyBox();
1789 dx = -cfg.dim/2;
1790 dy = -cfg.dim/2;
1791 } else {
1792 box = adjustRectToFitText(node);
1793 dx = box.x + config.icons.xoff;
1794 dy = box.y + config.icons.yoff;
1795 }
1796
Simon Hunteb1514d2014-11-20 09:57:29 -08001797 g = node.append('g')
1798 .attr('class', 'glyphIcon deviceIcon')
Simon Huntc72967b2014-11-20 09:21:42 -08001799 .attr('transform', translate(dx, dy));
1800
1801 g.append('rect').attr({
1802 x: 0,
1803 y: 0,
1804 rx: cfg.rx,
1805 width: cfg.dim,
1806 height: cfg.dim
1807 });
1808
1809 g.append('use').attr({
1810 'xlink:href': iid,
1811 width: cfg.dim,
1812 height: cfg.dim
1813 });
1814
Simon Huntc72967b2014-11-20 09:21:42 -08001815 }
1816
Simon Hunt7b403bc2014-11-22 19:01:00 -08001817 function find(key, array, tag) {
1818 var _tag = tag || 'key',
1819 idx, n, d;
1820 for (idx = 0, n = array.length; idx < n; idx++) {
1821 d = array[idx];
1822 if (d[_tag] === key) {
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001823 return idx;
1824 }
1825 }
1826 return -1;
1827 }
1828
1829 function removeLinkElement(linkData) {
Simon Hunt8257f4c2014-11-16 19:34:54 -08001830 var idx = find(linkData.key, network.links),
1831 removed;
1832 if (idx >=0) {
1833 // remove from links array
1834 removed = network.links.splice(idx, 1);
1835 // remove from lookup cache
1836 delete network.lookup[removed[0].key];
1837 updateLinks();
1838 network.force.resume();
1839 }
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001840 }
Simon Huntc7ee0662014-11-05 16:44:37 -08001841
Simon Hunt44031102014-11-11 13:20:36 -08001842 function removeHostElement(hostData) {
1843 // first, remove associated hostLink...
1844 removeLinkElement(hostData.linkData);
1845
1846 // remove from lookup cache
1847 delete network.lookup[hostData.id];
1848 // remove from nodes array
1849 var idx = find(hostData.id, network.nodes);
1850 network.nodes.splice(idx, 1);
1851 // remove from SVG
1852 updateNodes();
1853 network.force.resume();
1854 }
1855
1856
Simon Huntc7ee0662014-11-05 16:44:37 -08001857 function tick() {
1858 node.attr({
Simon Hunt99c13842014-11-06 18:23:12 -08001859 transform: function (d) { return translate(d.x, d.y); }
Simon Huntc7ee0662014-11-05 16:44:37 -08001860 });
1861
1862 link.attr({
1863 x1: function (d) { return d.source.x; },
1864 y1: function (d) { return d.source.y; },
1865 x2: function (d) { return d.target.x; },
1866 y2: function (d) { return d.target.y; }
1867 });
Simon Hunte2575b62014-11-18 15:25:53 -08001868
1869 linkLabel.each(function (d) {
1870 var el = d3.select(this);
Thomas Vachuska4731f122014-11-20 04:56:19 -08001871 var lnk = findLinkById(d.key);
1872
1873 if (lnk) {
1874 var parms = {
Simon Hunte2575b62014-11-18 15:25:53 -08001875 x1: lnk.source.x,
1876 y1: lnk.source.y,
1877 x2: lnk.target.x,
1878 y2: lnk.target.y
1879 };
Thomas Vachuska4731f122014-11-20 04:56:19 -08001880 el.attr('transform', transformLabel(parms));
1881 }
Simon Hunte2575b62014-11-18 15:25:53 -08001882 });
Simon Huntc7ee0662014-11-05 16:44:37 -08001883 }
Simon Hunt934c3ce2014-11-05 11:45:07 -08001884
1885 // ==============================
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001886 // Web-Socket for live data
1887
1888 function webSockUrl() {
1889 return document.location.toString()
1890 .replace(/\#.*/, '')
1891 .replace('http://', 'ws://')
1892 .replace('https://', 'wss://')
1893 .replace('index2.html', config.webSockUrl);
1894 }
1895
1896 webSock = {
1897 ws : null,
1898
1899 connect : function() {
1900 webSock.ws = new WebSocket(webSockUrl());
1901
1902 webSock.ws.onopen = function() {
Simon Hunt0c6d4192014-11-12 12:07:10 -08001903 noWebSock(false);
Thomas Vachuska47635c62014-11-22 01:21:36 -08001904 requestSummary();
1905 oiBox.show();
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001906 };
1907
1908 webSock.ws.onmessage = function(m) {
1909 if (m.data) {
Simon Huntbb282f52014-11-10 11:08:19 -08001910 wsTraceRx(m.data);
Thomas Vachuskad472c6e2014-11-07 19:11:05 -08001911 handleServerEvent(JSON.parse(m.data));
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001912 }
1913 };
1914
1915 webSock.ws.onclose = function(m) {
1916 webSock.ws = null;
Simon Hunt0c6d4192014-11-12 12:07:10 -08001917 noWebSock(true);
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001918 };
1919 },
1920
1921 send : function(text) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001922 if (text != null) {
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001923 webSock._send(text);
1924 }
1925 },
1926
1927 _send : function(message) {
1928 if (webSock.ws) {
1929 webSock.ws.send(message);
Simon Hunta255a2c2014-11-13 22:29:35 -08001930 } else if (config.useLiveData) {
Simon Hunt56d51852014-11-09 13:03:35 -08001931 network.view.alert('no web socket open\n\n' + message);
Simon Hunta255a2c2014-11-13 22:29:35 -08001932 } else {
1933 console.log('WS Send: ' + JSON.stringify(message));
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001934 }
1935 }
1936
1937 };
1938
Simon Hunt0c6d4192014-11-12 12:07:10 -08001939 function noWebSock(b) {
1940 mask.style('display',b ? 'block' : 'none');
1941 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001942
1943 function sendMessage(evType, payload) {
1944 var toSend = {
Simon Huntbb282f52014-11-10 11:08:19 -08001945 event: evType,
1946 sid: ++sid,
1947 payload: payload
1948 },
1949 asText = JSON.stringify(toSend);
1950 wsTraceTx(asText);
1951 webSock.send(asText);
Simon Huntc76ae892014-11-18 17:31:51 -08001952
1953 // Temporary measure for debugging UI behavior ...
1954 if (!config.useLiveData) {
1955 handleTestSend(toSend);
1956 }
Simon Huntbb282f52014-11-10 11:08:19 -08001957 }
1958
1959 function wsTraceTx(msg) {
1960 wsTrace('tx', msg);
1961 }
1962 function wsTraceRx(msg) {
1963 wsTrace('rx', msg);
1964 }
1965 function wsTrace(rxtx, msg) {
Simon Huntbb282f52014-11-10 11:08:19 -08001966 console.log('[' + rxtx + '] ' + msg);
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001967 }
1968
Simon Huntc76ae892014-11-18 17:31:51 -08001969 // NOTE: Temporary hardcoded example for showing detail pane
1970 // while we fine-
1971 // Probably should not merge this change...
1972 function handleTestSend(msg) {
1973 if (msg.event === 'requestDetails') {
1974 showDetails({
1975 event: 'showDetails',
1976 sid: 1001,
1977 payload: {
1978 "id": "of:0000ffffffffff09",
1979 "type": "roadm",
1980 "propOrder": [
1981 "Name",
1982 "Vendor",
1983 "H/W Version",
1984 "S/W Version",
1985 "-",
1986 "Latitude",
1987 "Longitude",
1988 "Ports"
1989 ],
1990 "props": {
1991 "Name": null,
1992 "Vendor": "Linc",
1993 "H/W Version": "OE",
1994 "S/W Version": "?",
1995 "-": "",
1996 "Latitude": "40.8",
1997 "Longitude": "73.1",
1998 "Ports": "2"
1999 }
2000 }
2001 });
2002 }
2003 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002004
2005 // ==============================
2006 // Selection stuff
2007
2008 function selectObject(obj, el) {
2009 var n,
Simon Hunt01095ff2014-11-13 16:37:29 -08002010 srcEv = d3.event.sourceEvent,
2011 meta = srcEv.metaKey,
2012 shift = srcEv.shiftKey;
2013
Simon Huntdeab4322014-11-13 18:49:07 -08002014 if ((panZoom() && !meta) || (!panZoom() && meta)) {
Simon Hunt01095ff2014-11-13 16:37:29 -08002015 return;
2016 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002017
2018 if (el) {
2019 n = d3.select(el);
2020 } else {
2021 node.each(function(d) {
2022 if (d == obj) {
2023 n = d3.select(el = this);
2024 }
2025 });
2026 }
2027 if (!n) return;
2028
Simon Hunt01095ff2014-11-13 16:37:29 -08002029 if (shift && n.classed('selected')) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002030 deselectObject(obj.id);
Simon Hunt61d04042014-11-11 17:27:16 -08002031 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002032 return;
2033 }
2034
Simon Hunt01095ff2014-11-13 16:37:29 -08002035 if (!shift) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002036 deselectAll();
2037 }
2038
Simon Huntc31d5692014-11-12 13:27:18 -08002039 selections[obj.id] = { obj: obj, el: el };
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002040 selectOrder.push(obj.id);
2041
2042 n.classed('selected', true);
Simon Hunt61d04042014-11-11 17:27:16 -08002043 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002044 }
2045
2046 function deselectObject(id) {
Simon Huntc31d5692014-11-12 13:27:18 -08002047 var obj = selections[id],
2048 idx;
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002049 if (obj) {
2050 d3.select(obj.el).classed('selected', false);
Simon Hunt61d04042014-11-11 17:27:16 -08002051 delete selections[id];
Simon Huntc31d5692014-11-12 13:27:18 -08002052 idx = $.inArray(id, selectOrder);
2053 if (idx >= 0) {
2054 selectOrder.splice(idx, 1);
2055 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002056 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002057 }
2058
2059 function deselectAll() {
2060 // deselect all nodes in the network...
2061 node.classed('selected', false);
2062 selections = {};
2063 selectOrder = [];
Simon Hunt61d04042014-11-11 17:27:16 -08002064 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002065 }
2066
Thomas Vachuska47635c62014-11-22 01:21:36 -08002067 // update the state of the sumary pane
2068 function updateSummaryPane() {
2069
2070 }
2071
Simon Hunt61d04042014-11-11 17:27:16 -08002072 // update the state of the detail pane, based on current selections
2073 function updateDetailPane() {
2074 var nSel = selectOrder.length;
2075 if (!nSel) {
Thomas Vachuska9edca302014-11-22 17:06:42 -08002076 emptySelect();
Simon Hunt61d04042014-11-11 17:27:16 -08002077 } else if (nSel === 1) {
2078 singleSelect();
Thomas Vachuska9edca302014-11-22 17:06:42 -08002079 requestTrafficForMode();
Simon Hunt61d04042014-11-11 17:27:16 -08002080 } else {
2081 multiSelect();
2082 }
2083 }
2084
Thomas Vachuska9edca302014-11-22 17:06:42 -08002085 function emptySelect() {
2086 detailPane.hide();
2087 cancelTraffic();
2088 }
2089
Simon Hunt61d04042014-11-11 17:27:16 -08002090 function singleSelect() {
Thomas Vachuska9edca302014-11-22 17:06:42 -08002091 // NOTE: detail is shown from showDetails event callback
Simon Hunt61d04042014-11-11 17:27:16 -08002092 requestDetails();
Thomas Vachuska9edca302014-11-22 17:06:42 -08002093 requestTrafficForMode();
Simon Hunt61d04042014-11-11 17:27:16 -08002094 }
2095
2096 function multiSelect() {
Simon Huntb53e0682014-11-12 13:32:01 -08002097 populateMultiSelect();
Thomas Vachuska9edca302014-11-22 17:06:42 -08002098 requestTrafficForMode();
Simon Huntb53e0682014-11-12 13:32:01 -08002099 }
2100
2101 function addSep(tbody) {
2102 var tr = tbody.append('tr');
2103 $('<hr>').appendTo(tr.append('td').attr('colspan', 2));
2104 }
2105
2106 function addProp(tbody, label, value) {
2107 var tr = tbody.append('tr');
2108
2109 tr.append('td')
2110 .attr('class', 'label')
2111 .text(label + ' :');
2112
2113 tr.append('td')
2114 .attr('class', 'value')
2115 .text(value);
2116 }
2117
2118 function populateMultiSelect() {
2119 detailPane.empty();
2120
Simon Hunta3dd9572014-11-20 15:22:41 -08002121 var title = detailPane.append('h3'),
2122 table = detailPane.append('table'),
2123 tbody = table.append('tbody');
Simon Huntb53e0682014-11-12 13:32:01 -08002124
Thomas Vachuska4731f122014-11-20 04:56:19 -08002125 title.text('Selected Nodes');
Simon Huntb53e0682014-11-12 13:32:01 -08002126
2127 selectOrder.forEach(function (d, i) {
2128 addProp(tbody, i+1, d);
2129 });
Simon Huntd72bc702014-11-13 18:38:04 -08002130
2131 addMultiSelectActions();
Simon Hunt61d04042014-11-11 17:27:16 -08002132 }
2133
Thomas Vachuska47635c62014-11-22 01:21:36 -08002134 // TODO: refactor to consolidate with populateDetails
2135 function populateSummary(data) {
2136 summaryPane.empty();
2137
2138 var svg = summaryPane.append('svg'),
2139 iid = iconGlyphUrl(data);
2140
2141 var title = summaryPane.append('h2'),
2142 table = summaryPane.append('table'),
2143 tbody = table.append('tbody');
2144
2145 appendGlyph(svg, 0, 0, 40, iid);
2146
2147 svg.append('use')
2148 .attr({
2149 class: 'birdBadge',
2150 transform: translate(8,12),
2151 'xlink:href': '#bird',
2152 width: 24,
2153 height: 24,
2154 fill: '#fff'
2155 });
2156
2157 title.text('ONOS Summary');
2158
2159 data.propOrder.forEach(function(p) {
2160 if (p === '-') {
2161 addSep(tbody);
2162 } else {
2163 addProp(tbody, p, data.props[p]);
2164 }
2165 });
2166 }
2167
Simon Hunt61d04042014-11-11 17:27:16 -08002168 function populateDetails(data) {
2169 detailPane.empty();
2170
Simon Hunta6a9fe72014-11-20 11:17:12 -08002171 var svg = detailPane.append('svg'),
2172 iid = iconGlyphUrl(data);
2173
Simon Hunta3dd9572014-11-20 15:22:41 -08002174 var title = detailPane.append('h2'),
2175 table = detailPane.append('table'),
2176 tbody = table.append('tbody');
Simon Hunt61d04042014-11-11 17:27:16 -08002177
Simon Hunta6a9fe72014-11-20 11:17:12 -08002178 appendGlyph(svg, 0, 0, 40, iid);
2179 title.text(data.id);
Simon Hunt61d04042014-11-11 17:27:16 -08002180
2181 data.propOrder.forEach(function(p) {
2182 if (p === '-') {
2183 addSep(tbody);
2184 } else {
2185 addProp(tbody, p, data.props[p]);
2186 }
2187 });
Simon Huntd72bc702014-11-13 18:38:04 -08002188
Thomas Vachuska4731f122014-11-20 04:56:19 -08002189 addSingleSelectActions(data);
Simon Hunt61d04042014-11-11 17:27:16 -08002190 }
2191
Thomas Vachuska4731f122014-11-20 04:56:19 -08002192 function addSingleSelectActions(data) {
Simon Huntd72bc702014-11-13 18:38:04 -08002193 detailPane.append('hr');
2194 // always want to allow 'show traffic'
Thomas Vachuska4731f122014-11-20 04:56:19 -08002195 addAction(detailPane, 'Show Related Traffic', showTrafficAction);
2196
2197 if (data.type === 'switch') {
2198 addAction(detailPane, 'Show Device Flows', showDeviceLinkFlowsAction);
2199 }
Simon Huntd72bc702014-11-13 18:38:04 -08002200 }
2201
2202 function addMultiSelectActions() {
2203 detailPane.append('hr');
2204 // always want to allow 'show traffic'
Thomas Vachuska4731f122014-11-20 04:56:19 -08002205 addAction(detailPane, 'Show Related Traffic', showTrafficAction);
Simon Huntd72bc702014-11-13 18:38:04 -08002206 // if exactly two hosts are selected, also want 'add host intent'
2207 if (nSel() === 2 && allSelectionsClass('host')) {
Thomas Vachuska9edca302014-11-22 17:06:42 -08002208 addAction(detailPane, 'Create Host-to-Host Flow', addHostIntentAction);
2209 } else if (nSel() >= 2 && allSelectionsClass('host')) {
2210 addAction(detailPane, 'Create Multi-Source Flow', addMultiSourceIntentAction);
Simon Huntd72bc702014-11-13 18:38:04 -08002211 }
2212 }
2213
Simon Hunta5e89142014-11-14 07:00:33 -08002214 function addAction(panel, text, cb) {
2215 panel.append('div')
Simon Huntd72bc702014-11-13 18:38:04 -08002216 .classed('actionBtn', true)
2217 .text(text)
2218 .on('click', cb);
2219 }
2220
2221
Paul Greysonfcba0e82014-11-13 10:21:16 -08002222 function zoomPan(scale, translate) {
2223 zoomPanContainer.attr("transform", "translate(" + translate + ")scale(" + scale + ")");
2224 // keep the map lines constant width while zooming
Thomas Vachuska89543292014-11-19 11:28:33 -08002225 bgImg.style("stroke-width", 2.0 / scale + "px");
Paul Greysonfcba0e82014-11-13 10:21:16 -08002226 }
2227
2228 function resetZoomPan() {
2229 zoomPan(1, [0,0]);
2230 zoom.scale(1).translate([0,0]);
2231 }
2232
2233 function setupZoomPan() {
2234 function zoomed() {
Simon Huntdeab4322014-11-13 18:49:07 -08002235 if (!panZoom() ^ !d3.event.sourceEvent.metaKey) {
Paul Greysonfcba0e82014-11-13 10:21:16 -08002236 zoomPan(d3.event.scale, d3.event.translate);
2237 }
2238 }
2239
2240 zoom = d3.behavior.zoom()
2241 .translate([0, 0])
2242 .scale(1)
2243 .scaleExtent([1, 8])
2244 .on("zoom", zoomed);
2245
2246 svg.call(zoom);
2247 }
2248
Simon Hunt61d04042014-11-11 17:27:16 -08002249 // ==============================
2250 // Test harness code
Simon Hunt56d51852014-11-09 13:03:35 -08002251
2252 function prepareScenario(view, ctx, dbg) {
2253 var sc = scenario,
2254 urlSc = sc.evDir + ctx + sc.evScenario;
2255
2256 if (!ctx) {
2257 view.alert("No scenario specified (null ctx)");
2258 return;
2259 }
2260
2261 sc.view = view;
2262 sc.ctx = ctx;
2263 sc.debug = dbg;
2264 sc.evNumber = 0;
2265
2266 d3.json(urlSc, function(err, data) {
Simon Huntbb282f52014-11-10 11:08:19 -08002267 var p = data && data.params || {},
2268 desc = data && data.description || null,
Simon Huntfc274c92014-11-11 11:05:46 -08002269 intro = data && data.title;
Simon Huntbb282f52014-11-10 11:08:19 -08002270
Simon Hunt56d51852014-11-09 13:03:35 -08002271 if (err) {
2272 view.alert('No scenario found:\n\n' + urlSc + '\n\n' + err);
2273 } else {
2274 sc.params = p;
Simon Huntbb282f52014-11-10 11:08:19 -08002275 if (desc) {
2276 intro += '\n\n ' + desc.join('\n ');
2277 }
2278 view.alert(intro);
Simon Hunt56d51852014-11-09 13:03:35 -08002279 }
2280 });
2281
2282 }
2283
Simon Hunt01095ff2014-11-13 16:37:29 -08002284 // ==============================
2285 // Toggle Buttons in masthead
Simon Hunt0c6d4192014-11-12 12:07:10 -08002286
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002287 // TODO: toggle button (and other widgets in the masthead) should be provided
2288 // by the framework; not generated by the view.
2289
Thomas Vachuska47635c62014-11-22 01:21:36 -08002290 //var showInstances;
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002291
2292 function addButtonBar(view) {
2293 var bb = d3.select('#mast')
2294 .append('span').classed('right', true).attr('id', 'bb');
2295
Simon Hunta5e89142014-11-14 07:00:33 -08002296 function mkTogBtn(text, cb) {
2297 return bb.append('span')
2298 .classed('btn', true)
2299 .text(text)
2300 .on('click', cb);
2301 }
Simon Hunt01095ff2014-11-13 16:37:29 -08002302
Thomas Vachuska47635c62014-11-22 01:21:36 -08002303 //showInstances = mkTogBtn('Show Instances', toggleInst);
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002304 }
2305
Simon Huntdeab4322014-11-13 18:49:07 -08002306 function panZoom() {
Simon Hunte5b71752014-11-18 20:06:07 -08002307 return false;
Simon Hunta5e89142014-11-14 07:00:33 -08002308 }
2309
Simon Hunt7fa116d2014-11-17 14:16:55 -08002310 function loadGlyphs(svg) {
2311 var defs = svg.append('defs');
2312 gly.defBird(defs);
Simon Huntc72967b2014-11-20 09:21:42 -08002313 gly.defGlyphs(defs);
Simon Huntb82f6902014-11-22 11:53:15 -08002314 gly.defBadges(defs);
Simon Hunt7fa116d2014-11-17 14:16:55 -08002315 }
Simon Hunt01095ff2014-11-13 16:37:29 -08002316
Simon Hunt62c47542014-11-22 22:16:32 -08002317 function sendUpdateMeta(d) {
2318 var ll = geoMapProjection.invert([d.x, d.y]),
2319 metaUi = {
2320 x: d.x,
2321 y: d.y,
2322 lng: ll[0],
2323 lat: ll[1]
2324 };
2325 d.metaUi = metaUi;
2326 sendMessage('updateMeta', {
2327 id: d.id,
2328 'class': d.class,
2329 'memento': metaUi
2330 });
2331 }
2332
Thomas Vachuska7d638d32014-11-07 10:24:43 -08002333 // ==============================
Simon Hunt142d0032014-11-04 20:13:09 -08002334 // View life-cycle callbacks
Simon Hunt195cb382014-11-03 17:50:51 -08002335
Simon Huntf67722a2014-11-10 09:32:06 -08002336 function preload(view, ctx, flags) {
Simon Hunt142d0032014-11-04 20:13:09 -08002337 var w = view.width(),
2338 h = view.height(),
Simon Huntc7ee0662014-11-05 16:44:37 -08002339 fcfg = config.force,
2340 fpad = fcfg.pad,
2341 forceDim = [w - 2*fpad, h - 2*fpad];
Simon Hunt195cb382014-11-03 17:50:51 -08002342
Simon Hunt142d0032014-11-04 20:13:09 -08002343 // NOTE: view.$div is a D3 selection of the view's div
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002344 var viewBox = '0 0 ' + config.logicalSize + ' ' + config.logicalSize;
2345 svg = view.$div.append('svg').attr('viewBox', viewBox);
Simon Hunt934c3ce2014-11-05 11:45:07 -08002346 setSize(svg, view);
2347
Simon Hunt7fa116d2014-11-17 14:16:55 -08002348 loadGlyphs(svg);
Simon Hunt12ce12e2014-11-15 21:13:19 -08002349
Paul Greysonfcba0e82014-11-13 10:21:16 -08002350 zoomPanContainer = svg.append('g').attr('id', 'zoomPanContainer');
Paul Greysonfcba0e82014-11-13 10:21:16 -08002351 setupZoomPan();
2352
Simon Hunt1a9eff92014-11-07 11:06:34 -08002353 // add blue glow filter to svg layer
Paul Greysonfcba0e82014-11-13 10:21:16 -08002354 d3u.appendGlow(zoomPanContainer);
Simon Hunt1a9eff92014-11-07 11:06:34 -08002355
Simon Huntc7ee0662014-11-05 16:44:37 -08002356 // group for the topology
Paul Greysonfcba0e82014-11-13 10:21:16 -08002357 topoG = zoomPanContainer.append('g')
Simon Huntd3b7d512014-11-12 15:48:41 -08002358 .attr('id', 'topo-G')
Simon Huntc7ee0662014-11-05 16:44:37 -08002359 .attr('transform', fcfg.translate());
2360
Simon Hunte2575b62014-11-18 15:25:53 -08002361 // subgroups for links, link labels, and nodes
Simon Huntc7ee0662014-11-05 16:44:37 -08002362 linkG = topoG.append('g').attr('id', 'links');
Simon Hunte2575b62014-11-18 15:25:53 -08002363 linkLabelG = topoG.append('g').attr('id', 'linkLabels');
Simon Huntc7ee0662014-11-05 16:44:37 -08002364 nodeG = topoG.append('g').attr('id', 'nodes');
2365
Simon Hunte2575b62014-11-18 15:25:53 -08002366 // selection of links, linkLabels, and nodes
Simon Huntc7ee0662014-11-05 16:44:37 -08002367 link = linkG.selectAll('.link');
Simon Hunte2575b62014-11-18 15:25:53 -08002368 linkLabel = linkLabelG.selectAll('.linkLabel');
Simon Huntc7ee0662014-11-05 16:44:37 -08002369 node = nodeG.selectAll('.node');
2370
Simon Hunt7cd48f32014-11-09 23:42:50 -08002371 function chrg(d) {
2372 return fcfg.charge[d.class] || -12000;
2373 }
Simon Hunt99c13842014-11-06 18:23:12 -08002374 function ldist(d) {
Simon Hunt7cd48f32014-11-09 23:42:50 -08002375 return fcfg.linkDistance[d.type] || 50;
Simon Hunt99c13842014-11-06 18:23:12 -08002376 }
2377 function lstrg(d) {
Simon Hunt7cd48f32014-11-09 23:42:50 -08002378 // 0.0 - 1.0
2379 return fcfg.linkStrength[d.type] || 1.0;
Simon Hunt99c13842014-11-06 18:23:12 -08002380 }
2381
Simon Hunt1a9eff92014-11-07 11:06:34 -08002382 function selectCb(d, self) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08002383 selectObject(d, self);
Simon Hunt1a9eff92014-11-07 11:06:34 -08002384 }
2385
2386 function atDragEnd(d, self) {
Simon Hunt56d51852014-11-09 13:03:35 -08002387 // once we've finished moving, pin the node in position
2388 d.fixed = true;
2389 d3.select(self).classed('fixed', true);
2390 if (config.useLiveData) {
Simon Hunt902c9922014-11-11 11:59:31 -08002391 sendUpdateMeta(d);
Simon Hunta255a2c2014-11-13 22:29:35 -08002392 } else {
2393 console.log('Moving node ' + d.id + ' to [' + d.x + ',' + d.y + ']');
Simon Hunt1a9eff92014-11-07 11:06:34 -08002394 }
2395 }
2396
Simon Huntc7ee0662014-11-05 16:44:37 -08002397 // set up the force layout
2398 network.force = d3.layout.force()
2399 .size(forceDim)
2400 .nodes(network.nodes)
2401 .links(network.links)
Simon Hunt7cd48f32014-11-09 23:42:50 -08002402 .gravity(0.4)
2403 .friction(0.7)
2404 .charge(chrg)
Simon Hunt99c13842014-11-06 18:23:12 -08002405 .linkDistance(ldist)
2406 .linkStrength(lstrg)
Simon Huntc7ee0662014-11-05 16:44:37 -08002407 .on('tick', tick);
Simon Hunt195cb382014-11-03 17:50:51 -08002408
Simon Hunt01095ff2014-11-13 16:37:29 -08002409 network.drag = d3u.createDragBehavior(network.force,
Simon Huntdeab4322014-11-13 18:49:07 -08002410 selectCb, atDragEnd, panZoom);
Simon Hunt0c6d4192014-11-12 12:07:10 -08002411
2412 // create mask layer for when we lose connection to server.
Simon Hunta5e89142014-11-14 07:00:33 -08002413 // TODO: this should be part of the framework
Simon Hunt0c6d4192014-11-12 12:07:10 -08002414 mask = view.$div.append('div').attr('id','topo-mask');
2415 para(mask, 'Oops!');
2416 para(mask, 'Web-socket connection to server closed...');
2417 para(mask, 'Try refreshing the page.');
Simon Hunt12ce12e2014-11-15 21:13:19 -08002418
2419 mask.append('svg')
2420 .attr({
2421 id: 'mask-bird',
2422 width: w,
2423 height: h
2424 })
2425 .append('g')
2426 .attr('transform', birdTranslate(w, h))
2427 .style('opacity', 0.3)
2428 .append('use')
2429 .attr({
2430 'xlink:href': '#bird',
2431 width: config.birdDim,
2432 height: config.birdDim,
2433 fill: '#111'
Thomas Vachuska89543292014-11-19 11:28:33 -08002434 })
Simon Hunt1a9eff92014-11-07 11:06:34 -08002435 }
Simon Hunt195cb382014-11-03 17:50:51 -08002436
Simon Hunt01095ff2014-11-13 16:37:29 -08002437 function para(sel, text) {
2438 sel.append('p').text(text);
2439 }
2440
2441
Simon Hunt56d51852014-11-09 13:03:35 -08002442 function load(view, ctx, flags) {
Simon Huntf67722a2014-11-10 09:32:06 -08002443 // resize, in case the window was resized while we were not loaded
2444 resize(view, ctx, flags);
2445
Simon Hunt99c13842014-11-06 18:23:12 -08002446 // cache the view token, so network topo functions can access it
2447 network.view = view;
Simon Hunt56d51852014-11-09 13:03:35 -08002448 config.useLiveData = !flags.local;
2449
2450 if (!config.useLiveData) {
2451 prepareScenario(view, ctx, flags.debug);
2452 }
Simon Hunt99c13842014-11-06 18:23:12 -08002453
2454 // set our radio buttons and key bindings
Simon Hunt9462e8c2014-11-14 17:28:09 -08002455 layerBtnSet = view.setRadio(layerButtons);
Simon Hunt934c3ce2014-11-05 11:45:07 -08002456 view.setKeys(keyDispatch);
Simon Hunt195cb382014-11-03 17:50:51 -08002457
Simon Huntf8e5b4e02014-11-13 11:17:57 -08002458 // patch in our "button bar" for now
2459 // TODO: implement a more official frameworky way of doing this..
2460 addButtonBar(view);
2461
Simon Huntd3b7d512014-11-12 15:48:41 -08002462 // Load map data asynchronously; complete startup after that..
2463 loadGeoJsonData();
Simon Hunta255a2c2014-11-13 22:29:35 -08002464 }
2465
Thomas Vachuskaa3148a72014-11-19 21:38:35 -08002466 function startAntTimer() {
Thomas Vachuska4731f122014-11-20 04:56:19 -08002467 if (!antTimer) {
2468 var pulses = [5, 3, 1.2, 3],
2469 pulse = 0;
2470 antTimer = setInterval(function () {
2471 pulse = pulse + 1;
2472 pulse = pulse === pulses.length ? 0 : pulse;
2473 d3.selectAll('.animated').style('stroke-width', pulses[pulse]);
2474 }, 200);
2475 }
Thomas Vachuskaa3148a72014-11-19 21:38:35 -08002476 }
2477
2478 function stopAntTimer() {
Simon Hunta255a2c2014-11-13 22:29:35 -08002479 if (antTimer) {
2480 clearInterval(antTimer);
2481 antTimer = null;
2482 }
Simon Huntd3b7d512014-11-12 15:48:41 -08002483 }
2484
Thomas Vachuskaa3148a72014-11-19 21:38:35 -08002485 function unload(view, ctx, flags) {
2486 stopAntTimer();
2487 }
2488
Simon Huntd3b7d512014-11-12 15:48:41 -08002489 // TODO: move these to config/state portion of script
Simon Hunta6a9fe72014-11-20 11:17:12 -08002490 var geoJsonUrl = 'json/map/continental_us.json',
Simon Huntd3b7d512014-11-12 15:48:41 -08002491 geoJson;
2492
2493 function loadGeoJsonData() {
2494 d3.json(geoJsonUrl, function (err, data) {
2495 if (err) {
2496 // fall back to USA map background
2497 loadStaticMap();
2498 } else {
2499 geoJson = data;
2500 loadGeoMap();
2501 }
2502
2503 // finally, connect to the server...
2504 if (config.useLiveData) {
2505 webSock.connect();
2506 }
2507 });
2508 }
2509
2510 function showBg() {
2511 return config.options.showBackground ? 'visible' : 'hidden';
2512 }
2513
2514 function loadStaticMap() {
2515 fnTrace('loadStaticMap', config.backgroundUrl);
2516 var w = network.view.width(),
2517 h = network.view.height();
2518
2519 // load the background image
2520 bgImg = svg.insert('svg:image', '#topo-G')
2521 .attr({
2522 id: 'topo-bg',
2523 width: w,
2524 height: h,
2525 'xlink:href': config.backgroundUrl
2526 })
2527 .style({
2528 visibility: showBg()
2529 });
2530 }
2531
2532 function loadGeoMap() {
2533 fnTrace('loadGeoMap', geoJsonUrl);
Simon Huntd3b7d512014-11-12 15:48:41 -08002534
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002535 // extracts the topojson data into geocoordinate-based geometry
2536 var topoData = topojson.feature(geoJson, geoJson.objects.states);
Simon Huntd3b7d512014-11-12 15:48:41 -08002537
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002538 // see: http://bl.ocks.org/mbostock/4707858
2539 geoMapProjection = d3.geo.mercator();
2540 var path = d3.geo.path().projection(geoMapProjection);
Simon Huntd3b7d512014-11-12 15:48:41 -08002541
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002542 geoMapProjection
2543 .scale(1)
2544 .translate([0, 0]);
Simon Huntd3b7d512014-11-12 15:48:41 -08002545
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002546 // [[x1,y1],[x2,y2]]
2547 var b = path.bounds(topoData);
Paul Greysonfcba0e82014-11-13 10:21:16 -08002548 // size map to 95% of minimum dimension to fill space
2549 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 -08002550 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 -08002551
Paul Greyson6cb8ca02014-11-12 18:09:02 -08002552 geoMapProjection
2553 .scale(s)
2554 .translate(t);
2555
Paul Greysonfcba0e82014-11-13 10:21:16 -08002556 bgImg = zoomPanContainer.insert("g", '#topo-G');
Thomas Vachuska89543292014-11-19 11:28:33 -08002557 bgImg.attr('id', 'map').selectAll('path')
2558 .data(topoData.features)
2559 .enter()
2560 .append('path')
2561 .attr('d', path);
Simon Hunt195cb382014-11-03 17:50:51 -08002562 }
2563
Simon Huntf67722a2014-11-10 09:32:06 -08002564 function resize(view, ctx, flags) {
Simon Hunt12ce12e2014-11-15 21:13:19 -08002565 var w = view.width(),
2566 h = view.height();
2567
Simon Hunt934c3ce2014-11-05 11:45:07 -08002568 setSize(svg, view);
Simon Hunt12ce12e2014-11-15 21:13:19 -08002569
2570 d3.select('#mask-bird').attr({ width: w, height: h})
2571 .select('g').attr('transform', birdTranslate(w, h));
Simon Hunt142d0032014-11-04 20:13:09 -08002572 }
2573
Simon Hunt12ce12e2014-11-15 21:13:19 -08002574 function birdTranslate(w, h) {
2575 var bdim = config.birdDim;
2576 return 'translate('+((w-bdim)*.4)+','+((h-bdim)*.1)+')';
2577 }
Simon Hunt142d0032014-11-04 20:13:09 -08002578
2579 // ==============================
2580 // View registration
Simon Hunt195cb382014-11-03 17:50:51 -08002581
Simon Hunt25248912014-11-04 11:25:48 -08002582 onos.ui.addView('topo', {
Simon Hunt142d0032014-11-04 20:13:09 -08002583 preload: preload,
2584 load: load,
Simon Hunta255a2c2014-11-13 22:29:35 -08002585 unload: unload,
Simon Hunt142d0032014-11-04 20:13:09 -08002586 resize: resize
Simon Hunt195cb382014-11-03 17:50:51 -08002587 });
2588
Thomas Vachuska47635c62014-11-22 01:21:36 -08002589 summaryPane = onos.ui.addFloatingPanel('topo-summary');
Simon Hunt61d04042014-11-11 17:27:16 -08002590 detailPane = onos.ui.addFloatingPanel('topo-detail');
Simon Hunta5e89142014-11-14 07:00:33 -08002591 oiBox = onos.ui.addFloatingPanel('topo-oibox', 'TL');
Simon Huntb82f6902014-11-22 11:53:15 -08002592 oiBox.width(20);
Simon Hunt61d04042014-11-11 17:27:16 -08002593
Simon Hunt195cb382014-11-03 17:50:51 -08002594}(ONOS));