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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.math.BigDecimal;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.List;
18 import java.util.Optional;
20 import java.util.concurrent.ExecutionException;
21 import java.util.stream.Collectors;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.transportpce.common.NetworkUtils;
24 import org.opendaylight.transportpce.common.ResponseCodes;
25 import org.opendaylight.transportpce.common.StringConstants;
26 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
27 import org.opendaylight.transportpce.common.mapping.MappingUtils;
28 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
29 import org.opendaylight.transportpce.common.mapping.PortMapping;
30 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
31 import org.opendaylight.transportpce.common.service.ServiceTypes;
32 import org.opendaylight.transportpce.pce.PceComplianceCheck;
33 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.PathComputationRequestInput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mc.capabilities.McCapabilities;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
51 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 import org.opendaylight.yangtools.yang.common.Uint32;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 public class PceCalculation {
58 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
59 private NetworkTransactionService networkTransactionService = null;
61 ///////////// data parsed from Input/////////////////
62 private PathComputationRequestInput input;
63 private String anodeId = "";
64 private String znodeId = "";
65 private String serviceFormatA = "";
66 private String serviceFormatZ = "";
67 private String serviceType = "";
68 private Uint32 serviceRate = Uint32.valueOf(0);
70 private PceConstraints pceHardConstraints;
72 ///////////// Intermediate data/////////////////
73 private List<PceLink> addLinks = new ArrayList<>();
74 private List<PceLink> dropLinks = new ArrayList<>();
75 private HashSet<NodeId> azSrgs = new HashSet<>();
77 private PceNode aendPceNode = null;
78 private PceNode zendPceNode = null;
80 private List<Link> allLinks = null;
81 private List<Node> allNodes = null;
83 // this List serves graph calculation
84 private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
85 // this List serves calculation of ZtoA path description
86 // TODO maybe better solution is possible
87 private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
88 private Set<LinkId> linksToExclude = new HashSet<>();
89 private PceResult returnStructure;
90 private PortMapping portMapping;
92 private enum ConstraintTypes {
93 NONE, HARD_EXCLUDE, HARD_INCLUDE, HARD_DIVERSITY, SOFT_EXCLUDE, SOFT_INCLUDE, SOFT_DIVERSITY;
96 private MappingUtils mappingUtils;
98 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
99 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc,
100 PortMapping portMapping) {
102 this.networkTransactionService = networkTransactionService;
103 this.returnStructure = rc;
105 this.pceHardConstraints = pceHardConstraints;
106 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
107 this.portMapping = portMapping;
111 public void retrievePceNetwork() {
113 LOG.info("In PceCalculation retrieveNetwork: ");
116 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
119 MapUtils.mapDiversityConstraints(allNodes, allLinks, pceHardConstraints);
122 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
125 printNodesInfo(allPceNodes);
127 returnStructure.setRC(ResponseCodes.RESPONSE_OK);
131 private boolean parseInput() {
132 if (!PceComplianceCheck.checkString(input.getServiceAEnd().getServiceFormat().getName())
133 || !PceComplianceCheck.checkString(input.getServiceZEnd().getServiceFormat().getName())
134 || !PceComplianceCheck.checkString(input.getServiceAEnd().getServiceRate().toString())) {
135 LOG.error("Service Format and Service Rate are required for a path calculation");
138 serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
139 serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
140 serviceRate = input.getServiceAEnd().getServiceRate();
141 serviceType = ServiceTypes.getServiceType(
144 NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
145 && checkAendInputTxPortName()
146 ? portMapping.getMapping(
147 input.getServiceAEnd().getNodeId(),
148 input.getServiceAEnd().getTxDirection().getPort().getPortName())
151 LOG.info("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
155 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
156 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
160 private boolean checkAendInputTxPortName() {
161 return checkAendInputTxPort()
162 && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null;
165 private boolean checkAendInputTxPortDeviceName() {
166 return checkAendInputTxPort()
167 && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null;
170 private boolean checkAendInputTxPort() {
171 return input.getServiceAEnd() != null
172 && input.getServiceAEnd().getTxDirection() != null
173 && input.getServiceAEnd().getTxDirection().getPort() != null;
176 private boolean checkZendInputTxPortDeviceName() {
177 return input.getServiceZEnd() != null
178 && input.getServiceZEnd().getTxDirection() != null
179 && input.getServiceZEnd().getTxDirection().getPort() != null
180 && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null;
183 private void getAZnodeId() {
185 checkAendInputTxPortDeviceName()
186 ? input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName()
187 : input.getServiceAEnd().getNodeId();
189 checkZendInputTxPortDeviceName()
190 ? input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName()
191 : input.getServiceZEnd().getNodeId();
194 private boolean readMdSal() {
195 InstanceIdentifier<Network> nwInstanceIdentifier = null;
196 switch (serviceType) {
197 case StringConstants.SERVICE_TYPE_100GE_T:
198 case StringConstants.SERVICE_TYPE_400GE:
199 case StringConstants.SERVICE_TYPE_OTU4:
200 case StringConstants.SERVICE_TYPE_OTUC2:
201 case StringConstants.SERVICE_TYPE_OTUC3:
202 case StringConstants.SERVICE_TYPE_OTUC4:
203 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
204 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
205 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
207 case StringConstants.SERVICE_TYPE_100GE_M:
208 case StringConstants.SERVICE_TYPE_100GE_S:
209 case StringConstants.SERVICE_TYPE_ODU4:
210 case StringConstants.SERVICE_TYPE_ODUC2:
211 case StringConstants.SERVICE_TYPE_ODUC3:
212 case StringConstants.SERVICE_TYPE_ODUC4:
213 case StringConstants.SERVICE_TYPE_10GE:
214 case StringConstants.SERVICE_TYPE_1GE:
215 LOG.info("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
216 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
217 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
220 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
225 if (readTopology(nwInstanceIdentifier) == null) {
226 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
230 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
231 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
232 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
234 LOG.warn("no otn links in otn-topology");
236 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
237 -> l1.getSource().getSourceTp().getValue().compareTo(l2.getSource().getSourceTp().getValue()))
238 .collect(Collectors.toList());
240 if (allNodes == null || allNodes.isEmpty()) {
241 LOG.error("readMdSal: no nodes ");
244 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
245 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
247 if (allLinks == null || allLinks.isEmpty()) {
248 LOG.error("readMdSal: no links ");
251 LOG.info("readMdSal: network links: {} links added", allLinks.size());
252 LOG.debug("readMdSal: network links: {} links added", allLinks);
257 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
260 Optional<Network> nwOptional =
261 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
262 if (nwOptional.isPresent()) {
263 nw = nwOptional.get();
264 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
265 networkTransactionService.close();
267 } catch (InterruptedException | ExecutionException e) {
268 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
269 networkTransactionService.close();
270 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
271 throw new RuntimeException(
272 "readMdSal: Error reading from operational store, topology : " + nwInstanceIdentifier + " :" + e);
277 private boolean analyzeNw() {
279 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
280 switch (serviceType) {
281 case StringConstants.SERVICE_TYPE_100GE_T:
282 case StringConstants.SERVICE_TYPE_OTU4:
283 case StringConstants.SERVICE_TYPE_400GE:
284 case StringConstants.SERVICE_TYPE_OTUC2:
285 case StringConstants.SERVICE_TYPE_OTUC3:
286 case StringConstants.SERVICE_TYPE_OTUC4:
287 // 100GE service and OTU4 service are handled at the openroadm-topology layer
288 for (Node node : allNodes) {
292 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
294 if (aendPceNode == null || zendPceNode == null) {
295 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
298 for (Link link : allLinks) {
302 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
304 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
305 for (NodeId srg : azSrgs) {
306 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
309 for (PceLink link : addLinks) {
310 filteraddLinks(link);
312 for (PceLink link : dropLinks) {
313 filterdropLinks(link);
318 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
320 for (Node node : allNodes) {
321 validateOtnNode(node);
324 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
326 if (aendPceNode == null || zendPceNode == null) {
327 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
330 for (Link link : allLinks) {
336 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
338 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
342 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
343 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
348 private boolean filteraddLinks(PceLink pcelink) {
350 NodeId nodeId = pcelink.getSourceId();
352 if (azSrgs.contains(nodeId)) {
353 allPceLinks.put(pcelink.getLinkId(), pcelink);
354 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
355 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
359 // remove the SRG from PceNodes, as it is not directly connected to A/Z
360 allPceNodes.remove(nodeId);
361 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
366 private boolean filterdropLinks(PceLink pcelink) {
368 NodeId nodeId = pcelink.getDestId();
370 if (azSrgs.contains(nodeId)) {
371 allPceLinks.put(pcelink.getLinkId(), pcelink);
372 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
373 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
377 // remove the SRG from PceNodes, as it is not directly connected to A/Z
378 allPceNodes.remove(pcelink.getDestId());
379 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
384 private boolean validateLink(Link link) {
385 LOG.info("validateLink: link {} ", link);
387 NodeId sourceId = link.getSource().getSourceNode();
388 NodeId destId = link.getDestination().getDestNode();
389 PceNode source = allPceNodes.get(sourceId);
390 PceNode dest = allPceNodes.get(destId);
391 State state = link.augmentation(Link1.class).getOperationalState();
393 if (source == null) {
394 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
395 link.getSource().getSourceNode().getValue());
399 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
400 link.getDestination().getDestNode().getValue());
404 if (State.OutOfService.equals(state)) {
405 LOG.debug("validateLink: Link is ignored due operational state - {}",
410 switch (serviceType) {
411 case StringConstants.SERVICE_TYPE_100GE_T:
412 case StringConstants.SERVICE_TYPE_OTU4:
413 case StringConstants.SERVICE_TYPE_OTUC2:
414 case StringConstants.SERVICE_TYPE_OTUC3:
415 case StringConstants.SERVICE_TYPE_OTUC4:
416 case StringConstants.SERVICE_TYPE_400GE:
417 return processPceLink(link, sourceId, destId, source, dest);
418 case StringConstants.SERVICE_TYPE_ODU4:
419 case StringConstants.SERVICE_TYPE_10GE:
420 case StringConstants.SERVICE_TYPE_100GE_M:
421 case StringConstants.SERVICE_TYPE_100GE_S:
422 case StringConstants.SERVICE_TYPE_ODUC2:
423 case StringConstants.SERVICE_TYPE_ODUC3:
424 case StringConstants.SERVICE_TYPE_ODUC4:
425 case StringConstants.SERVICE_TYPE_1GE:
426 return processPceOtnLink(link, source, dest);
428 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
433 private void validateNode(Node node) {
434 LOG.info("validateNode: node {} ", node);
435 // PceNode will be used in Graph algorithm
436 Node1 node1 = node.augmentation(Node1.class);
438 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
441 if (State.OutOfService.equals(node1.getOperationalState())) {
442 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
446 OpenroadmNodeType nodeType = node1.getNodeType();
447 String deviceNodeId = MapUtils.getSupNetworkNode(node);
448 // Should never happen but because of existing topology test files
449 // we have to manage this case
450 if (deviceNodeId == null || deviceNodeId.isBlank()) {
451 deviceNodeId = node.getNodeId().getValue();
454 LOG.info("Device node id {} for {}", deviceNodeId, node);
455 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
456 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
457 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
458 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
459 pceNode.initFrequenciesBitSet();
461 if (!pceNode.isValid()) {
462 LOG.warn(" validateNode: Node is ignored");
465 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
469 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode)) {
470 if (this.aendPceNode == null && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
471 // Added to ensure A-node has a addlink in the topology
472 List<Link> links = this.allLinks.stream()
473 .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
474 .collect(Collectors.toList());
475 if (links.size() > 0) {
476 this.aendPceNode = pceNode;
479 if (this.zendPceNode == null && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
480 // Added to ensure Z-node has a droplink in the topology
481 List<Link> links = this.allLinks.stream()
482 .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
483 .collect(Collectors.toList());
484 if (links.size() > 0) {
485 this.zendPceNode = pceNode;
490 allPceNodes.put(pceNode.getNodeId(), pceNode);
491 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
495 @SuppressWarnings("fallthrough")
497 value = "SF_SWITCH_FALLTHROUGH",
498 justification = "intentional fallthrough")
499 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
500 switch (serviceFormat) {
503 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
508 switch (azEndPoint) {
510 return checkAendInputTxPortDeviceName()
511 && pceNode.getNodeId().getValue()
512 .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName());
514 return checkZendInputTxPortDeviceName()
515 && pceNode.getNodeId().getValue()
516 .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName());
521 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
526 private void validateOtnNode(Node node) {
527 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
528 // PceOtnNode will be used in Graph algorithm
529 if (node.augmentation(Node1.class) == null) {
530 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
534 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
535 String clientPort = null;
536 if (node.getNodeId().getValue().equals(anodeId)
537 && this.aendPceNode == null
538 && input.getServiceAEnd() != null
539 && input.getServiceAEnd().getRxDirection() != null
540 && input.getServiceAEnd().getRxDirection().getPort() != null
541 && input.getServiceAEnd().getRxDirection().getPort().getPortName() != null) {
542 clientPort = input.getServiceAEnd().getRxDirection().getPort().getPortName();
543 } else if (node.getNodeId().getValue().equals(znodeId)
544 && this.zendPceNode == null
545 && input.getServiceZEnd() != null
546 && input.getServiceZEnd().getRxDirection() != null
547 && input.getServiceZEnd().getRxDirection().getPort() != null
548 && input.getServiceZEnd().getRxDirection().getPort().getPortName() != null) {
549 clientPort = input.getServiceZEnd().getRxDirection().getPort().getPortName();
552 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType, clientPort);
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());
573 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
574 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
575 return ConstraintTypes.NONE;
577 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
578 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
579 return ConstraintTypes.HARD_EXCLUDE;
581 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
582 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
583 return ConstraintTypes.HARD_EXCLUDE;
585 return ConstraintTypes.NONE;
588 private ConstraintTypes validateLinkConstraints(PceLink link) {
589 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
590 return ConstraintTypes.NONE;
593 // for now SRLG is the only constraint for link
594 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
595 return ConstraintTypes.NONE;
598 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
599 constraints.retainAll(link.getsrlgList());
600 if (!constraints.isEmpty()) {
601 LOG.info("validateLinkConstraints: {}", link.getLinkId().getValue());
602 return ConstraintTypes.HARD_EXCLUDE;
605 return ConstraintTypes.NONE;
608 private void dropOppositeLink(Link link) {
609 LinkId opplink = MapUtils.extractOppositeLink(link);
611 if (allPceLinks.containsKey(opplink)) {
612 allPceLinks.remove(opplink);
614 linksToExclude.add(opplink);
618 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
619 switch (openroadmNodeType) {
621 pceNode.initSrgTps();
622 this.azSrgs.add(nodeId);
625 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
628 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
632 if (!pceNode.isValid()) {
633 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
639 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
640 PceLink pcelink = new PceLink(link, source, dest);
641 if (!pcelink.isValid()) {
642 dropOppositeLink(link);
643 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
646 LinkId linkId = pcelink.getLinkId();
647 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
648 dropOppositeLink(link);
649 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
652 switch (pcelink.getlinkType()) {
655 allPceLinks.put(linkId, pcelink);
656 source.addOutgoingLink(pcelink);
657 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
658 pcelink.getlinkType(), pcelink);
662 source.getRdmSrgClient(pcelink.getSourceTP().getValue(), StringConstants.SERVICE_DIRECTION_AZ));
663 addLinks.add(pcelink);
664 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
668 dest.getRdmSrgClient(pcelink.getDestTP().getValue(), StringConstants.SERVICE_DIRECTION_ZA));
669 dropLinks.add(pcelink);
670 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
673 // store separately all SRG links directly
674 azSrgs.add(sourceId);
676 if (!dest.checkTP(pcelink.getDestTP().getValue())) {
678 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
681 if (dest.getXpdrClient(pcelink.getDestTP().getValue()) != null) {
682 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().getValue()));
684 allPceLinks.put(linkId, pcelink);
685 source.addOutgoingLink(pcelink);
686 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
688 // does it mean XPONDER==>>SRG ?
690 // store separately all SRG links directly
693 if (!source.checkTP(pcelink.getSourceTP().getValue())) {
695 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
698 if (source.getXpdrClient(pcelink.getSourceTP().getValue()) != null) {
699 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().getValue()));
701 allPceLinks.put(linkId, pcelink);
702 source.addOutgoingLink(pcelink);
703 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
706 LOG.warn("validateLink: link type is not supported {}", pcelink);
711 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
712 PceLink pceOtnLink = new PceLink(link, source, dest);
714 if (!pceOtnLink.isOtnValid(link, serviceType)) {
715 dropOppositeLink(link);
716 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
720 LinkId linkId = pceOtnLink.getLinkId();
721 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
722 dropOppositeLink(link);
723 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
727 switch (pceOtnLink.getlinkType()) {
729 if (source.getXpdrClient(pceOtnLink.getSourceTP().getValue()) != null) {
730 pceOtnLink.setClient(source.getXpdrClient(pceOtnLink.getSourceTP().getValue()));
732 if (dest.getXpdrClient(pceOtnLink.getDestTP().getValue()) != null) {
733 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().getValue()));
735 allPceLinks.put(linkId, pceOtnLink);
736 source.addOutgoingLink(pceOtnLink);
737 LOG.info("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
740 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
745 public PceNode getaendPceNode() {
749 public PceNode getzendPceNode() {
753 public Map<NodeId, PceNode> getAllPceNodes() {
754 return this.allPceNodes;
757 public Map<LinkId, PceLink> getAllPceLinks() {
758 return this.allPceLinks;
761 public String getServiceType() {
765 public PceResult getReturnStructure() {
766 return returnStructure;
769 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
770 allPceNodes.forEach(((nodeId, pceNode) -> {
771 LOG.info("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
772 pceNode.getOutgoingLinks());
777 * Get mc capability slot width granularity for device.
778 * @param deviceNodeId String
779 * @param nodeId NodeId
780 * @return slot width granularity
782 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
783 // nodeId: openroadm-topology level node
784 // deviceNodeId: openroadm-network level node
785 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
786 String[] params = nodeId.getValue().split("-");
787 // DEGx or SRGx or XPDRx
788 String moduleName = params[params.length - 1];
789 for (McCapabilities mcCapabitility : mcCapabilities) {
790 if (mcCapabitility.getMcNodeName().contains("XPDR")
791 && mcCapabitility.getSlotWidthGranularity() != null) {
792 return mcCapabitility.getSlotWidthGranularity().getValue();
794 if (mcCapabitility.getMcNodeName().contains(moduleName)
795 && mcCapabitility.getSlotWidthGranularity() != null) {
796 return mcCapabitility.getSlotWidthGranularity().getValue();
799 return GridConstant.SLOT_WIDTH_50;
803 * Get mc capability central-width granularity for device.
804 * @param deviceNodeId String
805 * @param nodeId NodeId
806 * @return center-freq granularity
808 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
809 // nodeId: openroadm-topology level node
810 // deviceNodeId: openroadm-network level node
811 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
812 String[] params = nodeId.getValue().split("-");
813 // DEGx or SRGx or XPDRx
814 String moduleName = params[params.length - 1];
815 for (McCapabilities mcCapabitility : mcCapabilities) {
816 if (mcCapabitility.getMcNodeName().contains("XPDR")
817 && mcCapabitility.getCenterFreqGranularity() != null) {
818 return mcCapabitility.getCenterFreqGranularity().getValue();
820 if (mcCapabitility.getMcNodeName().contains(moduleName)
821 && mcCapabitility.getCenterFreqGranularity() != null) {
822 return mcCapabitility.getCenterFreqGranularity().getValue();
825 return GridConstant.SLOT_WIDTH_50;