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.rev220316.mc.capabilities.McCapabilities;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.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.rev211210.OpenroadmLinkType;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.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.get();
277 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
278 networkTransactionService.close();
280 } catch (InterruptedException | ExecutionException e) {
281 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
282 networkTransactionService.close();
283 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
288 private boolean analyzeNw() {
290 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
291 switch (serviceType) {
292 case StringConstants.SERVICE_TYPE_100GE_T:
293 case StringConstants.SERVICE_TYPE_OTU4:
294 case StringConstants.SERVICE_TYPE_400GE:
295 case StringConstants.SERVICE_TYPE_OTUC2:
296 case StringConstants.SERVICE_TYPE_OTUC3:
297 case StringConstants.SERVICE_TYPE_OTUC4:
298 // 100GE service and OTU4 service are handled at the openroadm-topology layer
299 for (Node node : allNodes) {
303 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
305 if (aendPceNode == null || zendPceNode == null) {
306 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
309 for (Link link : allLinks) {
313 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
315 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
316 for (NodeId srg : azSrgs) {
317 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
320 for (PceLink link : addLinks) {
321 filteraddLinks(link);
323 for (PceLink link : dropLinks) {
324 filterdropLinks(link);
329 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
331 for (Node node : allNodes) {
332 validateOtnNode(node);
335 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
337 if (aendPceNode == null || zendPceNode == null) {
338 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
341 for (Link link : allLinks) {
347 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
349 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
353 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
354 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
359 private boolean filteraddLinks(PceLink pcelink) {
361 NodeId nodeId = pcelink.getSourceId();
363 if (azSrgs.contains(nodeId)) {
364 allPceLinks.put(pcelink.getLinkId(), pcelink);
365 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
366 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
370 // remove the SRG from PceNodes, as it is not directly connected to A/Z
371 allPceNodes.remove(nodeId);
372 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
377 private boolean filterdropLinks(PceLink pcelink) {
379 NodeId nodeId = pcelink.getDestId();
381 if (azSrgs.contains(nodeId)) {
382 allPceLinks.put(pcelink.getLinkId(), pcelink);
383 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
384 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
388 // remove the SRG from PceNodes, as it is not directly connected to A/Z
389 allPceNodes.remove(pcelink.getDestId());
390 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
395 private boolean validateLink(Link link) {
396 LOG.debug("validateLink: link {} ", link);
398 NodeId sourceId = link.getSource().getSourceNode();
399 NodeId destId = link.getDestination().getDestNode();
400 PceNode source = allPceNodes.get(sourceId);
401 PceNode dest = allPceNodes.get(destId);
402 State state = link.augmentation(Link1.class).getOperationalState();
404 if (source == null) {
405 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
406 link.getSource().getSourceNode().getValue());
410 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
411 link.getDestination().getDestNode().getValue());
415 if (State.OutOfService.equals(state)) {
416 LOG.debug("validateLink: Link is ignored due operational state - {}",
421 switch (serviceType) {
422 case StringConstants.SERVICE_TYPE_100GE_T:
423 case StringConstants.SERVICE_TYPE_OTU4:
424 case StringConstants.SERVICE_TYPE_OTUC2:
425 case StringConstants.SERVICE_TYPE_OTUC3:
426 case StringConstants.SERVICE_TYPE_OTUC4:
427 case StringConstants.SERVICE_TYPE_400GE:
428 return processPceLink(link, sourceId, destId, source, dest);
429 case StringConstants.SERVICE_TYPE_ODU4:
430 case StringConstants.SERVICE_TYPE_10GE:
431 case StringConstants.SERVICE_TYPE_100GE_M:
432 case StringConstants.SERVICE_TYPE_100GE_S:
433 case StringConstants.SERVICE_TYPE_ODUC2:
434 case StringConstants.SERVICE_TYPE_ODUC3:
435 case StringConstants.SERVICE_TYPE_ODUC4:
436 case StringConstants.SERVICE_TYPE_1GE:
437 return processPceOtnLink(link, source, dest);
439 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
444 private void validateNode(Node node) {
445 LOG.debug("validateNode: node {} ", node);
446 // PceNode will be used in Graph algorithm
447 Node1 node1 = node.augmentation(Node1.class);
449 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
452 if (State.OutOfService.equals(node1.getOperationalState())) {
453 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
457 OpenroadmNodeType nodeType = node1.getNodeType();
458 String deviceNodeId = MapUtils.getSupNetworkNode(node);
459 // Should never happen but because of existing topology test files
460 // we have to manage this case
461 if (deviceNodeId == null || deviceNodeId.isBlank()) {
462 deviceNodeId = node.getNodeId().getValue();
465 LOG.debug("Device node id {} for {}", deviceNodeId, node);
466 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
467 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
468 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
469 if (endpoints != null) {
470 pceNode.setEndpoints(endpoints);
472 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
473 pceNode.initFrequenciesBitSet();
475 if (!pceNode.isValid()) {
476 LOG.debug(" validateNode: Node {} is ignored", node.getNodeId().getValue());
479 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
483 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode)) {
484 if (this.aendPceNode == null && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
485 // Added to ensure A-node has a addlink in the topology
486 List<Link> links = this.allLinks.stream()
487 .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
488 .collect(Collectors.toList());
489 if (!links.isEmpty()) {
490 this.aendPceNode = pceNode;
493 if (this.zendPceNode == null && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
494 // Added to ensure Z-node has a droplink in the topology
495 List<Link> links = this.allLinks.stream()
496 .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
497 .collect(Collectors.toList());
498 if (!links.isEmpty()) {
499 this.zendPceNode = pceNode;
504 allPceNodes.put(pceNode.getNodeId(), pceNode);
505 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
508 @SuppressWarnings("fallthrough")
510 value = "SF_SWITCH_FALLTHROUGH",
511 justification = "intentional fallthrough")
512 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
513 switch (serviceFormat) {
516 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
521 switch (azEndPoint) {
523 return checkAendInputTxPortDeviceName()
524 && pceNode.getNodeId().getValue()
525 .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName());
527 return checkZendInputTxPortDeviceName()
528 && pceNode.getNodeId().getValue()
529 .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName());
534 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
539 private void validateOtnNode(Node node) {
540 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
541 // PceOtnNode will be used in Graph algorithm
542 if (node.augmentation(Node1.class) == null) {
543 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
547 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
548 String clientPort = null;
549 if (node.getNodeId().getValue().equals(anodeId)
550 && this.aendPceNode == null
551 && input.getServiceAEnd() != null
552 && input.getServiceAEnd().getRxDirection() != null
553 && input.getServiceAEnd().getRxDirection().getPort() != null
554 && input.getServiceAEnd().getRxDirection().getPort().getPortName() != null) {
555 clientPort = input.getServiceAEnd().getRxDirection().getPort().getPortName();
556 } else if (node.getNodeId().getValue().equals(znodeId)
557 && this.zendPceNode == null
558 && input.getServiceZEnd() != null
559 && input.getServiceZEnd().getRxDirection() != null
560 && input.getServiceZEnd().getRxDirection().getPort() != null
561 && input.getServiceZEnd().getRxDirection().getPort().getPortName() != null) {
562 clientPort = input.getServiceZEnd().getRxDirection().getPort().getPortName();
565 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType, clientPort);
566 pceOtnNode.validateXponder(anodeId, znodeId);
568 if (!pceOtnNode.isValid()) {
569 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
572 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
575 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
576 this.aendPceNode = pceOtnNode;
578 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
579 this.zendPceNode = pceOtnNode;
581 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
582 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
585 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
586 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
587 return ConstraintTypes.NONE;
589 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
590 LOG.debug("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
591 return ConstraintTypes.HARD_EXCLUDE;
593 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
594 LOG.debug("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
595 return ConstraintTypes.HARD_EXCLUDE;
597 return ConstraintTypes.NONE;
600 private ConstraintTypes validateLinkConstraints(PceLink link) {
601 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
602 return ConstraintTypes.NONE;
605 // for now SRLG is the only constraint for link
606 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
607 return ConstraintTypes.NONE;
610 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
611 constraints.retainAll(link.getsrlgList());
612 if (!constraints.isEmpty()) {
613 LOG.debug("validateLinkConstraints: {}", link.getLinkId().getValue());
614 return ConstraintTypes.HARD_EXCLUDE;
617 return ConstraintTypes.NONE;
620 private void dropOppositeLink(Link link) {
621 LinkId opplink = MapUtils.extractOppositeLink(link);
623 if (allPceLinks.containsKey(opplink)) {
624 allPceLinks.remove(opplink);
626 linksToExclude.add(opplink);
630 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
631 switch (openroadmNodeType) {
633 pceNode.initSrgTps();
634 this.azSrgs.add(nodeId);
637 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
640 LOG.debug("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
644 if (!pceNode.isValid()) {
645 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
651 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
652 PceLink pcelink = new PceLink(link, source, dest);
653 if (!pcelink.isValid()) {
654 dropOppositeLink(link);
655 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
658 LinkId linkId = pcelink.getLinkId();
659 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
660 dropOppositeLink(link);
661 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
664 switch (pcelink.getlinkType()) {
667 allPceLinks.put(linkId, pcelink);
668 source.addOutgoingLink(pcelink);
669 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
670 pcelink.getlinkType(), pcelink);
674 source.getRdmSrgClient(pcelink.getSourceTP().getValue(), StringConstants.SERVICE_DIRECTION_AZ));
675 addLinks.add(pcelink);
676 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
680 dest.getRdmSrgClient(pcelink.getDestTP().getValue(), StringConstants.SERVICE_DIRECTION_ZA));
681 dropLinks.add(pcelink);
682 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
685 // store separately all SRG links directly
686 azSrgs.add(sourceId);
688 if (!dest.checkTP(pcelink.getDestTP().getValue())) {
690 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
693 if (dest.getXpdrClient(pcelink.getDestTP().getValue()) != null) {
694 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().getValue()));
696 allPceLinks.put(linkId, pcelink);
697 source.addOutgoingLink(pcelink);
698 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
700 // does it mean XPONDER==>>SRG ?
702 // store separately all SRG links directly
705 if (!source.checkTP(pcelink.getSourceTP().getValue())) {
707 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
710 if (source.getXpdrClient(pcelink.getSourceTP().getValue()) != null) {
711 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().getValue()));
713 allPceLinks.put(linkId, pcelink);
714 source.addOutgoingLink(pcelink);
715 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
718 LOG.warn("validateLink: link type is not supported {}", pcelink);
723 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
724 PceLink pceOtnLink = new PceLink(link, source, dest);
726 if (!pceOtnLink.isOtnValid(link, serviceType)) {
727 dropOppositeLink(link);
728 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
732 LinkId linkId = pceOtnLink.getLinkId();
733 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
734 dropOppositeLink(link);
735 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
739 switch (pceOtnLink.getlinkType()) {
741 if (source.getXpdrClient(pceOtnLink.getSourceTP().getValue()) != null) {
742 pceOtnLink.setClient(source.getXpdrClient(pceOtnLink.getSourceTP().getValue()));
744 if (dest.getXpdrClient(pceOtnLink.getDestTP().getValue()) != null) {
745 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().getValue()));
747 allPceLinks.put(linkId, pceOtnLink);
748 source.addOutgoingLink(pceOtnLink);
749 LOG.debug("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
752 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
757 public PceNode getaendPceNode() {
761 public PceNode getzendPceNode() {
765 public Map<NodeId, PceNode> getAllPceNodes() {
766 return this.allPceNodes;
769 public Map<LinkId, PceLink> getAllPceLinks() {
770 return this.allPceLinks;
773 public String getServiceType() {
777 public PceResult getReturnStructure() {
778 return returnStructure;
781 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
782 allPceNodes.forEach(((nodeId, pceNode) -> {
783 LOG.debug("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
784 pceNode.getOutgoingLinks());
789 * Get mc capability slot width granularity for device.
790 * @param deviceNodeId String
791 * @param nodeId NodeId
792 * @return slot width granularity
794 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
795 // nodeId: openroadm-topology level node
796 // deviceNodeId: openroadm-network level node
797 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
798 String[] params = nodeId.getValue().split("-");
799 // DEGx or SRGx or XPDRx
800 String moduleName = params[params.length - 1];
801 for (McCapabilities mcCapabitility : mcCapabilities) {
802 if (mcCapabitility.getMcNodeName().contains("XPDR")
803 && mcCapabitility.getSlotWidthGranularity() != null) {
804 return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
806 if (mcCapabitility.getMcNodeName().contains(moduleName)
807 && mcCapabitility.getSlotWidthGranularity() != null) {
808 return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
811 return GridConstant.SLOT_WIDTH_50;
815 * Get mc capability central-width granularity for device.
816 * @param deviceNodeId String
817 * @param nodeId NodeId
818 * @return center-freq granularity
820 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
821 // nodeId: openroadm-topology level node
822 // deviceNodeId: openroadm-network level node
823 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
824 String[] params = nodeId.getValue().split("-");
825 // DEGx or SRGx or XPDRx
826 String moduleName = params[params.length - 1];
827 for (McCapabilities mcCapabitility : mcCapabilities) {
828 if (mcCapabitility.getMcNodeName().contains("XPDR")
829 && mcCapabitility.getCenterFreqGranularity() != null) {
830 return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
832 if (mcCapabitility.getMcNodeName().contains(moduleName)
833 && mcCapabitility.getCenterFreqGranularity() != null) {
834 return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
837 return GridConstant.SLOT_WIDTH_50;