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.constraints.PceConstraints;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilities;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.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.device.types.rev191129.PortQual;
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.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 = null;
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 Long serviceRate = 0L;
68 private PceConstraints pceHardConstraints;
70 ///////////// Intermediate data/////////////////
71 private List<PceLink> addLinks = new ArrayList<>();
72 private List<PceLink> dropLinks = new ArrayList<>();
73 private HashSet<NodeId> azSrgs = new HashSet<>();
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 Set<LinkId> linksToExclude = new HashSet<>();
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.info("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);
129 private boolean parseInput() {
130 if (input.getServiceAEnd().getServiceFormat() == null || input.getServiceZEnd().getServiceFormat() == null
131 || input.getServiceAEnd().getServiceRate() == null) {
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().toJava();
139 LOG.info("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
142 if (StringConstants.SERVICE_TYPE_ODU4.equals(serviceType)
143 || StringConstants.SERVICE_TYPE_ODUC4.equals(serviceType)
144 || StringConstants.SERVICE_TYPE_100GE_M.equals(serviceType)
145 || StringConstants.SERVICE_TYPE_10GE.equals(serviceType)
146 || StringConstants.SERVICE_TYPE_1GE.equals(serviceType)) {
147 anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
148 znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
150 anodeId = input.getServiceAEnd().getNodeId();
151 znodeId = input.getServiceZEnd().getNodeId();
154 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
155 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
159 private void setServiceType() {
160 if ("Ethernet".equals(serviceFormatA)) {
161 switch (serviceRate.intValue()) {
163 serviceType = StringConstants.SERVICE_TYPE_1GE;
166 serviceType = StringConstants.SERVICE_TYPE_10GE;
169 serviceType = StringConstants.SERVICE_TYPE_100GE_T;
170 if (NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId())
171 .getNodeInfo().getNodeType())) {
172 if (input.getServiceAEnd().getTxDirection() != null
173 && input.getServiceAEnd().getTxDirection().getPort() != null
174 && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null) {
175 String lcp = input.getServiceAEnd().getTxDirection().getPort().getPortName();
176 if (portMapping.getMapping(input.getServiceAEnd().getNodeId(), lcp) != null) {
177 Mapping mapping = portMapping.getMapping(input.getServiceAEnd().getNodeId(), lcp);
178 if (PortQual.SwitchClient.getName().equals(mapping.getPortQual())) {
179 serviceType = StringConstants.SERVICE_TYPE_100GE_M;
186 serviceType = StringConstants.SERVICE_TYPE_400GE;
189 LOG.warn("Invalid service-rate {}", serviceRate);
193 if ("OC".equals(serviceFormatA) && Long.valueOf(100L).equals(serviceRate)) {
194 serviceType = StringConstants.SERVICE_TYPE_100GE_T;
196 if ("OTU".equals(serviceFormatA)) {
197 switch (serviceRate.intValue()) {
199 serviceType = StringConstants.SERVICE_TYPE_OTU4;
202 serviceType = StringConstants.SERVICE_TYPE_OTUC4;
205 LOG.warn("Invalid service-rate {}", serviceRate);
209 if ("ODU".equals(serviceFormatA)) {
210 switch (serviceRate.intValue()) {
212 serviceType = StringConstants.SERVICE_TYPE_ODU4;
215 serviceType = StringConstants.SERVICE_TYPE_ODUC4;
218 LOG.warn("Invalid service-rate {}", serviceRate);
224 private boolean readMdSal() {
225 InstanceIdentifier<Network> nwInstanceIdentifier = null;
226 switch (serviceType) {
227 case StringConstants.SERVICE_TYPE_100GE_T:
228 case StringConstants.SERVICE_TYPE_400GE:
229 case StringConstants.SERVICE_TYPE_OTU4:
230 case StringConstants.SERVICE_TYPE_OTUC4:
231 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
232 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
233 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
235 case StringConstants.SERVICE_TYPE_100GE_M:
236 case StringConstants.SERVICE_TYPE_ODU4:
237 case StringConstants.SERVICE_TYPE_ODUC4:
238 case StringConstants.SERVICE_TYPE_10GE:
239 case StringConstants.SERVICE_TYPE_1GE:
240 LOG.info("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
241 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
242 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
245 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
250 if (readTopology(nwInstanceIdentifier) != null) {
251 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
252 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
253 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
255 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
256 -> l1.getSource().getSourceTp().toString().compareTo(l2.getSource().getSourceTp().toString()))
257 .collect(Collectors.toList());
259 LOG.warn("no otn links in otn-topology");
261 if (allNodes == null || allNodes.isEmpty()) {
262 LOG.error("readMdSal: no nodes ");
265 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
266 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
268 if (allLinks == null || allLinks.isEmpty()) {
269 LOG.error("readMdSal: no links ");
272 LOG.info("readMdSal: network links: {} links added", allLinks.size());
273 LOG.debug("readMdSal: network links: {} links added", allLinks);
277 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
282 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
285 Optional<Network> nwOptional =
286 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
287 if (nwOptional.isPresent()) {
288 nw = nwOptional.get();
289 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
290 networkTransactionService.close();
292 } catch (InterruptedException | ExecutionException e) {
293 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
294 networkTransactionService.close();
295 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
296 throw new RuntimeException(
297 "readMdSal: Error reading from operational store, topology : " + nwInstanceIdentifier + " :" + e);
302 private boolean analyzeNw() {
304 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
306 if (StringConstants.SERVICE_TYPE_100GE_T.equals(serviceType)
307 || StringConstants.SERVICE_TYPE_OTU4.equals(serviceType)
308 || StringConstants.SERVICE_TYPE_400GE.equals(serviceType)
309 || StringConstants.SERVICE_TYPE_OTUC4.equals(serviceType)) {
310 // 100GE service and OTU4 service are handled at the openroadm-topology layer
311 for (Node node : allNodes) {
315 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
317 if (aendPceNode == null || zendPceNode == null) {
318 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
321 for (Link link : allLinks) {
325 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
327 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
328 for (NodeId srg : azSrgs) {
329 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
332 for (PceLink link : addLinks) {
333 filteraddLinks(link);
335 for (PceLink link : dropLinks) {
336 filterdropLinks(link);
340 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
342 for (Node node : allNodes) {
343 validateOtnNode(node);
346 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
348 if (aendPceNode == null || zendPceNode == null) {
349 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
352 for (Link link : allLinks) {
357 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
359 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
363 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
364 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
369 private boolean filteraddLinks(PceLink pcelink) {
371 NodeId nodeId = pcelink.getSourceId();
373 if (azSrgs.contains(nodeId)) {
374 allPceLinks.put(pcelink.getLinkId(), pcelink);
375 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
376 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
380 // remove the SRG from PceNodes, as it is not directly connected to A/Z
381 allPceNodes.remove(nodeId);
382 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
387 private boolean filterdropLinks(PceLink pcelink) {
389 NodeId nodeId = pcelink.getDestId();
391 if (azSrgs.contains(nodeId)) {
392 allPceLinks.put(pcelink.getLinkId(), pcelink);
393 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
394 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
398 // remove the SRG from PceNodes, as it is not directly connected to A/Z
399 allPceNodes.remove(pcelink.getDestId());
400 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
405 private boolean validateLink(Link link) {
406 LOG.info("validateLink: link {} ", link);
408 NodeId sourceId = link.getSource().getSourceNode();
409 NodeId destId = link.getDestination().getDestNode();
410 PceNode source = allPceNodes.get(sourceId);
411 PceNode dest = allPceNodes.get(destId);
412 State state = link.augmentation(Link1.class).getOperationalState();
414 if (source == null) {
415 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
416 link.getSource().getSourceNode().getValue());
420 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
421 link.getDestination().getDestNode().getValue());
425 if (State.OutOfService.equals(state)) {
426 LOG.debug("validateLink: Link is ignored due operational state - {}",
431 switch (serviceType) {
432 case StringConstants.SERVICE_TYPE_100GE_T:
433 case StringConstants.SERVICE_TYPE_OTU4:
434 case StringConstants.SERVICE_TYPE_OTUC4:
435 case StringConstants.SERVICE_TYPE_400GE:
436 return processPceLink(link, sourceId, destId, source, dest);
437 case StringConstants.SERVICE_TYPE_ODU4:
438 case StringConstants.SERVICE_TYPE_10GE:
439 case StringConstants.SERVICE_TYPE_100GE_M:
440 case StringConstants.SERVICE_TYPE_ODUC4:
441 case StringConstants.SERVICE_TYPE_1GE:
442 return processPceOtnLink(link, source, dest);
444 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
449 private void validateNode(Node node) {
450 LOG.debug("validateNode: node {} ", node);
451 // PceNode will be used in Graph algorithm
452 Node1 node1 = node.augmentation(Node1.class);
454 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
457 if (State.OutOfService.equals(node1.getOperationalState())) {
458 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
462 OpenroadmNodeType nodeType = node1.getNodeType();
463 String deviceNodeId = MapUtils.getSupNetworkNode(node);
464 // Should never happen but because of existing topology test files
465 // we have to manage this case
466 if (deviceNodeId == null || deviceNodeId.isBlank()) {
467 deviceNodeId = node.getNodeId().getValue();
470 LOG.info("Device node id {} for {}", deviceNodeId, node);
471 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
472 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
473 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
474 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
475 pceNode.initFrequenciesBitSet();
477 if (!pceNode.isValid()) {
478 LOG.warn(" validateNode: Node is ignored");
481 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
484 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.aendPceNode == null
485 && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
486 this.aendPceNode = pceNode;
488 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.zendPceNode == null
489 && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
490 this.zendPceNode = pceNode;
493 allPceNodes.put(pceNode.getNodeId(), pceNode);
494 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
498 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
499 switch (serviceFormat) {
502 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
507 if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue()
508 .equals(this.input.getServiceAEnd().getRxDirection().getPort().getPortDeviceName())) {
511 if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue()
512 .equals(this.input.getServiceZEnd().getRxDirection().getPort().getPortDeviceName())) {
517 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
522 private void validateOtnNode(Node node) {
523 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
524 // PceOtnNode will be used in Graph algorithm
525 if (node.augmentation(Node1.class) != null) {
526 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
528 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType);
529 pceOtnNode.validateXponder(anodeId, znodeId);
531 if (!pceOtnNode.isValid()) {
532 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
535 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
538 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
539 this.aendPceNode = pceOtnNode;
541 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
542 this.zendPceNode = pceOtnNode;
544 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
545 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
548 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
553 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
554 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
555 return ConstraintTypes.NONE;
557 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
558 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
559 return ConstraintTypes.HARD_EXCLUDE;
561 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
562 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
563 return ConstraintTypes.HARD_EXCLUDE;
565 return ConstraintTypes.NONE;
568 private ConstraintTypes validateLinkConstraints(PceLink link) {
569 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
570 return ConstraintTypes.NONE;
573 // for now SRLG is the only constraint for link
574 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
575 return ConstraintTypes.NONE;
578 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
579 constraints.retainAll(link.getsrlgList());
580 if (!constraints.isEmpty()) {
581 LOG.info("validateLinkConstraints: {}", link.getLinkId().getValue());
582 return ConstraintTypes.HARD_EXCLUDE;
585 return ConstraintTypes.NONE;
588 private void dropOppositeLink(Link link) {
589 LinkId opplink = MapUtils.extractOppositeLink(link);
591 if (allPceLinks.containsKey(opplink)) {
592 allPceLinks.remove(opplink);
594 linksToExclude.add(opplink);
598 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
599 switch (openroadmNodeType) {
601 pceNode.initSrgTps();
602 this.azSrgs.add(nodeId);
605 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
608 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
612 if (!pceNode.isValid()) {
613 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
619 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
620 PceLink pcelink = new PceLink(link, source, dest);
621 if (!pcelink.isValid()) {
622 dropOppositeLink(link);
623 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
626 LinkId linkId = pcelink.getLinkId();
627 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
628 dropOppositeLink(link);
629 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
632 switch (pcelink.getlinkType()) {
635 allPceLinks.put(linkId, pcelink);
636 source.addOutgoingLink(pcelink);
637 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
638 pcelink.getlinkType(), pcelink);
641 pcelink.setClient(source.getRdmSrgClient(pcelink.getSourceTP().toString()));
642 addLinks.add(pcelink);
643 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
646 pcelink.setClient(dest.getRdmSrgClient(pcelink.getDestTP().toString()));
647 dropLinks.add(pcelink);
648 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
651 // store separately all SRG links directly
652 azSrgs.add(sourceId);
654 if (!dest.checkTP(pcelink.getDestTP().toString())) {
656 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
659 if (dest.getXpdrClient(pcelink.getDestTP().toString()) != null) {
660 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().toString()));
662 allPceLinks.put(linkId, pcelink);
663 source.addOutgoingLink(pcelink);
664 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
666 // does it mean XPONDER==>>SRG ?
668 // store separately all SRG links directly
671 if (!source.checkTP(pcelink.getSourceTP().toString())) {
673 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
676 if (source.getXpdrClient(pcelink.getSourceTP().toString()) != null) {
677 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().toString()));
679 allPceLinks.put(linkId, pcelink);
680 source.addOutgoingLink(pcelink);
681 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
684 LOG.warn("validateLink: link type is not supported {}", pcelink);
689 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
690 PceLink pceOtnLink = new PceLink(link, source, dest);
692 if (!pceOtnLink.isOtnValid(link, serviceType)) {
693 dropOppositeLink(link);
694 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
698 LinkId linkId = pceOtnLink.getLinkId();
699 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
700 dropOppositeLink(link);
701 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
705 switch (pceOtnLink.getlinkType()) {
707 if (dest.getXpdrClient(pceOtnLink.getDestTP().toString()) != null) {
708 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().toString()));
711 allPceLinks.put(linkId, pceOtnLink);
712 source.addOutgoingLink(pceOtnLink);
713 LOG.info("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
716 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
721 public PceNode getaendPceNode() {
725 public PceNode getzendPceNode() {
729 public Map<NodeId, PceNode> getAllPceNodes() {
730 return this.allPceNodes;
733 public Map<LinkId, PceLink> getAllPceLinks() {
734 return this.allPceLinks;
737 public String getServiceType() {
741 public PceResult getReturnStructure() {
742 return returnStructure;
745 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
746 allPceNodes.forEach(((nodeId, pceNode) -> {
747 LOG.info("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
748 pceNode.getOutgoingLinks());
753 * Get mc capability slot width granularity for device.
754 * @param deviceNodeId String
755 * @param nodeId NodeId
756 * @return slot width granularity
758 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
759 // nodeId: openroadm-topology level node
760 // deviceNodeId: openroadm-network level node
761 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
762 String[] params = nodeId.getValue().split("-");
763 // DEGx or SRGx or XPDRx
764 String moduleName = params[params.length - 1];
765 for (McCapabilities mcCapabitility : mcCapabilities) {
766 if (mcCapabitility.getMcNodeName().contains("XPDR")
767 && mcCapabitility.getSlotWidthGranularity() != null) {
768 return mcCapabitility.getSlotWidthGranularity().getValue();
770 if (mcCapabitility.getMcNodeName().contains(moduleName)
771 && mcCapabitility.getSlotWidthGranularity() != null) {
772 return mcCapabitility.getSlotWidthGranularity().getValue();
775 return GridConstant.SLOT_WIDTH_50;
779 * Get mc capability central-width granularity for device.
780 * @param deviceNodeId String
781 * @param nodeId NodeId
782 * @return center-freq granularity
784 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
785 // nodeId: openroadm-topology level node
786 // deviceNodeId: openroadm-network level node
787 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
788 String[] params = nodeId.getValue().split("-");
789 // DEGx or SRGx or XPDRx
790 String moduleName = params[params.length - 1];
791 for (McCapabilities mcCapabitility : mcCapabilities) {
792 if (mcCapabitility.getMcNodeName().contains("XPDR")
793 && mcCapabitility.getCenterFreqGranularity() != null) {
794 return mcCapabitility.getCenterFreqGranularity().getValue();
796 if (mcCapabitility.getMcNodeName().contains(moduleName)
797 && mcCapabitility.getCenterFreqGranularity() != null) {
798 return mcCapabitility.getCenterFreqGranularity().getValue();
801 return GridConstant.SLOT_WIDTH_50;