Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [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 | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [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 | ONOS GUI -- Topology layer filtering Module. |
| 19 | Provides functionality to visually differentiate between the packet and |
| 20 | optical layers of the topology. |
| 21 | */ |
| 22 | |
| 23 | (function () { |
| 24 | 'use strict'; |
| 25 | |
| 26 | // injected refs |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 27 | var $log, fs, flash, tps, tts; |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 28 | |
| 29 | // api to topoForce |
| 30 | var api; |
| 31 | /* |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 32 | node() // get ref to D3 selection of nodes |
| 33 | link() // get ref to D3 selection of links |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 34 | */ |
| 35 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 36 | var smax = 'suppressedmax'; |
| 37 | |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 38 | // which "layer" a particular item "belongs to" |
| 39 | var layerLookup = { |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 40 | host: { |
| 41 | endstation: 'pkt', // default, if host event does not define type |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 42 | router: 'pkt', |
| 43 | bgpSpeaker: 'pkt' |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 44 | }, |
| 45 | device: { |
| 46 | switch: 'pkt', |
Michele Santuari | 54f420d | 2016-08-18 09:02:18 +0200 | [diff] [blame] | 47 | router: 'pkt', |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 48 | roadm: 'opt', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 49 | otn: 'opt' |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 50 | }, |
| 51 | link: { |
| 52 | hostLink: 'pkt', |
| 53 | direct: 'pkt', |
| 54 | indirect: '', |
| 55 | tunnel: '', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 56 | optical: 'opt' |
| 57 | } |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 58 | }, |
| 59 | // order of layer cycling in button |
| 60 | dispatch = [ |
| 61 | { |
| 62 | type: 'all', |
| 63 | action: function () { suppressLayers(false); }, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 64 | msg: 'All Layers Shown' |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 65 | }, |
| 66 | { |
| 67 | type: 'pkt', |
| 68 | action: function () { showLayer('pkt'); }, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 69 | msg: 'Packet Layer Shown' |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 70 | }, |
| 71 | { |
| 72 | type: 'opt', |
| 73 | action: function () { showLayer('opt'); }, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 74 | msg: 'Optical Layer Shown' |
| 75 | } |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 76 | ], |
| 77 | layer = 0; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 78 | |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 79 | function clickAction() { |
| 80 | layer = (layer + 1) % dispatch.length; |
| 81 | dispatch[layer].action(); |
| 82 | flash.flash(dispatch[layer].msg); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | function selected() { |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 86 | return dispatch[layer].type; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 89 | function inLayer(d, layer) { |
| 90 | var type = d.class === 'link' ? d.type() : d.type, |
| 91 | look = layerLookup[d.class], |
| 92 | lyr = look && look[type]; |
| 93 | return lyr === layer; |
| 94 | } |
| 95 | |
| 96 | function unsuppressLayer(which) { |
| 97 | api.node().each(function (d) { |
| 98 | var node = d.el; |
| 99 | if (inLayer(d, which)) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 100 | node.classed(smax, false); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 101 | } |
| 102 | }); |
| 103 | |
| 104 | api.link().each(function (d) { |
| 105 | var link = d.el; |
| 106 | if (inLayer(d, which)) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 107 | link.classed(smax, false); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 108 | } |
| 109 | }); |
| 110 | } |
| 111 | |
| 112 | function suppressLayers(b) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 113 | api.node().classed(smax, b); |
| 114 | api.link().classed(smax, b); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | function showLayer(which) { |
| 118 | suppressLayers(true); |
| 119 | unsuppressLayer(which); |
| 120 | } |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 121 | |
| 122 | // === ----------------------------------------------------- |
| 123 | // === MODULE DEFINITION === |
| 124 | |
| 125 | angular.module('ovTopo') |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 126 | .factory('TopoFilterService', |
| 127 | ['$log', 'FnService', |
| 128 | 'FlashService', |
| 129 | 'TopoPanelService', |
| 130 | 'TopoTrafficService', |
| 131 | |
| 132 | function (_$log_, _fs_, _flash_, _tps_, _tts_) { |
| 133 | $log = _$log_; |
| 134 | fs = _fs_; |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 135 | flash = _flash_; |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 136 | tps = _tps_; |
| 137 | tts = _tts_; |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 138 | |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 139 | function initFilter(_api_) { |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 140 | api = _api_; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 141 | } |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 142 | |
| 143 | return { |
| 144 | initFilter: initFilter, |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 145 | |
| 146 | clickAction: clickAction, |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 147 | selected: selected, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 148 | inLayer: inLayer |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 149 | }; |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 150 | }]); |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 151 | }()); |