Power control support for 87.5GHz spectrum width
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / ModelMappingUtils.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.renderer;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.Optional;
16 import java.util.TreeMap;
17 import java.util.stream.Collectors;
18 import org.opendaylight.transportpce.common.NodeIdPair;
19 import org.opendaylight.transportpce.common.StringConstants;
20 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
21 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
22 import org.opendaylight.transportpce.common.mapping.PortMappingUtils;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.Action;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInputBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInputBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfoBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfoBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInputBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutputBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
46 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
47 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.Resource;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.Link;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
54 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.Nodes;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.NodesBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.NodesKey;
57 import org.opendaylight.yangtools.yang.common.RpcResult;
58 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
59 import org.opendaylight.yangtools.yang.common.Uint32;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
62
63
64 public final class ModelMappingUtils {
65
66     private static final Logger LOG = LoggerFactory.getLogger(ModelMappingUtils.class);
67     private static final String TERMINATION_POINT = "TerminationPoint";
68     private static final String LINK = "Link";
69
70     private ModelMappingUtils() {
71     }
72
73     public static ServicePowerSetupInput createServicePowerSetupInput(List<Nodes> olmList,
74             ServiceImplementationRequestInput input) {
75         ServicePowerSetupInputBuilder olmSetupBldr = new ServicePowerSetupInputBuilder().setNodes(olmList);
76         if (input != null && input.getPathDescription() != null
77                 && input.getPathDescription().getAToZDirection() != null) {
78             AToZDirection atoZDirection = input.getPathDescription().getAToZDirection();
79             olmSetupBldr.setWaveNumber(atoZDirection.getAToZWavelengthNumber());
80             if (atoZDirection.getAToZMinFrequency() != null) {
81                 olmSetupBldr.setLowerSpectralSlotNumber(Uint32
82                         .valueOf(GridUtils
83                                 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
84             }
85             if (atoZDirection.getAToZMaxFrequency() != null) {
86                 olmSetupBldr.setHigherSpectralSlotNumber(Uint32
87                         .valueOf(GridUtils
88                                 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
89             }
90         }
91         return olmSetupBldr.build();
92     }
93
94     public static ServiceImplementationRequestOutput createServiceImplResponse(String responseCode, String message) {
95         return new ServiceImplementationRequestOutputBuilder()
96                 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
97                 .build();
98     }
99
100     public static ServiceDeleteOutput createServiceDeleteResponse(String responseCode, String message) {
101         return new ServiceDeleteOutputBuilder()
102                 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
103                 .build();
104     }
105
106     public static ConfigurationResponseCommon createCommonResponse(String responseCode, String message) {
107         return new ConfigurationResponseCommonBuilder()
108                 .setResponseMessage(message)
109                 .setResponseCode(responseCode)
110                 .build();
111     }
112
113     public static ListenableFuture<RpcResult<ServiceImplementationRequestOutput>>
114             createServiceImplementationRpcResponse(ServiceImplementationRequestOutput payload) {
115         return RpcResultBuilder.success(payload).buildFuture();
116     }
117
118     public static ListenableFuture<RpcResult<ServiceDeleteOutput>>
119             createServiceDeleteRpcResponse(ServiceDeleteOutput payload) {
120         return RpcResultBuilder.success(payload).buildFuture();
121     }
122
123     public static ServicePathInputData rendererCreateServiceInputAToZ(String serviceName,
124             PathDescription pathDescription, Action operation) {
125         int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
126         AToZDirection atoZDirection = pathDescription.getAToZDirection();
127         LOG.info("Building ServicePathInputData for a to z direction {}", atoZDirection);
128         NodeLists nodeLists = getNodesListAToZ(atoZDirection.nonnullAToZ().values().iterator());
129         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
130             .setServiceName(serviceName)
131             .setOperation(operation)
132             .setNodes(nodeLists.getRendererNodeList())
133             .setNmcWidth(new FrequencyGHz(GridConstant.WIDTH_40))
134             .setMcWidth(new FrequencyGHz(pathDescription.getAToZDirection().getAToZMaxFrequency().getValue()
135                        .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue())));
136         if (atoZDirection.getAToZWavelengthNumber() != null) {
137             servicePathInputBuilder
138                 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
139         }
140         if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
141                 .equals(atoZDirection.getAToZWavelengthNumber())) {
142             scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
143         }
144         if (atoZDirection.getAToZMinFrequency() != null) {
145             servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
146             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
147                     .valueOf(GridUtils
148                             .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
149         }
150         if (atoZDirection.getAToZMaxFrequency() != null) {
151             servicePathInputBuilder.setMaxFreq(new FrequencyTHz(atoZDirection.getAToZMaxFrequency().getValue()));
152             servicePathInputBuilder.setHigherSpectralSlotNumber(
153                     Uint32.valueOf(GridUtils
154                             .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
155         }
156         if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
157             servicePathInputBuilder.setCenterFreq(
158                     GridUtils.getCentralFrequencyWithPrecision(atoZDirection.getAToZMinFrequency().getValue(),
159                             atoZDirection.getAToZMaxFrequency().getValue(), scale));
160         }
161         if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
162             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
163                     .forName(atoZDirection.getModulationFormat());
164             if (optionalModulationFormat.isPresent()
165                     && GridConstant.FREQUENCY_WIDTH_TABLE
166                     .contains(atoZDirection.getRate(), optionalModulationFormat.get())) {
167                 servicePathInputBuilder
168                     .setNmcWidth(FrequencyGHz
169                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
170                         optionalModulationFormat.get())));
171             }
172         }
173         servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
174             .setAEndApiInfo(createAendApiInfo(pathDescription, false))
175             .setZEndApiInfo(createZendApiInfo(pathDescription, false));
176         return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
177     }
178
179     public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
180             PathDescription pathDescription, Action operation) {
181         int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
182         ZToADirection ztoADirection = pathDescription.getZToADirection();
183         LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
184         NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
185         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
186             .setOperation(operation)
187             .setServiceName(serviceName)
188             .setNodes(nodeLists.getRendererNodeList())
189             .setNmcWidth(new FrequencyGHz(GridConstant.WIDTH_40))
190             .setMcWidth(new FrequencyGHz(pathDescription.getAToZDirection().getAToZMaxFrequency().getValue()
191                         .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue())));
192         if (ztoADirection.getZToAWavelengthNumber() != null) {
193             servicePathInputBuilder
194                 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
195         }
196         if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
197                 .equals(ztoADirection.getZToAWavelengthNumber())) {
198             scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
199         }
200         if (ztoADirection.getZToAMinFrequency() != null) {
201             servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
202             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
203                     .valueOf(GridUtils
204                             .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
205         }
206         if (ztoADirection.getZToAMaxFrequency() != null) {
207             servicePathInputBuilder.setMaxFreq(new FrequencyTHz(ztoADirection.getZToAMaxFrequency().getValue()));
208             servicePathInputBuilder.setHigherSpectralSlotNumber(
209                     Uint32.valueOf(GridUtils
210                             .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
211         }
212         if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
213             servicePathInputBuilder.setCenterFreq(
214                     GridUtils.getCentralFrequencyWithPrecision(ztoADirection.getZToAMinFrequency().getValue(),
215                             ztoADirection.getZToAMaxFrequency().getValue(), scale));
216         }
217         if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
218             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
219                     .forName(ztoADirection.getModulationFormat());
220             if (optionalModulationFormat.isPresent()
221                     && GridConstant.FREQUENCY_WIDTH_TABLE
222                     .contains(ztoADirection.getRate(), optionalModulationFormat.get())) {
223                 servicePathInputBuilder.setNmcWidth(FrequencyGHz
224                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
225                                 optionalModulationFormat.get())));
226             }
227         }
228         servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
229             .setAEndApiInfo(createAendApiInfo(pathDescription, false))
230             .setZEndApiInfo(createZendApiInfo(pathDescription, false));
231         return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
232     }
233
234     // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
235     public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
236         String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
237         // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
238         List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.Nodes> nodes =
239             new ArrayList<>();
240         NodeLists nodeLists =
241             (asideToZside)
242             ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
243             : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
244         LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
245         for (Nodes node: nodeLists.getRendererNodeList()) {
246             org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.NodesBuilder nb
247                 = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes
248                     .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
249             if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
250                 nb.setNetwork2Tp(node.getSrcTp());
251             } else {
252                 nb.setClientTp(node.getSrcTp());
253             }
254             nodes.add(nb.build());
255         }
256         OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
257             .setServiceName(serviceName)
258             .setOperation(operation)
259             .setServiceFormat(serviceFormat)
260             .setServiceRate(serviceRate)
261             .setNodes(nodes)
262             .setAEndApiInfo(createAendApiInfo(pathDescription, true))
263             .setZEndApiInfo(createZendApiInfo(pathDescription, true));
264
265         // set the trib-slots and trib-ports for the lower oder odu
266         if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
267             Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
268                 .split("\\.")[0]);
269             Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
270                 .split("\\.")[1]);
271             otnServicePathInputBuilder
272                 .setTribPortNumber(tribPort)
273                 .setTribSlot(minTribSlot);
274         }
275         if (serviceRate.intValue() == 100) {
276             List<OpucnTribSlotDef> opucnTribSlotDefList = new ArrayList<>();
277             opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMinTribSlot());
278             opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMaxTribSlot());
279             otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
280         }
281         return otnServicePathInputBuilder.build();
282     }
283
284     public static ServicePathInput rendererDeleteServiceInput(String serviceName,
285             ServiceDeleteInput serviceDeleteInput) {
286         //TODO: finish model-model mapping
287         return new ServicePathInputBuilder().setServiceName(serviceName).build();
288     }
289
290     public static List<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
291         List<String> linkidList = new ArrayList<>();
292         pathDescription.getAToZDirection().getAToZ().values().stream()
293             .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
294             .forEach(rsc -> {
295                 Link link = (Link) rsc.getResource().getResource();
296                 linkidList.add(link.getLinkId());
297             });
298         pathDescription.getZToADirection().getZToA().values().stream()
299             .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
300             .forEach(rsc -> {
301                 Link link = (Link) rsc.getResource().getResource();
302                 linkidList.add(link.getLinkId());
303             });
304         return linkidList;
305     }
306
307     private static NodeLists getNodesListZtoA(Iterator<ZToA> iterator) {
308         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
309         List<Nodes> olmList = new ArrayList<>();
310         List<Nodes> list = new ArrayList<>();
311
312         while (iterator.hasNext()) {
313             ZToA pathDesObj = iterator.next();
314             try {
315                 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
316             } catch (IllegalArgumentException | SecurityException e) {
317                 //TODO: Auto-generated catch block
318                 LOG.error("Did not find the getResource method", e);
319             }
320         }
321         populateNodeLists(treeMap, list, olmList, false);
322         return new NodeLists(olmList, list);
323     }
324
325     private static NodeLists getNodesListAToZ(Iterator<AToZ> iterator) {
326         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
327         List<Nodes> list = new ArrayList<>();
328         List<Nodes> olmList = new ArrayList<>();
329
330         while (iterator.hasNext()) {
331             AToZ pathDesObj = iterator.next();
332             try {
333                 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
334             } catch (IllegalArgumentException | SecurityException e) {
335                 //TODO: Auto-generated catch block
336                 LOG.error("Did not find the getResource method", e);
337             }
338         }
339         populateNodeLists(treeMap, list, olmList, true);
340         return new NodeLists(olmList, list);
341     }
342
343     private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
344             String direction) {
345         String resourceType = rsrc.implementedInterface().getSimpleName();
346         LOG.info("Inside {} {}", direction, resourceType);
347         switch (resourceType) {
348             case TERMINATION_POINT:
349                 TerminationPoint tp = (TerminationPoint) rsrc;
350                 LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
351                 String tpID = tp.getTpId();
352
353                 //TODO: do not rely on ID to be in certain format
354                 if (tpID.contains("CTP") || tpID.contains("CP")) {
355                     return;
356                 }
357                 String nodeID = "";
358                 if (tpID.contains(StringConstants.TTP_TOKEN)) {
359                     nodeID = tp.getTpNodeId().split("-DEG")[0];
360                 } else if (tpID.contains(StringConstants.PP_TOKEN)) {
361                     nodeID = tp.getTpNodeId().split("-SRG")[0];
362                 } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
363                         || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
364                     nodeID = tp.getTpNodeId().split("-XPDR")[0];
365                 } else {
366                     return;
367                 }
368                 int id = Integer.parseInt(sortId);
369                 treeMap.put(id, new NodeIdPair(nodeID, tpID));
370                 return;
371             case LINK:
372                 LOG.info("The type is link");
373                 return;
374             default:
375                 LOG.info("The type is not identified: {}", resourceType);
376                 return;
377         }
378     }
379
380     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
381         value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
382         justification = "loop when value is not always null - "
383                 + "TODO: check if something exists in Java lib")
384     private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
385             boolean isAToz) {
386         String desID = null;
387         String srcID = null;
388         LOG.info("treeMap values = {}", treeMap.values());
389         for (NodeIdPair values : treeMap.values()) {
390             if (srcID == null) {
391                 srcID = values.getTpID();
392             } else if (desID == null) {
393                 desID = values.getTpID();
394                 NodesBuilder olmNb = new NodesBuilder()
395                     .setNodeId(values.getNodeID())
396                     .setDestTp(desID)
397                     .setSrcTp(srcID);
398                 olmList.add(olmNb.build());
399                 if (srcID.isEmpty()) {
400                     srcID = null;
401                 }
402                 if (desID.isEmpty()) {
403                     desID = new StringBuilder(srcID).toString();
404                     srcID = null;
405                 }
406                 if (isAToz) {
407                     NodesBuilder nb = new NodesBuilder()
408                         .withKey(new NodesKey(values.getNodeID()))
409                         .setDestTp(desID)
410                         .setSrcTp(srcID);
411                     if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
412                         nb.setDestTp(srcID).setSrcTp(desID);
413                     }
414                     list.add(nb.build());
415                 } else {
416                     if (srcID != null && desID != null && !srcID.contains(StringConstants.NETWORK_TOKEN)
417                         && !desID.contains(StringConstants.NETWORK_TOKEN)) {
418                         NodesBuilder nb = new NodesBuilder()
419                             .withKey(new NodesKey(values.getNodeID()))
420                             .setDestTp(desID)
421                             .setSrcTp(srcID);
422                         list.add(nb.build());
423                     }
424                 }
425                 srcID = null;
426                 desID = null;
427             } else {
428                 LOG.warn("both, the source and destination id are not null!");
429             }
430         }
431     }
432
433     private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
434         String anodeId = null;
435         String sapi = null;
436         String dapi = null;
437         if (isForOtn) {
438             anodeId = extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId");
439             sapi = PortMappingUtils.fnv1size64(
440                 String.join("-", anodeId, extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
441             dapi = PortMappingUtils.fnv1size64(
442                 String.join("-", extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
443                     extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
444         } else {
445             anodeId = extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId");
446             sapi = PortMappingUtils.fnv1size64(
447                 String.join("-", anodeId, extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
448             dapi = PortMappingUtils.fnv1size64(
449                 String.join("-", extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
450                     extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
451         }
452         return new AEndApiInfoBuilder()
453             .setSapi(sapi)
454             .setExpectedDapi(sapi)
455             .setDapi(dapi)
456             .setExpectedSapi(dapi)
457             .setNodeId(anodeId)
458             .build();
459     }
460
461     private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
462         String znodeId = null;
463         String sapi = null;
464         String dapi = null;
465         if (isForOtn) {
466             znodeId = extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId");
467             sapi = PortMappingUtils.fnv1size64(
468                 String.join("-", znodeId, extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
469             dapi = PortMappingUtils.fnv1size64(
470                 String.join("-", extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
471                     extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
472         } else {
473             znodeId = extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId");
474             sapi = PortMappingUtils.fnv1size64(
475                 String.join("-", znodeId, extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
476             dapi = PortMappingUtils.fnv1size64(
477                 String.join("-", extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
478                     extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
479         }
480         return new ZEndApiInfoBuilder()
481             .setSapi(sapi)
482             .setExpectedDapi(sapi)
483             .setDapi(dapi)
484             .setExpectedSapi(dapi)
485             .setNodeId(znodeId)
486             .build();
487     }
488
489     private static Map<String, String> extractAendFromPathDescriptionForOtn(PathDescription pathDescription) {
490         List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
491             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
492             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
493                 .getSimpleName()))
494             .collect(Collectors.toList());
495         for (AToZ atoZ : tpList) {
496             TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
497             if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
498                 String nodeId = tp.getTpNodeId();
499                 String lcp = tp.getTpId();
500                 return Map.of("nodeId", nodeId, "tpid", lcp);
501             }
502         }
503         return Map.of();
504     }
505
506     private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
507         List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
508             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
509             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
510                 .getSimpleName()))
511             .collect(Collectors.toList());
512         for (ZToA ztoA : tpList) {
513             TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
514             if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
515                 String nodeId = tp.getTpNodeId();
516                 String lcp = tp.getTpId();
517                 return Map.of("nodeId", nodeId, "tpid", lcp);
518             }
519         }
520         return Map.of();
521     }
522
523     private static Map<String, String> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
524         List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
525             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
526             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
527                 .getSimpleName()))
528             .collect(Collectors.toList());
529         for (AToZ atoZ : tpList) {
530             TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
531             if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
532 //                String nodeId = tp.getTpNodeId();
533 //                String lcp = tp.getTpId();
534                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
535             }
536         }
537         return Map.of();
538     }
539
540     private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
541         List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
542             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
543             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
544                 .getSimpleName()))
545             .collect(Collectors.toList());
546         for (ZToA ztoA : tpList) {
547             TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
548             if (!tp.getTpId().contains("CLIENT")  && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
549 //                String nodeId = tp.getTpNodeId();
550 //                String lcp = tp.getTpId();
551                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
552             }
553         }
554         return Map.of();
555     }
556 }