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