blob: bda2d7e866f627afc2bbf4978ba383e8cd35c8b0 [file] [log] [blame]
Simon Hunt99ee1e22015-02-13 09:24:43 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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
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',
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020047 roadm: 'opt',
48 otn: 'opt'
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070049 },
50 link: {
51 hostLink: 'pkt',
52 direct: 'pkt',
53 indirect: '',
54 tunnel: '',
55 optical: 'opt'
Simon Hunteb0fa052015-02-17 19:20:28 -080056 }
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070057 },
58 // order of layer cycling in button
59 dispatch = [
60 {
61 type: 'all',
62 action: function () { suppressLayers(false); },
63 msg: 'All Layers Shown'
64 },
65 {
66 type: 'pkt',
67 action: function () { showLayer('pkt'); },
68 msg: 'Packet Layer Shown'
69 },
70 {
71 type: 'opt',
72 action: function () { showLayer('opt'); },
73 msg: 'Optical Layer Shown'
74 }
75 ],
76 layer = 0;
Simon Hunteb0fa052015-02-17 19:20:28 -080077
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070078 function clickAction() {
79 layer = (layer + 1) % dispatch.length;
80 dispatch[layer].action();
81 flash.flash(dispatch[layer].msg);
Simon Hunteb0fa052015-02-17 19:20:28 -080082 }
83
84 function selected() {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070085 return dispatch[layer].type;
Simon Hunteb0fa052015-02-17 19:20:28 -080086 }
87
Simon Hunteb0fa052015-02-17 19:20:28 -080088 function inLayer(d, layer) {
89 var type = d.class === 'link' ? d.type() : d.type,
90 look = layerLookup[d.class],
91 lyr = look && look[type];
92 return lyr === layer;
93 }
94
95 function unsuppressLayer(which) {
96 api.node().each(function (d) {
97 var node = d.el;
98 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -070099 node.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800100 }
101 });
102
103 api.link().each(function (d) {
104 var link = d.el;
105 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -0700106 link.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800107 }
108 });
109 }
110
111 function suppressLayers(b) {
Simon Hunt743a8492015-08-25 16:18:19 -0700112 api.node().classed(smax, b);
113 api.link().classed(smax, b);
Simon Hunteb0fa052015-02-17 19:20:28 -0800114 }
115
116 function showLayer(which) {
117 suppressLayers(true);
118 unsuppressLayer(which);
119 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800120
121 // === -----------------------------------------------------
122 // === MODULE DEFINITION ===
123
124 angular.module('ovTopo')
125 .factory('TopoFilterService',
126 ['$log', 'FnService',
127 'FlashService',
128 'TopoPanelService',
129 'TopoTrafficService',
130
131 function (_$log_, _fs_, _flash_, _tps_, _tts_) {
132 $log = _$log_;
133 fs = _fs_;
134 flash = _flash_;
135 tps = _tps_;
136 tts = _tts_;
137
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700138 function initFilter(_api_) {
Simon Hunt99ee1e22015-02-13 09:24:43 -0800139 api = _api_;
Simon Hunteb0fa052015-02-17 19:20:28 -0800140 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800141
142 return {
143 initFilter: initFilter,
Simon Hunteb0fa052015-02-17 19:20:28 -0800144
145 clickAction: clickAction,
Simon Huntc3c5b672015-02-20 11:32:13 -0800146 selected: selected,
147 inLayer: inLayer
Simon Hunt99ee1e22015-02-13 09:24:43 -0800148 };
149 }]);
150}());