blob: 5d52ab1e6f3589bcba680d0f65e96905742c8b35 [file] [log] [blame]
Simon Huntf542d842015-02-11 16:20:33 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Huntf542d842015-02-11 16:20:33 -08003 *
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 Hunt8d22c4b2015-08-06 16:24:43 -070026 var $log, fs, flash, wss, api;
Simon Huntf542d842015-02-11 16:20:33 -080027
Simon Huntf542d842015-02-11 16:20:33 -080028 /*
Simon Hunt8d22c4b2015-08-06 16:24:43 -070029 API to topoForce
30 hovered()
31 somethingSelected()
32 selectOrder()
Simon Huntf542d842015-02-11 16:20:33 -080033 */
34
Simon Huntf542d842015-02-11 16:20:33 -080035 // internal state
Simon Hunt8d22c4b2015-08-06 16:24:43 -070036 var trafficMode = null,
37 hoverMode = null;
Simon Huntf542d842015-02-11 16:20:33 -080038
39
40 // === -----------------------------------------------------
Simon Huntf542d842015-02-11 16:20:33 -080041 // Helper functions
42
Simon Hunt8d22c4b2015-08-06 16:24:43 -070043 // invoked in response to change in selection and/or mouseover/out:
Simon Huntd2862c32015-08-24 17:41:51 -070044 function requestTrafficForMode(mouse) {
Simon Hunta17fa672015-08-19 18:42:22 -070045 if (trafficMode === 'flows') {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070046 requestDeviceLinkFlows();
Simon Hunta17fa672015-08-19 18:42:22 -070047 } else if (trafficMode === 'intents') {
Simon Huntd2862c32015-08-24 17:41:51 -070048 if (!mouse || hoverMode === 'intents') {
49 requestRelatedIntents();
50 }
Simon Hunt8d22c4b2015-08-06 16:24:43 -070051 } else {
Simon Huntd2862c32015-08-24 17:41:51 -070052 // do nothing
Simon Hunt8d22c4b2015-08-06 16:24:43 -070053 }
54 }
55
Simon Huntf542d842015-02-11 16:20:33 -080056 function requestDeviceLinkFlows() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070057 // generates payload based on current hover-state
Simon Huntf542d842015-02-11 16:20:33 -080058 var hov = api.hovered();
59
60 function hoverValid() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070061 return hoverMode === 'flows' &&
Simon Huntf542d842015-02-11 16:20:33 -080062 hov && (hov.class === 'device');
63 }
64
Simon Hunt8d22c4b2015-08-06 16:24:43 -070065 if (api.somethingSelected()) {
Simon Hunt237676b52015-03-10 19:04:26 -070066 wss.sendEvent('requestDeviceLinkFlows', {
Simon Huntf542d842015-02-11 16:20:33 -080067 ids: api.selectOrder(),
68 hover: hoverValid() ? hov.id : ''
69 });
70 }
71 }
72
73 function requestRelatedIntents() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070074 // generates payload based on current hover-state
Simon Huntf542d842015-02-11 16:20:33 -080075 var hov = api.hovered();
76
77 function hoverValid() {
Prince Pereira46c82d42016-09-19 13:30:50 +053078 return hoverMode === 'intents' && hov && (
79 hov.class === 'host' ||
80 hov.class === 'device' ||
81 hov.class === 'link');
Simon Huntf542d842015-02-11 16:20:33 -080082 }
83
Simon Hunt8d22c4b2015-08-06 16:24:43 -070084 if (api.somethingSelected()) {
Simon Hunt237676b52015-03-10 19:04:26 -070085 wss.sendEvent('requestRelatedIntents', {
Simon Huntf542d842015-02-11 16:20:33 -080086 ids: api.selectOrder(),
87 hover: hoverValid() ? hov.id : ''
88 });
89 }
90 }
91
92
Simon Hunt8d22c4b2015-08-06 16:24:43 -070093 // === -------------------------------------------------------------
94 // Traffic requests invoked from keystrokes or toolbar buttons...
Simon Huntf542d842015-02-11 16:20:33 -080095
Simon Huntd2862c32015-08-24 17:41:51 -070096 function cancelTraffic(forced) {
97 if (!trafficMode || (!forced && trafficMode === 'allFlowPort')) {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070098 return false;
Simon Huntf542d842015-02-11 16:20:33 -080099 }
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700100
101 trafficMode = hoverMode = null;
102 wss.sendEvent('cancelTraffic');
103 flash.flash('Traffic monitoring canceled');
104 return true;
Simon Huntf542d842015-02-11 16:20:33 -0800105 }
106
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700107 function showAllFlowTraffic() {
Simon Huntd2862c32015-08-24 17:41:51 -0700108 trafficMode = 'allFlowPort';
109 hoverMode = null;
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700110 wss.sendEvent('requestAllFlowTraffic');
111 flash.flash('All Flow Traffic');
112 }
113
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700114 function showAllPortTraffic() {
Simon Huntd2862c32015-08-24 17:41:51 -0700115 trafficMode = 'allFlowPort';
116 hoverMode = null;
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700117 wss.sendEvent('requestAllPortTraffic');
118 flash.flash('All Port Traffic');
Simon Huntf542d842015-02-11 16:20:33 -0800119 }
120
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700121 function showDeviceLinkFlows () {
122 trafficMode = hoverMode = 'flows';
123 requestDeviceLinkFlows();
124 flash.flash('Device Flows');
125 }
Simon Huntf542d842015-02-11 16:20:33 -0800126
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700127 function showRelatedIntents () {
128 trafficMode = hoverMode = 'intents';
Simon Huntf542d842015-02-11 16:20:33 -0800129 requestRelatedIntents();
130 flash.flash('Related Paths');
131 }
132
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700133 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 Hunt4a6b54b2015-10-27 22:08:25 -0700157 // 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 Hunt8d22c4b2015-08-06 16:24:43 -0700165
166 // === ------------------------------------------------------
167 // action buttons on detail panel (multiple selection)
168
169 function addHostIntent () {
Simon Huntf542d842015-02-11 16:20:33 -0800170 var so = api.selectOrder();
Simon Hunt237676b52015-03-10 19:04:26 -0700171 wss.sendEvent('addHostIntent', {
Simon Huntf542d842015-02-11 16:20:33 -0800172 one: so[0],
173 two: so[1],
174 ids: so
175 });
Simon Huntd2862c32015-08-24 17:41:51 -0700176 trafficMode = 'intents';
177 hoverMode = null;
Simon Huntf542d842015-02-11 16:20:33 -0800178 flash.flash('Host-to-Host flow added');
179 }
180
Viswanath KSP0f297702016-08-13 18:02:43 +0530181 function removeIntent (d) {
182 $log.debug('Entering removeIntent');
183 wss.sendEvent('removeIntent', {
184 appId: d.appId,
185 appName: d.appName,
Viswanath KSP813a20d2016-09-13 04:25:41 +0530186 key: d.key,
187 purge: d.intentPurge
Viswanath KSP0f297702016-08-13 18:02:43 +0530188 });
189 trafficMode = 'intents';
190 hoverMode = null;
Viswanath KSP813a20d2016-09-13 04:25:41 +0530191 var txt = d.intentPurge ? 'purged' : 'withdrawn';
192 flash.flash('Intent ' + txt);
Viswanath KSP0f297702016-08-13 18:02:43 +0530193 }
194
Viswanath KSP14aee092016-10-02 01:47:40 +0530195 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 Hunt8d22c4b2015-08-06 16:24:43 -0700208 function addMultiSourceIntent () {
Simon Huntf542d842015-02-11 16:20:33 -0800209 var so = api.selectOrder();
Simon Hunt237676b52015-03-10 19:04:26 -0700210 wss.sendEvent('addMultiSourceIntent', {
Simon Huntf542d842015-02-11 16:20:33 -0800211 src: so.slice(0, so.length - 1),
212 dst: so[so.length - 1],
213 ids: so
214 });
Simon Huntd2862c32015-08-24 17:41:51 -0700215 trafficMode = 'intents';
216 hoverMode = null;
Simon Huntf542d842015-02-11 16:20:33 -0800217 flash.flash('Multi-Source flow added');
218 }
219
Simon Huntf542d842015-02-11 16:20:33 -0800220
Simon Huntf542d842015-02-11 16:20:33 -0800221 // === -----------------------------------------------------
222 // === MODULE DEFINITION ===
223
224 angular.module('ovTopo')
Simon Hunt75ec9692015-02-11 16:40:36 -0800225 .factory('TopoTrafficService',
Simon Hunt237676b52015-03-10 19:04:26 -0700226 ['$log', 'FnService', 'FlashService', 'WebSocketService',
Simon Huntf542d842015-02-11 16:20:33 -0800227
Simon Hunt237676b52015-03-10 19:04:26 -0700228 function (_$log_, _fs_, _flash_, _wss_) {
Simon Huntf542d842015-02-11 16:20:33 -0800229 $log = _$log_;
230 fs = _fs_;
231 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700232 wss = _wss_;
Simon Huntf542d842015-02-11 16:20:33 -0800233
Simon Huntf542d842015-02-11 16:20:33 -0800234 return {
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700235 initTraffic: function (_api_) { api = _api_; },
236 destroyTraffic: function () { },
Simon Huntf542d842015-02-11 16:20:33 -0800237
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700238 // invoked from toolbar overlay buttons or keystrokes
Simon Huntf542d842015-02-11 16:20:33 -0800239 cancelTraffic: cancelTraffic,
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700240 showAllFlowTraffic: showAllFlowTraffic,
241 showAllPortTraffic: showAllPortTraffic,
242 showDeviceLinkFlows: showDeviceLinkFlows,
243 showRelatedIntents: showRelatedIntents,
244 showPrevIntent: showPrevIntent,
245 showNextIntent: showNextIntent,
246 showSelectedIntentTraffic: showSelectedIntentTraffic,
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700247 selectIntent: selectIntent,
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700248
249 // invoked from mouseover/mouseout and selection change
Simon Huntf542d842015-02-11 16:20:33 -0800250 requestTrafficForMode: requestTrafficForMode,
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700251
Simon Huntd3ceffa2015-08-25 12:44:35 -0700252 // TODO: these should move to new UI demo app
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700253 // invoked from buttons on detail (multi-select) panel
254 addHostIntent: addHostIntent,
Viswanath KSP0f297702016-08-13 18:02:43 +0530255 addMultiSourceIntent: addMultiSourceIntent,
Viswanath KSP14aee092016-10-02 01:47:40 +0530256 removeIntent: removeIntent,
257 resubmitIntent: resubmitIntent
Simon Huntf542d842015-02-11 16:20:33 -0800258 };
259 }]);
260}());