blob: 1226664af1df278de6bb4788f9b1898b41be55c7 [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 Hunteb0fa052015-02-17 19:20:28 -080036 // which "layer" a particular item "belongs to"
37 var layerLookup = {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070038 host: {
39 endstation: 'pkt', // default, if host event does not define type
40 router: 'pkt',
41 bgpSpeaker: 'pkt'
42 },
43 device: {
44 switch: 'pkt',
45 roadm: 'opt'
46 },
47 link: {
48 hostLink: 'pkt',
49 direct: 'pkt',
50 indirect: '',
51 tunnel: '',
52 optical: 'opt'
Simon Hunteb0fa052015-02-17 19:20:28 -080053 }
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070054 },
55 // order of layer cycling in button
56 dispatch = [
57 {
58 type: 'all',
59 action: function () { suppressLayers(false); },
60 msg: 'All Layers Shown'
61 },
62 {
63 type: 'pkt',
64 action: function () { showLayer('pkt'); },
65 msg: 'Packet Layer Shown'
66 },
67 {
68 type: 'opt',
69 action: function () { showLayer('opt'); },
70 msg: 'Optical Layer Shown'
71 }
72 ],
73 layer = 0;
Simon Hunteb0fa052015-02-17 19:20:28 -080074
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070075 function clickAction() {
76 layer = (layer + 1) % dispatch.length;
77 dispatch[layer].action();
78 flash.flash(dispatch[layer].msg);
Simon Hunteb0fa052015-02-17 19:20:28 -080079 }
80
81 function selected() {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070082 return dispatch[layer].type;
Simon Hunteb0fa052015-02-17 19:20:28 -080083 }
84
Simon Hunteb0fa052015-02-17 19:20:28 -080085 function inLayer(d, layer) {
86 var type = d.class === 'link' ? d.type() : d.type,
87 look = layerLookup[d.class],
88 lyr = look && look[type];
89 return lyr === layer;
90 }
91
92 function unsuppressLayer(which) {
93 api.node().each(function (d) {
94 var node = d.el;
95 if (inLayer(d, which)) {
96 node.classed('suppressed', false);
97 }
98 });
99
100 api.link().each(function (d) {
101 var link = d.el;
102 if (inLayer(d, which)) {
103 link.classed('suppressed', false);
104 }
105 });
106 }
107
108 function suppressLayers(b) {
109 api.node().classed('suppressed', b);
110 api.link().classed('suppressed', b);
111// d3.selectAll('svg .port').classed('inactive', false);
112// d3.selectAll('svg .portText').classed('inactive', false);
113 }
114
115 function showLayer(which) {
116 suppressLayers(true);
117 unsuppressLayer(which);
118 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800119
120 // === -----------------------------------------------------
121 // === MODULE DEFINITION ===
122
123 angular.module('ovTopo')
124 .factory('TopoFilterService',
125 ['$log', 'FnService',
126 'FlashService',
127 'TopoPanelService',
128 'TopoTrafficService',
129
130 function (_$log_, _fs_, _flash_, _tps_, _tts_) {
131 $log = _$log_;
132 fs = _fs_;
133 flash = _flash_;
134 tps = _tps_;
135 tts = _tts_;
136
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700137 function initFilter(_api_) {
Simon Hunt99ee1e22015-02-13 09:24:43 -0800138 api = _api_;
Simon Hunteb0fa052015-02-17 19:20:28 -0800139 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800140
141 return {
142 initFilter: initFilter,
Simon Hunteb0fa052015-02-17 19:20:28 -0800143
144 clickAction: clickAction,
Simon Huntc3c5b672015-02-20 11:32:13 -0800145 selected: selected,
146 inLayer: inLayer
Simon Hunt99ee1e22015-02-13 09:24:43 -0800147 };
148 }]);
149}());