blob: 93085423af0b19e05fefe6ce6493e98dd02115d6 [file] [log] [blame]
Simon Huntf542d842015-02-11 16:20:33 -08001/*
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 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:
44 function requestTrafficForMode() {
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 Hunt8d22c4b2015-08-06 16:24:43 -070048 requestRelatedIntents();
49 } else {
50 cancelTraffic();
51 }
52 }
53
Simon Huntf542d842015-02-11 16:20:33 -080054 function requestDeviceLinkFlows() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070055 // generates payload based on current hover-state
Simon Huntf542d842015-02-11 16:20:33 -080056 var hov = api.hovered();
57
58 function hoverValid() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070059 return hoverMode === 'flows' &&
Simon Huntf542d842015-02-11 16:20:33 -080060 hov && (hov.class === 'device');
61 }
62
Simon Hunt8d22c4b2015-08-06 16:24:43 -070063 if (api.somethingSelected()) {
Simon Hunt237676b52015-03-10 19:04:26 -070064 wss.sendEvent('requestDeviceLinkFlows', {
Simon Huntf542d842015-02-11 16:20:33 -080065 ids: api.selectOrder(),
66 hover: hoverValid() ? hov.id : ''
67 });
68 }
69 }
70
71 function requestRelatedIntents() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070072 // generates payload based on current hover-state
Simon Huntf542d842015-02-11 16:20:33 -080073 var hov = api.hovered();
74
75 function hoverValid() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070076 return hoverMode === 'intents' &&
Simon Huntf542d842015-02-11 16:20:33 -080077 hov && (hov.class === 'host' || hov.class === 'device');
78 }
79
Simon Hunt8d22c4b2015-08-06 16:24:43 -070080 if (api.somethingSelected()) {
Simon Hunt237676b52015-03-10 19:04:26 -070081 wss.sendEvent('requestRelatedIntents', {
Simon Huntf542d842015-02-11 16:20:33 -080082 ids: api.selectOrder(),
83 hover: hoverValid() ? hov.id : ''
84 });
85 }
86 }
87
88
Simon Hunt8d22c4b2015-08-06 16:24:43 -070089 // === -------------------------------------------------------------
90 // Traffic requests invoked from keystrokes or toolbar buttons...
Simon Huntf542d842015-02-11 16:20:33 -080091
92 function cancelTraffic() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070093 if (!trafficMode) {
94 return false;
Simon Huntf542d842015-02-11 16:20:33 -080095 }
Simon Hunt8d22c4b2015-08-06 16:24:43 -070096
97 trafficMode = hoverMode = null;
98 wss.sendEvent('cancelTraffic');
99 flash.flash('Traffic monitoring canceled');
100 return true;
Simon Huntf542d842015-02-11 16:20:33 -0800101 }
102
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700103 function showAllFlowTraffic() {
104 trafficMode = 'allFlow';
105 hoverMode = 'all';
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700106 wss.sendEvent('requestAllFlowTraffic');
107 flash.flash('All Flow Traffic');
108 }
109
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700110 function showAllPortTraffic() {
111 trafficMode = 'allPort';
112 hoverMode = 'all';
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700113 wss.sendEvent('requestAllPortTraffic');
114 flash.flash('All Port Traffic');
Simon Huntf542d842015-02-11 16:20:33 -0800115 }
116
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700117 function showDeviceLinkFlows () {
118 trafficMode = hoverMode = 'flows';
119 requestDeviceLinkFlows();
120 flash.flash('Device Flows');
121 }
Simon Huntf542d842015-02-11 16:20:33 -0800122
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700123 function showRelatedIntents () {
124 trafficMode = hoverMode = 'intents';
Simon Huntf542d842015-02-11 16:20:33 -0800125 requestRelatedIntents();
126 flash.flash('Related Paths');
127 }
128
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700129 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 Huntf542d842015-02-11 16:20:33 -0800158 var so = api.selectOrder();
Simon Hunt237676b52015-03-10 19:04:26 -0700159 wss.sendEvent('addHostIntent', {
Simon Huntf542d842015-02-11 16:20:33 -0800160 one: so[0],
161 two: so[1],
162 ids: so
163 });
164 flash.flash('Host-to-Host flow added');
165 }
166
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700167 function addMultiSourceIntent () {
Simon Huntf542d842015-02-11 16:20:33 -0800168 var so = api.selectOrder();
Simon Hunt237676b52015-03-10 19:04:26 -0700169 wss.sendEvent('addMultiSourceIntent', {
Simon Huntf542d842015-02-11 16:20:33 -0800170 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 Huntf542d842015-02-11 16:20:33 -0800177
Simon Huntf542d842015-02-11 16:20:33 -0800178 // === -----------------------------------------------------
179 // === MODULE DEFINITION ===
180
181 angular.module('ovTopo')
Simon Hunt75ec9692015-02-11 16:40:36 -0800182 .factory('TopoTrafficService',
Simon Hunt237676b52015-03-10 19:04:26 -0700183 ['$log', 'FnService', 'FlashService', 'WebSocketService',
Simon Huntf542d842015-02-11 16:20:33 -0800184
Simon Hunt237676b52015-03-10 19:04:26 -0700185 function (_$log_, _fs_, _flash_, _wss_) {
Simon Huntf542d842015-02-11 16:20:33 -0800186 $log = _$log_;
187 fs = _fs_;
188 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700189 wss = _wss_;
Simon Huntf542d842015-02-11 16:20:33 -0800190
Simon Huntf542d842015-02-11 16:20:33 -0800191 return {
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700192 initTraffic: function (_api_) { api = _api_; },
193 destroyTraffic: function () { },
Simon Huntf542d842015-02-11 16:20:33 -0800194
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700195 // invoked from toolbar overlay buttons or keystrokes
Simon Huntf542d842015-02-11 16:20:33 -0800196 cancelTraffic: cancelTraffic,
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700197 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 Huntf542d842015-02-11 16:20:33 -0800206 requestTrafficForMode: requestTrafficForMode,
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700207
208 // invoked from buttons on detail (multi-select) panel
209 addHostIntent: addHostIntent,
210 addMultiSourceIntent: addMultiSourceIntent
Simon Huntf542d842015-02-11 16:20:33 -0800211 };
212 }]);
213}());