blob: d87cd27d7345b98cefb523554023826271ed1b63 [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
21 */
22
23(function (onos) {
24 'use strict';
25
Simon Hunt1a9eff92014-11-07 11:06:34 -080026 // shorter names for library APIs
Simon Huntbb282f52014-11-10 11:08:19 -080027 var d3u = onos.lib.d3util,
28 trace;
Simon Hunt1a9eff92014-11-07 11:06:34 -080029
Simon Hunt195cb382014-11-03 17:50:51 -080030 // configuration data
31 var config = {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -080032 useLiveData: true,
Simon Huntfc274c92014-11-11 11:05:46 -080033 fnTrace: true,
Simon Hunt195cb382014-11-03 17:50:51 -080034 debugOn: false,
35 debug: {
Simon Hunt99c13842014-11-06 18:23:12 -080036 showNodeXY: true,
37 showKeyHandler: false
Simon Hunt195cb382014-11-03 17:50:51 -080038 },
39 options: {
40 layering: true,
41 collisionPrevention: true,
Simon Hunt142d0032014-11-04 20:13:09 -080042 showBackground: true
Simon Hunt195cb382014-11-03 17:50:51 -080043 },
44 backgroundUrl: 'img/us-map.png',
Thomas Vachuska7d638d32014-11-07 10:24:43 -080045 webSockUrl: 'ws/topology',
Simon Hunt195cb382014-11-03 17:50:51 -080046 data: {
47 live: {
48 jsonUrl: 'rs/topology/graph',
49 detailPrefix: 'rs/topology/graph/',
50 detailSuffix: ''
51 },
52 fake: {
53 jsonUrl: 'json/network2.json',
54 detailPrefix: 'json/',
55 detailSuffix: '.json'
56 }
57 },
Simon Hunt99c13842014-11-06 18:23:12 -080058 labels: {
59 imgPad: 16,
60 padLR: 4,
61 padTB: 3,
62 marginLR: 3,
63 marginTB: 2,
64 port: {
65 gap: 3,
66 width: 18,
67 height: 14
68 }
69 },
Simon Hunt1a9eff92014-11-07 11:06:34 -080070 topo: {
71 linkInColor: '#66f',
72 linkInWidth: 14
73 },
Simon Hunt99c13842014-11-06 18:23:12 -080074 icons: {
75 w: 28,
76 h: 28,
77 xoff: -12,
78 yoff: -8
79 },
Simon Hunt195cb382014-11-03 17:50:51 -080080 iconUrl: {
81 device: 'img/device.png',
82 host: 'img/host.png',
83 pkt: 'img/pkt.png',
84 opt: 'img/opt.png'
85 },
Simon Hunt195cb382014-11-03 17:50:51 -080086 force: {
Simon Hunt7cd48f32014-11-09 23:42:50 -080087 note_for_links: 'link.type is used to differentiate',
Simon Huntc7ee0662014-11-05 16:44:37 -080088 linkDistance: {
Simon Hunt7cd48f32014-11-09 23:42:50 -080089 direct: 100,
90 optical: 120,
Thomas Vachuska3266abf2014-11-13 09:28:46 -080091 hostLink: 3
Simon Huntc7ee0662014-11-05 16:44:37 -080092 },
93 linkStrength: {
Simon Hunt7cd48f32014-11-09 23:42:50 -080094 direct: 1.0,
95 optical: 1.0,
96 hostLink: 1.0
Simon Huntc7ee0662014-11-05 16:44:37 -080097 },
Simon Hunt7cd48f32014-11-09 23:42:50 -080098 note_for_nodes: 'node.class is used to differentiate',
Simon Huntc7ee0662014-11-05 16:44:37 -080099 charge: {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800100 device: -8000,
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800101 host: -5000
Simon Huntc7ee0662014-11-05 16:44:37 -0800102 },
103 pad: 20,
Simon Hunt195cb382014-11-03 17:50:51 -0800104 translate: function() {
105 return 'translate(' +
Simon Huntc7ee0662014-11-05 16:44:37 -0800106 config.force.pad + ',' +
107 config.force.pad + ')';
Simon Hunt195cb382014-11-03 17:50:51 -0800108 }
Paul Greyson6cb8ca02014-11-12 18:09:02 -0800109 },
110 // see below in creation of viewBox on main svg
111 logicalSize: 1000
Simon Hunt195cb382014-11-03 17:50:51 -0800112 };
113
Simon Hunt142d0032014-11-04 20:13:09 -0800114 // radio buttons
115 var btnSet = [
Simon Hunt934c3ce2014-11-05 11:45:07 -0800116 { text: 'All Layers', cb: showAllLayers },
117 { text: 'Packet Only', cb: showPacketLayer },
118 { text: 'Optical Only', cb: showOpticalLayer }
119 ];
120
121 // key bindings
122 var keyDispatch = {
Simon Hunt1a9eff92014-11-07 11:06:34 -0800123 M: testMe, // TODO: remove (testing only)
Simon Hunt50128c02014-11-08 13:36:15 -0800124 S: injectStartupEvents, // TODO: remove (testing only)
125 space: injectTestEvent, // TODO: remove (testing only)
Simon Hunt99c13842014-11-06 18:23:12 -0800126
Thomas Vachuska65368e32014-11-08 16:10:20 -0800127 B: toggleBg, // TODO: do we really need this?
Simon Hunt934c3ce2014-11-05 11:45:07 -0800128 L: cycleLabels,
129 P: togglePorts,
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800130 U: unpin,
131
Simon Huntb53e0682014-11-12 13:32:01 -0800132 W: requestTraffic, // bag of selections
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800133 X: cancelTraffic,
134 Z: requestPath // host-to-host intent (and monitor)
Simon Hunt934c3ce2014-11-05 11:45:07 -0800135 };
Simon Hunt142d0032014-11-04 20:13:09 -0800136
Simon Hunt195cb382014-11-03 17:50:51 -0800137 // state variables
Simon Hunt99c13842014-11-06 18:23:12 -0800138 var network = {
Simon Hunt50128c02014-11-08 13:36:15 -0800139 view: null, // view token reference
Simon Hunt99c13842014-11-06 18:23:12 -0800140 nodes: [],
141 links: [],
142 lookup: {}
143 },
Simon Hunt56d51852014-11-09 13:03:35 -0800144 scenario = {
145 evDir: 'json/ev/',
146 evScenario: '/scenario.json',
147 evPrefix: '/ev_',
148 evOnos: '_onos.json',
149 evUi: '_ui.json',
150 ctx: null,
151 params: {},
152 evNumber: 0,
153 view: null,
154 debug: false
155 },
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800156 webSock,
Simon Hunt0c6d4192014-11-12 12:07:10 -0800157 sid = 0,
Simon Hunt56d51852014-11-09 13:03:35 -0800158 deviceLabelIndex = 0,
159 hostLabelIndex = 0,
Simon Hunt61d04042014-11-11 17:27:16 -0800160 detailPane,
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800161 selectOrder = [],
162 selections = {},
Simon Hunt6ac93f32014-11-13 12:17:27 -0800163 hovered = null,
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800164
Simon Hunt195cb382014-11-03 17:50:51 -0800165 highlighted = null,
Simon Hunt195cb382014-11-03 17:50:51 -0800166 viewMode = 'showAll',
167 portLabelsOn = false;
168
Simon Hunt934c3ce2014-11-05 11:45:07 -0800169 // D3 selections
170 var svg,
171 bgImg,
Simon Huntc7ee0662014-11-05 16:44:37 -0800172 topoG,
173 nodeG,
174 linkG,
175 node,
Simon Hunt0c6d4192014-11-12 12:07:10 -0800176 link,
177 mask;
Simon Hunt195cb382014-11-03 17:50:51 -0800178
Paul Greyson6cb8ca02014-11-12 18:09:02 -0800179 // the projection for the map background
180 var geoMapProjection;
181
Simon Hunt142d0032014-11-04 20:13:09 -0800182 // ==============================
Simon Hunt934c3ce2014-11-05 11:45:07 -0800183 // For Debugging / Development
Simon Hunt195cb382014-11-03 17:50:51 -0800184
Simon Hunt99c13842014-11-06 18:23:12 -0800185 function note(label, msg) {
186 console.log('NOTE: ' + label + ': ' + msg);
Simon Hunt195cb382014-11-03 17:50:51 -0800187 }
188
Simon Hunt99c13842014-11-06 18:23:12 -0800189 function debug(what) {
190 return config.debugOn && config.debug[what];
Simon Hunt934c3ce2014-11-05 11:45:07 -0800191 }
192
Simon Huntfc274c92014-11-11 11:05:46 -0800193 function fnTrace(msg, id) {
194 if (config.fnTrace) {
195 console.log('FN: ' + msg + ' [' + id + ']');
196 }
197 }
Simon Hunt99c13842014-11-06 18:23:12 -0800198
Simon Hunt934c3ce2014-11-05 11:45:07 -0800199 // ==============================
200 // Key Callbacks
201
Simon Hunt99c13842014-11-06 18:23:12 -0800202 function testMe(view) {
Simon Hunt50128c02014-11-08 13:36:15 -0800203 view.alert('test');
Simon Hunt99c13842014-11-06 18:23:12 -0800204 }
205
Simon Hunt56d51852014-11-09 13:03:35 -0800206 function abortIfLive() {
Simon Hunt50128c02014-11-08 13:36:15 -0800207 if (config.useLiveData) {
Simon Huntb53e0682014-11-12 13:32:01 -0800208 network.view.alert("Sorry, currently using live data..");
Simon Hunt56d51852014-11-09 13:03:35 -0800209 return true;
Simon Hunt50128c02014-11-08 13:36:15 -0800210 }
Simon Hunt56d51852014-11-09 13:03:35 -0800211 return false;
212 }
Simon Hunt50128c02014-11-08 13:36:15 -0800213
Simon Hunt56d51852014-11-09 13:03:35 -0800214 function testDebug(msg) {
215 if (scenario.debug) {
216 scenario.view.alert(msg);
217 }
218 }
Simon Hunt99c13842014-11-06 18:23:12 -0800219
Simon Hunt56d51852014-11-09 13:03:35 -0800220 function injectTestEvent(view) {
221 if (abortIfLive()) { return; }
222 var sc = scenario,
223 evn = ++sc.evNumber,
224 pfx = sc.evDir + sc.ctx + sc.evPrefix + evn,
225 onosUrl = pfx + sc.evOnos,
Simon Hunt7cd48f32014-11-09 23:42:50 -0800226 uiUrl = pfx + sc.evUi,
227 stack = [
228 { url: onosUrl, cb: handleServerEvent },
229 { url: uiUrl, cb: handleUiEvent }
230 ];
231 recurseFetchEvent(stack, evn);
Simon Hunt56d51852014-11-09 13:03:35 -0800232 }
233
Simon Hunt7cd48f32014-11-09 23:42:50 -0800234 function recurseFetchEvent(stack, evn) {
235 var v = scenario.view,
236 frame;
237 if (stack.length === 0) {
Simon Huntfc274c92014-11-11 11:05:46 -0800238 v.alert('Oops!\n\nNo event #' + evn + ' found.');
Simon Hunt7cd48f32014-11-09 23:42:50 -0800239 return;
240 }
241 frame = stack.shift();
242
243 d3.json(frame.url, function (err, data) {
Simon Hunt99c13842014-11-06 18:23:12 -0800244 if (err) {
Simon Hunt56d51852014-11-09 13:03:35 -0800245 if (err.status === 404) {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800246 // if we didn't find the data, try the next stack frame
247 recurseFetchEvent(stack, evn);
Simon Hunt56d51852014-11-09 13:03:35 -0800248 } else {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800249 v.alert('non-404 error:\n\n' + frame.url + '\n\n' + err);
Simon Hunt56d51852014-11-09 13:03:35 -0800250 }
Simon Hunt99c13842014-11-06 18:23:12 -0800251 } else {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800252 testDebug('loaded: ' + frame.url);
253 frame.cb(data);
Simon Hunt99c13842014-11-06 18:23:12 -0800254 }
255 });
Simon Hunt934c3ce2014-11-05 11:45:07 -0800256
Simon Hunt56d51852014-11-09 13:03:35 -0800257 }
Simon Hunt50128c02014-11-08 13:36:15 -0800258
Simon Hunt56d51852014-11-09 13:03:35 -0800259 function handleUiEvent(data) {
Simon Huntbb282f52014-11-10 11:08:19 -0800260 scenario.view.alert('UI Tx: ' + data.event + '\n\n' +
261 JSON.stringify(data));
Simon Hunt56d51852014-11-09 13:03:35 -0800262 }
263
264 function injectStartupEvents(view) {
265 var last = scenario.params.lastAuto || 0;
266 if (abortIfLive()) { return; }
267
268 while (scenario.evNumber < last) {
Simon Hunt1a9eff92014-11-07 11:06:34 -0800269 injectTestEvent(view);
270 }
271 }
272
Simon Hunt934c3ce2014-11-05 11:45:07 -0800273 function toggleBg() {
274 var vis = bgImg.style('visibility');
275 bgImg.style('visibility', (vis === 'hidden') ? 'visible' : 'hidden');
276 }
277
Simon Hunt99c13842014-11-06 18:23:12 -0800278 function cycleLabels() {
Simon Huntbb282f52014-11-10 11:08:19 -0800279 deviceLabelIndex = (deviceLabelIndex === network.deviceLabelCount - 1)
280 ? 0 : deviceLabelIndex + 1;
Simon Hunt5f36d342014-11-08 21:33:14 -0800281
Simon Hunt99c13842014-11-06 18:23:12 -0800282 network.nodes.forEach(function (d) {
Simon Huntbb282f52014-11-10 11:08:19 -0800283 if (d.class === 'device') {
284 updateDeviceLabel(d);
285 }
Simon Hunt99c13842014-11-06 18:23:12 -0800286 });
Simon Hunt934c3ce2014-11-05 11:45:07 -0800287 }
288
289 function togglePorts(view) {
Simon Hunt50128c02014-11-08 13:36:15 -0800290 view.alert('togglePorts() callback')
Simon Hunt934c3ce2014-11-05 11:45:07 -0800291 }
292
Simon Hunt6ac93f32014-11-13 12:17:27 -0800293 function unpin() {
294 if (hovered) {
295 hovered.fixed = false;
296 hovered.el.classed('fixed', false);
297 network.force.resume();
298 }
Simon Hunt934c3ce2014-11-05 11:45:07 -0800299 }
300
301 // ==============================
302 // Radio Button Callbacks
303
Simon Hunt195cb382014-11-03 17:50:51 -0800304 function showAllLayers() {
Simon Hunt142d0032014-11-04 20:13:09 -0800305// network.node.classed('inactive', false);
306// network.link.classed('inactive', false);
307// d3.selectAll('svg .port').classed('inactive', false);
308// d3.selectAll('svg .portText').classed('inactive', false);
Simon Hunt934c3ce2014-11-05 11:45:07 -0800309 // TODO ...
Simon Hunt50128c02014-11-08 13:36:15 -0800310 network.view.alert('showAllLayers() callback');
Simon Hunt195cb382014-11-03 17:50:51 -0800311 }
312
313 function showPacketLayer() {
Simon Hunt934c3ce2014-11-05 11:45:07 -0800314 showAllLayers();
315 // TODO ...
Simon Hunt50128c02014-11-08 13:36:15 -0800316 network.view.alert('showPacketLayer() callback');
Simon Hunt195cb382014-11-03 17:50:51 -0800317 }
318
319 function showOpticalLayer() {
Simon Hunt934c3ce2014-11-05 11:45:07 -0800320 showAllLayers();
321 // TODO ...
Simon Hunt50128c02014-11-08 13:36:15 -0800322 network.view.alert('showOpticalLayer() callback');
Simon Hunt195cb382014-11-03 17:50:51 -0800323 }
324
Simon Hunt142d0032014-11-04 20:13:09 -0800325 // ==============================
Simon Hunt934c3ce2014-11-05 11:45:07 -0800326 // Private functions
327
Simon Hunt99c13842014-11-06 18:23:12 -0800328 function safeId(s) {
329 return s.replace(/[^a-z0-9]/gi, '-');
330 }
331
Simon Huntc7ee0662014-11-05 16:44:37 -0800332 // set the size of the given element to that of the view (reduced if padded)
333 function setSize(el, view, pad) {
334 var padding = pad ? pad * 2 : 0;
Simon Hunt934c3ce2014-11-05 11:45:07 -0800335 el.attr({
Simon Huntc7ee0662014-11-05 16:44:37 -0800336 width: view.width() - padding,
337 height: view.height() - padding
Simon Hunt934c3ce2014-11-05 11:45:07 -0800338 });
339 }
340
Simon Hunt934c3ce2014-11-05 11:45:07 -0800341
Simon Hunt99c13842014-11-06 18:23:12 -0800342 // ==============================
343 // Event handlers for server-pushed events
344
Simon Huntbb282f52014-11-10 11:08:19 -0800345 function logicError(msg) {
346 // TODO, report logic error to server, via websock, so it can be logged
347 network.view.alert('Logic Error:\n\n' + msg);
Simon Huntfc274c92014-11-11 11:05:46 -0800348 console.warn(msg);
Simon Huntbb282f52014-11-10 11:08:19 -0800349 }
350
Simon Hunt99c13842014-11-06 18:23:12 -0800351 var eventDispatch = {
352 addDevice: addDevice,
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800353 addLink: addLink,
Simon Hunt56d51852014-11-09 13:03:35 -0800354 addHost: addHost,
Simon Huntb53e0682014-11-12 13:32:01 -0800355
Simon Huntbb282f52014-11-10 11:08:19 -0800356 updateDevice: updateDevice,
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800357 updateLink: updateLink,
Simon Hunt7cd48f32014-11-09 23:42:50 -0800358 updateHost: updateHost,
Simon Huntb53e0682014-11-12 13:32:01 -0800359
Simon Huntbb282f52014-11-10 11:08:19 -0800360 removeDevice: stillToImplement,
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800361 removeLink: removeLink,
Simon Hunt44031102014-11-11 13:20:36 -0800362 removeHost: removeHost,
Simon Huntb53e0682014-11-12 13:32:01 -0800363
Simon Hunt61d04042014-11-11 17:27:16 -0800364 showDetails: showDetails,
Simon Huntb53e0682014-11-12 13:32:01 -0800365 showPath: showPath,
366 showTraffic: showTraffic
Simon Hunt99c13842014-11-06 18:23:12 -0800367 };
368
369 function addDevice(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800370 fnTrace('addDevice', data.payload.id);
Simon Hunt99c13842014-11-06 18:23:12 -0800371 var device = data.payload,
Simon Hunt7cd48f32014-11-09 23:42:50 -0800372 nodeData = createDeviceNode(device);
Simon Hunt7cd48f32014-11-09 23:42:50 -0800373 network.nodes.push(nodeData);
374 network.lookup[nodeData.id] = nodeData;
Simon Hunt99c13842014-11-06 18:23:12 -0800375 updateNodes();
376 network.force.start();
377 }
378
Simon Hunt99c13842014-11-06 18:23:12 -0800379 function addLink(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800380 fnTrace('addLink', data.payload.id);
Simon Hunt99c13842014-11-06 18:23:12 -0800381 var link = data.payload,
382 lnk = createLink(link);
Simon Hunt99c13842014-11-06 18:23:12 -0800383 if (lnk) {
Simon Hunt99c13842014-11-06 18:23:12 -0800384 network.links.push(lnk);
Thomas Vachuska4830d392014-11-09 17:09:56 -0800385 network.lookup[lnk.id] = lnk;
Simon Hunt99c13842014-11-06 18:23:12 -0800386 updateLinks();
387 network.force.start();
388 }
389 }
390
Simon Hunt56d51852014-11-09 13:03:35 -0800391 function addHost(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800392 fnTrace('addHost', data.payload.id);
Simon Hunt56d51852014-11-09 13:03:35 -0800393 var host = data.payload,
394 node = createHostNode(host),
395 lnk;
Simon Hunt56d51852014-11-09 13:03:35 -0800396 network.nodes.push(node);
397 network.lookup[host.id] = node;
398 updateNodes();
399
400 lnk = createHostLink(host);
401 if (lnk) {
Simon Hunt44031102014-11-11 13:20:36 -0800402 node.linkData = lnk; // cache ref on its host
Simon Hunt56d51852014-11-09 13:03:35 -0800403 network.links.push(lnk);
Thomas Vachuska4830d392014-11-09 17:09:56 -0800404 network.lookup[host.ingress] = lnk;
405 network.lookup[host.egress] = lnk;
Simon Hunt56d51852014-11-09 13:03:35 -0800406 updateLinks();
407 }
408 network.force.start();
409 }
410
Simon Hunt44031102014-11-11 13:20:36 -0800411 // TODO: fold updateX(...) methods into one base method; remove duplication
Simon Huntbb282f52014-11-10 11:08:19 -0800412 function updateDevice(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800413 fnTrace('updateDevice', data.payload.id);
Simon Huntbb282f52014-11-10 11:08:19 -0800414 var device = data.payload,
415 id = device.id,
416 nodeData = network.lookup[id];
417 if (nodeData) {
418 $.extend(nodeData, device);
419 updateDeviceState(nodeData);
420 } else {
421 logicError('updateDevice lookup fail. ID = "' + id + '"');
422 }
423 }
424
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800425 function updateLink(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800426 fnTrace('updateLink', data.payload.id);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800427 var link = data.payload,
428 id = link.id,
429 linkData = network.lookup[id];
430 if (linkData) {
431 $.extend(linkData, link);
432 updateLinkState(linkData);
433 } else {
434 logicError('updateLink lookup fail. ID = "' + id + '"');
435 }
436 }
437
Simon Hunt7cd48f32014-11-09 23:42:50 -0800438 function updateHost(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800439 fnTrace('updateHost', data.payload.id);
Simon Hunt7cd48f32014-11-09 23:42:50 -0800440 var host = data.payload,
Simon Huntbb282f52014-11-10 11:08:19 -0800441 id = host.id,
442 hostData = network.lookup[id];
443 if (hostData) {
444 $.extend(hostData, host);
445 updateHostState(hostData);
446 } else {
447 logicError('updateHost lookup fail. ID = "' + id + '"');
448 }
Simon Hunt7cd48f32014-11-09 23:42:50 -0800449 }
450
Simon Hunt44031102014-11-11 13:20:36 -0800451 // TODO: fold removeX(...) methods into base method - remove dup code
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800452 function removeLink(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800453 fnTrace('removeLink', data.payload.id);
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800454 var link = data.payload,
455 id = link.id,
456 linkData = network.lookup[id];
457 if (linkData) {
458 removeLinkElement(linkData);
459 } else {
460 logicError('removeLink lookup fail. ID = "' + id + '"');
461 }
462 }
463
Simon Hunt44031102014-11-11 13:20:36 -0800464 function removeHost(data) {
465 fnTrace('removeHost', data.payload.id);
466 var host = data.payload,
467 id = host.id,
468 hostData = network.lookup[id];
469 if (hostData) {
470 removeHostElement(hostData);
471 } else {
472 logicError('removeHost lookup fail. ID = "' + id + '"');
473 }
474 }
475
Simon Hunt61d04042014-11-11 17:27:16 -0800476 function showDetails(data) {
477 fnTrace('showDetails', data.payload.id);
478 populateDetails(data.payload);
Simon Huntb53e0682014-11-12 13:32:01 -0800479 // TODO: Add single-select actions ...
Simon Hunt61d04042014-11-11 17:27:16 -0800480 detailPane.show();
481 }
482
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800483 function showPath(data) {
Simon Huntfc274c92014-11-11 11:05:46 -0800484 fnTrace('showPath', data.payload.id);
Thomas Vachuska4830d392014-11-09 17:09:56 -0800485 var links = data.payload.links,
486 s = [ data.event + "\n" + links.length ];
487 links.forEach(function (d, i) {
488 s.push(d);
489 });
490 network.view.alert(s.join('\n'));
491
492 links.forEach(function (d, i) {
493 var link = network.lookup[d];
494 if (link) {
Simon Hunt7cd48f32014-11-09 23:42:50 -0800495 link.el.classed('showPath', true);
Thomas Vachuska4830d392014-11-09 17:09:56 -0800496 }
497 });
498
499 // TODO: add selection-highlite lines to links
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800500 }
501
Simon Huntb53e0682014-11-12 13:32:01 -0800502 function showTraffic(data) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800503 fnTrace('showTraffic', data.payload.id);
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800504 var paths = data.payload.paths;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800505
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800506 // Revert any links hilighted previously.
507 network.links.forEach(function (d) {
508 d.el.classed('showPath', false);
509 });
510
511 // Now hilight all links in the paths payload.
512 paths.forEach(function (d) {
513 var links = d.links;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800514 links.forEach(function (d, i) {
515 var link = network.lookup[d];
516 if (link) {
517 link.el.classed('showPath', true);
518 }
519 });
520 });
521 //network.view.alert("showTraffic() -- TODO")
Simon Huntb53e0682014-11-12 13:32:01 -0800522 }
523
Simon Hunt56d51852014-11-09 13:03:35 -0800524 // ...............................
525
526 function stillToImplement(data) {
527 var p = data.payload;
528 note(data.event, p.id);
Simon Hunt7cd48f32014-11-09 23:42:50 -0800529 network.view.alert('Not yet implemented: "' + data.event + '"');
Simon Hunt56d51852014-11-09 13:03:35 -0800530 }
Simon Hunt99c13842014-11-06 18:23:12 -0800531
532 function unknownEvent(data) {
Simon Hunt50128c02014-11-08 13:36:15 -0800533 network.view.alert('Unknown event type: "' + data.event + '"');
Simon Hunt99c13842014-11-06 18:23:12 -0800534 }
535
536 function handleServerEvent(data) {
537 var fn = eventDispatch[data.event] || unknownEvent;
538 fn(data);
539 }
540
541 // ==============================
Simon Hunt61d04042014-11-11 17:27:16 -0800542 // Out-going messages...
543
Simon Huntb53e0682014-11-12 13:32:01 -0800544 function userFeedback(msg) {
545 // for now, use the alert pane as is. Maybe different alert style in
546 // the future (centered on view; dismiss button?)
547 network.view.alert(msg);
548 }
549
550 function nSel() {
551 return selectOrder.length;
552 }
Simon Hunt61d04042014-11-11 17:27:16 -0800553 function getSel(idx) {
554 return selections[selectOrder[idx]];
555 }
Simon Huntb53e0682014-11-12 13:32:01 -0800556 function getSelId(idx) {
557 return getSel(idx).obj.id;
558 }
559 function allSelectionsClass(cls) {
560 for (var i=0, n=nSel(); i<n; i++) {
561 if (getSel(i).obj.class !== cls) {
562 return false;
563 }
564 }
565 return true;
566 }
Simon Hunt61d04042014-11-11 17:27:16 -0800567
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800568 function requestTraffic(hoverNode) {
569 if (nSel() > 0 || hoverNode) {
570 var nodes = hoverNode ? selectOrder.concat(hoverNode.id) : selectOrder;
Simon Huntb53e0682014-11-12 13:32:01 -0800571 sendMessage('requestTraffic', {
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800572 ids: nodes
Simon Huntb53e0682014-11-12 13:32:01 -0800573 });
574 } else {
575 userFeedback('Request-Traffic requires one or\n' +
576 'more items to be selected.');
577 }
578 }
579
Simon Hunt61d04042014-11-11 17:27:16 -0800580 function requestPath() {
Simon Huntb53e0682014-11-12 13:32:01 -0800581 if (nSel() === 2 && allSelectionsClass('host')) {
582 sendMessage('requestPath', {
583 one: getSelId(0),
584 two: getSelId(1)
585 });
586 } else {
587 userFeedback('Request-Path requires two\n' +
588 'hosts to be selected.');
589 }
Simon Hunt61d04042014-11-11 17:27:16 -0800590 }
591
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800592 function cancelTraffic(hoverNode) {
593 if (hoverNode && selectOrder.length) {
594 requestTraffic();
595 } else {
596 // FIXME: from where do we get the intent id(s) to send to the server?
597 sendMessage('cancelTraffic', {
598 ids: ["need_the_intent_id"]
599 });
600 }
Simon Huntac9e24f2014-11-12 10:12:21 -0800601 }
602
Simon Hunt61d04042014-11-11 17:27:16 -0800603 // request details for the selected element
604 function requestDetails() {
605 var data = getSel(0).obj,
606 payload = {
607 id: data.id,
608 class: data.class
609 };
610 sendMessage('requestDetails', payload);
611 }
612
613 // ==============================
Simon Hunt99c13842014-11-06 18:23:12 -0800614 // force layout modification functions
615
616 function translate(x, y) {
617 return 'translate(' + x + ',' + y + ')';
618 }
619
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800620 function missMsg(what, id) {
621 return '\n[' + what + '] "' + id + '" missing ';
622 }
623
624 function linkEndPoints(srcId, dstId) {
625 var srcNode = network.lookup[srcId],
626 dstNode = network.lookup[dstId],
627 sMiss = !srcNode ? missMsg('src', srcId) : '',
628 dMiss = !dstNode ? missMsg('dst', dstId) : '';
629
630 if (sMiss || dMiss) {
631 logicError('Node(s) not on map for link:\n' + sMiss + dMiss);
632 return null;
633 }
634 return {
635 source: srcNode,
636 target: dstNode,
637 x1: srcNode.x,
638 y1: srcNode.y,
639 x2: dstNode.x,
640 y2: dstNode.y
641 };
642 }
643
Simon Hunt56d51852014-11-09 13:03:35 -0800644 function createHostLink(host) {
645 var src = host.id,
646 dst = host.cp.device,
Simon Hunt7cd48f32014-11-09 23:42:50 -0800647 id = host.ingress,
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800648 lnk = linkEndPoints(src, dst);
Simon Hunt56d51852014-11-09 13:03:35 -0800649
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800650 if (!lnk) {
Simon Hunt56d51852014-11-09 13:03:35 -0800651 return null;
652 }
653
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800654 // Synthesize link ...
655 $.extend(lnk, {
Thomas Vachuska4830d392014-11-09 17:09:56 -0800656 id: id,
Simon Hunt56d51852014-11-09 13:03:35 -0800657 class: 'link',
Simon Hunt7cd48f32014-11-09 23:42:50 -0800658 type: 'hostLink',
Simon Hunt56d51852014-11-09 13:03:35 -0800659 svgClass: 'link hostLink',
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800660 linkWidth: 1
Simon Hunt7cd48f32014-11-09 23:42:50 -0800661 });
Simon Hunt99c13842014-11-06 18:23:12 -0800662 return lnk;
663 }
664
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800665 function createLink(link) {
666 var lnk = linkEndPoints(link.src, link.dst),
667 type = link.type;
668
669 if (!lnk) {
670 return null;
671 }
672
673 // merge in remaining data
674 $.extend(lnk, link, {
675 class: 'link',
676 svgClass: type ? 'link ' + type : 'link'
677 });
678 return lnk;
Simon Hunt1a9eff92014-11-07 11:06:34 -0800679 }
680
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800681 var widthRatio = 1.4,
682 linkScale = d3.scale.linear()
683 .domain([1, 12])
684 .range([widthRatio, 12 * widthRatio])
685 .clamp(true);
686
687 function updateLinkWidth (d) {
688 // TODO: watch out for .showPath/.showTraffic classes
689 d.el.transition()
690 .duration(1000)
691 .attr('stroke-width', linkScale(d.linkWidth));
692 }
693
694
Simon Hunt99c13842014-11-06 18:23:12 -0800695 function updateLinks() {
696 link = linkG.selectAll('.link')
697 .data(network.links, function (d) { return d.id; });
698
699 // operate on existing links, if necessary
700 // link .foo() .bar() ...
701
702 // operate on entering links:
703 var entering = link.enter()
704 .append('line')
705 .attr({
Simon Hunt99c13842014-11-06 18:23:12 -0800706 class: function (d) { return d.svgClass; },
707 x1: function (d) { return d.x1; },
708 y1: function (d) { return d.y1; },
709 x2: function (d) { return d.x2; },
710 y2: function (d) { return d.y2; },
Simon Hunt1a9eff92014-11-07 11:06:34 -0800711 stroke: config.topo.linkInColor,
712 'stroke-width': config.topo.linkInWidth
Simon Hunt99c13842014-11-06 18:23:12 -0800713 })
714 .transition().duration(1000)
715 .attr({
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800716 'stroke-width': function (d) { return linkScale(d.linkWidth); },
Simon Hunt99c13842014-11-06 18:23:12 -0800717 stroke: '#666' // TODO: remove explicit stroke, rather...
718 });
719
720 // augment links
Simon Hunt7cd48f32014-11-09 23:42:50 -0800721 entering.each(function (d) {
722 var link = d3.select(this);
723 // provide ref to element selection from backing data....
724 d.el = link;
Simon Hunt99c13842014-11-06 18:23:12 -0800725
Simon Hunt7cd48f32014-11-09 23:42:50 -0800726 // TODO: add src/dst port labels etc.
727 });
Thomas Vachuska4830d392014-11-09 17:09:56 -0800728
729 // operate on both existing and new links, if necessary
730 //link .foo() .bar() ...
731
732 // operate on exiting links:
Thomas Vachuska4830d392014-11-09 17:09:56 -0800733 link.exit()
Thomas Vachuska4830d392014-11-09 17:09:56 -0800734 .attr({
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800735 'stroke-dasharray': '3, 3'
Thomas Vachuska4830d392014-11-09 17:09:56 -0800736 })
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800737 .style('opacity', 0.4)
738 .transition()
Simon Huntea80eb42014-11-11 13:46:57 -0800739 .duration(1500)
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800740 .attr({
741 'stroke-dasharray': '3, 12'
742 })
743 .transition()
Simon Huntea80eb42014-11-11 13:46:57 -0800744 .duration(500)
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800745 .style('opacity', 0.0)
Thomas Vachuska4830d392014-11-09 17:09:56 -0800746 .remove();
Simon Hunt99c13842014-11-06 18:23:12 -0800747 }
748
749 function createDeviceNode(device) {
750 // start with the object as is
751 var node = device,
Simon Huntbb282f52014-11-10 11:08:19 -0800752 type = device.type,
753 svgCls = type ? 'node device ' + type : 'node device';
Simon Hunt99c13842014-11-06 18:23:12 -0800754
755 // Augment as needed...
756 node.class = 'device';
Simon Huntbb282f52014-11-10 11:08:19 -0800757 node.svgClass = device.online ? svgCls + ' online' : svgCls;
Simon Hunt99c13842014-11-06 18:23:12 -0800758 positionNode(node);
759
760 // cache label array length
761 network.deviceLabelCount = device.labels.length;
Simon Hunt99c13842014-11-06 18:23:12 -0800762 return node;
763 }
764
Simon Hunt56d51852014-11-09 13:03:35 -0800765 function createHostNode(host) {
766 // start with the object as is
767 var node = host;
768
769 // Augment as needed...
770 node.class = 'host';
Simon Hunt7cd48f32014-11-09 23:42:50 -0800771 if (!node.type) {
772 // TODO: perhaps type would be: {phone, tablet, laptop, endstation} ?
773 node.type = 'endstation';
774 }
Simon Hunt56d51852014-11-09 13:03:35 -0800775 node.svgClass = 'node host';
776 // TODO: consider placing near its switch, if [x,y] not defined
777 positionNode(node);
778
779 // cache label array length
780 network.hostLabelCount = host.labels.length;
Simon Hunt56d51852014-11-09 13:03:35 -0800781 return node;
782 }
783
Simon Hunt99c13842014-11-06 18:23:12 -0800784 function positionNode(node) {
785 var meta = node.metaUi,
Simon Huntac9e24f2014-11-12 10:12:21 -0800786 x = meta && meta.x,
787 y = meta && meta.y,
788 xy;
Simon Hunt99c13842014-11-06 18:23:12 -0800789
Simon Huntac9e24f2014-11-12 10:12:21 -0800790 // If we have [x,y] already, use that...
Simon Hunt99c13842014-11-06 18:23:12 -0800791 if (x && y) {
792 node.fixed = true;
Simon Huntac9e24f2014-11-12 10:12:21 -0800793 node.x = x;
794 node.y = y;
795 return;
Simon Hunt99c13842014-11-06 18:23:12 -0800796 }
Simon Huntac9e24f2014-11-12 10:12:21 -0800797
Paul Greyson6cb8ca02014-11-12 18:09:02 -0800798 var location = node.location;
799 if (location && location.type === 'latlng') {
800 var coord = geoMapProjection([location.lng, location.lat]);
801 node.fixed = true;
802 node.x = coord[0];
803 node.y = coord[1];
804 return;
805 }
806
Simon Huntac9e24f2014-11-12 10:12:21 -0800807 // Note: Placing incoming unpinned nodes at exactly the same point
808 // (center of the view) causes them to explode outwards when
809 // the force layout kicks in. So, we spread them out a bit
810 // initially, to provide a more serene layout convergence.
811 // Additionally, if the node is a host, we place it near
812 // the device it is connected to.
813
814 function spread(s) {
815 return Math.floor((Math.random() * s) - s/2);
816 }
817
818 function randDim(dim) {
819 return dim / 2 + spread(dim * 0.7071);
820 }
821
822 function rand() {
823 return {
824 x: randDim(network.view.width()),
825 y: randDim(network.view.height())
826 };
827 }
828
829 function near(node) {
830 var min = 12,
831 dx = spread(12),
832 dy = spread(12);
833 return {
834 x: node.x + min + dx,
835 y: node.y + min + dy
836 };
837 }
838
839 function getDevice(cp) {
840 var d = network.lookup[cp.device];
841 return d || rand();
842 }
843
844 xy = (node.class === 'host') ? near(getDevice(node.cp)) : rand();
845 $.extend(node, xy);
Simon Hunt99c13842014-11-06 18:23:12 -0800846 }
847
Simon Hunt99c13842014-11-06 18:23:12 -0800848 function iconUrl(d) {
849 return 'img/' + d.type + '.png';
850 }
851
852 // returns the newly computed bounding box of the rectangle
853 function adjustRectToFitText(n) {
854 var text = n.select('text'),
855 box = text.node().getBBox(),
856 lab = config.labels;
857
858 text.attr('text-anchor', 'middle')
859 .attr('y', '-0.8em')
860 .attr('x', lab.imgPad/2);
861
862 // translate the bbox so that it is centered on [x,y]
863 box.x = -box.width / 2;
864 box.y = -box.height / 2;
865
866 // add padding
867 box.x -= (lab.padLR + lab.imgPad/2);
868 box.width += lab.padLR * 2 + lab.imgPad;
869 box.y -= lab.padTB;
870 box.height += lab.padTB * 2;
871
872 return box;
873 }
874
Simon Hunt1a9eff92014-11-07 11:06:34 -0800875 function mkSvgClass(d) {
876 return d.fixed ? d.svgClass + ' fixed' : d.svgClass;
877 }
878
Simon Hunt7cd48f32014-11-09 23:42:50 -0800879 function hostLabel(d) {
880 var idx = (hostLabelIndex < d.labels.length) ? hostLabelIndex : 0;
881 return d.labels[idx];
882 }
883 function deviceLabel(d) {
884 var idx = (deviceLabelIndex < d.labels.length) ? deviceLabelIndex : 0;
885 return d.labels[idx];
886 }
887 function niceLabel(label) {
888 return (label && label.trim()) ? label : '.';
889 }
890
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800891 function updateDeviceLabel(d) {
892 var label = niceLabel(deviceLabel(d)),
893 node = d.el,
894 box;
895
896 node.select('text')
897 .text(label)
898 .style('opacity', 0)
899 .transition()
900 .style('opacity', 1);
901
902 box = adjustRectToFitText(node);
903
904 node.select('rect')
905 .transition()
906 .attr(box);
907
908 node.select('image')
909 .transition()
910 .attr('x', box.x + config.icons.xoff)
911 .attr('y', box.y + config.icons.yoff);
912 }
913
914 function updateHostLabel(d) {
915 var label = hostLabel(d),
916 host = d.el;
917
918 host.select('text').text(label);
919 }
920
Simon Huntbb282f52014-11-10 11:08:19 -0800921 function updateDeviceState(nodeData) {
922 nodeData.el.classed('online', nodeData.online);
923 updateDeviceLabel(nodeData);
924 // TODO: review what else might need to be updated
925 }
926
Simon Hunt3f03d4a2014-11-10 20:14:37 -0800927 function updateLinkState(linkData) {
928 updateLinkWidth(linkData);
929 // TODO: review what else might need to be updated
930 // update label, if showing
931 }
932
Simon Huntbb282f52014-11-10 11:08:19 -0800933 function updateHostState(hostData) {
934 updateHostLabel(hostData);
935 // TODO: review what else might need to be updated
936 }
937
Simon Hunt6ac93f32014-11-13 12:17:27 -0800938 function nodeMouseOver(d) {
939 console.log("Hover:", d);
940 hovered = d;
941 if (d.class === 'host') {
942 //requestTraffic(d);
943 }
944 }
945
946 function nodeMouseOut(d) {
947 console.log("Unhover:", d);
948 hovered = null;
949 if (d.class === 'host') {
950 //cancelTraffic(d);
951 }
952 }
Simon Huntbb282f52014-11-10 11:08:19 -0800953
Simon Hunt99c13842014-11-06 18:23:12 -0800954 function updateNodes() {
955 node = nodeG.selectAll('.node')
956 .data(network.nodes, function (d) { return d.id; });
957
958 // operate on existing nodes, if necessary
Simon Hunt7cd48f32014-11-09 23:42:50 -0800959 // update host labels
Simon Hunt99c13842014-11-06 18:23:12 -0800960 //node .foo() .bar() ...
961
962 // operate on entering nodes:
963 var entering = node.enter()
964 .append('g')
965 .attr({
966 id: function (d) { return safeId(d.id); },
Simon Hunt1a9eff92014-11-07 11:06:34 -0800967 class: mkSvgClass,
Simon Hunt99c13842014-11-06 18:23:12 -0800968 transform: function (d) { return translate(d.x, d.y); },
969 opacity: 0
970 })
Simon Hunt1a9eff92014-11-07 11:06:34 -0800971 .call(network.drag)
Simon Hunt6ac93f32014-11-13 12:17:27 -0800972 .on('mouseover', nodeMouseOver)
973 .on('mouseout', nodeMouseOut)
Simon Hunt99c13842014-11-06 18:23:12 -0800974 .transition()
975 .attr('opacity', 1);
976
977 // augment device nodes...
978 entering.filter('.device').each(function (d) {
979 var node = d3.select(this),
980 icon = iconUrl(d),
Simon Hunt7cd48f32014-11-09 23:42:50 -0800981 label = niceLabel(deviceLabel(d)),
Simon Hunt99c13842014-11-06 18:23:12 -0800982 box;
983
Simon Hunt7cd48f32014-11-09 23:42:50 -0800984 // provide ref to element from backing data....
985 d.el = node;
986
Simon Hunt99c13842014-11-06 18:23:12 -0800987 node.append('rect')
988 .attr({
989 'rx': 5,
990 'ry': 5
991 });
992
993 node.append('text')
Simon Hunt7cd48f32014-11-09 23:42:50 -0800994 .text(label)
Simon Hunt99c13842014-11-06 18:23:12 -0800995 .attr('dy', '1.1em');
996
997 box = adjustRectToFitText(node);
998
999 node.select('rect')
1000 .attr(box);
1001
1002 if (icon) {
1003 var cfg = config.icons;
1004 node.append('svg:image')
1005 .attr({
1006 x: box.x + config.icons.xoff,
1007 y: box.y + config.icons.yoff,
1008 width: cfg.w,
1009 height: cfg.h,
1010 'xlink:href': icon
1011 });
1012 }
1013
1014 // debug function to show the modelled x,y coordinates of nodes...
1015 if (debug('showNodeXY')) {
1016 node.select('rect').attr('fill-opacity', 0.5);
1017 node.append('circle')
1018 .attr({
1019 class: 'debug',
1020 cx: 0,
1021 cy: 0,
1022 r: '3px'
1023 });
Simon Huntc7ee0662014-11-05 16:44:37 -08001024 }
1025 });
Simon Hunt934c3ce2014-11-05 11:45:07 -08001026
Simon Hunt56d51852014-11-09 13:03:35 -08001027 // augment host nodes...
1028 entering.filter('.host').each(function (d) {
1029 var node = d3.select(this),
Simon Hunt56d51852014-11-09 13:03:35 -08001030 box;
1031
Simon Hunt7cd48f32014-11-09 23:42:50 -08001032 // provide ref to element from backing data....
1033 d.el = node;
1034
Simon Hunt56d51852014-11-09 13:03:35 -08001035 node.append('circle')
1036 .attr('r', 8); // TODO: define host circle radius
1037
1038 // TODO: are we attaching labels to hosts?
1039 node.append('text')
Simon Hunt7cd48f32014-11-09 23:42:50 -08001040 .text(hostLabel)
1041 .attr('dy', '1.3em')
1042 .attr('text-anchor', 'middle');
Simon Hunt56d51852014-11-09 13:03:35 -08001043
1044 // debug function to show the modelled x,y coordinates of nodes...
1045 if (debug('showNodeXY')) {
1046 node.select('circle').attr('fill-opacity', 0.5);
1047 node.append('circle')
1048 .attr({
1049 class: 'debug',
1050 cx: 0,
1051 cy: 0,
1052 r: '3px'
1053 });
1054 }
1055 });
Simon Huntc7ee0662014-11-05 16:44:37 -08001056
Simon Hunt99c13842014-11-06 18:23:12 -08001057 // operate on both existing and new nodes, if necessary
1058 //node .foo() .bar() ...
Simon Huntc7ee0662014-11-05 16:44:37 -08001059
Simon Hunt99c13842014-11-06 18:23:12 -08001060 // operate on exiting nodes:
Simon Huntea80eb42014-11-11 13:46:57 -08001061 // Note that the node is removed after 2 seconds.
1062 // Sub element animations should be shorter than 2 seconds.
1063 var exiting = node.exit()
Simon Hunt44031102014-11-11 13:20:36 -08001064 .transition()
1065 .duration(2000)
Simon Huntea80eb42014-11-11 13:46:57 -08001066 .style('opacity', 0)
Simon Hunt99c13842014-11-06 18:23:12 -08001067 .remove();
Simon Huntea80eb42014-11-11 13:46:57 -08001068
1069 // host node exits....
1070 exiting.filter('.host').each(function (d) {
1071 var node = d3.select(this);
1072
1073 node.select('text')
1074 .style('opacity', 0.5)
1075 .transition()
1076 .duration(1000)
1077 .style('opacity', 0);
1078 // note, leave <g>.remove to remove this element
1079
1080 node.select('circle')
1081 .style('stroke-fill', '#555')
1082 .style('fill', '#888')
1083 .style('opacity', 0.5)
1084 .transition()
1085 .duration(1500)
1086 .attr('r', 0);
1087 // note, leave <g>.remove to remove this element
1088
1089 });
1090
1091 // TODO: device node exits
Simon Huntc7ee0662014-11-05 16:44:37 -08001092 }
1093
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001094 function find(id, array) {
1095 for (var idx = 0, n = array.length; idx < n; idx++) {
1096 if (array[idx].id === id) {
1097 return idx;
1098 }
1099 }
1100 return -1;
1101 }
1102
1103 function removeLinkElement(linkData) {
1104 // remove from lookup cache
1105 delete network.lookup[linkData.id];
1106 // remove from links array
1107 var idx = find(linkData.id, network.links);
Simon Huntfc274c92014-11-11 11:05:46 -08001108 network.links.splice(idx, 1);
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001109 // remove from SVG
1110 updateLinks();
Simon Hunt44031102014-11-11 13:20:36 -08001111 network.force.resume();
Simon Hunt3f03d4a2014-11-10 20:14:37 -08001112 }
Simon Huntc7ee0662014-11-05 16:44:37 -08001113
Simon Hunt44031102014-11-11 13:20:36 -08001114 function removeHostElement(hostData) {
1115 // first, remove associated hostLink...
1116 removeLinkElement(hostData.linkData);
1117
1118 // remove from lookup cache
1119 delete network.lookup[hostData.id];
1120 // remove from nodes array
1121 var idx = find(hostData.id, network.nodes);
1122 network.nodes.splice(idx, 1);
1123 // remove from SVG
1124 updateNodes();
1125 network.force.resume();
1126 }
1127
1128
Simon Huntc7ee0662014-11-05 16:44:37 -08001129 function tick() {
1130 node.attr({
Simon Hunt99c13842014-11-06 18:23:12 -08001131 transform: function (d) { return translate(d.x, d.y); }
Simon Huntc7ee0662014-11-05 16:44:37 -08001132 });
1133
1134 link.attr({
1135 x1: function (d) { return d.source.x; },
1136 y1: function (d) { return d.source.y; },
1137 x2: function (d) { return d.target.x; },
1138 y2: function (d) { return d.target.y; }
1139 });
1140 }
Simon Hunt934c3ce2014-11-05 11:45:07 -08001141
1142 // ==============================
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001143 // Web-Socket for live data
1144
1145 function webSockUrl() {
1146 return document.location.toString()
1147 .replace(/\#.*/, '')
1148 .replace('http://', 'ws://')
1149 .replace('https://', 'wss://')
1150 .replace('index2.html', config.webSockUrl);
1151 }
1152
1153 webSock = {
1154 ws : null,
1155
1156 connect : function() {
1157 webSock.ws = new WebSocket(webSockUrl());
1158
1159 webSock.ws.onopen = function() {
Simon Hunt0c6d4192014-11-12 12:07:10 -08001160 noWebSock(false);
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001161 };
1162
1163 webSock.ws.onmessage = function(m) {
1164 if (m.data) {
Simon Huntbb282f52014-11-10 11:08:19 -08001165 wsTraceRx(m.data);
Thomas Vachuskad472c6e2014-11-07 19:11:05 -08001166 handleServerEvent(JSON.parse(m.data));
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001167 }
1168 };
1169
1170 webSock.ws.onclose = function(m) {
1171 webSock.ws = null;
Simon Hunt0c6d4192014-11-12 12:07:10 -08001172 noWebSock(true);
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001173 };
1174 },
1175
1176 send : function(text) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001177 if (text != null) {
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001178 webSock._send(text);
1179 }
1180 },
1181
1182 _send : function(message) {
1183 if (webSock.ws) {
1184 webSock.ws.send(message);
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001185 } else {
Simon Hunt56d51852014-11-09 13:03:35 -08001186 network.view.alert('no web socket open\n\n' + message);
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001187 }
1188 }
1189
1190 };
1191
Simon Hunt0c6d4192014-11-12 12:07:10 -08001192 function noWebSock(b) {
1193 mask.style('display',b ? 'block' : 'none');
1194 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001195
Simon Hunt61d04042014-11-11 17:27:16 -08001196 // TODO: use cache of pending messages (key = sid) to reconcile responses
1197
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001198 function sendMessage(evType, payload) {
1199 var toSend = {
Simon Huntbb282f52014-11-10 11:08:19 -08001200 event: evType,
1201 sid: ++sid,
1202 payload: payload
1203 },
1204 asText = JSON.stringify(toSend);
1205 wsTraceTx(asText);
1206 webSock.send(asText);
1207 }
1208
1209 function wsTraceTx(msg) {
1210 wsTrace('tx', msg);
1211 }
1212 function wsTraceRx(msg) {
1213 wsTrace('rx', msg);
1214 }
1215 function wsTrace(rxtx, msg) {
Simon Huntbb282f52014-11-10 11:08:19 -08001216 console.log('[' + rxtx + '] ' + msg);
1217 // TODO: integrate with trace view
1218 //if (trace) {
1219 // trace.output(rxtx, msg);
1220 //}
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001221 }
1222
1223
1224 // ==============================
1225 // Selection stuff
1226
1227 function selectObject(obj, el) {
1228 var n,
1229 meta = d3.event.sourceEvent.metaKey;
1230
1231 if (el) {
1232 n = d3.select(el);
1233 } else {
1234 node.each(function(d) {
1235 if (d == obj) {
1236 n = d3.select(el = this);
1237 }
1238 });
1239 }
1240 if (!n) return;
1241
1242 if (meta && n.classed('selected')) {
1243 deselectObject(obj.id);
Simon Hunt61d04042014-11-11 17:27:16 -08001244 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001245 return;
1246 }
1247
1248 if (!meta) {
1249 deselectAll();
1250 }
1251
Simon Huntc31d5692014-11-12 13:27:18 -08001252 selections[obj.id] = { obj: obj, el: el };
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001253 selectOrder.push(obj.id);
1254
1255 n.classed('selected', true);
Simon Hunt61d04042014-11-11 17:27:16 -08001256 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001257 }
1258
1259 function deselectObject(id) {
Simon Huntc31d5692014-11-12 13:27:18 -08001260 var obj = selections[id],
1261 idx;
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001262 if (obj) {
1263 d3.select(obj.el).classed('selected', false);
Simon Hunt61d04042014-11-11 17:27:16 -08001264 delete selections[id];
Simon Huntc31d5692014-11-12 13:27:18 -08001265 idx = $.inArray(id, selectOrder);
1266 if (idx >= 0) {
1267 selectOrder.splice(idx, 1);
1268 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001269 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001270 }
1271
1272 function deselectAll() {
1273 // deselect all nodes in the network...
1274 node.classed('selected', false);
1275 selections = {};
1276 selectOrder = [];
Simon Hunt61d04042014-11-11 17:27:16 -08001277 updateDetailPane();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001278 }
1279
Simon Hunt61d04042014-11-11 17:27:16 -08001280 // FIXME: this click handler does not get unloaded when the view does
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001281 $('#view').on('click', function(e) {
1282 if (!$(e.target).closest('.node').length) {
1283 if (!e.metaKey) {
1284 deselectAll();
1285 }
1286 }
1287 });
1288
Simon Hunt61d04042014-11-11 17:27:16 -08001289 // update the state of the detail pane, based on current selections
1290 function updateDetailPane() {
1291 var nSel = selectOrder.length;
1292 if (!nSel) {
1293 detailPane.hide();
1294 } else if (nSel === 1) {
1295 singleSelect();
1296 } else {
1297 multiSelect();
1298 }
1299 }
1300
1301 function singleSelect() {
1302 requestDetails();
Simon Huntb53e0682014-11-12 13:32:01 -08001303 // NOTE: detail pane will be shown from showDetails event callback
Simon Hunt61d04042014-11-11 17:27:16 -08001304 }
1305
1306 function multiSelect() {
Simon Huntb53e0682014-11-12 13:32:01 -08001307 populateMultiSelect();
1308 // TODO: Add multi-select actions ...
1309 }
1310
1311 function addSep(tbody) {
1312 var tr = tbody.append('tr');
1313 $('<hr>').appendTo(tr.append('td').attr('colspan', 2));
1314 }
1315
1316 function addProp(tbody, label, value) {
1317 var tr = tbody.append('tr');
1318
1319 tr.append('td')
1320 .attr('class', 'label')
1321 .text(label + ' :');
1322
1323 tr.append('td')
1324 .attr('class', 'value')
1325 .text(value);
1326 }
1327
1328 function populateMultiSelect() {
1329 detailPane.empty();
1330
1331 var title = detailPane.append("h2"),
1332 table = detailPane.append("table"),
1333 tbody = table.append("tbody");
1334
1335 title.text('Multi-Select...');
1336
1337 selectOrder.forEach(function (d, i) {
1338 addProp(tbody, i+1, d);
1339 });
Simon Hunt61d04042014-11-11 17:27:16 -08001340 }
1341
1342 function populateDetails(data) {
1343 detailPane.empty();
1344
1345 var title = detailPane.append("h2"),
1346 table = detailPane.append("table"),
1347 tbody = table.append("tbody");
1348
1349 $('<img src="img/' + data.type + '.png">').appendTo(title);
1350 $('<span>').attr('class', 'icon').text(data.id).appendTo(title);
1351
1352 data.propOrder.forEach(function(p) {
1353 if (p === '-') {
1354 addSep(tbody);
1355 } else {
1356 addProp(tbody, p, data.props[p]);
1357 }
1358 });
Simon Hunt61d04042014-11-11 17:27:16 -08001359 }
1360
1361 // ==============================
1362 // Test harness code
Simon Hunt56d51852014-11-09 13:03:35 -08001363
1364 function prepareScenario(view, ctx, dbg) {
1365 var sc = scenario,
1366 urlSc = sc.evDir + ctx + sc.evScenario;
1367
1368 if (!ctx) {
1369 view.alert("No scenario specified (null ctx)");
1370 return;
1371 }
1372
1373 sc.view = view;
1374 sc.ctx = ctx;
1375 sc.debug = dbg;
1376 sc.evNumber = 0;
1377
1378 d3.json(urlSc, function(err, data) {
Simon Huntbb282f52014-11-10 11:08:19 -08001379 var p = data && data.params || {},
1380 desc = data && data.description || null,
Simon Huntfc274c92014-11-11 11:05:46 -08001381 intro = data && data.title;
Simon Huntbb282f52014-11-10 11:08:19 -08001382
Simon Hunt56d51852014-11-09 13:03:35 -08001383 if (err) {
1384 view.alert('No scenario found:\n\n' + urlSc + '\n\n' + err);
1385 } else {
1386 sc.params = p;
Simon Huntbb282f52014-11-10 11:08:19 -08001387 if (desc) {
1388 intro += '\n\n ' + desc.join('\n ');
1389 }
1390 view.alert(intro);
Simon Hunt56d51852014-11-09 13:03:35 -08001391 }
1392 });
1393
1394 }
1395
Simon Hunt0c6d4192014-11-12 12:07:10 -08001396 function para(sel, text) {
1397 sel.append('p').text(text);
1398 }
1399
Simon Huntf8e5b4e02014-11-13 11:17:57 -08001400 // TODO: toggle button (and other widgets in the masthead) should be provided
1401 // by the framework; not generated by the view.
1402
1403 var showTrafficOnHover;
1404
1405 function addButtonBar(view) {
1406 var bb = d3.select('#mast')
1407 .append('span').classed('right', true).attr('id', 'bb');
1408
1409 showTrafficOnHover = bb.append('div')
1410 .classed('btn', true)
1411 .text('Show traffic on hover')
1412 .on('click', toggleShowTraffic);
1413 }
1414
1415 function toggleShowTraffic() {
1416 showTrafficOnHover.classed('active', !trafficHover());
1417 }
1418
1419 function trafficHover() {
1420 return showTrafficOnHover.classed('active');
1421 }
1422
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001423 // ==============================
Simon Hunt142d0032014-11-04 20:13:09 -08001424 // View life-cycle callbacks
Simon Hunt195cb382014-11-03 17:50:51 -08001425
Simon Huntf67722a2014-11-10 09:32:06 -08001426 function preload(view, ctx, flags) {
Simon Hunt142d0032014-11-04 20:13:09 -08001427 var w = view.width(),
1428 h = view.height(),
Simon Huntc7ee0662014-11-05 16:44:37 -08001429 fcfg = config.force,
1430 fpad = fcfg.pad,
1431 forceDim = [w - 2*fpad, h - 2*fpad];
Simon Hunt195cb382014-11-03 17:50:51 -08001432
Simon Huntbb282f52014-11-10 11:08:19 -08001433 // TODO: set trace api
1434 //trace = onos.exported.webSockTrace;
1435
Simon Hunt142d0032014-11-04 20:13:09 -08001436 // NOTE: view.$div is a D3 selection of the view's div
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001437 var viewBox = '0 0 ' + config.logicalSize + ' ' + config.logicalSize;
1438 svg = view.$div.append('svg').attr('viewBox', viewBox);
Simon Hunt934c3ce2014-11-05 11:45:07 -08001439 setSize(svg, view);
1440
Simon Hunt1a9eff92014-11-07 11:06:34 -08001441 // add blue glow filter to svg layer
1442 d3u.appendGlow(svg);
1443
Simon Huntc7ee0662014-11-05 16:44:37 -08001444 // group for the topology
1445 topoG = svg.append('g')
Simon Huntd3b7d512014-11-12 15:48:41 -08001446 .attr('id', 'topo-G')
Simon Huntc7ee0662014-11-05 16:44:37 -08001447 .attr('transform', fcfg.translate());
1448
1449 // subgroups for links and nodes
1450 linkG = topoG.append('g').attr('id', 'links');
1451 nodeG = topoG.append('g').attr('id', 'nodes');
1452
1453 // selection of nodes and links
1454 link = linkG.selectAll('.link');
1455 node = nodeG.selectAll('.node');
1456
Simon Hunt7cd48f32014-11-09 23:42:50 -08001457 function chrg(d) {
1458 return fcfg.charge[d.class] || -12000;
1459 }
Simon Hunt99c13842014-11-06 18:23:12 -08001460 function ldist(d) {
Simon Hunt7cd48f32014-11-09 23:42:50 -08001461 return fcfg.linkDistance[d.type] || 50;
Simon Hunt99c13842014-11-06 18:23:12 -08001462 }
1463 function lstrg(d) {
Simon Hunt7cd48f32014-11-09 23:42:50 -08001464 // 0.0 - 1.0
1465 return fcfg.linkStrength[d.type] || 1.0;
Simon Hunt99c13842014-11-06 18:23:12 -08001466 }
1467
Simon Hunt1a9eff92014-11-07 11:06:34 -08001468 function selectCb(d, self) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001469 selectObject(d, self);
Simon Hunt1a9eff92014-11-07 11:06:34 -08001470 }
1471
1472 function atDragEnd(d, self) {
Simon Hunt56d51852014-11-09 13:03:35 -08001473 // once we've finished moving, pin the node in position
1474 d.fixed = true;
1475 d3.select(self).classed('fixed', true);
1476 if (config.useLiveData) {
Simon Hunt902c9922014-11-11 11:59:31 -08001477 sendUpdateMeta(d);
Simon Hunt1a9eff92014-11-07 11:06:34 -08001478 }
1479 }
1480
Simon Hunt902c9922014-11-11 11:59:31 -08001481 function sendUpdateMeta(d) {
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001482 sendMessage('updateMeta', {
1483 id: d.id,
1484 'class': d.class,
Simon Hunt902c9922014-11-11 11:59:31 -08001485 'memento': {
1486 x: Math.floor(d.x),
1487 y: Math.floor(d.y)
1488 }
Thomas Vachuskad1be50d2014-11-08 16:10:20 -08001489 });
1490 }
1491
Simon Huntc7ee0662014-11-05 16:44:37 -08001492 // set up the force layout
1493 network.force = d3.layout.force()
1494 .size(forceDim)
1495 .nodes(network.nodes)
1496 .links(network.links)
Simon Hunt7cd48f32014-11-09 23:42:50 -08001497 .gravity(0.4)
1498 .friction(0.7)
1499 .charge(chrg)
Simon Hunt99c13842014-11-06 18:23:12 -08001500 .linkDistance(ldist)
1501 .linkStrength(lstrg)
Simon Huntc7ee0662014-11-05 16:44:37 -08001502 .on('tick', tick);
Simon Hunt195cb382014-11-03 17:50:51 -08001503
Simon Hunt1a9eff92014-11-07 11:06:34 -08001504 network.drag = d3u.createDragBehavior(network.force, selectCb, atDragEnd);
Simon Hunt0c6d4192014-11-12 12:07:10 -08001505
1506 // create mask layer for when we lose connection to server.
1507 mask = view.$div.append('div').attr('id','topo-mask');
1508 para(mask, 'Oops!');
1509 para(mask, 'Web-socket connection to server closed...');
1510 para(mask, 'Try refreshing the page.');
Simon Hunt1a9eff92014-11-07 11:06:34 -08001511 }
Simon Hunt195cb382014-11-03 17:50:51 -08001512
Simon Hunt56d51852014-11-09 13:03:35 -08001513 function load(view, ctx, flags) {
Simon Huntf67722a2014-11-10 09:32:06 -08001514 // resize, in case the window was resized while we were not loaded
1515 resize(view, ctx, flags);
1516
Simon Hunt99c13842014-11-06 18:23:12 -08001517 // cache the view token, so network topo functions can access it
1518 network.view = view;
Simon Hunt56d51852014-11-09 13:03:35 -08001519 config.useLiveData = !flags.local;
1520
1521 if (!config.useLiveData) {
1522 prepareScenario(view, ctx, flags.debug);
1523 }
Simon Hunt99c13842014-11-06 18:23:12 -08001524
1525 // set our radio buttons and key bindings
Simon Hunt934c3ce2014-11-05 11:45:07 -08001526 view.setRadio(btnSet);
1527 view.setKeys(keyDispatch);
Simon Hunt195cb382014-11-03 17:50:51 -08001528
Simon Huntf8e5b4e02014-11-13 11:17:57 -08001529 // patch in our "button bar" for now
1530 // TODO: implement a more official frameworky way of doing this..
1531 addButtonBar(view);
1532
Simon Huntd3b7d512014-11-12 15:48:41 -08001533 // Load map data asynchronously; complete startup after that..
1534 loadGeoJsonData();
1535 }
1536
1537 // TODO: move these to config/state portion of script
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001538 var geoJsonUrl = 'json/map/continental_us.json', // TODO: Paul
Simon Huntd3b7d512014-11-12 15:48:41 -08001539 geoJson;
1540
1541 function loadGeoJsonData() {
1542 d3.json(geoJsonUrl, function (err, data) {
1543 if (err) {
1544 // fall back to USA map background
1545 loadStaticMap();
1546 } else {
1547 geoJson = data;
1548 loadGeoMap();
1549 }
1550
1551 // finally, connect to the server...
1552 if (config.useLiveData) {
1553 webSock.connect();
1554 }
1555 });
1556 }
1557
1558 function showBg() {
1559 return config.options.showBackground ? 'visible' : 'hidden';
1560 }
1561
1562 function loadStaticMap() {
1563 fnTrace('loadStaticMap', config.backgroundUrl);
1564 var w = network.view.width(),
1565 h = network.view.height();
1566
1567 // load the background image
1568 bgImg = svg.insert('svg:image', '#topo-G')
1569 .attr({
1570 id: 'topo-bg',
1571 width: w,
1572 height: h,
1573 'xlink:href': config.backgroundUrl
1574 })
1575 .style({
1576 visibility: showBg()
1577 });
1578 }
1579
1580 function loadGeoMap() {
1581 fnTrace('loadGeoMap', geoJsonUrl);
Simon Huntd3b7d512014-11-12 15:48:41 -08001582
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001583 // extracts the topojson data into geocoordinate-based geometry
1584 var topoData = topojson.feature(geoJson, geoJson.objects.states);
Simon Huntd3b7d512014-11-12 15:48:41 -08001585
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001586 // see: http://bl.ocks.org/mbostock/4707858
1587 geoMapProjection = d3.geo.mercator();
1588 var path = d3.geo.path().projection(geoMapProjection);
Simon Huntd3b7d512014-11-12 15:48:41 -08001589
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001590 geoMapProjection
1591 .scale(1)
1592 .translate([0, 0]);
Simon Huntd3b7d512014-11-12 15:48:41 -08001593
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001594 // [[x1,y1],[x2,y2]]
1595 var b = path.bounds(topoData);
1596 // TODO: why 1.75?
1597 var s = 1.75 / Math.max((b[1][0] - b[0][0]) / config.logicalSize, (b[1][1] - b[0][1]) / config.logicalSize);
1598 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 -08001599
Paul Greyson6cb8ca02014-11-12 18:09:02 -08001600 geoMapProjection
1601 .scale(s)
1602 .translate(t);
1603
1604 bgImg = svg.insert("g", '#topo-G');
1605 bgImg.attr('id', 'map').selectAll('path')
1606 .data(topoData.features)
1607 .enter()
1608 .append('path')
1609 .attr('d', path);
Simon Hunt195cb382014-11-03 17:50:51 -08001610 }
1611
Simon Huntf67722a2014-11-10 09:32:06 -08001612 function resize(view, ctx, flags) {
Simon Hunt934c3ce2014-11-05 11:45:07 -08001613 setSize(svg, view);
Simon Hunt99c13842014-11-06 18:23:12 -08001614
1615 // TODO: hook to recompute layout, perhaps? work with zoom/pan code
1616 // adjust force layout size
Simon Hunt142d0032014-11-04 20:13:09 -08001617 }
1618
1619
1620 // ==============================
1621 // View registration
Simon Hunt195cb382014-11-03 17:50:51 -08001622
Simon Hunt25248912014-11-04 11:25:48 -08001623 onos.ui.addView('topo', {
Simon Hunt142d0032014-11-04 20:13:09 -08001624 preload: preload,
1625 load: load,
1626 resize: resize
Simon Hunt195cb382014-11-03 17:50:51 -08001627 });
1628
Simon Hunt61d04042014-11-11 17:27:16 -08001629 detailPane = onos.ui.addFloatingPanel('topo-detail');
1630
Simon Hunt195cb382014-11-03 17:50:51 -08001631}(ONOS));