2 * Copyright © 2017 AT&T, Inc. 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
9 package org.opendaylight.transportpce.pce.networkanalyzer;
11 import java.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.List;
17 import java.util.Optional;
19 import java.util.concurrent.ExecutionException;
20 import java.util.stream.Collectors;
21 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
22 import org.opendaylight.transportpce.common.NetworkUtils;
23 import org.opendaylight.transportpce.common.ResponseCodes;
24 import org.opendaylight.transportpce.common.StringConstants;
25 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
26 import org.opendaylight.transportpce.common.mapping.MappingUtils;
27 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
28 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
29 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.McCapabilities;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 public class PceCalculation {
50 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
51 private NetworkTransactionService networkTransactionService = null;
53 ///////////// data parsed from Input/////////////////
54 private PathComputationRequestInput input;
55 private String anodeId = "";
56 private String znodeId = "";
57 private String serviceFormatA = "";
58 private String serviceFormatZ = "";
59 private String serviceType = "";
60 private Long serviceRate = 0L;
62 private PceConstraints pceHardConstraints;
64 ///////////// Intermediate data/////////////////
65 private List<PceLink> addLinks = new ArrayList<>();
66 private List<PceLink> dropLinks = new ArrayList<>();
67 private HashSet<NodeId> azSrgs = new HashSet<>();
69 private PceNode aendPceNode = null;
70 private PceNode zendPceNode = null;
72 private List<Link> allLinks = null;
73 private List<Node> allNodes = null;
75 // this List serves graph calculation
76 private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
77 // this List serves calculation of ZtoA path description
78 // TODO maybe better solution is possible
79 private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
80 private Set<LinkId> linksToExclude = new HashSet<>();
81 private PceResult returnStructure;
83 private enum ConstraintTypes {
84 NONE, HARD_EXCLUDE, HARD_INCLUDE, HARD_DIVERSITY, SOFT_EXCLUDE, SOFT_INCLUDE, SOFT_DIVERSITY;
87 private MappingUtils mappingUtils;
89 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
90 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc) {
92 this.networkTransactionService = networkTransactionService;
93 this.returnStructure = rc;
95 this.pceHardConstraints = pceHardConstraints;
96 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
100 public void retrievePceNetwork() {
102 LOG.info("In PceCalculation retrieveNetwork: ");
105 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
108 MapUtils.mapDiversityConstraints(allNodes, allLinks, pceHardConstraints);
111 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
114 printNodesInfo(allPceNodes);
116 returnStructure.setRC(ResponseCodes.RESPONSE_OK);
120 private boolean parseInput() {
121 if (input.getServiceAEnd().getServiceFormat() == null || input.getServiceZEnd().getServiceFormat() == null
122 || input.getServiceAEnd().getServiceRate() == null) {
123 LOG.error("Service Format and Service Rate are required for a path calculation");
126 serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
127 serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
128 serviceRate = input.getServiceAEnd().getServiceRate().toJava();
130 LOG.info("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
131 if (!(serviceFormatA.equals(serviceFormatZ))) {
132 LOG.info("parseInput: different service format for A and Z not handled, will use service format from Aend");
133 } else if (serviceRate == 100L) {
134 switch (serviceFormatA) {
137 serviceType = StringConstants.SERVICE_TYPE_100GE;
140 serviceType = StringConstants.SERVICE_TYPE_OTU4;
143 serviceType = StringConstants.SERVICE_TYPE_ODU4;
146 LOG.debug("parseInput: unsupported service type: Format {} Rate 100L", serviceFormatA);
149 //switch(serviceRate) may seem a better option at first glance.
150 //But switching on Long or long is not directly possible in Java.
151 //And casting to int bumps the limit here.
152 //Passing by ENUM or String are possible alternatives.
153 //Maybe HashMap and similar options should also be considered here.
154 } else if ("Ethernet".equals(serviceFormatA)) {
155 //only rate 100L is currently supported except in Ethernet
156 if (serviceRate == 10L) {
157 serviceType = StringConstants.SERVICE_TYPE_10GE;
158 } else if (serviceRate == 1L) {
159 serviceType = StringConstants.SERVICE_TYPE_1GE;
161 LOG.debug("parseInput: unsupported service type: Format Ethernet Rate {}", serviceRate);
164 LOG.debug("parseInput: unsupported service type: Format {} Rate {}",
165 serviceFormatA, serviceRate);
167 if (StringConstants.SERVICE_TYPE_ODU4.equals(serviceType)
168 || StringConstants.SERVICE_TYPE_10GE.equals(serviceType)
169 || StringConstants.SERVICE_TYPE_1GE.equals(serviceType)) {
170 anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
171 znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
173 anodeId = input.getServiceAEnd().getNodeId();
174 znodeId = input.getServiceZEnd().getNodeId();
177 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
178 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
182 private boolean readMdSal() {
183 InstanceIdentifier<Network> nwInstanceIdentifier = null;
185 if (("OC".equals(serviceFormatA)) || ("OTU".equals(serviceFormatA)) || (("Ethernet".equals(serviceFormatA))
186 && (serviceRate == 100L))) {
188 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
189 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
190 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
191 } else if ("ODU".equals(serviceFormatA) || ("Ethernet".equals(serviceFormatA) && serviceRate == 10L)
192 || ("Ethernet".equals(serviceFormatA) && serviceRate == 1L)) {
193 LOG.info("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
194 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
195 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
197 LOG.info("readMdSal: service-rate {} / service-format not handled {}", serviceRate, serviceFormatA);
202 Optional<Network> nwOptional =
203 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
204 if (nwOptional.isPresent()) {
205 nw = nwOptional.get();
206 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
208 } catch (InterruptedException | ExecutionException e) {
209 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
210 networkTransactionService.close();
211 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
212 throw new RuntimeException(
213 "readMdSal: Error reading from operational store, topology : " + nwInstanceIdentifier + " :" + e);
215 networkTransactionService.close();
218 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
221 allNodes = nw.nonnullNode().values().stream().sorted((n1, n2)
222 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
223 Network1 nw1 = nw.augmentation(Network1.class);
225 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
226 -> l1.getSource().getSourceTp().toString().compareTo(l2.getSource().getSourceTp().toString()))
227 .collect(Collectors.toList());
229 LOG.warn("no otn links in otn-topology");
231 if (allNodes == null || allNodes.isEmpty()) {
232 LOG.error("readMdSal: no nodes ");
235 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
236 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
238 if (allLinks == null || allLinks.isEmpty()) {
239 LOG.error("readMdSal: no links ");
242 LOG.info("readMdSal: network links: {} links added", allLinks.size());
243 LOG.debug("readMdSal: network links: {} links added", allLinks);
248 private boolean analyzeNw() {
250 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
252 if ((StringConstants.SERVICE_TYPE_100GE.equals(serviceType))
253 || (StringConstants.SERVICE_TYPE_OTU4.equals(serviceType))) {
254 // 100GE service and OTU4 service are handled at the openroadm-topology layer
255 for (Node node : allNodes) {
259 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
261 if (aendPceNode == null || zendPceNode == null) {
262 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
265 for (Link link : allLinks) {
269 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
271 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
272 for (NodeId srg : azSrgs) {
273 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
276 for (PceLink link : addLinks) {
277 filteraddLinks(link);
279 for (PceLink link : dropLinks) {
280 filterdropLinks(link);
284 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
286 for (Node node : allNodes) {
287 validateOtnNode(node);
290 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
292 if (aendPceNode == null || zendPceNode == null) {
293 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
296 for (Link link : allLinks) {
301 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
303 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
307 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
308 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
313 private boolean filteraddLinks(PceLink pcelink) {
315 NodeId nodeId = pcelink.getSourceId();
317 if (azSrgs.contains(nodeId)) {
318 allPceLinks.put(pcelink.getLinkId(), pcelink);
319 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
320 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
324 // remove the SRG from PceNodes, as it is not directly connected to A/Z
325 allPceNodes.remove(nodeId);
326 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
331 private boolean filterdropLinks(PceLink pcelink) {
333 NodeId nodeId = pcelink.getDestId();
335 if (azSrgs.contains(nodeId)) {
336 allPceLinks.put(pcelink.getLinkId(), pcelink);
337 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
338 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
342 // remove the SRG from PceNodes, as it is not directly connected to A/Z
343 allPceNodes.remove(pcelink.getDestId());
344 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
349 private boolean validateLink(Link link) {
350 LOG.info("validateLink: link {} ", link);
352 NodeId sourceId = link.getSource().getSourceNode();
353 NodeId destId = link.getDestination().getDestNode();
354 PceNode source = allPceNodes.get(sourceId);
355 PceNode dest = allPceNodes.get(destId);
357 if (source == null) {
358 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
359 link.getSource().getSourceNode().getValue());
363 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
364 link.getDestination().getDestNode().getValue());
368 if ((StringConstants.SERVICE_TYPE_100GE.equals(serviceType))
369 || (StringConstants.SERVICE_TYPE_OTU4.equals(serviceType))) {
370 // 100GE or OTU4 services are handled at WDM Layer
371 PceLink pcelink = new PceLink(link, source, dest);
372 if (!pcelink.isValid()) {
373 dropOppositeLink(link);
374 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
377 LinkId linkId = pcelink.getLinkId();
378 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
379 dropOppositeLink(link);
380 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
383 switch (pcelink.getlinkType()) {
386 allPceLinks.put(linkId, pcelink);
387 source.addOutgoingLink(pcelink);
388 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
389 pcelink.getlinkType(), pcelink);
392 pcelink.setClient(source.getRdmSrgClient(pcelink.getSourceTP().toString()));
393 addLinks.add(pcelink);
394 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
397 pcelink.setClient(dest.getRdmSrgClient(pcelink.getDestTP().toString()));
398 dropLinks.add(pcelink);
399 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
402 // store separately all SRG links directly
403 azSrgs.add(sourceId);
405 if (!dest.checkTP(pcelink.getDestTP().toString())) {
407 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
410 if (dest.getXpdrClient(pcelink.getDestTP().toString()) != null) {
411 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().toString()));
413 allPceLinks.put(linkId, pcelink);
414 source.addOutgoingLink(pcelink);
415 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
417 // does it mean XPONDER==>>SRG ?
419 // store separately all SRG links directly
422 if (!source.checkTP(pcelink.getSourceTP().toString())) {
424 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
427 if (source.getXpdrClient(pcelink.getSourceTP().toString()) != null) {
428 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().toString()));
430 allPceLinks.put(linkId, pcelink);
431 source.addOutgoingLink(pcelink);
432 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
435 LOG.warn("validateLink: link type is not supported {}", pcelink);
439 } else if ((StringConstants.SERVICE_TYPE_ODU4.equals(serviceType))
440 || (StringConstants.SERVICE_TYPE_10GE.equals(serviceType))
441 || (StringConstants.SERVICE_TYPE_1GE.equals(serviceType))) {
442 // ODU4, 1GE and 10GE services relying on ODU2, ODU2e or ODU0 services are handled at OTN layer
443 PceLink pceOtnLink = new PceLink(link, source, dest);
445 if (!pceOtnLink.isOtnValid(link, serviceType)) {
446 dropOppositeLink(link);
447 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
451 LinkId linkId = pceOtnLink.getLinkId();
452 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
453 dropOppositeLink(link);
454 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
458 switch (pceOtnLink.getlinkType()) {
460 if (dest.getXpdrClient(pceOtnLink.getDestTP().toString()) != null) {
461 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().toString()));
464 allPceLinks.put(linkId, pceOtnLink);
465 source.addOutgoingLink(pceOtnLink);
466 LOG.info("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
469 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
474 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
480 private boolean validateNode(Node node) {
481 LOG.debug("validateNode: node {} ", node);
482 // PceNode will be used in Graph algorithm
483 Node1 node1 = node.augmentation(Node1.class);
485 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
488 OpenroadmNodeType nodeType = node1.getNodeType();
489 String deviceNodeId = MapUtils.getSupNetworkNode(node);
490 // Should never happen but because of existing topology test files
491 // we have to manage this case
492 if (deviceNodeId == null || deviceNodeId.isBlank()) {
493 deviceNodeId = node.getNodeId().getValue();
495 LOG.info("Device node id {} for {}", deviceNodeId, node);
496 PceOpticalNode pceNode = new PceOpticalNode(node, nodeType, mappingUtils.getOpenRoadmVersion(deviceNodeId),
497 getSlotWidthGranularity(deviceNodeId, node.getNodeId()));
498 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
499 pceNode.initFrequenciesBitSet();
501 if (!pceNode.isValid()) {
502 LOG.warn(" validateNode: Node is ignored");
505 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
508 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.aendPceNode == null
509 && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
510 this.aendPceNode = pceNode;
512 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.zendPceNode == null
513 && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
514 this.zendPceNode = pceNode;
517 allPceNodes.put(pceNode.getNodeId(), pceNode);
518 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
522 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
523 switch (serviceFormat) {
526 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
531 if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue()
532 .equals(this.input.getServiceAEnd().getRxDirection().getPort().getPortDeviceName())) {
535 if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue()
536 .equals(this.input.getServiceZEnd().getRxDirection().getPort().getPortDeviceName())) {
541 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
546 private boolean validateOtnNode(Node node) {
547 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
548 // PceOtnNode will be used in Graph algorithm
549 if (node.augmentation(Node1.class) != null) {
550 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
552 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType);
553 pceOtnNode.validateXponder(anodeId, znodeId);
555 if (!pceOtnNode.isValid()) {
556 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
559 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
562 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
563 this.aendPceNode = pceOtnNode;
565 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
566 this.zendPceNode = pceOtnNode;
568 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
569 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
572 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
577 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
578 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
579 return ConstraintTypes.NONE;
581 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
582 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
583 return ConstraintTypes.HARD_EXCLUDE;
585 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
586 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
587 return ConstraintTypes.HARD_EXCLUDE;
589 return ConstraintTypes.NONE;
592 private ConstraintTypes validateLinkConstraints(PceLink link) {
593 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
594 return ConstraintTypes.NONE;
597 // for now SRLG is the only constraint for link
598 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
599 return ConstraintTypes.NONE;
602 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
603 constraints.retainAll(link.getsrlgList());
604 if (!constraints.isEmpty()) {
605 LOG.info("validateLinkConstraints: {}", link.getLinkId().getValue());
606 return ConstraintTypes.HARD_EXCLUDE;
609 return ConstraintTypes.NONE;
612 private void dropOppositeLink(Link link) {
613 LinkId opplink = MapUtils.extractOppositeLink(link);
615 if (allPceLinks.containsKey(opplink)) {
616 allPceLinks.remove(opplink);
618 linksToExclude.add(opplink);
622 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
623 switch (openroadmNodeType) {
625 pceNode.initSrgTps();
626 this.azSrgs.add(nodeId);
629 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
632 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
636 if (!pceNode.isValid()) {
637 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
643 public PceNode getaendPceNode() {
647 public PceNode getzendPceNode() {
651 public Map<NodeId, PceNode> getAllPceNodes() {
652 return this.allPceNodes;
655 public Map<LinkId, PceLink> getAllPceLinks() {
656 return this.allPceLinks;
659 public String getServiceType() {
663 public PceResult getReturnStructure() {
664 return returnStructure;
667 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
668 allPceNodes.forEach(((nodeId, pceNode) -> {
669 LOG.info("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
670 pceNode.getOutgoingLinks());
675 * Get mc capability slot width granularity for device.
676 * @param deviceNodeId String
677 * @param nodeId NodeId
678 * @return slot width granularity
680 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
681 // nodeId: openroadm-topology level node
682 // deviceNodeId: openroadm-network level node
683 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
684 String[] params = nodeId.getValue().split("-");
686 String rdmModuleName = params[params.length - 1];
687 for (McCapabilities mcCapabitility : mcCapabilities) {
688 if (mcCapabitility.getMcNodeName().contains(rdmModuleName)
689 && mcCapabitility.getSlotWidthGranularity() != null) {
690 return mcCapabitility.getSlotWidthGranularity().getValue();
693 return GridConstant.SLOT_WIDTH_50;