blob: a2cd81825378dc83be95c86d929aef9f88c38d4d [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:
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() {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070078 return hoverMode === 'intents' &&
Simon Huntf542d842015-02-11 16:20:33 -080079 hov && (hov.class === 'host' || hov.class === 'device');
80 }
81
Simon Hunt8d22c4b2015-08-06 16:24:43 -070082 if (api.somethingSelected()) {
Simon Hunt237676b52015-03-10 19:04:26 -070083 wss.sendEvent('requestRelatedIntents', {
Simon Huntf542d842015-02-11 16:20:33 -080084 ids: api.selectOrder(),
85 hover: hoverValid() ? hov.id : ''
86 });
87 }
88 }
89
90
Simon Hunt8d22c4b2015-08-06 16:24:43 -070091 // === -------------------------------------------------------------
92 // Traffic requests invoked from keystrokes or toolbar buttons...
Simon Huntf542d842015-02-11 16:20:33 -080093
Simon Huntd2862c32015-08-24 17:41:51 -070094 function cancelTraffic(forced) {
95 if (!trafficMode || (!forced && trafficMode === 'allFlowPort')) {
Simon Hunt8d22c4b2015-08-06 16:24:43 -070096 return false;
Simon Huntf542d842015-02-11 16:20:33 -080097 }
Simon Hunt8d22c4b2015-08-06 16:24:43 -070098
99 trafficMode = hoverMode = null;
100 wss.sendEvent('cancelTraffic');
101 flash.flash('Traffic monitoring canceled');
102 return true;
Simon Huntf542d842015-02-11 16:20:33 -0800103 }
104
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700105 function showAllFlowTraffic() {
Simon Huntd2862c32015-08-24 17:41:51 -0700106 trafficMode = 'allFlowPort';
107 hoverMode = null;
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700108 wss.sendEvent('requestAllFlowTraffic');
109 flash.flash('All Flow Traffic');
110 }
111
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700112 function showAllPortTraffic() {
Simon Huntd2862c32015-08-24 17:41:51 -0700113 trafficMode = 'allFlowPort';
114 hoverMode = null;
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700115 wss.sendEvent('requestAllPortTraffic');
116 flash.flash('All Port Traffic');
Simon Huntf542d842015-02-11 16:20:33 -0800117 }
118
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700119 function showDeviceLinkFlows () {
120 trafficMode = hoverMode = 'flows';
121 requestDeviceLinkFlows();
122 flash.flash('Device Flows');
123 }
Simon Huntf542d842015-02-11 16:20:33 -0800124
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700125 function showRelatedIntents () {
126 trafficMode = hoverMode = 'intents';
Simon Huntf542d842015-02-11 16:20:33 -0800127 requestRelatedIntents();
128 flash.flash('Related Paths');
129 }
130
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700131 function showPrevIntent() {
132 if (trafficMode === 'intents') {
133 hoverMode = null;
134 wss.sendEvent('requestPrevRelatedIntent');
135 flash.flash('Previous related intent');
136 }
137 }
138
139 function showNextIntent() {
140 if (trafficMode === 'intents') {
141 hoverMode = null;
142 wss.sendEvent('requestNextRelatedIntent');
143 flash.flash('Next related intent');
144 }
145 }
146
147 function showSelectedIntentTraffic() {
148 if (trafficMode === 'intents') {
149 hoverMode = null;
150 wss.sendEvent('requestSelectedIntentTraffic');
151 flash.flash('Traffic on Selected Path');
152 }
153 }
154
155
156 // === ------------------------------------------------------
157 // action buttons on detail panel (multiple selection)
158
159 function addHostIntent () {
Simon Huntf542d842015-02-11 16:20:33 -0800160 var so = api.selectOrder();
Simon Hunt237676b52015-03-10 19:04:26 -0700161 wss.sendEvent('addHostIntent', {
Simon Huntf542d842015-02-11 16:20:33 -0800162 one: so[0],
163 two: so[1],
164 ids: so
165 });
Simon Huntd2862c32015-08-24 17:41:51 -0700166 trafficMode = 'intents';
167 hoverMode = null;
Simon Huntf542d842015-02-11 16:20:33 -0800168 flash.flash('Host-to-Host flow added');
169 }
170
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700171 function addMultiSourceIntent () {
Simon Huntf542d842015-02-11 16:20:33 -0800172 var so = api.selectOrder();
Simon Hunt237676b52015-03-10 19:04:26 -0700173 wss.sendEvent('addMultiSourceIntent', {
Simon Huntf542d842015-02-11 16:20:33 -0800174 src: so.slice(0, so.length - 1),
175 dst: so[so.length - 1],
176 ids: so
177 });
Simon Huntd2862c32015-08-24 17:41:51 -0700178 trafficMode = 'intents';
179 hoverMode = null;
Simon Huntf542d842015-02-11 16:20:33 -0800180 flash.flash('Multi-Source flow added');
181 }
182
Simon Huntf542d842015-02-11 16:20:33 -0800183
Simon Huntf542d842015-02-11 16:20:33 -0800184 // === -----------------------------------------------------
185 // === MODULE DEFINITION ===
186
187 angular.module('ovTopo')
Simon Hunt75ec9692015-02-11 16:40:36 -0800188 .factory('TopoTrafficService',
Simon Hunt237676b52015-03-10 19:04:26 -0700189 ['$log', 'FnService', 'FlashService', 'WebSocketService',
Simon Huntf542d842015-02-11 16:20:33 -0800190
Simon Hunt237676b52015-03-10 19:04:26 -0700191 function (_$log_, _fs_, _flash_, _wss_) {
Simon Huntf542d842015-02-11 16:20:33 -0800192 $log = _$log_;
193 fs = _fs_;
194 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700195 wss = _wss_;
Simon Huntf542d842015-02-11 16:20:33 -0800196
Simon Huntf542d842015-02-11 16:20:33 -0800197 return {
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700198 initTraffic: function (_api_) { api = _api_; },
199 destroyTraffic: function () { },
Simon Huntf542d842015-02-11 16:20:33 -0800200
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700201 // invoked from toolbar overlay buttons or keystrokes
Simon Huntf542d842015-02-11 16:20:33 -0800202 cancelTraffic: cancelTraffic,
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700203 showAllFlowTraffic: showAllFlowTraffic,
204 showAllPortTraffic: showAllPortTraffic,
205 showDeviceLinkFlows: showDeviceLinkFlows,
206 showRelatedIntents: showRelatedIntents,
207 showPrevIntent: showPrevIntent,
208 showNextIntent: showNextIntent,
209 showSelectedIntentTraffic: showSelectedIntentTraffic,
210
211 // invoked from mouseover/mouseout and selection change
Simon Huntf542d842015-02-11 16:20:33 -0800212 requestTrafficForMode: requestTrafficForMode,
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700213
214 // invoked from buttons on detail (multi-select) panel
215 addHostIntent: addHostIntent,
216 addMultiSourceIntent: addMultiSourceIntent
Simon Huntf542d842015-02-11 16:20:33 -0800217 };
218 }]);
219}());