blob: 21ad66e32ee2d97a7dce2eb1cc583e4beb134cc8 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
Sean Condon91481822019-01-01 13:56:14 +00002 * Copyright 2019-present Open Networking Foundation
Sean Condonf4f54a12018-10-10 23:25:46 +01003 *
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 */
Sean Condond88f3662019-04-03 16:35:30 +010016import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
Sean Condon91481822019-01-01 13:56:14 +000017import {animate, state, style, transition, trigger} from '@angular/animations';
Sean Condond88f3662019-04-03 16:35:30 +010018import {DetailsPanelBaseImpl, FnService, LionService, LogService, WebSocketService} from 'gui2-fw-lib';
19import {Host, Link, LinkType, NodeType, UiElement} from '../../layer/forcesvg/models';
Sean Condon91481822019-01-01 13:56:14 +000020import {Params, Router} from '@angular/router';
Sean Condonf4f54a12018-10-10 23:25:46 +010021
Sean Condon91481822019-01-01 13:56:14 +000022
23interface ButtonAttrs {
24 gid: string;
25 tt: string;
26 path: string;
27}
28
29const SHOWDEVICEVIEW: ButtonAttrs = {
30 gid: 'deviceTable',
31 tt: 'tt_ctl_show_device',
32 path: 'device',
33};
34const SHOWFLOWVIEW: ButtonAttrs = {
35 gid: 'flowTable',
36 tt: 'title_flows',
37 path: 'flow',
38};
39const SHOWPORTVIEW: ButtonAttrs = {
40 gid: 'portTable',
41 tt: 'tt_ctl_show_port',
42 path: 'port',
43};
44const SHOWGROUPVIEW: ButtonAttrs = {
45 gid: 'groupTable',
46 tt: 'tt_ctl_show_group',
47 path: 'group',
48};
49const SHOWMETERVIEW: ButtonAttrs = {
50 gid: 'meterTable',
51 tt: 'tt_ctl_show_meter',
52 path: 'meter',
53};
54const SHOWPIPECONFVIEW: ButtonAttrs = {
55 gid: 'pipeconfTable',
56 tt: 'tt_ctl_show_pipeconf',
57 path: 'pipeconf',
58};
Sean Condond88f3662019-04-03 16:35:30 +010059const RELATEDINTENTS: ButtonAttrs = {
60 gid: 'm_relatedIntents',
61 tt: 'tr_btn_show_related_traffic',
62 path: 'relatedIntents',
63};
64const CREATEHOSTTOHOSTFLOW: ButtonAttrs = {
65 gid: 'm_endstation',
66 tt: 'tr_btn_create_h2h_flow',
67 path: 'create_h2h_flow',
68};
69const CREATEMULTISOURCEFLOW: ButtonAttrs = {
70 gid: 'm_flows',
71 tt: 'tr_btn_create_msrc_flow',
72 path: 'create_msrc_flow',
73};
74
Sean Condon91481822019-01-01 13:56:14 +000075
76interface ShowDetails {
77 buttons: string[];
78 glyphId: string;
79 id: string;
80 navPath: string;
81 propLabels: Object;
82 propOrder: string[];
83 propValues: Object;
84 title: string;
85}
86/**
87 * ONOS GUI -- Topology Details Panel.
88 * Displays details of selected device. When no device is selected the panel slides
89 * off to the side and disappears
Sean Condond88f3662019-04-03 16:35:30 +010090 *
91 * This Panel is a child of the Topology component and it gets the 'selectedNodes'
92 * from there as an input component. See TopologyComponent.nodeSelected()
93 * The topology component gets these by listening to events from ForceSvgComponent
94 * which gets them in turn from Device, Host, SubRegion and Link components. This
95 * is so that each component respects the hierarchy
Sean Condonf4f54a12018-10-10 23:25:46 +010096 */
97@Component({
98 selector: 'onos-details',
99 templateUrl: './details.component.html',
100 styleUrls: [
101 './details.component.css', './details.theme.css',
102 '../../topology.common.css',
103 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css'
104 ],
105 animations: [
106 trigger('detailsPanelState', [
107 state('true', style({
108 transform: 'translateX(0%)',
Sean Condon91481822019-01-01 13:56:14 +0000109 opacity: '1.0'
Sean Condonf4f54a12018-10-10 23:25:46 +0100110 })),
111 state('false', style({
112 transform: 'translateX(100%)',
113 opacity: '0'
114 })),
115 transition('0 => 1', animate('100ms ease-in')),
116 transition('1 => 0', animate('100ms ease-out'))
117 ])
118 ]
119})
Sean Condon91481822019-01-01 13:56:14 +0000120export class DetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges {
Sean Condond88f3662019-04-03 16:35:30 +0100121 @Input() selectedNodes: UiElement[] = []; // Populated when user selects node or link
Sean Condonb2c483c2019-01-16 20:28:55 +0000122 @Input() on: boolean = false; // Override the parent class attribute
Sean Condon91481822019-01-01 13:56:14 +0000123
124 // deferred localization strings
Sean Condond88f3662019-04-03 16:35:30 +0100125 lionFnTopo; // Function
126 lionFnFlow; // Function for flow bundle
Sean Condon91481822019-01-01 13:56:14 +0000127 showDetails: ShowDetails; // Will be populated on callback. Cleared if nothing is selected
Sean Condonf4f54a12018-10-10 23:25:46 +0100128
129 constructor(
130 protected fs: FnService,
131 protected log: LogService,
Sean Condon91481822019-01-01 13:56:14 +0000132 protected router: Router,
Sean Condonf4f54a12018-10-10 23:25:46 +0100133 protected wss: WebSocketService,
Sean Condon91481822019-01-01 13:56:14 +0000134 private lion: LionService
Sean Condonf4f54a12018-10-10 23:25:46 +0100135 ) {
Sean Condon95fb5742019-04-02 12:16:55 +0100136 super(fs, log, wss, 'topo');
Sean Condon91481822019-01-01 13:56:14 +0000137
138 if (this.lion.ubercache.length === 0) {
Sean Condond88f3662019-04-03 16:35:30 +0100139 this.lionFnTopo = this.dummyLion;
140 this.lionFnFlow = this.dummyLion;
141 this.lion.loadCbs.set('detailscore', () => this.doLion());
Sean Condon91481822019-01-01 13:56:14 +0000142 } else {
143 this.doLion();
144 }
145
146 this.log.debug('Topo DetailsComponent constructed');
Sean Condonf4f54a12018-10-10 23:25:46 +0100147 }
148
Sean Condon91481822019-01-01 13:56:14 +0000149 /**
150 * When the component is initializing set up the handler for callbacks of
151 * ShowDetails from the WSS. Set the variable showDetails when ever a callback
152 * is made
153 */
154 ngOnInit(): void {
Sean Condon91481822019-01-01 13:56:14 +0000155 this.wss.bindHandlers(new Map<string, (data) => void>([
156 ['showDetails', (data) => {
157 this.showDetails = data;
158 // this.log.debug('showDetails received', data);
159 }
160 ]
161 ]));
162 this.log.debug('Topo DetailsComponent initialized');
163 }
164
165 /**
166 * When the component is being unloaded then unbind the WSS handler.
167 */
168 ngOnDestroy(): void {
169 this.wss.unbindHandlers(['showDetails']);
170 this.log.debug('Topo DetailsComponent destroyed');
171 }
172
173 /**
174 * If changes are detected on the Input param selectedNode, call on WSS sendEvent
Sean Condond88f3662019-04-03 16:35:30 +0100175 * and expect ShowDetails to be updated from data sent back from server.
176 *
Sean Condon91481822019-01-01 13:56:14 +0000177 * Note the difference in call to the WSS with requestDetails between a node
178 * and a link - the handling is done in TopologyViewMessageHandler#RequestDetails.process()
179 *
Sean Condond88f3662019-04-03 16:35:30 +0100180 * When multiple items are selected fabricate the ShowDetails here, and
181 * present buttons that allow custom actions
182 *
Sean Condon91481822019-01-01 13:56:14 +0000183 * The WSS will call back asynchronously (see fn in ngOnInit())
184 *
185 * @param changes Simple Changes set of updates
186 */
187 ngOnChanges(changes: SimpleChanges): void {
Sean Condond88f3662019-04-03 16:35:30 +0100188 if (changes['selectedNodes']) {
189 this.selectedNodes = changes['selectedNodes'].currentValue;
Sean Condon91481822019-01-01 13:56:14 +0000190 let type: any;
Sean Condond88f3662019-04-03 16:35:30 +0100191 if (this.selectedNodes.length === 0) {
Sean Condon91481822019-01-01 13:56:14 +0000192 // Selection has been cleared
193 this.showDetails = <ShowDetails>{};
194 return;
Sean Condond88f3662019-04-03 16:35:30 +0100195 } else if (this.selectedNodes.length > 1) {
196 // Don't send message to WSS just form dialog here
197 const propOrder: string[] = [];
198 const propValues: Object = {};
199 const propLabels: Object = {};
200 let numHosts: number = 0;
201 for (let i = 0; i < this.selectedNodes.length; i++) {
202 propOrder.push(i.toString());
203 propLabels[i.toString()] = i.toString();
204 propValues[i.toString()] = this.selectedNodes[i].id;
205 if (this.selectedNodes[i].hasOwnProperty('nodeType') &&
206 (<Host>this.selectedNodes[i]).nodeType === NodeType.HOST) {
207 numHosts++;
208 } else {
209 numHosts = -128; // Negate the whole thing so other buttons will not be shown
210 }
211 }
212 const buttons: string[] = [];
213 if (numHosts === 2) {
214 buttons.push('createHostToHostFlow');
215 } else if (numHosts > 2) {
216 buttons.push('createMultiSourceFlow');
217 }
218 buttons.push('relatedIntents');
219
220 this.showDetails = <ShowDetails>{
221 buttons: buttons,
222 glyphId: undefined,
223 id: 'multiple',
224 navPath: undefined,
225 propLabels: propLabels,
226 propOrder: propOrder,
227 propValues: propValues,
228 title: this.lionFnTopo('title_selected_items')
229 };
230 this.log.debug('Details panel generated from multiple devices', this.showDetails);
231 return;
Sean Condon91481822019-01-01 13:56:14 +0000232 }
233
Sean Condond88f3662019-04-03 16:35:30 +0100234 // If only one thing has been selected then request details of that from the server
235 const selectedNode = this.selectedNodes[0];
236 if (selectedNode.hasOwnProperty('nodeType')) { // For Device, Host, SubRegion
237 type = (<Host>selectedNode).nodeType;
Sean Condon91481822019-01-01 13:56:14 +0000238 this.wss.sendEvent('requestDetails', {
Sean Condond88f3662019-04-03 16:35:30 +0100239 id: selectedNode.id,
Sean Condon91481822019-01-01 13:56:14 +0000240 class: type,
241 });
Sean Condond88f3662019-04-03 16:35:30 +0100242 } else if (selectedNode.hasOwnProperty('type')) { // Must be link
243 const link: Link = <Link>selectedNode;
Sean Condon91481822019-01-01 13:56:14 +0000244 if (<LinkType><unknown>LinkType[link.type] === LinkType.UiEdgeLink) { // Number based enum
245 this.wss.sendEvent('requestDetails', {
246 key: link.id,
247 class: 'link',
248 sourceId: link.epA,
249 targetId: Link.deviceNameFromEp(link.epB),
250 targetPort: link.portB,
251 isEdgeLink: true
252 });
253 } else {
254 this.wss.sendEvent('requestDetails', {
255 key: link.id,
256 class: 'link',
257 sourceId: Link.deviceNameFromEp(link.epA),
258 sourcePort: link.portA,
259 targetId: Link.deviceNameFromEp(link.epB),
260 targetPort: link.portB,
261 isEdgeLink: false
262 });
263 }
264 } else {
Sean Condond88f3662019-04-03 16:35:30 +0100265 this.log.warn('Unexpected type for selected element', selectedNode);
Sean Condon91481822019-01-01 13:56:14 +0000266 }
Sean Condon91481822019-01-01 13:56:14 +0000267 }
268 }
269
270 /**
271 * Table of core button attributes to return per button icon
272 * @param btnName The name of the button
273 * @returns A structure with the button attributes
274 */
275 buttonAttribs(btnName: string): ButtonAttrs {
276 switch (btnName) {
277 case 'showDeviceView':
278 return SHOWDEVICEVIEW;
279 case 'showFlowView':
280 return SHOWFLOWVIEW;
281 case 'showPortView':
282 return SHOWPORTVIEW;
283 case 'showGroupView':
284 return SHOWGROUPVIEW;
285 case 'showMeterView':
286 return SHOWMETERVIEW;
287 case 'showPipeConfView':
288 return SHOWPIPECONFVIEW;
Sean Condond88f3662019-04-03 16:35:30 +0100289 case 'relatedIntents':
290 return RELATEDINTENTS;
291 case 'createHostToHostFlow':
292 return CREATEHOSTTOHOSTFLOW;
293 case 'createMultiSourceFlow':
294 return CREATEMULTISOURCEFLOW;
Sean Condon91481822019-01-01 13:56:14 +0000295 default:
296 return <ButtonAttrs>{
297 gid: btnName,
298 path: btnName
299 };
300 }
301 }
302
303 /**
304 * Navigate using Angular Routing. Combines the parameters to generate a relative URL
305 * e.g. if params are 'meter', 'device' and 'null:0000000000001' then the
306 * navigation URL will become "http://localhost:4200/#/meter?devId=null:0000000000000002"
307 *
Sean Condond88f3662019-04-03 16:35:30 +0100308 * When multiple hosts are selected other actions have to be accommodated
309 *
Sean Condon91481822019-01-01 13:56:14 +0000310 * @param path The path to navigate to
311 * @param navPath The parameter name to use
312 * @param selId the parameter value to use
313 */
Sean Condond88f3662019-04-03 16:35:30 +0100314 navto(path: string): void {
315 this.log.debug('navigate to', path, 'for',
316 this.showDetails.navPath, '=', this.showDetails.id);
317
318 const ids: string[] = [];
319 Object.values(this.showDetails.propValues).forEach((v) => ids.push(v));
320 if (path === 'relatedIntents' && this.showDetails.id === 'multiple') {
321 this.wss.sendEvent('requestRelatedIntents', {
322 'ids': ids,
323 'hover': ''
324 });
325
326 } else if (path === 'create_h2h_flow' && this.showDetails.id === 'multiple') {
327 this.wss.sendEvent('addHostIntent', {
328 'one': ids[0],
329 'two': ids[1],
330 'ids': ids
331 });
332
333 } else if (path === 'create_msrc_flow' && this.showDetails.id === 'multiple') {
334 // Should only happen when there are 3 or more ids
335 this.wss.sendEvent('addMultiSourceIntent', {
336 'src': ids.slice(0, ids.length - 1),
337 'dst': ids[ids.length - 1],
338 'ids': ids
339 });
340
341 } else if (this.showDetails.id) {
342 let navPath = this.showDetails.navPath;
Sean Condon91481822019-01-01 13:56:14 +0000343 if (navPath === 'device') {
344 navPath = 'devId';
345 }
346 const queryPar: Params = {};
Sean Condond88f3662019-04-03 16:35:30 +0100347 queryPar[navPath] = this.showDetails.id;
Sean Condon91481822019-01-01 13:56:14 +0000348 this.router.navigate([path], { queryParams: queryPar });
349 }
350 }
351
352 /**
353 * Read the LION bundle for Details panel and set up the lionFn
354 */
355 doLion() {
Sean Condond88f3662019-04-03 16:35:30 +0100356 this.lionFnTopo = this.lion.bundle('core.view.Topo');
357 this.lionFnFlow = this.lion.bundle('core.view.Flow');
Sean Condonf4f54a12018-10-10 23:25:46 +0100358 }
359
360}