blob: 5e4d43a0adb46b7c9431a48a61dd3d318886baa9 [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',
Andrea Campanella1c24fb92018-12-20 16:43:59 +010055 ols: 'opt',
56 terminal_device: 'opt',
57 roadm_otn: 'opt',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070058 },
59 link: {
60 hostLink: 'pkt',
61 direct: 'pkt',
62 indirect: '',
63 tunnel: '',
Steven Burrows1c2a9682017-07-14 16:52:46 +010064 optical: 'opt',
65 },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070066 },
67 // order of layer cycling in button
68 dispatch = [
69 {
70 type: 'all',
71 action: function () { suppressLayers(false); },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070072 },
73 {
74 type: 'pkt',
75 action: function () { showLayer('pkt'); },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070076 },
77 {
78 type: 'opt',
79 action: function () { showLayer('opt'); },
Steven Burrows1c2a9682017-07-14 16:52:46 +010080 },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070081 ],
Simon Hunte2d9dc72017-08-10 15:21:04 -070082 layer = 0,
83 layerType,
84 lionKey;
Simon Hunteb0fa052015-02-17 19:20:28 -080085
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070086 function clickAction() {
87 layer = (layer + 1) % dispatch.length;
88 dispatch[layer].action();
Simon Hunte2d9dc72017-08-10 15:21:04 -070089 layerType = dispatch[layer].type;
90 lionKey = 'fl_layer_' + layerType;
91 flash.flash(topoLion(lionKey));
Simon Hunteb0fa052015-02-17 19:20:28 -080092 }
93
94 function selected() {
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070095 return dispatch[layer].type;
Simon Hunteb0fa052015-02-17 19:20:28 -080096 }
97
Simon Hunteb0fa052015-02-17 19:20:28 -080098 function inLayer(d, layer) {
99 var type = d.class === 'link' ? d.type() : d.type,
100 look = layerLookup[d.class],
101 lyr = look && look[type];
102 return lyr === layer;
103 }
104
105 function unsuppressLayer(which) {
106 api.node().each(function (d) {
107 var node = d.el;
108 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -0700109 node.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800110 }
111 });
112
113 api.link().each(function (d) {
114 var link = d.el;
115 if (inLayer(d, which)) {
Simon Hunt743a8492015-08-25 16:18:19 -0700116 link.classed(smax, false);
Simon Hunteb0fa052015-02-17 19:20:28 -0800117 }
118 });
119 }
120
121 function suppressLayers(b) {
Simon Hunt743a8492015-08-25 16:18:19 -0700122 api.node().classed(smax, b);
123 api.link().classed(smax, b);
Simon Hunteb0fa052015-02-17 19:20:28 -0800124 }
125
126 function showLayer(which) {
127 suppressLayers(true);
128 unsuppressLayer(which);
129 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800130
Simon Hunte2d9dc72017-08-10 15:21:04 -0700131 // invoked after the localization bundle has been received from the server
132 function setLionBundle(bundle) {
133 topoLion = bundle;
134 }
135
Simon Hunt99ee1e22015-02-13 09:24:43 -0800136 // === -----------------------------------------------------
137 // === MODULE DEFINITION ===
138
139 angular.module('ovTopo')
Steven Burrows1c2a9682017-07-14 16:52:46 +0100140 .factory('TopoFilterService', ['FlashService',
141 function (_flash_) {
Simon Hunt99ee1e22015-02-13 09:24:43 -0800142 flash = _flash_;
Simon Hunt99ee1e22015-02-13 09:24:43 -0800143
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700144 function initFilter(_api_) {
Simon Hunt99ee1e22015-02-13 09:24:43 -0800145 api = _api_;
Simon Hunteb0fa052015-02-17 19:20:28 -0800146 }
Simon Hunt99ee1e22015-02-13 09:24:43 -0800147
148 return {
149 initFilter: initFilter,
Simon Hunteb0fa052015-02-17 19:20:28 -0800150
151 clickAction: clickAction,
Simon Huntc3c5b672015-02-20 11:32:13 -0800152 selected: selected,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100153 inLayer: inLayer,
Simon Hunte2d9dc72017-08-10 15:21:04 -0700154 setLionBundle: setLionBundle,
Simon Hunt99ee1e22015-02-13 09:24:43 -0800155 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100156 },
157 ]);
Simon Hunt99ee1e22015-02-13 09:24:43 -0800158}());