X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fconstraints%2FPceConstraintsCalc.java;h=0142d0fcc952cd6dbcc6ca96d8417b3c895a715a;hb=26ae7f03806a3079dca25ec6e3285f2ba369c481;hp=0c3cc109220160edfd56c2dd5b744c6438259674;hpb=7ea354677f9b8ee0b160a7b636c51bb0bedfcd7b;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/PceConstraintsCalc.java b/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/PceConstraintsCalc.java index 0c3cc1092..0142d0fcc 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/PceConstraintsCalc.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/PceConstraintsCalc.java @@ -8,41 +8,44 @@ 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 java.util.concurrent.TimeoutException; import java.util.stream.Collectors; - 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.rev200128.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.rev220808.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.rev211210.Constraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRouting; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Diversity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Exclude; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Include; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service.constraints.ServiceIdentifierList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service.constraints.ServiceIdentifierListKey; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.service.applicability.g.ServiceApplicability; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.Link; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.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); @@ -55,7 +58,7 @@ public class PceConstraintsCalc { public PceConstraintsCalc(PathComputationRequestInput input, NetworkTransactionService networkTransactionService) { LOG.debug("In PceconstraintsCalc start"); - pceMetrics = input.getPceMetric(); + pceMetrics = input.getPceRoutingMetric(); this.networkTransactionService = networkTransactionService; @@ -73,10 +76,7 @@ public class PceConstraintsCalc { LOG.info("In calcHardconstraints: no hard constraints."); return; } - - CoRoutingOrGeneral coRoutingOrGeneral = servicePathHardConstraints.getCoRoutingOrGeneral(); - readconstraints(coRoutingOrGeneral, pceHardConstraints); - + readConstraints(servicePathHardConstraints, pceHardConstraints); } private void calcSoftconstraints(PathComputationRequestInput input) { @@ -85,188 +85,108 @@ public class PceConstraintsCalc { 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); - 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); - tmpCoRouting = (CoRouting) coRoutingOrGeneral; - readCoRoutingContrains(tmpCoRouting, constraints); + if (hardConstraints.getCoRouting() != null) { + readCoRouting(hardConstraints.getCoRouting(), constraints); } - } - - 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().toJava()); - LOG.info("In readGeneralContrains: read latency {}", latency); + if (hardConstraints.getLatency() != null) { + constraints.setMaxLatency(hardConstraints.getLatency().getMaxLatency().longValue()); } + } - Exclude exclude = tmpGeneral.getExclude(); - List elementsToExclude = null; - if (exclude != null) { - elementsToExclude = exclude.getNodeId(); - if (elementsToExclude != null) { - constraints.setExcludeSupNodes(elementsToExclude); - } - - elementsToExclude = exclude.getSRLG(); - if (elementsToExclude != null) { - List srlgToExclude = new ArrayList<>(); - 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 elementsToExclude = new ArrayList<>(); + for (NodeIdType node : exclude.getNodeId()) { + elementsToExclude.add(node.getValue()); } + constraints.setExcludeSupNodes(elementsToExclude); } - - Include include = tmpGeneral.getInclude(); - if (include != null) { - List listHops = include.getOrderedHops(); - if (listHops != null) { - readIncludeNodes(listHops, constraints); + if (exclude.getSrlgId() != null) { + List elementsToExclude = new ArrayList<>(); + for (Uint32 srlg : exclude.getSrlgId()) { + elementsToExclude.add(srlg.longValue()); } - LOG.debug("in readGeneralContrains INCLUDE {} ", include); + 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; + 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 (Boolean.TRUE.equals(temp.isNode())) { - rt = PceConstraints.ResourceType.NODE; - } - if (Boolean.TRUE.equals(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 (Boolean.TRUE.equals(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); - readDiversity(diversity.getExistingService(), constraints, rt); } - } - private void readIncludeNodes(List listHops, PceConstraints constraints) { - for (int i = 0; i < listHops.size(); i++) { - HopType hoptype = listHops.get(i).getHopType().getHopType(); - - String hopt = hoptype.implementedInterface().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(new PceConstraints.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(new PceConstraints.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(new PceConstraints.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 srvList, PceConstraints constraints, PceConstraints.ResourceType rt) { - - List elementsToExclude = new ArrayList<>(); - LOG.info("in readDiversity {}", srvList); - - for (String srv : srvList) { - Optional service = getPathDescriptionFromDatastore(srv); - if (service.isPresent()) { - LOG.info("in readDiversity service list {}", service); - 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 serviceIdList = diversity.getServiceIdentifierList(); + Collection services = serviceIdList.values(); + for (ServiceIdentifierList serviceIdentifier : services) { + String serviceId = serviceIdentifier.getServiceIndentifier(); + ServiceApplicability serviceApplicability = serviceIdentifier.getServiceApplicability(); + Optional serviceOpt = getPathDescriptionFromDatastore(serviceId); + if (serviceOpt.isPresent()) { + List serviceNodes = getAToZNodeList(serviceOpt.get()); + if (serviceApplicability.getNode() && !serviceNodes.isEmpty()) { + constraints.setExcludeNodes(serviceNodes); + } + List serviceLinks = getSRLGList(serviceOpt.get()); + 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 getAToZNodeList(PathDescription pathDescription) { - List aendToZList = pathDescription.getAToZDirection().getAToZ(); + List 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()); @@ -287,7 +207,7 @@ public class PceConstraintsCalc { } private List getSRLGList(PathDescription pathDescription) { - List aendToZList = pathDescription.getAToZDirection().getAToZ(); + List aendToZList = new ArrayList<>(pathDescription.getAToZDirection().nonnullAToZ().values()); return aendToZList.stream().filter(aToZ -> { if (aToZ.getResource() == null || aToZ.getResource().getResource() == null) { @@ -331,15 +251,6 @@ public class PceConstraintsCalc { return result; } - private void readCoRoutingContrains(CoRouting tmpcoRouting, PceConstraints constraints) { - LOG.info("In readCoRoutingContrains start"); - - if (tmpcoRouting == null) { - LOG.info("In readCoRoutingContrains: no General constraints."); - } - - } - public PceConstraints getPceHardConstraints() { return pceHardConstraints; }