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