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.rev220118.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.rev211210.Link1;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1;
38 //import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
39 //import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
44 //import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
45 //import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
55 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
56 import org.opendaylight.yangtools.yang.common.Uint32;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
60 public class PceCalculation {
62 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
63 private NetworkTransactionService networkTransactionService = null;
65 ///////////// data parsed from Input/////////////////
66 private PathComputationRequestInput input;
67 private String anodeId = "";
68 private String znodeId = "";
69 private String serviceFormatA = "";
70 private String serviceFormatZ = "";
71 private String serviceType = "";
72 private Uint32 serviceRate = Uint32.valueOf(0);
74 private PceConstraints pceHardConstraints;
76 ///////////// Intermediate data/////////////////
77 private List<PceLink> addLinks = new ArrayList<>();
78 private List<PceLink> dropLinks = new ArrayList<>();
79 private HashSet<NodeId> azSrgs = new HashSet<>();
81 private PceNode aendPceNode = null;
82 private PceNode zendPceNode = null;
84 private List<Link> allLinks = null;
85 private List<Node> allNodes = null;
87 // this List serves graph calculation
88 private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
89 // this List serves calculation of ZtoA path description
90 // TODO maybe better solution is possible
91 private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
92 private Set<LinkId> linksToExclude = new HashSet<>();
93 private PceResult returnStructure;
94 private PortMapping portMapping;
96 private enum ConstraintTypes {
97 NONE, HARD_EXCLUDE, HARD_INCLUDE, HARD_DIVERSITY, SOFT_EXCLUDE, SOFT_INCLUDE, SOFT_DIVERSITY;
100 private MappingUtils mappingUtils;
102 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
103 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc,
104 PortMapping portMapping) {
106 this.networkTransactionService = networkTransactionService;
107 this.returnStructure = rc;
109 this.pceHardConstraints = pceHardConstraints;
110 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
111 this.portMapping = portMapping;
115 public void retrievePceNetwork() {
117 LOG.info("In PceCalculation retrieveNetwork: ");
120 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
123 MapUtils.mapDiversityConstraints(allNodes, allLinks, pceHardConstraints);
126 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
129 printNodesInfo(allPceNodes);
131 returnStructure.setRC(ResponseCodes.RESPONSE_OK);
135 private boolean parseInput() {
136 if (!PceComplianceCheck.checkString(input.getServiceAEnd().getServiceFormat().getName())
137 || !PceComplianceCheck.checkString(input.getServiceZEnd().getServiceFormat().getName())
138 || !PceComplianceCheck.checkString(input.getServiceAEnd().getServiceRate().toString())) {
139 LOG.error("Service Format and Service Rate are required for a path calculation");
142 serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
143 serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
144 serviceRate = input.getServiceAEnd().getServiceRate();
145 serviceType = ServiceTypes.getServiceType(
148 NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
149 && checkAendInputTxPortName()
150 ? portMapping.getMapping(
151 input.getServiceAEnd().getNodeId(),
152 input.getServiceAEnd().getTxDirection().getPort().getPortName())
155 LOG.info("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
159 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
160 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
164 private boolean checkAendInputTxPortName() {
165 return checkAendInputTxPort()
166 && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null;
169 private boolean checkAendInputTxPortDeviceName() {
170 return checkAendInputTxPort()
171 && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null;
174 private boolean checkAendInputTxPort() {
175 return input.getServiceAEnd() != null
176 && input.getServiceAEnd().getTxDirection() != null
177 && input.getServiceAEnd().getTxDirection().getPort() != null;
180 private boolean checkZendInputTxPortDeviceName() {
181 return input.getServiceZEnd() != null
182 && input.getServiceZEnd().getTxDirection() != null
183 && input.getServiceZEnd().getTxDirection().getPort() != null
184 && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null;
187 private void getAZnodeId() {
189 checkAendInputTxPortDeviceName()
190 ? input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName()
191 : input.getServiceAEnd().getNodeId();
193 checkZendInputTxPortDeviceName()
194 ? input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName()
195 : input.getServiceZEnd().getNodeId();
198 private boolean readMdSal() {
199 InstanceIdentifier<Network> nwInstanceIdentifier = null;
200 switch (serviceType) {
201 case StringConstants.SERVICE_TYPE_100GE_T:
202 case StringConstants.SERVICE_TYPE_400GE:
203 case StringConstants.SERVICE_TYPE_OTU4:
204 case StringConstants.SERVICE_TYPE_OTUC2:
205 case StringConstants.SERVICE_TYPE_OTUC3:
206 case StringConstants.SERVICE_TYPE_OTUC4:
207 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
208 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
209 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
211 case StringConstants.SERVICE_TYPE_100GE_M:
212 case StringConstants.SERVICE_TYPE_100GE_S:
213 case StringConstants.SERVICE_TYPE_ODU4:
214 case StringConstants.SERVICE_TYPE_ODUC2:
215 case StringConstants.SERVICE_TYPE_ODUC3:
216 case StringConstants.SERVICE_TYPE_ODUC4:
217 case StringConstants.SERVICE_TYPE_10GE:
218 case StringConstants.SERVICE_TYPE_1GE:
219 LOG.info("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
220 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
221 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
224 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
229 if (readTopology(nwInstanceIdentifier) == null) {
230 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
234 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
235 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
236 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
238 LOG.warn("no otn links in otn-topology");
240 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
241 -> l1.getSource().getSourceTp().getValue().compareTo(l2.getSource().getSourceTp().getValue()))
242 .collect(Collectors.toList());
244 if (allNodes == null || allNodes.isEmpty()) {
245 LOG.error("readMdSal: no nodes ");
248 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
249 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
251 if (allLinks == null || allLinks.isEmpty()) {
252 LOG.error("readMdSal: no links ");
255 LOG.info("readMdSal: network links: {} links added", allLinks.size());
256 LOG.debug("readMdSal: network links: {} links added", allLinks);
261 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
264 Optional<Network> nwOptional =
265 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
266 if (nwOptional.isPresent()) {
267 nw = nwOptional.get();
268 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
269 networkTransactionService.close();
271 } catch (InterruptedException | ExecutionException e) {
272 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
273 networkTransactionService.close();
274 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
275 throw new RuntimeException(
276 "readMdSal: Error reading from operational store, topology : " + nwInstanceIdentifier + " :" + e);
281 private boolean analyzeNw() {
283 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
284 switch (serviceType) {
285 case StringConstants.SERVICE_TYPE_100GE_T:
286 case StringConstants.SERVICE_TYPE_OTU4:
287 case StringConstants.SERVICE_TYPE_400GE:
288 case StringConstants.SERVICE_TYPE_OTUC2:
289 case StringConstants.SERVICE_TYPE_OTUC3:
290 case StringConstants.SERVICE_TYPE_OTUC4:
291 // 100GE service and OTU4 service are handled at the openroadm-topology layer
292 for (Node node : allNodes) {
296 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
298 if (aendPceNode == null || zendPceNode == null) {
299 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
302 for (Link link : allLinks) {
306 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
308 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
309 for (NodeId srg : azSrgs) {
310 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
313 for (PceLink link : addLinks) {
314 filteraddLinks(link);
316 for (PceLink link : dropLinks) {
317 filterdropLinks(link);
322 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
324 for (Node node : allNodes) {
325 validateOtnNode(node);
328 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
330 if (aendPceNode == null || zendPceNode == null) {
331 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
334 for (Link link : allLinks) {
340 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
342 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
346 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
347 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
352 private boolean filteraddLinks(PceLink pcelink) {
354 NodeId nodeId = pcelink.getSourceId();
356 if (azSrgs.contains(nodeId)) {
357 allPceLinks.put(pcelink.getLinkId(), pcelink);
358 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
359 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
363 // remove the SRG from PceNodes, as it is not directly connected to A/Z
364 allPceNodes.remove(nodeId);
365 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
370 private boolean filterdropLinks(PceLink pcelink) {
372 NodeId nodeId = pcelink.getDestId();
374 if (azSrgs.contains(nodeId)) {
375 allPceLinks.put(pcelink.getLinkId(), pcelink);
376 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
377 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
381 // remove the SRG from PceNodes, as it is not directly connected to A/Z
382 allPceNodes.remove(pcelink.getDestId());
383 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
388 private boolean validateLink(Link link) {
389 LOG.info("validateLink: link {} ", link);
391 NodeId sourceId = link.getSource().getSourceNode();
392 NodeId destId = link.getDestination().getDestNode();
393 PceNode source = allPceNodes.get(sourceId);
394 PceNode dest = allPceNodes.get(destId);
395 State state = link.augmentation(Link1.class).getOperationalState();
397 if (source == null) {
398 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
399 link.getSource().getSourceNode().getValue());
403 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
404 link.getDestination().getDestNode().getValue());
408 if (State.OutOfService.equals(state)) {
409 LOG.debug("validateLink: Link is ignored due operational state - {}",
414 switch (serviceType) {
415 case StringConstants.SERVICE_TYPE_100GE_T:
416 case StringConstants.SERVICE_TYPE_OTU4:
417 case StringConstants.SERVICE_TYPE_OTUC2:
418 case StringConstants.SERVICE_TYPE_OTUC3:
419 case StringConstants.SERVICE_TYPE_OTUC4:
420 case StringConstants.SERVICE_TYPE_400GE:
421 return processPceLink(link, sourceId, destId, source, dest);
422 case StringConstants.SERVICE_TYPE_ODU4:
423 case StringConstants.SERVICE_TYPE_10GE:
424 case StringConstants.SERVICE_TYPE_100GE_M:
425 case StringConstants.SERVICE_TYPE_100GE_S:
426 case StringConstants.SERVICE_TYPE_ODUC2:
427 case StringConstants.SERVICE_TYPE_ODUC3:
428 case StringConstants.SERVICE_TYPE_ODUC4:
429 case StringConstants.SERVICE_TYPE_1GE:
430 return processPceOtnLink(link, source, dest);
432 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
437 private void validateNode(Node node) {
438 LOG.info("validateNode: node {} ", node);
439 // PceNode will be used in Graph algorithm
440 Node1 node1 = node.augmentation(Node1.class);
442 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
445 if (State.OutOfService.equals(node1.getOperationalState())) {
446 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
450 OpenroadmNodeType nodeType = node1.getNodeType();
451 String deviceNodeId = MapUtils.getSupNetworkNode(node);
452 // Should never happen but because of existing topology test files
453 // we have to manage this case
454 if (deviceNodeId == null || deviceNodeId.isBlank()) {
455 deviceNodeId = node.getNodeId().getValue();
458 LOG.info("Device node id {} for {}", deviceNodeId, node);
459 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
460 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
461 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
462 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
463 pceNode.initFrequenciesBitSet();
465 if (!pceNode.isValid()) {
466 LOG.warn(" validateNode: Node is ignored");
469 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
473 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode)) {
474 if (this.aendPceNode == null && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
475 // Added to ensure A-node has a addlink in the topology
476 List<Link> links = this.allLinks.stream()
477 .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
478 .collect(Collectors.toList());
479 if (links.size() > 0) {
480 this.aendPceNode = pceNode;
483 if (this.zendPceNode == null && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
484 // Added to ensure Z-node has a droplink in the topology
485 List<Link> links = this.allLinks.stream()
486 .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
487 .collect(Collectors.toList());
488 if (links.size() > 0) {
489 this.zendPceNode = pceNode;
494 allPceNodes.put(pceNode.getNodeId(), pceNode);
495 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
499 @SuppressWarnings("fallthrough")
501 value = "SF_SWITCH_FALLTHROUGH",
502 justification = "intentional fallthrough")
503 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
504 switch (serviceFormat) {
507 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
512 switch (azEndPoint) {
514 return checkAendInputTxPortDeviceName()
515 && pceNode.getNodeId().getValue()
516 .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName());
518 return checkZendInputTxPortDeviceName()
519 && pceNode.getNodeId().getValue()
520 .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName());
525 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
530 private void validateOtnNode(Node node) {
531 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
532 // PceOtnNode will be used in Graph algorithm
533 if (node.augmentation(Node1.class) == null) {
534 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
538 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
539 String clientPort = null;
540 if (node.getNodeId().getValue().equals(anodeId)
541 && this.aendPceNode == null
542 && input.getServiceAEnd() != null
543 && input.getServiceAEnd().getRxDirection() != null
544 && input.getServiceAEnd().getRxDirection().getPort() != null
545 && input.getServiceAEnd().getRxDirection().getPort().getPortName() != null) {
546 clientPort = input.getServiceAEnd().getRxDirection().getPort().getPortName();
547 } else if (node.getNodeId().getValue().equals(znodeId)
548 && this.zendPceNode == null
549 && input.getServiceZEnd() != null
550 && input.getServiceZEnd().getRxDirection() != null
551 && input.getServiceZEnd().getRxDirection().getPort() != null
552 && input.getServiceZEnd().getRxDirection().getPort().getPortName() != null) {
553 clientPort = input.getServiceZEnd().getRxDirection().getPort().getPortName();
556 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType, clientPort);
557 pceOtnNode.validateXponder(anodeId, znodeId);
559 if (!pceOtnNode.isValid()) {
560 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
563 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
566 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
567 this.aendPceNode = pceOtnNode;
569 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
570 this.zendPceNode = pceOtnNode;
572 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
573 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
577 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
578 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
579 return ConstraintTypes.NONE;
581 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
582 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
583 return ConstraintTypes.HARD_EXCLUDE;
585 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
586 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
587 return ConstraintTypes.HARD_EXCLUDE;
589 return ConstraintTypes.NONE;
592 private ConstraintTypes validateLinkConstraints(PceLink link) {
593 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
594 return ConstraintTypes.NONE;
597 // for now SRLG is the only constraint for link
598 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
599 return ConstraintTypes.NONE;
602 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
603 constraints.retainAll(link.getsrlgList());
604 if (!constraints.isEmpty()) {
605 LOG.info("validateLinkConstraints: {}", link.getLinkId().getValue());
606 return ConstraintTypes.HARD_EXCLUDE;
609 return ConstraintTypes.NONE;
612 private void dropOppositeLink(Link link) {
613 LinkId opplink = MapUtils.extractOppositeLink(link);
615 if (allPceLinks.containsKey(opplink)) {
616 allPceLinks.remove(opplink);
618 linksToExclude.add(opplink);
622 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
623 switch (openroadmNodeType) {
625 pceNode.initSrgTps();
626 this.azSrgs.add(nodeId);
629 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
632 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
636 if (!pceNode.isValid()) {
637 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
643 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
644 PceLink pcelink = new PceLink(link, source, dest);
645 if (!pcelink.isValid()) {
646 dropOppositeLink(link);
647 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
650 LinkId linkId = pcelink.getLinkId();
651 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
652 dropOppositeLink(link);
653 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
656 switch (pcelink.getlinkType()) {
659 allPceLinks.put(linkId, pcelink);
660 source.addOutgoingLink(pcelink);
661 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
662 pcelink.getlinkType(), pcelink);
666 source.getRdmSrgClient(pcelink.getSourceTP().getValue(), StringConstants.SERVICE_DIRECTION_AZ));
667 addLinks.add(pcelink);
668 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
672 dest.getRdmSrgClient(pcelink.getDestTP().getValue(), StringConstants.SERVICE_DIRECTION_ZA));
673 dropLinks.add(pcelink);
674 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
677 // store separately all SRG links directly
678 azSrgs.add(sourceId);
680 if (!dest.checkTP(pcelink.getDestTP().getValue())) {
682 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
685 if (dest.getXpdrClient(pcelink.getDestTP().getValue()) != null) {
686 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().getValue()));
688 allPceLinks.put(linkId, pcelink);
689 source.addOutgoingLink(pcelink);
690 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
692 // does it mean XPONDER==>>SRG ?
694 // store separately all SRG links directly
697 if (!source.checkTP(pcelink.getSourceTP().getValue())) {
699 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
702 if (source.getXpdrClient(pcelink.getSourceTP().getValue()) != null) {
703 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().getValue()));
705 allPceLinks.put(linkId, pcelink);
706 source.addOutgoingLink(pcelink);
707 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
710 LOG.warn("validateLink: link type is not supported {}", pcelink);
715 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
716 PceLink pceOtnLink = new PceLink(link, source, dest);
718 if (!pceOtnLink.isOtnValid(link, serviceType)) {
719 dropOppositeLink(link);
720 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
724 LinkId linkId = pceOtnLink.getLinkId();
725 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
726 dropOppositeLink(link);
727 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
731 switch (pceOtnLink.getlinkType()) {
733 if (source.getXpdrClient(pceOtnLink.getSourceTP().getValue()) != null) {
734 pceOtnLink.setClient(source.getXpdrClient(pceOtnLink.getSourceTP().getValue()));
736 if (dest.getXpdrClient(pceOtnLink.getDestTP().getValue()) != null) {
737 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().getValue()));
739 allPceLinks.put(linkId, pceOtnLink);
740 source.addOutgoingLink(pceOtnLink);
741 LOG.info("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
744 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
749 public PceNode getaendPceNode() {
753 public PceNode getzendPceNode() {
757 public Map<NodeId, PceNode> getAllPceNodes() {
758 return this.allPceNodes;
761 public Map<LinkId, PceLink> getAllPceLinks() {
762 return this.allPceLinks;
765 public String getServiceType() {
769 public PceResult getReturnStructure() {
770 return returnStructure;
773 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
774 allPceNodes.forEach(((nodeId, pceNode) -> {
775 LOG.info("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
776 pceNode.getOutgoingLinks());
781 * Get mc capability slot width granularity for device.
782 * @param deviceNodeId String
783 * @param nodeId NodeId
784 * @return slot width granularity
786 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
787 // nodeId: openroadm-topology level node
788 // deviceNodeId: openroadm-network level node
789 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
790 String[] params = nodeId.getValue().split("-");
791 // DEGx or SRGx or XPDRx
792 String moduleName = params[params.length - 1];
793 for (McCapabilities mcCapabitility : mcCapabilities) {
794 if (mcCapabitility.getMcNodeName().contains("XPDR")
795 && mcCapabitility.getSlotWidthGranularity() != null) {
796 return mcCapabitility.getSlotWidthGranularity().getValue();
798 if (mcCapabitility.getMcNodeName().contains(moduleName)
799 && mcCapabitility.getSlotWidthGranularity() != null) {
800 return mcCapabitility.getSlotWidthGranularity().getValue();
803 return GridConstant.SLOT_WIDTH_50;
807 * Get mc capability central-width granularity for device.
808 * @param deviceNodeId String
809 * @param nodeId NodeId
810 * @return center-freq granularity
812 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
813 // nodeId: openroadm-topology level node
814 // deviceNodeId: openroadm-network level node
815 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
816 String[] params = nodeId.getValue().split("-");
817 // DEGx or SRGx or XPDRx
818 String moduleName = params[params.length - 1];
819 for (McCapabilities mcCapabitility : mcCapabilities) {
820 if (mcCapabitility.getMcNodeName().contains("XPDR")
821 && mcCapabitility.getCenterFreqGranularity() != null) {
822 return mcCapabitility.getCenterFreqGranularity().getValue();
824 if (mcCapabitility.getMcNodeName().contains(moduleName)
825 && mcCapabitility.getCenterFreqGranularity() != null) {
826 return mcCapabitility.getCenterFreqGranularity().getValue();
829 return GridConstant.SLOT_WIDTH_50;