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;
17 import java.util.Optional;
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.rev211210.configuration.response.common.ConfigurationResponseCommon;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.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.rev211210.ServiceDeleteInput;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
54 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.Resource;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.Link;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
57 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.Nodes;
58 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.optical.renderer.nodes.NodesBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.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 Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
174 .forName(atoZDirection.getModulationFormat());
175 if (optionalModulationFormat.isPresent()
176 && GridConstant.FREQUENCY_WIDTH_TABLE
177 .contains(atoZDirection.getRate(), optionalModulationFormat.get())) {
178 servicePathInputBuilder
179 .setNmcWidth(FrequencyGHz
180 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
181 optionalModulationFormat.get())));
184 servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
185 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
186 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
187 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
190 public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
191 PathDescription pathDescription, Action operation) {
192 int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
193 ZToADirection ztoADirection = pathDescription.getZToADirection();
194 LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
195 NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
196 ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
197 .setOperation(operation)
198 .setServiceName(serviceName)
199 .setNodes(nodeLists.getRendererNodeList())
200 .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
201 .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
202 pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
203 .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
204 if (ztoADirection.getZToAWavelengthNumber() != null) {
205 servicePathInputBuilder
206 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
208 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
209 .equals(ztoADirection.getZToAWavelengthNumber())) {
210 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
212 if (ztoADirection.getZToAMinFrequency() != null) {
213 servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
214 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
216 .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
218 if (ztoADirection.getZToAMaxFrequency() != null) {
219 servicePathInputBuilder.setMaxFreq(new FrequencyTHz(ztoADirection.getZToAMaxFrequency().getValue()));
220 servicePathInputBuilder.setHigherSpectralSlotNumber(
221 Uint32.valueOf(GridUtils
222 .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
224 if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
225 servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
226 ztoADirection.getZToAMinFrequency().getValue().decimalValue(),
227 ztoADirection.getZToAMaxFrequency().getValue().decimalValue(),
230 if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
231 Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
232 .forName(ztoADirection.getModulationFormat());
233 if (optionalModulationFormat.isPresent()
234 && GridConstant.FREQUENCY_WIDTH_TABLE
235 .contains(ztoADirection.getRate(), optionalModulationFormat.get())) {
236 servicePathInputBuilder.setNmcWidth(FrequencyGHz
237 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
238 optionalModulationFormat.get())));
241 servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
242 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
243 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
244 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
247 // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
248 public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
249 String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
250 // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
251 List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.Nodes> nodes =
253 NodeLists nodeLists =
255 ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
256 : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
257 LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
258 for (Nodes node: nodeLists.getRendererNodeList()) {
259 org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes.NodesBuilder nb
260 = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.otn.renderer.nodes
261 .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
262 if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
263 nb.setNetwork2Tp(node.getSrcTp());
265 nb.setClientTp(node.getSrcTp());
267 nodes.add(nb.build());
269 OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
270 .setServiceName(serviceName)
271 .setOperation(operation)
272 .setServiceFormat(serviceFormat)
273 .setServiceRate(serviceRate)
275 .setAEndApiInfo(createAendApiInfo(pathDescription, true))
276 .setZEndApiInfo(createZendApiInfo(pathDescription, true));
278 // set the trib-slots and trib-ports for the lower oder odu
279 if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
280 Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
282 Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
284 otnServicePathInputBuilder
285 .setTribPortNumber(tribPort)
286 .setTribSlot(minTribSlot);
288 if (serviceRate.intValue() == 100 && pathDescription.getAToZDirection().getMinTribSlot() != null
289 && pathDescription.getAToZDirection().getMaxTribSlot() != null) {
290 Set<OpucnTribSlotDef> opucnTribSlotDefList = new HashSet<>();
291 opucnTribSlotDefList.add(
292 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMinTribSlot().getValue()));
293 opucnTribSlotDefList.add(
294 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMaxTribSlot().getValue()));
295 otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
297 return otnServicePathInputBuilder.build();
300 public static ServicePathInput rendererDeleteServiceInput(String serviceName,
301 ServiceDeleteInput serviceDeleteInput) {
302 //TODO: finish model-model mapping
303 return new ServicePathInputBuilder().setServiceName(serviceName).build();
306 public static Set<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
307 Set<String> linkidList = new HashSet<>();
308 pathDescription.getAToZDirection().getAToZ().values().stream()
309 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
311 Link link = (Link) rsc.getResource().getResource();
312 linkidList.add(link.getLinkId());
314 pathDescription.getZToADirection().getZToA().values().stream()
315 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
317 Link link = (Link) rsc.getResource().getResource();
318 linkidList.add(link.getLinkId());
323 private static NodeLists getNodesListZtoA(Iterator<ZToA> iterator) {
324 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
325 List<Nodes> olmList = new ArrayList<>();
326 List<Nodes> list = new ArrayList<>();
328 while (iterator.hasNext()) {
329 ZToA pathDesObj = iterator.next();
331 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
332 } catch (IllegalArgumentException | SecurityException e) {
333 //TODO: Auto-generated catch block
334 LOG.error("Did not find the getResource method", e);
337 populateNodeLists(treeMap, list, olmList, false);
338 return new NodeLists(olmList, list);
341 private static NodeLists getNodesListAToZ(Iterator<AToZ> iterator) {
342 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
343 List<Nodes> list = new ArrayList<>();
344 List<Nodes> olmList = new ArrayList<>();
346 while (iterator.hasNext()) {
347 AToZ pathDesObj = iterator.next();
349 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
350 } catch (IllegalArgumentException | SecurityException e) {
351 //TODO: Auto-generated catch block
352 LOG.error("Did not find the getResource method", e);
355 populateNodeLists(treeMap, list, olmList, true);
356 return new NodeLists(olmList, list);
359 private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
361 String resourceType = rsrc.implementedInterface().getSimpleName();
362 LOG.info("Inside {} {}", direction, resourceType);
363 switch (resourceType) {
364 case TERMINATION_POINT:
365 TerminationPoint tp = (TerminationPoint) rsrc;
366 LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
367 String tpID = tp.getTpId();
369 //TODO: do not rely on ID to be in certain format
370 if (tpID.contains("CTP") || tpID.contains("CP")) {
374 if (tpID.contains(StringConstants.TTP_TOKEN)) {
375 nodeID = tp.getTpNodeId().split("-DEG")[0];
376 } else if (tpID.contains(StringConstants.PP_TOKEN)) {
377 nodeID = tp.getTpNodeId().split("-SRG")[0];
378 } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
379 || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
380 nodeID = tp.getTpNodeId().split("-XPDR")[0];
384 int id = Integer.parseInt(sortId);
385 treeMap.put(id, new NodeIdPair(nodeID, tpID));
388 LOG.info("The type is link");
391 LOG.info("The type is not identified: {}", resourceType);
396 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
397 value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
398 justification = "loop when value is not always null - "
399 + "TODO: check if something exists in Java lib")
400 private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
404 LOG.info("treeMap values = {}", treeMap.values());
405 for (NodeIdPair values : treeMap.values()) {
407 srcID = values.getTpID();
408 } else if (desID == null) {
409 desID = values.getTpID();
410 NodesBuilder olmNb = new NodesBuilder()
411 .setNodeId(values.getNodeID())
414 olmList.add(olmNb.build());
415 if (srcID.isEmpty()) {
418 if (desID.isEmpty()) {
419 desID = new StringBuilder(srcID).toString();
423 NodesBuilder nb = new NodesBuilder()
424 .withKey(new NodesKey(values.getNodeID()))
427 if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
428 nb.setDestTp(srcID).setSrcTp(desID);
430 list.add(nb.build());
432 if (srcID != null && desID != null && !srcID.contains(StringConstants.NETWORK_TOKEN)
433 && !desID.contains(StringConstants.NETWORK_TOKEN)) {
434 NodesBuilder nb = new NodesBuilder()
435 .withKey(new NodesKey(values.getNodeID()))
438 list.add(nb.build());
444 LOG.warn("both, the source and destination id are not null!");
449 private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
450 String anodeId = null;
454 anodeId = extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId");
455 sapi = PortMappingUtils.fnv1size64(
456 String.join("-", anodeId, extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
457 dapi = PortMappingUtils.fnv1size64(
458 String.join("-", extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
459 extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
461 anodeId = extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId");
462 sapi = PortMappingUtils.fnv1size64(
463 String.join("-", anodeId, extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
464 dapi = PortMappingUtils.fnv1size64(
465 String.join("-", extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
466 extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
468 return new AEndApiInfoBuilder()
470 .setExpectedDapi(sapi)
472 .setExpectedSapi(dapi)
477 private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
478 String znodeId = null;
482 znodeId = extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId");
483 sapi = PortMappingUtils.fnv1size64(
484 String.join("-", znodeId, extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
485 dapi = PortMappingUtils.fnv1size64(
486 String.join("-", extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
487 extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
489 znodeId = extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId");
490 sapi = PortMappingUtils.fnv1size64(
491 String.join("-", znodeId, extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
492 dapi = PortMappingUtils.fnv1size64(
493 String.join("-", extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
494 extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
496 return new ZEndApiInfoBuilder()
498 .setExpectedDapi(sapi)
500 .setExpectedSapi(dapi)
505 private static Map<String, String> extractAendFromPathDescriptionForOtn(PathDescription pathDescription) {
506 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
507 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
508 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
510 .collect(Collectors.toList());
511 for (AToZ atoZ : tpList) {
512 TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
513 if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
514 String nodeId = tp.getTpNodeId();
515 String lcp = tp.getTpId();
516 return Map.of("nodeId", nodeId, "tpid", lcp);
522 private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
523 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
524 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
525 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
527 .collect(Collectors.toList());
528 for (ZToA ztoA : tpList) {
529 TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
530 if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
531 String nodeId = tp.getTpNodeId();
532 String lcp = tp.getTpId();
533 return Map.of("nodeId", nodeId, "tpid", lcp);
539 private static Map<String, String> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
540 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
541 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
542 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
544 .collect(Collectors.toList());
545 for (AToZ atoZ : tpList) {
546 TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
547 if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
548 // String nodeId = tp.getTpNodeId();
549 // String lcp = tp.getTpId();
550 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
556 private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
557 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
558 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
559 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
561 .collect(Collectors.toList());
562 for (ZToA ztoA : tpList) {
563 TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
564 if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
565 // String nodeId = tp.getTpNodeId();
566 // String lcp = tp.getTpId();
567 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());