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 java.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.HashSet;
14 import java.util.Iterator;
15 import java.util.List;
18 import java.util.TreeMap;
19 import java.util.stream.Collectors;
20 import org.opendaylight.transportpce.common.NodeIdPair;
21 import org.opendaylight.transportpce.common.StringConstants;
22 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
23 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
24 import org.opendaylight.transportpce.common.mapping.PortMappingUtils;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.Action;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInputBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfoBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfoBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInputBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OpucnTribSlotDef;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.Resource;
54 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.Link;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.Nodes;
57 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.NodesBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.NodesKey;
59 import org.opendaylight.yangtools.yang.common.Decimal64;
60 import org.opendaylight.yangtools.yang.common.RpcResult;
61 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
62 import org.opendaylight.yangtools.yang.common.Uint32;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
67 public final class ModelMappingUtils {
69 private static final Logger LOG = LoggerFactory.getLogger(ModelMappingUtils.class);
70 private static final String TERMINATION_POINT = "TerminationPoint";
71 private static final String LINK = "Link";
73 private ModelMappingUtils() {
76 public static ServicePowerSetupInput createServicePowerSetupInput(List<Nodes> olmList,
77 ServiceImplementationRequestInput input) {
78 ServicePowerSetupInputBuilder olmSetupBldr = new ServicePowerSetupInputBuilder().setNodes(olmList);
79 if (input != null && input.getPathDescription() != null
80 && input.getPathDescription().getAToZDirection() != null) {
81 AToZDirection atoZDirection = input.getPathDescription().getAToZDirection();
82 olmSetupBldr.setWaveNumber(atoZDirection.getAToZWavelengthNumber());
83 if (atoZDirection.getAToZMinFrequency() != null) {
84 olmSetupBldr.setLowerSpectralSlotNumber(Uint32
86 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
88 if (atoZDirection.getAToZMaxFrequency() != null) {
89 olmSetupBldr.setHigherSpectralSlotNumber(Uint32
91 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
93 // Set the MC-width for the OLM
94 olmSetupBldr.setMcWidth(new FrequencyGHz(Decimal64.valueOf(
95 atoZDirection.getAToZMaxFrequency().getValue().decimalValue()
96 .subtract(atoZDirection.getAToZMinFrequency().getValue().decimalValue())
97 .multiply(new BigDecimal(1000)))));
99 return olmSetupBldr.build();
102 public static ServiceImplementationRequestOutput createServiceImplResponse(String responseCode, String message) {
103 return new ServiceImplementationRequestOutputBuilder()
104 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
108 public static ServiceDeleteOutput createServiceDeleteResponse(String responseCode, String message) {
109 return new ServiceDeleteOutputBuilder()
110 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
114 public static ConfigurationResponseCommon createCommonResponse(String responseCode, String message) {
115 return new ConfigurationResponseCommonBuilder()
116 .setResponseMessage(message)
117 .setResponseCode(responseCode)
121 public static ListenableFuture<RpcResult<ServiceImplementationRequestOutput>>
122 createServiceImplementationRpcResponse(ServiceImplementationRequestOutput payload) {
123 return RpcResultBuilder.success(payload).buildFuture();
126 public static ListenableFuture<RpcResult<ServiceDeleteOutput>>
127 createServiceDeleteRpcResponse(ServiceDeleteOutput payload) {
128 return RpcResultBuilder.success(payload).buildFuture();
131 public static ServicePathInputData rendererCreateServiceInputAToZ(String serviceName,
132 PathDescription pathDescription, Action operation) {
133 int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
134 AToZDirection atoZDirection = pathDescription.getAToZDirection();
135 LOG.info("Building ServicePathInputData for a to z direction {}", atoZDirection);
136 NodeLists nodeLists = getNodesListAToZ(atoZDirection.nonnullAToZ().values().iterator());
137 ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
138 .setServiceName(serviceName)
139 .setOperation(operation)
140 .setNodes(nodeLists.getRendererNodeList())
141 .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
142 .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
143 pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
144 .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
145 if (atoZDirection.getAToZWavelengthNumber() != null) {
146 servicePathInputBuilder
147 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
149 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
150 .equals(atoZDirection.getAToZWavelengthNumber())) {
151 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
153 if (atoZDirection.getAToZMinFrequency() != null) {
154 servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
155 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
157 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
159 if (atoZDirection.getAToZMaxFrequency() != null) {
160 servicePathInputBuilder.setMaxFreq(new FrequencyTHz(atoZDirection.getAToZMaxFrequency().getValue()));
161 servicePathInputBuilder.setHigherSpectralSlotNumber(
162 Uint32.valueOf(GridUtils
163 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
165 if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
166 servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
167 atoZDirection.getAToZMinFrequency().getValue().decimalValue(),
168 atoZDirection.getAToZMaxFrequency().getValue().decimalValue(),
171 if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
172 ModulationFormat modulationFormat = ModulationFormat.forName(atoZDirection.getModulationFormat());
173 if (modulationFormat != null
174 && GridConstant.FREQUENCY_WIDTH_TABLE
175 .contains(atoZDirection.getRate(), modulationFormat)) {
176 servicePathInputBuilder
177 .setNmcWidth(FrequencyGHz
178 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
182 servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
183 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
184 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
185 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
188 public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
189 PathDescription pathDescription, Action operation) {
190 int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
191 ZToADirection ztoADirection = pathDescription.getZToADirection();
192 LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
193 NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
194 ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
195 .setOperation(operation)
196 .setServiceName(serviceName)
197 .setNodes(nodeLists.getRendererNodeList())
198 .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
199 .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
200 pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
201 .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
202 if (ztoADirection.getZToAWavelengthNumber() != null) {
203 servicePathInputBuilder
204 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
206 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
207 .equals(ztoADirection.getZToAWavelengthNumber())) {
208 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
210 if (ztoADirection.getZToAMinFrequency() != null) {
211 servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
212 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
214 .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
216 if (ztoADirection.getZToAMaxFrequency() != null) {
217 servicePathInputBuilder.setMaxFreq(new FrequencyTHz(ztoADirection.getZToAMaxFrequency().getValue()));
218 servicePathInputBuilder.setHigherSpectralSlotNumber(
219 Uint32.valueOf(GridUtils
220 .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
222 if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
223 servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
224 ztoADirection.getZToAMinFrequency().getValue().decimalValue(),
225 ztoADirection.getZToAMaxFrequency().getValue().decimalValue(),
228 if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
229 ModulationFormat modulationFormat = ModulationFormat.forName(ztoADirection.getModulationFormat());
230 if (modulationFormat != null
231 && GridConstant.FREQUENCY_WIDTH_TABLE
232 .contains(ztoADirection.getRate(), modulationFormat)) {
233 servicePathInputBuilder.setNmcWidth(FrequencyGHz
234 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
238 servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
239 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
240 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
241 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
244 // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
245 public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
246 String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
247 // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
248 List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.Nodes> nodes =
250 NodeLists nodeLists =
252 ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
253 : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
254 LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
255 for (Nodes node: nodeLists.getRendererNodeList()) {
256 org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.NodesBuilder nb
257 = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes
258 .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
259 if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
260 nb.setNetwork2Tp(node.getSrcTp());
262 nb.setClientTp(node.getSrcTp());
264 nodes.add(nb.build());
266 OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
267 .setServiceName(serviceName)
268 .setOperation(operation)
269 .setServiceFormat(serviceFormat)
270 .setServiceRate(serviceRate)
272 .setAEndApiInfo(createAendApiInfo(pathDescription, true))
273 .setZEndApiInfo(createZendApiInfo(pathDescription, true));
275 // set the trib-slots and trib-ports for the lower oder odu
276 if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
277 Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
279 Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
281 otnServicePathInputBuilder
282 .setTribPortNumber(tribPort)
283 .setTribSlot(minTribSlot);
285 if (serviceRate.intValue() == 100 && pathDescription.getAToZDirection().getMinTribSlot() != null
286 && pathDescription.getAToZDirection().getMaxTribSlot() != null) {
287 Set<OpucnTribSlotDef> opucnTribSlotDefList = new HashSet<>();
288 opucnTribSlotDefList.add(
289 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMinTribSlot().getValue()));
290 opucnTribSlotDefList.add(
291 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMaxTribSlot().getValue()));
292 otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
294 return otnServicePathInputBuilder.build();
297 public static ServicePathInput rendererDeleteServiceInput(String serviceName,
298 ServiceDeleteInput serviceDeleteInput) {
299 //TODO: finish model-model mapping
300 return new ServicePathInputBuilder().setServiceName(serviceName).build();
303 public static Set<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
304 Set<String> linkidList = new HashSet<>();
305 pathDescription.getAToZDirection().getAToZ().values().stream()
306 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
308 Link link = (Link) rsc.getResource().getResource();
309 linkidList.add(link.getLinkId());
311 pathDescription.getZToADirection().getZToA().values().stream()
312 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
314 Link link = (Link) rsc.getResource().getResource();
315 linkidList.add(link.getLinkId());
320 private static NodeLists getNodesListZtoA(Iterator<ZToA> iterator) {
321 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
322 List<Nodes> olmList = new ArrayList<>();
323 List<Nodes> list = new ArrayList<>();
325 while (iterator.hasNext()) {
326 ZToA pathDesObj = iterator.next();
328 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
329 } catch (IllegalArgumentException | SecurityException e) {
330 //TODO: Auto-generated catch block
331 LOG.error("Did not find the getResource method", e);
334 populateNodeLists(treeMap, list, olmList, false);
335 return new NodeLists(olmList, list);
338 private static NodeLists getNodesListAToZ(Iterator<AToZ> iterator) {
339 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
340 List<Nodes> list = new ArrayList<>();
341 List<Nodes> olmList = new ArrayList<>();
343 while (iterator.hasNext()) {
344 AToZ pathDesObj = iterator.next();
346 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
347 } catch (IllegalArgumentException | SecurityException e) {
348 //TODO: Auto-generated catch block
349 LOG.error("Did not find the getResource method", e);
352 populateNodeLists(treeMap, list, olmList, true);
353 return new NodeLists(olmList, list);
356 private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
358 String resourceType = rsrc.implementedInterface().getSimpleName();
359 LOG.info("Inside {} {}", direction, resourceType);
360 switch (resourceType) {
361 case TERMINATION_POINT:
362 TerminationPoint tp = (TerminationPoint) rsrc;
363 LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
364 String tpID = tp.getTpId();
366 //TODO: do not rely on ID to be in certain format
367 if (tpID.contains("CTP") || tpID.contains("CP")) {
371 if (tpID.contains(StringConstants.TTP_TOKEN)) {
372 nodeID = tp.getTpNodeId().split("-DEG")[0];
373 } else if (tpID.contains(StringConstants.PP_TOKEN)) {
374 nodeID = tp.getTpNodeId().split("-SRG")[0];
375 } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
376 || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
377 nodeID = tp.getTpNodeId().split("-XPDR")[0];
381 int id = Integer.parseInt(sortId);
382 treeMap.put(id, new NodeIdPair(nodeID, tpID));
385 LOG.info("The type is link");
388 LOG.info("The type is not identified: {}", resourceType);
393 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
394 value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
395 justification = "loop when value is not always null - "
396 + "TODO: check if something exists in Java lib")
397 private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
401 LOG.info("treeMap values = {}", treeMap.values());
402 for (NodeIdPair values : treeMap.values()) {
404 srcID = values.getTpID();
405 } else if (desID == null) {
406 desID = values.getTpID();
407 NodesBuilder olmNb = new NodesBuilder()
408 .setNodeId(values.getNodeID())
411 olmList.add(olmNb.build());
412 if (srcID.isEmpty()) {
415 if (desID.isEmpty()) {
416 desID = new StringBuilder(srcID).toString();
420 NodesBuilder nb = new NodesBuilder()
421 .withKey(new NodesKey(values.getNodeID()))
424 if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
425 nb.setDestTp(srcID).setSrcTp(desID);
427 list.add(nb.build());
429 if (srcID != null && desID != null && !srcID.contains(StringConstants.NETWORK_TOKEN)
430 && !desID.contains(StringConstants.NETWORK_TOKEN)) {
431 NodesBuilder nb = new NodesBuilder()
432 .withKey(new NodesKey(values.getNodeID()))
435 list.add(nb.build());
441 LOG.warn("both, the source and destination id are not null!");
446 private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
447 String anodeId = null;
451 anodeId = extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId");
452 sapi = PortMappingUtils.fnv1size64(
453 String.join("-", anodeId, extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
454 dapi = PortMappingUtils.fnv1size64(
455 String.join("-", extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
456 extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
458 anodeId = extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId");
459 sapi = PortMappingUtils.fnv1size64(
460 String.join("-", anodeId, extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
461 dapi = PortMappingUtils.fnv1size64(
462 String.join("-", extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
463 extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
465 return new AEndApiInfoBuilder()
467 .setExpectedDapi(sapi)
469 .setExpectedSapi(dapi)
474 private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
475 String znodeId = null;
479 znodeId = extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId");
480 sapi = PortMappingUtils.fnv1size64(
481 String.join("-", znodeId, extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
482 dapi = PortMappingUtils.fnv1size64(
483 String.join("-", extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
484 extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
486 znodeId = extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId");
487 sapi = PortMappingUtils.fnv1size64(
488 String.join("-", znodeId, extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
489 dapi = PortMappingUtils.fnv1size64(
490 String.join("-", extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
491 extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
493 return new ZEndApiInfoBuilder()
495 .setExpectedDapi(sapi)
497 .setExpectedSapi(dapi)
502 private static Map<String, String> extractAendFromPathDescriptionForOtn(PathDescription pathDescription) {
503 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().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()
507 .collect(Collectors.toList());
508 for (AToZ atoZ : tpList) {
509 TerminationPoint tp = (TerminationPoint) atoZ.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);
519 private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
520 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().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()
524 .collect(Collectors.toList());
525 for (ZToA ztoA : tpList) {
526 TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
527 if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
528 String nodeId = tp.getTpNodeId();
529 String lcp = tp.getTpId();
530 return Map.of("nodeId", nodeId, "tpid", lcp);
536 private static Map<String, String> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
537 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().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()
541 .collect(Collectors.toList());
542 for (AToZ atoZ : tpList) {
543 TerminationPoint tp = (TerminationPoint) atoZ.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());
553 private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
554 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
555 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
556 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
558 .collect(Collectors.toList());
559 for (ZToA ztoA : tpList) {
560 TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
561 if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
562 // String nodeId = tp.getTpNodeId();
563 // String lcp = tp.getTpId();
564 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());