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