blob: f9b96ae871eefaf13b3bb6deb6c263545aa13b3b [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',
47 roadm: 'opt'
48 },
49 link: {
50 hostLink: 'pkt',
51 direct: 'pkt',
52 indirect: '',
53 tunnel: '',
54 optical: 'opt'
Simon Hunteb0fa052015-02-17 19:20:28 -080055 }
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070056 },
57 // order of layer cycling in button
58 dispatch = [
59 {
60 type: 'all',
61 action: function () { suppressLayers(false); },
62 msg: 'All Layers Shown'
63 },
64 {
65 type: 'pkt',
66 action: function () { showLayer('pkt'); },
67 msg: 'Packet Layer Shown'
68 },
69 {
70 type: 'opt',
71 action: function () { showLayer('opt'); },
72 msg: 'Optical Layer Shown'
73 }
74 ],
75 layer = 0;
Simon Hunteb0fa052015-02-17 19:20:28 -080076
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070077 function clickAction() {
78 layer = (layer + 1) % dispatch.length;
79 dispatch[layer].action();
80 flash.flash(dispatch[layer].msg);
Simon Hunteb0fa052015-02-17 19:20:28 -080081 }
82
83 function selected() {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070084 return dispatch[layer].type;
Simon Hunteb0fa052015-02-17 19:20:28 -080085 }
86
Simon Hunteb0fa052015-02-17 19:20:28 -080087 function inLayer(d, layer) {
88 var type = d.class === 'link' ? d.type() : d.type,
89 look = layerLookup[d.class],
90 lyr = look && look[type];
91 return lyr === layer;
92 }
93
94 function unsuppressLayer(which) {
95 api.node().each(function (d) {
96 var node = d.el;
97 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -070098 node.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -080099 }
100 });
101
102 api.link().each(function (d) {
103 var link = d.el;
104 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -0700105 link.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800106 }
107 });
108 }
109
110 function suppressLayers(b) {
Simon Hunt743a8492015-08-25 16:18:19 -0700111 api.node().classed(smax, b);
112 api.link().classed(smax, b);
Simon Hunteb0fa052015-02-17 19:20:28 -0800113 }
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}());