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.rev220615.PathComputationRequestInput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mc.capabilities.McCapabilities;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
49 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
50 import org.opendaylight.yangtools.yang.common.Uint32;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 public class PceCalculation {
56 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
57 private NetworkTransactionService networkTransactionService;
59 ///////////// data parsed from Input/////////////////
60 private PathComputationRequestInput input;
61 private String anodeId = "";
62 private String znodeId = "";
63 private String serviceFormatA = "";
64 private String serviceFormatZ = "";
65 private String serviceType = "";
66 private Uint32 serviceRate = Uint32.valueOf(0);
68 private PceConstraints pceHardConstraints;
70 ///////////// Intermediate data/////////////////
71 private List<PceLink> addLinks = new ArrayList<>();
72 private List<PceLink> dropLinks = new ArrayList<>();
73 private List<NodeId> azSrgs = new ArrayList<>();
75 private PceNode aendPceNode = null;
76 private PceNode zendPceNode = null;
78 private List<Link> allLinks = null;
79 private List<Node> allNodes = null;
81 // this List serves graph calculation
82 private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
83 // this List serves calculation of ZtoA path description
84 // TODO maybe better solution is possible
85 private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
86 private List<LinkId> linksToExclude = new ArrayList<>();
87 private PceResult returnStructure;
88 private PortMapping portMapping;
90 private enum ConstraintTypes {
91 NONE, HARD_EXCLUDE, HARD_INCLUDE, HARD_DIVERSITY, SOFT_EXCLUDE, SOFT_INCLUDE, SOFT_DIVERSITY;
94 private MappingUtils mappingUtils;
96 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
97 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc,
98 PortMapping portMapping) {
100 this.networkTransactionService = networkTransactionService;
101 this.returnStructure = rc;
103 this.pceHardConstraints = pceHardConstraints;
104 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
105 this.portMapping = portMapping;
109 public void retrievePceNetwork() {
111 LOG.debug("In PceCalculation retrieveNetwork");
114 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
117 MapUtils.mapDiversityConstraints(allNodes, allLinks, pceHardConstraints);
120 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
123 printNodesInfo(allPceNodes);
125 returnStructure.setRC(ResponseCodes.RESPONSE_OK);
128 private boolean parseInput() {
129 if (!PceComplianceCheck.checkString(input.getServiceAEnd().getServiceFormat().getName())
130 || !PceComplianceCheck.checkString(input.getServiceZEnd().getServiceFormat().getName())
131 || !PceComplianceCheck.checkString(input.getServiceAEnd().getServiceRate().toString())) {
132 LOG.error("Service Format and Service Rate are required for a path calculation");
135 serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
136 serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
137 serviceRate = input.getServiceAEnd().getServiceRate();
138 serviceType = ServiceTypes.getServiceType(
141 NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
142 && checkAendInputTxPortName()
143 ? portMapping.getMapping(
144 input.getServiceAEnd().getNodeId(),
145 input.getServiceAEnd().getTxDirection().getPort().getPortName())
148 LOG.debug("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
152 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
153 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
157 private boolean checkAendInputTxPortName() {
158 return checkAendInputTxPort()
159 && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null;
162 private boolean checkAendInputTxPortDeviceName() {
163 return checkAendInputTxPort()
164 && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null;
167 private boolean checkAendInputTxPort() {
168 return input.getServiceAEnd() != null
169 && input.getServiceAEnd().getTxDirection() != null
170 && input.getServiceAEnd().getTxDirection().getPort() != null;
173 private boolean checkZendInputTxPortDeviceName() {
174 return input.getServiceZEnd() != null
175 && input.getServiceZEnd().getTxDirection() != null
176 && input.getServiceZEnd().getTxDirection().getPort() != null
177 && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null;
180 private void getAZnodeId() {
182 checkAendInputTxPortDeviceName()
183 ? input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName()
184 : input.getServiceAEnd().getNodeId();
186 checkZendInputTxPortDeviceName()
187 ? input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName()
188 : input.getServiceZEnd().getNodeId();
191 private boolean readMdSal() {
192 InstanceIdentifier<Network> nwInstanceIdentifier = null;
193 switch (serviceType) {
194 case StringConstants.SERVICE_TYPE_100GE_T:
195 case StringConstants.SERVICE_TYPE_400GE:
196 case StringConstants.SERVICE_TYPE_OTU4:
197 case StringConstants.SERVICE_TYPE_OTUC2:
198 case StringConstants.SERVICE_TYPE_OTUC3:
199 case StringConstants.SERVICE_TYPE_OTUC4:
200 LOG.debug("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
201 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
202 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
204 case StringConstants.SERVICE_TYPE_100GE_M:
205 case StringConstants.SERVICE_TYPE_100GE_S:
206 case StringConstants.SERVICE_TYPE_ODU4:
207 case StringConstants.SERVICE_TYPE_ODUC2:
208 case StringConstants.SERVICE_TYPE_ODUC3:
209 case StringConstants.SERVICE_TYPE_ODUC4:
210 case StringConstants.SERVICE_TYPE_10GE:
211 case StringConstants.SERVICE_TYPE_1GE:
212 LOG.debug("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
213 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
214 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
217 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
222 if (readTopology(nwInstanceIdentifier) == null) {
223 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
227 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
228 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
229 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
231 LOG.warn("no otn links in otn-topology");
233 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
234 -> l1.getSource().getSourceTp().getValue().compareTo(l2.getSource().getSourceTp().getValue()))
235 .collect(Collectors.toList());
237 if (allNodes == null || allNodes.isEmpty()) {
238 LOG.error("readMdSal: no nodes ");
241 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
242 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
244 if (allLinks == null || allLinks.isEmpty()) {
245 LOG.error("readMdSal: no links ");
248 LOG.info("readMdSal: network links: {} links added", allLinks.size());
249 LOG.debug("readMdSal: network links: {} links added", allLinks);
254 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
257 Optional<Network> nwOptional =
258 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
259 if (nwOptional.isPresent()) {
260 nw = nwOptional.get();
261 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
262 networkTransactionService.close();
264 } catch (InterruptedException | ExecutionException e) {
265 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
266 networkTransactionService.close();
267 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
272 private boolean analyzeNw() {
274 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
275 switch (serviceType) {
276 case StringConstants.SERVICE_TYPE_100GE_T:
277 case StringConstants.SERVICE_TYPE_OTU4:
278 case StringConstants.SERVICE_TYPE_400GE:
279 case StringConstants.SERVICE_TYPE_OTUC2:
280 case StringConstants.SERVICE_TYPE_OTUC3:
281 case StringConstants.SERVICE_TYPE_OTUC4:
282 // 100GE service and OTU4 service are handled at the openroadm-topology layer
283 for (Node node : allNodes) {
287 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
289 if (aendPceNode == null || zendPceNode == null) {
290 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
293 for (Link link : allLinks) {
297 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
299 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
300 for (NodeId srg : azSrgs) {
301 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
304 for (PceLink link : addLinks) {
305 filteraddLinks(link);
307 for (PceLink link : dropLinks) {
308 filterdropLinks(link);
313 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
315 for (Node node : allNodes) {
316 validateOtnNode(node);
319 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
321 if (aendPceNode == null || zendPceNode == null) {
322 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
325 for (Link link : allLinks) {
331 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
333 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
337 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
338 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
343 private boolean filteraddLinks(PceLink pcelink) {
345 NodeId nodeId = pcelink.getSourceId();
347 if (azSrgs.contains(nodeId)) {
348 allPceLinks.put(pcelink.getLinkId(), pcelink);
349 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
350 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
354 // remove the SRG from PceNodes, as it is not directly connected to A/Z
355 allPceNodes.remove(nodeId);
356 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
361 private boolean filterdropLinks(PceLink pcelink) {
363 NodeId nodeId = pcelink.getDestId();
365 if (azSrgs.contains(nodeId)) {
366 allPceLinks.put(pcelink.getLinkId(), pcelink);
367 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
368 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
372 // remove the SRG from PceNodes, as it is not directly connected to A/Z
373 allPceNodes.remove(pcelink.getDestId());
374 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
379 private boolean validateLink(Link link) {
380 LOG.debug("validateLink: link {} ", link);
382 NodeId sourceId = link.getSource().getSourceNode();
383 NodeId destId = link.getDestination().getDestNode();
384 PceNode source = allPceNodes.get(sourceId);
385 PceNode dest = allPceNodes.get(destId);
386 State state = link.augmentation(Link1.class).getOperationalState();
388 if (source == null) {
389 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
390 link.getSource().getSourceNode().getValue());
394 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
395 link.getDestination().getDestNode().getValue());
399 if (State.OutOfService.equals(state)) {
400 LOG.debug("validateLink: Link is ignored due operational state - {}",
405 switch (serviceType) {
406 case StringConstants.SERVICE_TYPE_100GE_T:
407 case StringConstants.SERVICE_TYPE_OTU4:
408 case StringConstants.SERVICE_TYPE_OTUC2:
409 case StringConstants.SERVICE_TYPE_OTUC3:
410 case StringConstants.SERVICE_TYPE_OTUC4:
411 case StringConstants.SERVICE_TYPE_400GE:
412 return processPceLink(link, sourceId, destId, source, dest);
413 case StringConstants.SERVICE_TYPE_ODU4:
414 case StringConstants.SERVICE_TYPE_10GE:
415 case StringConstants.SERVICE_TYPE_100GE_M:
416 case StringConstants.SERVICE_TYPE_100GE_S:
417 case StringConstants.SERVICE_TYPE_ODUC2:
418 case StringConstants.SERVICE_TYPE_ODUC3:
419 case StringConstants.SERVICE_TYPE_ODUC4:
420 case StringConstants.SERVICE_TYPE_1GE:
421 return processPceOtnLink(link, source, dest);
423 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
428 private void validateNode(Node node) {
429 LOG.debug("validateNode: node {} ", node);
430 // PceNode will be used in Graph algorithm
431 Node1 node1 = node.augmentation(Node1.class);
433 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
436 if (State.OutOfService.equals(node1.getOperationalState())) {
437 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
441 OpenroadmNodeType nodeType = node1.getNodeType();
442 String deviceNodeId = MapUtils.getSupNetworkNode(node);
443 // Should never happen but because of existing topology test files
444 // we have to manage this case
445 if (deviceNodeId == null || deviceNodeId.isBlank()) {
446 deviceNodeId = node.getNodeId().getValue();
449 LOG.debug("Device node id {} for {}", deviceNodeId, node);
450 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
451 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
452 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
453 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
454 pceNode.initFrequenciesBitSet();
456 if (!pceNode.isValid()) {
457 LOG.debug(" validateNode: Node {} is ignored", node.getNodeId().getValue());
460 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
464 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode)) {
465 if (this.aendPceNode == null && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
466 // Added to ensure A-node has a addlink in the topology
467 List<Link> links = this.allLinks.stream()
468 .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
469 .collect(Collectors.toList());
470 if (!links.isEmpty()) {
471 this.aendPceNode = pceNode;
474 if (this.zendPceNode == null && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
475 // Added to ensure Z-node has a droplink in the topology
476 List<Link> links = this.allLinks.stream()
477 .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
478 .collect(Collectors.toList());
479 if (!links.isEmpty()) {
480 this.zendPceNode = pceNode;
485 allPceNodes.put(pceNode.getNodeId(), pceNode);
486 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
489 @SuppressWarnings("fallthrough")
491 value = "SF_SWITCH_FALLTHROUGH",
492 justification = "intentional fallthrough")
493 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
494 switch (serviceFormat) {
497 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
502 switch (azEndPoint) {
504 return checkAendInputTxPortDeviceName()
505 && pceNode.getNodeId().getValue()
506 .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName());
508 return checkZendInputTxPortDeviceName()
509 && pceNode.getNodeId().getValue()
510 .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName());
515 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
520 private void validateOtnNode(Node node) {
521 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
522 // PceOtnNode will be used in Graph algorithm
523 if (node.augmentation(Node1.class) == null) {
524 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
528 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
529 String clientPort = null;
530 if (node.getNodeId().getValue().equals(anodeId)
531 && this.aendPceNode == null
532 && input.getServiceAEnd() != null
533 && input.getServiceAEnd().getRxDirection() != null
534 && input.getServiceAEnd().getRxDirection().getPort() != null
535 && input.getServiceAEnd().getRxDirection().getPort().getPortName() != null) {
536 clientPort = input.getServiceAEnd().getRxDirection().getPort().getPortName();
537 } else if (node.getNodeId().getValue().equals(znodeId)
538 && this.zendPceNode == null
539 && input.getServiceZEnd() != null
540 && input.getServiceZEnd().getRxDirection() != null
541 && input.getServiceZEnd().getRxDirection().getPort() != null
542 && input.getServiceZEnd().getRxDirection().getPort().getPortName() != null) {
543 clientPort = input.getServiceZEnd().getRxDirection().getPort().getPortName();
546 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType, clientPort);
547 pceOtnNode.validateXponder(anodeId, znodeId);
549 if (!pceOtnNode.isValid()) {
550 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
553 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
556 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
557 this.aendPceNode = pceOtnNode;
559 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
560 this.zendPceNode = pceOtnNode;
562 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
563 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
566 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
567 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
568 return ConstraintTypes.NONE;
570 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
571 LOG.debug("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
572 return ConstraintTypes.HARD_EXCLUDE;
574 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
575 LOG.debug("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
576 return ConstraintTypes.HARD_EXCLUDE;
578 return ConstraintTypes.NONE;
581 private ConstraintTypes validateLinkConstraints(PceLink link) {
582 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
583 return ConstraintTypes.NONE;
586 // for now SRLG is the only constraint for link
587 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
588 return ConstraintTypes.NONE;
591 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
592 constraints.retainAll(link.getsrlgList());
593 if (!constraints.isEmpty()) {
594 LOG.debug("validateLinkConstraints: {}", link.getLinkId().getValue());
595 return ConstraintTypes.HARD_EXCLUDE;
598 return ConstraintTypes.NONE;
601 private void dropOppositeLink(Link link) {
602 LinkId opplink = MapUtils.extractOppositeLink(link);
604 if (allPceLinks.containsKey(opplink)) {
605 allPceLinks.remove(opplink);
607 linksToExclude.add(opplink);
611 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
612 switch (openroadmNodeType) {
614 pceNode.initSrgTps();
615 this.azSrgs.add(nodeId);
618 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
621 LOG.debug("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
625 if (!pceNode.isValid()) {
626 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
632 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
633 PceLink pcelink = new PceLink(link, source, dest);
634 if (!pcelink.isValid()) {
635 dropOppositeLink(link);
636 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
639 LinkId linkId = pcelink.getLinkId();
640 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
641 dropOppositeLink(link);
642 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
645 switch (pcelink.getlinkType()) {
648 allPceLinks.put(linkId, pcelink);
649 source.addOutgoingLink(pcelink);
650 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
651 pcelink.getlinkType(), pcelink);
655 source.getRdmSrgClient(pcelink.getSourceTP().getValue(), StringConstants.SERVICE_DIRECTION_AZ));
656 addLinks.add(pcelink);
657 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
661 dest.getRdmSrgClient(pcelink.getDestTP().getValue(), StringConstants.SERVICE_DIRECTION_ZA));
662 dropLinks.add(pcelink);
663 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
666 // store separately all SRG links directly
667 azSrgs.add(sourceId);
669 if (!dest.checkTP(pcelink.getDestTP().getValue())) {
671 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
674 if (dest.getXpdrClient(pcelink.getDestTP().getValue()) != null) {
675 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().getValue()));
677 allPceLinks.put(linkId, pcelink);
678 source.addOutgoingLink(pcelink);
679 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
681 // does it mean XPONDER==>>SRG ?
683 // store separately all SRG links directly
686 if (!source.checkTP(pcelink.getSourceTP().getValue())) {
688 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
691 if (source.getXpdrClient(pcelink.getSourceTP().getValue()) != null) {
692 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().getValue()));
694 allPceLinks.put(linkId, pcelink);
695 source.addOutgoingLink(pcelink);
696 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
699 LOG.warn("validateLink: link type is not supported {}", pcelink);
704 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
705 PceLink pceOtnLink = new PceLink(link, source, dest);
707 if (!pceOtnLink.isOtnValid(link, serviceType)) {
708 dropOppositeLink(link);
709 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
713 LinkId linkId = pceOtnLink.getLinkId();
714 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
715 dropOppositeLink(link);
716 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
720 switch (pceOtnLink.getlinkType()) {
722 if (source.getXpdrClient(pceOtnLink.getSourceTP().getValue()) != null) {
723 pceOtnLink.setClient(source.getXpdrClient(pceOtnLink.getSourceTP().getValue()));
725 if (dest.getXpdrClient(pceOtnLink.getDestTP().getValue()) != null) {
726 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().getValue()));
728 allPceLinks.put(linkId, pceOtnLink);
729 source.addOutgoingLink(pceOtnLink);
730 LOG.debug("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
733 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
738 public PceNode getaendPceNode() {
742 public PceNode getzendPceNode() {
746 public Map<NodeId, PceNode> getAllPceNodes() {
747 return this.allPceNodes;
750 public Map<LinkId, PceLink> getAllPceLinks() {
751 return this.allPceLinks;
754 public String getServiceType() {
758 public PceResult getReturnStructure() {
759 return returnStructure;
762 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
763 allPceNodes.forEach(((nodeId, pceNode) -> {
764 LOG.debug("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
765 pceNode.getOutgoingLinks());
770 * Get mc capability slot width granularity for device.
771 * @param deviceNodeId String
772 * @param nodeId NodeId
773 * @return slot width granularity
775 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
776 // nodeId: openroadm-topology level node
777 // deviceNodeId: openroadm-network level node
778 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
779 String[] params = nodeId.getValue().split("-");
780 // DEGx or SRGx or XPDRx
781 String moduleName = params[params.length - 1];
782 for (McCapabilities mcCapabitility : mcCapabilities) {
783 if (mcCapabitility.getMcNodeName().contains("XPDR")
784 && mcCapabitility.getSlotWidthGranularity() != null) {
785 return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
787 if (mcCapabitility.getMcNodeName().contains(moduleName)
788 && mcCapabitility.getSlotWidthGranularity() != null) {
789 return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
792 return GridConstant.SLOT_WIDTH_50;
796 * Get mc capability central-width granularity for device.
797 * @param deviceNodeId String
798 * @param nodeId NodeId
799 * @return center-freq granularity
801 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
802 // nodeId: openroadm-topology level node
803 // deviceNodeId: openroadm-network level node
804 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
805 String[] params = nodeId.getValue().split("-");
806 // DEGx or SRGx or XPDRx
807 String moduleName = params[params.length - 1];
808 for (McCapabilities mcCapabitility : mcCapabilities) {
809 if (mcCapabitility.getMcNodeName().contains("XPDR")
810 && mcCapabitility.getCenterFreqGranularity() != null) {
811 return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
813 if (mcCapabitility.getMcNodeName().contains(moduleName)
814 && mcCapabitility.getCenterFreqGranularity() != null) {
815 return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
818 return GridConstant.SLOT_WIDTH_50;