blob: b877fce10140567fce1a320fa7949416b05397e9 [file] [log] [blame]
Simon Hunt99ee1e22015-02-13 09:24:43 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt99ee1e22015-02-13 09:24:43 -08003 *
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
27 var $log, fs, flash, tps, tts;
28
29 // api to topoForce
30 var api;
31 /*
Simon Hunteb0fa052015-02-17 19:20:28 -080032 node() // get ref to D3 selection of nodes
33 link() // get ref to D3 selection of links
Simon Hunt99ee1e22015-02-13 09:24:43 -080034 */
35
Simon Hunt743a8492015-08-25 16:18:19 -070036 var smax = 'suppressedmax';
37
Simon Hunteb0fa052015-02-17 19:20:28 -080038 // which "layer" a particular item "belongs to"
39 var layerLookup = {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070040 host: {
41 endstation: 'pkt', // default, if host event does not define type
42 router: 'pkt',
43 bgpSpeaker: 'pkt'
44 },
45 device: {
46 switch: 'pkt',
Michele Santuari54f420d2016-08-18 09:02:18 +020047 router: 'pkt',
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020048 roadm: 'opt',
49 otn: 'opt'
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070050 },
51 link: {
52 hostLink: 'pkt',
53 direct: 'pkt',
54 indirect: '',
55 tunnel: '',
56 optical: 'opt'
Simon Hunteb0fa052015-02-17 19:20:28 -080057 }
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070058 },
59 // order of layer cycling in button
60 dispatch = [
61 {
62 type: 'all',
63 action: function () { suppressLayers(false); },
64 msg: 'All Layers Shown'
65 },
66 {
67 type: 'pkt',
68 action: function () { showLayer('pkt'); },
69 msg: 'Packet Layer Shown'
70 },
71 {
72 type: 'opt',
73 action: function () { showLayer('opt'); },
74 msg: 'Optical Layer Shown'
75 }
76 ],
77 layer = 0;
Simon Hunteb0fa052015-02-17 19:20:28 -080078
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070079 function clickAction() {
80 layer = (layer + 1) % dispatch.length;
81 dispatch[layer].action();
82 flash.flash(dispatch[layer].msg);
Simon Hunteb0fa052015-02-17 19:20:28 -080083 }
84
85 function selected() {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070086 return dispatch[layer].type;
Simon Hunteb0fa052015-02-17 19:20:28 -080087 }
88
Simon Hunteb0fa052015-02-17 19:20:28 -080089 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 Hunt743a8492015-08-25 16:18:19 -0700100 node.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800101 }
102 });
103
104 api.link().each(function (d) {
105 var link = d.el;
106 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -0700107 link.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800108 }
109 });
110 }
111
112 function suppressLayers(b) {
Simon Hunt743a8492015-08-25 16:18:19 -0700113 api.node().classed(smax, b);
114 api.link().classed(smax, b);
Simon Hunteb0fa052015-02-17 19:20:28 -0800115 }
116
117 function showLayer(which) {
118 suppressLayers(true);
119 unsuppressLayer(which);
120 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800121
122 // === -----------------------------------------------------
123 // === MODULE DEFINITION ===
124
125 angular.module('ovTopo')
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_;
135 flash = _flash_;
136 tps = _tps_;
137 tts = _tts_;
138
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700139 function initFilter(_api_) {
Simon Hunt99ee1e22015-02-13 09:24:43 -0800140 api = _api_;
Simon Hunteb0fa052015-02-17 19:20:28 -0800141 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800142
143 return {
144 initFilter: initFilter,
Simon Hunteb0fa052015-02-17 19:20:28 -0800145
146 clickAction: clickAction,
Simon Huntc3c5b672015-02-20 11:32:13 -0800147 selected: selected,
148 inLayer: inLayer
Simon Hunt99ee1e22015-02-13 09:24:43 -0800149 };
150 }]);
151}());