Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 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 | /* |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 19 | ONOS GUI -- Topology Traffic Overlay Module. |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 20 | Defines behavior for viewing different traffic modes. |
| 21 | Installed as a Topology Overlay. |
| 22 | */ |
| 23 | (function () { |
| 24 | 'use strict'; |
| 25 | |
| 26 | // injected refs |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 27 | var $log, tov, tts; |
| 28 | |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 29 | // function to be replaced by the localization bundle function |
| 30 | var topoLion = function (x) { |
| 31 | return '#ttrafov#' + x + '#'; |
| 32 | }; |
| 33 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 34 | // 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 Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 39 | |
| 40 | // traffic overlay definition |
| 41 | var overlay = { |
| 42 | overlayId: 'traffic', |
Simon Hunt | c217cb9 | 2016-08-30 16:17:51 -0700 | [diff] [blame] | 43 | glyphId: 'm_allTraffic', |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 44 | tooltip: function () { return topoLion('ov_tt_traffic'); }, |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 45 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 46 | // NOTE: Traffic glyphs already installed as part of the base ONOS set. |
| 47 | |
| 48 | activate: function () { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 49 | $log.debug('Traffic overlay ACTIVATED'); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 50 | }, |
| 51 | |
| 52 | deactivate: function () { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 53 | tts.cancelTraffic(true); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 54 | $log.debug('Traffic overlay DEACTIVATED'); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 55 | }, |
| 56 | |
| 57 | // detail panel button definitions |
| 58 | // (keys match button identifiers, also defined in TrafficOverlay.java) |
| 59 | buttons: { |
| 60 | showDeviceFlows: { |
Simon Hunt | c217cb9 | 2016-08-30 16:17:51 -0700 | [diff] [blame] | 61 | gid: 'm_flows', |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 62 | tt: function () { return topoLion('tr_btn_show_device_flows'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 63 | cb: function (data) { tts.showDeviceLinkFlows(); }, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 64 | }, |
| 65 | |
| 66 | showRelatedTraffic: { |
Simon Hunt | c217cb9 | 2016-08-30 16:17:51 -0700 | [diff] [blame] | 67 | gid: 'm_relatedIntents', |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 68 | tt: function () { return topoLion('tr_btn_show_related_traffic'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 69 | cb: function (data) { tts.showRelatedIntents(); }, |
| 70 | }, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 71 | }, |
| 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 Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 77 | cb: function () { tts.cancelTraffic(true); }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 78 | tt: function () { return topoLion('tr_btn_cancel_monitoring'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 79 | gid: 'm_xMark', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 80 | }, |
| 81 | |
| 82 | A: { |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 83 | cb: function () { tts.showAllTraffic(); }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 84 | tt: function () { return topoLion('tr_btn_monitor_all'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 85 | gid: 'm_allTraffic', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 86 | }, |
| 87 | F: { |
| 88 | cb: function () { tts.showDeviceLinkFlows(); }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 89 | tt: function () { return topoLion('tr_btn_show_dev_link_flows'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 90 | gid: 'm_flows', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 91 | }, |
| 92 | V: { |
| 93 | cb: function () { tts.showRelatedIntents(); }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 94 | tt: function () { return topoLion('tr_btn_show_all_rel_intents'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 95 | gid: 'm_relatedIntents', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 96 | }, |
| 97 | leftArrow: { |
| 98 | cb: function () { tts.showPrevIntent(); }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 99 | tt: function () { return topoLion('tr_btn_show_prev_rel_intent'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 100 | gid: 'm_prev', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 101 | }, |
| 102 | rightArrow: { |
| 103 | cb: function () { tts.showNextIntent(); }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 104 | tt: function () { return topoLion('tr_btn_show_next_rel_intent'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 105 | gid: 'm_next', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 106 | }, |
| 107 | W: { |
| 108 | cb: function () { tts.showSelectedIntentTraffic(); }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 109 | tt: function () { return topoLion('tr_btn_monitor_sel_intent'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 110 | gid: 'm_intentTraffic', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 111 | }, |
| 112 | |
| 113 | _keyOrder: [ |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 114 | '0', 'A', 'F', 'V', 'leftArrow', 'rightArrow', 'W', |
| 115 | ], |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 116 | }, |
| 117 | |
| 118 | hooks: { |
| 119 | // hook for handling escape key |
| 120 | escape: function () { |
| 121 | // Must return true to consume ESC, false otherwise. |
Simon Hunt | 5783017 | 2015-08-26 13:25:17 -0700 | [diff] [blame] | 122 | return tts.cancelTraffic(true); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 123 | }, |
| 124 | |
| 125 | // hooks for when the selection changes... |
| 126 | empty: function () { |
| 127 | tts.cancelTraffic(); |
| 128 | }, |
| 129 | single: function (data) { |
| 130 | tts.requestTrafficForMode(); |
| 131 | }, |
| 132 | multi: function (selectOrder) { |
| 133 | tts.requestTrafficForMode(); |
| 134 | tov.addDetailButton('showRelatedTraffic'); |
Simon Hunt | 584e92d | 2015-08-24 11:27:22 -0700 | [diff] [blame] | 135 | }, |
| 136 | |
| 137 | // mouse hooks |
| 138 | mouseover: function (m) { |
| 139 | // m has id, class, and type properties |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 140 | tts.requestTrafficForMode(true); |
Simon Hunt | 584e92d | 2015-08-24 11:27:22 -0700 | [diff] [blame] | 141 | }, |
| 142 | mouseout: function () { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 143 | tts.requestTrafficForMode(true); |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 144 | }, |
| 145 | |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 146 | // intent visualization hooks |
| 147 | acceptIntent: function (type) { |
| 148 | // accept any intent type except "Protected" intents |
| 149 | return (!type.startsWith('Protected')); |
| 150 | }, |
| 151 | showIntent: function (info) { |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 152 | $log.debug('^^ trafficOverlay.showintent() ^^', info); |
| 153 | tts.selectIntent(info); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 154 | }, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 155 | // localization bundle injection hook |
| 156 | injectLion: function (bundle) { |
| 157 | topoLion = bundle; |
| 158 | tts.setLionBundle(bundle); |
| 159 | }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 160 | }, |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 163 | // invoke code to register with the overlay service |
| 164 | angular.module('ovTopo') |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 165 | .run(['$log', 'TopoOverlayService', 'TopoTrafficService', |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 166 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 167 | function (_$log_, _tov_, _tts_) { |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 168 | $log = _$log_; |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 169 | tov = _tov_; |
| 170 | tts = _tts_; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 171 | tov.register(overlay); |
| 172 | }]); |
| 173 | |
| 174 | }()); |