blob: b5a5283840e1e5ad89a37b167e1cb4d020bb1b8c [file] [log] [blame]
Simon Hunt99ee1e22015-02-13 09:24:43 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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
Steven Burrows1c2a9682017-07-14 16:52:46 +010027 var flash;
Simon Hunt99ee1e22015-02-13 09:24:43 -080028
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 Hunte2d9dc72017-08-10 15:21:04 -070036 // function to be replaced by the localization bundle function
37 var topoLion = function (x) {
38 return '#tfltr#' + x + '#';
39 };
40
Simon Hunt743a8492015-08-25 16:18:19 -070041 var smax = 'suppressedmax';
42
Simon Hunteb0fa052015-02-17 19:20:28 -080043 // which "layer" a particular item "belongs to"
44 var layerLookup = {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070045 host: {
46 endstation: 'pkt', // default, if host event does not define type
Steven Burrows1c2a9682017-07-14 16:52:46 +010047 router: 'pkt',
48 bgpSpeaker: 'pkt',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070049 },
50 device: {
51 switch: 'pkt',
Michele Santuari54f420d2016-08-18 09:02:18 +020052 router: 'pkt',
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020053 roadm: 'opt',
Steven Burrows1c2a9682017-07-14 16:52:46 +010054 otn: 'opt',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070055 },
56 link: {
57 hostLink: 'pkt',
58 direct: 'pkt',
59 indirect: '',
60 tunnel: '',
Steven Burrows1c2a9682017-07-14 16:52:46 +010061 optical: 'opt',
62 },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070063 },
64 // order of layer cycling in button
65 dispatch = [
66 {
67 type: 'all',
68 action: function () { suppressLayers(false); },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070069 },
70 {
71 type: 'pkt',
72 action: function () { showLayer('pkt'); },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070073 },
74 {
75 type: 'opt',
76 action: function () { showLayer('opt'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010077 },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070078 ],
Simon Hunte2d9dc72017-08-10 15:21:04 -070079 layer = 0,
80 layerType,
81 lionKey;
Simon Hunteb0fa052015-02-17 19:20:28 -080082
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070083 function clickAction() {
84 layer = (layer + 1) % dispatch.length;
85 dispatch[layer].action();
Simon Hunte2d9dc72017-08-10 15:21:04 -070086 layerType = dispatch[layer].type;
87 lionKey = 'fl_layer_' + layerType;
88 flash.flash(topoLion(lionKey));
Simon Hunteb0fa052015-02-17 19:20:28 -080089 }
90
91 function selected() {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070092 return dispatch[layer].type;
Simon Hunteb0fa052015-02-17 19:20:28 -080093 }
94
Simon Hunteb0fa052015-02-17 19:20:28 -080095 function inLayer(d, layer) {
96 var type = d.class === 'link' ? d.type() : d.type,
97 look = layerLookup[d.class],
98 lyr = look && look[type];
99 return lyr === layer;
100 }
101
102 function unsuppressLayer(which) {
103 api.node().each(function (d) {
104 var node = d.el;
105 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -0700106 node.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800107 }
108 });
109
110 api.link().each(function (d) {
111 var link = d.el;
112 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -0700113 link.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800114 }
115 });
116 }
117
118 function suppressLayers(b) {
Simon Hunt743a8492015-08-25 16:18:19 -0700119 api.node().classed(smax, b);
120 api.link().classed(smax, b);
Simon Hunteb0fa052015-02-17 19:20:28 -0800121 }
122
123 function showLayer(which) {
124 suppressLayers(true);
125 unsuppressLayer(which);
126 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800127
Simon Hunte2d9dc72017-08-10 15:21:04 -0700128 // invoked after the localization bundle has been received from the server
129 function setLionBundle(bundle) {
130 topoLion = bundle;
131 }
132
Simon Hunt99ee1e22015-02-13 09:24:43 -0800133 // === -----------------------------------------------------
134 // === MODULE DEFINITION ===
135
136 angular.module('ovTopo')
Steven Burrows1c2a9682017-07-14 16:52:46 +0100137 .factory('TopoFilterService', ['FlashService',
138 function (_flash_) {
Simon Hunt99ee1e22015-02-13 09:24:43 -0800139 flash = _flash_;
Simon Hunt99ee1e22015-02-13 09:24:43 -0800140
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700141 function initFilter(_api_) {
Simon Hunt99ee1e22015-02-13 09:24:43 -0800142 api = _api_;
Simon Hunteb0fa052015-02-17 19:20:28 -0800143 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800144
145 return {
146 initFilter: initFilter,
Simon Hunteb0fa052015-02-17 19:20:28 -0800147
148 clickAction: clickAction,
Simon Huntc3c5b672015-02-20 11:32:13 -0800149 selected: selected,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100150 inLayer: inLayer,
Simon Hunte2d9dc72017-08-10 15:21:04 -0700151 setLionBundle: setLionBundle,
Simon Hunt99ee1e22015-02-13 09:24:43 -0800152 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100153 },
154 ]);
Simon Hunt99ee1e22015-02-13 09:24:43 -0800155}());