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.List;
17 import java.util.Optional;
18 import java.util.concurrent.ExecutionException;
19 import java.util.stream.Collectors;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.transportpce.common.NetworkUtils;
22 import org.opendaylight.transportpce.common.ResponseCodes;
23 import org.opendaylight.transportpce.common.StringConstants;
24 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
25 import org.opendaylight.transportpce.common.mapping.MappingUtils;
26 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
27 import org.opendaylight.transportpce.common.mapping.PortMapping;
28 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
29 import org.opendaylight.transportpce.common.service.ServiceTypes;
30 import org.opendaylight.transportpce.pce.PceComplianceCheck;
31 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.computation.reroute.request.input.Endpoints;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mc.capabilities.McCapabilities;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Link1;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmLinkType;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.opendaylight.yangtools.yang.common.Uint32;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
55 public class PceCalculation {
57 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
58 private NetworkTransactionService networkTransactionService;
60 ///////////// data parsed from Input/////////////////
61 private PathComputationRequestInput input;
62 private String anodeId = "";
63 private String znodeId = "";
64 private String serviceFormatA = "";
65 private String serviceFormatZ = "";
66 private String serviceType = "";
67 private Uint32 serviceRate = Uint32.valueOf(0);
69 private PceConstraints pceHardConstraints;
71 ///////////// Intermediate data/////////////////
72 private List<PceLink> addLinks = new ArrayList<>();
73 private List<PceLink> dropLinks = new ArrayList<>();
74 private List<NodeId> azSrgs = new ArrayList<>();
76 private PceNode aendPceNode = null;
77 private PceNode zendPceNode = null;
79 private List<Link> allLinks = null;
80 private List<Node> allNodes = null;
82 // this List serves graph calculation
83 private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
84 // this List serves calculation of ZtoA path description
85 // TODO maybe better solution is possible
86 private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
87 private List<LinkId> linksToExclude = new ArrayList<>();
88 private PceResult returnStructure;
89 private PortMapping portMapping;
90 // Define the termination points whose reservation status is not taken into account during the pruning process
91 private Endpoints endpoints;
93 private enum ConstraintTypes {
94 NONE, HARD_EXCLUDE, HARD_INCLUDE, HARD_DIVERSITY, SOFT_EXCLUDE, SOFT_INCLUDE, SOFT_DIVERSITY;
97 private MappingUtils mappingUtils;
99 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
100 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc,
101 PortMapping portMapping) {
103 this.networkTransactionService = networkTransactionService;
104 this.returnStructure = rc;
105 this.pceHardConstraints = pceHardConstraints;
106 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
107 this.portMapping = portMapping;
108 this.endpoints = null;
112 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
113 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc,
114 PortMapping portMapping, Endpoints endpoints) {
116 this.networkTransactionService = networkTransactionService;
117 this.returnStructure = rc;
118 this.pceHardConstraints = pceHardConstraints;
119 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
120 this.portMapping = portMapping;
121 this.endpoints = endpoints;
125 public void retrievePceNetwork() {
127 LOG.debug("In PceCalculation retrieveNetwork");
130 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
133 MapUtils.mapDiversityConstraints(allNodes, allLinks, pceHardConstraints);
136 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
139 printNodesInfo(allPceNodes);
141 returnStructure.setRC(ResponseCodes.RESPONSE_OK);
144 private boolean parseInput() {
145 if (!PceComplianceCheck.checkString(input.getServiceAEnd().getServiceFormat().getName())
146 || !PceComplianceCheck.checkString(input.getServiceZEnd().getServiceFormat().getName())
147 || !PceComplianceCheck.checkString(input.getServiceAEnd().getServiceRate().toString())) {
148 LOG.error("Service Format and Service Rate are required for a path calculation");
151 serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
152 serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
153 serviceRate = input.getServiceAEnd().getServiceRate();
154 serviceType = ServiceTypes.getServiceType(
157 NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
158 && checkAendInputTxPortName()
159 ? portMapping.getMapping(
160 input.getServiceAEnd().getNodeId(),
161 input.getServiceAEnd().getTxDirection().getPort().getPortName())
164 LOG.debug("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
168 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
169 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
173 private boolean checkAendInputTxPortName() {
174 return checkAendInputTxPort()
175 && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null;
178 private boolean checkAendInputTxPortDeviceName() {
179 return checkAendInputTxPort()
180 && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null;
183 private boolean checkAendInputTxPort() {
184 return input.getServiceAEnd() != null
185 && input.getServiceAEnd().getTxDirection() != null
186 && input.getServiceAEnd().getTxDirection().getPort() != null;
189 private boolean checkZendInputTxPortDeviceName() {
190 return input.getServiceZEnd() != null
191 && input.getServiceZEnd().getTxDirection() != null
192 && input.getServiceZEnd().getTxDirection().getPort() != null
193 && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null;
196 private void getAZnodeId() {
198 checkAendInputTxPortDeviceName()
199 ? input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName()
200 : input.getServiceAEnd().getNodeId();
202 checkZendInputTxPortDeviceName()
203 ? input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName()
204 : input.getServiceZEnd().getNodeId();
207 private boolean readMdSal() {
208 InstanceIdentifier<Network> nwInstanceIdentifier = null;
209 switch (serviceType) {
210 case StringConstants.SERVICE_TYPE_100GE_T:
211 case StringConstants.SERVICE_TYPE_400GE:
212 case StringConstants.SERVICE_TYPE_OTU4:
213 case StringConstants.SERVICE_TYPE_OTUC2:
214 case StringConstants.SERVICE_TYPE_OTUC3:
215 case StringConstants.SERVICE_TYPE_OTUC4:
216 LOG.debug("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
217 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
218 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
220 case StringConstants.SERVICE_TYPE_100GE_M:
221 case StringConstants.SERVICE_TYPE_100GE_S:
222 case StringConstants.SERVICE_TYPE_ODU4:
223 case StringConstants.SERVICE_TYPE_ODUC2:
224 case StringConstants.SERVICE_TYPE_ODUC3:
225 case StringConstants.SERVICE_TYPE_ODUC4:
226 case StringConstants.SERVICE_TYPE_10GE:
227 case StringConstants.SERVICE_TYPE_1GE:
228 LOG.debug("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
229 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
230 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
233 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
238 if (readTopology(nwInstanceIdentifier) == null) {
239 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
243 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
244 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
245 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
247 LOG.warn("no otn links in otn-topology");
249 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
250 -> l1.getSource().getSourceTp().getValue().compareTo(l2.getSource().getSourceTp().getValue()))
251 .collect(Collectors.toList());
253 if (allNodes == null || allNodes.isEmpty()) {
254 LOG.error("readMdSal: no nodes ");
257 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
258 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
260 if (allLinks == null || allLinks.isEmpty()) {
261 LOG.error("readMdSal: no links ");
264 LOG.info("readMdSal: network links: {} links added", allLinks.size());
265 LOG.debug("readMdSal: network links: {} links added", allLinks);
270 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
273 Optional<Network> nwOptional =
274 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
275 if (nwOptional.isPresent()) {
276 nw = nwOptional.orElseThrow();
277 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
279 } catch (InterruptedException | ExecutionException e) {
280 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
281 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
286 private boolean analyzeNw() {
288 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
289 switch (serviceType) {
290 case StringConstants.SERVICE_TYPE_100GE_T:
291 case StringConstants.SERVICE_TYPE_OTU4:
292 case StringConstants.SERVICE_TYPE_400GE:
293 case StringConstants.SERVICE_TYPE_OTUC2:
294 case StringConstants.SERVICE_TYPE_OTUC3:
295 case StringConstants.SERVICE_TYPE_OTUC4:
296 // 100GE service and OTU4 service are handled at the openroadm-topology layer
297 for (Node node : allNodes) {
301 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
303 if (aendPceNode == null || zendPceNode == null) {
304 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
307 for (Link link : allLinks) {
311 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
313 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
314 for (NodeId srg : azSrgs) {
315 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
318 for (PceLink link : addLinks) {
319 filteraddLinks(link);
321 for (PceLink link : dropLinks) {
322 filterdropLinks(link);
327 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
329 for (Node node : allNodes) {
330 validateOtnNode(node);
333 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
335 if (aendPceNode == null || zendPceNode == null) {
336 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
339 for (Link link : allLinks) {
345 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
347 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
351 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
352 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
357 private boolean filteraddLinks(PceLink pcelink) {
359 NodeId nodeId = pcelink.getSourceId();
361 if (azSrgs.contains(nodeId)) {
362 allPceLinks.put(pcelink.getLinkId(), pcelink);
363 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
364 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
368 // remove the SRG from PceNodes, as it is not directly connected to A/Z
369 allPceNodes.remove(nodeId);
370 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
375 private boolean filterdropLinks(PceLink pcelink) {
377 NodeId nodeId = pcelink.getDestId();
379 if (azSrgs.contains(nodeId)) {
380 allPceLinks.put(pcelink.getLinkId(), pcelink);
381 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
382 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
386 // remove the SRG from PceNodes, as it is not directly connected to A/Z
387 allPceNodes.remove(pcelink.getDestId());
388 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
393 private boolean validateLink(Link link) {
394 LOG.debug("validateLink: link {} ", link);
396 NodeId sourceId = link.getSource().getSourceNode();
397 NodeId destId = link.getDestination().getDestNode();
398 PceNode source = allPceNodes.get(sourceId);
399 PceNode dest = allPceNodes.get(destId);
400 State state = link.augmentation(Link1.class).getOperationalState();
402 if (source == null) {
403 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
404 link.getSource().getSourceNode().getValue());
408 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
409 link.getDestination().getDestNode().getValue());
413 if (State.OutOfService.equals(state)) {
414 LOG.debug("validateLink: Link is ignored due operational state - {}",
419 switch (serviceType) {
420 case StringConstants.SERVICE_TYPE_100GE_T:
421 case StringConstants.SERVICE_TYPE_OTU4:
422 case StringConstants.SERVICE_TYPE_OTUC2:
423 case StringConstants.SERVICE_TYPE_OTUC3:
424 case StringConstants.SERVICE_TYPE_OTUC4:
425 case StringConstants.SERVICE_TYPE_400GE:
426 return processPceLink(link, sourceId, destId, source, dest);
427 case StringConstants.SERVICE_TYPE_ODU4:
428 case StringConstants.SERVICE_TYPE_10GE:
429 case StringConstants.SERVICE_TYPE_100GE_M:
430 case StringConstants.SERVICE_TYPE_100GE_S:
431 case StringConstants.SERVICE_TYPE_ODUC2:
432 case StringConstants.SERVICE_TYPE_ODUC3:
433 case StringConstants.SERVICE_TYPE_ODUC4:
434 case StringConstants.SERVICE_TYPE_1GE:
435 return processPceOtnLink(link, source, dest);
437 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
442 private void validateNode(Node node) {
443 LOG.debug("validateNode: node {} ", node);
444 // PceNode will be used in Graph algorithm
445 Node1 node1 = node.augmentation(Node1.class);
447 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
450 if (State.OutOfService.equals(node1.getOperationalState())) {
451 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
455 OpenroadmNodeType nodeType = node1.getNodeType();
456 String deviceNodeId = MapUtils.getSupNetworkNode(node);
457 // Should never happen but because of existing topology test files
458 // we have to manage this case
459 if (deviceNodeId == null || deviceNodeId.isBlank()) {
460 deviceNodeId = node.getNodeId().getValue();
463 LOG.debug("Device node id {} for {}", deviceNodeId, node);
464 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
465 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
466 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
467 if (endpoints != null) {
468 pceNode.setEndpoints(endpoints);
470 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
471 pceNode.initFrequenciesBitSet();
473 if (!pceNode.isValid()) {
474 LOG.debug(" validateNode: Node {} is ignored", node.getNodeId().getValue());
477 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
481 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode)) {
482 if (this.aendPceNode == null && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
483 // Added to ensure A-node has a addlink in the topology
484 List<Link> links = this.allLinks.stream()
485 .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
486 .collect(Collectors.toList());
487 if (!links.isEmpty()) {
488 this.aendPceNode = pceNode;
491 if (this.zendPceNode == null && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
492 // Added to ensure Z-node has a droplink in the topology
493 List<Link> links = this.allLinks.stream()
494 .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
495 .collect(Collectors.toList());
496 if (!links.isEmpty()) {
497 this.zendPceNode = pceNode;
502 allPceNodes.put(pceNode.getNodeId(), pceNode);
503 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
506 @SuppressWarnings("fallthrough")
508 value = "SF_SWITCH_FALLTHROUGH",
509 justification = "intentional fallthrough")
510 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
511 switch (serviceFormat) {
514 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
519 switch (azEndPoint) {
521 return checkAendInputTxPortDeviceName()
522 && pceNode.getNodeId().getValue()
523 .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName());
525 return checkZendInputTxPortDeviceName()
526 && pceNode.getNodeId().getValue()
527 .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName());
532 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
537 private void validateOtnNode(Node node) {
538 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
539 // PceOtnNode will be used in Graph algorithm
540 if (node.augmentation(Node1.class) == null) {
541 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
545 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
546 String clientPort = null;
547 if (node.getNodeId().getValue().equals(anodeId)
548 && this.aendPceNode == null
549 && input.getServiceAEnd() != null
550 && input.getServiceAEnd().getRxDirection() != null
551 && input.getServiceAEnd().getRxDirection().getPort() != null
552 && input.getServiceAEnd().getRxDirection().getPort().getPortName() != null) {
553 clientPort = input.getServiceAEnd().getRxDirection().getPort().getPortName();
554 } else if (node.getNodeId().getValue().equals(znodeId)
555 && this.zendPceNode == null
556 && input.getServiceZEnd() != null
557 && input.getServiceZEnd().getRxDirection() != null
558 && input.getServiceZEnd().getRxDirection().getPort() != null
559 && input.getServiceZEnd().getRxDirection().getPort().getPortName() != null) {
560 clientPort = input.getServiceZEnd().getRxDirection().getPort().getPortName();
563 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType, clientPort);
564 pceOtnNode.validateXponder(anodeId, znodeId);
566 if (!pceOtnNode.isValid()) {
567 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
570 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
573 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
574 this.aendPceNode = pceOtnNode;
576 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
577 this.zendPceNode = pceOtnNode;
579 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
580 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
583 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
584 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
585 return ConstraintTypes.NONE;
587 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
588 LOG.debug("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
589 return ConstraintTypes.HARD_EXCLUDE;
591 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
592 LOG.debug("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
593 return ConstraintTypes.HARD_EXCLUDE;
595 return ConstraintTypes.NONE;
598 private ConstraintTypes validateLinkConstraints(PceLink link) {
599 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
600 return ConstraintTypes.NONE;
603 // for now SRLG is the only constraint for link
604 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
605 return ConstraintTypes.NONE;
608 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
609 constraints.retainAll(link.getsrlgList());
610 if (!constraints.isEmpty()) {
611 LOG.debug("validateLinkConstraints: {}", link.getLinkId().getValue());
612 return ConstraintTypes.HARD_EXCLUDE;
615 return ConstraintTypes.NONE;
618 private void dropOppositeLink(Link link) {
619 LinkId opplink = MapUtils.extractOppositeLink(link);
621 if (allPceLinks.containsKey(opplink)) {
622 allPceLinks.remove(opplink);
624 linksToExclude.add(opplink);
628 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
629 switch (openroadmNodeType) {
631 pceNode.initSrgTps();
632 this.azSrgs.add(nodeId);
635 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
638 LOG.debug("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
642 if (!pceNode.isValid()) {
643 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
649 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
650 PceLink pcelink = new PceLink(link, source, dest);
651 if (!pcelink.isValid()) {
652 dropOppositeLink(link);
653 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
656 LinkId linkId = pcelink.getLinkId();
657 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
658 dropOppositeLink(link);
659 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
662 switch (pcelink.getlinkType()) {
665 allPceLinks.put(linkId, pcelink);
666 source.addOutgoingLink(pcelink);
667 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
668 pcelink.getlinkType(), pcelink);
672 source.getRdmSrgClient(pcelink.getSourceTP().getValue(), StringConstants.SERVICE_DIRECTION_AZ));
673 addLinks.add(pcelink);
674 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
678 dest.getRdmSrgClient(pcelink.getDestTP().getValue(), StringConstants.SERVICE_DIRECTION_ZA));
679 dropLinks.add(pcelink);
680 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
683 // store separately all SRG links directly
684 azSrgs.add(sourceId);
686 if (!dest.checkTP(pcelink.getDestTP().getValue())) {
688 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
691 if (dest.getXpdrClient(pcelink.getDestTP().getValue()) != null) {
692 pcelink.setClientZ(dest.getXpdrClient(pcelink.getDestTP().getValue()));
694 allPceLinks.put(linkId, pcelink);
695 source.addOutgoingLink(pcelink);
696 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
698 // does it mean XPONDER==>>SRG ?
700 // store separately all SRG links directly
703 if (!source.checkTP(pcelink.getSourceTP().getValue())) {
705 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
708 if (source.getXpdrClient(pcelink.getSourceTP().getValue()) != null) {
709 pcelink.setClientA(source.getXpdrClient(pcelink.getSourceTP().getValue()));
711 allPceLinks.put(linkId, pcelink);
712 source.addOutgoingLink(pcelink);
713 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
716 LOG.warn("validateLink: link type is not supported {}", pcelink);
721 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
722 PceLink pceOtnLink = new PceLink(link, source, dest);
724 if (!pceOtnLink.isOtnValid(link, serviceType)) {
725 dropOppositeLink(link);
726 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
730 LinkId linkId = pceOtnLink.getLinkId();
731 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
732 dropOppositeLink(link);
733 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
737 switch (pceOtnLink.getlinkType()) {
739 if (source.getXpdrClient(pceOtnLink.getSourceTP().getValue()) != null) {
740 pceOtnLink.setClientA(source.getXpdrClient(pceOtnLink.getSourceTP().getValue()));
742 if (dest.getXpdrClient(pceOtnLink.getDestTP().getValue()) != null) {
743 pceOtnLink.setClientZ(dest.getXpdrClient(pceOtnLink.getDestTP().getValue()));
745 allPceLinks.put(linkId, pceOtnLink);
746 source.addOutgoingLink(pceOtnLink);
747 LOG.debug("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
750 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
755 public PceNode getaendPceNode() {
759 public PceNode getzendPceNode() {
763 public Map<NodeId, PceNode> getAllPceNodes() {
764 return this.allPceNodes;
767 public Map<LinkId, PceLink> getAllPceLinks() {
768 return this.allPceLinks;
771 public String getServiceType() {
775 public PceResult getReturnStructure() {
776 return returnStructure;
779 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
780 allPceNodes.forEach(((nodeId, pceNode) -> {
781 LOG.debug("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
782 pceNode.getOutgoingLinks());
787 * Get mc capability slot width granularity for device.
788 * @param deviceNodeId String
789 * @param nodeId NodeId
790 * @return slot width granularity
792 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
793 // nodeId: openroadm-topology level node
794 // deviceNodeId: openroadm-network level node
795 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
796 String[] params = nodeId.getValue().split("-");
797 // DEGx or SRGx or XPDRx
798 String moduleName = params[params.length - 1];
799 for (McCapabilities mcCapabitility : mcCapabilities) {
800 if (mcCapabitility.getMcNodeName().contains("XPDR")
801 && mcCapabitility.getSlotWidthGranularity() != null) {
802 return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
804 if (mcCapabitility.getMcNodeName().contains(moduleName)
805 && mcCapabitility.getSlotWidthGranularity() != null) {
806 return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
809 return GridConstant.SLOT_WIDTH_50;
813 * Get mc capability central-width granularity for device.
814 * @param deviceNodeId String
815 * @param nodeId NodeId
816 * @return center-freq granularity
818 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
819 // nodeId: openroadm-topology level node
820 // deviceNodeId: openroadm-network level node
821 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
822 String[] params = nodeId.getValue().split("-");
823 // DEGx or SRGx or XPDRx
824 String moduleName = params[params.length - 1];
825 for (McCapabilities mcCapabitility : mcCapabilities) {
826 if (mcCapabitility.getMcNodeName().contains("XPDR")
827 && mcCapabitility.getCenterFreqGranularity() != null) {
828 return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
830 if (mcCapabitility.getMcNodeName().contains(moduleName)
831 && mcCapabitility.getCenterFreqGranularity() != null) {
832 return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
835 return GridConstant.SLOT_WIDTH_50;