Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 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 | /* |
| 18 | ONOS GUI -- Topology Traffic Module. |
| 19 | Defines behavior for viewing different traffic modes. |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 26 | var $log, fs, flash, wss, api; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 27 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 28 | /* |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 29 | API to topoForce |
| 30 | hovered() |
| 31 | somethingSelected() |
| 32 | selectOrder() |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 33 | */ |
| 34 | |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 35 | var allTrafficTypes = [ |
| 36 | 'flowStatsBytes', |
| 37 | 'portStatsBitSec', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 38 | 'portStatsPktSec' |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 39 | ], |
| 40 | allTrafficMsgs = [ |
| 41 | 'Flow Stats (bytes)', |
| 42 | 'Port Stats (bits / second)', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 43 | 'Port Stats (packets / second)' |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 44 | ]; |
| 45 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 46 | // internal state |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 47 | var trafficMode = null, |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 48 | hoverMode = null, |
| 49 | allTrafficIndex = 0; |
| 50 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 51 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 52 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 53 | // === ----------------------------------------------------- |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 54 | // Helper functions |
| 55 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 56 | // invoked in response to change in selection and/or mouseover/out: |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 57 | function requestTrafficForMode(mouse) { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 58 | if (trafficMode === 'flows') { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 59 | requestDeviceLinkFlows(); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 60 | } else if (trafficMode === 'intents') { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 61 | if (!mouse || hoverMode === 'intents') { |
| 62 | requestRelatedIntents(); |
| 63 | } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 64 | } else { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 65 | // do nothing |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 69 | function requestDeviceLinkFlows() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 70 | // generates payload based on current hover-state |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 71 | var hov = api.hovered(); |
| 72 | |
| 73 | function hoverValid() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 74 | return hoverMode === 'flows' && |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 75 | hov && (hov.class === 'device'); |
| 76 | } |
| 77 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 78 | if (api.somethingSelected()) { |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 79 | wss.sendEvent('requestDeviceLinkFlows', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 80 | ids: api.selectOrder(), |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 81 | hover: hoverValid() ? hov.id : '' |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 82 | }); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | function requestRelatedIntents() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 87 | // generates payload based on current hover-state |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 88 | var hov = api.hovered(); |
| 89 | |
| 90 | function hoverValid() { |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 91 | return hoverMode === 'intents' && hov && ( |
| 92 | hov.class === 'host' || |
| 93 | hov.class === 'device' || |
| 94 | hov.class === 'link'); |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 97 | if (api.somethingSelected()) { |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 98 | wss.sendEvent('requestRelatedIntents', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 99 | ids: api.selectOrder(), |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 100 | hover: hoverValid() ? hov.id : '' |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 101 | }); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 106 | // === ------------------------------------------------------------- |
| 107 | // Traffic requests invoked from keystrokes or toolbar buttons... |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 108 | |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 109 | function cancelTraffic(forced) { |
| 110 | if (!trafficMode || (!forced && trafficMode === 'allFlowPort')) { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 111 | return false; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 112 | } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 113 | |
| 114 | trafficMode = hoverMode = null; |
| 115 | wss.sendEvent('cancelTraffic'); |
| 116 | flash.flash('Traffic monitoring canceled'); |
| 117 | return true; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 120 | function showAllTraffic() { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 121 | trafficMode = 'allFlowPort'; |
| 122 | hoverMode = null; |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 123 | wss.sendEvent('requestAllTraffic', { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 124 | trafficType: allTrafficTypes[allTrafficIndex] |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 125 | }); |
| 126 | flash.flash(allTrafficMsgs[allTrafficIndex]); |
| 127 | allTrafficIndex = (allTrafficIndex + 1) % 3; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 130 | function showDeviceLinkFlows () { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 131 | trafficMode = hoverMode = 'flows'; |
| 132 | requestDeviceLinkFlows(); |
| 133 | flash.flash('Device Flows'); |
| 134 | } |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 135 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 136 | function showRelatedIntents () { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 137 | trafficMode = hoverMode = 'intents'; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 138 | requestRelatedIntents(); |
| 139 | flash.flash('Related Paths'); |
| 140 | } |
| 141 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 142 | function showPrevIntent() { |
| 143 | if (trafficMode === 'intents') { |
| 144 | hoverMode = null; |
| 145 | wss.sendEvent('requestPrevRelatedIntent'); |
| 146 | flash.flash('Previous related intent'); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | function showNextIntent() { |
| 151 | if (trafficMode === 'intents') { |
| 152 | hoverMode = null; |
| 153 | wss.sendEvent('requestNextRelatedIntent'); |
| 154 | flash.flash('Next related intent'); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | function showSelectedIntentTraffic() { |
| 159 | if (trafficMode === 'intents') { |
| 160 | hoverMode = null; |
| 161 | wss.sendEvent('requestSelectedIntentTraffic'); |
| 162 | flash.flash('Traffic on Selected Path'); |
| 163 | } |
| 164 | } |
| 165 | |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 166 | // force the system to create a single intent selection |
| 167 | function selectIntent(data) { |
| 168 | trafficMode = 'intents'; |
| 169 | hoverMode = null; |
| 170 | wss.sendEvent('selectIntent', data); |
| 171 | flash.flash('Selecting Intent ' + data.key); |
| 172 | } |
| 173 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 174 | |
| 175 | // === ------------------------------------------------------ |
| 176 | // action buttons on detail panel (multiple selection) |
| 177 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 178 | function addHostIntent () { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 179 | var so = api.selectOrder(); |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 180 | wss.sendEvent('addHostIntent', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 181 | one: so[0], |
| 182 | two: so[1], |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 183 | ids: so |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 184 | }); |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 185 | trafficMode = 'intents'; |
| 186 | hoverMode = null; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 187 | flash.flash('Host-to-Host flow added'); |
| 188 | } |
| 189 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 190 | function removeIntent (d) { |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 191 | $log.debug('Entering removeIntent'); |
| 192 | wss.sendEvent('removeIntent', { |
| 193 | appId: d.appId, |
| 194 | appName: d.appName, |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 195 | key: d.key, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 196 | purge: d.intentPurge |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 197 | }); |
| 198 | trafficMode = 'intents'; |
| 199 | hoverMode = null; |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 200 | var txt = d.intentPurge ? 'purged' : 'withdrawn'; |
| 201 | flash.flash('Intent ' + txt); |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 202 | } |
| 203 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 204 | function resubmitIntent (d) { |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 205 | $log.debug('Entering resubmitIntent'); |
| 206 | wss.sendEvent('resubmitIntent', { |
| 207 | appId: d.appId, |
| 208 | appName: d.appName, |
| 209 | key: d.key, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 210 | purge: d.intentPurge |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 211 | }); |
| 212 | trafficMode = 'intents'; |
| 213 | hoverMode = null; |
| 214 | flash.flash('Intent resubmitted'); |
| 215 | } |
| 216 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 217 | function addMultiSourceIntent () { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 218 | var so = api.selectOrder(); |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 219 | wss.sendEvent('addMultiSourceIntent', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 220 | src: so.slice(0, so.length - 1), |
| 221 | dst: so[so.length - 1], |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 222 | ids: so |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 223 | }); |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 224 | trafficMode = 'intents'; |
| 225 | hoverMode = null; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 226 | flash.flash('Multi-Source flow added'); |
| 227 | } |
| 228 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 229 | function removeIntents () { |
Deepa Vaddireddy | 6334092 | 2017-01-19 08:15:31 +0530 | [diff] [blame] | 230 | $log.debug('Entering removeIntents'); |
| 231 | wss.sendEvent('removeIntents', {}); |
| 232 | trafficMode = 'intents'; |
| 233 | hoverMode = null; |
| 234 | flash.flash('Intent are purged'); |
| 235 | } |
| 236 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 237 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 238 | // === ----------------------------------------------------- |
| 239 | // === MODULE DEFINITION === |
| 240 | |
| 241 | angular.module('ovTopo') |
Simon Hunt | 75ec969 | 2015-02-11 16:40:36 -0800 | [diff] [blame] | 242 | .factory('TopoTrafficService', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 243 | ['$log', 'FnService', 'FlashService', 'WebSocketService', |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 244 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 245 | function (_$log_, _fs_, _flash_, _wss_) { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 246 | $log = _$log_; |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 247 | fs = _fs_; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 248 | flash = _flash_; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 249 | wss = _wss_; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 250 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 251 | return { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 252 | initTraffic: function (_api_) { api = _api_; }, |
| 253 | destroyTraffic: function () { }, |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 254 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 255 | // invoked from toolbar overlay buttons or keystrokes |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 256 | cancelTraffic: cancelTraffic, |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 257 | showAllTraffic: showAllTraffic, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 258 | showDeviceLinkFlows: showDeviceLinkFlows, |
| 259 | showRelatedIntents: showRelatedIntents, |
| 260 | showPrevIntent: showPrevIntent, |
| 261 | showNextIntent: showNextIntent, |
| 262 | showSelectedIntentTraffic: showSelectedIntentTraffic, |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 263 | selectIntent: selectIntent, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 264 | |
| 265 | // invoked from mouseover/mouseout and selection change |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 266 | requestTrafficForMode: requestTrafficForMode, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 267 | |
Simon Hunt | d3ceffa | 2015-08-25 12:44:35 -0700 | [diff] [blame] | 268 | // TODO: these should move to new UI demo app |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 269 | // invoked from buttons on detail (multi-select) panel |
| 270 | addHostIntent: addHostIntent, |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 271 | addMultiSourceIntent: addMultiSourceIntent, |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 272 | removeIntent: removeIntent, |
Deepa Vaddireddy | 6334092 | 2017-01-19 08:15:31 +0530 | [diff] [blame] | 273 | resubmitIntent: resubmitIntent, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 274 | removeIntents: removeIntents |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 275 | }; |
| 276 | }]); |
| 277 | }()); |