Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1 | /* |
| 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 Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 18 | ONOS network topology viewer - version 1.1 |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 19 | |
| 20 | @author Simon Hunt |
| 21 | */ |
| 22 | |
| 23 | (function (onos) { |
| 24 | 'use strict'; |
| 25 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 26 | // shorter names for library APIs |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 27 | var d3u = onos.lib.d3util, |
| 28 | trace; |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 29 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 30 | // configuration data |
| 31 | var config = { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 32 | useLiveData: true, |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 33 | fnTrace: true, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 34 | debugOn: false, |
| 35 | debug: { |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 36 | showNodeXY: true, |
| 37 | showKeyHandler: false |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 38 | }, |
| 39 | options: { |
| 40 | layering: true, |
| 41 | collisionPrevention: true, |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 42 | showBackground: true |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 43 | }, |
| 44 | backgroundUrl: 'img/us-map.png', |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 45 | webSockUrl: 'ws/topology', |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 46 | 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 Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 58 | 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 Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 70 | topo: { |
| 71 | linkInColor: '#66f', |
| 72 | linkInWidth: 14 |
| 73 | }, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 74 | icons: { |
| 75 | w: 28, |
| 76 | h: 28, |
| 77 | xoff: -12, |
| 78 | yoff: -8 |
| 79 | }, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 80 | iconUrl: { |
| 81 | device: 'img/device.png', |
| 82 | host: 'img/host.png', |
| 83 | pkt: 'img/pkt.png', |
| 84 | opt: 'img/opt.png' |
| 85 | }, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 86 | force: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 87 | note_for_links: 'link.type is used to differentiate', |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 88 | linkDistance: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 89 | direct: 100, |
| 90 | optical: 120, |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 91 | hostLink: 3 |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 92 | }, |
| 93 | linkStrength: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 94 | direct: 1.0, |
| 95 | optical: 1.0, |
| 96 | hostLink: 1.0 |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 97 | }, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 98 | note_for_nodes: 'node.class is used to differentiate', |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 99 | charge: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 100 | device: -8000, |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 101 | host: -5000 |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 102 | }, |
| 103 | pad: 20, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 104 | translate: function() { |
| 105 | return 'translate(' + |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 106 | config.force.pad + ',' + |
| 107 | config.force.pad + ')'; |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 108 | } |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 109 | }, |
| 110 | // see below in creation of viewBox on main svg |
| 111 | logicalSize: 1000 |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 114 | // radio buttons |
| 115 | var btnSet = [ |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 116 | { 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 Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 123 | M: testMe, // TODO: remove (testing only) |
| 124 | S: injectStartupEvents, // TODO: remove (testing only) |
| 125 | space: injectTestEvent, // TODO: remove (testing only) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 126 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 127 | B: toggleBg, |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 128 | L: cycleLabels, |
| 129 | P: togglePorts, |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 130 | U: unpin, |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 131 | R: resetZoomPan, |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 132 | esc: deselectAll |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 133 | }; |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 134 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 135 | // state variables |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 136 | var network = { |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 137 | view: null, // view token reference |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 138 | nodes: [], |
| 139 | links: [], |
| 140 | lookup: {} |
| 141 | }, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 142 | scenario = { |
| 143 | evDir: 'json/ev/', |
| 144 | evScenario: '/scenario.json', |
| 145 | evPrefix: '/ev_', |
| 146 | evOnos: '_onos.json', |
| 147 | evUi: '_ui.json', |
| 148 | ctx: null, |
| 149 | params: {}, |
| 150 | evNumber: 0, |
| 151 | view: null, |
| 152 | debug: false |
| 153 | }, |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 154 | webSock, |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 155 | sid = 0, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 156 | deviceLabelIndex = 0, |
| 157 | hostLabelIndex = 0, |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 158 | selections = {}, |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 159 | selectOrder = [], |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 160 | hovered = null, |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 161 | detailPane, |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 162 | antTimer = null, |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 163 | onosInstances = {}, |
| 164 | onosOrder = [], |
| 165 | oiBox, |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 166 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 167 | viewMode = 'showAll', |
| 168 | portLabelsOn = false; |
| 169 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 170 | // D3 selections |
| 171 | var svg, |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 172 | zoomPanContainer, |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 173 | bgImg, |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 174 | topoG, |
| 175 | nodeG, |
| 176 | linkG, |
| 177 | node, |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 178 | link, |
| 179 | mask; |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 180 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 181 | // the projection for the map background |
| 182 | var geoMapProjection; |
| 183 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 184 | // the zoom function |
| 185 | var zoom; |
| 186 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 187 | // ============================== |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 188 | // For Debugging / Development |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 189 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 190 | function note(label, msg) { |
| 191 | console.log('NOTE: ' + label + ': ' + msg); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 194 | function debug(what) { |
| 195 | return config.debugOn && config.debug[what]; |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 198 | function fnTrace(msg, id) { |
| 199 | if (config.fnTrace) { |
| 200 | console.log('FN: ' + msg + ' [' + id + ']'); |
| 201 | } |
| 202 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 203 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 204 | function evTrace(data) { |
| 205 | fnTrace(data.event, data.payload.id); |
| 206 | } |
| 207 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 208 | // ============================== |
| 209 | // Key Callbacks |
| 210 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 211 | function testMe(view) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 212 | //view.alert('test'); |
| 213 | detailPane.show(); |
| 214 | setTimeout(detailPane.hide, 2000); |
| 215 | oiBox.show(); |
| 216 | setTimeout(oiBox.hide, 2000); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 219 | function abortIfLive() { |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 220 | if (config.useLiveData) { |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 221 | network.view.alert("Sorry, currently using live data.."); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 222 | return true; |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 223 | } |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 224 | return false; |
| 225 | } |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 226 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 227 | function testDebug(msg) { |
| 228 | if (scenario.debug) { |
| 229 | scenario.view.alert(msg); |
| 230 | } |
| 231 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 232 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 233 | function injectTestEvent(view) { |
| 234 | if (abortIfLive()) { return; } |
| 235 | var sc = scenario, |
| 236 | evn = ++sc.evNumber, |
| 237 | pfx = sc.evDir + sc.ctx + sc.evPrefix + evn, |
| 238 | onosUrl = pfx + sc.evOnos, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 239 | uiUrl = pfx + sc.evUi, |
| 240 | stack = [ |
| 241 | { url: onosUrl, cb: handleServerEvent }, |
| 242 | { url: uiUrl, cb: handleUiEvent } |
| 243 | ]; |
| 244 | recurseFetchEvent(stack, evn); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 247 | function recurseFetchEvent(stack, evn) { |
| 248 | var v = scenario.view, |
| 249 | frame; |
| 250 | if (stack.length === 0) { |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 251 | v.alert('Oops!\n\nNo event #' + evn + ' found.'); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 252 | return; |
| 253 | } |
| 254 | frame = stack.shift(); |
| 255 | |
| 256 | d3.json(frame.url, function (err, data) { |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 257 | if (err) { |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 258 | if (err.status === 404) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 259 | // if we didn't find the data, try the next stack frame |
| 260 | recurseFetchEvent(stack, evn); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 261 | } else { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 262 | v.alert('non-404 error:\n\n' + frame.url + '\n\n' + err); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 263 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 264 | } else { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 265 | testDebug('loaded: ' + frame.url); |
| 266 | frame.cb(data); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 267 | } |
| 268 | }); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 269 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 270 | } |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 271 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 272 | function handleUiEvent(data) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 273 | scenario.view.alert('UI Tx: ' + data.event + '\n\n' + |
| 274 | JSON.stringify(data)); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | function injectStartupEvents(view) { |
| 278 | var last = scenario.params.lastAuto || 0; |
| 279 | if (abortIfLive()) { return; } |
| 280 | |
| 281 | while (scenario.evNumber < last) { |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 282 | injectTestEvent(view); |
| 283 | } |
| 284 | } |
| 285 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 286 | function toggleBg() { |
| 287 | var vis = bgImg.style('visibility'); |
| 288 | bgImg.style('visibility', (vis === 'hidden') ? 'visible' : 'hidden'); |
| 289 | } |
| 290 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 291 | function cycleLabels() { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 292 | deviceLabelIndex = (deviceLabelIndex === network.deviceLabelCount - 1) |
| 293 | ? 0 : deviceLabelIndex + 1; |
Simon Hunt | 5f36d34 | 2014-11-08 21:33:14 -0800 | [diff] [blame] | 294 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 295 | network.nodes.forEach(function (d) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 296 | if (d.class === 'device') { |
| 297 | updateDeviceLabel(d); |
| 298 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 299 | }); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | function togglePorts(view) { |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 303 | view.alert('togglePorts() callback') |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 306 | function unpin() { |
| 307 | if (hovered) { |
| 308 | hovered.fixed = false; |
| 309 | hovered.el.classed('fixed', false); |
| 310 | network.force.resume(); |
| 311 | } |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // ============================== |
| 315 | // Radio Button Callbacks |
| 316 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 317 | var layerLookup = { |
| 318 | host: { |
| 319 | endstation: 'pkt', // default, if host event does not define type |
| 320 | bgpSpeaker: 'pkt' |
| 321 | }, |
| 322 | device: { |
| 323 | switch: 'pkt', |
| 324 | roadm: 'opt' |
| 325 | }, |
| 326 | link: { |
| 327 | hostLink: 'pkt', |
| 328 | direct: 'pkt', |
| 329 | optical: 'opt' |
| 330 | } |
| 331 | }; |
| 332 | |
| 333 | function inLayer(d, layer) { |
| 334 | var look = layerLookup[d.class], |
| 335 | lyr = look && look[d.type]; |
| 336 | return lyr === layer; |
| 337 | } |
| 338 | |
| 339 | function unsuppressLayer(which) { |
| 340 | node.each(function (d) { |
| 341 | var node = d.el; |
| 342 | if (inLayer(d, which)) { |
| 343 | node.classed('suppressed', false); |
| 344 | } |
| 345 | }); |
| 346 | |
| 347 | link.each(function (d) { |
| 348 | var link = d.el; |
| 349 | if (inLayer(d, which)) { |
| 350 | link.classed('suppressed', false); |
| 351 | } |
| 352 | }); |
| 353 | } |
| 354 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 355 | function showAllLayers() { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 356 | node.classed('suppressed', false); |
| 357 | link.classed('suppressed', false); |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 358 | // d3.selectAll('svg .port').classed('inactive', false); |
| 359 | // d3.selectAll('svg .portText').classed('inactive', false); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | function showPacketLayer() { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 363 | node.classed('suppressed', true); |
| 364 | link.classed('suppressed', true); |
| 365 | unsuppressLayer('pkt'); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | function showOpticalLayer() { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 369 | node.classed('suppressed', true); |
| 370 | link.classed('suppressed', true); |
| 371 | unsuppressLayer('opt'); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 374 | // ============================== |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 375 | // Private functions |
| 376 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 377 | function safeId(s) { |
| 378 | return s.replace(/[^a-z0-9]/gi, '-'); |
| 379 | } |
| 380 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 381 | // set the size of the given element to that of the view (reduced if padded) |
| 382 | function setSize(el, view, pad) { |
| 383 | var padding = pad ? pad * 2 : 0; |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 384 | el.attr({ |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 385 | width: view.width() - padding, |
| 386 | height: view.height() - padding |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 387 | }); |
| 388 | } |
| 389 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 390 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 391 | // ============================== |
| 392 | // Event handlers for server-pushed events |
| 393 | |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 394 | function logicError(msg) { |
| 395 | // TODO, report logic error to server, via websock, so it can be logged |
| 396 | network.view.alert('Logic Error:\n\n' + msg); |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 397 | console.warn(msg); |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 400 | var eventDispatch = { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 401 | addInstance: addInstance, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 402 | addDevice: addDevice, |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 403 | addLink: addLink, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 404 | addHost: addHost, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 405 | |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 406 | updateInstance: stillToImplement, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 407 | updateDevice: updateDevice, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 408 | updateLink: updateLink, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 409 | updateHost: updateHost, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 410 | |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 411 | removeInstance: stillToImplement, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 412 | removeDevice: stillToImplement, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 413 | removeLink: removeLink, |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 414 | removeHost: removeHost, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 415 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 416 | showDetails: showDetails, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 417 | showPath: showPath, |
| 418 | showTraffic: showTraffic |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 419 | }; |
| 420 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 421 | function addInstance(data) { |
| 422 | evTrace(data); |
| 423 | var inst = data.payload, |
| 424 | id = inst.id; |
| 425 | if (onosInstances[id]) { |
| 426 | logicError('ONOS instance already added: ' + id); |
| 427 | return; |
| 428 | } |
| 429 | onosInstances[id] = inst; |
| 430 | onosOrder.push(inst); |
| 431 | updateInstances(); |
| 432 | } |
| 433 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 434 | function addDevice(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 435 | evTrace(data); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 436 | var device = data.payload, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 437 | nodeData = createDeviceNode(device); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 438 | network.nodes.push(nodeData); |
| 439 | network.lookup[nodeData.id] = nodeData; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 440 | updateNodes(); |
| 441 | network.force.start(); |
| 442 | } |
| 443 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 444 | function addLink(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 445 | evTrace(data); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 446 | var link = data.payload, |
| 447 | lnk = createLink(link); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 448 | if (lnk) { |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 449 | network.links.push(lnk); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 450 | network.lookup[lnk.id] = lnk; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 451 | updateLinks(); |
| 452 | network.force.start(); |
| 453 | } |
| 454 | } |
| 455 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 456 | function addHost(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 457 | evTrace(data); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 458 | var host = data.payload, |
| 459 | node = createHostNode(host), |
| 460 | lnk; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 461 | network.nodes.push(node); |
| 462 | network.lookup[host.id] = node; |
| 463 | updateNodes(); |
| 464 | |
| 465 | lnk = createHostLink(host); |
| 466 | if (lnk) { |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 467 | node.linkData = lnk; // cache ref on its host |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 468 | network.links.push(lnk); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 469 | network.lookup[host.ingress] = lnk; |
| 470 | network.lookup[host.egress] = lnk; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 471 | updateLinks(); |
| 472 | } |
| 473 | network.force.start(); |
| 474 | } |
| 475 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 476 | // TODO: fold updateX(...) methods into one base method; remove duplication |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 477 | function updateDevice(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 478 | evTrace(data); |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 479 | var device = data.payload, |
| 480 | id = device.id, |
| 481 | nodeData = network.lookup[id]; |
| 482 | if (nodeData) { |
| 483 | $.extend(nodeData, device); |
| 484 | updateDeviceState(nodeData); |
| 485 | } else { |
| 486 | logicError('updateDevice lookup fail. ID = "' + id + '"'); |
| 487 | } |
| 488 | } |
| 489 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 490 | function updateLink(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 491 | evTrace(data); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 492 | var link = data.payload, |
| 493 | id = link.id, |
| 494 | linkData = network.lookup[id]; |
| 495 | if (linkData) { |
| 496 | $.extend(linkData, link); |
| 497 | updateLinkState(linkData); |
| 498 | } else { |
| 499 | logicError('updateLink lookup fail. ID = "' + id + '"'); |
| 500 | } |
| 501 | } |
| 502 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 503 | function updateHost(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 504 | evTrace(data); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 505 | var host = data.payload, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 506 | id = host.id, |
| 507 | hostData = network.lookup[id]; |
| 508 | if (hostData) { |
| 509 | $.extend(hostData, host); |
| 510 | updateHostState(hostData); |
| 511 | } else { |
| 512 | logicError('updateHost lookup fail. ID = "' + id + '"'); |
| 513 | } |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 516 | // TODO: fold removeX(...) methods into base method - remove dup code |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 517 | function removeLink(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 518 | evTrace(data); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 519 | var link = data.payload, |
| 520 | id = link.id, |
| 521 | linkData = network.lookup[id]; |
| 522 | if (linkData) { |
| 523 | removeLinkElement(linkData); |
| 524 | } else { |
| 525 | logicError('removeLink lookup fail. ID = "' + id + '"'); |
| 526 | } |
| 527 | } |
| 528 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 529 | function removeHost(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 530 | evTrace(data); |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 531 | var host = data.payload, |
| 532 | id = host.id, |
| 533 | hostData = network.lookup[id]; |
| 534 | if (hostData) { |
| 535 | removeHostElement(hostData); |
| 536 | } else { |
| 537 | logicError('removeHost lookup fail. ID = "' + id + '"'); |
| 538 | } |
| 539 | } |
| 540 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 541 | function showDetails(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 542 | evTrace(data); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 543 | populateDetails(data.payload); |
| 544 | detailPane.show(); |
| 545 | } |
| 546 | |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 547 | function showPath(data) { |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 548 | // TODO: review - making sure we are handling the payload correctly. |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 549 | evTrace(data); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 550 | var links = data.payload.links, |
| 551 | s = [ data.event + "\n" + links.length ]; |
| 552 | links.forEach(function (d, i) { |
| 553 | s.push(d); |
| 554 | }); |
| 555 | network.view.alert(s.join('\n')); |
| 556 | |
| 557 | links.forEach(function (d, i) { |
| 558 | var link = network.lookup[d]; |
| 559 | if (link) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 560 | link.el.classed('showPath', true); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 561 | } |
| 562 | }); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 565 | function showTraffic(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 566 | evTrace(data); |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 567 | var paths = data.payload.paths; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 568 | |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 569 | // Revert any links hilighted previously. |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 570 | link.classed('primary secondary animated optical', false); |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 571 | |
| 572 | // Now hilight all links in the paths payload. |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 573 | paths.forEach(function (p) { |
| 574 | var cls = p.class; |
| 575 | p.links.forEach(function (id) { |
| 576 | var lnk = network.lookup[id]; |
| 577 | if (lnk) { |
| 578 | lnk.el.classed(cls, true); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 579 | } |
| 580 | }); |
| 581 | }); |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 582 | } |
| 583 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 584 | // ............................... |
| 585 | |
| 586 | function stillToImplement(data) { |
| 587 | var p = data.payload; |
| 588 | note(data.event, p.id); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 589 | network.view.alert('Not yet implemented: "' + data.event + '"'); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 590 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 591 | |
| 592 | function unknownEvent(data) { |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 593 | network.view.alert('Unknown event type: "' + data.event + '"'); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | function handleServerEvent(data) { |
| 597 | var fn = eventDispatch[data.event] || unknownEvent; |
| 598 | fn(data); |
| 599 | } |
| 600 | |
| 601 | // ============================== |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 602 | // Out-going messages... |
| 603 | |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 604 | function userFeedback(msg) { |
| 605 | // for now, use the alert pane as is. Maybe different alert style in |
| 606 | // the future (centered on view; dismiss button?) |
| 607 | network.view.alert(msg); |
| 608 | } |
| 609 | |
| 610 | function nSel() { |
| 611 | return selectOrder.length; |
| 612 | } |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 613 | function getSel(idx) { |
| 614 | return selections[selectOrder[idx]]; |
| 615 | } |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 616 | function getSelId(idx) { |
| 617 | return getSel(idx).obj.id; |
| 618 | } |
| 619 | function allSelectionsClass(cls) { |
| 620 | for (var i=0, n=nSel(); i<n; i++) { |
| 621 | if (getSel(i).obj.class !== cls) { |
| 622 | return false; |
| 623 | } |
| 624 | } |
| 625 | return true; |
| 626 | } |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 627 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 628 | // request details for the selected element |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 629 | // invoked from selection of a single node. |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 630 | function requestDetails() { |
| 631 | var data = getSel(0).obj, |
| 632 | payload = { |
| 633 | id: data.id, |
| 634 | class: data.class |
| 635 | }; |
| 636 | sendMessage('requestDetails', payload); |
| 637 | } |
| 638 | |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 639 | function addIntentAction() { |
| 640 | sendMessage('addHostIntent', { |
| 641 | one: getSelId(0), |
| 642 | two: getSelId(1) |
| 643 | }); |
| 644 | } |
| 645 | |
| 646 | function showTrafficAction() { |
| 647 | // if nothing is hovered over, and nothing selected, send cancel request |
| 648 | if (!hovered && nSel() === 0) { |
| 649 | sendMessage('cancelTraffic', {}); |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | // NOTE: hover is only populated if "show traffic on hover" is |
| 654 | // toggled on, and the item hovered is a host... |
| 655 | var hoverId = (trafficHover() && hovered && hovered.class === 'host') |
| 656 | ? hovered.id : ''; |
| 657 | sendMessage('requestTraffic', { |
| 658 | ids: selectOrder, |
| 659 | hover: hoverId |
| 660 | }); |
| 661 | } |
| 662 | |
| 663 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 664 | // ============================== |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 665 | // onos instance panel functions |
| 666 | |
| 667 | function updateInstances() { |
| 668 | var onoses = oiBox.el.selectAll('.onosInst') |
| 669 | .data(onosOrder, function (d) { return d.id; }); |
| 670 | |
| 671 | // operate on existing onoses if necessary |
| 672 | |
| 673 | var entering = onoses.enter() |
| 674 | .append('div') |
| 675 | .attr('class', 'onosInst') |
| 676 | .classed('online', function (d) { return d.online; }) |
| 677 | .text(function (d) { return d.id; }); |
| 678 | |
| 679 | // operate on existing + new onoses here |
| 680 | |
| 681 | // the departed... |
| 682 | var exiting = onoses.exit() |
| 683 | .transition() |
| 684 | .style('opacity', 0) |
| 685 | .remove(); |
| 686 | } |
| 687 | |
| 688 | // ============================== |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 689 | // force layout modification functions |
| 690 | |
| 691 | function translate(x, y) { |
| 692 | return 'translate(' + x + ',' + y + ')'; |
| 693 | } |
| 694 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 695 | function missMsg(what, id) { |
| 696 | return '\n[' + what + '] "' + id + '" missing '; |
| 697 | } |
| 698 | |
| 699 | function linkEndPoints(srcId, dstId) { |
| 700 | var srcNode = network.lookup[srcId], |
| 701 | dstNode = network.lookup[dstId], |
| 702 | sMiss = !srcNode ? missMsg('src', srcId) : '', |
| 703 | dMiss = !dstNode ? missMsg('dst', dstId) : ''; |
| 704 | |
| 705 | if (sMiss || dMiss) { |
| 706 | logicError('Node(s) not on map for link:\n' + sMiss + dMiss); |
| 707 | return null; |
| 708 | } |
| 709 | return { |
| 710 | source: srcNode, |
| 711 | target: dstNode, |
| 712 | x1: srcNode.x, |
| 713 | y1: srcNode.y, |
| 714 | x2: dstNode.x, |
| 715 | y2: dstNode.y |
| 716 | }; |
| 717 | } |
| 718 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 719 | function createHostLink(host) { |
| 720 | var src = host.id, |
| 721 | dst = host.cp.device, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 722 | id = host.ingress, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 723 | lnk = linkEndPoints(src, dst); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 724 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 725 | if (!lnk) { |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 726 | return null; |
| 727 | } |
| 728 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 729 | // Synthesize link ... |
| 730 | $.extend(lnk, { |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 731 | id: id, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 732 | class: 'link', |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 733 | type: 'hostLink', |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 734 | svgClass: 'link hostLink', |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 735 | linkWidth: 1 |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 736 | }); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 737 | return lnk; |
| 738 | } |
| 739 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 740 | function createLink(link) { |
| 741 | var lnk = linkEndPoints(link.src, link.dst), |
| 742 | type = link.type; |
| 743 | |
| 744 | if (!lnk) { |
| 745 | return null; |
| 746 | } |
| 747 | |
| 748 | // merge in remaining data |
| 749 | $.extend(lnk, link, { |
| 750 | class: 'link', |
| 751 | svgClass: type ? 'link ' + type : 'link' |
| 752 | }); |
| 753 | return lnk; |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 754 | } |
| 755 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 756 | var widthRatio = 1.4, |
| 757 | linkScale = d3.scale.linear() |
| 758 | .domain([1, 12]) |
| 759 | .range([widthRatio, 12 * widthRatio]) |
| 760 | .clamp(true); |
| 761 | |
| 762 | function updateLinkWidth (d) { |
| 763 | // TODO: watch out for .showPath/.showTraffic classes |
| 764 | d.el.transition() |
| 765 | .duration(1000) |
| 766 | .attr('stroke-width', linkScale(d.linkWidth)); |
| 767 | } |
| 768 | |
| 769 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 770 | function updateLinks() { |
| 771 | link = linkG.selectAll('.link') |
| 772 | .data(network.links, function (d) { return d.id; }); |
| 773 | |
| 774 | // operate on existing links, if necessary |
| 775 | // link .foo() .bar() ... |
| 776 | |
| 777 | // operate on entering links: |
| 778 | var entering = link.enter() |
| 779 | .append('line') |
| 780 | .attr({ |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 781 | class: function (d) { return d.svgClass; }, |
| 782 | x1: function (d) { return d.x1; }, |
| 783 | y1: function (d) { return d.y1; }, |
| 784 | x2: function (d) { return d.x2; }, |
| 785 | y2: function (d) { return d.y2; }, |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 786 | stroke: config.topo.linkInColor, |
| 787 | 'stroke-width': config.topo.linkInWidth |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 788 | }) |
| 789 | .transition().duration(1000) |
| 790 | .attr({ |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 791 | 'stroke-width': function (d) { return linkScale(d.linkWidth); }, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 792 | stroke: '#666' // TODO: remove explicit stroke, rather... |
| 793 | }); |
| 794 | |
| 795 | // augment links |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 796 | entering.each(function (d) { |
| 797 | var link = d3.select(this); |
| 798 | // provide ref to element selection from backing data.... |
| 799 | d.el = link; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 800 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 801 | // TODO: add src/dst port labels etc. |
| 802 | }); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 803 | |
| 804 | // operate on both existing and new links, if necessary |
| 805 | //link .foo() .bar() ... |
| 806 | |
| 807 | // operate on exiting links: |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 808 | link.exit() |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 809 | .attr({ |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 810 | 'stroke-dasharray': '3, 3' |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 811 | }) |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 812 | .style('opacity', 0.4) |
| 813 | .transition() |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 814 | .duration(1500) |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 815 | .attr({ |
| 816 | 'stroke-dasharray': '3, 12' |
| 817 | }) |
| 818 | .transition() |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 819 | .duration(500) |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 820 | .style('opacity', 0.0) |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 821 | .remove(); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | function createDeviceNode(device) { |
| 825 | // start with the object as is |
| 826 | var node = device, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 827 | type = device.type, |
| 828 | svgCls = type ? 'node device ' + type : 'node device'; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 829 | |
| 830 | // Augment as needed... |
| 831 | node.class = 'device'; |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 832 | node.svgClass = device.online ? svgCls + ' online' : svgCls; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 833 | positionNode(node); |
| 834 | |
| 835 | // cache label array length |
| 836 | network.deviceLabelCount = device.labels.length; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 837 | return node; |
| 838 | } |
| 839 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 840 | function createHostNode(host) { |
| 841 | // start with the object as is |
| 842 | var node = host; |
| 843 | |
| 844 | // Augment as needed... |
| 845 | node.class = 'host'; |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 846 | if (!node.type) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 847 | node.type = 'endstation'; |
| 848 | } |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 849 | node.svgClass = 'node host'; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 850 | positionNode(node); |
| 851 | |
| 852 | // cache label array length |
| 853 | network.hostLabelCount = host.labels.length; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 854 | return node; |
| 855 | } |
| 856 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 857 | function positionNode(node) { |
| 858 | var meta = node.metaUi, |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 859 | x = meta && meta.x, |
| 860 | y = meta && meta.y, |
| 861 | xy; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 862 | |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 863 | // If we have [x,y] already, use that... |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 864 | if (x && y) { |
| 865 | node.fixed = true; |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 866 | node.x = x; |
| 867 | node.y = y; |
| 868 | return; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 869 | } |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 870 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 871 | var location = node.location; |
| 872 | if (location && location.type === 'latlng') { |
| 873 | var coord = geoMapProjection([location.lng, location.lat]); |
| 874 | node.fixed = true; |
| 875 | node.x = coord[0]; |
| 876 | node.y = coord[1]; |
| 877 | return; |
| 878 | } |
| 879 | |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 880 | // Note: Placing incoming unpinned nodes at exactly the same point |
| 881 | // (center of the view) causes them to explode outwards when |
| 882 | // the force layout kicks in. So, we spread them out a bit |
| 883 | // initially, to provide a more serene layout convergence. |
| 884 | // Additionally, if the node is a host, we place it near |
| 885 | // the device it is connected to. |
| 886 | |
| 887 | function spread(s) { |
| 888 | return Math.floor((Math.random() * s) - s/2); |
| 889 | } |
| 890 | |
| 891 | function randDim(dim) { |
| 892 | return dim / 2 + spread(dim * 0.7071); |
| 893 | } |
| 894 | |
| 895 | function rand() { |
| 896 | return { |
| 897 | x: randDim(network.view.width()), |
| 898 | y: randDim(network.view.height()) |
| 899 | }; |
| 900 | } |
| 901 | |
| 902 | function near(node) { |
| 903 | var min = 12, |
| 904 | dx = spread(12), |
| 905 | dy = spread(12); |
| 906 | return { |
| 907 | x: node.x + min + dx, |
| 908 | y: node.y + min + dy |
| 909 | }; |
| 910 | } |
| 911 | |
| 912 | function getDevice(cp) { |
| 913 | var d = network.lookup[cp.device]; |
| 914 | return d || rand(); |
| 915 | } |
| 916 | |
| 917 | xy = (node.class === 'host') ? near(getDevice(node.cp)) : rand(); |
| 918 | $.extend(node, xy); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 919 | } |
| 920 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 921 | function iconUrl(d) { |
| 922 | return 'img/' + d.type + '.png'; |
| 923 | } |
| 924 | |
| 925 | // returns the newly computed bounding box of the rectangle |
| 926 | function adjustRectToFitText(n) { |
| 927 | var text = n.select('text'), |
| 928 | box = text.node().getBBox(), |
| 929 | lab = config.labels; |
| 930 | |
| 931 | text.attr('text-anchor', 'middle') |
| 932 | .attr('y', '-0.8em') |
| 933 | .attr('x', lab.imgPad/2); |
| 934 | |
| 935 | // translate the bbox so that it is centered on [x,y] |
| 936 | box.x = -box.width / 2; |
| 937 | box.y = -box.height / 2; |
| 938 | |
| 939 | // add padding |
| 940 | box.x -= (lab.padLR + lab.imgPad/2); |
| 941 | box.width += lab.padLR * 2 + lab.imgPad; |
| 942 | box.y -= lab.padTB; |
| 943 | box.height += lab.padTB * 2; |
| 944 | |
| 945 | return box; |
| 946 | } |
| 947 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 948 | function mkSvgClass(d) { |
| 949 | return d.fixed ? d.svgClass + ' fixed' : d.svgClass; |
| 950 | } |
| 951 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 952 | function hostLabel(d) { |
| 953 | var idx = (hostLabelIndex < d.labels.length) ? hostLabelIndex : 0; |
| 954 | return d.labels[idx]; |
| 955 | } |
| 956 | function deviceLabel(d) { |
| 957 | var idx = (deviceLabelIndex < d.labels.length) ? deviceLabelIndex : 0; |
| 958 | return d.labels[idx]; |
| 959 | } |
| 960 | function niceLabel(label) { |
| 961 | return (label && label.trim()) ? label : '.'; |
| 962 | } |
| 963 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 964 | function updateDeviceLabel(d) { |
| 965 | var label = niceLabel(deviceLabel(d)), |
| 966 | node = d.el, |
| 967 | box; |
| 968 | |
| 969 | node.select('text') |
| 970 | .text(label) |
| 971 | .style('opacity', 0) |
| 972 | .transition() |
| 973 | .style('opacity', 1); |
| 974 | |
| 975 | box = adjustRectToFitText(node); |
| 976 | |
| 977 | node.select('rect') |
| 978 | .transition() |
| 979 | .attr(box); |
| 980 | |
| 981 | node.select('image') |
| 982 | .transition() |
| 983 | .attr('x', box.x + config.icons.xoff) |
| 984 | .attr('y', box.y + config.icons.yoff); |
| 985 | } |
| 986 | |
| 987 | function updateHostLabel(d) { |
| 988 | var label = hostLabel(d), |
| 989 | host = d.el; |
| 990 | |
| 991 | host.select('text').text(label); |
| 992 | } |
| 993 | |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 994 | function updateDeviceState(nodeData) { |
| 995 | nodeData.el.classed('online', nodeData.online); |
| 996 | updateDeviceLabel(nodeData); |
| 997 | // TODO: review what else might need to be updated |
| 998 | } |
| 999 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1000 | function updateLinkState(linkData) { |
| 1001 | updateLinkWidth(linkData); |
| 1002 | // TODO: review what else might need to be updated |
| 1003 | // update label, if showing |
| 1004 | } |
| 1005 | |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1006 | function updateHostState(hostData) { |
| 1007 | updateHostLabel(hostData); |
| 1008 | // TODO: review what else might need to be updated |
| 1009 | } |
| 1010 | |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1011 | function nodeMouseOver(d) { |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1012 | hovered = d; |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1013 | if (trafficHover() && d.class === 'host') { |
| 1014 | showTrafficAction(); |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | function nodeMouseOut(d) { |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1019 | hovered = null; |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1020 | if (trafficHover() && d.class === 'host') { |
| 1021 | showTrafficAction(); |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1022 | } |
| 1023 | } |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1024 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1025 | function updateNodes() { |
| 1026 | node = nodeG.selectAll('.node') |
| 1027 | .data(network.nodes, function (d) { return d.id; }); |
| 1028 | |
| 1029 | // operate on existing nodes, if necessary |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1030 | // update host labels |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1031 | //node .foo() .bar() ... |
| 1032 | |
| 1033 | // operate on entering nodes: |
| 1034 | var entering = node.enter() |
| 1035 | .append('g') |
| 1036 | .attr({ |
| 1037 | id: function (d) { return safeId(d.id); }, |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1038 | class: mkSvgClass, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1039 | transform: function (d) { return translate(d.x, d.y); }, |
| 1040 | opacity: 0 |
| 1041 | }) |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1042 | .call(network.drag) |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1043 | .on('mouseover', nodeMouseOver) |
| 1044 | .on('mouseout', nodeMouseOut) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1045 | .transition() |
| 1046 | .attr('opacity', 1); |
| 1047 | |
| 1048 | // augment device nodes... |
| 1049 | entering.filter('.device').each(function (d) { |
| 1050 | var node = d3.select(this), |
| 1051 | icon = iconUrl(d), |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1052 | label = niceLabel(deviceLabel(d)), |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1053 | box; |
| 1054 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1055 | // provide ref to element from backing data.... |
| 1056 | d.el = node; |
| 1057 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1058 | node.append('rect') |
| 1059 | .attr({ |
| 1060 | 'rx': 5, |
| 1061 | 'ry': 5 |
| 1062 | }); |
| 1063 | |
| 1064 | node.append('text') |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1065 | .text(label) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1066 | .attr('dy', '1.1em'); |
| 1067 | |
| 1068 | box = adjustRectToFitText(node); |
| 1069 | |
| 1070 | node.select('rect') |
| 1071 | .attr(box); |
| 1072 | |
| 1073 | if (icon) { |
| 1074 | var cfg = config.icons; |
| 1075 | node.append('svg:image') |
| 1076 | .attr({ |
| 1077 | x: box.x + config.icons.xoff, |
| 1078 | y: box.y + config.icons.yoff, |
| 1079 | width: cfg.w, |
| 1080 | height: cfg.h, |
| 1081 | 'xlink:href': icon |
| 1082 | }); |
| 1083 | } |
| 1084 | |
| 1085 | // debug function to show the modelled x,y coordinates of nodes... |
| 1086 | if (debug('showNodeXY')) { |
| 1087 | node.select('rect').attr('fill-opacity', 0.5); |
| 1088 | node.append('circle') |
| 1089 | .attr({ |
| 1090 | class: 'debug', |
| 1091 | cx: 0, |
| 1092 | cy: 0, |
| 1093 | r: '3px' |
| 1094 | }); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1095 | } |
| 1096 | }); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 1097 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1098 | // augment host nodes... |
| 1099 | entering.filter('.host').each(function (d) { |
| 1100 | var node = d3.select(this), |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1101 | box; |
| 1102 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1103 | // provide ref to element from backing data.... |
| 1104 | d.el = node; |
| 1105 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1106 | node.append('circle') |
| 1107 | .attr('r', 8); // TODO: define host circle radius |
| 1108 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1109 | node.append('text') |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1110 | .text(hostLabel) |
| 1111 | .attr('dy', '1.3em') |
| 1112 | .attr('text-anchor', 'middle'); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1113 | |
| 1114 | // debug function to show the modelled x,y coordinates of nodes... |
| 1115 | if (debug('showNodeXY')) { |
| 1116 | node.select('circle').attr('fill-opacity', 0.5); |
| 1117 | node.append('circle') |
| 1118 | .attr({ |
| 1119 | class: 'debug', |
| 1120 | cx: 0, |
| 1121 | cy: 0, |
| 1122 | r: '3px' |
| 1123 | }); |
| 1124 | } |
| 1125 | }); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1126 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1127 | // operate on both existing and new nodes, if necessary |
| 1128 | //node .foo() .bar() ... |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1129 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1130 | // operate on exiting nodes: |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1131 | // Note that the node is removed after 2 seconds. |
| 1132 | // Sub element animations should be shorter than 2 seconds. |
| 1133 | var exiting = node.exit() |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 1134 | .transition() |
| 1135 | .duration(2000) |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1136 | .style('opacity', 0) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1137 | .remove(); |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1138 | |
| 1139 | // host node exits.... |
| 1140 | exiting.filter('.host').each(function (d) { |
| 1141 | var node = d3.select(this); |
| 1142 | |
| 1143 | node.select('text') |
| 1144 | .style('opacity', 0.5) |
| 1145 | .transition() |
| 1146 | .duration(1000) |
| 1147 | .style('opacity', 0); |
| 1148 | // note, leave <g>.remove to remove this element |
| 1149 | |
| 1150 | node.select('circle') |
| 1151 | .style('stroke-fill', '#555') |
| 1152 | .style('fill', '#888') |
| 1153 | .style('opacity', 0.5) |
| 1154 | .transition() |
| 1155 | .duration(1500) |
| 1156 | .attr('r', 0); |
| 1157 | // note, leave <g>.remove to remove this element |
| 1158 | |
| 1159 | }); |
| 1160 | |
| 1161 | // TODO: device node exits |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1164 | function find(id, array) { |
| 1165 | for (var idx = 0, n = array.length; idx < n; idx++) { |
| 1166 | if (array[idx].id === id) { |
| 1167 | return idx; |
| 1168 | } |
| 1169 | } |
| 1170 | return -1; |
| 1171 | } |
| 1172 | |
| 1173 | function removeLinkElement(linkData) { |
| 1174 | // remove from lookup cache |
| 1175 | delete network.lookup[linkData.id]; |
| 1176 | // remove from links array |
| 1177 | var idx = find(linkData.id, network.links); |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 1178 | network.links.splice(idx, 1); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1179 | // remove from SVG |
| 1180 | updateLinks(); |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 1181 | network.force.resume(); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1182 | } |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1183 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 1184 | function removeHostElement(hostData) { |
| 1185 | // first, remove associated hostLink... |
| 1186 | removeLinkElement(hostData.linkData); |
| 1187 | |
| 1188 | // remove from lookup cache |
| 1189 | delete network.lookup[hostData.id]; |
| 1190 | // remove from nodes array |
| 1191 | var idx = find(hostData.id, network.nodes); |
| 1192 | network.nodes.splice(idx, 1); |
| 1193 | // remove from SVG |
| 1194 | updateNodes(); |
| 1195 | network.force.resume(); |
| 1196 | } |
| 1197 | |
| 1198 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1199 | function tick() { |
| 1200 | node.attr({ |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1201 | transform: function (d) { return translate(d.x, d.y); } |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1202 | }); |
| 1203 | |
| 1204 | link.attr({ |
| 1205 | x1: function (d) { return d.source.x; }, |
| 1206 | y1: function (d) { return d.source.y; }, |
| 1207 | x2: function (d) { return d.target.x; }, |
| 1208 | y2: function (d) { return d.target.y; } |
| 1209 | }); |
| 1210 | } |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 1211 | |
| 1212 | // ============================== |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1213 | // Web-Socket for live data |
| 1214 | |
| 1215 | function webSockUrl() { |
| 1216 | return document.location.toString() |
| 1217 | .replace(/\#.*/, '') |
| 1218 | .replace('http://', 'ws://') |
| 1219 | .replace('https://', 'wss://') |
| 1220 | .replace('index2.html', config.webSockUrl); |
| 1221 | } |
| 1222 | |
| 1223 | webSock = { |
| 1224 | ws : null, |
| 1225 | |
| 1226 | connect : function() { |
| 1227 | webSock.ws = new WebSocket(webSockUrl()); |
| 1228 | |
| 1229 | webSock.ws.onopen = function() { |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 1230 | noWebSock(false); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1231 | }; |
| 1232 | |
| 1233 | webSock.ws.onmessage = function(m) { |
| 1234 | if (m.data) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1235 | wsTraceRx(m.data); |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 1236 | handleServerEvent(JSON.parse(m.data)); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1237 | } |
| 1238 | }; |
| 1239 | |
| 1240 | webSock.ws.onclose = function(m) { |
| 1241 | webSock.ws = null; |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 1242 | noWebSock(true); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1243 | }; |
| 1244 | }, |
| 1245 | |
| 1246 | send : function(text) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1247 | if (text != null) { |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1248 | webSock._send(text); |
| 1249 | } |
| 1250 | }, |
| 1251 | |
| 1252 | _send : function(message) { |
| 1253 | if (webSock.ws) { |
| 1254 | webSock.ws.send(message); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 1255 | } else if (config.useLiveData) { |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1256 | network.view.alert('no web socket open\n\n' + message); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 1257 | } else { |
| 1258 | console.log('WS Send: ' + JSON.stringify(message)); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | }; |
| 1263 | |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 1264 | function noWebSock(b) { |
| 1265 | mask.style('display',b ? 'block' : 'none'); |
| 1266 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1267 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1268 | // TODO: use cache of pending messages (key = sid) to reconcile responses |
| 1269 | |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1270 | function sendMessage(evType, payload) { |
| 1271 | var toSend = { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1272 | event: evType, |
| 1273 | sid: ++sid, |
| 1274 | payload: payload |
| 1275 | }, |
| 1276 | asText = JSON.stringify(toSend); |
| 1277 | wsTraceTx(asText); |
| 1278 | webSock.send(asText); |
| 1279 | } |
| 1280 | |
| 1281 | function wsTraceTx(msg) { |
| 1282 | wsTrace('tx', msg); |
| 1283 | } |
| 1284 | function wsTraceRx(msg) { |
| 1285 | wsTrace('rx', msg); |
| 1286 | } |
| 1287 | function wsTrace(rxtx, msg) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1288 | console.log('[' + rxtx + '] ' + msg); |
| 1289 | // TODO: integrate with trace view |
| 1290 | //if (trace) { |
| 1291 | // trace.output(rxtx, msg); |
| 1292 | //} |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | // ============================== |
| 1297 | // Selection stuff |
| 1298 | |
| 1299 | function selectObject(obj, el) { |
| 1300 | var n, |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1301 | srcEv = d3.event.sourceEvent, |
| 1302 | meta = srcEv.metaKey, |
| 1303 | shift = srcEv.shiftKey; |
| 1304 | |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 1305 | if ((panZoom() && !meta) || (!panZoom() && meta)) { |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1306 | return; |
| 1307 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1308 | |
| 1309 | if (el) { |
| 1310 | n = d3.select(el); |
| 1311 | } else { |
| 1312 | node.each(function(d) { |
| 1313 | if (d == obj) { |
| 1314 | n = d3.select(el = this); |
| 1315 | } |
| 1316 | }); |
| 1317 | } |
| 1318 | if (!n) return; |
| 1319 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1320 | if (shift && n.classed('selected')) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1321 | deselectObject(obj.id); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1322 | updateDetailPane(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1323 | return; |
| 1324 | } |
| 1325 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1326 | if (!shift) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1327 | deselectAll(); |
| 1328 | } |
| 1329 | |
Simon Hunt | c31d569 | 2014-11-12 13:27:18 -0800 | [diff] [blame] | 1330 | selections[obj.id] = { obj: obj, el: el }; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1331 | selectOrder.push(obj.id); |
| 1332 | |
| 1333 | n.classed('selected', true); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1334 | updateDetailPane(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | function deselectObject(id) { |
Simon Hunt | c31d569 | 2014-11-12 13:27:18 -0800 | [diff] [blame] | 1338 | var obj = selections[id], |
| 1339 | idx; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1340 | if (obj) { |
| 1341 | d3.select(obj.el).classed('selected', false); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1342 | delete selections[id]; |
Simon Hunt | c31d569 | 2014-11-12 13:27:18 -0800 | [diff] [blame] | 1343 | idx = $.inArray(id, selectOrder); |
| 1344 | if (idx >= 0) { |
| 1345 | selectOrder.splice(idx, 1); |
| 1346 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1347 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | function deselectAll() { |
| 1351 | // deselect all nodes in the network... |
| 1352 | node.classed('selected', false); |
| 1353 | selections = {}; |
| 1354 | selectOrder = []; |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1355 | updateDetailPane(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1358 | // update the state of the detail pane, based on current selections |
| 1359 | function updateDetailPane() { |
| 1360 | var nSel = selectOrder.length; |
| 1361 | if (!nSel) { |
| 1362 | detailPane.hide(); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1363 | showTrafficAction(); // sends cancelTraffic event |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1364 | } else if (nSel === 1) { |
| 1365 | singleSelect(); |
| 1366 | } else { |
| 1367 | multiSelect(); |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | function singleSelect() { |
| 1372 | requestDetails(); |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 1373 | // NOTE: detail pane will be shown from showDetails event callback |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | function multiSelect() { |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 1377 | populateMultiSelect(); |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | function addSep(tbody) { |
| 1381 | var tr = tbody.append('tr'); |
| 1382 | $('<hr>').appendTo(tr.append('td').attr('colspan', 2)); |
| 1383 | } |
| 1384 | |
| 1385 | function addProp(tbody, label, value) { |
| 1386 | var tr = tbody.append('tr'); |
| 1387 | |
| 1388 | tr.append('td') |
| 1389 | .attr('class', 'label') |
| 1390 | .text(label + ' :'); |
| 1391 | |
| 1392 | tr.append('td') |
| 1393 | .attr('class', 'value') |
| 1394 | .text(value); |
| 1395 | } |
| 1396 | |
| 1397 | function populateMultiSelect() { |
| 1398 | detailPane.empty(); |
| 1399 | |
| 1400 | var title = detailPane.append("h2"), |
| 1401 | table = detailPane.append("table"), |
| 1402 | tbody = table.append("tbody"); |
| 1403 | |
| 1404 | title.text('Multi-Select...'); |
| 1405 | |
| 1406 | selectOrder.forEach(function (d, i) { |
| 1407 | addProp(tbody, i+1, d); |
| 1408 | }); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1409 | |
| 1410 | addMultiSelectActions(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | function populateDetails(data) { |
| 1414 | detailPane.empty(); |
| 1415 | |
| 1416 | var title = detailPane.append("h2"), |
| 1417 | table = detailPane.append("table"), |
| 1418 | tbody = table.append("tbody"); |
| 1419 | |
| 1420 | $('<img src="img/' + data.type + '.png">').appendTo(title); |
| 1421 | $('<span>').attr('class', 'icon').text(data.id).appendTo(title); |
| 1422 | |
| 1423 | data.propOrder.forEach(function(p) { |
| 1424 | if (p === '-') { |
| 1425 | addSep(tbody); |
| 1426 | } else { |
| 1427 | addProp(tbody, p, data.props[p]); |
| 1428 | } |
| 1429 | }); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1430 | |
| 1431 | addSingleSelectActions(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1434 | function addSingleSelectActions() { |
| 1435 | detailPane.append('hr'); |
| 1436 | // always want to allow 'show traffic' |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1437 | addAction(detailPane, 'Show Traffic', showTrafficAction); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | function addMultiSelectActions() { |
| 1441 | detailPane.append('hr'); |
| 1442 | // always want to allow 'show traffic' |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1443 | addAction(detailPane, 'Show Traffic', showTrafficAction); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1444 | // if exactly two hosts are selected, also want 'add host intent' |
| 1445 | if (nSel() === 2 && allSelectionsClass('host')) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1446 | addAction(detailPane, 'Add Host Intent', addIntentAction); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1450 | function addAction(panel, text, cb) { |
| 1451 | panel.append('div') |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1452 | .classed('actionBtn', true) |
| 1453 | .text(text) |
| 1454 | .on('click', cb); |
| 1455 | } |
| 1456 | |
| 1457 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1458 | function zoomPan(scale, translate) { |
| 1459 | zoomPanContainer.attr("transform", "translate(" + translate + ")scale(" + scale + ")"); |
| 1460 | // keep the map lines constant width while zooming |
| 1461 | bgImg.style("stroke-width", 2.0 / scale + "px"); |
| 1462 | } |
| 1463 | |
| 1464 | function resetZoomPan() { |
| 1465 | zoomPan(1, [0,0]); |
| 1466 | zoom.scale(1).translate([0,0]); |
| 1467 | } |
| 1468 | |
| 1469 | function setupZoomPan() { |
| 1470 | function zoomed() { |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 1471 | if (!panZoom() ^ !d3.event.sourceEvent.metaKey) { |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1472 | zoomPan(d3.event.scale, d3.event.translate); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | zoom = d3.behavior.zoom() |
| 1477 | .translate([0, 0]) |
| 1478 | .scale(1) |
| 1479 | .scaleExtent([1, 8]) |
| 1480 | .on("zoom", zoomed); |
| 1481 | |
| 1482 | svg.call(zoom); |
| 1483 | } |
| 1484 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1485 | // ============================== |
| 1486 | // Test harness code |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1487 | |
| 1488 | function prepareScenario(view, ctx, dbg) { |
| 1489 | var sc = scenario, |
| 1490 | urlSc = sc.evDir + ctx + sc.evScenario; |
| 1491 | |
| 1492 | if (!ctx) { |
| 1493 | view.alert("No scenario specified (null ctx)"); |
| 1494 | return; |
| 1495 | } |
| 1496 | |
| 1497 | sc.view = view; |
| 1498 | sc.ctx = ctx; |
| 1499 | sc.debug = dbg; |
| 1500 | sc.evNumber = 0; |
| 1501 | |
| 1502 | d3.json(urlSc, function(err, data) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1503 | var p = data && data.params || {}, |
| 1504 | desc = data && data.description || null, |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 1505 | intro = data && data.title; |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1506 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1507 | if (err) { |
| 1508 | view.alert('No scenario found:\n\n' + urlSc + '\n\n' + err); |
| 1509 | } else { |
| 1510 | sc.params = p; |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1511 | if (desc) { |
| 1512 | intro += '\n\n ' + desc.join('\n '); |
| 1513 | } |
| 1514 | view.alert(intro); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1515 | } |
| 1516 | }); |
| 1517 | |
| 1518 | } |
| 1519 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1520 | // ============================== |
| 1521 | // Toggle Buttons in masthead |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 1522 | |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 1523 | // TODO: toggle button (and other widgets in the masthead) should be provided |
| 1524 | // by the framework; not generated by the view. |
| 1525 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1526 | var showInstances, |
| 1527 | doPanZoom, |
| 1528 | showTrafficOnHover; |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 1529 | |
| 1530 | function addButtonBar(view) { |
| 1531 | var bb = d3.select('#mast') |
| 1532 | .append('span').classed('right', true).attr('id', 'bb'); |
| 1533 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1534 | function mkTogBtn(text, cb) { |
| 1535 | return bb.append('span') |
| 1536 | .classed('btn', true) |
| 1537 | .text(text) |
| 1538 | .on('click', cb); |
| 1539 | } |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1540 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1541 | showInstances = mkTogBtn('Show Instances', toggleInst); |
| 1542 | doPanZoom = mkTogBtn('Pan/Zoom', togglePanZoom); |
| 1543 | showTrafficOnHover = mkTogBtn('Show traffic on hover', toggleTrafficHover); |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1546 | function instShown() { |
| 1547 | return showInstances.classed('active'); |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 1548 | } |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1549 | function toggleInst() { |
| 1550 | showInstances.classed('active', !instShown()); |
| 1551 | if (instShown()) { |
| 1552 | oiBox.show(); |
| 1553 | } else { |
| 1554 | oiBox.hide(); |
| 1555 | } |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1556 | } |
| 1557 | |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 1558 | function panZoom() { |
| 1559 | return doPanZoom.classed('active'); |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1560 | } |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1561 | function togglePanZoom() { |
| 1562 | doPanZoom.classed('active', !panZoom()); |
| 1563 | } |
| 1564 | |
| 1565 | function trafficHover() { |
| 1566 | return showTrafficOnHover.classed('active'); |
| 1567 | } |
| 1568 | function toggleTrafficHover() { |
| 1569 | showTrafficOnHover.classed('active', !trafficHover()); |
| 1570 | } |
| 1571 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1572 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1573 | // ============================== |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 1574 | // View life-cycle callbacks |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1575 | |
Simon Hunt | f67722a | 2014-11-10 09:32:06 -0800 | [diff] [blame] | 1576 | function preload(view, ctx, flags) { |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 1577 | var w = view.width(), |
| 1578 | h = view.height(), |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1579 | fcfg = config.force, |
| 1580 | fpad = fcfg.pad, |
| 1581 | forceDim = [w - 2*fpad, h - 2*fpad]; |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1582 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 1583 | // NOTE: view.$div is a D3 selection of the view's div |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1584 | var viewBox = '0 0 ' + config.logicalSize + ' ' + config.logicalSize; |
| 1585 | svg = view.$div.append('svg').attr('viewBox', viewBox); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 1586 | setSize(svg, view); |
| 1587 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1588 | zoomPanContainer = svg.append('g').attr('id', 'zoomPanContainer'); |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1589 | setupZoomPan(); |
| 1590 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1591 | // add blue glow filter to svg layer |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1592 | d3u.appendGlow(zoomPanContainer); |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1593 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1594 | // group for the topology |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1595 | topoG = zoomPanContainer.append('g') |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1596 | .attr('id', 'topo-G') |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1597 | .attr('transform', fcfg.translate()); |
| 1598 | |
| 1599 | // subgroups for links and nodes |
| 1600 | linkG = topoG.append('g').attr('id', 'links'); |
| 1601 | nodeG = topoG.append('g').attr('id', 'nodes'); |
| 1602 | |
| 1603 | // selection of nodes and links |
| 1604 | link = linkG.selectAll('.link'); |
| 1605 | node = nodeG.selectAll('.node'); |
| 1606 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1607 | function chrg(d) { |
| 1608 | return fcfg.charge[d.class] || -12000; |
| 1609 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1610 | function ldist(d) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1611 | return fcfg.linkDistance[d.type] || 50; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1612 | } |
| 1613 | function lstrg(d) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1614 | // 0.0 - 1.0 |
| 1615 | return fcfg.linkStrength[d.type] || 1.0; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1616 | } |
| 1617 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1618 | function selectCb(d, self) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1619 | selectObject(d, self); |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | function atDragEnd(d, self) { |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1623 | // once we've finished moving, pin the node in position |
| 1624 | d.fixed = true; |
| 1625 | d3.select(self).classed('fixed', true); |
| 1626 | if (config.useLiveData) { |
Simon Hunt | 902c992 | 2014-11-11 11:59:31 -0800 | [diff] [blame] | 1627 | sendUpdateMeta(d); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 1628 | } else { |
| 1629 | console.log('Moving node ' + d.id + ' to [' + d.x + ',' + d.y + ']'); |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
Simon Hunt | 902c992 | 2014-11-11 11:59:31 -0800 | [diff] [blame] | 1633 | function sendUpdateMeta(d) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1634 | sendMessage('updateMeta', { |
| 1635 | id: d.id, |
| 1636 | 'class': d.class, |
Simon Hunt | 902c992 | 2014-11-11 11:59:31 -0800 | [diff] [blame] | 1637 | 'memento': { |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1638 | x: d.x, |
| 1639 | y: d.y |
Simon Hunt | 902c992 | 2014-11-11 11:59:31 -0800 | [diff] [blame] | 1640 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 1641 | }); |
| 1642 | } |
| 1643 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1644 | // set up the force layout |
| 1645 | network.force = d3.layout.force() |
| 1646 | .size(forceDim) |
| 1647 | .nodes(network.nodes) |
| 1648 | .links(network.links) |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1649 | .gravity(0.4) |
| 1650 | .friction(0.7) |
| 1651 | .charge(chrg) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1652 | .linkDistance(ldist) |
| 1653 | .linkStrength(lstrg) |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1654 | .on('tick', tick); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1655 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1656 | network.drag = d3u.createDragBehavior(network.force, |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 1657 | selectCb, atDragEnd, panZoom); |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 1658 | |
| 1659 | // create mask layer for when we lose connection to server. |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1660 | // TODO: this should be part of the framework |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 1661 | mask = view.$div.append('div').attr('id','topo-mask'); |
| 1662 | para(mask, 'Oops!'); |
| 1663 | para(mask, 'Web-socket connection to server closed...'); |
| 1664 | para(mask, 'Try refreshing the page.'); |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1665 | } |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1666 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 1667 | function para(sel, text) { |
| 1668 | sel.append('p').text(text); |
| 1669 | } |
| 1670 | |
| 1671 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1672 | function load(view, ctx, flags) { |
Simon Hunt | f67722a | 2014-11-10 09:32:06 -0800 | [diff] [blame] | 1673 | // resize, in case the window was resized while we were not loaded |
| 1674 | resize(view, ctx, flags); |
| 1675 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1676 | // cache the view token, so network topo functions can access it |
| 1677 | network.view = view; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1678 | config.useLiveData = !flags.local; |
| 1679 | |
| 1680 | if (!config.useLiveData) { |
| 1681 | prepareScenario(view, ctx, flags.debug); |
| 1682 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1683 | |
| 1684 | // set our radio buttons and key bindings |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 1685 | view.setRadio(btnSet); |
| 1686 | view.setKeys(keyDispatch); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1687 | |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 1688 | // patch in our "button bar" for now |
| 1689 | // TODO: implement a more official frameworky way of doing this.. |
| 1690 | addButtonBar(view); |
| 1691 | |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1692 | // Load map data asynchronously; complete startup after that.. |
| 1693 | loadGeoJsonData(); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 1694 | |
| 1695 | // start the and timer |
| 1696 | var dashIdx = 0; |
| 1697 | antTimer = setInterval(function () { |
| 1698 | // TODO: figure out how to choose Src-->Dst and Dst-->Src, per link |
| 1699 | dashIdx = dashIdx === 0 ? 14 : dashIdx - 2; |
| 1700 | d3.selectAll('.animated').style('stroke-dashoffset', dashIdx); |
| 1701 | }, 35); |
| 1702 | } |
| 1703 | |
| 1704 | function unload(view, ctx, flags) { |
| 1705 | if (antTimer) { |
| 1706 | clearInterval(antTimer); |
| 1707 | antTimer = null; |
| 1708 | } |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | // TODO: move these to config/state portion of script |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1712 | var geoJsonUrl = 'json/map/continental_us.json', // TODO: Paul |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1713 | geoJson; |
| 1714 | |
| 1715 | function loadGeoJsonData() { |
| 1716 | d3.json(geoJsonUrl, function (err, data) { |
| 1717 | if (err) { |
| 1718 | // fall back to USA map background |
| 1719 | loadStaticMap(); |
| 1720 | } else { |
| 1721 | geoJson = data; |
| 1722 | loadGeoMap(); |
| 1723 | } |
| 1724 | |
| 1725 | // finally, connect to the server... |
| 1726 | if (config.useLiveData) { |
| 1727 | webSock.connect(); |
| 1728 | } |
| 1729 | }); |
| 1730 | } |
| 1731 | |
| 1732 | function showBg() { |
| 1733 | return config.options.showBackground ? 'visible' : 'hidden'; |
| 1734 | } |
| 1735 | |
| 1736 | function loadStaticMap() { |
| 1737 | fnTrace('loadStaticMap', config.backgroundUrl); |
| 1738 | var w = network.view.width(), |
| 1739 | h = network.view.height(); |
| 1740 | |
| 1741 | // load the background image |
| 1742 | bgImg = svg.insert('svg:image', '#topo-G') |
| 1743 | .attr({ |
| 1744 | id: 'topo-bg', |
| 1745 | width: w, |
| 1746 | height: h, |
| 1747 | 'xlink:href': config.backgroundUrl |
| 1748 | }) |
| 1749 | .style({ |
| 1750 | visibility: showBg() |
| 1751 | }); |
| 1752 | } |
| 1753 | |
| 1754 | function loadGeoMap() { |
| 1755 | fnTrace('loadGeoMap', geoJsonUrl); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1756 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1757 | // extracts the topojson data into geocoordinate-based geometry |
| 1758 | var topoData = topojson.feature(geoJson, geoJson.objects.states); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1759 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1760 | // see: http://bl.ocks.org/mbostock/4707858 |
| 1761 | geoMapProjection = d3.geo.mercator(); |
| 1762 | var path = d3.geo.path().projection(geoMapProjection); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1763 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1764 | geoMapProjection |
| 1765 | .scale(1) |
| 1766 | .translate([0, 0]); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1767 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1768 | // [[x1,y1],[x2,y2]] |
| 1769 | var b = path.bounds(topoData); |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1770 | // size map to 95% of minimum dimension to fill space |
| 1771 | var s = .95 / Math.min((b[1][0] - b[0][0]) / config.logicalSize, (b[1][1] - b[0][1]) / config.logicalSize); |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1772 | var t = [(config.logicalSize - s * (b[1][0] + b[0][0])) / 2, (config.logicalSize - s * (b[1][1] + b[0][1])) / 2]; |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 1773 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1774 | geoMapProjection |
| 1775 | .scale(s) |
| 1776 | .translate(t); |
| 1777 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 1778 | bgImg = zoomPanContainer.insert("g", '#topo-G'); |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1779 | bgImg.attr('id', 'map').selectAll('path') |
| 1780 | .data(topoData.features) |
| 1781 | .enter() |
| 1782 | .append('path') |
| 1783 | .attr('d', path); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
Simon Hunt | f67722a | 2014-11-10 09:32:06 -0800 | [diff] [blame] | 1786 | function resize(view, ctx, flags) { |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 1787 | setSize(svg, view); |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | |
| 1791 | // ============================== |
| 1792 | // View registration |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1793 | |
Simon Hunt | 2524891 | 2014-11-04 11:25:48 -0800 | [diff] [blame] | 1794 | onos.ui.addView('topo', { |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 1795 | preload: preload, |
| 1796 | load: load, |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 1797 | unload: unload, |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 1798 | resize: resize |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1799 | }); |
| 1800 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1801 | detailPane = onos.ui.addFloatingPanel('topo-detail'); |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1802 | oiBox = onos.ui.addFloatingPanel('topo-oibox', 'TL'); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1803 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 1804 | }(ONOS)); |