blob: eabd2b7ff92bd26f728568443ccf6417290a6014 [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
2 Copyright 2020 TATA ELXSI
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 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17 */
18/**
19 * @file VNFComposerComponent
20 */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053021 import { isNullOrUndefined } from 'util';
kumaran.m3b4814a2020-05-01 19:48:54 +053022import { HttpHeaders } from '@angular/common/http';
23import { Component, ElementRef, Injector, ViewChild, ViewEncapsulation } from '@angular/core';
24import { ActivatedRoute, Router } from '@angular/router';
25import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
26import { TranslateService } from '@ngx-translate/core';
27import { NotifierService } from 'angular-notifier';
Barath Kumar R063a3f12020-12-29 16:35:09 +053028import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053029import { ConfirmationTopologyComponent } from 'ConfirmationTopology';
30import * as d3 from 'd3';
31import { DataService } from 'DataService';
32import { environment } from 'environment';
33import * as HttpStatus from 'http-status-codes';
34import * as jsyaml from 'js-yaml';
35import { RestService } from 'RestService';
36import { SharedService } from 'SharedService';
Barath Kumar R063a3f12020-12-29 16:35:09 +053037import { COMPOSERNODES, EXTCPD, GRAPHDETAILS, INTCPD, IVLD, Tick, TickPath, VDU, VDUINTCPD, VNFD, VNFDATA, VNIR } from 'VNFDModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053038
39/**
40 * Creating component
41 * @Component takes VNFComposerComponent.html as template url
42 */
43@Component({
44 templateUrl: './VNFComposerComponent.html',
45 styleUrls: ['./VNFComposerComponent.scss'],
46 encapsulation: ViewEncapsulation.None
47})
48/** Exporting a class @exports VNFComposerComponent */
49export class VNFComposerComponent {
50 /** To inject services @public */
51 public injector: Injector;
52 /** View child contains graphContainer ref @public */
53 @ViewChild('graphContainer', { static: true }) public graphContainer: ElementRef;
54 /** dataService to pass the data from one component to another @public */
55 public dataService: DataService;
56 /** random number count @public */
57 public randomNumberLength: number;
58 /** Contains the vnfd information @public */
59 public vnfList: string[] = [];
kumaran.m3b4814a2020-05-01 19:48:54 +053060 /** Contains VNFD Information @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +053061 public vnfdInfo: VNFD = { 'product-name': '', description: '', version: '', id: '', provider: '' };
kumaran.m3b4814a2020-05-01 19:48:54 +053062 /** Contains right panel box information @public */
63 public showRightSideInfo: string = '';
64 /** Add the fixed class for the freeze @public */
65 public fixedClass: string = 'fixed';
66 /** Check the loading results @public */
67 public isLoadingResults: boolean = true;
68 /** Give the message for the loading @public */
69 public message: string = 'PLEASEWAIT';
70 /** Assign the forcesimulation active @public */
71 public forceSimulationActive: boolean = false;
72 /** Assign pinned class for the button when freezed @public */
73 public classApplied: boolean = false;
74 /** Contains sidebar open status @public */
75 public sideBarOpened: boolean = false;
kumaran.m3b4814a2020-05-01 19:48:54 +053076 /** Contains SVG attributes @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053077 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053078 private svg: any;
79 /** Contains forced node animations @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053080 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053081 private force: any;
82 /** Contains the Drag line */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053083 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053084 private dragLine: any;
85 /** Contains id of the node @private */
86 private identifier: string;
87 /** Contains path information of the node */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053088 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053089 private path: any;
90 /** Contains node network @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053091 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053092 private network: any;
93 /** Contains node network @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053094 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053095 private virutualDeploymentUnit: any;
96 /** Contains node connectionPoint @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053097 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053098 private connectionPoint: any;
99 /** Contains node intConnectionPoint @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530100 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +0530101 private intConnectionPoint: any;
102 /** Contains the node information @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530103 private nodes: COMPOSERNODES[] = [];
kumaran.m3b4814a2020-05-01 19:48:54 +0530104 /** Contains the link information of nodes @private */
105 private links: {}[] = [];
106 /** Instance of the rest service @private */
107 private restService: RestService;
108 /** Service holds the router information @private */
109 private router: Router;
110 /** Service contails all the shared service information @private */
111 private sharedService: SharedService;
112 /** Holds teh instance of AuthService class of type AuthService @private */
113 private activatedRoute: ActivatedRoute;
114 /** Notifier service to popup notification @private */
115 private notifierService: NotifierService;
116 /** Controls the header form @private */
117 private headers: HttpHeaders;
118 /** Contains tranlsate instance @private */
119 private translateService: TranslateService;
120 /** Rendered nodes represent network @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530121 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +0530122 private gNetwork: any;
123 /** Rendered nodes represent VDU @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530124 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +0530125 private gVirutualDeploymentUnit: any;
126 /** Rendered nodes represent connection point @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530127 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +0530128 private gConnectionPoint: any;
129 /** Rendered nodes represent internal connection point @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530130 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +0530131 private gIntConnectionPoint: any;
132 /** Contains all the information about VNF Details @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530133 private vnfdPackageDetails: VNFD;
kumaran.m3b4814a2020-05-01 19:48:54 +0530134 /** Conatins mousedown action @private */
135 private mousedownNode: COMPOSERNODES = null;
136 /** Conatins mouseup action @private */
137 private mouseupNode: COMPOSERNODES = null;
138 /** Conatins current Selection node action @private */
139 private currentSelectedNode: COMPOSERNODES = null;
140 /** Add the activeNode for the selected @private */
141 private activeNode: string = 'active';
142 /** Contains lastkeypressed instance @private */
143 private lastKeyDown: number = -1;
144 /** Contains VDU Information @private */
145 private vduInfo: VDU;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530146 /** Contains VDU Old value Information @private */
147 private oldVDUID: string;
kumaran.m3b4814a2020-05-01 19:48:54 +0530148 /** Contains Internal VL Information @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530149 private intvlInfo: IVLD;
150 /** Contains Internal VL Old value Information @private */
151 private oldintVLID: string;
kumaran.m3b4814a2020-05-01 19:48:54 +0530152 /** Contains Connection Point Information @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530153 private cpInfo: EXTCPD;
154 /** Contains Connection Point Old value Information @private */
155 private oldCPID: string;
kumaran.m3b4814a2020-05-01 19:48:54 +0530156 /** Contains Internal Connection Point Information @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530157 private intcpInfo: VNIR;
kumaran.m3b4814a2020-05-01 19:48:54 +0530158 /** Instance of the modal service @private */
159 private modalService: NgbModal;
160
161 constructor(injector: Injector) {
162 this.injector = injector;
163 this.restService = this.injector.get(RestService);
164 this.dataService = this.injector.get(DataService);
165 this.router = this.injector.get(Router);
166 this.activatedRoute = this.injector.get(ActivatedRoute);
167 this.notifierService = this.injector.get(NotifierService);
168 this.translateService = this.injector.get(TranslateService);
169 this.sharedService = this.injector.get(SharedService);
170 this.modalService = this.injector.get(NgbModal);
171 }
172 /**
173 * Lifecyle Hooks the trigger before component is instantiate
174 */
175 public ngOnInit(): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530176 this.identifier = this.activatedRoute.snapshot.paramMap.get('id');
177 this.generateData();
178 this.headers = new HttpHeaders({
harshini.r92d376d2022-04-05 12:35:14 +0530179 'Content-Type': 'application/gzip',
kumaran.m3b4814a2020-05-01 19:48:54 +0530180 Accept: 'application/json',
181 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
182 });
183 }
184
185 /** Prepare information for node creation of VNFD @public */
186 public generateData(): void {
187 this.nodes = []; this.links = []; this.vnfdPackageDetails = null;
188 this.showRightSideInfo = 'vnfdInfo';
Barath Kumar R063a3f12020-12-29 16:35:09 +0530189 this.restService.getResource(environment.VNFPACKAGESCONTENT_URL + '/' + this.identifier)
190 .subscribe((vnfdPackageDetails: VNFD): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530191 try {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530192 delete vnfdPackageDetails._admin;
193 delete vnfdPackageDetails._id;
194 delete vnfdPackageDetails._links;
195 this.vnfdPackageDetails = vnfdPackageDetails;
196 this.generateVDU(vnfdPackageDetails);
197 this.generateCPPoint(vnfdPackageDetails);
198 this.generateInternalVLD(vnfdPackageDetails);
199 this.generateInternalCP(vnfdPackageDetails);
200 this.generateIntVLCPLinks(vnfdPackageDetails);
201 this.generateVDUCPLinks(vnfdPackageDetails);
kumaran.m3b4814a2020-05-01 19:48:54 +0530202 this.createNode(this.nodes);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530203 this.generateVNFInfo(vnfdPackageDetails);
kumaran.m3b4814a2020-05-01 19:48:54 +0530204 } catch (e) {
205 this.notifierService.notify('error', this.translateService.instant('ERROR'));
206 }
207 this.isLoadingResults = false;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530208 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530209 error.error = typeof error.error === 'string' ? jsyaml.load(error.error) : error.error;
210 if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530211 this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => {
212 // Catch Navigation Error
213 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530214 } else {
215 this.restService.handleError(error, 'get');
216 }
217 this.isLoadingResults = false;
218 this.showRightSideInfo = '';
219 });
220 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530221 /** Generate the VNF Package Information */
222 public generateVNFInfo(vnfdPackageDetails: VNFD): void {
223 this.vnfdInfo['product-name'] = vnfdPackageDetails['product-name'];
224 this.vnfdInfo.description = vnfdPackageDetails.description;
225 this.vnfdInfo.version = vnfdPackageDetails.version;
226 this.vnfdInfo.id = vnfdPackageDetails.id;
227 this.vnfdInfo.provider = vnfdPackageDetails.provider;
228 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530229 /** Events handles at drag on D3 region @public */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530230 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +0530231 public drag(ev: any): void {
232 ev.dataTransfer.setData('text', ev.target.id);
233 }
234 /** Events handles drop at D3 region @public */
235 public drop(ev: DragEvent): void {
236 ev.preventDefault();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530237 const getDropedName: string = ev.dataTransfer.getData('text');
238 if (getDropedName === 'vdu') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530239 this.svg.selectAll('*').remove();
240 this.vduDropCompose();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530241 } else if (getDropedName === 'cp') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530242 this.svg.selectAll('*').remove();
243 this.cpDropCompose();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530244 } else if (getDropedName === 'intvl') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530245 this.svg.selectAll('*').remove();
246 this.intvlDropCompose();
247 }
248 }
249 /** Events handles allow drop on D3 region @public */
250 public allowDrop(ev: DragEvent): void {
251 ev.preventDefault();
252 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530253 /** Generate and list VDU @public */
254 public generateVDU(vnfdPackageDetails: VNFD): void {
255 if (vnfdPackageDetails.vdu !== undefined) {
256 vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
257 this.nodes.push({
258 id: vdu.id,
259 name: vdu.name,
260 reflexive: false,
261 type: 'vdu'
262 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530263 });
264 }
265 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530266 /** Generate and list CP points @public */
267 public generateCPPoint(vnfdPackageDetails: VNFD): void {
268 if (vnfdPackageDetails['ext-cpd'] !== undefined) {
269 vnfdPackageDetails['ext-cpd'].forEach((cp: EXTCPD): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530270 this.nodes.push({
Barath Kumar R86e497d2021-05-04 17:16:14 +0530271 id: cp['int-cpd'].cpd !== undefined ? cp['int-cpd'].cpd : cp.id,
Barath Kumar R063a3f12020-12-29 16:35:09 +0530272 name: cp.id,
273 reflexive: false,
274 type: 'cp'
kumaran.m3b4814a2020-05-01 19:48:54 +0530275 });
276 });
277 }
278 }
279 /** Generate and list Internal VLD @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530280 public generateInternalVLD(vnfdPackageDetails: VNFD): void {
281 if (vnfdPackageDetails['int-virtual-link-desc'] !== undefined) {
282 vnfdPackageDetails['int-virtual-link-desc'].forEach((ivld: IVLD): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530283 this.nodes.push({
Barath Kumar R063a3f12020-12-29 16:35:09 +0530284 id: ivld.id,
285 name: ivld.id,
286 reflexive: false,
287 type: 'intvl'
kumaran.m3b4814a2020-05-01 19:48:54 +0530288 });
289 });
290 }
291 }
292 /** Generate and list Internal CP @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530293 public generateInternalCP(vnfdPackageDetails: VNFD): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530294 if (vnfdPackageDetails.vdu !== undefined) {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530295 vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
296 if (vdu['int-cpd'] !== undefined) {
297 vdu['int-cpd'].forEach((intcpd: VDUINTCPD): void => {
298 if (intcpd['int-virtual-link-desc'] !== undefined) {
299 intcpd['virtual-network-interface-requirement'].forEach((vnir: VNIR): void => {
300 this.nodes.push({
301 id: intcpd.id,
302 name: vnir.name,
303 reflexive: false,
304 type: 'intcp'
305 });
306 });
307 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530308 });
309 }
310 });
311 }
312 }
313 /** Generate VDU External and Internal CP Links @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530314 public generateVDUCPLinks(vnfdPackageDetails: VNFD): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530315 if (vnfdPackageDetails.vdu !== undefined) {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530316 vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
317 const vduLink: string = vdu.id;
318 if (vdu['int-cpd'] !== undefined) {
319 vdu['int-cpd'].forEach((intCPD: VDUINTCPD): void => {
320 if (intCPD['int-virtual-link-desc'] !== undefined) {
321 intCPD['virtual-network-interface-requirement'].forEach((vnir: VNIR): void => {
322 this.links.push({ source: vduLink, target: intCPD.id });
323 });
324 } else {
325 this.links.push({ source: vduLink, target: intCPD.id });
kumaran.m3b4814a2020-05-01 19:48:54 +0530326 }
327 });
328 }
329 });
330 }
331 }
332 /** Generate Network/VLD/Internal VirtualLink, CP Links @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530333 public generateIntVLCPLinks(vnfdPackageDetails: VNFD): void {
334 if (vnfdPackageDetails.vdu !== undefined) {
335 vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
336 if (vdu['int-cpd'] !== undefined) {
337 vdu['int-cpd'].forEach((intCPD: VDUINTCPD): void => {
338 const vldName: string = intCPD['int-virtual-link-desc'];
339 if (intCPD['int-virtual-link-desc'] !== undefined) {
340 intCPD['virtual-network-interface-requirement'].forEach((vnir: VNIR): void => {
341 this.links.push({ source: vldName, target: intCPD.id });
342 });
343 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530344 });
345 }
346 });
347 }
348 }
349 /** VNFD details can be saved on users inputs @public */
350 public saveVNFD(): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530351 this.vnfdPackageDetails['product-name'] = this.vnfdInfo['product-name'];
kumaran.m3b4814a2020-05-01 19:48:54 +0530352 this.vnfdPackageDetails.description = this.vnfdInfo.description;
353 this.vnfdPackageDetails.version = this.vnfdInfo.version;
354 this.vnfdPackageDetails.id = this.vnfdInfo.id;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530355 this.vnfdPackageDetails.provider = this.vnfdInfo.provider;
kumaran.m3b4814a2020-05-01 19:48:54 +0530356 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
kumaran.m3b4814a2020-05-01 19:48:54 +0530357 }
358 /** VDU details can be saved on users inputs @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530359 public saveVDU(getVDUID: string): void {
360 const getOLDVDUID: string = this.oldVDUID;
361 this.vnfdPackageDetails.vdu.forEach((ref: VDU): void => {
362 if (ref.id === getVDUID) {
kumaran.m3b4814a2020-05-01 19:48:54 +0530363 ref.id = this.vduInfo.id;
364 ref.name = this.vduInfo.name;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530365 ref.description = this.vduInfo.description !== undefined ? this.vduInfo.description : '';
366 ref['sw-image-desc'] = this.vduInfo['sw-image-desc'];
367 }
368 });
369 this.vnfdPackageDetails['ext-cpd'].forEach((extCPD: EXTCPD): void => {
370 if (extCPD['int-cpd'] !== undefined) {
371 if (extCPD['int-cpd']['vdu-id'] === getOLDVDUID) {
372 extCPD['int-cpd']['vdu-id'] = this.vduInfo.id;
373 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530374 }
375 });
376 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
377 }
378 /** IntVL details can be saved on users inputs @public */
379 public saveIntVL(intVLID: string): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530380 const getOldID: string = this.oldintVLID;
381 this.vnfdPackageDetails['int-virtual-link-desc'].forEach((ivldDetails: IVLD): void => {
382 if (ivldDetails.id === intVLID) {
383 ivldDetails.id = this.intvlInfo.id;
384 }
385 });
386 this.vnfdPackageDetails.vdu.forEach((vduDetails: VDU): void => {
387 if (vduDetails['int-cpd'] !== undefined) {
388 vduDetails['int-cpd'].forEach((intCPDDetails: VDUINTCPD): void => {
389 if (intCPDDetails['int-virtual-link-desc'] !== undefined) {
390 if (intCPDDetails['int-virtual-link-desc'] === getOldID) {
391 intCPDDetails['int-virtual-link-desc'] = this.intvlInfo.id;
392 }
393 }
394 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530395 }
396 });
397 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
398 }
399 /** IntVL details can be saved on users inputs @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530400 public saveCP(cpID: string): void {
401 const getOldCP: string = this.oldCPID;
402 this.vnfdPackageDetails['ext-cpd'].forEach((ref: EXTCPD): void => {
403 if (ref.id === cpID) {
404 ref.id = this.cpInfo.id;
kumaran.m3b4814a2020-05-01 19:48:54 +0530405 }
406 });
Barath Kumar R063a3f12020-12-29 16:35:09 +0530407 if (this.vnfdPackageDetails['mgmt-cp'] === getOldCP) {
408 this.vnfdPackageDetails['mgmt-cp'] = this.cpInfo.id;
409 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530410 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
411 }
412 /** Edit topology @public */
413 public onEdit(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530414 this.router.navigate(['/packages/vnf/edit/', this.identifier]).catch((): void => {
415 // Catch Navigation Error
416 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530417 }
418 /** Show Info @public */
419 public showInfo(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530420 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530421 const modalRef: NgbModalRef = this.modalService.open(ConfirmationTopologyComponent, { backdrop: 'static' });
422 modalRef.componentInstance.topologyType = 'Info';
423 modalRef.componentInstance.topologytitle = this.translateService.instant('PAGE.TOPOLOGY.INFO');
Barath Kumar R063a3f12020-12-29 16:35:09 +0530424 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530425 if (result) {
426 // empty
427 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530428 }).catch((): void => {
429 // Catch Navigation Error
430 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530431 }
432 /** Event to freeze the animation @public */
433 public onFreeze(): void {
434 this.classApplied = !this.classApplied;
435 const alreadyFixedIsActive: boolean = d3.select('svg#graphContainer').classed(this.fixedClass);
436 d3.select('svg#graphContainer').classed(this.fixedClass, !alreadyFixedIsActive);
437 if (alreadyFixedIsActive) {
438 this.force.stop();
439 }
440 this.forceSimulationActive = alreadyFixedIsActive;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530441 this.nodes.forEach((d: COMPOSERNODES): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530442 d.fx = (alreadyFixedIsActive) ? null : d.x;
443 d.fy = (alreadyFixedIsActive) ? null : d.y;
444 });
445 if (alreadyFixedIsActive) {
446 this.force.restart();
447 }
448 }
449 /** Events handles when dragended @public */
450 public toggleSidebar(): void {
451 this.sideBarOpened = !this.sideBarOpened;
452 this.deselectAllNodes();
453 this.showRightSideInfo = 'vnfdInfo';
454 }
455 /** Get the default Configuration of containers @private */
456 private getGraphContainerAttr(): GRAPHDETAILS {
457 return {
458 width: 700,
459 height: 400,
460 nodeHeight: 50,
461 nodeWidth: 35,
462 textX: -35,
463 textY: 30,
464 radius: 5,
465 distance: 50,
466 strength: -500,
467 forcex: 2,
468 forcey: 2,
469 sourcePaddingYes: 17,
470 sourcePaddingNo: 12,
471 targetPaddingYes: 4,
472 targetPaddingNo: 3,
473 alphaTarget: 0.3,
474 imageX: -25,
475 imageY: -25,
476 shiftKeyCode: 17
477 };
478 }
479 /** Node is created and render at D3 region @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530480 private createNode(nodes: VNFD[]): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530481 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
482 d3.selectAll('svg#graphContainer > *').remove();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530483 d3.select(window).on('keydown', (): void => { this.keyDown(); });
484 d3.select(window).on('keyup', (): void => { this.keyUp(); });
485 this.svg = d3.select('#graphContainer')
486 .attr('oncontextmenu', 'return false;')
487 .attr('viewBox', `0 0 ${graphContainerAttr.width} ${graphContainerAttr.height}`)
488 .on('mousemove', (): void => { this.mousemove(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530489 this.force = d3.forceSimulation()
Barath Kumar R063a3f12020-12-29 16:35:09 +0530490 .force('link', d3.forceLink().id((d: TickPath): string => d.id).distance(graphContainerAttr.distance))
kumaran.m3b4814a2020-05-01 19:48:54 +0530491 .force('charge', d3.forceManyBody().strength(graphContainerAttr.strength))
492 .force('x', d3.forceX(graphContainerAttr.width / graphContainerAttr.forcex))
493 .force('y', d3.forceY(graphContainerAttr.height / graphContainerAttr.forcey))
Barath Kumar R063a3f12020-12-29 16:35:09 +0530494 .on('tick', (): void => { this.tick(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530495 this.path = this.svg.append('svg:g').selectAll('path');
496 this.dragLine = this.svg.append('svg:path').attr('class', 'link dragline hidden').attr('d', 'M0,0L0,0');
497 this.network = this.svg.append('svg:g').selectAll('network');
498 this.virutualDeploymentUnit = this.svg.append('svg:g').selectAll('virutualDeploymentUnit');
499 this.connectionPoint = this.svg.append('svg:g').selectAll('connectionPoint');
500 this.intConnectionPoint = this.svg.append('svg:g').selectAll('intConnectionPoint');
501 this.restart(nodes);
502 }
503 /** Update force layout (called automatically each iteration) @private */
504 private tick(): void {
505 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530506 this.path.attr('d', (d: Tick): string => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530507 const deltaX: number = d.target.x - d.source.x; const deltaY: number = d.target.y - d.source.y;
508 const dist: number = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
509 const normX: number = deltaX / dist; const normY: number = deltaY / dist;
510 const sourcePadding: number = d.left ? graphContainerAttr.sourcePaddingYes : graphContainerAttr.sourcePaddingNo;
511 const targetPadding: number = d.right ? graphContainerAttr.targetPaddingYes : graphContainerAttr.targetPaddingNo;
512 const sourceX: number = d.source.x + (sourcePadding * normX); const sourceY: number = d.source.y + (sourcePadding * normY);
513 const targetX: number = d.target.x - (targetPadding * normX); const targetY: number = d.target.y - (targetPadding * normY);
514 return `M${sourceX},${sourceY}L${targetX},${targetY}`;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530515 }).on('dblclick', (d: Tick): void => { this.getDeleteLinkConfirmation(d); });
516 this.network.attr('transform', (d: TickPath): string => `translate(${d.x},${d.y})`);
517 this.virutualDeploymentUnit.attr('transform', (d: TickPath): string => `translate(${d.x},${d.y})`);
518 this.connectionPoint.attr('transform', (d: TickPath): string => `translate(${d.x},${d.y})`);
519 this.intConnectionPoint.attr('transform', (d: TickPath): string => `translate(${d.x},${d.y})`);
kumaran.m3b4814a2020-05-01 19:48:54 +0530520 }
521 /** Update graph (called when needed) @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530522 private restart(nodes: VNFD[]): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530523 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
524 this.path = this.path.data(this.links);
525 const cpNodes: {}[] = []; const vduNodes: {}[] = []; const vlNodes: {}[] = []; const intcpNodes: {}[] = []; //Nodes are known by id
Barath Kumar R063a3f12020-12-29 16:35:09 +0530526 nodes.forEach((nodeList: COMPOSERNODES): void => {
527 if (nodeList.type === 'cp') { cpNodes.push(nodeList); }
528 else if (nodeList.type === 'vdu') { vduNodes.push(nodeList); }
529 else if (nodeList.type === 'intvl') { vlNodes.push(nodeList); }
530 else if (nodeList.type === 'intcp') { intcpNodes.push(nodeList); }
kumaran.m3b4814a2020-05-01 19:48:54 +0530531 });
Barath Kumar R063a3f12020-12-29 16:35:09 +0530532 this.network = this.network.data(vlNodes, (d: VNFD): string => d.id);
533 this.virutualDeploymentUnit = this.virutualDeploymentUnit.data(vduNodes, (d: VNFD): string => d.id);
534 this.connectionPoint = this.connectionPoint.data(cpNodes, (d: VNFD): string => d.id);
535 this.intConnectionPoint = this.intConnectionPoint.data(intcpNodes, (d: VNFD): string => d.id);
kumaran.m3b4814a2020-05-01 19:48:54 +0530536 this.resetAndCreateNodes();
537 this.force.nodes(nodes).force('link').links(this.links); //Set the graph in motion
538 this.force.alphaTarget(graphContainerAttr.alphaTarget).restart();
539 }
540 /** Rest and create nodes @private */
541 private resetAndCreateNodes(): void {
542 this.path.exit().remove();
543 this.network.exit().remove();
544 this.virutualDeploymentUnit.exit().remove();
545 this.connectionPoint.exit().remove();
546 this.intConnectionPoint.exit().remove();
547 this.getPathNodes();
548 this.getgNetwork();
549 this.getgVirutualDeploymentUnit();
550 this.getgConnectionPoint();
551 this.getgIntConnectionPoint();
552 this.network = this.gNetwork.merge(this.network);
553 this.virutualDeploymentUnit = this.gVirutualDeploymentUnit.merge(this.virutualDeploymentUnit);
554 this.connectionPoint = this.gConnectionPoint.merge(this.connectionPoint);
555 this.intConnectionPoint = this.gIntConnectionPoint.merge(this.intConnectionPoint);
556 this.path.merge(this.path);
557 }
558 /** Setting the Path @private */
559 private getPathNodes(): void {
560 this.path = this.path.enter().append('svg:path').attr('class', 'link');
561 }
562 /** Settings all the network attributes of nodes @private */
563 private getgNetwork(): void {
564 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
565 this.gNetwork = this.network.enter().append('svg:g');
566 this.gNetwork.append('svg:circle').attr('r', graphContainerAttr.radius).style('fill', '#eeeeee');
567 this.gNetwork.append('svg:image')
568 .style('opacity', 1)
569 .attr('x', graphContainerAttr.imageX)
570 .attr('y', graphContainerAttr.imageY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530571 .call(this.onDragDrop())
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530572 .attr('id', (d: COMPOSERNODES): string => d.id)
kumaran.m3b4814a2020-05-01 19:48:54 +0530573 .attr('class', 'node').attr('width', graphContainerAttr.nodeWidth).attr('height', graphContainerAttr.nodeHeight)
574 .attr('xlink:href', 'assets/images/INTVL.svg')
Barath Kumar R063a3f12020-12-29 16:35:09 +0530575 .on('mousedown', (d: COMPOSERNODES): void => { this.mouseDown(d); })
576 .on('mouseup', (d: COMPOSERNODES): void => { this.mouseUp(d); })
577 .on('click', (d: COMPOSERNODES): void => { this.singleClick(this.network, d); this.onNodeClickToggleSidebar(); })
578 .on('dblclick', (d: COMPOSERNODES): void => { this.getDeleteNodeConfirmation(d); this.onNodedblClickToggleSidebar(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530579 this.gNetwork.append('svg:text')
580 .attr('class', 'node_text')
581 .attr('y', graphContainerAttr.textY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530582 .text((d: COMPOSERNODES): string => d.id);
kumaran.m3b4814a2020-05-01 19:48:54 +0530583 }
584 /** Settings all the connection point attributes of nodes @private */
585 private getgVirutualDeploymentUnit(): void {
586 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
587 this.gVirutualDeploymentUnit = this.virutualDeploymentUnit.enter().append('svg:g');
588 this.gVirutualDeploymentUnit.append('svg:circle').attr('r', graphContainerAttr.radius).style('fill', '#eeeeee');
589 this.gVirutualDeploymentUnit.append('svg:image')
590 .style('opacity', 1)
591 .attr('x', graphContainerAttr.imageX)
592 .attr('y', graphContainerAttr.imageY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530593 .call(this.onDragDrop())
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530594 .attr('id', (d: COMPOSERNODES): string => d.id)
kumaran.m3b4814a2020-05-01 19:48:54 +0530595 .attr('class', 'node').attr('width', graphContainerAttr.nodeWidth).attr('height', graphContainerAttr.nodeHeight)
596 .attr('xlink:href', 'assets/images/VDU.svg')
Barath Kumar R063a3f12020-12-29 16:35:09 +0530597 .on('mousedown', (d: COMPOSERNODES): void => { this.mouseDown(d); })
598 .on('mouseup', (d: COMPOSERNODES): void => { this.mouseUp(d); })
599 .on('click', (d: COMPOSERNODES): void => { this.singleClick(this.virutualDeploymentUnit, d); this.onNodeClickToggleSidebar(); })
600 .on('dblclick', (d: COMPOSERNODES): void => { this.getDeleteNodeConfirmation(d); this.onNodedblClickToggleSidebar(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530601 this.gVirutualDeploymentUnit.append('svg:text')
602 .attr('class', 'node_text')
603 .attr('y', graphContainerAttr.textY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530604 .text((d: COMPOSERNODES): string => d.id);
kumaran.m3b4814a2020-05-01 19:48:54 +0530605 }
606 /** Settings all the connection point attributes of nodes @private */
607 private getgConnectionPoint(): void {
608 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
609 this.gConnectionPoint = this.connectionPoint.enter().append('svg:g');
610 this.gVirutualDeploymentUnit.append('svg:circle').attr('r', graphContainerAttr.radius).style('fill', '#eeeeee');
611 this.gConnectionPoint.append('svg:image')
612 .style('opacity', 1)
613 .attr('x', graphContainerAttr.imageX)
614 .attr('y', graphContainerAttr.imageY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530615 .call(this.onDragDrop())
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530616 .attr('id', (d: COMPOSERNODES): string => d.id)
kumaran.m3b4814a2020-05-01 19:48:54 +0530617 .attr('class', 'node').attr('width', graphContainerAttr.nodeWidth).attr('height', graphContainerAttr.nodeHeight)
618 .attr('xlink:href', 'assets/images/CP-VNF.svg')
Barath Kumar R063a3f12020-12-29 16:35:09 +0530619 .on('mousedown', (d: COMPOSERNODES): void => { this.mouseDown(d); })
620 .on('mouseup', (d: COMPOSERNODES): void => { this.mouseUp(d); })
621 .on('click', (d: COMPOSERNODES): void => { this.singleClick(this.connectionPoint, d); this.onNodeClickToggleSidebar(); })
622 .on('dblclick', (d: COMPOSERNODES): void => { this.getDeleteNodeConfirmation(d); this.onNodedblClickToggleSidebar(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530623 this.gConnectionPoint.append('svg:text')
624 .attr('class', 'node_text')
625 .attr('y', graphContainerAttr.textY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530626 .text((d: COMPOSERNODES): string => d.name);
kumaran.m3b4814a2020-05-01 19:48:54 +0530627 }
628 /** Settings all the internal connection point attributes of nodes @private */
629 private getgIntConnectionPoint(): void {
630 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
631 this.gIntConnectionPoint = this.intConnectionPoint.enter().append('svg:g');
632 this.gIntConnectionPoint.append('svg:circle').attr('r', graphContainerAttr.radius).style('fill', '#eeeeee');
633 this.gIntConnectionPoint.append('svg:image')
634 .style('opacity', 1)
635 .attr('x', graphContainerAttr.imageX)
636 .attr('y', graphContainerAttr.imageY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530637 .call(this.onDragDrop())
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530638 .attr('id', (d: COMPOSERNODES): string => d.id)
kumaran.m3b4814a2020-05-01 19:48:54 +0530639 .attr('class', 'node').attr('width', graphContainerAttr.nodeWidth).attr('height', graphContainerAttr.nodeHeight)
640 .attr('xlink:href', 'assets/images/INTCP.svg')
Barath Kumar R063a3f12020-12-29 16:35:09 +0530641 .on('mousedown', (d: COMPOSERNODES): void => { this.mouseDown(d); })
642 .on('mouseup', (d: COMPOSERNODES): void => { this.mouseUp(d); })
643 .on('click', (d: COMPOSERNODES): void => { this.singleClick(this.intConnectionPoint, d); this.onNodeClickToggleSidebar(); })
644 .on('dblclick', (d: COMPOSERNODES): void => { this.getDeleteNodeConfirmation(d); this.onNodedblClickToggleSidebar(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530645 this.gIntConnectionPoint.append('svg:text')
646 .attr('class', 'node_text')
647 .attr('y', graphContainerAttr.textY)
Barath Kumar R063a3f12020-12-29 16:35:09 +0530648 .text((d: COMPOSERNODES): string => d.name);
kumaran.m3b4814a2020-05-01 19:48:54 +0530649 }
650 /** Drop VDU Composer Data @private */
651 private vduDropCompose(): void {
652 const randomID: string = this.sharedService.randomString();
Barath Kumar R86e497d2021-05-04 17:16:14 +0530653 if (this.vnfdPackageDetails['mgmt-cp'] === undefined) {
654 this.notifierService.notify('error', this.translateService.instant('PAGE.TOPOLOGY.ADDCPBEFOREVDU'));
655 } else {
656 if (this.vnfdPackageDetails.vdu === undefined) {
657 this.vnfdPackageDetails.vdu = [];
658 }
659 this.vnfdPackageDetails.vdu.push({
660 id: 'vdu_' + randomID,
661 name: 'vdu_' + randomID,
662 description: '',
663 'sw-image-desc': 'ubuntu',
664 'int-cpd': [],
665 'monitoring-parameter': [],
666 'virtual-compute-desc': '',
667 'virtual-storage-desc': []
668 });
669 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530670 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530671 }
672 /** Drop CP Composer Data @private */
673 private cpDropCompose(): void {
674 const randomID: string = this.sharedService.randomString();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530675 if (this.vnfdPackageDetails['ext-cpd'] === undefined) {
676 this.vnfdPackageDetails['ext-cpd'] = [];
kumaran.m3b4814a2020-05-01 19:48:54 +0530677 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530678 this.vnfdPackageDetails['ext-cpd'].push({
679 id: 'cp_' + randomID,
680 'int-cpd': {}
kumaran.m3b4814a2020-05-01 19:48:54 +0530681 });
Barath Kumar R86e497d2021-05-04 17:16:14 +0530682 if (this.vnfdPackageDetails['mgmt-cp'] === undefined) {
683 this.vnfdPackageDetails['mgmt-cp'] = 'cp_' + randomID;
684 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530685 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
686 }
687 /** Drop IntVL Composer Data @private */
688 private intvlDropCompose(): void {
689 const randomID: string = this.sharedService.randomString();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530690 if (this.vnfdPackageDetails['int-virtual-link-desc'] === undefined) {
691 this.vnfdPackageDetails['int-virtual-link-desc'] = [];
692 }
693 this.vnfdPackageDetails['int-virtual-link-desc'].push({
694 id: 'vnf_vl_' + randomID
kumaran.m3b4814a2020-05-01 19:48:54 +0530695 });
696 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
697 }
698 /** Add the Add Nodes Data @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530699 private addNodes(apiURL: string, identifier: string, data: VNFD): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530700 this.isLoadingResults = true;
701 const apiURLHeader: APIURLHEADER = {
702 url: apiURL + '/' + identifier + '/package_content',
703 httpOptions: { headers: this.headers }
704 };
Barath Kumar R063a3f12020-12-29 16:35:09 +0530705 const vnfData: VNFDATA = {};
706 vnfData.vnfd = data;
kumaran.m3b4814a2020-05-01 19:48:54 +0530707 const descriptorInfo: string = jsyaml.dump(vnfData, { sortKeys: true });
708 this.sharedService.targzFile({ packageType: 'vnfd', id: this.identifier, descriptor: descriptorInfo })
709 .then((content: ArrayBuffer): void => {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530710 this.restService.putResource(apiURLHeader, content).subscribe((res: {}): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530711 this.generateData();
712 this.notifierService.notify('success', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.UPDATEDSUCCESSFULLY'));
713 this.isLoadingResults = false;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530714 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530715 this.generateData();
716 this.restService.handleError(error, 'put');
717 this.isLoadingResults = false;
718 });
719 }).catch((): void => {
720 this.notifierService.notify('error', this.translateService.instant('ERROR'));
721 this.isLoadingResults = false;
722 });
723 }
724 /** Events handles when mousedown click it will capture the selected node data @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530725 private mouseDown(d: COMPOSERNODES): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530726 // eslint-disable-next-line deprecation/deprecation
kumaran.m3b4814a2020-05-01 19:48:54 +0530727 event.preventDefault();
728 if (d3.event.ctrlKey) { return; }
729 if (d3.event.shiftKey) {
730 this.mousedownNode = d;
731 this.currentSelectedNode = (this.mousedownNode === this.currentSelectedNode) ? null : this.mousedownNode;
732 this.dragLine.classed('hidden', false)
733 .attr('d', `M${this.mousedownNode.x},${this.mousedownNode.y}L${this.mousedownNode.x},${this.mousedownNode.y}`);
734 }
735 }
736 /** Event handles when mouseup event occures @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530737 private mouseUp(d: COMPOSERNODES): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530738 if (!this.mousedownNode) { return; }
739 this.dragLine.classed('hidden', true);
740 this.mouseupNode = d;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530741 if (this.mousedownNode.type === 'vdu') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530742 this.vduMouseDownNode();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530743 } else if (this.mousedownNode.type === 'cp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530744 this.cpMouseDownNode();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530745 } else if (this.mousedownNode.type === 'intvl') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530746 this.intVLMouseDownNode();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530747 } else if (this.mousedownNode.type === 'intcp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530748 this.intCPMouseDownNode();
749 } else {
kumaran.m3b4814a2020-05-01 19:48:54 +0530750 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.INVALIDSELECTION'));
751 this.deselectPath();
752 }
753 this.resetMouseActions();
754 this.currentSelectedNode = null;
755 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530756 /** Establish a connection point between vdu and other nodes @private */
757 private vduMouseDownNode(): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530758 if (this.mousedownNode.type === 'vdu' && this.mouseupNode.type === 'cp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530759 this.vduCPConnection(this.mousedownNode.id, this.mouseupNode.id);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530760 } else if (this.mousedownNode.type === 'vdu' && this.mouseupNode.type === 'intcp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530761 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKVDUANDINTCP'));
762 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530763 } else if (this.mousedownNode.type === 'vdu' && this.mouseupNode.type === 'vdu') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530764 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKVDUANDVDU'));
765 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530766 } else if (this.mousedownNode.type === 'vdu' && this.mouseupNode.type === 'intvl') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530767 this.vduIntvlConnection(this.mousedownNode.id, this.mouseupNode.id);
768 }
769 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530770 /** Establish a connection point between cp and other nodes @private */
771 private cpMouseDownNode(): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530772 if (this.mousedownNode.type === 'cp' && this.mouseupNode.type === 'vdu') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530773 this.vduCPConnection(this.mouseupNode.id, this.mousedownNode.id);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530774 } else if (this.mousedownNode.type === 'cp' && this.mouseupNode.type === 'intvl') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530775 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKCPANDVNFVL'));
776 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530777 } else if (this.mousedownNode.type === 'cp' && this.mouseupNode.type === 'intcp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530778 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKCPANDINTCP'));
779 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530780 } else if (this.mousedownNode.type === 'cp' && this.mouseupNode.type === 'cp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530781 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKCPANDCP'));
782 this.deselectPath();
783 }
784 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530785 /** Establish a connection piont between intvl and other nodes @private */
786 private intVLMouseDownNode(): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530787 if (this.mousedownNode.type === 'intvl' && this.mouseupNode.type === 'cp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530788 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKVNFVLANDCP'));
789 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530790 } else if (this.mousedownNode.type === 'intvl' && this.mouseupNode.type === 'vdu') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530791 this.vduIntvlConnection(this.mouseupNode.id, this.mousedownNode.id);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530792 } else if (this.mousedownNode.type === 'intvl' && this.mouseupNode.type === 'intvl') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530793 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKVNFVLANDVNFVL'));
794 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530795 } else if (this.mousedownNode.type === 'intvl' && this.mouseupNode.type === 'intcp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530796 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKVNFVLANDONTCP'));
797 this.deselectPath();
798 }
799 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530800 /** Establish a connection point between intcp and other nodes @private */
801 private intCPMouseDownNode(): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530802 if (this.mousedownNode.type === 'intcp' && this.mouseupNode.type === 'vdu') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530803 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKINTCPANDVDU'));
804 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530805 } else if (this.mousedownNode.type === 'intcp' && this.mouseupNode.type === 'cp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530806 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKINTCPANDCP'));
807 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530808 } else if (this.mousedownNode.type === 'intcp' && this.mouseupNode.type === 'intvl') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530809 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKINTCPANDVNFVL'));
810 this.deselectPath();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530811 } else if (this.mousedownNode.type === 'intcp' && this.mouseupNode.type === 'intcp') {
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530812 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.CANNOTLINKINTCPANDINTCP'));
813 this.deselectPath();
814 }
815 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530816 /** Establish a connection between VDU & CP vice versa @private */
817 private vduCPConnection(nodeA: string, nodeB: string): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530818 const vduExternalID: string = nodeA + '-eth_' + this.sharedService.randomString();
819 if (this.vnfdPackageDetails.vdu !== undefined) {
820 this.vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
821 const vduID: string = vdu.id;
822 if (vdu.id === nodeA) {
823 if (this.vnfdPackageDetails['ext-cpd'] !== undefined) {
824 this.vnfdPackageDetails['ext-cpd'].forEach((extcpd: EXTCPD, index: number): void => {
825 if (extcpd.id === nodeB) {
826 if (vdu['int-cpd'] === undefined) {
827 vdu['int-cpd'] = [];
828 }
Barath Kumar R86e497d2021-05-04 17:16:14 +0530829 vdu['int-cpd'].push({
830 id: vduExternalID,
831 'virtual-network-interface-requirement': [
832 {
833 name: vduExternalID,
834 position: 1,
835 'virtual-interface': { type: 'PARAVIRT' }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530836 }
Barath Kumar R86e497d2021-05-04 17:16:14 +0530837 ]
838 });
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530839 // eslint-disable-next-line security/detect-object-injection
Barath Kumar R86e497d2021-05-04 17:16:14 +0530840 this.vnfdPackageDetails['ext-cpd'][index] = {
841 id: extcpd.id,
842 'int-cpd': {
843 cpd: vduExternalID,
844 'vdu-id': vduID
845 }
846 };
Barath Kumar R063a3f12020-12-29 16:35:09 +0530847 }
848 });
849 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530850 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530851 });
852 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530853 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
854 this.deselectPath();
855 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530856 /** Establish a connection between vdu & intvl and vice versa @private */
857 private vduIntvlConnection(nodeA: string, nodeB: string): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530858 const vduInternalID: string = nodeA + '-eth_' + this.sharedService.randomString();
859 if (this.vnfdPackageDetails.vdu !== undefined) {
860 this.vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
861 if (vdu.id === nodeA) {
862 if (vdu['int-cpd'] === undefined) {
863 vdu['int-cpd'] = [];
864 }
865 vdu['int-cpd'].push({
866 id: vduInternalID,
867 'int-virtual-link-desc': nodeB,
868 'virtual-network-interface-requirement': [
869 {
870 name: vduInternalID,
871 position: 1,
872 'virtual-interface': { type: 'PARAVIRT' }
873 }
874 ]
875 });
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530876 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530877 });
878 }
Barath Kumar Rb323b2a2020-07-07 15:31:19 +0530879 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
880 this.deselectPath();
881 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530882 /** Events handles when mousemove it will capture the selected node data @private */
883 private mousemove(): void {
884 if (!this.mousedownNode) { return; }
885 this.dragLine.attr('d',
886 `M${this.mousedownNode.x},${this.mousedownNode.y}L${d3.mouse(d3.event.currentTarget)[0]},${d3.mouse(d3.event.currentTarget)[1]}`);
887 }
888 /** reset Mouse varaibles @private */
889 private resetMouseActions(): void {
890 this.mousedownNode = null;
891 this.mouseupNode = null;
892 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530893 /** drag event @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530894 // eslint-disable-next-line @typescript-eslint/no-explicit-any
Barath Kumar R063a3f12020-12-29 16:35:09 +0530895 private onDragDrop(): any {
896 return d3.drag().filter(this.dragFilter)
897 .on('start', this.dragstarted)
898 .on('drag', this.dragged)
899 .on('end', this.dragended);
900 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530901 /** Key press event @private */
902 private keyDown(): void {
903 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
904 if (this.lastKeyDown !== -1) { return; }
905 this.lastKeyDown = d3.event.keyCode;
906 if (d3.event.keyCode === graphContainerAttr.shiftKeyCode) {
kumaran.m3b4814a2020-05-01 19:48:54 +0530907 this.svg.classed('ctrl', true);
908 }
909 }
910 /** Key realse event @private */
911 private keyUp(): void {
912 const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr();
913 this.lastKeyDown = -1;
914 if (d3.event.keyCode === graphContainerAttr.shiftKeyCode) {
915 this.gNetwork.on('.drag', null);
916 this.gVirutualDeploymentUnit.on('.drag', null);
917 this.gConnectionPoint.on('.drag', null);
918 this.gIntConnectionPoint.on('.drag', null);
919 this.svg.classed('ctrl', false);
920 }
921 }
922 /** Mosue Drag Line false if it is not satisfied @private */
923 private deselectPath(): void {
924 this.dragLine.classed('hidden', true).attr('d', 'M0,0L0,0');
925 }
926 /** Events handles when Shift Click to perform create cp @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530927 // eslint-disable-next-line @typescript-eslint/no-explicit-any
Barath Kumar R063a3f12020-12-29 16:35:09 +0530928 private singleClick(nodeSelected: any, d: COMPOSERNODES): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530929 this.selectedNode(nodeSelected, d);
930 }
931 /** Get confirmation Before Deleting the Node in Topology @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530932 private getDeleteNodeConfirmation(d: COMPOSERNODES): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530933 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530934 const modalRef: NgbModalRef = this.modalService.open(ConfirmationTopologyComponent, { backdrop: 'static' });
935 modalRef.componentInstance.topologyType = 'Delete';
936 modalRef.componentInstance.topologyname = d.name;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530937 if (d.type === 'vdu') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530938 modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.VDU';
Barath Kumar R063a3f12020-12-29 16:35:09 +0530939 } else if (d.type === 'intvl') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530940 modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.INTVL';
Barath Kumar R063a3f12020-12-29 16:35:09 +0530941 } else if (d.type === 'cp') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530942 modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.CONNECTIONPOINT';
Barath Kumar R063a3f12020-12-29 16:35:09 +0530943 } else if (d.type === 'intcp') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530944 modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.INTCP';
945 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530946 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530947 if (result) {
948 this.deleteNode(d);
949 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530950 }).catch((): void => {
951 // Catch Navigation Error
952 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530953 }
954 /** Delete nodes @private */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530955 private deleteNode(d: COMPOSERNODES): void {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530956 this.nodes.forEach((node: VNFD): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530957 if (node.id === d.id) {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530958 if (d.type === 'cp') {
959 if (this.vnfdPackageDetails['ext-cpd'] !== undefined) {
960 let getRelatedVDUCPD: string; let getRelatedVDUID: string;
961 const posExtCPD: number = this.vnfdPackageDetails['ext-cpd'].findIndex((e: EXTCPD): boolean => {
962 if (e.id === d.name) {
963 if (e['int-cpd'] !== undefined) {
964 getRelatedVDUCPD = e['int-cpd'].cpd; getRelatedVDUID = e['int-cpd']['vdu-id'];
kumaran.m3b4814a2020-05-01 19:48:54 +0530965 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530966 return true;
967 } else {
968 return false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530969 }
970 });
Barath Kumar R063a3f12020-12-29 16:35:09 +0530971 if (posExtCPD !== -1) {
972 this.vnfdPackageDetails['ext-cpd'].splice(posExtCPD, 1);
kumaran.m3b4814a2020-05-01 19:48:54 +0530973 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530974 if (getRelatedVDUCPD !== undefined && getRelatedVDUID !== undefined) {
975 this.vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
976 if (vdu.id === getRelatedVDUID) {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530977 const posINTCPD: number = vdu['int-cpd'].findIndex((intCPD: VDUINTCPD): boolean => intCPD.id === getRelatedVDUCPD);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530978 if (posINTCPD !== -1) {
979 vdu['int-cpd'].splice(posINTCPD, 1);
980 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530981 }
982 });
983 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530984 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530985 } else if (d.type === 'intcp') {
986 this.vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530987 const posINTCPD: number = vdu['int-cpd'].findIndex((intCPD: VDUINTCPD): boolean => intCPD.id === d.id);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530988 if (posINTCPD !== -1) {
989 vdu['int-cpd'].splice(posINTCPD, 1);
990 }
991 });
992 } else if (d.type === 'intvl') {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530993 const posINTVLD: number = this.vnfdPackageDetails['int-virtual-link-desc'].findIndex((intVLD: IVLD): boolean => intVLD.id === d.id);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530994 if (posINTVLD !== -1) {
995 this.vnfdPackageDetails['int-virtual-link-desc'].splice(posINTVLD, 1);
996 }
997 if (this.vnfdPackageDetails.vdu !== undefined) {
998 this.vnfdPackageDetails.vdu.forEach((vduDetails: VDU): void => {
999 if (vduDetails['int-cpd'] !== undefined) {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +05301000 const newVDUintCPDArray: VDUINTCPD[] = vduDetails['int-cpd'].filter((item: VDUINTCPD): boolean => item['int-virtual-link-desc'] !== undefined ? item['int-virtual-link-desc'] !== d.id ? true : false : true);
Barath Kumar R063a3f12020-12-29 16:35:09 +05301001 vduDetails['int-cpd'] = newVDUintCPDArray;
1002 }
1003 });
1004 }
1005 } else if (d.type === 'vdu') {
1006 const getRelatedExtCPD: string[] = [];
1007 const posVDU: number = this.vnfdPackageDetails.vdu.findIndex((vduDetails: VDU): boolean => {
1008 if (vduDetails.id === d.id) {
1009 if (vduDetails['int-cpd'] !== undefined) {
1010 vduDetails['int-cpd'].forEach((intCPDDetails: VDUINTCPD): void => {
1011 if (intCPDDetails['int-virtual-link-desc'] === undefined) {
1012 getRelatedExtCPD.push(intCPDDetails.id);
1013 }
1014 });
1015 }
1016 return true;
1017 } else {
1018 return false;
1019 }
1020 });
1021 if (posVDU !== -1) {
1022 this.vnfdPackageDetails.vdu.splice(posVDU, 1);
1023 }
1024 getRelatedExtCPD.forEach((CPDID: string, index: number): void => {
1025 this.vnfdPackageDetails['ext-cpd'].forEach((extCPD: EXTCPD): void => {
1026 if (extCPD['int-cpd'] !== undefined) {
1027 if (extCPD['int-cpd'].cpd === CPDID) {
Barath Kumar R86e497d2021-05-04 17:16:14 +05301028 extCPD['int-cpd'] = {};
Barath Kumar R063a3f12020-12-29 16:35:09 +05301029 }
1030 }
1031 });
1032 });
kumaran.m3b4814a2020-05-01 19:48:54 +05301033 } else {
1034 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.INVALIDSELECTION'));
1035 }
1036 this.addNodes(environment.VNFPACKAGES_URL, this.identifier, this.vnfdPackageDetails);
1037 }
1038 });
1039 }
1040 /** Get confirmation before deleting the ink in Topology @private */
1041 private getDeleteLinkConfirmation(d: Tick): void {
1042 this.notifierService.notify('warning', this.translateService.instant('PAGE.VNFPACKAGE.VNFCOMPOSE.YOUCANNOTDELETELINK'));
1043 }
1044 /** Selected nodes @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +05301045 // eslint-disable-next-line @typescript-eslint/no-explicit-any
Barath Kumar R063a3f12020-12-29 16:35:09 +05301046 private selectedNode(nodeSeleced: any, d: COMPOSERNODES): void {
kumaran.m3b4814a2020-05-01 19:48:54 +05301047 const alreadyIsActive: boolean = nodeSeleced.select('#' + d.id).classed(this.activeNode);
1048 this.deselectAllNodes();
1049 nodeSeleced.select('#' + d.id).classed(this.activeNode, !alreadyIsActive);
Barath Kumar R063a3f12020-12-29 16:35:09 +05301050 if (d.type === 'vdu' && !alreadyIsActive) {
1051 this.vnfdPackageDetails.vdu.forEach((res: VDU): void => {
1052 if (res.id === d.id) {
kumaran.m3b4814a2020-05-01 19:48:54 +05301053 this.showRightSideInfo = 'vduInfo';
1054 this.vduInfo = res;
Barath Kumar R063a3f12020-12-29 16:35:09 +05301055 this.oldVDUID = res.id;
kumaran.m3b4814a2020-05-01 19:48:54 +05301056 }
1057 });
Barath Kumar R063a3f12020-12-29 16:35:09 +05301058 } else if (d.type === 'cp' && !alreadyIsActive) {
1059 this.vnfdPackageDetails['ext-cpd'].forEach((cp: EXTCPD): void => {
1060 const getCPDID: string = cp['int-cpd'] !== undefined ? cp['int-cpd'].cpd : cp.id;
1061 if (getCPDID === d.id) {
kumaran.m3b4814a2020-05-01 19:48:54 +05301062 this.showRightSideInfo = 'cpInfo';
Barath Kumar R063a3f12020-12-29 16:35:09 +05301063 this.cpInfo = cp;
1064 this.oldCPID = cp.id;
kumaran.m3b4814a2020-05-01 19:48:54 +05301065 }
1066 });
Barath Kumar R063a3f12020-12-29 16:35:09 +05301067 } else if (d.type === 'intvl' && !alreadyIsActive) {
1068 this.vnfdPackageDetails['int-virtual-link-desc'].forEach((ivld: IVLD): void => {
1069 if (ivld.id === d.id) {
1070 this.showRightSideInfo = 'intvlInfo';
1071 this.intvlInfo = ivld;
1072 this.oldintVLID = ivld.id;
1073 }
1074 });
1075 } else if (d.type === 'intcp' && !alreadyIsActive) {
1076 this.vnfdPackageDetails.vdu.forEach((vdu: VDU): void => {
1077 vdu['int-cpd'].forEach((intcpd: VDUINTCPD): void => {
1078 if (intcpd.id === d.id) {
1079 if (intcpd['int-virtual-link-desc'] !== undefined) {
1080 intcpd['virtual-network-interface-requirement'].forEach((vnir: VNIR): void => {
1081 this.intcpInfo = vnir;
1082 this.showRightSideInfo = 'intcpInfo';
1083 });
1084 }
1085 }
1086 });
1087 });
kumaran.m3b4814a2020-05-01 19:48:54 +05301088 } else {
1089 this.showRightSideInfo = 'vnfdInfo';
1090 }
1091 }
1092 /** De-select all the selected nodes @private */
1093 private deselectAllNodes(): void {
1094 this.network.select('image').classed(this.activeNode, false);
1095 this.virutualDeploymentUnit.select('image').classed(this.activeNode, false);
1096 this.connectionPoint.select('image').classed(this.activeNode, false);
1097 this.intConnectionPoint.select('image').classed(this.activeNode, false);
1098 }
Barath Kumar R063a3f12020-12-29 16:35:09 +05301099 /** Events handles when to drag using filter for the keys @private */
1100 private dragFilter(): boolean {
1101 return d3.event.ctrlKey && !d3.event.button;
1102 }
kumaran.m3b4814a2020-05-01 19:48:54 +05301103 /** Events handles when dragstarted @private */
1104 private dragstarted(d: COMPOSERNODES): void {
1105 d.fx = d.x;
1106 d.fy = d.y;
1107 }
1108 /** Events handles when dragged @private */
1109 private dragged(d: COMPOSERNODES): void {
1110 d.fx = d.x = d3.event.x;
1111 d.fy = d.y = d3.event.y;
1112 }
1113 /** Events handles when dragended @private */
1114 private dragended(d: COMPOSERNODES): void {
1115 if (this.forceSimulationActive) {
1116 d.fx = null;
1117 d.fy = null;
1118 } else {
1119 d.fx = d.x;
1120 d.fy = d.y;
1121 this.forceSimulationActive = false;
1122 }
1123 }
1124 /** Events handles when node double click @private */
1125 private onNodedblClickToggleSidebar(): void {
1126 this.sideBarOpened = false;
1127 }
1128 /** Events handles when node single click @private */
1129 private onNodeClickToggleSidebar(): void {
1130 this.sideBarOpened = true;
1131 }
1132}