2 * Copyright © 2017 AT&T and others. All rights reserved.
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
8 package org.opendaylight.transportpce.renderer;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.math.BigDecimal;
13 import java.util.ArrayList;
14 import java.util.HashSet;
15 import java.util.Iterator;
16 import java.util.List;
19 import java.util.TreeMap;
20 import java.util.stream.Collectors;
21 import org.opendaylight.transportpce.common.NodeIdPair;
22 import org.opendaylight.transportpce.common.StringConstants;
23 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
24 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
25 import org.opendaylight.transportpce.common.mapping.PortMappingUtils;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.Action;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInputBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInputBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfoBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfoBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInputBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutputBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OpucnTribSlotDef;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInput;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.PathDescription;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirection;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirection;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToA;
54 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.Resource;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.Link;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPoint;
57 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.Nodes;
58 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.NodesBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.NodesKey;
60 import org.opendaylight.yangtools.yang.common.Decimal64;
61 import org.opendaylight.yangtools.yang.common.RpcResult;
62 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
63 import org.opendaylight.yangtools.yang.common.Uint32;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
68 public final class ModelMappingUtils {
70 private static final Logger LOG = LoggerFactory.getLogger(ModelMappingUtils.class);
71 private static final String TERMINATION_POINT = "TerminationPoint";
72 private static final String LINK = "Link";
74 private ModelMappingUtils() {
77 public static ServicePowerSetupInput createServicePowerSetupInput(List<Nodes> olmList,
78 ServiceImplementationRequestInput input) {
79 ServicePowerSetupInputBuilder olmSetupBldr = new ServicePowerSetupInputBuilder().setNodes(olmList);
80 if (input != null && input.getPathDescription() != null
81 && input.getPathDescription().getAToZDirection() != null) {
82 AToZDirection atoZDirection = input.getPathDescription().getAToZDirection();
83 olmSetupBldr.setWaveNumber(atoZDirection.getAToZWavelengthNumber());
84 if (atoZDirection.getAToZMinFrequency() != null) {
85 olmSetupBldr.setLowerSpectralSlotNumber(Uint32
87 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
89 if (atoZDirection.getAToZMaxFrequency() != null) {
90 olmSetupBldr.setHigherSpectralSlotNumber(Uint32
92 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
94 // Set the MC-width for the OLM
95 olmSetupBldr.setMcWidth(new FrequencyGHz(Decimal64.valueOf(
96 atoZDirection.getAToZMaxFrequency().getValue().decimalValue()
97 .subtract(atoZDirection.getAToZMinFrequency().getValue().decimalValue())
98 .multiply(new BigDecimal(1000)))));
100 return olmSetupBldr.build();
103 public static ServiceImplementationRequestOutput createServiceImplResponse(String responseCode, String message) {
104 return new ServiceImplementationRequestOutputBuilder()
105 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
109 public static ServiceDeleteOutput createServiceDeleteResponse(String responseCode, String message) {
110 return new ServiceDeleteOutputBuilder()
111 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
115 public static ConfigurationResponseCommon createCommonResponse(String responseCode, String message) {
116 return new ConfigurationResponseCommonBuilder()
117 .setResponseMessage(message)
118 .setResponseCode(responseCode)
122 public static ListenableFuture<RpcResult<ServiceImplementationRequestOutput>>
123 createServiceImplementationRpcResponse(ServiceImplementationRequestOutput payload) {
124 return RpcResultBuilder.success(payload).buildFuture();
127 public static ListenableFuture<RpcResult<ServiceDeleteOutput>>
128 createServiceDeleteRpcResponse(ServiceDeleteOutput payload) {
129 return RpcResultBuilder.success(payload).buildFuture();
132 public static ServicePathInputData rendererCreateServiceInputAToZ(String serviceName,
133 PathDescription pathDescription, Action operation) {
134 int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
135 AToZDirection atoZDirection = pathDescription.getAToZDirection();
136 LOG.info("Building ServicePathInputData for a to z direction {}", atoZDirection);
137 NodeLists nodeLists = getNodesListAToZ(atoZDirection.nonnullAToZ().values().iterator());
138 ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
139 .setServiceName(serviceName)
140 .setOperation(operation)
141 .setNodes(nodeLists.getRendererNodeList())
142 .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
143 .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
144 pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
145 .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
146 if (atoZDirection.getAToZWavelengthNumber() != null) {
147 servicePathInputBuilder
148 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
150 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
151 .equals(atoZDirection.getAToZWavelengthNumber())) {
152 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
154 if (atoZDirection.getAToZMinFrequency() != null) {
155 servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
156 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
158 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
160 if (atoZDirection.getAToZMaxFrequency() != null) {
161 servicePathInputBuilder.setMaxFreq(new FrequencyTHz(atoZDirection.getAToZMaxFrequency().getValue()));
162 servicePathInputBuilder.setHigherSpectralSlotNumber(
163 Uint32.valueOf(GridUtils
164 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
166 if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
167 servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
168 atoZDirection.getAToZMinFrequency().getValue().decimalValue(),
169 atoZDirection.getAToZMaxFrequency().getValue().decimalValue(),
172 if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
173 ModulationFormat modulationFormat = ModulationFormat.forName(atoZDirection.getModulationFormat());
174 if (modulationFormat != null
175 && GridConstant.FREQUENCY_WIDTH_TABLE
176 .contains(atoZDirection.getRate(), modulationFormat)) {
177 servicePathInputBuilder
178 .setNmcWidth(FrequencyGHz
179 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
183 servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
184 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
185 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
186 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
189 public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
190 PathDescription pathDescription, Action operation) {
191 int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
192 ZToADirection ztoADirection = pathDescription.getZToADirection();
193 LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
194 NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
195 ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
196 .setOperation(operation)
197 .setServiceName(serviceName)
198 .setNodes(nodeLists.getRendererNodeList())
199 .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
200 .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
201 pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
202 .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
203 if (ztoADirection.getZToAWavelengthNumber() != null) {
204 servicePathInputBuilder
205 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
207 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
208 .equals(ztoADirection.getZToAWavelengthNumber())) {
209 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
211 if (ztoADirection.getZToAMinFrequency() != null) {
212 servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
213 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
215 .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
217 if (ztoADirection.getZToAMaxFrequency() != null) {
218 servicePathInputBuilder.setMaxFreq(new FrequencyTHz(ztoADirection.getZToAMaxFrequency().getValue()));
219 servicePathInputBuilder.setHigherSpectralSlotNumber(
220 Uint32.valueOf(GridUtils
221 .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
223 if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
224 servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
225 ztoADirection.getZToAMinFrequency().getValue().decimalValue(),
226 ztoADirection.getZToAMaxFrequency().getValue().decimalValue(),
229 if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
230 ModulationFormat modulationFormat = ModulationFormat.forName(ztoADirection.getModulationFormat());
231 if (modulationFormat != null
232 && GridConstant.FREQUENCY_WIDTH_TABLE
233 .contains(ztoADirection.getRate(), modulationFormat)) {
234 servicePathInputBuilder.setNmcWidth(FrequencyGHz
235 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
239 servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
240 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
241 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
242 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
245 // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
246 public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
247 String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
248 // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
249 List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.otn.renderer.nodes.Nodes> nodes =
251 NodeLists nodeLists =
253 ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
254 : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
255 LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
256 for (Nodes node: nodeLists.getRendererNodeList()) {
257 org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.otn.renderer.nodes.NodesBuilder nb
258 = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.otn.renderer.nodes
259 .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
260 if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
261 nb.setNetwork2Tp(node.getSrcTp());
263 nb.setClientTp(node.getSrcTp());
265 nodes.add(nb.build());
267 OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
268 .setServiceName(serviceName)
269 .setOperation(operation)
270 .setServiceFormat(serviceFormat)
271 .setServiceRate(serviceRate)
273 .setAEndApiInfo(createAendApiInfo(pathDescription, true))
274 .setZEndApiInfo(createZendApiInfo(pathDescription, true));
276 // set the trib-slots and trib-ports for the lower oder odu
277 if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
278 Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
280 Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
282 otnServicePathInputBuilder
283 .setTribPortNumber(tribPort)
284 .setTribSlot(minTribSlot);
286 if (serviceRate.intValue() == 100 && pathDescription.getAToZDirection().getMinTribSlot() != null
287 && pathDescription.getAToZDirection().getMaxTribSlot() != null) {
288 Set<OpucnTribSlotDef> opucnTribSlotDefList = new HashSet<>();
289 opucnTribSlotDefList.add(
290 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMinTribSlot().getValue()));
291 opucnTribSlotDefList.add(
292 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMaxTribSlot().getValue()));
293 otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
295 return otnServicePathInputBuilder.build();
298 public static ServicePathInput rendererDeleteServiceInput(String serviceName,
299 ServiceDeleteInput serviceDeleteInput) {
300 //TODO: finish model-model mapping
301 return new ServicePathInputBuilder().setServiceName(serviceName).build();
304 public static Set<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
305 Set<String> linkidList = new HashSet<>();
306 pathDescription.getAToZDirection().getAToZ().values().stream()
307 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
309 Link link = (Link) rsc.getResource().getResource();
310 linkidList.add(link.getLinkId());
312 pathDescription.getZToADirection().getZToA().values().stream()
313 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
315 Link link = (Link) rsc.getResource().getResource();
316 linkidList.add(link.getLinkId());
321 private static NodeLists getNodesListZtoA(Iterator<ZToA> iterator) {
322 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
323 List<Nodes> olmList = new ArrayList<>();
324 List<Nodes> list = new ArrayList<>();
326 while (iterator.hasNext()) {
327 ZToA pathDesObj = iterator.next();
329 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
330 } catch (IllegalArgumentException | SecurityException e) {
331 //TODO: Auto-generated catch block
332 LOG.error("Did not find the getResource method", e);
335 populateNodeLists(treeMap, list, olmList, false);
336 return new NodeLists(olmList, list);
339 private static NodeLists getNodesListAToZ(Iterator<AToZ> iterator) {
340 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
341 List<Nodes> list = new ArrayList<>();
342 List<Nodes> olmList = new ArrayList<>();
344 while (iterator.hasNext()) {
345 AToZ pathDesObj = iterator.next();
347 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
348 } catch (IllegalArgumentException | SecurityException e) {
349 //TODO: Auto-generated catch block
350 LOG.error("Did not find the getResource method", e);
353 populateNodeLists(treeMap, list, olmList, true);
354 return new NodeLists(olmList, list);
357 private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
359 String resourceType = rsrc.implementedInterface().getSimpleName();
360 LOG.info("Inside {} {}", direction, resourceType);
361 switch (resourceType) {
362 case TERMINATION_POINT:
363 TerminationPoint tp = (TerminationPoint) rsrc;
364 LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
365 String tpID = tp.getTpId();
367 //TODO: do not rely on ID to be in certain format
368 if (tpID.contains("CTP") || tpID.contains("CP")) {
372 if (tpID.contains(StringConstants.TTP_TOKEN)) {
373 nodeID = tp.getTpNodeId().split("-DEG")[0];
374 } else if (tpID.contains(StringConstants.PP_TOKEN)) {
375 nodeID = tp.getTpNodeId().split("-SRG")[0];
376 } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
377 || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
378 nodeID = tp.getTpNodeId().split("-XPDR")[0];
382 int id = Integer.parseInt(sortId);
383 treeMap.put(id, new NodeIdPair(nodeID, tpID));
386 LOG.info("The type is link");
389 LOG.info("The type is not identified: {}", resourceType);
395 value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
396 justification = "loop when value is not always null - "
397 + "TODO: check if something exists in Java lib")
398 private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
402 LOG.info("treeMap values = {}", treeMap.values());
403 for (NodeIdPair values : treeMap.values()) {
405 srcID = values.getTpID();
406 } else if (desID == null) {
407 desID = values.getTpID();
408 NodesBuilder olmNb = new NodesBuilder()
409 .setNodeId(values.getNodeID())
412 olmList.add(olmNb.build());
413 if (srcID.isEmpty()) {
416 if (desID.isEmpty()) {
417 desID = new StringBuilder(srcID).toString();
421 NodesBuilder nb = new NodesBuilder()
422 .withKey(new NodesKey(values.getNodeID()))
425 if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
426 nb.setDestTp(srcID).setSrcTp(desID);
428 list.add(nb.build());
430 if (srcID != null && desID != null && !srcID.contains(StringConstants.NETWORK_TOKEN)
431 && !desID.contains(StringConstants.NETWORK_TOKEN)) {
432 NodesBuilder nb = new NodesBuilder()
433 .withKey(new NodesKey(values.getNodeID()))
436 list.add(nb.build());
442 LOG.warn("both, the source and destination id are not null!");
447 private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
448 String anodeId = null;
452 anodeId = extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId");
453 sapi = PortMappingUtils.fnv1size64(
454 String.join("-", anodeId, extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
455 dapi = PortMappingUtils.fnv1size64(
456 String.join("-", extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
457 extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
459 anodeId = extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId");
460 sapi = PortMappingUtils.fnv1size64(
461 String.join("-", anodeId, extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
462 dapi = PortMappingUtils.fnv1size64(
463 String.join("-", extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
464 extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
466 return new AEndApiInfoBuilder()
468 .setExpectedDapi(sapi)
470 .setExpectedSapi(dapi)
475 private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
476 String znodeId = null;
480 znodeId = extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId");
481 sapi = PortMappingUtils.fnv1size64(
482 String.join("-", znodeId, extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
483 dapi = PortMappingUtils.fnv1size64(
484 String.join("-", extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
485 extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
487 znodeId = extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId");
488 sapi = PortMappingUtils.fnv1size64(
489 String.join("-", znodeId, extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
490 dapi = PortMappingUtils.fnv1size64(
491 String.join("-", extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
492 extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
494 return new ZEndApiInfoBuilder()
496 .setExpectedDapi(sapi)
498 .setExpectedSapi(dapi)
503 private static Map<String, String> extractAendFromPathDescriptionForOtn(PathDescription pathDescription) {
504 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
505 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
506 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
508 .collect(Collectors.toList());
509 for (AToZ atoZ : tpList) {
510 TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
511 if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
512 String nodeId = tp.getTpNodeId();
513 String lcp = tp.getTpId();
514 return Map.of("nodeId", nodeId, "tpid", lcp);
520 private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
521 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
522 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
523 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
525 .collect(Collectors.toList());
526 for (ZToA ztoA : tpList) {
527 TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
528 if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
529 String nodeId = tp.getTpNodeId();
530 String lcp = tp.getTpId();
531 return Map.of("nodeId", nodeId, "tpid", lcp);
537 private static Map<String, String> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
538 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
539 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
540 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
542 .collect(Collectors.toList());
543 for (AToZ atoZ : tpList) {
544 TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
545 if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
546 // String nodeId = tp.getTpNodeId();
547 // String lcp = tp.getTpId();
548 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
554 private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
555 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
556 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
557 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
559 .collect(Collectors.toList());
560 for (ZToA ztoA : tpList) {
561 TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
562 if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
563 // String nodeId = tp.getTpNodeId();
564 // String lcp = tp.getTpId();
565 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());