blob: 2057f7b708fcd40342629fa89575fcc6cb6b3260 [file] [log] [blame]
Simon Hunt72e44bf2015-07-21 21:34:20 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Hunt72e44bf2015-07-21 21:34:20 -07003 *
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/*
Simon Hunt8d22c4b2015-08-06 16:24:43 -070019 ONOS GUI -- Topology Traffic Overlay Module.
Simon Hunt72e44bf2015-07-21 21:34:20 -070020 Defines behavior for viewing different traffic modes.
21 Installed as a Topology Overlay.
22 */
23(function () {
24 'use strict';
25
26 // injected refs
Simon Hunt8d22c4b2015-08-06 16:24:43 -070027 var $log, tov, tts;
28
Simon Huntcaed0412017-08-12 13:49:17 -070029 // function to be replaced by the localization bundle function
30 var topoLion = function (x) {
31 return '#ttrafov#' + x + '#';
32 };
33
Simon Hunt8d22c4b2015-08-06 16:24:43 -070034 // NOTE: no internal state here -- see TopoTrafficService for that
35
36 // NOTE: providing button disabling requires too big a refactoring of
37 // the button factory etc. Will have to be done another time.
38
Simon Hunt72e44bf2015-07-21 21:34:20 -070039
40 // traffic overlay definition
41 var overlay = {
42 overlayId: 'traffic',
Simon Huntc217cb92016-08-30 16:17:51 -070043 glyphId: 'm_allTraffic',
Simon Huntcaed0412017-08-12 13:49:17 -070044 tooltip: function () { return topoLion('ov_tt_traffic'); },
Simon Hunt72e44bf2015-07-21 21:34:20 -070045
Simon Hunt8d22c4b2015-08-06 16:24:43 -070046 // NOTE: Traffic glyphs already installed as part of the base ONOS set.
47
48 activate: function () {
Steven Burrows1c2a9682017-07-14 16:52:46 +010049 $log.debug('Traffic overlay ACTIVATED');
Simon Hunt8d22c4b2015-08-06 16:24:43 -070050 },
51
52 deactivate: function () {
Simon Huntd2862c32015-08-24 17:41:51 -070053 tts.cancelTraffic(true);
Steven Burrows1c2a9682017-07-14 16:52:46 +010054 $log.debug('Traffic overlay DEACTIVATED');
Simon Hunt8d22c4b2015-08-06 16:24:43 -070055 },
56
57 // detail panel button definitions
58 // (keys match button identifiers, also defined in TrafficOverlay.java)
59 buttons: {
60 showDeviceFlows: {
Simon Huntc217cb92016-08-30 16:17:51 -070061 gid: 'm_flows',
Simon Huntcaed0412017-08-12 13:49:17 -070062 tt: function () { return topoLion('tr_btn_show_device_flows'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010063 cb: function (data) { tts.showDeviceLinkFlows(); },
Simon Hunt8d22c4b2015-08-06 16:24:43 -070064 },
65
66 showRelatedTraffic: {
Simon Huntc217cb92016-08-30 16:17:51 -070067 gid: 'm_relatedIntents',
Simon Huntcaed0412017-08-12 13:49:17 -070068 tt: function () { return topoLion('tr_btn_show_related_traffic'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010069 cb: function (data) { tts.showRelatedIntents(); },
70 },
Simon Hunt8d22c4b2015-08-06 16:24:43 -070071 },
72
73 // key bindings for traffic overlay toolbar buttons
74 // NOTE: fully qual. button ID is derived from overlay-id and key-name
75 keyBindings: {
76 0: {
Simon Huntd2862c32015-08-24 17:41:51 -070077 cb: function () { tts.cancelTraffic(true); },
Simon Huntcaed0412017-08-12 13:49:17 -070078 tt: function () { return topoLion('tr_btn_cancel_monitoring'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010079 gid: 'm_xMark',
Simon Hunt8d22c4b2015-08-06 16:24:43 -070080 },
81
82 A: {
Simon Hunt21281fd2017-03-30 22:28:28 -070083 cb: function () { tts.showAllTraffic(); },
Simon Huntcaed0412017-08-12 13:49:17 -070084 tt: function () { return topoLion('tr_btn_monitor_all'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010085 gid: 'm_allTraffic',
Simon Hunt8d22c4b2015-08-06 16:24:43 -070086 },
87 F: {
88 cb: function () { tts.showDeviceLinkFlows(); },
Simon Huntcaed0412017-08-12 13:49:17 -070089 tt: function () { return topoLion('tr_btn_show_dev_link_flows'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010090 gid: 'm_flows',
Simon Hunt8d22c4b2015-08-06 16:24:43 -070091 },
92 V: {
93 cb: function () { tts.showRelatedIntents(); },
Simon Huntcaed0412017-08-12 13:49:17 -070094 tt: function () { return topoLion('tr_btn_show_all_rel_intents'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010095 gid: 'm_relatedIntents',
Simon Hunt8d22c4b2015-08-06 16:24:43 -070096 },
97 leftArrow: {
98 cb: function () { tts.showPrevIntent(); },
Simon Huntcaed0412017-08-12 13:49:17 -070099 tt: function () { return topoLion('tr_btn_show_prev_rel_intent'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100100 gid: 'm_prev',
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700101 },
102 rightArrow: {
103 cb: function () { tts.showNextIntent(); },
Simon Huntcaed0412017-08-12 13:49:17 -0700104 tt: function () { return topoLion('tr_btn_show_next_rel_intent'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100105 gid: 'm_next',
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700106 },
107 W: {
108 cb: function () { tts.showSelectedIntentTraffic(); },
Simon Huntcaed0412017-08-12 13:49:17 -0700109 tt: function () { return topoLion('tr_btn_monitor_sel_intent'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100110 gid: 'm_intentTraffic',
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700111 },
Thomas Vachuska2b4de872021-03-30 16:31:34 -0700112 C: {
113 cb: function () { tts.showCustomTraffic(); },
114 tt: function () { return topoLion('tr_btn_monitor_custom_all'); },
115 gid: 'm_allTraffic',
116 },
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700117
118 _keyOrder: [
Thomas Vachuska2b4de872021-03-30 16:31:34 -0700119 '0', 'A', 'F', 'V', 'leftArrow', 'rightArrow', 'W', 'C'
Steven Burrows1c2a9682017-07-14 16:52:46 +0100120 ],
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700121 },
122
123 hooks: {
124 // hook for handling escape key
125 escape: function () {
126 // Must return true to consume ESC, false otherwise.
Simon Hunt57830172015-08-26 13:25:17 -0700127 return tts.cancelTraffic(true);
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700128 },
129
130 // hooks for when the selection changes...
131 empty: function () {
132 tts.cancelTraffic();
133 },
134 single: function (data) {
135 tts.requestTrafficForMode();
136 },
137 multi: function (selectOrder) {
138 tts.requestTrafficForMode();
139 tov.addDetailButton('showRelatedTraffic');
Simon Hunt584e92d2015-08-24 11:27:22 -0700140 },
141
142 // mouse hooks
143 mouseover: function (m) {
144 // m has id, class, and type properties
Simon Huntd2862c32015-08-24 17:41:51 -0700145 tts.requestTrafficForMode(true);
Simon Hunt584e92d2015-08-24 11:27:22 -0700146 },
147 mouseout: function () {
Simon Huntd2862c32015-08-24 17:41:51 -0700148 tts.requestTrafficForMode(true);
Simon Hunt8419efd2017-01-12 12:36:28 -0800149 },
150
Simon Hunt441c9ae2017-02-03 18:22:31 -0800151 // intent visualization hooks
152 acceptIntent: function (type) {
153 // accept any intent type except "Protected" intents
154 return (!type.startsWith('Protected'));
155 },
156 showIntent: function (info) {
Simon Huntfc5c5842017-02-01 23:32:18 -0800157 $log.debug('^^ trafficOverlay.showintent() ^^', info);
158 tts.selectIntent(info);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100159 },
Simon Huntcaed0412017-08-12 13:49:17 -0700160 // localization bundle injection hook
161 injectLion: function (bundle) {
162 topoLion = bundle;
163 tts.setLionBundle(bundle);
164 },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100165 },
Simon Hunt72e44bf2015-07-21 21:34:20 -0700166 };
167
Simon Hunt72e44bf2015-07-21 21:34:20 -0700168 // invoke code to register with the overlay service
169 angular.module('ovTopo')
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700170 .run(['$log', 'TopoOverlayService', 'TopoTrafficService',
Simon Hunt72e44bf2015-07-21 21:34:20 -0700171
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700172 function (_$log_, _tov_, _tts_) {
Simon Hunt72e44bf2015-07-21 21:34:20 -0700173 $log = _$log_;
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700174 tov = _tov_;
175 tts = _tts_;
Simon Hunt72e44bf2015-07-21 21:34:20 -0700176 tov.register(overlay);
177 }]);
178
179}());