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.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
15 import java.util.Optional;
16 import java.util.TreeMap;
17 import java.util.stream.Collectors;
18 import org.opendaylight.transportpce.common.NodeIdPair;
19 import org.opendaylight.transportpce.common.StringConstants;
20 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
21 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
22 import org.opendaylight.transportpce.common.mapping.PortMappingUtils;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.Action;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInputBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInputBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfoBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfoBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInputBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutputBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
46 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
47 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.Resource;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.Link;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
54 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.Nodes;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.NodesBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.NodesKey;
57 import org.opendaylight.yangtools.yang.common.RpcResult;
58 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
59 import org.opendaylight.yangtools.yang.common.Uint32;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
64 public final class ModelMappingUtils {
66 private static final Logger LOG = LoggerFactory.getLogger(ModelMappingUtils.class);
67 private static final String TERMINATION_POINT = "TerminationPoint";
68 private static final String LINK = "Link";
70 private ModelMappingUtils() {
73 public static ServicePowerSetupInput createServicePowerSetupInput(List<Nodes> olmList,
74 ServiceImplementationRequestInput input) {
75 ServicePowerSetupInputBuilder olmSetupBldr = new ServicePowerSetupInputBuilder().setNodes(olmList);
76 if (input != null && input.getPathDescription() != null
77 && input.getPathDescription().getAToZDirection() != null) {
78 AToZDirection atoZDirection = input.getPathDescription().getAToZDirection();
79 olmSetupBldr.setWaveNumber(atoZDirection.getAToZWavelengthNumber());
80 if (atoZDirection.getAToZMinFrequency() != null) {
81 olmSetupBldr.setLowerSpectralSlotNumber(Uint32
83 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
85 if (atoZDirection.getAToZMaxFrequency() != null) {
86 olmSetupBldr.setHigherSpectralSlotNumber(Uint32
88 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
91 return olmSetupBldr.build();
94 public static ServiceImplementationRequestOutput createServiceImplResponse(String responseCode, String message) {
95 return new ServiceImplementationRequestOutputBuilder()
96 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
100 public static ServiceDeleteOutput createServiceDeleteResponse(String responseCode, String message) {
101 return new ServiceDeleteOutputBuilder()
102 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
106 public static ConfigurationResponseCommon createCommonResponse(String responseCode, String message) {
107 return new ConfigurationResponseCommonBuilder()
108 .setResponseMessage(message)
109 .setResponseCode(responseCode)
113 public static ListenableFuture<RpcResult<ServiceImplementationRequestOutput>>
114 createServiceImplementationRpcResponse(ServiceImplementationRequestOutput payload) {
115 return RpcResultBuilder.success(payload).buildFuture();
118 public static ListenableFuture<RpcResult<ServiceDeleteOutput>>
119 createServiceDeleteRpcResponse(ServiceDeleteOutput payload) {
120 return RpcResultBuilder.success(payload).buildFuture();
123 public static ServicePathInputData rendererCreateServiceInputAToZ(String serviceName,
124 PathDescription pathDescription, Action operation) {
125 int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
126 AToZDirection atoZDirection = pathDescription.getAToZDirection();
127 LOG.info("Building ServicePathInputData for a to z direction {}", atoZDirection);
128 NodeLists nodeLists = getNodesListAToZ(atoZDirection.nonnullAToZ().values().iterator());
129 ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
130 .setServiceName(serviceName)
131 .setOperation(operation)
132 .setNodes(nodeLists.getRendererNodeList())
133 .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
134 if (atoZDirection.getAToZWavelengthNumber() != null) {
135 servicePathInputBuilder
136 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
138 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
139 .equals(atoZDirection.getAToZWavelengthNumber())) {
140 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
142 if (atoZDirection.getAToZMinFrequency() != null) {
143 servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
144 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
146 .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
148 if (atoZDirection.getAToZMaxFrequency() != null) {
149 servicePathInputBuilder.setMaxFreq(new FrequencyTHz(atoZDirection.getAToZMaxFrequency().getValue()));
150 servicePathInputBuilder.setHigherSpectralSlotNumber(
151 Uint32.valueOf(GridUtils
152 .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
154 if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
155 servicePathInputBuilder.setCenterFreq(
156 GridUtils.getCentralFrequencyWithPrecision(atoZDirection.getAToZMinFrequency().getValue(),
157 atoZDirection.getAToZMaxFrequency().getValue(), scale));
159 if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
160 Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
161 .forName(atoZDirection.getModulationFormat());
162 if (optionalModulationFormat.isPresent()
163 && GridConstant.FREQUENCY_WIDTH_TABLE
164 .contains(atoZDirection.getRate(), optionalModulationFormat.get())) {
165 servicePathInputBuilder
166 .setWidth(FrequencyGHz
167 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
168 optionalModulationFormat.get())));
171 servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
172 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
173 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
174 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
177 public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
178 PathDescription pathDescription, Action operation) {
179 int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
180 ZToADirection ztoADirection = pathDescription.getZToADirection();
181 LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
182 NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
183 ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
184 .setOperation(operation)
185 .setServiceName(serviceName)
186 .setNodes(nodeLists.getRendererNodeList())
187 .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
188 if (ztoADirection.getZToAWavelengthNumber() != null) {
189 servicePathInputBuilder
190 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
192 if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
193 .equals(ztoADirection.getZToAWavelengthNumber())) {
194 scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
196 if (ztoADirection.getZToAMinFrequency() != null) {
197 servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
198 servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
200 .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
202 if (ztoADirection.getZToAMaxFrequency() != null) {
203 servicePathInputBuilder.setMaxFreq(new FrequencyTHz(ztoADirection.getZToAMaxFrequency().getValue()));
204 servicePathInputBuilder.setHigherSpectralSlotNumber(
205 Uint32.valueOf(GridUtils
206 .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
208 if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
209 servicePathInputBuilder.setCenterFreq(
210 GridUtils.getCentralFrequencyWithPrecision(ztoADirection.getZToAMinFrequency().getValue(),
211 ztoADirection.getZToAMaxFrequency().getValue(), scale));
213 if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
214 Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
215 .forName(ztoADirection.getModulationFormat());
216 if (optionalModulationFormat.isPresent()
217 && GridConstant.FREQUENCY_WIDTH_TABLE
218 .contains(ztoADirection.getRate(), optionalModulationFormat.get())) {
219 servicePathInputBuilder.setWidth(FrequencyGHz
220 .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
221 optionalModulationFormat.get())));
224 servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
225 .setAEndApiInfo(createAendApiInfo(pathDescription, false))
226 .setZEndApiInfo(createZendApiInfo(pathDescription, false));
227 return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
230 // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
231 public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
232 String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
233 // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
234 List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.Nodes> nodes =
236 NodeLists nodeLists =
238 ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
239 : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
240 LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
241 for (Nodes node: nodeLists.getRendererNodeList()) {
242 org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.NodesBuilder nb
243 = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes
244 .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
245 if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
246 nb.setNetwork2Tp(node.getSrcTp());
248 nb.setClientTp(node.getSrcTp());
250 nodes.add(nb.build());
252 OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
253 .setServiceName(serviceName)
254 .setOperation(operation)
255 .setServiceFormat(serviceFormat)
256 .setServiceRate(serviceRate)
258 .setAEndApiInfo(createAendApiInfo(pathDescription, true))
259 .setZEndApiInfo(createZendApiInfo(pathDescription, true));
261 // set the trib-slots and trib-ports for the lower oder odu
262 if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
263 Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
265 Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
267 otnServicePathInputBuilder
268 .setTribPortNumber(tribPort)
269 .setTribSlot(minTribSlot);
271 if (serviceRate.intValue() == 100) {
272 List<OpucnTribSlotDef> opucnTribSlotDefList = new ArrayList<>();
273 opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMinTribSlot());
274 opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMaxTribSlot());
275 otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
277 return otnServicePathInputBuilder.build();
280 public static ServicePathInput rendererDeleteServiceInput(String serviceName,
281 ServiceDeleteInput serviceDeleteInput) {
282 //TODO: finish model-model mapping
283 return new ServicePathInputBuilder().setServiceName(serviceName).build();
286 public static List<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
287 List<String> linkidList = new ArrayList<>();
288 pathDescription.getAToZDirection().getAToZ().values().stream()
289 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
291 Link link = (Link) rsc.getResource().getResource();
292 linkidList.add(link.getLinkId());
294 pathDescription.getZToADirection().getZToA().values().stream()
295 .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
297 Link link = (Link) rsc.getResource().getResource();
298 linkidList.add(link.getLinkId());
303 private static NodeLists getNodesListZtoA(Iterator<ZToA> iterator) {
304 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
305 List<Nodes> olmList = new ArrayList<>();
306 List<Nodes> list = new ArrayList<>();
308 while (iterator.hasNext()) {
309 ZToA pathDesObj = iterator.next();
311 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
312 } catch (IllegalArgumentException | SecurityException e) {
313 //TODO: Auto-generated catch block
314 LOG.error("Did not find the getResource method", e);
317 populateNodeLists(treeMap, list, olmList, false);
318 return new NodeLists(olmList, list);
321 private static NodeLists getNodesListAToZ(Iterator<AToZ> iterator) {
322 Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
323 List<Nodes> list = new ArrayList<>();
324 List<Nodes> olmList = new ArrayList<>();
326 while (iterator.hasNext()) {
327 AToZ pathDesObj = iterator.next();
329 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
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, true);
336 return new NodeLists(olmList, list);
339 private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
341 String resourceType = rsrc.implementedInterface().getSimpleName();
342 LOG.info("Inside {} {}", direction, resourceType);
343 switch (resourceType) {
344 case TERMINATION_POINT:
345 TerminationPoint tp = (TerminationPoint) rsrc;
346 LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
347 String tpID = tp.getTpId();
349 //TODO: do not rely on ID to be in certain format
350 if (tpID.contains("CTP") || tpID.contains("CP")) {
354 if (tpID.contains(StringConstants.TTP_TOKEN)) {
355 nodeID = tp.getTpNodeId().split("-DEG")[0];
356 } else if (tpID.contains(StringConstants.PP_TOKEN)) {
357 nodeID = tp.getTpNodeId().split("-SRG")[0];
358 } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
359 || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
360 nodeID = tp.getTpNodeId().split("-XPDR")[0];
364 int id = Integer.parseInt(sortId);
365 treeMap.put(id, new NodeIdPair(nodeID, tpID));
368 LOG.info("The type is link");
371 LOG.info("The type is not identified: {}", resourceType);
376 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
377 value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
378 justification = "loop when value is not always null - "
379 + "TODO: check if something exists in Java lib")
380 private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
384 LOG.info("treeMap values = {}", treeMap.values());
385 for (NodeIdPair values : treeMap.values()) {
387 srcID = values.getTpID();
388 } else if (desID == null) {
389 desID = values.getTpID();
390 NodesBuilder olmNb = new NodesBuilder()
391 .setNodeId(values.getNodeID())
394 olmList.add(olmNb.build());
395 if (srcID.isEmpty()) {
398 if (desID.isEmpty()) {
399 desID = new StringBuilder(srcID).toString();
403 NodesBuilder nb = new NodesBuilder()
404 .withKey(new NodesKey(values.getNodeID()))
407 if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
408 nb.setDestTp(srcID).setSrcTp(desID);
410 list.add(nb.build());
412 if (srcID != null && desID != null && !srcID.contains(StringConstants.NETWORK_TOKEN)
413 && !desID.contains(StringConstants.NETWORK_TOKEN)) {
414 NodesBuilder nb = new NodesBuilder()
415 .withKey(new NodesKey(values.getNodeID()))
418 list.add(nb.build());
424 LOG.warn("both, the source and destination id are not null!");
429 private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
430 String anodeId = null;
434 anodeId = extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId");
435 sapi = PortMappingUtils.fnv1size64(
436 String.join("-", anodeId, extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
437 dapi = PortMappingUtils.fnv1size64(
438 String.join("-", extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
439 extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
441 anodeId = extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId");
442 sapi = PortMappingUtils.fnv1size64(
443 String.join("-", anodeId, extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
444 dapi = PortMappingUtils.fnv1size64(
445 String.join("-", extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
446 extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
448 return new AEndApiInfoBuilder()
450 .setExpectedDapi(sapi)
452 .setExpectedSapi(dapi)
457 private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
458 String znodeId = null;
462 znodeId = extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId");
463 sapi = PortMappingUtils.fnv1size64(
464 String.join("-", znodeId, extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
465 dapi = PortMappingUtils.fnv1size64(
466 String.join("-", extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
467 extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
469 znodeId = extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId");
470 sapi = PortMappingUtils.fnv1size64(
471 String.join("-", znodeId, extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
472 dapi = PortMappingUtils.fnv1size64(
473 String.join("-", extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
474 extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
476 return new ZEndApiInfoBuilder()
478 .setExpectedDapi(sapi)
480 .setExpectedSapi(dapi)
485 private static Map<String, String> extractAendFromPathDescriptionForOtn(PathDescription pathDescription) {
486 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
487 .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
488 .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
490 .collect(Collectors.toList());
491 for (AToZ atoZ : tpList) {
492 TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
493 if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
494 String nodeId = tp.getTpNodeId();
495 String lcp = tp.getTpId();
496 return Map.of("nodeId", nodeId, "tpid", lcp);
502 private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
503 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().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 (ZToA ztoA : tpList) {
509 TerminationPoint tp = (TerminationPoint) ztoA.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> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
520 List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().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 (AToZ atoZ : tpList) {
526 TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
527 if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
528 // String nodeId = tp.getTpNodeId();
529 // String lcp = tp.getTpId();
530 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
536 private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
537 List<ZToA> tpList = pathDescription.getZToADirection().getZToA().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 (ZToA ztoA : tpList) {
543 TerminationPoint tp = (TerminationPoint) ztoA.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());