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.rev210426.mapping.Mapping;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilities;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
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.opendaylight.yangtools.yang.common.Uint32;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 public class PceCalculation {
58 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
59 private NetworkTransactionService networkTransactionService = null;
61 ///////////// data parsed from Input/////////////////
62 private PathComputationRequestInput input;
63 private String anodeId = "";
64 private String znodeId = "";
65 private String serviceFormatA = "";
66 private String serviceFormatZ = "";
67 private String serviceType = "";
68 private Uint32 serviceRate = Uint32.valueOf(0);
70 private PceConstraints pceHardConstraints;
72 ///////////// Intermediate data/////////////////
73 private List<PceLink> addLinks = new ArrayList<>();
74 private List<PceLink> dropLinks = new ArrayList<>();
75 private HashSet<NodeId> azSrgs = new HashSet<>();
77 private PceNode aendPceNode = null;
78 private PceNode zendPceNode = null;
80 private List<Link> allLinks = null;
81 private List<Node> allNodes = null;
83 // this List serves graph calculation
84 private Map<NodeId, PceNode> allPceNodes = new HashMap<>();
85 // this List serves calculation of ZtoA path description
86 // TODO maybe better solution is possible
87 private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
88 private Set<LinkId> linksToExclude = new HashSet<>();
89 private PceResult returnStructure;
90 private PortMapping portMapping;
92 private enum ConstraintTypes {
93 NONE, HARD_EXCLUDE, HARD_INCLUDE, HARD_DIVERSITY, SOFT_EXCLUDE, SOFT_INCLUDE, SOFT_DIVERSITY;
96 private MappingUtils mappingUtils;
98 public PceCalculation(PathComputationRequestInput input, NetworkTransactionService networkTransactionService,
99 PceConstraints pceHardConstraints, PceConstraints pceSoftConstraints, PceResult rc,
100 PortMapping portMapping) {
102 this.networkTransactionService = networkTransactionService;
103 this.returnStructure = rc;
105 this.pceHardConstraints = pceHardConstraints;
106 this.mappingUtils = new MappingUtilsImpl(networkTransactionService.getDataBroker());
107 this.portMapping = portMapping;
111 public void retrievePceNetwork() {
113 LOG.info("In PceCalculation retrieveNetwork: ");
116 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
119 MapUtils.mapDiversityConstraints(allNodes, allLinks, pceHardConstraints);
122 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
125 printNodesInfo(allPceNodes);
127 returnStructure.setRC(ResponseCodes.RESPONSE_OK);
131 private boolean parseInput() {
132 if (!PceComplianceCheck.checkString(input.getServiceAEnd().getServiceFormat().getName())
133 || !PceComplianceCheck.checkString(input.getServiceZEnd().getServiceFormat().getName())
134 || !PceComplianceCheck.checkString(input.getServiceAEnd().getServiceRate().toString())) {
135 LOG.error("Service Format and Service Rate are required for a path calculation");
138 serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
139 serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
140 serviceRate = input.getServiceAEnd().getServiceRate();
141 if (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 Mapping mapping = portMapping.getMapping(input.getServiceAEnd().getNodeId(),
146 input.getServiceAEnd().getTxDirection().getPort().getPortName());
147 serviceType = ServiceTypes.getServiceType(serviceFormatA, serviceRate, mapping);
149 serviceType = ServiceTypes.getServiceType(serviceFormatA, serviceRate, null);
152 LOG.info("parseInput: A and Z :[{}] and [{}]", anodeId, znodeId);
156 returnStructure.setRate(input.getServiceAEnd().getServiceRate().toJava());
157 returnStructure.setServiceFormat(input.getServiceAEnd().getServiceFormat());
161 private void getAZnodeId() {
162 if (StringConstants.SERVICE_TYPE_ODU4.equals(serviceType)
163 || StringConstants.SERVICE_TYPE_ODUC4.equals(serviceType)
164 || StringConstants.SERVICE_TYPE_100GE_M.equals(serviceType)
165 || StringConstants.SERVICE_TYPE_10GE.equals(serviceType)
166 || StringConstants.SERVICE_TYPE_1GE.equals(serviceType)) {
167 anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
168 znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
170 anodeId = input.getServiceAEnd().getNodeId();
171 znodeId = input.getServiceZEnd().getNodeId();
175 private boolean readMdSal() {
176 InstanceIdentifier<Network> nwInstanceIdentifier = null;
177 switch (serviceType) {
178 case StringConstants.SERVICE_TYPE_100GE_T:
179 case StringConstants.SERVICE_TYPE_400GE:
180 case StringConstants.SERVICE_TYPE_OTU4:
181 case StringConstants.SERVICE_TYPE_OTUC4:
182 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
183 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
184 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).build();
186 case StringConstants.SERVICE_TYPE_100GE_M:
187 case StringConstants.SERVICE_TYPE_ODU4:
188 case StringConstants.SERVICE_TYPE_ODUC4:
189 case StringConstants.SERVICE_TYPE_10GE:
190 case StringConstants.SERVICE_TYPE_1GE:
191 LOG.info("readMdSal: network {}", NetworkUtils.OTN_NETWORK_ID);
192 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
193 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID))).build();
196 LOG.warn("readMdSal: unknown service-type for service-rate {} and service-format {}", serviceRate,
201 if (readTopology(nwInstanceIdentifier) != null) {
202 allNodes = readTopology(nwInstanceIdentifier).nonnullNode().values().stream().sorted((n1, n2)
203 -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue())).collect(Collectors.toList());
204 Network1 nw1 = readTopology(nwInstanceIdentifier).augmentation(Network1.class);
206 allLinks = nw1.nonnullLink().values().stream().sorted((l1, l2)
207 -> l1.getSource().getSourceTp().toString().compareTo(l2.getSource().getSourceTp().toString()))
208 .collect(Collectors.toList());
210 LOG.warn("no otn links in otn-topology");
212 if (allNodes == null || allNodes.isEmpty()) {
213 LOG.error("readMdSal: no nodes ");
216 LOG.info("readMdSal: network nodes: {} nodes added", allNodes.size());
217 LOG.debug("readMdSal: network nodes: {} nodes added", allNodes);
219 if (allLinks == null || allLinks.isEmpty()) {
220 LOG.error("readMdSal: no links ");
223 LOG.info("readMdSal: network links: {} links added", allLinks.size());
224 LOG.debug("readMdSal: network links: {} links added", allLinks);
228 LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
233 private Network readTopology(InstanceIdentifier<Network> nwInstanceIdentifier) {
236 Optional<Network> nwOptional =
237 networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, nwInstanceIdentifier).get();
238 if (nwOptional.isPresent()) {
239 nw = nwOptional.get();
240 LOG.debug("readMdSal: network nodes: nwOptional.isPresent = true {}", nw);
241 networkTransactionService.close();
243 } catch (InterruptedException | ExecutionException e) {
244 LOG.error("readMdSal: Error reading topology {}", nwInstanceIdentifier);
245 networkTransactionService.close();
246 returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
247 throw new RuntimeException(
248 "readMdSal: Error reading from operational store, topology : " + nwInstanceIdentifier + " :" + e);
253 private boolean analyzeNw() {
255 LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
257 if (StringConstants.SERVICE_TYPE_100GE_T.equals(serviceType)
258 || StringConstants.SERVICE_TYPE_OTU4.equals(serviceType)
259 || StringConstants.SERVICE_TYPE_400GE.equals(serviceType)
260 || StringConstants.SERVICE_TYPE_OTUC4.equals(serviceType)) {
261 // 100GE service and OTU4 service are handled at the openroadm-topology layer
262 for (Node node : allNodes) {
266 LOG.debug("analyzeNw: allPceNodes size {}", allPceNodes.size());
268 if (aendPceNode == null || zendPceNode == null) {
269 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
272 for (Link link : allLinks) {
276 LOG.debug("analyzeNw: addLinks size {}, dropLinks size {}", addLinks.size(), dropLinks.size());
278 LOG.debug("analyzeNw: azSrgs size = {}", azSrgs.size());
279 for (NodeId srg : azSrgs) {
280 LOG.debug("analyzeNw: A/Z Srgs SRG = {}", srg.getValue());
283 for (PceLink link : addLinks) {
284 filteraddLinks(link);
286 for (PceLink link : dropLinks) {
287 filterdropLinks(link);
291 // ODU4, 10GE/ODU2e or 1GE/ODU0 services are handled at openroadm-otn layer
293 for (Node node : allNodes) {
294 validateOtnNode(node);
297 LOG.info("analyzeNw: allPceNodes {}", allPceNodes);
299 if (aendPceNode == null || zendPceNode == null) {
300 LOG.error("analyzeNw: Error in reading nodes: A or Z do not present in the network");
303 for (Link link : allLinks) {
308 LOG.info("analyzeNw: allPceNodes size {}, allPceLinks size {}", allPceNodes.size(), allPceLinks.size());
310 if ((allPceNodes.size() == 0) || (allPceLinks.size() == 0)) {
314 LOG.debug("analyzeNw: allPceNodes {}", allPceNodes);
315 LOG.debug("analyzeNw: allPceLinks {}", allPceLinks);
320 private boolean filteraddLinks(PceLink pcelink) {
322 NodeId nodeId = pcelink.getSourceId();
324 if (azSrgs.contains(nodeId)) {
325 allPceLinks.put(pcelink.getLinkId(), pcelink);
326 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
327 LOG.debug("analyzeNw: Add_LINK added to source and to allPceLinks {}", pcelink.getLinkId());
331 // remove the SRG from PceNodes, as it is not directly connected to A/Z
332 allPceNodes.remove(nodeId);
333 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
338 private boolean filterdropLinks(PceLink pcelink) {
340 NodeId nodeId = pcelink.getDestId();
342 if (azSrgs.contains(nodeId)) {
343 allPceLinks.put(pcelink.getLinkId(), pcelink);
344 allPceNodes.get(nodeId).addOutgoingLink(pcelink);
345 LOG.debug("analyzeNw: Drop_LINK added to dest and to allPceLinks {}", pcelink.getLinkId());
349 // remove the SRG from PceNodes, as it is not directly connected to A/Z
350 allPceNodes.remove(pcelink.getDestId());
351 LOG.debug("analyzeNw: SRG removed {}", nodeId.getValue());
356 private boolean validateLink(Link link) {
357 LOG.info("validateLink: link {} ", link);
359 NodeId sourceId = link.getSource().getSourceNode();
360 NodeId destId = link.getDestination().getDestNode();
361 PceNode source = allPceNodes.get(sourceId);
362 PceNode dest = allPceNodes.get(destId);
363 State state = link.augmentation(Link1.class).getOperationalState();
365 if (source == null) {
366 LOG.debug("validateLink: Link is ignored due source node is rejected by node validation - {}",
367 link.getSource().getSourceNode().getValue());
371 LOG.debug("validateLink: Link is ignored due dest node is rejected by node validation - {}",
372 link.getDestination().getDestNode().getValue());
376 if (State.OutOfService.equals(state)) {
377 LOG.debug("validateLink: Link is ignored due operational state - {}",
382 switch (serviceType) {
383 case StringConstants.SERVICE_TYPE_100GE_T:
384 case StringConstants.SERVICE_TYPE_OTU4:
385 case StringConstants.SERVICE_TYPE_OTUC4:
386 case StringConstants.SERVICE_TYPE_400GE:
387 return processPceLink(link, sourceId, destId, source, dest);
388 case StringConstants.SERVICE_TYPE_ODU4:
389 case StringConstants.SERVICE_TYPE_10GE:
390 case StringConstants.SERVICE_TYPE_100GE_M:
391 case StringConstants.SERVICE_TYPE_ODUC4:
392 case StringConstants.SERVICE_TYPE_1GE:
393 return processPceOtnLink(link, source, dest);
395 LOG.error(" validateLink: Unmanaged service type {}", serviceType);
400 private void validateNode(Node node) {
401 LOG.debug("validateNode: node {} ", node);
402 // PceNode will be used in Graph algorithm
403 Node1 node1 = node.augmentation(Node1.class);
405 LOG.error("getNodeType: no Node1 (type) Augmentation for node: [{}]. Node is ignored", node.getNodeId());
408 if (State.OutOfService.equals(node1.getOperationalState())) {
409 LOG.error("getNodeType: node is ignored due to operational state - {}", node1.getOperationalState()
413 OpenroadmNodeType nodeType = node1.getNodeType();
414 String deviceNodeId = MapUtils.getSupNetworkNode(node);
415 // Should never happen but because of existing topology test files
416 // we have to manage this case
417 if (deviceNodeId == null || deviceNodeId.isBlank()) {
418 deviceNodeId = node.getNodeId().getValue();
421 LOG.info("Device node id {} for {}", deviceNodeId, node);
422 PceOpticalNode pceNode = new PceOpticalNode(deviceNodeId, this.serviceType, portMapping, node, nodeType,
423 mappingUtils.getOpenRoadmVersion(deviceNodeId), getSlotWidthGranularity(deviceNodeId, node.getNodeId()),
424 getCentralFreqGranularity(deviceNodeId, node.getNodeId()));
425 pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
426 pceNode.initFrequenciesBitSet();
428 if (!pceNode.isValid()) {
429 LOG.warn(" validateNode: Node is ignored");
432 if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
435 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.aendPceNode == null
436 && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
437 this.aendPceNode = pceNode;
439 if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.zendPceNode == null
440 && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
441 this.zendPceNode = pceNode;
444 allPceNodes.put(pceNode.getNodeId(), pceNode);
445 LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
449 private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
450 switch (serviceFormat) {
453 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
458 if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue()
459 .equals(this.input.getServiceAEnd().getRxDirection().getPort().getPortDeviceName())) {
462 if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue()
463 .equals(this.input.getServiceZEnd().getRxDirection().getPort().getPortDeviceName())) {
468 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
473 private void validateOtnNode(Node node) {
474 LOG.info("validateOtnNode: {} ", node.getNodeId().getValue());
475 // PceOtnNode will be used in Graph algorithm
476 if (node.augmentation(Node1.class) != null) {
477 OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
479 PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType);
480 pceOtnNode.validateXponder(anodeId, znodeId);
482 if (!pceOtnNode.isValid()) {
483 LOG.warn(" validateOtnNode: Node {} is ignored", node.getNodeId().getValue());
486 if (validateNodeConstraints(pceOtnNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
489 if (pceOtnNode.getNodeId().getValue().equals(anodeId) && this.aendPceNode == null) {
490 this.aendPceNode = pceOtnNode;
492 if (pceOtnNode.getNodeId().getValue().equals(znodeId) && this.zendPceNode == null) {
493 this.zendPceNode = pceOtnNode;
495 allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
496 LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
499 LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
504 private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
505 if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
506 return ConstraintTypes.NONE;
508 if (pceHardConstraints.getExcludeSupNodes().contains(pcenode.getSupNetworkNodeId())) {
509 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
510 return ConstraintTypes.HARD_EXCLUDE;
512 if (pceHardConstraints.getExcludeCLLI().contains(pcenode.getSupClliNodeId())) {
513 LOG.info("validateNodeConstraints: {}", pcenode.getNodeId().getValue());
514 return ConstraintTypes.HARD_EXCLUDE;
516 return ConstraintTypes.NONE;
519 private ConstraintTypes validateLinkConstraints(PceLink link) {
520 if (pceHardConstraints.getExcludeSRLG().isEmpty()) {
521 return ConstraintTypes.NONE;
524 // for now SRLG is the only constraint for link
525 if (link.getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
526 return ConstraintTypes.NONE;
529 List<Long> constraints = new ArrayList<>(pceHardConstraints.getExcludeSRLG());
530 constraints.retainAll(link.getsrlgList());
531 if (!constraints.isEmpty()) {
532 LOG.info("validateLinkConstraints: {}", link.getLinkId().getValue());
533 return ConstraintTypes.HARD_EXCLUDE;
536 return ConstraintTypes.NONE;
539 private void dropOppositeLink(Link link) {
540 LinkId opplink = MapUtils.extractOppositeLink(link);
542 if (allPceLinks.containsKey(opplink)) {
543 allPceLinks.remove(opplink);
545 linksToExclude.add(opplink);
549 private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceOpticalNode pceNode) {
550 switch (openroadmNodeType) {
552 pceNode.initSrgTps();
553 this.azSrgs.add(nodeId);
556 pceNode.initXndrTps(input.getServiceAEnd().getServiceFormat());
559 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
563 if (!pceNode.isValid()) {
564 LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
570 private boolean processPceLink(Link link, NodeId sourceId, NodeId destId, PceNode source, PceNode dest) {
571 PceLink pcelink = new PceLink(link, source, dest);
572 if (!pcelink.isValid()) {
573 dropOppositeLink(link);
574 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
577 LinkId linkId = pcelink.getLinkId();
578 if (validateLinkConstraints(pcelink).equals(ConstraintTypes.HARD_EXCLUDE)) {
579 dropOppositeLink(link);
580 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
583 switch (pcelink.getlinkType()) {
586 allPceLinks.put(linkId, pcelink);
587 source.addOutgoingLink(pcelink);
588 LOG.debug("validateLink: {}-LINK added to allPceLinks {}",
589 pcelink.getlinkType(), pcelink);
592 pcelink.setClient(source.getRdmSrgClient(pcelink.getSourceTP().toString()));
593 addLinks.add(pcelink);
594 LOG.debug("validateLink: ADD-LINK saved {}", pcelink);
597 pcelink.setClient(dest.getRdmSrgClient(pcelink.getDestTP().toString()));
598 dropLinks.add(pcelink);
599 LOG.debug("validateLink: DROP-LINK saved {}", pcelink);
602 // store separately all SRG links directly
603 azSrgs.add(sourceId);
605 if (!dest.checkTP(pcelink.getDestTP().toString())) {
607 "validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink);
610 if (dest.getXpdrClient(pcelink.getDestTP().toString()) != null) {
611 pcelink.setClient(dest.getXpdrClient(pcelink.getDestTP().toString()));
613 allPceLinks.put(linkId, pcelink);
614 source.addOutgoingLink(pcelink);
615 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink);
617 // does it mean XPONDER==>>SRG ?
619 // store separately all SRG links directly
622 if (!source.checkTP(pcelink.getSourceTP().toString())) {
624 "validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink);
627 if (source.getXpdrClient(pcelink.getSourceTP().toString()) != null) {
628 pcelink.setClient(source.getXpdrClient(pcelink.getSourceTP().toString()));
630 allPceLinks.put(linkId, pcelink);
631 source.addOutgoingLink(pcelink);
632 LOG.debug("validateLink: XPONDER-OUTPUT link added to allPceLinks {}", pcelink);
635 LOG.warn("validateLink: link type is not supported {}", pcelink);
640 private boolean processPceOtnLink(Link link, PceNode source, PceNode dest) {
641 PceLink pceOtnLink = new PceLink(link, source, dest);
643 if (!pceOtnLink.isOtnValid(link, serviceType)) {
644 dropOppositeLink(link);
645 LOG.error(" validateLink: Link is ignored due errors in network data or in opposite link");
649 LinkId linkId = pceOtnLink.getLinkId();
650 if (validateLinkConstraints(pceOtnLink).equals(ConstraintTypes.HARD_EXCLUDE)) {
651 dropOppositeLink(link);
652 LOG.debug("validateLink: constraints : link is ignored == {}", linkId.getValue());
656 switch (pceOtnLink.getlinkType()) {
658 if (dest.getXpdrClient(pceOtnLink.getDestTP().toString()) != null) {
659 pceOtnLink.setClient(dest.getXpdrClient(pceOtnLink.getDestTP().toString()));
662 allPceLinks.put(linkId, pceOtnLink);
663 source.addOutgoingLink(pceOtnLink);
664 LOG.info("validateLink: OTN-LINK added to allPceLinks {}", pceOtnLink);
667 LOG.warn("validateLink: link type is not supported {}", pceOtnLink);
672 public PceNode getaendPceNode() {
676 public PceNode getzendPceNode() {
680 public Map<NodeId, PceNode> getAllPceNodes() {
681 return this.allPceNodes;
684 public Map<LinkId, PceLink> getAllPceLinks() {
685 return this.allPceLinks;
688 public String getServiceType() {
692 public PceResult getReturnStructure() {
693 return returnStructure;
696 private static void printNodesInfo(Map<NodeId, PceNode> allPceNodes) {
697 allPceNodes.forEach(((nodeId, pceNode) -> {
698 LOG.info("In printNodes in node {} : outgoing links {} ", pceNode.getNodeId().getValue(),
699 pceNode.getOutgoingLinks());
704 * Get mc capability slot width granularity for device.
705 * @param deviceNodeId String
706 * @param nodeId NodeId
707 * @return slot width granularity
709 private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
710 // nodeId: openroadm-topology level node
711 // deviceNodeId: openroadm-network level node
712 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
713 String[] params = nodeId.getValue().split("-");
714 // DEGx or SRGx or XPDRx
715 String moduleName = params[params.length - 1];
716 for (McCapabilities mcCapabitility : mcCapabilities) {
717 if (mcCapabitility.getMcNodeName().contains("XPDR")
718 && mcCapabitility.getSlotWidthGranularity() != null) {
719 return mcCapabitility.getSlotWidthGranularity().getValue();
721 if (mcCapabitility.getMcNodeName().contains(moduleName)
722 && mcCapabitility.getSlotWidthGranularity() != null) {
723 return mcCapabitility.getSlotWidthGranularity().getValue();
726 return GridConstant.SLOT_WIDTH_50;
730 * Get mc capability central-width granularity for device.
731 * @param deviceNodeId String
732 * @param nodeId NodeId
733 * @return center-freq granularity
735 private BigDecimal getCentralFreqGranularity(String deviceNodeId, NodeId nodeId) {
736 // nodeId: openroadm-topology level node
737 // deviceNodeId: openroadm-network level node
738 List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
739 String[] params = nodeId.getValue().split("-");
740 // DEGx or SRGx or XPDRx
741 String moduleName = params[params.length - 1];
742 for (McCapabilities mcCapabitility : mcCapabilities) {
743 if (mcCapabitility.getMcNodeName().contains("XPDR")
744 && mcCapabitility.getCenterFreqGranularity() != null) {
745 return mcCapabitility.getCenterFreqGranularity().getValue();
747 if (mcCapabitility.getMcNodeName().contains(moduleName)
748 && mcCapabitility.getCenterFreqGranularity() != null) {
749 return mcCapabitility.getCenterFreqGranularity().getValue();
752 return GridConstant.SLOT_WIDTH_50;