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.pce.PceComplianceCheck;
31 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.PathComputationRequestInput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.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.device.types.rev191129.PortQual;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
51 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
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 Long serviceRate = 0L;
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().toJava();
141 LOG.info("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
146 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
147 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
151 private void getAZnodeId() {
152 if (StringConstants.SERVICE_TYPE_ODU4.equals(serviceType)
153 || StringConstants.SERVICE_TYPE_ODUC4.equals(serviceType)
154 || StringConstants.SERVICE_TYPE_100GE_M.equals(serviceType)
155 || StringConstants.SERVICE_TYPE_10GE.equals(serviceType)
156 || StringConstants.SERVICE_TYPE_1GE.equals(serviceType)) {
157 anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
158 znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
160 anodeId = input.getServiceAEnd().getNodeId();
161 znodeId = input.getServiceZEnd().getNodeId();
165 private void setServiceType() {
166 if ("Ethernet".equals(serviceFormatA)) {
167 switch (serviceRate.intValue()) {
169 serviceType = StringConstants.SERVICE_TYPE_1GE;
172 serviceType = StringConstants.SERVICE_TYPE_10GE;
175 serviceType = StringConstants.SERVICE_TYPE_100GE_T;
176 if (NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId())
177 .getNodeInfo().getNodeType())) {
178 if (input.getServiceAEnd().getTxDirection() != null
179 && input.getServiceAEnd().getTxDirection().getPort() != null
180 && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null) {
181 String lcp = input.getServiceAEnd().getTxDirection().getPort().getPortName();
182 if (portMapping.getMapping(input.getServiceAEnd().getNodeId(), lcp) != null) {
183 Mapping mapping = portMapping.getMapping(input.getServiceAEnd().getNodeId(), lcp);
184 if (PortQual.SwitchClient.getName().equals(mapping.getPortQual())) {
185 serviceType = StringConstants.SERVICE_TYPE_100GE_M;
192 serviceType = StringConstants.SERVICE_TYPE_400GE;
195 LOG.warn("Invalid service-rate {}", serviceRate);
199 if ("OC".equals(serviceFormatA) && Long.valueOf(100L).equals(serviceRate)) {
200 serviceType = StringConstants.SERVICE_TYPE_100GE_T;
202 if ("OTU".equals(serviceFormatA)) {
203 switch (serviceRate.intValue()) {
205 serviceType = StringConstants.SERVICE_TYPE_OTU4;
208 serviceType = StringConstants.SERVICE_TYPE_OTUC4;
211 LOG.warn("Invalid service-rate {}", serviceRate);
215 if ("ODU".equals(serviceFormatA)) {
216 switch (serviceRate.intValue()) {
218 serviceType = StringConstants.SERVICE_TYPE_ODU4;
221 serviceType = StringConstants.SERVICE_TYPE_ODUC4;
224 LOG.warn("Invalid service-rate {}", serviceRate);
230 private boolean readMdSal() {
231 InstanceIdentifier<Network> nwInstanceIdentifier = null;
232 switch (serviceType) {
233 case StringConstants.SERVICE_TYPE_100GE_T:
234 case StringConstants.SERVICE_TYPE_400GE:
235 case StringConstants.SERVICE_TYPE_OTU4:
236 case StringConstants.SERVICE_TYPE_OTUC4:
237 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
238 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
239 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
241 case StringConstants.SERVICE_TYPE_100GE_M:
242 case StringConstants.SERVICE_TYPE_ODU4:
243 case StringConstants.SERVICE_TYPE_ODUC4:
244 case StringConstants.SERVICE_TYPE_10GE:
245 case StringConstants.SERVICE_TYPE_1GE:
246 LOG.info("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
247 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
248 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
251 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
256 if (readTopology(nwInstanceIdentifier) != null) {
257 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
258 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
259 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
261 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
262 -> l1.getSource().getSourceTp().toString().compareTo(l2.getSource().getSourceTp().toString()))
263 .collect(Collectors.toList());
265 LOG.warn("no otn links in otn-topology");
267 if (allNodes == null || allNodes.isEmpty()) {
268 LOG.error("readMdSal: no nodes ");
271 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
272 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
274 if (allLinks == null || allLinks.isEmpty()) {
275 LOG.error("readMdSal: no links ");
278 LOG.info("readMdSal: network links: {} links added", allLinks.size());
279 LOG.debug("readMdSal: network links: {} links added", allLinks);
283 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
288 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
291 Optional<Network> nwOptional =
292 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
293 if (nwOptional.isPresent()) {
294 nw = nwOptional.get();
295 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
296 networkTransactionService.close();
298 } catch (InterruptedException | ExecutionException e) {
299 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
300 networkTransactionService.close();
301 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
302 throw new RuntimeException(
303 "readMdSal: Error reading from operational store, topology : " + nwInstanceIdentifier + " :" + e);
308 private boolean analyzeNw() {
310 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
312 if (StringConstants.SERVICE_TYPE_100GE_T.equals(serviceType)
313 || StringConstants.SERVICE_TYPE_OTU4.equals(serviceType)
314 || StringConstants.SERVICE_TYPE_400GE.equals(serviceType)
315 || StringConstants.SERVICE_TYPE_OTUC4.equals(serviceType)) {
316 // 100GE service and OTU4 service are handled at the openroadm-topology layer
317 for (Node node : allNodes) {
321 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
323 if (aendPceNode == null || zendPceNode == null) {
324 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
327 for (Link link : allLinks) {
331 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
333 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
334 for (NodeId srg : azSrgs) {
335 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
338 for (PceLink link : addLinks) {
339 filteraddLinks(link);
341 for (PceLink link : dropLinks) {
342 filterdropLinks(link);
346 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
348 for (Node node : allNodes) {
349 validateOtnNode(node);
352 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
354 if (aendPceNode == null || zendPceNode == null) {
355 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
358 for (Link link : allLinks) {
363 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
365 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
369 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
370 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
375 private boolean filteraddLinks(PceLink pcelink) {
377 NodeId nodeId = pcelink.getSourceId();
379 if (azSrgs.contains(nodeId)) {
380 allPceLinks.put(pcelink.getLinkId(), pcelink);
381 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
382 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
386 // remove the SRG from PceNodes, as it is not directly connected to A/Z
387 allPceNodes.remove(nodeId);
388 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
393 private boolean filterdropLinks(PceLink pcelink) {
395 NodeId nodeId = pcelink.getDestId();
397 if (azSrgs.contains(nodeId)) {
398 allPceLinks.put(pcelink.getLinkId(), pcelink);
399 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
400 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
404 // remove the SRG from PceNodes, as it is not directly connected to A/Z
405 allPceNodes.remove(pcelink.getDestId());
406 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
411 private boolean validateLink(Link link) {
412 LOG.info("validateLink: link {} ", link);
414 NodeId sourceId = link.getSource().getSourceNode();
415 NodeId destId = link.getDestination().getDestNode();
416 PceNode source = allPceNodes.get(sourceId);
417 PceNode dest = allPceNodes.get(destId);
418 State state = link.augmentation(Link1.class).getOperationalState();
420 if (source == null) {
421 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
422 link.getSource().getSourceNode().getValue());
426 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
427 link.getDestination().getDestNode().getValue());
431 if (State.OutOfService.equals(state)) {
432 LOG.debug("validateLink: Link is ignored due operational state - {}",
437 switch (serviceType) {
438 case StringConstants.SERVICE_TYPE_100GE_T:
439 case StringConstants.SERVICE_TYPE_OTU4:
440 case StringConstants.SERVICE_TYPE_OTUC4:
441 case StringConstants.SERVICE_TYPE_400GE:
442 return processPceLink(link, sourceId, destId, source, dest);
443 case StringConstants.SERVICE_TYPE_ODU4:
444 case StringConstants.SERVICE_TYPE_10GE:
445 case StringConstants.SERVICE_TYPE_100GE_M:
446 case StringConstants.SERVICE_TYPE_ODUC4:
447 case StringConstants.SERVICE_TYPE_1GE:
448 return processPceOtnLink(link, source, dest);
450 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
455 private void validateNode(Node node) {
456 LOG.debug("validateNode: node {} ", node);
457 // PceNode will be used in Graph algorithm
458 Node1 node1 = node.augmentation(Node1.class);
460 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
463 if (State.OutOfService.equals(node1.getOperationalState())) {
464 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
468 OpenroadmNodeType nodeType = node1.getNodeType();
469 String deviceNodeId = MapUtils.getSupNetworkNode(node);
470 // Should never happen but because of existing topology test files
471 // we have to manage this case
472 if (deviceNodeId == null || deviceNodeId.isBlank()) {
473 deviceNodeId = node.getNodeId().getValue();
476 LOG.info("Device node id {} for {}", deviceNodeId, node);
477 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
478 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
479 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
480 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
481 pceNode.initFrequenciesBitSet();
483 if (!pceNode.isValid()) {
484 LOG.warn(" validateNode: Node is ignored");
487 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
490 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.aendPceNode == null
491 && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
492 this.aendPceNode = pceNode;
494 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.zendPceNode == null
495 && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
496 this.zendPceNode = pceNode;
499 allPceNodes.put(pceNode.getNodeId(), pceNode);
500 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
504 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
505 switch (serviceFormat) {
508 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
513 if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue()
514 .equals(this.input.getServiceAEnd().getRxDirection().getPort().getPortDeviceName())) {
517 if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue()
518 .equals(this.input.getServiceZEnd().getRxDirection().getPort().getPortDeviceName())) {
523 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
528 private void validateOtnNode(Node node) {
529 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
530 // PceOtnNode will be used in Graph algorithm
531 if (node.augmentation(Node1.class) != null) {
532 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
534 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType);
535 pceOtnNode.validateXponder(anodeId, znodeId);
537 if (!pceOtnNode.isValid()) {
538 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
541 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
544 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
545 this.aendPceNode = pceOtnNode;
547 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
548 this.zendPceNode = pceOtnNode;
550 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
551 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
554 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
559 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
560 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
561 return ConstraintTypes.NONE;
563 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
564 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
565 return ConstraintTypes.HARD_EXCLUDE;
567 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
568 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
569 return ConstraintTypes.HARD_EXCLUDE;
571 return ConstraintTypes.NONE;
574 private ConstraintTypes validateLinkConstraints(PceLink link) {
575 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
576 return ConstraintTypes.NONE;
579 // for now SRLG is the only constraint for link
580 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
581 return ConstraintTypes.NONE;
584 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
585 constraints.retainAll(link.getsrlgList());
586 if (!constraints.isEmpty()) {
587 LOG.info("validateLinkConstraints: {}", link.getLinkId().getValue());
588 return ConstraintTypes.HARD_EXCLUDE;
591 return ConstraintTypes.NONE;
594 private void dropOppositeLink(Link link) {
595 LinkId opplink = MapUtils.extractOppositeLink(link);
597 if (allPceLinks.containsKey(opplink)) {
598 allPceLinks.remove(opplink);
600 linksToExclude.add(opplink);
604 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
605 switch (openroadmNodeType) {
607 pceNode.initSrgTps();
608 this.azSrgs.add(nodeId);
611 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
614 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
618 if (!pceNode.isValid()) {
619 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
625 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
626 PceLink pcelink = new PceLink(link, source, dest);
627 if (!pcelink.isValid()) {
628 dropOppositeLink(link);
629 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
632 LinkId linkId = pcelink.getLinkId();
633 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
634 dropOppositeLink(link);
635 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
638 switch (pcelink.getlinkType()) {
641 allPceLinks.put(linkId, pcelink);
642 source.addOutgoingLink(pcelink);
643 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
644 pcelink.getlinkType(), pcelink);
647 pcelink.setClient(source.getRdmSrgClient(pcelink.getSourceTP().toString()));
648 addLinks.add(pcelink);
649 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
652 pcelink.setClient(dest.getRdmSrgClient(pcelink.getDestTP().toString()));
653 dropLinks.add(pcelink);
654 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
657 // store separately all SRG links directly
658 azSrgs.add(sourceId);
660 if (!dest.checkTP(pcelink.getDestTP().toString())) {
662 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
665 if (dest.getXpdrClient(pcelink.getDestTP().toString()) != null) {
666 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().toString()));
668 allPceLinks.put(linkId, pcelink);
669 source.addOutgoingLink(pcelink);
670 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
672 // does it mean XPONDER==>>SRG ?
674 // store separately all SRG links directly
677 if (!source.checkTP(pcelink.getSourceTP().toString())) {
679 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
682 if (source.getXpdrClient(pcelink.getSourceTP().toString()) != null) {
683 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().toString()));
685 allPceLinks.put(linkId, pcelink);
686 source.addOutgoingLink(pcelink);
687 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
690 LOG.warn("validateLink: link type is not supported {}", pcelink);
695 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
696 PceLink pceOtnLink = new PceLink(link, source, dest);
698 if (!pceOtnLink.isOtnValid(link, serviceType)) {
699 dropOppositeLink(link);
700 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
704 LinkId linkId = pceOtnLink.getLinkId();
705 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
706 dropOppositeLink(link);
707 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
711 switch (pceOtnLink.getlinkType()) {
713 if (dest.getXpdrClient(pceOtnLink.getDestTP().toString()) != null) {
714 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().toString()));
717 allPceLinks.put(linkId, pceOtnLink);
718 source.addOutgoingLink(pceOtnLink);
719 LOG.info("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
722 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
727 public PceNode getaendPceNode() {
731 public PceNode getzendPceNode() {
735 public Map<NodeId, PceNode> getAllPceNodes() {
736 return this.allPceNodes;
739 public Map<LinkId, PceLink> getAllPceLinks() {
740 return this.allPceLinks;
743 public String getServiceType() {
747 public PceResult getReturnStructure() {
748 return returnStructure;
751 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
752 allPceNodes.forEach(((nodeId, pceNode) -> {
753 LOG.info("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
754 pceNode.getOutgoingLinks());
759 * Get mc capability slot width granularity for device.
760 * @param deviceNodeId String
761 * @param nodeId NodeId
762 * @return slot width granularity
764 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
765 // nodeId: openroadm-topology level node
766 // deviceNodeId: openroadm-network level node
767 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
768 String[] params = nodeId.getValue().split("-");
769 // DEGx or SRGx or XPDRx
770 String moduleName = params[params.length - 1];
771 for (McCapabilities mcCapabitility : mcCapabilities) {
772 if (mcCapabitility.getMcNodeName().contains("XPDR")
773 && mcCapabitility.getSlotWidthGranularity() != null) {
774 return mcCapabitility.getSlotWidthGranularity().getValue();
776 if (mcCapabitility.getMcNodeName().contains(moduleName)
777 && mcCapabitility.getSlotWidthGranularity() != null) {
778 return mcCapabitility.getSlotWidthGranularity().getValue();
781 return GridConstant.SLOT_WIDTH_50;
785 * Get mc capability central-width granularity for device.
786 * @param deviceNodeId String
787 * @param nodeId NodeId
788 * @return center-freq granularity
790 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
791 // nodeId: openroadm-topology level node
792 // deviceNodeId: openroadm-network level node
793 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
794 String[] params = nodeId.getValue().split("-");
795 // DEGx or SRGx or XPDRx
796 String moduleName = params[params.length - 1];
797 for (McCapabilities mcCapabitility : mcCapabilities) {
798 if (mcCapabitility.getMcNodeName().contains("XPDR")
799 && mcCapabitility.getCenterFreqGranularity() != null) {
800 return mcCapabitility.getCenterFreqGranularity().getValue();
802 if (mcCapabitility.getMcNodeName().contains(moduleName)
803 && mcCapabitility.getCenterFreqGranularity() != null) {
804 return mcCapabitility.getCenterFreqGranularity().getValue();
807 return GridConstant.SLOT_WIDTH_50;