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.Iterator;
14 import java.util.List;
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;
65 public final class ModelMappingUtils {
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";
71 private ModelMappingUtils() {
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
84 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
86 if (atoZDirection.getAToZMaxFrequency() != null) {
87 olmSetupBldr.setHigherSpectralSlotNumber(Uint32
89 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
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))));
95 return olmSetupBldr.build();
98 public static ServiceImplementationRequestOutput createServiceImplResponse(String responseCode, String message) {
99 return new ServiceImplementationRequestOutputBuilder()
100 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
104 public static ServiceDeleteOutput createServiceDeleteResponse(String responseCode, String message) {
105 return new ServiceDeleteOutputBuilder()
106 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
110 public static ConfigurationResponseCommon createCommonResponse(String responseCode, String message) {
111 return new ConfigurationResponseCommonBuilder()
112 .setResponseMessage(message)
113 .setResponseCode(responseCode)
117 public static ListenableFuture<RpcResult<ServiceImplementationRequestOutput>>
118 createServiceImplementationRpcResponse(ServiceImplementationRequestOutput payload) {
119 return RpcResultBuilder.success(payload).buildFuture();
122 public static ListenableFuture<RpcResult<ServiceDeleteOutput>>
123 createServiceDeleteRpcResponse(ServiceDeleteOutput payload) {
124 return RpcResultBuilder.success(payload).buildFuture();
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());
144 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
145 .equals(atoZDirection.getAToZWavelengthNumber())) {
146 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
148 if (atoZDirection.getAToZMinFrequency() != null) {
149 servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
150 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
152 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
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())));
160 if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
161 servicePathInputBuilder.setCenterFreq(
162 GridUtils.getCentralFrequencyWithPrecision(atoZDirection.getAToZMinFrequency().getValue(),
163 atoZDirection.getAToZMaxFrequency().getValue(), scale));
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())));
177 servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
178 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
179 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
180 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
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());
200 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
201 .equals(ztoADirection.getZToAWavelengthNumber())) {
202 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
204 if (ztoADirection.getZToAMinFrequency() != null) {
205 servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
206 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
208 .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
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())));
216 if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
217 servicePathInputBuilder.setCenterFreq(
218 GridUtils.getCentralFrequencyWithPrecision(ztoADirection.getZToAMinFrequency().getValue(),
219 ztoADirection.getZToAMaxFrequency().getValue(), scale));
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())));
232 servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
233 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
234 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
235 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
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 =
244 NodeLists nodeLists =
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());
256 nb.setClientTp(node.getSrcTp());
258 nodes.add(nb.build());
260 OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
261 .setServiceName(serviceName)
262 .setOperation(operation)
263 .setServiceFormat(serviceFormat)
264 .setServiceRate(serviceRate)
266 .setAEndApiInfo(createAendApiInfo(pathDescription, true))
267 .setZEndApiInfo(createZendApiInfo(pathDescription, true));
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()
273 Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
275 otnServicePathInputBuilder
276 .setTribPortNumber(tribPort)
277 .setTribSlot(minTribSlot);
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);
285 return otnServicePathInputBuilder.build();
288 public static ServicePathInput rendererDeleteServiceInput(String serviceName,
289 ServiceDeleteInput serviceDeleteInput) {
290 //TODO: finish model-model mapping
291 return new ServicePathInputBuilder().setServiceName(serviceName).build();
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()))
299 Link link = (Link) rsc.getResource().getResource();
300 linkidList.add(link.getLinkId());
302 pathDescription.getZToADirection().getZToA().values().stream()
303 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
305 Link link = (Link) rsc.getResource().getResource();
306 linkidList.add(link.getLinkId());
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<>();
316 while (iterator.hasNext()) {
317 ZToA pathDesObj = iterator.next();
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);
325 populateNodeLists(treeMap, list, olmList, false);
326 return new NodeLists(olmList, list);
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<>();
334 while (iterator.hasNext()) {
335 AToZ pathDesObj = iterator.next();
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);
343 populateNodeLists(treeMap, list, olmList, true);
344 return new NodeLists(olmList, list);
347 private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
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();
357 //TODO: do not rely on ID to be in certain format
358 if (tpID.contains("CTP") || tpID.contains("CP")) {
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];
372 int id = Integer.parseInt(sortId);
373 treeMap.put(id, new NodeIdPair(nodeID, tpID));
376 LOG.info("The type is link");
379 LOG.info("The type is not identified: {}", resourceType);
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,
392 LOG.info("treeMap values = {}", treeMap.values());
393 for (NodeIdPair values : treeMap.values()) {
395 srcID = values.getTpID();
396 } else if (desID == null) {
397 desID = values.getTpID();
398 NodesBuilder olmNb = new NodesBuilder()
399 .setNodeId(values.getNodeID())
402 olmList.add(olmNb.build());
403 if (srcID.isEmpty()) {
406 if (desID.isEmpty()) {
407 desID = new StringBuilder(srcID).toString();
411 NodesBuilder nb = new NodesBuilder()
412 .withKey(new NodesKey(values.getNodeID()))
415 if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
416 nb.setDestTp(srcID).setSrcTp(desID);
418 list.add(nb.build());
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()))
426 list.add(nb.build());
432 LOG.warn("both, the source and destination id are not null!");
437 private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
438 String anodeId = null;
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")));
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")));
456 return new AEndApiInfoBuilder()
458 .setExpectedDapi(sapi)
460 .setExpectedSapi(dapi)
465 private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
466 String znodeId = null;
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")));
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")));
484 return new ZEndApiInfoBuilder()
486 .setExpectedDapi(sapi)
488 .setExpectedSapi(dapi)
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()
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);
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()
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);
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()
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());
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()
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());