Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | /* |
| 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: |
| 44 | function requestTrafficForMode() { |
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 | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 48 | requestRelatedIntents(); |
| 49 | } else { |
| 50 | cancelTraffic(); |
| 51 | } |
| 52 | } |
| 53 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 54 | function requestDeviceLinkFlows() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 55 | // generates payload based on current hover-state |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 56 | var hov = api.hovered(); |
| 57 | |
| 58 | function hoverValid() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 59 | return hoverMode === 'flows' && |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 60 | hov && (hov.class === 'device'); |
| 61 | } |
| 62 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 63 | if (api.somethingSelected()) { |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 64 | wss.sendEvent('requestDeviceLinkFlows', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 65 | ids: api.selectOrder(), |
| 66 | hover: hoverValid() ? hov.id : '' |
| 67 | }); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | function requestRelatedIntents() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 72 | // generates payload based on current hover-state |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 73 | var hov = api.hovered(); |
| 74 | |
| 75 | function hoverValid() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 76 | return hoverMode === 'intents' && |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 77 | hov && (hov.class === 'host' || hov.class === 'device'); |
| 78 | } |
| 79 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 80 | if (api.somethingSelected()) { |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 81 | wss.sendEvent('requestRelatedIntents', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 82 | ids: api.selectOrder(), |
| 83 | hover: hoverValid() ? hov.id : '' |
| 84 | }); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 89 | // === ------------------------------------------------------------- |
| 90 | // Traffic requests invoked from keystrokes or toolbar buttons... |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 91 | |
| 92 | function cancelTraffic() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 93 | if (!trafficMode) { |
| 94 | return false; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 95 | } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 96 | |
| 97 | trafficMode = hoverMode = null; |
| 98 | wss.sendEvent('cancelTraffic'); |
| 99 | flash.flash('Traffic monitoring canceled'); |
| 100 | return true; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 103 | function showAllFlowTraffic() { |
| 104 | trafficMode = 'allFlow'; |
| 105 | hoverMode = 'all'; |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 106 | wss.sendEvent('requestAllFlowTraffic'); |
| 107 | flash.flash('All Flow Traffic'); |
| 108 | } |
| 109 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 110 | function showAllPortTraffic() { |
| 111 | trafficMode = 'allPort'; |
| 112 | hoverMode = 'all'; |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 113 | wss.sendEvent('requestAllPortTraffic'); |
| 114 | flash.flash('All Port Traffic'); |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 117 | function showDeviceLinkFlows () { |
| 118 | trafficMode = hoverMode = 'flows'; |
| 119 | requestDeviceLinkFlows(); |
| 120 | flash.flash('Device Flows'); |
| 121 | } |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 122 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 123 | function showRelatedIntents () { |
| 124 | trafficMode = hoverMode = 'intents'; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 125 | requestRelatedIntents(); |
| 126 | flash.flash('Related Paths'); |
| 127 | } |
| 128 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 129 | function showPrevIntent() { |
| 130 | if (trafficMode === 'intents') { |
| 131 | hoverMode = null; |
| 132 | wss.sendEvent('requestPrevRelatedIntent'); |
| 133 | flash.flash('Previous related intent'); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | function showNextIntent() { |
| 138 | if (trafficMode === 'intents') { |
| 139 | hoverMode = null; |
| 140 | wss.sendEvent('requestNextRelatedIntent'); |
| 141 | flash.flash('Next related intent'); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | function showSelectedIntentTraffic() { |
| 146 | if (trafficMode === 'intents') { |
| 147 | hoverMode = null; |
| 148 | wss.sendEvent('requestSelectedIntentTraffic'); |
| 149 | flash.flash('Traffic on Selected Path'); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | // === ------------------------------------------------------ |
| 155 | // action buttons on detail panel (multiple selection) |
| 156 | |
| 157 | function addHostIntent () { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 158 | var so = api.selectOrder(); |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 159 | wss.sendEvent('addHostIntent', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 160 | one: so[0], |
| 161 | two: so[1], |
| 162 | ids: so |
| 163 | }); |
| 164 | flash.flash('Host-to-Host flow added'); |
| 165 | } |
| 166 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 167 | function addMultiSourceIntent () { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 168 | var so = api.selectOrder(); |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 169 | wss.sendEvent('addMultiSourceIntent', { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 170 | src: so.slice(0, so.length - 1), |
| 171 | dst: so[so.length - 1], |
| 172 | ids: so |
| 173 | }); |
| 174 | flash.flash('Multi-Source flow added'); |
| 175 | } |
| 176 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 177 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 178 | // === ----------------------------------------------------- |
| 179 | // === MODULE DEFINITION === |
| 180 | |
| 181 | angular.module('ovTopo') |
Simon Hunt | 75ec969 | 2015-02-11 16:40:36 -0800 | [diff] [blame] | 182 | .factory('TopoTrafficService', |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 183 | ['$log', 'FnService', 'FlashService', 'WebSocketService', |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 184 | |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 185 | function (_$log_, _fs_, _flash_, _wss_) { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 186 | $log = _$log_; |
| 187 | fs = _fs_; |
| 188 | flash = _flash_; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 189 | wss = _wss_; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 190 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 191 | return { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 192 | initTraffic: function (_api_) { api = _api_; }, |
| 193 | destroyTraffic: function () { }, |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 194 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 195 | // invoked from toolbar overlay buttons or keystrokes |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 196 | cancelTraffic: cancelTraffic, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 197 | showAllFlowTraffic: showAllFlowTraffic, |
| 198 | showAllPortTraffic: showAllPortTraffic, |
| 199 | showDeviceLinkFlows: showDeviceLinkFlows, |
| 200 | showRelatedIntents: showRelatedIntents, |
| 201 | showPrevIntent: showPrevIntent, |
| 202 | showNextIntent: showNextIntent, |
| 203 | showSelectedIntentTraffic: showSelectedIntentTraffic, |
| 204 | |
| 205 | // invoked from mouseover/mouseout and selection change |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 206 | requestTrafficForMode: requestTrafficForMode, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 207 | |
| 208 | // invoked from buttons on detail (multi-select) panel |
| 209 | addHostIntent: addHostIntent, |
| 210 | addMultiSourceIntent: addMultiSourceIntent |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 211 | }; |
| 212 | }]); |
| 213 | }()); |