Manage ODU4 services over multiple OTU4
[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.rev210618.optical.renderer.nodes.Nodes;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.NodesBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.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             .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
134         if (atoZDirection.getAToZWavelengthNumber() != null) {
135             servicePathInputBuilder
136                 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
137         }
138         if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
139                 .equals(atoZDirection.getAToZWavelengthNumber())) {
140             scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
141         }
142         if (atoZDirection.getAToZMinFrequency() != null) {
143             servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
144             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
145                     .valueOf(GridUtils
146                             .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
147         }
148         if (atoZDirection.getAToZMaxFrequency() != null) {
149             servicePathInputBuilder.setMaxFreq(new FrequencyTHz(atoZDirection.getAToZMaxFrequency().getValue()));
150             servicePathInputBuilder.setHigherSpectralSlotNumber(
151                     Uint32.valueOf(GridUtils
152                             .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
153         }
154         if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
155             servicePathInputBuilder.setCenterFreq(
156                     GridUtils.getCentralFrequencyWithPrecision(atoZDirection.getAToZMinFrequency().getValue(),
157                             atoZDirection.getAToZMaxFrequency().getValue(), scale));
158         }
159         if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
160             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
161                     .forName(atoZDirection.getModulationFormat());
162             if (optionalModulationFormat.isPresent()
163                     && GridConstant.FREQUENCY_WIDTH_TABLE
164                     .contains(atoZDirection.getRate(), optionalModulationFormat.get())) {
165                 servicePathInputBuilder
166                     .setWidth(FrequencyGHz
167                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
168                         optionalModulationFormat.get())));
169             }
170         }
171         servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
172             .setAEndApiInfo(createAendApiInfo(pathDescription, false))
173             .setZEndApiInfo(createZendApiInfo(pathDescription, false));
174         return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
175     }
176
177     public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
178             PathDescription pathDescription, Action operation) {
179         int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
180         ZToADirection ztoADirection = pathDescription.getZToADirection();
181         LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
182         NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
183         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
184             .setOperation(operation)
185             .setServiceName(serviceName)
186             .setNodes(nodeLists.getRendererNodeList())
187             .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
188         if (ztoADirection.getZToAWavelengthNumber() != null) {
189             servicePathInputBuilder
190                 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
191         }
192         if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
193                 .equals(ztoADirection.getZToAWavelengthNumber())) {
194             scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
195         }
196         if (ztoADirection.getZToAMinFrequency() != null) {
197             servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
198             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
199                     .valueOf(GridUtils
200                             .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
201         }
202         if (ztoADirection.getZToAMaxFrequency() != null) {
203             servicePathInputBuilder.setMaxFreq(new FrequencyTHz(ztoADirection.getZToAMaxFrequency().getValue()));
204             servicePathInputBuilder.setHigherSpectralSlotNumber(
205                     Uint32.valueOf(GridUtils
206                             .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
207         }
208         if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
209             servicePathInputBuilder.setCenterFreq(
210                     GridUtils.getCentralFrequencyWithPrecision(ztoADirection.getZToAMinFrequency().getValue(),
211                             ztoADirection.getZToAMaxFrequency().getValue(), scale));
212         }
213         if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
214             Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
215                     .forName(ztoADirection.getModulationFormat());
216             if (optionalModulationFormat.isPresent()
217                     && GridConstant.FREQUENCY_WIDTH_TABLE
218                     .contains(ztoADirection.getRate(), optionalModulationFormat.get())) {
219                 servicePathInputBuilder.setWidth(FrequencyGHz
220                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
221                                 optionalModulationFormat.get())));
222             }
223         }
224         servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
225             .setAEndApiInfo(createAendApiInfo(pathDescription, false))
226             .setZEndApiInfo(createZendApiInfo(pathDescription, false));
227         return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
228     }
229
230     // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
231     public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
232         String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
233         // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
234         List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.Nodes> nodes =
235             new ArrayList<>();
236         NodeLists nodeLists =
237             (asideToZside)
238             ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
239             : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
240         LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
241         for (Nodes node: nodeLists.getRendererNodeList()) {
242             org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.NodesBuilder nb
243                 = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes
244                     .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
245             if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
246                 nb.setNetwork2Tp(node.getSrcTp());
247             } else {
248                 nb.setClientTp(node.getSrcTp());
249             }
250             nodes.add(nb.build());
251         }
252         OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
253             .setServiceName(serviceName)
254             .setOperation(operation)
255             .setServiceFormat(serviceFormat)
256             .setServiceRate(serviceRate)
257             .setNodes(nodes)
258             .setAEndApiInfo(createAendApiInfo(pathDescription, true))
259             .setZEndApiInfo(createZendApiInfo(pathDescription, true));
260
261         // set the trib-slots and trib-ports for the lower oder odu
262         if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
263             Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
264                 .split("\\.")[0]);
265             Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
266                 .split("\\.")[1]);
267             otnServicePathInputBuilder
268                 .setTribPortNumber(tribPort)
269                 .setTribSlot(minTribSlot);
270         }
271         if (serviceRate.intValue() == 100) {
272             List<OpucnTribSlotDef> opucnTribSlotDefList = new ArrayList<>();
273             opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMinTribSlot());
274             opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMaxTribSlot());
275             otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
276         }
277         return otnServicePathInputBuilder.build();
278     }
279
280     public static ServicePathInput rendererDeleteServiceInput(String serviceName,
281             ServiceDeleteInput serviceDeleteInput) {
282         //TODO: finish model-model mapping
283         return new ServicePathInputBuilder().setServiceName(serviceName).build();
284     }
285
286     public static List<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
287         List<String> linkidList = new ArrayList<>();
288         pathDescription.getAToZDirection().getAToZ().values().stream()
289             .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
290             .forEach(rsc -> {
291                 Link link = (Link) rsc.getResource().getResource();
292                 linkidList.add(link.getLinkId());
293             });
294         pathDescription.getZToADirection().getZToA().values().stream()
295             .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
296             .forEach(rsc -> {
297                 Link link = (Link) rsc.getResource().getResource();
298                 linkidList.add(link.getLinkId());
299             });
300         return linkidList;
301     }
302
303     private static NodeLists getNodesListZtoA(Iterator<ZToA> iterator) {
304         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
305         List<Nodes> olmList = new ArrayList<>();
306         List<Nodes> list = new ArrayList<>();
307
308         while (iterator.hasNext()) {
309             ZToA pathDesObj = iterator.next();
310             try {
311                 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
312             } catch (IllegalArgumentException | SecurityException e) {
313                 //TODO: Auto-generated catch block
314                 LOG.error("Did not find the getResource method", e);
315             }
316         }
317         populateNodeLists(treeMap, list, olmList, false);
318         return new NodeLists(olmList, list);
319     }
320
321     private static NodeLists getNodesListAToZ(Iterator<AToZ> iterator) {
322         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
323         List<Nodes> list = new ArrayList<>();
324         List<Nodes> olmList = new ArrayList<>();
325
326         while (iterator.hasNext()) {
327             AToZ pathDesObj = iterator.next();
328             try {
329                 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
330             } catch (IllegalArgumentException | SecurityException e) {
331                 //TODO: Auto-generated catch block
332                 LOG.error("Did not find the getResource method", e);
333             }
334         }
335         populateNodeLists(treeMap, list, olmList, true);
336         return new NodeLists(olmList, list);
337     }
338
339     private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
340             String direction) {
341         String resourceType = rsrc.implementedInterface().getSimpleName();
342         LOG.info("Inside {} {}", direction, resourceType);
343         switch (resourceType) {
344             case TERMINATION_POINT:
345                 TerminationPoint tp = (TerminationPoint) rsrc;
346                 LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
347                 String tpID = tp.getTpId();
348
349                 //TODO: do not rely on ID to be in certain format
350                 if (tpID.contains("CTP") || tpID.contains("CP")) {
351                     return;
352                 }
353                 String nodeID = "";
354                 if (tpID.contains(StringConstants.TTP_TOKEN)) {
355                     nodeID = tp.getTpNodeId().split("-DEG")[0];
356                 } else if (tpID.contains(StringConstants.PP_TOKEN)) {
357                     nodeID = tp.getTpNodeId().split("-SRG")[0];
358                 } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
359                         || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
360                     nodeID = tp.getTpNodeId().split("-XPDR")[0];
361                 } else {
362                     return;
363                 }
364                 int id = Integer.parseInt(sortId);
365                 treeMap.put(id, new NodeIdPair(nodeID, tpID));
366                 return;
367             case LINK:
368                 LOG.info("The type is link");
369                 return;
370             default:
371                 LOG.info("The type is not identified: {}", resourceType);
372                 return;
373         }
374     }
375
376     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
377         value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
378         justification = "loop when value is not always null - "
379                 + "TODO: check if something exists in Java lib")
380     private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
381             boolean isAToz) {
382         String desID = null;
383         String srcID = null;
384         LOG.info("treeMap values = {}", treeMap.values());
385         for (NodeIdPair values : treeMap.values()) {
386             if (srcID == null) {
387                 srcID = values.getTpID();
388             } else if (desID == null) {
389                 desID = values.getTpID();
390                 NodesBuilder olmNb = new NodesBuilder()
391                     .setNodeId(values.getNodeID())
392                     .setDestTp(desID)
393                     .setSrcTp(srcID);
394                 olmList.add(olmNb.build());
395                 if (srcID.isEmpty()) {
396                     srcID = null;
397                 }
398                 if (desID.isEmpty()) {
399                     desID = new StringBuilder(srcID).toString();
400                     srcID = null;
401                 }
402                 if (isAToz) {
403                     NodesBuilder nb = new NodesBuilder()
404                         .withKey(new NodesKey(values.getNodeID()))
405                         .setDestTp(desID)
406                         .setSrcTp(srcID);
407                     if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
408                         nb.setDestTp(srcID).setSrcTp(desID);
409                     }
410                     list.add(nb.build());
411                 } else {
412                     if (srcID != null && desID != null && !srcID.contains(StringConstants.NETWORK_TOKEN)
413                         && !desID.contains(StringConstants.NETWORK_TOKEN)) {
414                         NodesBuilder nb = new NodesBuilder()
415                             .withKey(new NodesKey(values.getNodeID()))
416                             .setDestTp(desID)
417                             .setSrcTp(srcID);
418                         list.add(nb.build());
419                     }
420                 }
421                 srcID = null;
422                 desID = null;
423             } else {
424                 LOG.warn("both, the source and destination id are not null!");
425             }
426         }
427     }
428
429     private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
430         String anodeId = null;
431         String sapi = null;
432         String dapi = null;
433         if (isForOtn) {
434             anodeId = extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId");
435             sapi = PortMappingUtils.fnv1size64(
436                 String.join("-", anodeId, extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
437             dapi = PortMappingUtils.fnv1size64(
438                 String.join("-", extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
439                     extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
440         } else {
441             anodeId = extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId");
442             sapi = PortMappingUtils.fnv1size64(
443                 String.join("-", anodeId, extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
444             dapi = PortMappingUtils.fnv1size64(
445                 String.join("-", extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
446                     extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
447         }
448         return new AEndApiInfoBuilder()
449             .setSapi(sapi)
450             .setExpectedDapi(sapi)
451             .setDapi(dapi)
452             .setExpectedSapi(dapi)
453             .setNodeId(anodeId)
454             .build();
455     }
456
457     private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
458         String znodeId = null;
459         String sapi = null;
460         String dapi = null;
461         if (isForOtn) {
462             znodeId = extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId");
463             sapi = PortMappingUtils.fnv1size64(
464                 String.join("-", znodeId, extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
465             dapi = PortMappingUtils.fnv1size64(
466                 String.join("-", extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
467                     extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
468         } else {
469             znodeId = extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId");
470             sapi = PortMappingUtils.fnv1size64(
471                 String.join("-", znodeId, extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
472             dapi = PortMappingUtils.fnv1size64(
473                 String.join("-", extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
474                     extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
475         }
476         return new ZEndApiInfoBuilder()
477             .setSapi(sapi)
478             .setExpectedDapi(sapi)
479             .setDapi(dapi)
480             .setExpectedSapi(dapi)
481             .setNodeId(znodeId)
482             .build();
483     }
484
485     private static Map<String, String> extractAendFromPathDescriptionForOtn(PathDescription pathDescription) {
486         List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
487             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
488             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
489                 .getSimpleName()))
490             .collect(Collectors.toList());
491         for (AToZ atoZ : tpList) {
492             TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
493             if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
494                 String nodeId = tp.getTpNodeId();
495                 String lcp = tp.getTpId();
496                 return Map.of("nodeId", nodeId, "tpid", lcp);
497             }
498         }
499         return null;
500     }
501
502     private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
503         List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
504             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
505             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
506                 .getSimpleName()))
507             .collect(Collectors.toList());
508         for (ZToA ztoA : tpList) {
509             TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
510             if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
511                 String nodeId = tp.getTpNodeId();
512                 String lcp = tp.getTpId();
513                 return Map.of("nodeId", nodeId, "tpid", lcp);
514             }
515         }
516         return null;
517     }
518
519     private static Map<String, String> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
520         List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
521             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
522             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
523                 .getSimpleName()))
524             .collect(Collectors.toList());
525         for (AToZ atoZ : tpList) {
526             TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
527             if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
528 //                String nodeId = tp.getTpNodeId();
529 //                String lcp = tp.getTpId();
530                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
531             }
532         }
533         return null;
534     }
535
536     private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
537         List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
538             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
539             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
540                 .getSimpleName()))
541             .collect(Collectors.toList());
542         for (ZToA ztoA : tpList) {
543             TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
544             if (!tp.getTpId().contains("CLIENT")  && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
545 //                String nodeId = tp.getTpNodeId();
546 //                String lcp = tp.getTpId();
547                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
548             }
549         }
550         return null;
551     }
552 }