package org.opendaylight.transportpce.pce.constraints;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.transportpce.common.Timeouts;
import org.opendaylight.transportpce.common.network.NetworkTransactionService;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.PathDescription;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZ;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.Link;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.Node;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp.PceMetric;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.CoRoutingOrGeneral;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.CoRouting;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.General;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.Diversity;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.Exclude;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.Include;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.Latency;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.include_.OrderedHops;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.diversity.existing.service.contraints.sp.ExistingServiceApplicability;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ordered.constraints.sp.hop.type.HopType;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraints;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraints;
+import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.Constraints;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.CoRouting;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.Diversity;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.Exclude;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.Include;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing.service.constraints.ServiceIdentifierList;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.diversity.existing.service.constraints.ServiceIdentifierListKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraints;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.SoftConstraints;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.service.applicability.g.ServiceApplicability;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.PathDescription;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.Link;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.Node;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.PceMetric;
import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
public class PceConstraintsCalc {
/* Logging. */
private static final Logger LOG = LoggerFactory.getLogger(PceConstraintsCalc.class);
public PceConstraintsCalc(PathComputationRequestInput input, NetworkTransactionService networkTransactionService) {
LOG.debug("In PceconstraintsCalc start");
- pceMetrics = input.getPceMetric();
+ pceMetrics = input.getPceRoutingMetric();
this.networkTransactionService = networkTransactionService;
// TODO. for now metrics are set into hard structure
- LOG.info("In PceConstraintsCalc: read PceMetric {}", pceMetrics.toString());
+ LOG.info("In PceConstraintsCalc: read PceMetric {}", pceMetrics);
pceHardConstraints.setPceMetrics(pceMetrics);
calcHardconstraints(input);
LOG.info("In calcHardconstraints: no hard constraints.");
return;
}
-
- CoRoutingOrGeneral coRoutingOrGeneral = servicePathHardConstraints.getCoRoutingOrGeneral();
- readconstraints(coRoutingOrGeneral, pceHardConstraints);
-
+ readConstraints(servicePathHardConstraints, pceHardConstraints);
}
private void calcSoftconstraints(PathComputationRequestInput input) {
LOG.info("In calcSoftconstraints: no soft constraints.");
return;
}
-
- CoRoutingOrGeneral coRoutingOrGeneral = servicePathSoftConstraints.getCoRoutingOrGeneral();
- readconstraints(coRoutingOrGeneral, pceSoftConstraints);
-
+ readConstraints(servicePathSoftConstraints, pceSoftConstraints);
}
- private void readconstraints(CoRoutingOrGeneral coRoutingOrGeneral, PceConstraints constraints) {
- LOG.debug("In readconstraints start");
+ private void readConstraints(Constraints hardConstraints, PceConstraints constraints) {
+ LOG.debug("In readHardconstraints start");
- if (coRoutingOrGeneral == null) {
- LOG.info("In readHardconstraints: no CoRoutingOrGeneral constraints.");
- return;
+ if (hardConstraints.getInclude() != null) {
+ readInclude(hardConstraints.getInclude(), constraints);
}
-
- General tmpGeneral = null;
- CoRouting tmpCoRouting = null;
-
- if (coRoutingOrGeneral instanceof General) {
- LOG.info("In readconstraints General {}", coRoutingOrGeneral.toString());
- tmpGeneral = (General) coRoutingOrGeneral;
- readGeneralContrains(tmpGeneral, constraints);
- return;
+ if (hardConstraints.getExclude() != null) {
+ readExclude(hardConstraints.getExclude(), constraints);
}
-
- if (coRoutingOrGeneral instanceof CoRouting) {
- LOG.info("In readconstraints CoRouting {}", coRoutingOrGeneral.toString());
- tmpCoRouting = (CoRouting) coRoutingOrGeneral;
- readCoRoutingContrains(tmpCoRouting, constraints);
- return;
+ if (hardConstraints.getCoRouting() != null) {
+ readCoRouting(hardConstraints.getCoRouting(), constraints);
}
-
- return;
-
- }
-
- private void readGeneralContrains(General tmpGeneral, PceConstraints constraints) {
- LOG.debug("In readGeneralContrains start");
-
- if (tmpGeneral == null) {
- LOG.info("In readGeneralContrains: no General constraints.");
- return;
+ if (hardConstraints.getDiversity() != null) {
+ readDiversity(hardConstraints.getDiversity(), constraints);
}
-
- Latency latency = tmpGeneral.getLatency();
- if (latency != null) {
- constraints.setMaxLatency(latency.getMaxLatency());
- LOG.info("In readGeneralContrains: read latency {}", latency.toString());
+ if (hardConstraints.getLatency() != null) {
+ constraints.setMaxLatency(hardConstraints.getLatency().getMaxLatency().longValue());
}
+ }
- Exclude exclude = tmpGeneral.getExclude();
- List<String> elementsToExclude = null;
- if (exclude != null) {
- elementsToExclude = exclude.getNodeId();
- if (elementsToExclude != null) {
- constraints.setExcludeSupNodes(elementsToExclude);
- }
-
- elementsToExclude = exclude.getSRLG();
- if (elementsToExclude != null) {
- List<Long> srlgToExclude = new ArrayList<Long>();
- for (String str : elementsToExclude) {
- srlgToExclude.add(Long.parseLong(str));
- }
- constraints.setExcludeSRLG(srlgToExclude);
- }
-
- elementsToExclude = exclude.getClli();
- if (elementsToExclude != null) {
- constraints.setExcludeCLLI(elementsToExclude);
+ private void readExclude(Exclude exclude, PceConstraints constraints) {
+ //TODO: Implement other exclude constraints: fiber-bundle, link-identifier
+ // and supporting-service-name
+ if (exclude.getNodeId() != null) {
+ List<String> elementsToExclude = new ArrayList<>();
+ for (NodeIdType node : exclude.getNodeId()) {
+ elementsToExclude.add(node.getValue());
}
+ constraints.setExcludeSupNodes(elementsToExclude);
}
-
- Include include = tmpGeneral.getInclude();
- if (include != null) {
- List<OrderedHops> listHops = include.getOrderedHops();
- if (listHops != null) {
- readIncludeNodes(listHops, constraints);
+ if (exclude.getSrlgId() != null) {
+ List<Long> elementsToExclude = new ArrayList<>();
+ for (Uint32 srlg : exclude.getSrlgId()) {
+ elementsToExclude.add(srlg.longValue());
}
- LOG.debug("in readGeneralContrains INCLUDE {} ", include.toString());
+ constraints.setExcludeSRLG(elementsToExclude);
+ }
+ if (exclude.getSite() != null) {
+ constraints.setExcludeCLLI(new ArrayList<>(exclude.getSite()));
+ }
+ if (exclude.getFiberBundle() != null || exclude.getLinkIdentifier() != null
+ || exclude.getSupportingServiceName() != null) {
+ LOG.warn("exclude constraints of type fiber-bundle, link-identifier"
+ + "or supporting-service-name are not implemented yet");
}
+ }
- Diversity diversity = tmpGeneral.getDiversity();
- PceConstraints.ResourceType rt = PceConstraints.ResourceType.NONE;
- if (diversity != null) {
- ExistingServiceApplicability temp = diversity.getExistingServiceApplicability();
- if (temp == null) {
- return;
- }
- if (temp.isNode()) {
- rt = PceConstraints.ResourceType.NODE;
+ private void readInclude(Include include, PceConstraints constraints) {
+ if (include.getNodeId() != null) {
+ for (NodeIdType node : include.getNodeId()) {
+ constraints.setListToInclude(new ResourcePair(PceConstraints.ResourceType.NODE, node.getValue()));
}
- if (temp.isSrlg()) {
- rt = PceConstraints.ResourceType.SRLG;
+ }
+ if (include.getSrlgId() != null) {
+ for (Uint32 srlg : include.getSrlgId()) {
+ constraints.setListToInclude(new ResourcePair(PceConstraints.ResourceType.SRLG, srlg.toString()));
}
- if (temp.isClli()) {
- rt = PceConstraints.ResourceType.CLLI;
+ }
+ if (include.getSite() != null) {
+ for (String site : include.getSite()) {
+ constraints.setListToInclude(new ResourcePair(PceConstraints.ResourceType.CLLI, site));
}
- LOG.info("in readGeneralContrains {} list is :{}", rt, diversity.toString());
- readDiversity(diversity.getExistingService(), constraints, rt);
}
-
}
- private void readIncludeNodes(List<OrderedHops> listHops, PceConstraints constraints) {
- for (int i = 0; i < listHops.size(); i++) {
- HopType hoptype = listHops.get(i).getHopType().getHopType();
-
- String hopt = hoptype.getImplementedInterface().getSimpleName();
- LOG.info("in readIncludeNodes next hop to include {}", hopt);
- switch (hopt) {
- case "Node":
- org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
- .rev171017.ordered.constraints.sp.hop.type.hop.type.Node
- node = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
- .constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.Node) hoptype;
- constraints.setListToInclude(constraints.new ResourcePair(PceConstraints.ResourceType.NODE,
- node.getNodeId()));
- break;
- case "SRLG":
- org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
- .rev171017.ordered.constraints.sp.hop.type.hop.type.SRLG
- srlg = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
- .constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.SRLG) hoptype;
- constraints.setListToInclude(constraints.new ResourcePair(PceConstraints.ResourceType.SRLG,
- srlg.getSRLG()));
- break;
- case "Clli":
- org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
- .rev171017.ordered.constraints.sp.hop.type.hop.type.Clli
- clli = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
- .constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.Clli) hoptype;
- constraints.setListToInclude(constraints.new ResourcePair(PceConstraints.ResourceType.CLLI,
- clli.getClli()));
- break;
- default:
- LOG.error("in readIncludeNodes unsupported include type {}", hopt);
- }
+ private void readCoRouting(CoRouting tmpcoRouting, PceConstraints constraints) {
+ if (tmpcoRouting == null) {
+ LOG.info("In readCoRoutingContrains: no CoRouting constraints.");
+ } else {
+ LOG.warn("CoRouting constraints handling not implemented yet");
}
}
- private void readDiversity(List<String> srvList, PceConstraints constraints, PceConstraints.ResourceType rt) {
-
- List<String> elementsToExclude = new ArrayList<String>();
- LOG.info("in readDiversity {}", srvList.toString());
-
- for (String srv : srvList) {
- Optional<PathDescription> service = getPathDescriptionFromDatastore(srv);
- if (service.isPresent()) {
- LOG.info("in readDiversity service list {}", service.toString());
- switch (rt) {
- case NODE:
- elementsToExclude
- .addAll(getAToZNodeList(service.get()));
- LOG.info("readDiversity NODE : {}", elementsToExclude);
- if (elementsToExclude != null) {
- constraints.setExcludeNodes(elementsToExclude);
- }
- break;
- case SRLG:
- elementsToExclude
- .addAll(getSRLGList(service.get()));
- LOG.info("readDiversity SRLG : {}", elementsToExclude);
- if (elementsToExclude != null) {
- constraints.setExcludeSrlgLinks(elementsToExclude);
- }
- break;
- case CLLI:
- /// Retrieve nodes into dedicated CLLI list
- /// during node validation check their CLLI and build CLLI exclude list
- elementsToExclude
- .addAll(getAToZNodeList(service.get()));
- LOG.info("readDiversity CLLI : {}", elementsToExclude);
- if (elementsToExclude != null) {
- constraints.setExcludeClliNodes(elementsToExclude);
- }
- break;
- default:
- LOG.info("in readDiversity unsupported divercity type", rt);
+ private void readDiversity(Diversity diversity, PceConstraints constraints) {
+ //TODO: How to implement the DiversityType: serial or synchronous?
+ Map<ServiceIdentifierListKey, ServiceIdentifierList> serviceIdList = diversity.getServiceIdentifierList();
+ Collection<ServiceIdentifierList> services = serviceIdList.values();
+ for (ServiceIdentifierList serviceIdentifier : services) {
+ String serviceId = serviceIdentifier.getServiceIdentifier();
+ ServiceApplicability serviceApplicability = serviceIdentifier.getServiceApplicability();
+ Optional<PathDescription> serviceOpt = getPathDescriptionFromDatastore(serviceId);
+ if (serviceOpt.isPresent()) {
+ List<String> serviceNodes = getAToZNodeList(serviceOpt.orElseThrow());
+ if (serviceApplicability.getNode() && !serviceNodes.isEmpty()) {
+ constraints.setExcludeNodes(serviceNodes);
+ }
+ List<String> serviceLinks = getSRLGList(serviceOpt.orElseThrow());
+ if (serviceApplicability.getLink() && !serviceLinks.isEmpty()) {
+ constraints.setExcludeSrlgLinks(serviceLinks);
+ }
+ if (serviceApplicability.getSite() && !serviceNodes.isEmpty()) {
+ constraints.setExcludeClliNodes(serviceNodes);
}
-
- } else {
- LOG.info("in readDiversity srv={} is not present", srv);
}
}
-
}
private List<String> getAToZNodeList(PathDescription pathDescription) {
- List<AToZ> aendToZList = pathDescription.getAToZDirection().getAToZ();
+ List<AToZ> aendToZList = new ArrayList<>(pathDescription.getAToZDirection().nonnullAToZ().values());
return aendToZList.stream().filter(aToZ -> {
if (aToZ.getResource() == null || aToZ.getResource().getResource() == null) {
LOG.warn("Diversity constraint: Resource of AToZ node {} is null! Skipping this node!", aToZ.getId());
return true;
}).map(aToZ -> {
Node node = ((Node) aToZ.getResource().getResource());
- return node.getNodeId().toString();
+ return node.getNodeId();
}).collect(Collectors.toList());
}
private List<String> getSRLGList(PathDescription pathDescription) {
- List<AToZ> aendToZList = pathDescription.getAToZDirection().getAToZ();
+ List<AToZ> aendToZList = new ArrayList<>(pathDescription.getAToZDirection().nonnullAToZ().values());
return aendToZList.stream().filter(aToZ -> {
if (aToZ.getResource() == null
|| aToZ.getResource().getResource() == null) {
LOG.info("PCE diversity constraints: Getting path description for service {}", serviceName);
ServicePaths servicePaths =
networkTransactionService.read(LogicalDatastoreType.CONFIGURATION, pathDescriptionIID)
- .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS).get();
+ .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS).orElseThrow();
if (servicePaths != null) {
PathDescription path = servicePaths.getPathDescription();
if (path != null) {
return result;
}
- private void readCoRoutingContrains(CoRouting tmpcoRouting, PceConstraints constraints) {
- LOG.info("In readCoRoutingContrains start");
-
- if (tmpcoRouting == null) {
- LOG.info("In readCoRoutingContrains: no General constraints.");
- return;
- }
-
- }
-
public PceConstraints getPceHardConstraints() {
return pceHardConstraints;
}