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 |
Simon Hunt | a6a9fe7 | 2014-11-20 11:17:12 -0800 | [diff] [blame] | 21 | @author Thomas Vachuska |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | (function (onos) { |
| 25 | 'use strict'; |
| 26 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 27 | // shorter names for library APIs |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 28 | var d3u = onos.lib.d3util, |
Simon Hunt | a6a9fe7 | 2014-11-20 11:17:12 -0800 | [diff] [blame] | 29 | gly = onos.lib.glyphs; |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 30 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 31 | // configuration data |
| 32 | var config = { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 33 | useLiveData: true, |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 34 | fnTrace: true, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 35 | debugOn: false, |
| 36 | debug: { |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 37 | showNodeXY: true, |
| 38 | showKeyHandler: false |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 39 | }, |
Simon Hunt | 12ce12e | 2014-11-15 21:13:19 -0800 | [diff] [blame] | 40 | birdDim: 400, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 41 | options: { |
| 42 | layering: true, |
| 43 | collisionPrevention: true, |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 44 | showBackground: true |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 45 | }, |
| 46 | backgroundUrl: 'img/us-map.png', |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 47 | webSockUrl: 'ws/topology', |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 48 | data: { |
| 49 | live: { |
| 50 | jsonUrl: 'rs/topology/graph', |
| 51 | detailPrefix: 'rs/topology/graph/', |
| 52 | detailSuffix: '' |
| 53 | }, |
| 54 | fake: { |
| 55 | jsonUrl: 'json/network2.json', |
| 56 | detailPrefix: 'json/', |
| 57 | detailSuffix: '.json' |
| 58 | } |
| 59 | }, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 60 | labels: { |
| 61 | imgPad: 16, |
| 62 | padLR: 4, |
| 63 | padTB: 3, |
| 64 | marginLR: 3, |
| 65 | marginTB: 2, |
| 66 | port: { |
| 67 | gap: 3, |
| 68 | width: 18, |
| 69 | height: 14 |
| 70 | } |
| 71 | }, |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 72 | topo: { |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 73 | linkBaseColor: '#666', |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 74 | linkInColor: '#66f', |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 75 | linkInWidth: 12, |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 76 | linkOutColor: '#f00', |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 77 | linkOutWidth: 10 |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 78 | }, |
Paul Greyson | 29cd58f | 2014-11-18 13:14:57 -0800 | [diff] [blame] | 79 | icons: { |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 80 | device: { |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 81 | dim: 36, |
| 82 | rx: 4, |
| 83 | xoff: -20, |
| 84 | yoff: -18 |
| 85 | }, |
| 86 | host: { |
| 87 | defaultRadius: 9, |
| 88 | radius: { |
| 89 | endstation: 14, |
| 90 | bgpSpeaker: 14, |
| 91 | router: 14 |
| 92 | } |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 93 | } |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 94 | }, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 95 | force: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 96 | note_for_links: 'link.type is used to differentiate', |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 97 | linkDistance: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 98 | direct: 100, |
| 99 | optical: 120, |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 100 | hostLink: 3 |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 101 | }, |
| 102 | linkStrength: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 103 | direct: 1.0, |
| 104 | optical: 1.0, |
| 105 | hostLink: 1.0 |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 106 | }, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 107 | note_for_nodes: 'node.class is used to differentiate', |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 108 | charge: { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 109 | device: -8000, |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 110 | host: -5000 |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 111 | }, |
| 112 | pad: 20, |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 113 | translate: function() { |
| 114 | return 'translate(' + |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 115 | config.force.pad + ',' + |
| 116 | config.force.pad + ')'; |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 117 | } |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 118 | }, |
| 119 | // see below in creation of viewBox on main svg |
| 120 | logicalSize: 1000 |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 123 | // radio buttons |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 124 | var layerButtons = [ |
| 125 | { text: 'All Layers', id: 'all', cb: showAllLayers }, |
| 126 | { text: 'Packet Only', id: 'pkt', cb: showPacketLayer }, |
| 127 | { text: 'Optical Only', id: 'opt', cb: showOpticalLayer } |
| 128 | ], |
| 129 | layerBtnSet, |
| 130 | layerBtnDispatch = { |
| 131 | all: showAllLayers, |
| 132 | pkt: showPacketLayer, |
| 133 | opt: showOpticalLayer |
| 134 | }; |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 135 | |
| 136 | // key bindings |
| 137 | var keyDispatch = { |
Simon Hunt | 988c6fc | 2014-11-20 17:43:03 -0800 | [diff] [blame] | 138 | // TODO: remove these "development only" bindings |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 139 | 0: testMe, |
| 140 | equals: injectStartupEvents, |
| 141 | dash: injectTestEvent, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 142 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 143 | O: [toggleSummary, 'Toggle ONOS summary pane'], |
| 144 | I: [toggleInstances, 'Toggle ONOS instances pane'], |
Simon Hunt | 988c6fc | 2014-11-20 17:43:03 -0800 | [diff] [blame] | 145 | B: [toggleBg, 'Toggle background image'], |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 146 | H: [toggleHosts, 'Toggle host visibility'], |
Simon Hunt | 988c6fc | 2014-11-20 17:43:03 -0800 | [diff] [blame] | 147 | L: [cycleLabels, 'Cycle Device labels'], |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 148 | P: togglePorts, |
Simon Hunt | 8751434 | 2014-11-24 16:41:27 -0800 | [diff] [blame] | 149 | U: [unpin, 'Unpin node (hover mouse over)'], |
| 150 | R: [resetZoomPan, 'Reset zoom / pan'], |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 151 | V: [showTrafficAction, 'Show related traffic'], |
Simon Hunt | 56ef0fe | 2014-11-21 08:24:43 -0800 | [diff] [blame] | 152 | A: [showAllTrafficAction, 'Show all traffic'], |
| 153 | F: [showDeviceLinkFlowsAction, 'Show device link flows'], |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 154 | esc: handleEscape |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 155 | }; |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 156 | |
Simon Hunt | 8751434 | 2014-11-24 16:41:27 -0800 | [diff] [blame] | 157 | // mouse gestures |
| 158 | var gestures = [ |
| 159 | ['click', 'Select the item and show details'], |
| 160 | ['shift-click', 'Toggle selection state'], |
| 161 | ['drag', 'Reposition (and pin) device / host'], |
| 162 | ['cmd-scroll', 'Zoom in / out'], |
| 163 | ['cmd-drag', 'Pan'] |
| 164 | ]; |
| 165 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 166 | // state variables |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 167 | var network = { |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 168 | view: null, // view token reference |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 169 | nodes: [], |
| 170 | links: [], |
Simon Hunt | 269670f | 2014-11-17 16:17:43 -0800 | [diff] [blame] | 171 | lookup: {}, |
| 172 | revLinkToKey: {} |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 173 | }, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 174 | scenario = { |
| 175 | evDir: 'json/ev/', |
| 176 | evScenario: '/scenario.json', |
| 177 | evPrefix: '/ev_', |
| 178 | evOnos: '_onos.json', |
| 179 | evUi: '_ui.json', |
| 180 | ctx: null, |
| 181 | params: {}, |
| 182 | evNumber: 0, |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 183 | view: null |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 184 | }, |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 185 | webSock, |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 186 | sid = 0, |
Thomas Vachuska | 60d72bf | 2014-11-21 13:02:00 -0800 | [diff] [blame] | 187 | deviceLabelCount = 3, |
Simon Hunt | 209155e | 2014-11-21 12:16:09 -0800 | [diff] [blame] | 188 | hostLabelCount = 2, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 189 | deviceLabelIndex = 0, |
| 190 | hostLabelIndex = 0, |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 191 | selections = {}, |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 192 | selectOrder = [], |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 193 | hovered = null, |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 194 | summaryPane, |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 195 | detailPane, |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 196 | antTimer = null, |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 197 | onosInstances = {}, |
| 198 | onosOrder = [], |
| 199 | oiBox, |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 200 | oiShowMaster = false, |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 201 | portLabelsOn = false, |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 202 | cat7 = d3u.cat7(), |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 203 | colorAffinity = false, |
| 204 | showHosts = false; |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 205 | |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 206 | // constants |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 207 | var hoverModeAll = 1, |
| 208 | hoverModeFlows = 2, |
| 209 | hoverModeIntents = 3, |
| 210 | hoverMode = hoverModeFlows; |
| 211 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 212 | // D3 selections |
| 213 | var svg, |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 214 | zoomPanContainer, |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 215 | bgImg, |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 216 | topoG, |
| 217 | nodeG, |
| 218 | linkG, |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 219 | linkLabelG, |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 220 | node, |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 221 | link, |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 222 | linkLabel, |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 223 | mask; |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 224 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 225 | // the projection for the map background |
| 226 | var geoMapProjection; |
| 227 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 228 | // the zoom function |
| 229 | var zoom; |
| 230 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 231 | // ============================== |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 232 | // For Debugging / Development |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 233 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 234 | function note(label, msg) { |
| 235 | console.log('NOTE: ' + label + ': ' + msg); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 238 | function debug(what) { |
| 239 | return config.debugOn && config.debug[what]; |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 242 | function fnTrace(msg, id) { |
| 243 | if (config.fnTrace) { |
| 244 | console.log('FN: ' + msg + ' [' + id + ']'); |
| 245 | } |
| 246 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 247 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 248 | function evTrace(data) { |
| 249 | fnTrace(data.event, data.payload.id); |
| 250 | } |
| 251 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 252 | // ============================== |
| 253 | // Key Callbacks |
| 254 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 255 | function testMe(view) { |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 256 | //view.alert('Theme is ' + view.getTheme()); |
Simon Hunt | a3dd957 | 2014-11-20 15:22:41 -0800 | [diff] [blame] | 257 | //view.flash('This is some text'); |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 258 | cat7.testCard(svg); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 261 | function injectTestEvent(view) { |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 262 | if (config.useLiveData) { return; } |
| 263 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 264 | var sc = scenario, |
| 265 | evn = ++sc.evNumber, |
| 266 | pfx = sc.evDir + sc.ctx + sc.evPrefix + evn, |
| 267 | onosUrl = pfx + sc.evOnos, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 268 | uiUrl = pfx + sc.evUi, |
| 269 | stack = [ |
| 270 | { url: onosUrl, cb: handleServerEvent }, |
| 271 | { url: uiUrl, cb: handleUiEvent } |
| 272 | ]; |
| 273 | recurseFetchEvent(stack, evn); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 276 | function recurseFetchEvent(stack, evn) { |
| 277 | var v = scenario.view, |
| 278 | frame; |
| 279 | if (stack.length === 0) { |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 280 | v.alert('Oops!\n\nNo event #' + evn + ' found.'); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 281 | return; |
| 282 | } |
| 283 | frame = stack.shift(); |
| 284 | |
| 285 | d3.json(frame.url, function (err, data) { |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 286 | if (err) { |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 287 | if (err.status === 404) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 288 | // if we didn't find the data, try the next stack frame |
| 289 | recurseFetchEvent(stack, evn); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 290 | } else { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 291 | v.alert('non-404 error:\n\n' + frame.url + '\n\n' + err); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 292 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 293 | } else { |
Simon Hunt | 1712ed8 | 2014-11-17 12:56:00 -0800 | [diff] [blame] | 294 | wsTrace('test', JSON.stringify(data)); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 295 | frame.cb(data); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 296 | } |
| 297 | }); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 298 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 299 | } |
Simon Hunt | 50128c0 | 2014-11-08 13:36:15 -0800 | [diff] [blame] | 300 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 301 | function handleUiEvent(data) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 302 | scenario.view.alert('UI Tx: ' + data.event + '\n\n' + |
| 303 | JSON.stringify(data)); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | function injectStartupEvents(view) { |
| 307 | var last = scenario.params.lastAuto || 0; |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 308 | if (config.useLiveData) { return; } |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 309 | |
| 310 | while (scenario.evNumber < last) { |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 311 | injectTestEvent(view); |
| 312 | } |
| 313 | } |
| 314 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 315 | function toggleBg() { |
| 316 | var vis = bgImg.style('visibility'); |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 317 | bgImg.style('visibility', visVal(vis === 'hidden')); |
| 318 | } |
| 319 | |
| 320 | function toggleHosts() { |
| 321 | showHosts = !showHosts; |
| 322 | updateHostVisibility(); |
| 323 | network.view.flash('Hosts ' + visVal(showHosts)); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 326 | function cycleLabels() { |
Thomas Vachuska | 60d72bf | 2014-11-21 13:02:00 -0800 | [diff] [blame] | 327 | deviceLabelIndex = (deviceLabelIndex === 2) |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 328 | ? 0 : deviceLabelIndex + 1; |
Simon Hunt | 5f36d34 | 2014-11-08 21:33:14 -0800 | [diff] [blame] | 329 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 330 | network.nodes.forEach(function (d) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 331 | if (d.class === 'device') { |
| 332 | updateDeviceLabel(d); |
| 333 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 334 | }); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | function togglePorts(view) { |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 338 | //view.alert('togglePorts() callback') |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 341 | function unpin() { |
| 342 | if (hovered) { |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 343 | sendUpdateMeta(hovered); |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 344 | hovered.fixed = false; |
| 345 | hovered.el.classed('fixed', false); |
| 346 | network.force.resume(); |
| 347 | } |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 350 | function handleEscape(view) { |
| 351 | if (oiShowMaster) { |
| 352 | cancelAffinity(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 353 | } else if (detailPane.isVisible()) { |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 354 | deselectAll(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 355 | } else if (oiBox.isVisible()) { |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 356 | hideInstances(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 357 | } else if (summaryPane.isVisible()) { |
| 358 | cancelSummary(); |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame] | 359 | stopAntTimer(); |
| 360 | } else { |
| 361 | hoverMode = hoverModeFlows; |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 365 | // ============================== |
| 366 | // Radio Button Callbacks |
| 367 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 368 | var layerLookup = { |
| 369 | host: { |
Simon Hunt | 209155e | 2014-11-21 12:16:09 -0800 | [diff] [blame] | 370 | endstation: 'pkt', // default, if host event does not define type |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 371 | router: 'pkt', |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 372 | bgpSpeaker: 'pkt' |
| 373 | }, |
| 374 | device: { |
| 375 | switch: 'pkt', |
| 376 | roadm: 'opt' |
| 377 | }, |
| 378 | link: { |
| 379 | hostLink: 'pkt', |
| 380 | direct: 'pkt', |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 381 | indirect: '', |
| 382 | tunnel: '', |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 383 | optical: 'opt' |
| 384 | } |
| 385 | }; |
| 386 | |
| 387 | function inLayer(d, layer) { |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 388 | var type = d.class === 'link' ? d.type() : d.type, |
| 389 | look = layerLookup[d.class], |
| 390 | lyr = look && look[type]; |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 391 | return lyr === layer; |
| 392 | } |
| 393 | |
| 394 | function unsuppressLayer(which) { |
| 395 | node.each(function (d) { |
| 396 | var node = d.el; |
| 397 | if (inLayer(d, which)) { |
| 398 | node.classed('suppressed', false); |
| 399 | } |
| 400 | }); |
| 401 | |
| 402 | link.each(function (d) { |
| 403 | var link = d.el; |
| 404 | if (inLayer(d, which)) { |
| 405 | link.classed('suppressed', false); |
| 406 | } |
| 407 | }); |
| 408 | } |
| 409 | |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 410 | function suppressLayers(b) { |
| 411 | node.classed('suppressed', b); |
| 412 | link.classed('suppressed', b); |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 413 | // d3.selectAll('svg .port').classed('inactive', false); |
| 414 | // d3.selectAll('svg .portText').classed('inactive', false); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 417 | function showAllLayers() { |
| 418 | suppressLayers(false); |
| 419 | } |
| 420 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 421 | function showPacketLayer() { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 422 | node.classed('suppressed', true); |
| 423 | link.classed('suppressed', true); |
| 424 | unsuppressLayer('pkt'); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | function showOpticalLayer() { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 428 | node.classed('suppressed', true); |
| 429 | link.classed('suppressed', true); |
| 430 | unsuppressLayer('opt'); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 433 | function restoreLayerState() { |
| 434 | layerBtnDispatch[layerBtnSet.selected()](); |
| 435 | } |
| 436 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 437 | // ============================== |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 438 | // Private functions |
| 439 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 440 | function safeId(s) { |
| 441 | return s.replace(/[^a-z0-9]/gi, '-'); |
| 442 | } |
| 443 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 444 | // set the size of the given element to that of the view (reduced if padded) |
| 445 | function setSize(el, view, pad) { |
| 446 | var padding = pad ? pad * 2 : 0; |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 447 | el.attr({ |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 448 | width: view.width() - padding, |
| 449 | height: view.height() - padding |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 450 | }); |
| 451 | } |
| 452 | |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 453 | function makeNodeKey(d, what) { |
| 454 | var port = what + 'Port'; |
| 455 | return d[what] + '/' + d[port]; |
| 456 | } |
| 457 | |
| 458 | function makeLinkKey(d, flipped) { |
| 459 | var one = flipped ? makeNodeKey(d, 'dst') : makeNodeKey(d, 'src'), |
| 460 | two = flipped ? makeNodeKey(d, 'src') : makeNodeKey(d, 'dst'); |
| 461 | return one + '-' + two; |
| 462 | } |
| 463 | |
Simon Hunt | 269670f | 2014-11-17 16:17:43 -0800 | [diff] [blame] | 464 | function findLinkById(id) { |
| 465 | // check to see if this is a reverse lookup, else default to given id |
| 466 | var key = network.revLinkToKey[id] || id; |
| 467 | return key && network.lookup[key]; |
| 468 | } |
| 469 | |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 470 | function findLink(linkData, op) { |
| 471 | var key = makeLinkKey(linkData), |
| 472 | keyrev = makeLinkKey(linkData, 1), |
| 473 | link = network.lookup[key], |
| 474 | linkRev = network.lookup[keyrev], |
| 475 | result = {}, |
| 476 | ldata = link || linkRev, |
| 477 | rawLink; |
| 478 | |
| 479 | if (op === 'add') { |
| 480 | if (link) { |
| 481 | // trying to add a link that we already know about |
| 482 | result.ldata = link; |
| 483 | result.badLogic = 'addLink: link already added'; |
| 484 | |
| 485 | } else if (linkRev) { |
| 486 | // we found the reverse of the link to be added |
| 487 | result.ldata = linkRev; |
| 488 | if (linkRev.fromTarget) { |
| 489 | result.badLogic = 'addLink: link already added'; |
| 490 | } |
| 491 | } |
| 492 | } else if (op === 'update') { |
| 493 | if (!ldata) { |
| 494 | result.badLogic = 'updateLink: link not found'; |
| 495 | } else { |
| 496 | rawLink = link ? ldata.fromSource : ldata.fromTarget; |
| 497 | result.updateWith = function (data) { |
| 498 | $.extend(rawLink, data); |
| 499 | restyleLinkElement(ldata); |
| 500 | } |
| 501 | } |
| 502 | } else if (op === 'remove') { |
| 503 | if (!ldata) { |
| 504 | result.badLogic = 'removeLink: link not found'; |
| 505 | } else { |
| 506 | rawLink = link ? ldata.fromSource : ldata.fromTarget; |
| 507 | |
| 508 | if (!rawLink) { |
| 509 | result.badLogic = 'removeLink: link not found'; |
| 510 | |
| 511 | } else { |
| 512 | result.removeRawLink = function () { |
| 513 | if (link) { |
| 514 | // remove fromSource |
| 515 | ldata.fromSource = null; |
| 516 | if (ldata.fromTarget) { |
| 517 | // promote target into source position |
| 518 | ldata.fromSource = ldata.fromTarget; |
| 519 | ldata.fromTarget = null; |
| 520 | ldata.key = keyrev; |
| 521 | delete network.lookup[key]; |
| 522 | network.lookup[keyrev] = ldata; |
Simon Hunt | 269670f | 2014-11-17 16:17:43 -0800 | [diff] [blame] | 523 | delete network.revLinkToKey[keyrev]; |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 524 | } |
| 525 | } else { |
| 526 | // remove fromTarget |
| 527 | ldata.fromTarget = null; |
Simon Hunt | 269670f | 2014-11-17 16:17:43 -0800 | [diff] [blame] | 528 | delete network.revLinkToKey[keyrev]; |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 529 | } |
| 530 | if (ldata.fromSource) { |
| 531 | restyleLinkElement(ldata); |
| 532 | } else { |
| 533 | removeLinkElement(ldata); |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | return result; |
| 540 | } |
| 541 | |
| 542 | function addLinkUpdate(ldata, link) { |
| 543 | // add link event, but we already have the reverse link installed |
| 544 | ldata.fromTarget = link; |
Simon Hunt | 269670f | 2014-11-17 16:17:43 -0800 | [diff] [blame] | 545 | network.revLinkToKey[link.id] = ldata.key; |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 546 | restyleLinkElement(ldata); |
| 547 | } |
| 548 | |
| 549 | var allLinkTypes = 'direct indirect optical tunnel', |
| 550 | defaultLinkType = 'direct'; |
| 551 | |
| 552 | function restyleLinkElement(ldata) { |
| 553 | // this fn's job is to look at raw links and decide what svg classes |
| 554 | // need to be applied to the line element in the DOM |
| 555 | var el = ldata.el, |
| 556 | type = ldata.type(), |
| 557 | lw = ldata.linkWidth(), |
| 558 | online = ldata.online(); |
| 559 | |
| 560 | el.classed('link', true); |
| 561 | el.classed('inactive', !online); |
| 562 | el.classed(allLinkTypes, false); |
| 563 | if (type) { |
| 564 | el.classed(type, true); |
| 565 | } |
| 566 | el.transition() |
| 567 | .duration(1000) |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 568 | .attr('stroke-width', linkScale(lw)) |
| 569 | .attr('stroke', config.topo.linkBaseColor); |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 570 | } |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 571 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 572 | // ============================== |
| 573 | // Event handlers for server-pushed events |
| 574 | |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 575 | function logicError(msg) { |
| 576 | // TODO, report logic error to server, via websock, so it can be logged |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 577 | console.warn(msg); |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 578 | } |
| 579 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 580 | var eventDispatch = { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 581 | addInstance: addInstance, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 582 | addDevice: addDevice, |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 583 | addLink: addLink, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 584 | addHost: addHost, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 585 | |
Simon Hunt | fcfb46c | 2014-11-19 12:53:38 -0800 | [diff] [blame] | 586 | updateInstance: updateInstance, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 587 | updateDevice: updateDevice, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 588 | updateLink: updateLink, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 589 | updateHost: updateHost, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 590 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 591 | removeInstance: removeInstance, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 592 | removeDevice: stillToImplement, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 593 | removeLink: removeLink, |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 594 | removeHost: removeHost, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 595 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 596 | showDetails: showDetails, |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 597 | showSummary: showSummary, |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 598 | showTraffic: showTraffic |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 599 | }; |
| 600 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 601 | function addInstance(data) { |
| 602 | evTrace(data); |
| 603 | var inst = data.payload, |
| 604 | id = inst.id; |
| 605 | if (onosInstances[id]) { |
| 606 | logicError('ONOS instance already added: ' + id); |
| 607 | return; |
| 608 | } |
| 609 | onosInstances[id] = inst; |
| 610 | onosOrder.push(inst); |
| 611 | updateInstances(); |
| 612 | } |
| 613 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 614 | function addDevice(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 615 | evTrace(data); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 616 | var device = data.payload, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 617 | nodeData = createDeviceNode(device); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 618 | network.nodes.push(nodeData); |
| 619 | network.lookup[nodeData.id] = nodeData; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 620 | updateNodes(); |
| 621 | network.force.start(); |
| 622 | } |
| 623 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 624 | function addLink(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 625 | evTrace(data); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 626 | var link = data.payload, |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 627 | result = findLink(link, 'add'), |
| 628 | bad = result.badLogic, |
| 629 | ldata = result.ldata; |
| 630 | |
| 631 | if (bad) { |
| 632 | logicError(bad + ': ' + link.id); |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | if (ldata) { |
| 637 | // we already have a backing store link for src/dst nodes |
| 638 | addLinkUpdate(ldata, link); |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | // no backing store link yet |
| 643 | ldata = createLink(link); |
| 644 | if (ldata) { |
| 645 | network.links.push(ldata); |
| 646 | network.lookup[ldata.key] = ldata; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 647 | updateLinks(); |
| 648 | network.force.start(); |
| 649 | } |
| 650 | } |
| 651 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 652 | function addHost(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 653 | evTrace(data); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 654 | var host = data.payload, |
| 655 | node = createHostNode(host), |
| 656 | lnk; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 657 | network.nodes.push(node); |
| 658 | network.lookup[host.id] = node; |
| 659 | updateNodes(); |
| 660 | |
| 661 | lnk = createHostLink(host); |
| 662 | if (lnk) { |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 663 | node.linkData = lnk; // cache ref on its host |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 664 | network.links.push(lnk); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 665 | network.lookup[host.ingress] = lnk; |
| 666 | network.lookup[host.egress] = lnk; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 667 | updateLinks(); |
| 668 | } |
| 669 | network.force.start(); |
| 670 | } |
| 671 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 672 | // TODO: fold updateX(...) methods into one base method; remove duplication |
Simon Hunt | 56a2ea4 | 2014-11-19 12:39:31 -0800 | [diff] [blame] | 673 | |
| 674 | function updateInstance(data) { |
| 675 | evTrace(data); |
| 676 | var inst = data.payload, |
| 677 | id = inst.id, |
| 678 | instData = onosInstances[id]; |
| 679 | if (instData) { |
| 680 | $.extend(instData, inst); |
| 681 | updateInstances(); |
Simon Hunt | 56a2ea4 | 2014-11-19 12:39:31 -0800 | [diff] [blame] | 682 | } else { |
| 683 | logicError('updateInstance lookup fail. ID = "' + id + '"'); |
| 684 | } |
| 685 | } |
| 686 | |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 687 | function updateDevice(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 688 | evTrace(data); |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 689 | var device = data.payload, |
| 690 | id = device.id, |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 691 | d = network.lookup[id]; |
| 692 | if (d) { |
| 693 | $.extend(d, device); |
| 694 | if (positionNode(d, true)) { |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 695 | sendUpdateMeta(d, true); |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 696 | } |
| 697 | updateNodes(); |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 698 | } else { |
| 699 | logicError('updateDevice lookup fail. ID = "' + id + '"'); |
| 700 | } |
| 701 | } |
| 702 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 703 | function updateLink(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 704 | evTrace(data); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 705 | var link = data.payload, |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 706 | result = findLink(link, 'update'), |
| 707 | bad = result.badLogic; |
| 708 | if (bad) { |
| 709 | logicError(bad + ': ' + link.id); |
| 710 | return; |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 711 | } |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 712 | result.updateWith(link); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 713 | } |
| 714 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 715 | function updateHost(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 716 | evTrace(data); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 717 | var host = data.payload, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 718 | id = host.id, |
| 719 | hostData = network.lookup[id]; |
| 720 | if (hostData) { |
| 721 | $.extend(hostData, host); |
| 722 | updateHostState(hostData); |
| 723 | } else { |
| 724 | logicError('updateHost lookup fail. ID = "' + id + '"'); |
| 725 | } |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 728 | // TODO: fold removeX(...) methods into base method - remove dup code |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 729 | function removeInstance(data) { |
| 730 | evTrace(data); |
| 731 | var inst = data.payload, |
| 732 | id = inst.id, |
| 733 | instData = onosInstances[id]; |
| 734 | if (instData) { |
| 735 | var idx = find(id, onosOrder, 'id'); |
| 736 | if (idx >= 0) { |
| 737 | onosOrder.splice(idx, 1); |
| 738 | } |
| 739 | delete onosInstances[id]; |
| 740 | updateInstances(); |
| 741 | } else { |
| 742 | logicError('updateInstance lookup fail. ID = "' + id + '"'); |
| 743 | } |
| 744 | } |
| 745 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 746 | function removeLink(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 747 | evTrace(data); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 748 | var link = data.payload, |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 749 | result = findLink(link, 'remove'), |
| 750 | bad = result.badLogic; |
| 751 | if (bad) { |
| 752 | logicError(bad + ': ' + link.id); |
| 753 | return; |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 754 | } |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 755 | result.removeRawLink(); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 758 | function removeHost(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 759 | evTrace(data); |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 760 | var host = data.payload, |
| 761 | id = host.id, |
| 762 | hostData = network.lookup[id]; |
| 763 | if (hostData) { |
| 764 | removeHostElement(hostData); |
| 765 | } else { |
| 766 | logicError('removeHost lookup fail. ID = "' + id + '"'); |
| 767 | } |
| 768 | } |
| 769 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 770 | function showSummary(data) { |
| 771 | evTrace(data); |
| 772 | populateSummary(data.payload); |
Simon Hunt | 06811b7 | 2014-11-25 18:54:48 -0800 | [diff] [blame] | 773 | showSummaryPane(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 774 | } |
| 775 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 776 | function showDetails(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 777 | evTrace(data); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 778 | populateDetails(data.payload); |
Simon Hunt | 06811b7 | 2014-11-25 18:54:48 -0800 | [diff] [blame] | 779 | showDetailPane(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 782 | function showTraffic(data) { |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 783 | evTrace(data); |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 784 | var paths = data.payload.paths, |
| 785 | hasTraffic = false; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 786 | |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 787 | // Revert any links hilighted previously. |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 788 | link.style('stroke-width', null) |
Thomas Vachuska | a3148a7 | 2014-11-19 21:38:35 -0800 | [diff] [blame] | 789 | .classed('primary secondary animated optical', false); |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 790 | // Remove all previous labels. |
| 791 | removeLinkLabels(); |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 792 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 793 | // Now hilight all links in the paths payload, and attach |
| 794 | // labels to them, if they are defined. |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 795 | paths.forEach(function (p) { |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 796 | var n = p.links.length, |
| 797 | i, |
| 798 | ldata; |
| 799 | |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 800 | hasTraffic = hasTraffic || p.traffic; |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 801 | for (i=0; i<n; i++) { |
| 802 | ldata = findLinkById(p.links[i]); |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 803 | if (ldata && ldata.el) { |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 804 | ldata.el.classed(p.class, true); |
| 805 | ldata.label = p.labels[i]; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 806 | } |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 807 | } |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 808 | }); |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 809 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 810 | updateLinks(); |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 811 | |
| 812 | if (hasTraffic && !antTimer) { |
| 813 | startAntTimer(); |
| 814 | } else if (!hasTraffic && antTimer) { |
| 815 | stopAntTimer(); |
| 816 | } |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 817 | } |
| 818 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 819 | // ............................... |
| 820 | |
| 821 | function stillToImplement(data) { |
| 822 | var p = data.payload; |
| 823 | note(data.event, p.id); |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 824 | if (!config.useLiveData) { |
| 825 | network.view.alert('Not yet implemented: "' + data.event + '"'); |
| 826 | } |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 827 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 828 | |
| 829 | function unknownEvent(data) { |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 830 | console.warn('Unknown event type: "' + data.event + '"', data); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | function handleServerEvent(data) { |
| 834 | var fn = eventDispatch[data.event] || unknownEvent; |
| 835 | fn(data); |
| 836 | } |
| 837 | |
| 838 | // ============================== |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 839 | // Out-going messages... |
| 840 | |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 841 | function nSel() { |
| 842 | return selectOrder.length; |
| 843 | } |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 844 | function getSel(idx) { |
| 845 | return selections[selectOrder[idx]]; |
| 846 | } |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 847 | function getSelId(idx) { |
| 848 | return getSel(idx).obj.id; |
| 849 | } |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 850 | function getSelIds(start, endOffset) { |
| 851 | var end = selectOrder.length - endOffset; |
| 852 | var ids = []; |
| 853 | selectOrder.slice(start, end).forEach(function (d) { |
| 854 | ids.push(getSelId(d)); |
| 855 | }); |
| 856 | return ids; |
| 857 | } |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 858 | function allSelectionsClass(cls) { |
| 859 | for (var i=0, n=nSel(); i<n; i++) { |
| 860 | if (getSel(i).obj.class !== cls) { |
| 861 | return false; |
| 862 | } |
| 863 | } |
| 864 | return true; |
| 865 | } |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 866 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 867 | function toggleInstances() { |
| 868 | if (!oiBox.isVisible()) { |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 869 | showInstances(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 870 | } else { |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 871 | hideInstances(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 875 | function showInstances() { |
| 876 | oiBox.show(); |
| 877 | colorAffinity = true; |
| 878 | updateDeviceColors(); |
| 879 | } |
| 880 | |
| 881 | function hideInstances() { |
| 882 | oiBox.hide(); |
| 883 | colorAffinity = false; |
| 884 | cancelAffinity(); |
| 885 | updateDeviceColors(); |
| 886 | } |
| 887 | |
| 888 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 889 | function toggleSummary() { |
| 890 | if (!summaryPane.isVisible()) { |
| 891 | requestSummary(); |
| 892 | } else { |
| 893 | cancelSummary(); |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | // request overall summary data |
| 898 | function requestSummary() { |
| 899 | sendMessage('requestSummary', {}); |
| 900 | } |
| 901 | |
| 902 | function cancelSummary() { |
| 903 | sendMessage('cancelSummary', {}); |
Simon Hunt | 06811b7 | 2014-11-25 18:54:48 -0800 | [diff] [blame] | 904 | hideSummaryPane(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 905 | } |
| 906 | |
Simon Hunt | 06811b7 | 2014-11-25 18:54:48 -0800 | [diff] [blame] | 907 | // encapsulate interaction between summary and details panes |
| 908 | function showSummaryPane() { |
| 909 | if (detailPane.isVisible()) { |
| 910 | detailPane.down(summaryPane.show); |
| 911 | } else { |
| 912 | summaryPane.show(); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | function hideSummaryPane() { |
| 917 | summaryPane.hide(function () { |
| 918 | if (detailPane.isVisible()) { |
| 919 | detailPane.up(); |
| 920 | } |
| 921 | }); |
| 922 | } |
| 923 | |
| 924 | function showDetailPane() { |
| 925 | if (summaryPane.isVisible()) { |
| 926 | detailPane.down(detailPane.show); |
| 927 | } else { |
| 928 | detailPane.up(detailPane.show); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | function hideDetailPane() { |
| 933 | detailPane.hide(); |
| 934 | } |
| 935 | |
| 936 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 937 | // request details for the selected element |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 938 | // invoked from selection of a single node. |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 939 | function requestDetails() { |
| 940 | var data = getSel(0).obj, |
| 941 | payload = { |
| 942 | id: data.id, |
| 943 | class: data.class |
| 944 | }; |
| 945 | sendMessage('requestDetails', payload); |
| 946 | } |
| 947 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 948 | function addHostIntentAction() { |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 949 | sendMessage('addHostIntent', { |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 950 | one: selectOrder[0], |
| 951 | two: selectOrder[1], |
| 952 | ids: selectOrder |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 953 | }); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 954 | network.view.flash('Host-to-Host flow added'); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 955 | } |
| 956 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 957 | function addMultiSourceIntentAction() { |
| 958 | sendMessage('addMultiSourceIntent', { |
| 959 | src: selectOrder.slice(0, selectOrder.length - 1), |
| 960 | dst: selectOrder[selectOrder.length - 1], |
| 961 | ids: selectOrder |
| 962 | }); |
| 963 | network.view.flash('Multi-Source flow added'); |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 964 | } |
| 965 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 966 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 967 | function cancelTraffic() { |
| 968 | sendMessage('cancelTraffic', {}); |
| 969 | } |
| 970 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 971 | function requestTrafficForMode() { |
| 972 | if (hoverMode === hoverModeAll) { |
| 973 | requestAllTraffic(); |
| 974 | } else if (hoverMode === hoverModeFlows) { |
| 975 | requestDeviceLinkFlows(); |
| 976 | } else if (hoverMode === hoverModeIntents) { |
| 977 | requestSelectTraffic(); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 978 | } |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 979 | } |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 980 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 981 | function showTrafficAction() { |
| 982 | hoverMode = hoverModeIntents; |
| 983 | requestSelectTraffic(); |
| 984 | network.view.flash('Related Traffic'); |
| 985 | } |
| 986 | |
| 987 | function requestSelectTraffic() { |
| 988 | if (validateSelectionContext()) { |
| 989 | var hoverId = (hoverMode === hoverModeIntents && hovered && |
| 990 | (hovered.class === 'host' || hovered.class === 'device')) |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 991 | ? hovered.id : ''; |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 992 | sendMessage('requestTraffic', { |
| 993 | ids: selectOrder, |
| 994 | hover: hoverId |
| 995 | }); |
| 996 | } |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 997 | } |
| 998 | |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 999 | |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 1000 | function showDeviceLinkFlowsAction() { |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 1001 | hoverMode = hoverModeFlows; |
| 1002 | requestDeviceLinkFlows(); |
Thomas Vachuska | c59658c | 2014-11-21 13:13:36 -0800 | [diff] [blame] | 1003 | network.view.flash('Device Flows'); |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 1006 | function requestDeviceLinkFlows() { |
| 1007 | if (validateSelectionContext()) { |
| 1008 | var hoverId = (hoverMode === hoverModeFlows && hovered && |
| 1009 | (hovered.class === 'device')) ? hovered.id : ''; |
| 1010 | sendMessage('requestDeviceLinkFlows', { |
| 1011 | ids: selectOrder, |
| 1012 | hover: hoverId |
| 1013 | }); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | function showAllTrafficAction() { |
| 1019 | hoverMode = hoverModeAll; |
| 1020 | requestAllTraffic(); |
| 1021 | network.view.flash('All Traffic'); |
| 1022 | } |
| 1023 | |
| 1024 | function requestAllTraffic() { |
| 1025 | sendMessage('requestAllTraffic', {}); |
| 1026 | } |
| 1027 | |
| 1028 | function validateSelectionContext() { |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 1029 | if (!hovered && nSel() === 0) { |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 1030 | cancelTraffic(); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 1031 | return false; |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 1032 | } |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 1033 | return true; |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 1034 | } |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 1035 | |
Simon Hunt | a6a9fe7 | 2014-11-20 11:17:12 -0800 | [diff] [blame] | 1036 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 1037 | // ============================== |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1038 | // onos instance panel functions |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1039 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1040 | var instCfg = { |
| 1041 | rectPad: 8, |
| 1042 | nodeOx: 9, |
| 1043 | nodeOy: 9, |
| 1044 | nodeDim: 40, |
| 1045 | birdOx: 19, |
| 1046 | birdOy: 21, |
| 1047 | birdDim: 21, |
| 1048 | uiDy: 45, |
| 1049 | titleDy: 30, |
| 1050 | textYOff: 20, |
| 1051 | textYSpc: 15 |
| 1052 | }; |
| 1053 | |
| 1054 | function viewBox(dim) { |
| 1055 | return '0 0 ' + dim.w + ' ' + dim.h; |
| 1056 | } |
| 1057 | |
| 1058 | function instRectAttr(dim) { |
| 1059 | var pad = instCfg.rectPad; |
| 1060 | return { |
| 1061 | x: pad, |
| 1062 | y: pad, |
| 1063 | width: dim.w - pad*2, |
| 1064 | height: dim.h - pad*2, |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1065 | rx: 6 |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1066 | }; |
| 1067 | } |
| 1068 | |
| 1069 | function computeDim(self) { |
| 1070 | var css = window.getComputedStyle(self); |
| 1071 | return { |
| 1072 | w: stripPx(css.width), |
| 1073 | h: stripPx(css.height) |
| 1074 | }; |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1075 | } |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1076 | |
| 1077 | function updateInstances() { |
| 1078 | var onoses = oiBox.el.selectAll('.onosInst') |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1079 | .data(onosOrder, function (d) { return d.id; }), |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1080 | instDim = {w:0,h:0}, |
| 1081 | c = instCfg; |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1082 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1083 | function nSw(n) { |
| 1084 | return '# Switches: ' + n; |
| 1085 | } |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1086 | |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1087 | // operate on existing onos instances if necessary |
| 1088 | onoses.each(function (d) { |
| 1089 | var el = d3.select(this), |
| 1090 | svg = el.select('svg'); |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1091 | instDim = computeDim(this); |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1092 | |
| 1093 | // update online state |
| 1094 | el.classed('online', d.online); |
| 1095 | |
| 1096 | // update ui-attached state |
| 1097 | svg.select('use.uiBadge').remove(); |
| 1098 | if (d.uiAttached) { |
| 1099 | attachUiBadge(svg); |
| 1100 | } |
| 1101 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1102 | function updAttr(id, value) { |
| 1103 | svg.select('text.instLabel.'+id).text(value); |
| 1104 | } |
| 1105 | |
| 1106 | updAttr('ip', d.ip); |
| 1107 | updAttr('ns', nSw(d.switches)); |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1108 | }); |
| 1109 | |
| 1110 | |
| 1111 | // operate on new onos instances |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1112 | var entering = onoses.enter() |
| 1113 | .append('div') |
| 1114 | .attr('class', 'onosInst') |
| 1115 | .classed('online', function (d) { return d.online; }) |
Simon Hunt | 9c15eca | 2014-11-15 18:37:59 -0800 | [diff] [blame] | 1116 | .on('click', clickInst); |
| 1117 | |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1118 | entering.each(function (d) { |
Simon Hunt | 9c15eca | 2014-11-15 18:37:59 -0800 | [diff] [blame] | 1119 | var el = d3.select(this), |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1120 | rectAttr, |
| 1121 | svg; |
| 1122 | instDim = computeDim(this); |
| 1123 | rectAttr = instRectAttr(instDim); |
Simon Hunt | 9c15eca | 2014-11-15 18:37:59 -0800 | [diff] [blame] | 1124 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1125 | svg = el.append('svg').attr({ |
| 1126 | width: instDim.w, |
| 1127 | height: instDim.h, |
| 1128 | viewBox: viewBox(instDim) |
Simon Hunt | 9590801 | 2014-11-20 10:20:26 -0800 | [diff] [blame] | 1129 | }); |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1130 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1131 | svg.append('rect').attr(rectAttr); |
Simon Hunt | 9c15eca | 2014-11-15 18:37:59 -0800 | [diff] [blame] | 1132 | |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 1133 | //appendGlyph(svg, c.nodeOx, c.nodeOy, c.nodeDim, '#node'); |
| 1134 | appendBadge(svg, 14, 14, 28, '#bird'); |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 1135 | |
| 1136 | if (d.uiAttached) { |
| 1137 | attachUiBadge(svg); |
| 1138 | } |
| 1139 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1140 | var left = c.nodeOx + c.nodeDim, |
| 1141 | len = rectAttr.width - left, |
| 1142 | hlen = len / 2, |
| 1143 | midline = hlen + left; |
Simon Hunt | 9c15eca | 2014-11-15 18:37:59 -0800 | [diff] [blame] | 1144 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1145 | // title |
| 1146 | svg.append('text') |
| 1147 | .attr({ |
| 1148 | class: 'instTitle', |
| 1149 | x: midline, |
| 1150 | y: c.titleDy |
| 1151 | }) |
| 1152 | .text(d.id); |
| 1153 | |
| 1154 | // a couple of attributes |
| 1155 | var ty = c.titleDy + c.textYOff; |
| 1156 | |
| 1157 | function addAttr(id, label) { |
| 1158 | svg.append('text').attr({ |
| 1159 | class: 'instLabel ' + id, |
| 1160 | x: midline, |
| 1161 | y: ty |
| 1162 | }).text(label); |
| 1163 | ty += c.textYSpc; |
| 1164 | } |
| 1165 | |
| 1166 | addAttr('ip', d.ip); |
| 1167 | addAttr('ns', nSw(d.switches)); |
Simon Hunt | 9c15eca | 2014-11-15 18:37:59 -0800 | [diff] [blame] | 1168 | }); |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1169 | |
| 1170 | // operate on existing + new onoses here |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 1171 | // set the affinity colors... |
| 1172 | onoses.each(function (d) { |
| 1173 | var el = d3.select(this), |
| 1174 | rect = el.select('svg').select('rect'), |
| 1175 | col = instColor(d.id, d.online); |
| 1176 | rect.style('fill', col); |
| 1177 | }); |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1178 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1179 | // adjust the panel size appropriately... |
| 1180 | oiBox.width(instDim.w * onosOrder.length); |
| 1181 | oiBox.height(instDim.h); |
| 1182 | |
| 1183 | // remove any outgoing instances |
| 1184 | onoses.exit().remove(); |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1185 | } |
| 1186 | |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 1187 | function instColor(id, online) { |
| 1188 | return cat7.get(id, !online, network.view.getTheme()); |
| 1189 | } |
| 1190 | |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 1191 | function clickInst(d) { |
| 1192 | var el = d3.select(this), |
| 1193 | aff = el.classed('affinity'); |
| 1194 | if (!aff) { |
| 1195 | setAffinity(el, d); |
| 1196 | } else { |
| 1197 | cancelAffinity(); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | function setAffinity(el, d) { |
| 1202 | d3.selectAll('.onosInst') |
| 1203 | .classed('mastership', true) |
| 1204 | .classed('affinity', false); |
| 1205 | el.classed('affinity', true); |
| 1206 | |
| 1207 | suppressLayers(true); |
| 1208 | node.each(function (n) { |
| 1209 | if (n.master === d.id) { |
| 1210 | n.el.classed('suppressed', false); |
| 1211 | } |
| 1212 | }); |
| 1213 | oiShowMaster = true; |
| 1214 | } |
| 1215 | |
| 1216 | function cancelAffinity() { |
| 1217 | d3.selectAll('.onosInst') |
| 1218 | .classed('mastership affinity', false); |
| 1219 | restoreLayerState(); |
| 1220 | oiShowMaster = false; |
| 1221 | } |
| 1222 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1223 | // TODO: these should be moved out to utility module. |
| 1224 | function stripPx(s) { |
| 1225 | return s.replace(/px$/,''); |
| 1226 | } |
| 1227 | |
| 1228 | function appendUse(svg, ox, oy, dim, iid, cls) { |
| 1229 | var use = svg.append('use').attr({ |
| 1230 | transform: translate(ox,oy), |
| 1231 | 'xlink:href': iid, |
| 1232 | width: dim, |
| 1233 | height: dim |
| 1234 | }); |
| 1235 | if (cls) { |
| 1236 | use.classed(cls, true); |
| 1237 | } |
| 1238 | return use; |
| 1239 | } |
| 1240 | |
| 1241 | function appendGlyph(svg, ox, oy, dim, iid, cls) { |
| 1242 | appendUse(svg, ox, oy, dim, iid, cls).classed('glyphIcon', true); |
| 1243 | } |
| 1244 | |
| 1245 | function appendBadge(svg, ox, oy, dim, iid, cls) { |
| 1246 | appendUse(svg, ox, oy, dim, iid,cls ).classed('badgeIcon', true); |
| 1247 | } |
| 1248 | |
| 1249 | function attachUiBadge(svg) { |
| 1250 | appendBadge(svg, 12, instCfg.uiDy, 30, '#uiAttached', 'uiBadge'); |
| 1251 | } |
| 1252 | |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 1253 | function visVal(b) { |
| 1254 | return b ? 'visible' : 'hidden'; |
| 1255 | } |
| 1256 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 1257 | // ============================== |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1258 | // force layout modification functions |
| 1259 | |
| 1260 | function translate(x, y) { |
| 1261 | return 'translate(' + x + ',' + y + ')'; |
| 1262 | } |
| 1263 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 1264 | function rotate(deg) { |
| 1265 | return 'rotate(' + deg + ')'; |
| 1266 | } |
| 1267 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1268 | function missMsg(what, id) { |
| 1269 | return '\n[' + what + '] "' + id + '" missing '; |
| 1270 | } |
| 1271 | |
| 1272 | function linkEndPoints(srcId, dstId) { |
| 1273 | var srcNode = network.lookup[srcId], |
| 1274 | dstNode = network.lookup[dstId], |
| 1275 | sMiss = !srcNode ? missMsg('src', srcId) : '', |
| 1276 | dMiss = !dstNode ? missMsg('dst', dstId) : ''; |
| 1277 | |
| 1278 | if (sMiss || dMiss) { |
| 1279 | logicError('Node(s) not on map for link:\n' + sMiss + dMiss); |
| 1280 | return null; |
| 1281 | } |
| 1282 | return { |
| 1283 | source: srcNode, |
| 1284 | target: dstNode, |
| 1285 | x1: srcNode.x, |
| 1286 | y1: srcNode.y, |
| 1287 | x2: dstNode.x, |
| 1288 | y2: dstNode.y |
| 1289 | }; |
| 1290 | } |
| 1291 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1292 | function createHostLink(host) { |
| 1293 | var src = host.id, |
| 1294 | dst = host.cp.device, |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1295 | id = host.ingress, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1296 | lnk = linkEndPoints(src, dst); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1297 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1298 | if (!lnk) { |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1299 | return null; |
| 1300 | } |
| 1301 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1302 | // Synthesize link ... |
| 1303 | $.extend(lnk, { |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 1304 | key: id, |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1305 | class: 'link', |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 1306 | |
| 1307 | type: function () { return 'hostLink'; }, |
| 1308 | // TODO: ideally, we should see if our edge switch is online... |
| 1309 | online: function () { return true; }, |
| 1310 | linkWidth: function () { return 1; } |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1311 | }); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1312 | return lnk; |
| 1313 | } |
| 1314 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1315 | function createLink(link) { |
Simon Hunt | a6a9fe7 | 2014-11-20 11:17:12 -0800 | [diff] [blame] | 1316 | var lnk = linkEndPoints(link.src, link.dst); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1317 | |
| 1318 | if (!lnk) { |
| 1319 | return null; |
| 1320 | } |
| 1321 | |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 1322 | $.extend(lnk, { |
| 1323 | key: link.id, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1324 | class: 'link', |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 1325 | fromSource: link, |
| 1326 | |
| 1327 | // functions to aggregate dual link state |
| 1328 | type: function () { |
| 1329 | var s = lnk.fromSource, |
| 1330 | t = lnk.fromTarget; |
| 1331 | return (s && s.type) || (t && t.type) || defaultLinkType; |
| 1332 | }, |
| 1333 | online: function () { |
| 1334 | var s = lnk.fromSource, |
| 1335 | t = lnk.fromTarget; |
| 1336 | return (s && s.online) || (t && t.online); |
| 1337 | }, |
| 1338 | linkWidth: function () { |
| 1339 | var s = lnk.fromSource, |
| 1340 | t = lnk.fromTarget, |
| 1341 | ws = (s && s.linkWidth) || 0, |
| 1342 | wt = (t && t.linkWidth) || 0; |
| 1343 | return Math.max(ws, wt); |
| 1344 | } |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1345 | }); |
| 1346 | return lnk; |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 1349 | function removeLinkLabels() { |
| 1350 | network.links.forEach(function (d) { |
| 1351 | d.label = ''; |
| 1352 | }); |
| 1353 | } |
| 1354 | |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 1355 | function showHostVis(el) { |
| 1356 | el.style('visibility', visVal(showHosts)); |
| 1357 | } |
| 1358 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1359 | var widthRatio = 1.4, |
| 1360 | linkScale = d3.scale.linear() |
| 1361 | .domain([1, 12]) |
| 1362 | .range([widthRatio, 12 * widthRatio]) |
| 1363 | .clamp(true); |
| 1364 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1365 | function updateLinks() { |
| 1366 | link = linkG.selectAll('.link') |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 1367 | .data(network.links, function (d) { return d.key; }); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1368 | |
| 1369 | // operate on existing links, if necessary |
| 1370 | // link .foo() .bar() ... |
| 1371 | |
| 1372 | // operate on entering links: |
| 1373 | var entering = link.enter() |
| 1374 | .append('line') |
| 1375 | .attr({ |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1376 | x1: function (d) { return d.x1; }, |
| 1377 | y1: function (d) { return d.y1; }, |
| 1378 | x2: function (d) { return d.x2; }, |
| 1379 | y2: function (d) { return d.y2; }, |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1380 | stroke: config.topo.linkInColor, |
| 1381 | 'stroke-width': config.topo.linkInWidth |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1382 | }); |
| 1383 | |
| 1384 | // augment links |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1385 | entering.each(function (d) { |
| 1386 | var link = d3.select(this); |
| 1387 | // provide ref to element selection from backing data.... |
| 1388 | d.el = link; |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 1389 | restyleLinkElement(d); |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 1390 | if (d.type() === 'hostLink') { |
| 1391 | showHostVis(link); |
| 1392 | } |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1393 | }); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 1394 | |
| 1395 | // operate on both existing and new links, if necessary |
| 1396 | //link .foo() .bar() ... |
| 1397 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 1398 | // apply or remove labels |
| 1399 | var labelData = getLabelData(); |
| 1400 | applyLinkLabels(labelData); |
| 1401 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 1402 | // operate on exiting links: |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 1403 | link.exit() |
Simon Hunt | 13bf9c8 | 2014-11-18 07:26:44 -0800 | [diff] [blame] | 1404 | .attr('stroke-dasharray', '3, 3') |
| 1405 | .style('opacity', 0.5) |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1406 | .transition() |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1407 | .duration(1500) |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1408 | .attr({ |
Simon Hunt | 13bf9c8 | 2014-11-18 07:26:44 -0800 | [diff] [blame] | 1409 | 'stroke-dasharray': '3, 12', |
| 1410 | stroke: config.topo.linkOutColor, |
| 1411 | 'stroke-width': config.topo.linkOutWidth |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1412 | }) |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1413 | .style('opacity', 0.0) |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 1414 | .remove(); |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 1415 | |
| 1416 | // NOTE: invoke a single tick to force the labels to position |
| 1417 | // onto their links. |
| 1418 | tick(); |
| 1419 | } |
| 1420 | |
| 1421 | function getLabelData() { |
| 1422 | // create the backing data for showing labels.. |
| 1423 | var data = []; |
| 1424 | link.each(function (d) { |
| 1425 | if (d.label) { |
| 1426 | data.push({ |
| 1427 | id: 'lab-' + d.key, |
| 1428 | key: d.key, |
| 1429 | label: d.label, |
| 1430 | ldata: d |
| 1431 | }); |
| 1432 | } |
| 1433 | }); |
| 1434 | return data; |
| 1435 | } |
| 1436 | |
| 1437 | var linkLabelOffset = '0.3em'; |
| 1438 | |
| 1439 | function applyLinkLabels(data) { |
| 1440 | var entering; |
| 1441 | |
| 1442 | linkLabel = linkLabelG.selectAll('.linkLabel') |
| 1443 | .data(data, function (d) { return d.id; }); |
| 1444 | |
Simon Hunt | 56a2ea4 | 2014-11-19 12:39:31 -0800 | [diff] [blame] | 1445 | // for elements already existing, we need to update the text |
| 1446 | // and adjust the rectangle size to fit |
| 1447 | linkLabel.each(function (d) { |
| 1448 | var el = d3.select(this), |
| 1449 | rect = el.select('rect'), |
| 1450 | text = el.select('text'); |
| 1451 | text.text(d.label); |
| 1452 | rect.attr(rectAroundText(el)); |
| 1453 | }); |
Thomas Vachuska | f75b7ab | 2014-11-19 12:15:55 -0800 | [diff] [blame] | 1454 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 1455 | entering = linkLabel.enter().append('g') |
| 1456 | .classed('linkLabel', true) |
| 1457 | .attr('id', function (d) { return d.id; }); |
| 1458 | |
| 1459 | entering.each(function (d) { |
| 1460 | var el = d3.select(this), |
| 1461 | rect, |
| 1462 | text, |
| 1463 | parms = { |
| 1464 | x1: d.ldata.x1, |
| 1465 | y1: d.ldata.y1, |
| 1466 | x2: d.ldata.x2, |
| 1467 | y2: d.ldata.y2 |
| 1468 | }; |
| 1469 | |
| 1470 | d.el = el; |
| 1471 | rect = el.append('rect'); |
| 1472 | text = el.append('text').text(d.label); |
| 1473 | rect.attr(rectAroundText(el)); |
| 1474 | text.attr('dy', linkLabelOffset); |
| 1475 | |
| 1476 | el.attr('transform', transformLabel(parms)); |
| 1477 | }); |
| 1478 | |
| 1479 | // Remove any links that are no longer required. |
| 1480 | linkLabel.exit().remove(); |
| 1481 | } |
| 1482 | |
| 1483 | function rectAroundText(el) { |
| 1484 | var text = el.select('text'), |
| 1485 | box = text.node().getBBox(); |
| 1486 | |
| 1487 | // translate the bbox so that it is centered on [x,y] |
| 1488 | box.x = -box.width / 2; |
| 1489 | box.y = -box.height / 2; |
| 1490 | |
| 1491 | // add padding |
| 1492 | box.x -= 1; |
| 1493 | box.width += 2; |
| 1494 | return box; |
| 1495 | } |
| 1496 | |
| 1497 | function transformLabel(p) { |
| 1498 | var dx = p.x2 - p.x1, |
| 1499 | dy = p.y2 - p.y1, |
| 1500 | xMid = dx/2 + p.x1, |
| 1501 | yMid = dy/2 + p.y1; |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 1502 | return translate(xMid, yMid); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | function createDeviceNode(device) { |
| 1506 | // start with the object as is |
| 1507 | var node = device, |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1508 | type = device.type, |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1509 | svgCls = type ? 'node device ' + type : 'node device', |
| 1510 | labels = device.labels || []; |
| 1511 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1512 | // Augment as needed... |
| 1513 | node.class = 'device'; |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1514 | node.svgClass = device.online ? svgCls + ' online' : svgCls; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1515 | positionNode(node); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1516 | return node; |
| 1517 | } |
| 1518 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1519 | function createHostNode(host) { |
| 1520 | // start with the object as is |
| 1521 | var node = host; |
| 1522 | |
| 1523 | // Augment as needed... |
| 1524 | node.class = 'host'; |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1525 | if (!node.type) { |
Simon Hunt | 209155e | 2014-11-21 12:16:09 -0800 | [diff] [blame] | 1526 | node.type = 'endstation'; |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1527 | } |
Simon Hunt | 7fa116d | 2014-11-17 14:16:55 -0800 | [diff] [blame] | 1528 | node.svgClass = 'node host ' + node.type; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1529 | positionNode(node); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1530 | return node; |
| 1531 | } |
| 1532 | |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1533 | function positionNode(node, forUpdate) { |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1534 | var meta = node.metaUi, |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 1535 | x = meta && meta.x, |
| 1536 | y = meta && meta.y, |
| 1537 | xy; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1538 | |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 1539 | // If we have [x,y] already, use that... |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1540 | if (x && y) { |
| 1541 | node.fixed = true; |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1542 | node.px = node.x = x; |
| 1543 | node.py = node.y = y; |
| 1544 | //node.px = x; |
| 1545 | //node.py = y; |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 1546 | return; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1547 | } |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 1548 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1549 | var location = node.location; |
| 1550 | if (location && location.type === 'latlng') { |
| 1551 | var coord = geoMapProjection([location.lng, location.lat]); |
| 1552 | node.fixed = true; |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1553 | node.px = node.x = coord[0]; |
| 1554 | node.py = node.y = coord[1]; |
| 1555 | //node.x = coord[0]; |
| 1556 | //node.y = coord[1]; |
| 1557 | return true; |
| 1558 | } |
| 1559 | |
| 1560 | // if this is a node update (not a node add).. skip randomizer |
| 1561 | if (forUpdate) { |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 1562 | return; |
| 1563 | } |
| 1564 | |
Simon Hunt | ac9e24f | 2014-11-12 10:12:21 -0800 | [diff] [blame] | 1565 | // Note: Placing incoming unpinned nodes at exactly the same point |
| 1566 | // (center of the view) causes them to explode outwards when |
| 1567 | // the force layout kicks in. So, we spread them out a bit |
| 1568 | // initially, to provide a more serene layout convergence. |
| 1569 | // Additionally, if the node is a host, we place it near |
| 1570 | // the device it is connected to. |
| 1571 | |
| 1572 | function spread(s) { |
| 1573 | return Math.floor((Math.random() * s) - s/2); |
| 1574 | } |
| 1575 | |
| 1576 | function randDim(dim) { |
| 1577 | return dim / 2 + spread(dim * 0.7071); |
| 1578 | } |
| 1579 | |
| 1580 | function rand() { |
| 1581 | return { |
| 1582 | x: randDim(network.view.width()), |
| 1583 | y: randDim(network.view.height()) |
| 1584 | }; |
| 1585 | } |
| 1586 | |
| 1587 | function near(node) { |
| 1588 | var min = 12, |
| 1589 | dx = spread(12), |
| 1590 | dy = spread(12); |
| 1591 | return { |
| 1592 | x: node.x + min + dx, |
| 1593 | y: node.y + min + dy |
| 1594 | }; |
| 1595 | } |
| 1596 | |
| 1597 | function getDevice(cp) { |
| 1598 | var d = network.lookup[cp.device]; |
| 1599 | return d || rand(); |
| 1600 | } |
| 1601 | |
| 1602 | xy = (node.class === 'host') ? near(getDevice(node.cp)) : rand(); |
| 1603 | $.extend(node, xy); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1606 | |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1607 | function iconGlyphUrl(d) { |
| 1608 | var which = d.type || 'unknown'; |
| 1609 | return '#' + which; |
| 1610 | } |
| 1611 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1612 | // returns the newly computed bounding box of the rectangle |
| 1613 | function adjustRectToFitText(n) { |
| 1614 | var text = n.select('text'), |
| 1615 | box = text.node().getBBox(), |
| 1616 | lab = config.labels; |
| 1617 | |
| 1618 | text.attr('text-anchor', 'middle') |
| 1619 | .attr('y', '-0.8em') |
| 1620 | .attr('x', lab.imgPad/2); |
| 1621 | |
| 1622 | // translate the bbox so that it is centered on [x,y] |
| 1623 | box.x = -box.width / 2; |
| 1624 | box.y = -box.height / 2; |
| 1625 | |
| 1626 | // add padding |
| 1627 | box.x -= (lab.padLR + lab.imgPad/2); |
| 1628 | box.width += lab.padLR * 2 + lab.imgPad; |
| 1629 | box.y -= lab.padTB; |
| 1630 | box.height += lab.padTB * 2; |
| 1631 | |
| 1632 | return box; |
| 1633 | } |
| 1634 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1635 | function mkSvgClass(d) { |
| 1636 | return d.fixed ? d.svgClass + ' fixed' : d.svgClass; |
| 1637 | } |
| 1638 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1639 | function hostLabel(d) { |
| 1640 | var idx = (hostLabelIndex < d.labels.length) ? hostLabelIndex : 0; |
| 1641 | return d.labels[idx]; |
| 1642 | } |
| 1643 | function deviceLabel(d) { |
| 1644 | var idx = (deviceLabelIndex < d.labels.length) ? deviceLabelIndex : 0; |
| 1645 | return d.labels[idx]; |
| 1646 | } |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1647 | function trimLabel(label) { |
| 1648 | return (label && label.trim()) || ''; |
| 1649 | } |
| 1650 | |
| 1651 | function emptyBox() { |
| 1652 | return { |
| 1653 | x: -2, |
| 1654 | y: -2, |
| 1655 | width: 4, |
| 1656 | height: 4 |
| 1657 | }; |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1658 | } |
| 1659 | |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1660 | function updateDeviceLabel(d) { |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1661 | var label = trimLabel(deviceLabel(d)), |
| 1662 | noLabel = !label, |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1663 | node = d.el, |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1664 | box, |
| 1665 | dx, |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 1666 | dy, |
| 1667 | cfg = config.icons.device; |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1668 | |
| 1669 | node.select('text') |
| 1670 | .text(label) |
| 1671 | .style('opacity', 0) |
| 1672 | .transition() |
| 1673 | .style('opacity', 1); |
| 1674 | |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1675 | if (noLabel) { |
| 1676 | box = emptyBox(); |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 1677 | dx = -cfg.dim/2; |
| 1678 | dy = -cfg.dim/2; |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1679 | } else { |
| 1680 | box = adjustRectToFitText(node); |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 1681 | dx = box.x + cfg.xoff; |
| 1682 | dy = box.y + cfg.yoff; |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1683 | } |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1684 | |
| 1685 | node.select('rect') |
| 1686 | .transition() |
| 1687 | .attr(box); |
| 1688 | |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1689 | node.select('g.deviceIcon') |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 1690 | .transition() |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1691 | .attr('transform', translate(dx, dy)); |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | function updateHostLabel(d) { |
| 1695 | var label = hostLabel(d), |
| 1696 | host = d.el; |
| 1697 | |
| 1698 | host.select('text').text(label); |
| 1699 | } |
| 1700 | |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1701 | // FIXME : fold this into updateNodes. |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1702 | function updateHostState(hostData) { |
| 1703 | updateHostLabel(hostData); |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1704 | } |
| 1705 | |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 1706 | function updateHostVisibility() { |
| 1707 | var v = visVal(showHosts); |
| 1708 | nodeG.selectAll('.host').style('visibility', v); |
| 1709 | linkG.selectAll('.hostLink').style('visibility', v); |
| 1710 | } |
| 1711 | |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1712 | function nodeMouseOver(d) { |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1713 | hovered = d; |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 1714 | requestTrafficForMode(); |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | function nodeMouseOut(d) { |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1718 | hovered = null; |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 1719 | requestTrafficForMode(); |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1720 | } |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 1721 | |
Simon Hunt | eb1514d | 2014-11-20 09:57:29 -0800 | [diff] [blame] | 1722 | function addHostIcon(node, radius, iid) { |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 1723 | var dim = radius * 1.5, |
| 1724 | xlate = -dim / 2; |
| 1725 | |
Simon Hunt | eb1514d | 2014-11-20 09:57:29 -0800 | [diff] [blame] | 1726 | node.append('use').attr({ |
| 1727 | class: 'glyphIcon hostIcon', |
| 1728 | transform: translate(xlate,xlate), |
| 1729 | 'xlink:href': iid, |
| 1730 | width: dim, |
| 1731 | height: dim |
| 1732 | }); |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 1733 | } |
| 1734 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1735 | function updateNodes() { |
| 1736 | node = nodeG.selectAll('.node') |
| 1737 | .data(network.nodes, function (d) { return d.id; }); |
| 1738 | |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1739 | // operate on existing nodes... |
| 1740 | node.filter('.device').each(function (d) { |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1741 | var node = d.el; |
| 1742 | node.classed('online', d.online); |
| 1743 | updateDeviceLabel(d); |
| 1744 | positionNode(d, true); |
| 1745 | }); |
| 1746 | |
| 1747 | node.filter('.host').each(function (d) { |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1748 | var node = d.el; |
| 1749 | // TODO: appropriate update of host visuals |
| 1750 | }); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1751 | |
| 1752 | // operate on entering nodes: |
| 1753 | var entering = node.enter() |
| 1754 | .append('g') |
| 1755 | .attr({ |
| 1756 | id: function (d) { return safeId(d.id); }, |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1757 | class: mkSvgClass, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1758 | transform: function (d) { return translate(d.x, d.y); }, |
| 1759 | opacity: 0 |
| 1760 | }) |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 1761 | .call(network.drag) |
Simon Hunt | 6ac93f3 | 2014-11-13 12:17:27 -0800 | [diff] [blame] | 1762 | .on('mouseover', nodeMouseOver) |
| 1763 | .on('mouseout', nodeMouseOut) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1764 | .transition() |
| 1765 | .attr('opacity', 1); |
| 1766 | |
| 1767 | // augment device nodes... |
| 1768 | entering.filter('.device').each(function (d) { |
| 1769 | var node = d3.select(this), |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1770 | label = trimLabel(deviceLabel(d)), |
| 1771 | noLabel = !label, |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1772 | box; |
| 1773 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1774 | // provide ref to element from backing data.... |
| 1775 | d.el = node; |
| 1776 | |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1777 | node.append('rect').attr({ rx: 5, ry: 5 }); |
| 1778 | node.append('text').text(label).attr('dy', '1.1em'); |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1779 | box = adjustRectToFitText(node); |
Simon Hunt | a3dd957 | 2014-11-20 15:22:41 -0800 | [diff] [blame] | 1780 | node.select('rect').attr(box); |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1781 | addDeviceIcon(node, box, noLabel, iconGlyphUrl(d)); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1782 | }); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 1783 | |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 1784 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1785 | // augment host nodes... |
| 1786 | entering.filter('.host').each(function (d) { |
| 1787 | var node = d3.select(this), |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 1788 | cfg = config.icons.host, |
| 1789 | r = cfg.radius[d.type] || cfg.defaultRadius, |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 1790 | textDy = r + 10, |
Simon Hunt | eb1514d | 2014-11-20 09:57:29 -0800 | [diff] [blame] | 1791 | iid = iconGlyphUrl(d); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1792 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1793 | // provide ref to element from backing data.... |
| 1794 | d.el = node; |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 1795 | showHostVis(node); |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1796 | |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1797 | node.append('circle').attr('r', r); |
Simon Hunt | eb1514d | 2014-11-20 09:57:29 -0800 | [diff] [blame] | 1798 | if (iid) { |
| 1799 | addHostIcon(node, r, iid); |
Simon Hunt | 7fa116d | 2014-11-17 14:16:55 -0800 | [diff] [blame] | 1800 | } |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1801 | node.append('text') |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1802 | .text(hostLabel) |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 1803 | .attr('dy', textDy) |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 1804 | .attr('text-anchor', 'middle'); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 1805 | }); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1806 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1807 | // operate on both existing and new nodes, if necessary |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1808 | updateDeviceColors(); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1809 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1810 | // operate on exiting nodes: |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1811 | // Note that the node is removed after 2 seconds. |
| 1812 | // Sub element animations should be shorter than 2 seconds. |
| 1813 | var exiting = node.exit() |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 1814 | .transition() |
| 1815 | .duration(2000) |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1816 | .style('opacity', 0) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1817 | .remove(); |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1818 | |
| 1819 | // host node exits.... |
| 1820 | exiting.filter('.host').each(function (d) { |
| 1821 | var node = d3.select(this); |
| 1822 | |
| 1823 | node.select('text') |
| 1824 | .style('opacity', 0.5) |
| 1825 | .transition() |
| 1826 | .duration(1000) |
| 1827 | .style('opacity', 0); |
| 1828 | // note, leave <g>.remove to remove this element |
| 1829 | |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 1830 | node.select('circle') |
| 1831 | .style('stroke-fill', '#555') |
| 1832 | .style('fill', '#888') |
Simon Hunt | ea80eb4 | 2014-11-11 13:46:57 -0800 | [diff] [blame] | 1833 | .style('opacity', 0.5) |
| 1834 | .transition() |
| 1835 | .duration(1500) |
| 1836 | .attr('r', 0); |
| 1837 | // note, leave <g>.remove to remove this element |
| 1838 | |
| 1839 | }); |
| 1840 | |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 1841 | // TODO: device node exit animation |
| 1842 | |
| 1843 | network.force.resume(); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1844 | } |
| 1845 | |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1846 | var dCol = { |
| 1847 | black: '#000', |
| 1848 | paleblue: '#acf', |
| 1849 | offwhite: '#ddd', |
| 1850 | midgrey: '#888', |
| 1851 | lightgrey: '#bbb', |
| 1852 | orange: '#f90' |
| 1853 | }; |
| 1854 | |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1855 | // note: these are the device icon colors without affinity |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1856 | var dColTheme = { |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1857 | light: { |
| 1858 | online: { |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1859 | glyph: dCol.black, |
| 1860 | rect: dCol.paleblue |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1861 | }, |
| 1862 | offline: { |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1863 | glyph: dCol.midgrey, |
| 1864 | rect: dCol.lightgrey |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1865 | } |
| 1866 | }, |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1867 | // TODO: theme |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1868 | dark: { |
| 1869 | online: { |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1870 | glyph: dCol.black, |
| 1871 | rect: dCol.paleblue |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1872 | }, |
| 1873 | offline: { |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1874 | glyph: dCol.midgrey, |
| 1875 | rect: dCol.lightgrey |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | }; |
| 1879 | |
| 1880 | function devBaseColor(d) { |
| 1881 | var t = network.view.getTheme(), |
| 1882 | o = d.online ? 'online' : 'offline'; |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1883 | return dColTheme[t][o]; |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | function setDeviceColor(d) { |
| 1887 | var o = d.online, |
| 1888 | s = d.el.classed('selected'), |
| 1889 | c = devBaseColor(d), |
| 1890 | a = instColor(d.master, o), |
| 1891 | g, r, |
| 1892 | icon = d.el.select('g.deviceIcon'); |
| 1893 | |
| 1894 | if (s) { |
| 1895 | g = c.glyph; |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1896 | r = dColTheme.sel; |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1897 | } else if (colorAffinity) { |
| 1898 | g = o ? a : c.glyph; |
Simon Hunt | 95dad92 | 2014-11-24 09:43:31 -0800 | [diff] [blame] | 1899 | r = o ? dCol.offwhite : a; |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 1900 | } else { |
| 1901 | g = c.glyph; |
| 1902 | r = c.rect; |
| 1903 | } |
| 1904 | |
| 1905 | icon.select('use') |
| 1906 | .style('fill', g); |
| 1907 | icon.select('rect') |
| 1908 | .style('fill', r); |
| 1909 | } |
| 1910 | |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1911 | function addDeviceIcon(node, box, noLabel, iid) { |
| 1912 | var cfg = config.icons.device, |
| 1913 | dx, |
| 1914 | dy, |
| 1915 | g; |
| 1916 | |
| 1917 | if (noLabel) { |
| 1918 | box = emptyBox(); |
| 1919 | dx = -cfg.dim/2; |
| 1920 | dy = -cfg.dim/2; |
| 1921 | } else { |
| 1922 | box = adjustRectToFitText(node); |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 1923 | dx = box.x + cfg.xoff; |
| 1924 | dy = box.y + cfg.yoff; |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1925 | } |
| 1926 | |
Simon Hunt | eb1514d | 2014-11-20 09:57:29 -0800 | [diff] [blame] | 1927 | g = node.append('g') |
| 1928 | .attr('class', 'glyphIcon deviceIcon') |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1929 | .attr('transform', translate(dx, dy)); |
| 1930 | |
| 1931 | g.append('rect').attr({ |
| 1932 | x: 0, |
| 1933 | y: 0, |
| 1934 | rx: cfg.rx, |
| 1935 | width: cfg.dim, |
| 1936 | height: cfg.dim |
| 1937 | }); |
| 1938 | |
| 1939 | g.append('use').attr({ |
| 1940 | 'xlink:href': iid, |
| 1941 | width: cfg.dim, |
| 1942 | height: cfg.dim |
| 1943 | }); |
| 1944 | |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 1945 | } |
| 1946 | |
Simon Hunt | 7b403bc | 2014-11-22 19:01:00 -0800 | [diff] [blame] | 1947 | function find(key, array, tag) { |
| 1948 | var _tag = tag || 'key', |
| 1949 | idx, n, d; |
| 1950 | for (idx = 0, n = array.length; idx < n; idx++) { |
| 1951 | d = array[idx]; |
| 1952 | if (d[_tag] === key) { |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1953 | return idx; |
| 1954 | } |
| 1955 | } |
| 1956 | return -1; |
| 1957 | } |
| 1958 | |
| 1959 | function removeLinkElement(linkData) { |
Simon Hunt | 8257f4c | 2014-11-16 19:34:54 -0800 | [diff] [blame] | 1960 | var idx = find(linkData.key, network.links), |
| 1961 | removed; |
| 1962 | if (idx >=0) { |
| 1963 | // remove from links array |
| 1964 | removed = network.links.splice(idx, 1); |
| 1965 | // remove from lookup cache |
| 1966 | delete network.lookup[removed[0].key]; |
| 1967 | updateLinks(); |
| 1968 | network.force.resume(); |
| 1969 | } |
Simon Hunt | 3f03d4a | 2014-11-10 20:14:37 -0800 | [diff] [blame] | 1970 | } |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1971 | |
Simon Hunt | 4403110 | 2014-11-11 13:20:36 -0800 | [diff] [blame] | 1972 | function removeHostElement(hostData) { |
| 1973 | // first, remove associated hostLink... |
| 1974 | removeLinkElement(hostData.linkData); |
| 1975 | |
| 1976 | // remove from lookup cache |
| 1977 | delete network.lookup[hostData.id]; |
| 1978 | // remove from nodes array |
| 1979 | var idx = find(hostData.id, network.nodes); |
| 1980 | network.nodes.splice(idx, 1); |
| 1981 | // remove from SVG |
| 1982 | updateNodes(); |
| 1983 | network.force.resume(); |
| 1984 | } |
| 1985 | |
| 1986 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1987 | function tick() { |
| 1988 | node.attr({ |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 1989 | transform: function (d) { return translate(d.x, d.y); } |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 1990 | }); |
| 1991 | |
| 1992 | link.attr({ |
| 1993 | x1: function (d) { return d.source.x; }, |
| 1994 | y1: function (d) { return d.source.y; }, |
| 1995 | x2: function (d) { return d.target.x; }, |
| 1996 | y2: function (d) { return d.target.y; } |
| 1997 | }); |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 1998 | |
| 1999 | linkLabel.each(function (d) { |
| 2000 | var el = d3.select(this); |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2001 | var lnk = findLinkById(d.key); |
| 2002 | |
| 2003 | if (lnk) { |
| 2004 | var parms = { |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 2005 | x1: lnk.source.x, |
| 2006 | y1: lnk.source.y, |
| 2007 | x2: lnk.target.x, |
| 2008 | y2: lnk.target.y |
| 2009 | }; |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2010 | el.attr('transform', transformLabel(parms)); |
| 2011 | } |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 2012 | }); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2013 | } |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 2014 | |
| 2015 | // ============================== |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2016 | // Web-Socket for live data |
| 2017 | |
| 2018 | function webSockUrl() { |
| 2019 | return document.location.toString() |
| 2020 | .replace(/\#.*/, '') |
| 2021 | .replace('http://', 'ws://') |
| 2022 | .replace('https://', 'wss://') |
Simon Hunt | e5ab138 | 2014-11-25 10:28:51 -0800 | [diff] [blame] | 2023 | .replace('index.html', config.webSockUrl); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | webSock = { |
| 2027 | ws : null, |
| 2028 | |
| 2029 | connect : function() { |
| 2030 | webSock.ws = new WebSocket(webSockUrl()); |
| 2031 | |
| 2032 | webSock.ws.onopen = function() { |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 2033 | noWebSock(false); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 2034 | requestSummary(); |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 2035 | showInstances(); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2036 | }; |
| 2037 | |
| 2038 | webSock.ws.onmessage = function(m) { |
| 2039 | if (m.data) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 2040 | wsTraceRx(m.data); |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 2041 | handleServerEvent(JSON.parse(m.data)); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2042 | } |
| 2043 | }; |
| 2044 | |
| 2045 | webSock.ws.onclose = function(m) { |
| 2046 | webSock.ws = null; |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 2047 | noWebSock(true); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2048 | }; |
| 2049 | }, |
| 2050 | |
| 2051 | send : function(text) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2052 | if (text != null) { |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2053 | webSock._send(text); |
| 2054 | } |
| 2055 | }, |
| 2056 | |
| 2057 | _send : function(message) { |
| 2058 | if (webSock.ws) { |
| 2059 | webSock.ws.send(message); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 2060 | } else if (config.useLiveData) { |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 2061 | console.warn('no web socket open', message); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 2062 | } else { |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 2063 | console.log('WS Send: ', message); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | }; |
| 2068 | |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 2069 | function noWebSock(b) { |
| 2070 | mask.style('display',b ? 'block' : 'none'); |
| 2071 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2072 | |
| 2073 | function sendMessage(evType, payload) { |
| 2074 | var toSend = { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 2075 | event: evType, |
| 2076 | sid: ++sid, |
| 2077 | payload: payload |
| 2078 | }, |
| 2079 | asText = JSON.stringify(toSend); |
| 2080 | wsTraceTx(asText); |
| 2081 | webSock.send(asText); |
Simon Hunt | c76ae89 | 2014-11-18 17:31:51 -0800 | [diff] [blame] | 2082 | |
| 2083 | // Temporary measure for debugging UI behavior ... |
| 2084 | if (!config.useLiveData) { |
| 2085 | handleTestSend(toSend); |
| 2086 | } |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | function wsTraceTx(msg) { |
| 2090 | wsTrace('tx', msg); |
| 2091 | } |
| 2092 | function wsTraceRx(msg) { |
| 2093 | wsTrace('rx', msg); |
| 2094 | } |
| 2095 | function wsTrace(rxtx, msg) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 2096 | console.log('[' + rxtx + '] ' + msg); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2097 | } |
| 2098 | |
Simon Hunt | c76ae89 | 2014-11-18 17:31:51 -0800 | [diff] [blame] | 2099 | // NOTE: Temporary hardcoded example for showing detail pane |
| 2100 | // while we fine- |
| 2101 | // Probably should not merge this change... |
| 2102 | function handleTestSend(msg) { |
| 2103 | if (msg.event === 'requestDetails') { |
| 2104 | showDetails({ |
| 2105 | event: 'showDetails', |
| 2106 | sid: 1001, |
| 2107 | payload: { |
| 2108 | "id": "of:0000ffffffffff09", |
| 2109 | "type": "roadm", |
| 2110 | "propOrder": [ |
| 2111 | "Name", |
| 2112 | "Vendor", |
| 2113 | "H/W Version", |
| 2114 | "S/W Version", |
| 2115 | "-", |
| 2116 | "Latitude", |
| 2117 | "Longitude", |
| 2118 | "Ports" |
| 2119 | ], |
| 2120 | "props": { |
| 2121 | "Name": null, |
| 2122 | "Vendor": "Linc", |
| 2123 | "H/W Version": "OE", |
| 2124 | "S/W Version": "?", |
| 2125 | "-": "", |
| 2126 | "Latitude": "40.8", |
| 2127 | "Longitude": "73.1", |
| 2128 | "Ports": "2" |
| 2129 | } |
| 2130 | } |
| 2131 | }); |
| 2132 | } |
| 2133 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2134 | |
| 2135 | // ============================== |
| 2136 | // Selection stuff |
| 2137 | |
| 2138 | function selectObject(obj, el) { |
| 2139 | var n, |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2140 | srcEv = d3.event.sourceEvent, |
| 2141 | meta = srcEv.metaKey, |
| 2142 | shift = srcEv.shiftKey; |
| 2143 | |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 2144 | if ((panZoom() && !meta) || (!panZoom() && meta)) { |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2145 | return; |
| 2146 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2147 | |
| 2148 | if (el) { |
| 2149 | n = d3.select(el); |
| 2150 | } else { |
| 2151 | node.each(function(d) { |
| 2152 | if (d == obj) { |
| 2153 | n = d3.select(el = this); |
| 2154 | } |
| 2155 | }); |
| 2156 | } |
| 2157 | if (!n) return; |
| 2158 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2159 | if (shift && n.classed('selected')) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2160 | deselectObject(obj.id); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2161 | updateDetailPane(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2162 | return; |
| 2163 | } |
| 2164 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2165 | if (!shift) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2166 | deselectAll(); |
| 2167 | } |
| 2168 | |
Simon Hunt | c31d569 | 2014-11-12 13:27:18 -0800 | [diff] [blame] | 2169 | selections[obj.id] = { obj: obj, el: el }; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2170 | selectOrder.push(obj.id); |
| 2171 | |
| 2172 | n.classed('selected', true); |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 2173 | updateDeviceColors(obj); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2174 | updateDetailPane(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | function deselectObject(id) { |
Simon Hunt | c31d569 | 2014-11-12 13:27:18 -0800 | [diff] [blame] | 2178 | var obj = selections[id], |
| 2179 | idx; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2180 | if (obj) { |
| 2181 | d3.select(obj.el).classed('selected', false); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2182 | delete selections[id]; |
Simon Hunt | c31d569 | 2014-11-12 13:27:18 -0800 | [diff] [blame] | 2183 | idx = $.inArray(id, selectOrder); |
| 2184 | if (idx >= 0) { |
| 2185 | selectOrder.splice(idx, 1); |
| 2186 | } |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 2187 | updateDeviceColors(obj.obj); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2188 | } |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | function deselectAll() { |
| 2192 | // deselect all nodes in the network... |
| 2193 | node.classed('selected', false); |
| 2194 | selections = {}; |
| 2195 | selectOrder = []; |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 2196 | updateDeviceColors(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2197 | updateDetailPane(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2198 | } |
| 2199 | |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 2200 | function updateDeviceColors(d) { |
| 2201 | if (d) { |
| 2202 | setDeviceColor(d); |
| 2203 | } else { |
| 2204 | node.filter('.device').each(function (d) { |
| 2205 | setDeviceColor(d); |
| 2206 | }); |
| 2207 | } |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 2208 | } |
| 2209 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2210 | // update the state of the detail pane, based on current selections |
| 2211 | function updateDetailPane() { |
| 2212 | var nSel = selectOrder.length; |
| 2213 | if (!nSel) { |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2214 | emptySelect(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2215 | } else if (nSel === 1) { |
| 2216 | singleSelect(); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2217 | requestTrafficForMode(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2218 | } else { |
| 2219 | multiSelect(); |
| 2220 | } |
| 2221 | } |
| 2222 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2223 | function emptySelect() { |
Simon Hunt | 06811b7 | 2014-11-25 18:54:48 -0800 | [diff] [blame] | 2224 | hideDetailPane(); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2225 | cancelTraffic(); |
| 2226 | } |
| 2227 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2228 | function singleSelect() { |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2229 | // NOTE: detail is shown from showDetails event callback |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2230 | requestDetails(); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2231 | requestTrafficForMode(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | function multiSelect() { |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 2235 | populateMultiSelect(); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2236 | requestTrafficForMode(); |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | function addSep(tbody) { |
| 2240 | var tr = tbody.append('tr'); |
| 2241 | $('<hr>').appendTo(tr.append('td').attr('colspan', 2)); |
| 2242 | } |
| 2243 | |
| 2244 | function addProp(tbody, label, value) { |
| 2245 | var tr = tbody.append('tr'); |
| 2246 | |
| 2247 | tr.append('td') |
| 2248 | .attr('class', 'label') |
| 2249 | .text(label + ' :'); |
| 2250 | |
| 2251 | tr.append('td') |
| 2252 | .attr('class', 'value') |
| 2253 | .text(value); |
| 2254 | } |
| 2255 | |
| 2256 | function populateMultiSelect() { |
| 2257 | detailPane.empty(); |
| 2258 | |
Simon Hunt | a3dd957 | 2014-11-20 15:22:41 -0800 | [diff] [blame] | 2259 | var title = detailPane.append('h3'), |
| 2260 | table = detailPane.append('table'), |
| 2261 | tbody = table.append('tbody'); |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 2262 | |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2263 | title.text('Selected Nodes'); |
Simon Hunt | b53e068 | 2014-11-12 13:32:01 -0800 | [diff] [blame] | 2264 | |
| 2265 | selectOrder.forEach(function (d, i) { |
| 2266 | addProp(tbody, i+1, d); |
| 2267 | }); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 2268 | |
| 2269 | addMultiSelectActions(); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2270 | } |
| 2271 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 2272 | // TODO: refactor to consolidate with populateDetails |
| 2273 | function populateSummary(data) { |
| 2274 | summaryPane.empty(); |
| 2275 | |
| 2276 | var svg = summaryPane.append('svg'), |
| 2277 | iid = iconGlyphUrl(data); |
| 2278 | |
| 2279 | var title = summaryPane.append('h2'), |
| 2280 | table = summaryPane.append('table'), |
| 2281 | tbody = table.append('tbody'); |
| 2282 | |
| 2283 | appendGlyph(svg, 0, 0, 40, iid); |
| 2284 | |
| 2285 | svg.append('use') |
| 2286 | .attr({ |
| 2287 | class: 'birdBadge', |
| 2288 | transform: translate(8,12), |
| 2289 | 'xlink:href': '#bird', |
| 2290 | width: 24, |
| 2291 | height: 24, |
| 2292 | fill: '#fff' |
| 2293 | }); |
| 2294 | |
| 2295 | title.text('ONOS Summary'); |
| 2296 | |
| 2297 | data.propOrder.forEach(function(p) { |
| 2298 | if (p === '-') { |
| 2299 | addSep(tbody); |
| 2300 | } else { |
| 2301 | addProp(tbody, p, data.props[p]); |
| 2302 | } |
| 2303 | }); |
| 2304 | } |
| 2305 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2306 | function populateDetails(data) { |
| 2307 | detailPane.empty(); |
| 2308 | |
Simon Hunt | a6a9fe7 | 2014-11-20 11:17:12 -0800 | [diff] [blame] | 2309 | var svg = detailPane.append('svg'), |
| 2310 | iid = iconGlyphUrl(data); |
| 2311 | |
Simon Hunt | a3dd957 | 2014-11-20 15:22:41 -0800 | [diff] [blame] | 2312 | var title = detailPane.append('h2'), |
| 2313 | table = detailPane.append('table'), |
| 2314 | tbody = table.append('tbody'); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2315 | |
Simon Hunt | a6a9fe7 | 2014-11-20 11:17:12 -0800 | [diff] [blame] | 2316 | appendGlyph(svg, 0, 0, 40, iid); |
| 2317 | title.text(data.id); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2318 | |
| 2319 | data.propOrder.forEach(function(p) { |
| 2320 | if (p === '-') { |
| 2321 | addSep(tbody); |
| 2322 | } else { |
| 2323 | addProp(tbody, p, data.props[p]); |
| 2324 | } |
| 2325 | }); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 2326 | |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2327 | addSingleSelectActions(data); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2328 | } |
| 2329 | |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2330 | function addSingleSelectActions(data) { |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 2331 | detailPane.append('hr'); |
| 2332 | // always want to allow 'show traffic' |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2333 | addAction(detailPane, 'Show Related Traffic', showTrafficAction); |
| 2334 | |
| 2335 | if (data.type === 'switch') { |
| 2336 | addAction(detailPane, 'Show Device Flows', showDeviceLinkFlowsAction); |
| 2337 | } |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | function addMultiSelectActions() { |
| 2341 | detailPane.append('hr'); |
| 2342 | // always want to allow 'show traffic' |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2343 | addAction(detailPane, 'Show Related Traffic', showTrafficAction); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 2344 | // if exactly two hosts are selected, also want 'add host intent' |
| 2345 | if (nSel() === 2 && allSelectionsClass('host')) { |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 2346 | addAction(detailPane, 'Create Host-to-Host Flow', addHostIntentAction); |
| 2347 | } else if (nSel() >= 2 && allSelectionsClass('host')) { |
| 2348 | addAction(detailPane, 'Create Multi-Source Flow', addMultiSourceIntentAction); |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 2352 | function addAction(panel, text, cb) { |
| 2353 | panel.append('div') |
Simon Hunt | d72bc70 | 2014-11-13 18:38:04 -0800 | [diff] [blame] | 2354 | .classed('actionBtn', true) |
| 2355 | .text(text) |
| 2356 | .on('click', cb); |
| 2357 | } |
| 2358 | |
| 2359 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2360 | function zoomPan(scale, translate) { |
| 2361 | zoomPanContainer.attr("transform", "translate(" + translate + ")scale(" + scale + ")"); |
| 2362 | // keep the map lines constant width while zooming |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 2363 | bgImg.style("stroke-width", 2.0 / scale + "px"); |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | function resetZoomPan() { |
| 2367 | zoomPan(1, [0,0]); |
| 2368 | zoom.scale(1).translate([0,0]); |
| 2369 | } |
| 2370 | |
| 2371 | function setupZoomPan() { |
| 2372 | function zoomed() { |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 2373 | if (!panZoom() ^ !d3.event.sourceEvent.metaKey) { |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2374 | zoomPan(d3.event.scale, d3.event.translate); |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | zoom = d3.behavior.zoom() |
| 2379 | .translate([0, 0]) |
| 2380 | .scale(1) |
| 2381 | .scaleExtent([1, 8]) |
| 2382 | .on("zoom", zoomed); |
| 2383 | |
| 2384 | svg.call(zoom); |
| 2385 | } |
| 2386 | |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2387 | // ============================== |
| 2388 | // Test harness code |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 2389 | |
| 2390 | function prepareScenario(view, ctx, dbg) { |
| 2391 | var sc = scenario, |
| 2392 | urlSc = sc.evDir + ctx + sc.evScenario; |
| 2393 | |
| 2394 | if (!ctx) { |
| 2395 | view.alert("No scenario specified (null ctx)"); |
| 2396 | return; |
| 2397 | } |
| 2398 | |
| 2399 | sc.view = view; |
| 2400 | sc.ctx = ctx; |
| 2401 | sc.debug = dbg; |
| 2402 | sc.evNumber = 0; |
| 2403 | |
| 2404 | d3.json(urlSc, function(err, data) { |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 2405 | var p = data && data.params || {}, |
| 2406 | desc = data && data.description || null, |
Simon Hunt | fc274c9 | 2014-11-11 11:05:46 -0800 | [diff] [blame] | 2407 | intro = data && data.title; |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 2408 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 2409 | if (err) { |
| 2410 | view.alert('No scenario found:\n\n' + urlSc + '\n\n' + err); |
| 2411 | } else { |
| 2412 | sc.params = p; |
Simon Hunt | bb282f5 | 2014-11-10 11:08:19 -0800 | [diff] [blame] | 2413 | if (desc) { |
| 2414 | intro += '\n\n ' + desc.join('\n '); |
| 2415 | } |
| 2416 | view.alert(intro); |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 2417 | } |
| 2418 | }); |
| 2419 | |
| 2420 | } |
| 2421 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2422 | // ============================== |
| 2423 | // Toggle Buttons in masthead |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 2424 | |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 2425 | // TODO: toggle button (and other widgets in the masthead) should be provided |
| 2426 | // by the framework; not generated by the view. |
| 2427 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 2428 | //var showInstances; |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 2429 | |
Simon Hunt | 8751434 | 2014-11-24 16:41:27 -0800 | [diff] [blame] | 2430 | /* |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 2431 | function addButtonBar(view) { |
| 2432 | var bb = d3.select('#mast') |
| 2433 | .append('span').classed('right', true).attr('id', 'bb'); |
| 2434 | |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 2435 | function mkTogBtn(text, cb) { |
| 2436 | return bb.append('span') |
| 2437 | .classed('btn', true) |
| 2438 | .text(text) |
| 2439 | .on('click', cb); |
| 2440 | } |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2441 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 2442 | //showInstances = mkTogBtn('Show Instances', toggleInst); |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 2443 | } |
Simon Hunt | 8751434 | 2014-11-24 16:41:27 -0800 | [diff] [blame] | 2444 | */ |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 2445 | |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 2446 | function panZoom() { |
Simon Hunt | e5b7175 | 2014-11-18 20:06:07 -0800 | [diff] [blame] | 2447 | return false; |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 2448 | } |
| 2449 | |
Simon Hunt | 7fa116d | 2014-11-17 14:16:55 -0800 | [diff] [blame] | 2450 | function loadGlyphs(svg) { |
| 2451 | var defs = svg.append('defs'); |
| 2452 | gly.defBird(defs); |
Simon Hunt | c72967b | 2014-11-20 09:21:42 -0800 | [diff] [blame] | 2453 | gly.defGlyphs(defs); |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 2454 | gly.defBadges(defs); |
Simon Hunt | 7fa116d | 2014-11-17 14:16:55 -0800 | [diff] [blame] | 2455 | } |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2456 | |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 2457 | function sendUpdateMeta(d, store) { |
| 2458 | var metaUi = {}, |
| 2459 | ll; |
| 2460 | |
| 2461 | if (store) { |
| 2462 | ll = geoMapProjection.invert([d.x, d.y]); |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 2463 | metaUi = { |
| 2464 | x: d.x, |
| 2465 | y: d.y, |
| 2466 | lng: ll[0], |
| 2467 | lat: ll[1] |
| 2468 | }; |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 2469 | } |
Simon Hunt | 62c4754 | 2014-11-22 22:16:32 -0800 | [diff] [blame] | 2470 | d.metaUi = metaUi; |
| 2471 | sendMessage('updateMeta', { |
| 2472 | id: d.id, |
| 2473 | 'class': d.class, |
| 2474 | 'memento': metaUi |
| 2475 | }); |
| 2476 | } |
| 2477 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 2478 | // ============================== |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 2479 | // View life-cycle callbacks |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2480 | |
Simon Hunt | f67722a | 2014-11-10 09:32:06 -0800 | [diff] [blame] | 2481 | function preload(view, ctx, flags) { |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 2482 | var w = view.width(), |
| 2483 | h = view.height(), |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2484 | fcfg = config.force, |
| 2485 | fpad = fcfg.pad, |
| 2486 | forceDim = [w - 2*fpad, h - 2*fpad]; |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2487 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 2488 | // NOTE: view.$div is a D3 selection of the view's div |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 2489 | var viewBox = '0 0 ' + config.logicalSize + ' ' + config.logicalSize; |
| 2490 | svg = view.$div.append('svg').attr('viewBox', viewBox); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 2491 | setSize(svg, view); |
| 2492 | |
Simon Hunt | 7fa116d | 2014-11-17 14:16:55 -0800 | [diff] [blame] | 2493 | loadGlyphs(svg); |
Simon Hunt | 12ce12e | 2014-11-15 21:13:19 -0800 | [diff] [blame] | 2494 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2495 | zoomPanContainer = svg.append('g').attr('id', 'zoomPanContainer'); |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2496 | setupZoomPan(); |
| 2497 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 2498 | // add blue glow filter to svg layer |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2499 | d3u.appendGlow(zoomPanContainer); |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 2500 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2501 | // group for the topology |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2502 | topoG = zoomPanContainer.append('g') |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2503 | .attr('id', 'topo-G') |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2504 | .attr('transform', fcfg.translate()); |
| 2505 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 2506 | // subgroups for links, link labels, and nodes |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2507 | linkG = topoG.append('g').attr('id', 'links'); |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 2508 | linkLabelG = topoG.append('g').attr('id', 'linkLabels'); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2509 | nodeG = topoG.append('g').attr('id', 'nodes'); |
| 2510 | |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 2511 | // selection of links, linkLabels, and nodes |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2512 | link = linkG.selectAll('.link'); |
Simon Hunt | e2575b6 | 2014-11-18 15:25:53 -0800 | [diff] [blame] | 2513 | linkLabel = linkLabelG.selectAll('.linkLabel'); |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2514 | node = nodeG.selectAll('.node'); |
| 2515 | |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 2516 | function chrg(d) { |
| 2517 | return fcfg.charge[d.class] || -12000; |
| 2518 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 2519 | function ldist(d) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 2520 | return fcfg.linkDistance[d.type] || 50; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 2521 | } |
| 2522 | function lstrg(d) { |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 2523 | // 0.0 - 1.0 |
| 2524 | return fcfg.linkStrength[d.type] || 1.0; |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 2525 | } |
| 2526 | |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 2527 | function selectCb(d, self) { |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 2528 | selectObject(d, self); |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | function atDragEnd(d, self) { |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 2532 | // once we've finished moving, pin the node in position |
| 2533 | d.fixed = true; |
| 2534 | d3.select(self).classed('fixed', true); |
| 2535 | if (config.useLiveData) { |
Simon Hunt | 395a70c | 2014-11-22 23:17:40 -0800 | [diff] [blame] | 2536 | sendUpdateMeta(d, true); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 2537 | } else { |
| 2538 | console.log('Moving node ' + d.id + ' to [' + d.x + ',' + d.y + ']'); |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 2539 | } |
| 2540 | } |
| 2541 | |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2542 | // set up the force layout |
| 2543 | network.force = d3.layout.force() |
| 2544 | .size(forceDim) |
| 2545 | .nodes(network.nodes) |
| 2546 | .links(network.links) |
Simon Hunt | 7cd48f3 | 2014-11-09 23:42:50 -0800 | [diff] [blame] | 2547 | .gravity(0.4) |
| 2548 | .friction(0.7) |
| 2549 | .charge(chrg) |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 2550 | .linkDistance(ldist) |
| 2551 | .linkStrength(lstrg) |
Simon Hunt | c7ee066 | 2014-11-05 16:44:37 -0800 | [diff] [blame] | 2552 | .on('tick', tick); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2553 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2554 | network.drag = d3u.createDragBehavior(network.force, |
Simon Hunt | deab432 | 2014-11-13 18:49:07 -0800 | [diff] [blame] | 2555 | selectCb, atDragEnd, panZoom); |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 2556 | |
| 2557 | // create mask layer for when we lose connection to server. |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 2558 | // TODO: this should be part of the framework |
Simon Hunt | 0c6d419 | 2014-11-12 12:07:10 -0800 | [diff] [blame] | 2559 | mask = view.$div.append('div').attr('id','topo-mask'); |
| 2560 | para(mask, 'Oops!'); |
| 2561 | para(mask, 'Web-socket connection to server closed...'); |
| 2562 | para(mask, 'Try refreshing the page.'); |
Simon Hunt | 12ce12e | 2014-11-15 21:13:19 -0800 | [diff] [blame] | 2563 | |
| 2564 | mask.append('svg') |
| 2565 | .attr({ |
| 2566 | id: 'mask-bird', |
| 2567 | width: w, |
| 2568 | height: h |
| 2569 | }) |
| 2570 | .append('g') |
| 2571 | .attr('transform', birdTranslate(w, h)) |
| 2572 | .style('opacity', 0.3) |
| 2573 | .append('use') |
| 2574 | .attr({ |
| 2575 | 'xlink:href': '#bird', |
| 2576 | width: config.birdDim, |
| 2577 | height: config.birdDim, |
| 2578 | fill: '#111' |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 2579 | }) |
Simon Hunt | 1a9eff9 | 2014-11-07 11:06:34 -0800 | [diff] [blame] | 2580 | } |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2581 | |
Simon Hunt | 01095ff | 2014-11-13 16:37:29 -0800 | [diff] [blame] | 2582 | function para(sel, text) { |
| 2583 | sel.append('p').text(text); |
| 2584 | } |
| 2585 | |
| 2586 | |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 2587 | function load(view, ctx, flags) { |
Simon Hunt | f67722a | 2014-11-10 09:32:06 -0800 | [diff] [blame] | 2588 | // resize, in case the window was resized while we were not loaded |
| 2589 | resize(view, ctx, flags); |
| 2590 | |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 2591 | // cache the view token, so network topo functions can access it |
| 2592 | network.view = view; |
Simon Hunt | 56d5185 | 2014-11-09 13:03:35 -0800 | [diff] [blame] | 2593 | config.useLiveData = !flags.local; |
| 2594 | |
| 2595 | if (!config.useLiveData) { |
| 2596 | prepareScenario(view, ctx, flags.debug); |
| 2597 | } |
Simon Hunt | 99c1384 | 2014-11-06 18:23:12 -0800 | [diff] [blame] | 2598 | |
| 2599 | // set our radio buttons and key bindings |
Simon Hunt | 9462e8c | 2014-11-14 17:28:09 -0800 | [diff] [blame] | 2600 | layerBtnSet = view.setRadio(layerButtons); |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 2601 | view.setKeys(keyDispatch); |
Simon Hunt | 8751434 | 2014-11-24 16:41:27 -0800 | [diff] [blame] | 2602 | view.setGestures(gestures); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2603 | |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 2604 | // patch in our "button bar" for now |
| 2605 | // TODO: implement a more official frameworky way of doing this.. |
Simon Hunt | 8751434 | 2014-11-24 16:41:27 -0800 | [diff] [blame] | 2606 | //addButtonBar(view); |
Simon Hunt | f8e5b4e0 | 2014-11-13 11:17:57 -0800 | [diff] [blame] | 2607 | |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2608 | // Load map data asynchronously; complete startup after that.. |
| 2609 | loadGeoJsonData(); |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 2610 | } |
| 2611 | |
Thomas Vachuska | a3148a7 | 2014-11-19 21:38:35 -0800 | [diff] [blame] | 2612 | function startAntTimer() { |
Thomas Vachuska | 4731f12 | 2014-11-20 04:56:19 -0800 | [diff] [blame] | 2613 | if (!antTimer) { |
| 2614 | var pulses = [5, 3, 1.2, 3], |
| 2615 | pulse = 0; |
| 2616 | antTimer = setInterval(function () { |
| 2617 | pulse = pulse + 1; |
| 2618 | pulse = pulse === pulses.length ? 0 : pulse; |
| 2619 | d3.selectAll('.animated').style('stroke-width', pulses[pulse]); |
| 2620 | }, 200); |
| 2621 | } |
Thomas Vachuska | a3148a7 | 2014-11-19 21:38:35 -0800 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | function stopAntTimer() { |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 2625 | if (antTimer) { |
| 2626 | clearInterval(antTimer); |
| 2627 | antTimer = null; |
| 2628 | } |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2629 | } |
| 2630 | |
Thomas Vachuska | a3148a7 | 2014-11-19 21:38:35 -0800 | [diff] [blame] | 2631 | function unload(view, ctx, flags) { |
| 2632 | stopAntTimer(); |
| 2633 | } |
| 2634 | |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2635 | // TODO: move these to config/state portion of script |
Simon Hunt | a6a9fe7 | 2014-11-20 11:17:12 -0800 | [diff] [blame] | 2636 | var geoJsonUrl = 'json/map/continental_us.json', |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2637 | geoJson; |
| 2638 | |
| 2639 | function loadGeoJsonData() { |
| 2640 | d3.json(geoJsonUrl, function (err, data) { |
| 2641 | if (err) { |
| 2642 | // fall back to USA map background |
| 2643 | loadStaticMap(); |
| 2644 | } else { |
| 2645 | geoJson = data; |
| 2646 | loadGeoMap(); |
| 2647 | } |
| 2648 | |
| 2649 | // finally, connect to the server... |
| 2650 | if (config.useLiveData) { |
| 2651 | webSock.connect(); |
| 2652 | } |
| 2653 | }); |
| 2654 | } |
| 2655 | |
| 2656 | function showBg() { |
Simon Hunt | 434cf14 | 2014-11-24 11:10:28 -0800 | [diff] [blame] | 2657 | return visVal(config.options.showBackground); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | function loadStaticMap() { |
| 2661 | fnTrace('loadStaticMap', config.backgroundUrl); |
| 2662 | var w = network.view.width(), |
| 2663 | h = network.view.height(); |
| 2664 | |
| 2665 | // load the background image |
| 2666 | bgImg = svg.insert('svg:image', '#topo-G') |
| 2667 | .attr({ |
| 2668 | id: 'topo-bg', |
| 2669 | width: w, |
| 2670 | height: h, |
| 2671 | 'xlink:href': config.backgroundUrl |
| 2672 | }) |
| 2673 | .style({ |
| 2674 | visibility: showBg() |
| 2675 | }); |
| 2676 | } |
| 2677 | |
| 2678 | function loadGeoMap() { |
| 2679 | fnTrace('loadGeoMap', geoJsonUrl); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2680 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 2681 | // extracts the topojson data into geocoordinate-based geometry |
| 2682 | var topoData = topojson.feature(geoJson, geoJson.objects.states); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2683 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 2684 | // see: http://bl.ocks.org/mbostock/4707858 |
| 2685 | geoMapProjection = d3.geo.mercator(); |
| 2686 | var path = d3.geo.path().projection(geoMapProjection); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2687 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 2688 | geoMapProjection |
| 2689 | .scale(1) |
| 2690 | .translate([0, 0]); |
Simon Hunt | d3b7d51 | 2014-11-12 15:48:41 -0800 | [diff] [blame] | 2691 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 2692 | // [[x1,y1],[x2,y2]] |
| 2693 | var b = path.bounds(topoData); |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2694 | // size map to 95% of minimum dimension to fill space |
| 2695 | 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] | 2696 | 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] | 2697 | |
Paul Greyson | 6cb8ca0 | 2014-11-12 18:09:02 -0800 | [diff] [blame] | 2698 | geoMapProjection |
| 2699 | .scale(s) |
| 2700 | .translate(t); |
| 2701 | |
Paul Greyson | fcba0e8 | 2014-11-13 10:21:16 -0800 | [diff] [blame] | 2702 | bgImg = zoomPanContainer.insert("g", '#topo-G'); |
Thomas Vachuska | 8954329 | 2014-11-19 11:28:33 -0800 | [diff] [blame] | 2703 | bgImg.attr('id', 'map').selectAll('path') |
| 2704 | .data(topoData.features) |
| 2705 | .enter() |
| 2706 | .append('path') |
| 2707 | .attr('d', path); |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2708 | } |
| 2709 | |
Simon Hunt | f67722a | 2014-11-10 09:32:06 -0800 | [diff] [blame] | 2710 | function resize(view, ctx, flags) { |
Simon Hunt | 12ce12e | 2014-11-15 21:13:19 -0800 | [diff] [blame] | 2711 | var w = view.width(), |
| 2712 | h = view.height(); |
| 2713 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 2714 | setSize(svg, view); |
Simon Hunt | 12ce12e | 2014-11-15 21:13:19 -0800 | [diff] [blame] | 2715 | |
| 2716 | d3.select('#mask-bird').attr({ width: w, height: h}) |
| 2717 | .select('g').attr('transform', birdTranslate(w, h)); |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 2718 | } |
| 2719 | |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 2720 | function theme(view, ctx, flags) { |
| 2721 | updateInstances(); |
Simon Hunt | b0ecfa5 | 2014-11-23 21:05:12 -0800 | [diff] [blame] | 2722 | updateDeviceColors(); |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 2723 | } |
| 2724 | |
Simon Hunt | 12ce12e | 2014-11-15 21:13:19 -0800 | [diff] [blame] | 2725 | function birdTranslate(w, h) { |
| 2726 | var bdim = config.birdDim; |
| 2727 | return 'translate('+((w-bdim)*.4)+','+((h-bdim)*.1)+')'; |
| 2728 | } |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 2729 | |
Simon Hunt | 06811b7 | 2014-11-25 18:54:48 -0800 | [diff] [blame] | 2730 | function isF(f) { return $.isFunction(f) ? f : null; } |
| 2731 | function noop() {} |
| 2732 | |
| 2733 | function augmentDetailPane() { |
| 2734 | var dp = detailPane; |
| 2735 | dp.ypos = { up: 64, down: 320, current: 320}; |
| 2736 | |
| 2737 | dp._move = function (y, cb) { |
| 2738 | var endCb = isF(cb) || noop, |
| 2739 | yp = dp.ypos; |
| 2740 | if (yp.current !== y) { |
| 2741 | yp.current = y; |
| 2742 | dp.el.transition().duration(300) |
| 2743 | .each('end', endCb) |
| 2744 | .style('top', yp.current + 'px'); |
| 2745 | } else { |
| 2746 | endCb(); |
| 2747 | } |
| 2748 | }; |
| 2749 | |
| 2750 | dp.down = function (cb) { dp._move(dp.ypos.down, cb); }; |
| 2751 | dp.up = function (cb) { dp._move(dp.ypos.up, cb); }; |
| 2752 | } |
| 2753 | |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 2754 | // ============================== |
| 2755 | // View registration |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2756 | |
Simon Hunt | 2524891 | 2014-11-04 11:25:48 -0800 | [diff] [blame] | 2757 | onos.ui.addView('topo', { |
Simon Hunt | 142d003 | 2014-11-04 20:13:09 -0800 | [diff] [blame] | 2758 | preload: preload, |
| 2759 | load: load, |
Simon Hunt | a255a2c | 2014-11-13 22:29:35 -0800 | [diff] [blame] | 2760 | unload: unload, |
Simon Hunt | 8f40cce | 2014-11-23 15:57:30 -0800 | [diff] [blame] | 2761 | resize: resize, |
| 2762 | theme: theme |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2763 | }); |
| 2764 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 2765 | summaryPane = onos.ui.addFloatingPanel('topo-summary'); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2766 | detailPane = onos.ui.addFloatingPanel('topo-detail'); |
Simon Hunt | 06811b7 | 2014-11-25 18:54:48 -0800 | [diff] [blame] | 2767 | augmentDetailPane(); |
Simon Hunt | a5e8914 | 2014-11-14 07:00:33 -0800 | [diff] [blame] | 2768 | oiBox = onos.ui.addFloatingPanel('topo-oibox', 'TL'); |
Simon Hunt | b82f690 | 2014-11-22 11:53:15 -0800 | [diff] [blame] | 2769 | oiBox.width(20); |
Simon Hunt | 61d0404 | 2014-11-11 17:27:16 -0800 | [diff] [blame] | 2770 | |
Simon Hunt | 195cb38 | 2014-11-03 17:50:51 -0800 | [diff] [blame] | 2771 | }(ONOS)); |