Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 | |
| 29 | // NOTE: no internal state here -- see TopoTrafficService for that |
| 30 | |
| 31 | // NOTE: providing button disabling requires too big a refactoring of |
| 32 | // the button factory etc. Will have to be done another time. |
| 33 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 34 | |
| 35 | // traffic overlay definition |
| 36 | var overlay = { |
| 37 | overlayId: 'traffic', |
Simon Hunt | c217cb9 | 2016-08-30 16:17:51 -0700 | [diff] [blame] | 38 | glyphId: 'm_allTraffic', |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 39 | tooltip: 'Traffic Overlay', |
| 40 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 41 | // NOTE: Traffic glyphs already installed as part of the base ONOS set. |
| 42 | |
| 43 | activate: function () { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 44 | $log.debug("Traffic overlay ACTIVATED"); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 45 | }, |
| 46 | |
| 47 | deactivate: function () { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 48 | tts.cancelTraffic(true); |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 49 | $log.debug("Traffic overlay DEACTIVATED"); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 50 | }, |
| 51 | |
| 52 | // detail panel button definitions |
| 53 | // (keys match button identifiers, also defined in TrafficOverlay.java) |
| 54 | buttons: { |
| 55 | showDeviceFlows: { |
Simon Hunt | c217cb9 | 2016-08-30 16:17:51 -0700 | [diff] [blame] | 56 | gid: 'm_flows', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 57 | tt: 'Show Device Flows', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 58 | cb: function (data) { tts.showDeviceLinkFlows(); } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 59 | }, |
| 60 | |
| 61 | showRelatedTraffic: { |
Simon Hunt | c217cb9 | 2016-08-30 16:17:51 -0700 | [diff] [blame] | 62 | gid: 'm_relatedIntents', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 63 | tt: 'Show Related Traffic', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 64 | cb: function (data) { tts.showRelatedIntents(); } |
| 65 | } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 66 | }, |
| 67 | |
| 68 | // key bindings for traffic overlay toolbar buttons |
| 69 | // NOTE: fully qual. button ID is derived from overlay-id and key-name |
| 70 | keyBindings: { |
| 71 | 0: { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 72 | cb: function () { tts.cancelTraffic(true); }, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 73 | tt: 'Cancel traffic monitoring', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 74 | gid: 'm_xMark' |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 75 | }, |
| 76 | |
| 77 | A: { |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 78 | cb: function () { tts.showAllTraffic(); }, |
| 79 | tt: 'Monitor all traffic', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 80 | gid: 'm_allTraffic' |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 81 | }, |
| 82 | F: { |
| 83 | cb: function () { tts.showDeviceLinkFlows(); }, |
| 84 | tt: 'Show device link flows', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 85 | gid: 'm_flows' |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 86 | }, |
| 87 | V: { |
| 88 | cb: function () { tts.showRelatedIntents(); }, |
| 89 | tt: 'Show all related intents', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 90 | gid: 'm_relatedIntents' |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 91 | }, |
| 92 | leftArrow: { |
| 93 | cb: function () { tts.showPrevIntent(); }, |
| 94 | tt: 'Show previous related intent', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 95 | gid: 'm_prev' |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 96 | }, |
| 97 | rightArrow: { |
| 98 | cb: function () { tts.showNextIntent(); }, |
| 99 | tt: 'Show next related intent', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 100 | gid: 'm_next' |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 101 | }, |
| 102 | W: { |
| 103 | cb: function () { tts.showSelectedIntentTraffic(); }, |
| 104 | tt: 'Monitor traffic of selected intent', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 105 | gid: 'm_intentTraffic' |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 106 | }, |
| 107 | |
| 108 | _keyOrder: [ |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 109 | '0', 'A', 'F', 'V', 'leftArrow', 'rightArrow', 'W' |
| 110 | ] |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 111 | }, |
| 112 | |
| 113 | hooks: { |
| 114 | // hook for handling escape key |
| 115 | escape: function () { |
| 116 | // Must return true to consume ESC, false otherwise. |
Simon Hunt | 5783017 | 2015-08-26 13:25:17 -0700 | [diff] [blame] | 117 | return tts.cancelTraffic(true); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 118 | }, |
| 119 | |
| 120 | // hooks for when the selection changes... |
| 121 | empty: function () { |
| 122 | tts.cancelTraffic(); |
| 123 | }, |
| 124 | single: function (data) { |
| 125 | tts.requestTrafficForMode(); |
| 126 | }, |
| 127 | multi: function (selectOrder) { |
| 128 | tts.requestTrafficForMode(); |
| 129 | tov.addDetailButton('showRelatedTraffic'); |
Simon Hunt | 584e92d | 2015-08-24 11:27:22 -0700 | [diff] [blame] | 130 | }, |
| 131 | |
| 132 | // mouse hooks |
| 133 | mouseover: function (m) { |
| 134 | // m has id, class, and type properties |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 135 | tts.requestTrafficForMode(true); |
Simon Hunt | 584e92d | 2015-08-24 11:27:22 -0700 | [diff] [blame] | 136 | }, |
| 137 | mouseout: function () { |
Simon Hunt | d2862c3 | 2015-08-24 17:41:51 -0700 | [diff] [blame] | 138 | tts.requestTrafficForMode(true); |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 139 | }, |
| 140 | |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 141 | // intent visualization hooks |
| 142 | acceptIntent: function (type) { |
| 143 | // accept any intent type except "Protected" intents |
| 144 | return (!type.startsWith('Protected')); |
| 145 | }, |
| 146 | showIntent: function (info) { |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 147 | $log.debug('^^ trafficOverlay.showintent() ^^', info); |
| 148 | tts.selectIntent(info); |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 153 | // invoke code to register with the overlay service |
| 154 | angular.module('ovTopo') |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 155 | .run(['$log', 'TopoOverlayService', 'TopoTrafficService', |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 156 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 157 | function (_$log_, _tov_, _tts_) { |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 158 | $log = _$log_; |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 159 | tov = _tov_; |
| 160 | tts = _tts_; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 161 | tov.register(overlay); |
| 162 | }]); |
| 163 | |
| 164 | }()); |