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 java.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.List;
17 import java.util.Optional;
19 import java.util.concurrent.ExecutionException;
20 import java.util.stream.Collectors;
21 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
22 import org.opendaylight.transportpce.common.NetworkUtils;
23 import org.opendaylight.transportpce.common.ResponseCodes;
24 import org.opendaylight.transportpce.common.StringConstants;
25 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
26 import org.opendaylight.transportpce.common.mapping.MappingUtils;
27 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
28 import org.opendaylight.transportpce.common.mapping.PortMapping;
29 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
30 import org.opendaylight.transportpce.common.service.ServiceTypes;
31 import org.opendaylight.transportpce.pce.PceComplianceCheck;
32 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.PathComputationRequestInput;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mc.capabilities.McCapabilities;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.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.rev200529.OpenroadmLinkType;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.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 = null;
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 HashSet<NodeId> azSrgs = new HashSet<>();
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 Set<LinkId> linksToExclude = new HashSet<>();
88 private PceResult returnStructure;
89 private PortMapping portMapping;
91 private enum ConstraintTypes {
92 NONE, HARD_EXCLUDE, HARD_INCLUDE, HARD_DIVERSITY, SOFT_EXCLUDE, SOFT_INCLUDE, SOFT_DIVERSITY;
95 private MappingUtils mappingUtils;
97 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
98 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc,
99 PortMapping portMapping) {
101 this.networkTransactionService = networkTransactionService;
102 this.returnStructure = rc;
104 this.pceHardConstraints = pceHardConstraints;
105 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
106 this.portMapping = portMapping;
110 public void retrievePceNetwork() {
112 LOG.info("In PceCalculation retrieveNetwork: ");
115 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
118 MapUtils.mapDiversityConstraints(allNodes, allLinks, pceHardConstraints);
121 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
124 printNodesInfo(allPceNodes);
126 returnStructure.setRC(ResponseCodes.RESPONSE_OK);
130 private boolean parseInput() {
131 if (!PceComplianceCheck.checkString(input.getServiceAEnd().getServiceFormat().getName())
132 || !PceComplianceCheck.checkString(input.getServiceZEnd().getServiceFormat().getName())
133 || !PceComplianceCheck.checkString(input.getServiceAEnd().getServiceRate().toString())) {
134 LOG.error("Service Format and Service Rate are required for a path calculation");
137 serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
138 serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
139 serviceRate = input.getServiceAEnd().getServiceRate();
140 serviceType = ServiceTypes.getServiceType(serviceFormatA, serviceRate,
141 (NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
142 && input.getServiceAEnd().getTxDirection() != null
143 && input.getServiceAEnd().getTxDirection().getPort() != null
144 && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null)
145 ? portMapping.getMapping(input.getServiceAEnd().getNodeId(),
146 input.getServiceAEnd().getTxDirection().getPort().getPortName())
149 LOG.info("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
153 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
154 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
158 private void getAZnodeId() {
159 if (input.getServiceAEnd() != null
160 && input.getServiceAEnd().getTxDirection() != null
161 && input.getServiceAEnd().getTxDirection().getPort() != null
162 && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null) {
163 anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
165 anodeId = input.getServiceAEnd().getNodeId();
167 if (input.getServiceZEnd() != null
168 && input.getServiceZEnd().getTxDirection() != null
169 && input.getServiceZEnd().getTxDirection().getPort() != null
170 && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null) {
171 znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
173 znodeId = input.getServiceZEnd().getNodeId();
177 private boolean readMdSal() {
178 InstanceIdentifier<Network> nwInstanceIdentifier = null;
179 switch (serviceType) {
180 case StringConstants.SERVICE_TYPE_100GE_T:
181 case StringConstants.SERVICE_TYPE_400GE:
182 case StringConstants.SERVICE_TYPE_OTU4:
183 case StringConstants.SERVICE_TYPE_OTUC2:
184 case StringConstants.SERVICE_TYPE_OTUC3:
185 case StringConstants.SERVICE_TYPE_OTUC4:
186 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
187 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
188 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
190 case StringConstants.SERVICE_TYPE_100GE_M:
191 case StringConstants.SERVICE_TYPE_100GE_S:
192 case StringConstants.SERVICE_TYPE_ODU4:
193 case StringConstants.SERVICE_TYPE_ODUC2:
194 case StringConstants.SERVICE_TYPE_ODUC3:
195 case StringConstants.SERVICE_TYPE_ODUC4:
196 case StringConstants.SERVICE_TYPE_10GE:
197 case StringConstants.SERVICE_TYPE_1GE:
198 LOG.info("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
199 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
200 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
203 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
208 if (readTopology(nwInstanceIdentifier) == null) {
209 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
213 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
214 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
215 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
217 LOG.warn("no otn links in otn-topology");
219 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
220 -> l1.getSource().getSourceTp().getValue().compareTo(l2.getSource().getSourceTp().getValue()))
221 .collect(Collectors.toList());
223 if (allNodes == null || allNodes.isEmpty()) {
224 LOG.error("readMdSal: no nodes ");
227 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
228 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
230 if (allLinks == null || allLinks.isEmpty()) {
231 LOG.error("readMdSal: no links ");
234 LOG.info("readMdSal: network links: {} links added", allLinks.size());
235 LOG.debug("readMdSal: network links: {} links added", allLinks);
240 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
243 Optional<Network> nwOptional =
244 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
245 if (nwOptional.isPresent()) {
246 nw = nwOptional.get();
247 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
248 networkTransactionService.close();
250 } catch (InterruptedException | ExecutionException e) {
251 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
252 networkTransactionService.close();
253 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
254 throw new RuntimeException(
255 "readMdSal: Error reading from operational store, topology : " + nwInstanceIdentifier + " :" + e);
260 private boolean analyzeNw() {
262 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
263 switch (serviceType) {
264 case StringConstants.SERVICE_TYPE_100GE_T:
265 case StringConstants.SERVICE_TYPE_OTU4:
266 case StringConstants.SERVICE_TYPE_400GE:
267 case StringConstants.SERVICE_TYPE_OTUC2:
268 case StringConstants.SERVICE_TYPE_OTUC3:
269 case StringConstants.SERVICE_TYPE_OTUC4:
270 // 100GE service and OTU4 service are handled at the openroadm-topology layer
271 for (Node node : allNodes) {
275 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
277 if (aendPceNode == null || zendPceNode == null) {
278 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
281 for (Link link : allLinks) {
285 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
287 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
288 for (NodeId srg : azSrgs) {
289 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
292 for (PceLink link : addLinks) {
293 filteraddLinks(link);
295 for (PceLink link : dropLinks) {
296 filterdropLinks(link);
301 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
303 for (Node node : allNodes) {
304 validateOtnNode(node);
307 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
309 if (aendPceNode == null || zendPceNode == null) {
310 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
313 for (Link link : allLinks) {
319 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
321 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
325 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
326 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
331 private boolean filteraddLinks(PceLink pcelink) {
333 NodeId nodeId = pcelink.getSourceId();
335 if (azSrgs.contains(nodeId)) {
336 allPceLinks.put(pcelink.getLinkId(), pcelink);
337 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
338 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
342 // remove the SRG from PceNodes, as it is not directly connected to A/Z
343 allPceNodes.remove(nodeId);
344 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
349 private boolean filterdropLinks(PceLink pcelink) {
351 NodeId nodeId = pcelink.getDestId();
353 if (azSrgs.contains(nodeId)) {
354 allPceLinks.put(pcelink.getLinkId(), pcelink);
355 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
356 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
360 // remove the SRG from PceNodes, as it is not directly connected to A/Z
361 allPceNodes.remove(pcelink.getDestId());
362 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
367 private boolean validateLink(Link link) {
368 LOG.info("validateLink: link {} ", link);
370 NodeId sourceId = link.getSource().getSourceNode();
371 NodeId destId = link.getDestination().getDestNode();
372 PceNode source = allPceNodes.get(sourceId);
373 PceNode dest = allPceNodes.get(destId);
374 State state = link.augmentation(Link1.class).getOperationalState();
376 if (source == null) {
377 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
378 link.getSource().getSourceNode().getValue());
382 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
383 link.getDestination().getDestNode().getValue());
387 if (State.OutOfService.equals(state)) {
388 LOG.debug("validateLink: Link is ignored due operational state - {}",
393 switch (serviceType) {
394 case StringConstants.SERVICE_TYPE_100GE_T:
395 case StringConstants.SERVICE_TYPE_OTU4:
396 case StringConstants.SERVICE_TYPE_OTUC2:
397 case StringConstants.SERVICE_TYPE_OTUC3:
398 case StringConstants.SERVICE_TYPE_OTUC4:
399 case StringConstants.SERVICE_TYPE_400GE:
400 return processPceLink(link, sourceId, destId, source, dest);
401 case StringConstants.SERVICE_TYPE_ODU4:
402 case StringConstants.SERVICE_TYPE_10GE:
403 case StringConstants.SERVICE_TYPE_100GE_M:
404 case StringConstants.SERVICE_TYPE_100GE_S:
405 case StringConstants.SERVICE_TYPE_ODUC2:
406 case StringConstants.SERVICE_TYPE_ODUC3:
407 case StringConstants.SERVICE_TYPE_ODUC4:
408 case StringConstants.SERVICE_TYPE_1GE:
409 return processPceOtnLink(link, source, dest);
411 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
416 private void validateNode(Node node) {
417 LOG.info("validateNode: node {} ", node);
418 // PceNode will be used in Graph algorithm
419 Node1 node1 = node.augmentation(Node1.class);
421 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
424 if (State.OutOfService.equals(node1.getOperationalState())) {
425 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
429 OpenroadmNodeType nodeType = node1.getNodeType();
430 String deviceNodeId = MapUtils.getSupNetworkNode(node);
431 // Should never happen but because of existing topology test files
432 // we have to manage this case
433 if (deviceNodeId == null || deviceNodeId.isBlank()) {
434 deviceNodeId = node.getNodeId().getValue();
437 LOG.info("Device node id {} for {}", deviceNodeId, node);
438 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
439 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
440 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
441 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
442 pceNode.initFrequenciesBitSet();
444 if (!pceNode.isValid()) {
445 LOG.warn(" validateNode: Node is ignored");
448 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
452 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode)) {
453 if (this.aendPceNode == null && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
454 // Added to ensure A-node has a addlink in the topology
455 List<Link> links = this.allLinks.stream()
456 .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
457 .collect(Collectors.toList());
458 if (links.size() > 0) {
459 this.aendPceNode = pceNode;
462 if (this.zendPceNode == null && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
463 // Added to ensure Z-node has a droplink in the topology
464 List<Link> links = this.allLinks.stream()
465 .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
466 .collect(Collectors.toList());
467 if (links.size() > 0) {
468 this.zendPceNode = pceNode;
473 allPceNodes.put(pceNode.getNodeId(), pceNode);
474 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
478 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
479 switch (serviceFormat) {
482 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
485 if ("A".equals(azEndPoint)
486 && this.input.getServiceAEnd().getTxDirection() != null
487 && this.input.getServiceAEnd().getTxDirection().getPort() != null
488 && this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null
489 && pceNode.getNodeId().getValue()
490 .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName())) {
493 if ("Z".equals(azEndPoint)
494 && this.input.getServiceZEnd().getTxDirection() != null
495 && this.input.getServiceZEnd().getTxDirection().getPort() != null
496 && this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null
497 && pceNode.getNodeId().getValue()
498 .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName())) {
503 if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue()
504 .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName())) {
507 if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue()
508 .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName())) {
513 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
518 private void validateOtnNode(Node node) {
519 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
520 // PceOtnNode will be used in Graph algorithm
521 if (node.augmentation(Node1.class) == null) {
522 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
526 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
527 String clientPort = null;
528 if (node.getNodeId().getValue().equals(anodeId)
529 && this.aendPceNode == null
530 && input.getServiceAEnd() != null
531 && input.getServiceAEnd().getRxDirection() != null
532 && input.getServiceAEnd().getRxDirection().getPort() != null
533 && input.getServiceAEnd().getRxDirection().getPort().getPortName() != null) {
534 clientPort = input.getServiceAEnd().getRxDirection().getPort().getPortName();
535 } else if (node.getNodeId().getValue().equals(znodeId)
536 && this.zendPceNode == null
537 && input.getServiceZEnd() != null
538 && input.getServiceZEnd().getRxDirection() != null
539 && input.getServiceZEnd().getRxDirection().getPort() != null
540 && input.getServiceZEnd().getRxDirection().getPort().getPortName() != null) {
541 clientPort = input.getServiceZEnd().getRxDirection().getPort().getPortName();
544 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType, clientPort);
545 pceOtnNode.validateXponder(anodeId, znodeId);
547 if (!pceOtnNode.isValid()) {
548 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
551 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
554 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
555 this.aendPceNode = pceOtnNode;
557 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
558 this.zendPceNode = pceOtnNode;
560 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
561 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
565 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
566 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
567 return ConstraintTypes.NONE;
569 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
570 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
571 return ConstraintTypes.HARD_EXCLUDE;
573 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
574 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
575 return ConstraintTypes.HARD_EXCLUDE;
577 return ConstraintTypes.NONE;
580 private ConstraintTypes validateLinkConstraints(PceLink link) {
581 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
582 return ConstraintTypes.NONE;
585 // for now SRLG is the only constraint for link
586 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
587 return ConstraintTypes.NONE;
590 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
591 constraints.retainAll(link.getsrlgList());
592 if (!constraints.isEmpty()) {
593 LOG.info("validateLinkConstraints: {}", link.getLinkId().getValue());
594 return ConstraintTypes.HARD_EXCLUDE;
597 return ConstraintTypes.NONE;
600 private void dropOppositeLink(Link link) {
601 LinkId opplink = MapUtils.extractOppositeLink(link);
603 if (allPceLinks.containsKey(opplink)) {
604 allPceLinks.remove(opplink);
606 linksToExclude.add(opplink);
610 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
611 switch (openroadmNodeType) {
613 pceNode.initSrgTps();
614 this.azSrgs.add(nodeId);
617 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
620 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
624 if (!pceNode.isValid()) {
625 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
631 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
632 PceLink pcelink = new PceLink(link, source, dest);
633 if (!pcelink.isValid()) {
634 dropOppositeLink(link);
635 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
638 LinkId linkId = pcelink.getLinkId();
639 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
640 dropOppositeLink(link);
641 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
644 switch (pcelink.getlinkType()) {
647 allPceLinks.put(linkId, pcelink);
648 source.addOutgoingLink(pcelink);
649 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
650 pcelink.getlinkType(), pcelink);
654 source.getRdmSrgClient(pcelink.getSourceTP().getValue(), StringConstants.SERVICE_DIRECTION_AZ));
655 addLinks.add(pcelink);
656 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
660 dest.getRdmSrgClient(pcelink.getDestTP().getValue(), StringConstants.SERVICE_DIRECTION_ZA));
661 dropLinks.add(pcelink);
662 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
665 // store separately all SRG links directly
666 azSrgs.add(sourceId);
668 if (!dest.checkTP(pcelink.getDestTP().getValue())) {
670 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
673 if (dest.getXpdrClient(pcelink.getDestTP().getValue()) != null) {
674 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().getValue()));
676 allPceLinks.put(linkId, pcelink);
677 source.addOutgoingLink(pcelink);
678 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
680 // does it mean XPONDER==>>SRG ?
682 // store separately all SRG links directly
685 if (!source.checkTP(pcelink.getSourceTP().getValue())) {
687 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
690 if (source.getXpdrClient(pcelink.getSourceTP().getValue()) != null) {
691 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().getValue()));
693 allPceLinks.put(linkId, pcelink);
694 source.addOutgoingLink(pcelink);
695 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
698 LOG.warn("validateLink: link type is not supported {}", pcelink);
703 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
704 PceLink pceOtnLink = new PceLink(link, source, dest);
706 if (!pceOtnLink.isOtnValid(link, serviceType)) {
707 dropOppositeLink(link);
708 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
712 LinkId linkId = pceOtnLink.getLinkId();
713 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
714 dropOppositeLink(link);
715 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
719 switch (pceOtnLink.getlinkType()) {
721 if (source.getXpdrClient(pceOtnLink.getSourceTP().getValue()) != null) {
722 pceOtnLink.setClient(source.getXpdrClient(pceOtnLink.getSourceTP().getValue()));
724 if (dest.getXpdrClient(pceOtnLink.getDestTP().getValue()) != null) {
725 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().getValue()));
727 allPceLinks.put(linkId, pceOtnLink);
728 source.addOutgoingLink(pceOtnLink);
729 LOG.info("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
732 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
737 public PceNode getaendPceNode() {
741 public PceNode getzendPceNode() {
745 public Map<NodeId, PceNode> getAllPceNodes() {
746 return this.allPceNodes;
749 public Map<LinkId, PceLink> getAllPceLinks() {
750 return this.allPceLinks;
753 public String getServiceType() {
757 public PceResult getReturnStructure() {
758 return returnStructure;
761 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
762 allPceNodes.forEach(((nodeId, pceNode) -> {
763 LOG.info("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
764 pceNode.getOutgoingLinks());
769 * Get mc capability slot width granularity for device.
770 * @param deviceNodeId String
771 * @param nodeId NodeId
772 * @return slot width granularity
774 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
775 // nodeId: openroadm-topology level node
776 // deviceNodeId: openroadm-network level node
777 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
778 String[] params = nodeId.getValue().split("-");
779 // DEGx or SRGx or XPDRx
780 String moduleName = params[params.length - 1];
781 for (McCapabilities mcCapabitility : mcCapabilities) {
782 if (mcCapabitility.getMcNodeName().contains("XPDR")
783 && mcCapabitility.getSlotWidthGranularity() != null) {
784 return mcCapabitility.getSlotWidthGranularity().getValue();
786 if (mcCapabitility.getMcNodeName().contains(moduleName)
787 && mcCapabitility.getSlotWidthGranularity() != null) {
788 return mcCapabitility.getSlotWidthGranularity().getValue();
791 return GridConstant.SLOT_WIDTH_50;
795 * Get mc capability central-width granularity for device.
796 * @param deviceNodeId String
797 * @param nodeId NodeId
798 * @return center-freq granularity
800 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
801 // nodeId: openroadm-topology level node
802 // deviceNodeId: openroadm-network level node
803 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
804 String[] params = nodeId.getValue().split("-");
805 // DEGx or SRGx or XPDRx
806 String moduleName = params[params.length - 1];
807 for (McCapabilities mcCapabitility : mcCapabilities) {
808 if (mcCapabitility.getMcNodeName().contains("XPDR")
809 && mcCapabitility.getCenterFreqGranularity() != null) {
810 return mcCapabitility.getCenterFreqGranularity().getValue();
812 if (mcCapabitility.getMcNodeName().contains(moduleName)
813 && mcCapabitility.getCenterFreqGranularity() != null) {
814 return mcCapabitility.getCenterFreqGranularity().getValue();
817 return GridConstant.SLOT_WIDTH_50;