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=754d51eeba610568a887e6929c92430831311227;hb=1e2f9a502de80450411761fd2f636e2b7ee32301;hp=1b8372ef683b08b457205ae25cd2d4ff47d33e6f;hpb=7c90be243c9c65418b81768e1e0ed6ac58bad4a8;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 1b8372ef6..754d51eeb 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 @@ -7,41 +7,39 @@ */ package org.opendaylight.transportpce.pce.constraints; -import com.google.common.base.Optional; - import java.util.ArrayList; import java.util.List; +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.controller.md.sal.common.api.data.LogicalDatastoreType; +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.rev220118.PathComputationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.CoRoutingOrGeneral; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRouting; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.General; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Diversity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Exclude; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Include; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Latency; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.diversity.existing.service.constraints.ExistingServiceApplicability; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraints; +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; @@ -57,12 +55,12 @@ public class PceConstraintsCalc { 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); @@ -105,21 +103,17 @@ public class PceConstraintsCalc { CoRouting tmpCoRouting = null; if (coRoutingOrGeneral instanceof General) { - LOG.info("In readconstraints General {}", coRoutingOrGeneral.toString()); + LOG.info("In readconstraints General {}", coRoutingOrGeneral); tmpGeneral = (General) coRoutingOrGeneral; readGeneralContrains(tmpGeneral, constraints); return; } if (coRoutingOrGeneral instanceof CoRouting) { - LOG.info("In readconstraints CoRouting {}", coRoutingOrGeneral.toString()); + LOG.info("In readconstraints CoRouting {}", coRoutingOrGeneral); tmpCoRouting = (CoRouting) coRoutingOrGeneral; readCoRoutingContrains(tmpCoRouting, constraints); - return; } - - return; - } private void readGeneralContrains(General tmpGeneral, PceConstraints constraints) { @@ -132,40 +126,18 @@ public class PceConstraintsCalc { Latency latency = tmpGeneral.getLatency(); if (latency != null) { - constraints.setMaxLatency(latency.getMaxLatency()); - LOG.info("In readGeneralContrains: read latency {}", latency.toString()); + constraints.setMaxLatency(latency.getMaxLatency().toJava()); + LOG.info("In readGeneralContrains: read latency {}", latency); } 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); - } + readExclude(exclude, constraints); } Include include = tmpGeneral.getInclude(); if (include != null) { - List listHops = include.getOrderedHops(); - if (listHops != null) { - readIncludeNodes(listHops, constraints); - } - LOG.debug("in readGeneralContrains INCLUDE {} ", include.toString()); + readInclude(include, constraints); } Diversity diversity = tmpGeneral.getDiversity(); @@ -175,79 +147,83 @@ public class PceConstraintsCalc { if (temp == null) { return; } - if (temp.isNode()) { + if (Boolean.TRUE.equals(temp.getNode())) { rt = PceConstraints.ResourceType.NODE; } - if (temp.isSrlg()) { + if (Boolean.TRUE.equals(temp.getSrlg())) { rt = PceConstraints.ResourceType.SRLG; } - if (temp.isClli()) { + if (Boolean.TRUE.equals(temp.getSite())) { rt = PceConstraints.ResourceType.CLLI; } - LOG.info("in readGeneralContrains {} list is :{}", rt, diversity.toString()); + LOG.info("in readGeneralContrains {} list is :{}", rt, diversity); readDiversity(diversity.getExistingService(), constraints, rt); } + } + private void readExclude(Exclude exclude, PceConstraints constraints) { + List nodes = exclude.getNodeId(); + if (nodes != null) { + List elementsToExclude = new ArrayList<>(); + for (NodeIdType node : nodes) { + elementsToExclude.add(node.getValue()); + } + constraints.setExcludeSupNodes(elementsToExclude); + } + List srlgs = exclude.getSrlgId(); + if (srlgs != null) { + List elementsToExclude = new ArrayList<>(); + for (Uint32 srlg : srlgs) { + elementsToExclude.add(srlg.longValue()); + } + constraints.setExcludeSRLG(elementsToExclude); + } + List sites = exclude.getSite(); + if (sites != null) { + constraints.setExcludeCLLI(exclude.getSite()); + } } - 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.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 readInclude(Include include, PceConstraints constraints) { + List nodes = include.getNodeId(); + if (nodes != null) { + for (NodeIdType node : nodes) { + constraints.setListToInclude(new ResourcePair(PceConstraints.ResourceType.NODE, node.getValue())); + } + } + List srlgs = include.getSrlgId(); + if (srlgs != null) { + for (Uint32 srlg : srlgs) { + constraints.setListToInclude(new ResourcePair(PceConstraints.ResourceType.SRLG, srlg.toString())); + } + } + List sites = include.getSite(); + if (sites != null) { + for (String site : sites) { + constraints.setListToInclude(new ResourcePair(PceConstraints.ResourceType.CLLI, site)); } } } private void readDiversity(List srvList, PceConstraints constraints, PceConstraints.ResourceType rt) { - List elementsToExclude = new ArrayList(); - LOG.info("in readDiversity {}", srvList.toString()); + 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.toString()); + LOG.info("in readDiversity service list {}", service); switch (rt) { case NODE: - elementsToExclude - .addAll(getAToZNodeList(service.get())); + elementsToExclude.addAll(getAToZNodeList(service.get())); LOG.info("readDiversity NODE : {}", elementsToExclude); if (elementsToExclude != null) { constraints.setExcludeNodes(elementsToExclude); } break; case SRLG: - elementsToExclude - .addAll(getSRLGList(service.get())); + elementsToExclude.addAll(getSRLGList(service.get())); LOG.info("readDiversity SRLG : {}", elementsToExclude); if (elementsToExclude != null) { constraints.setExcludeSrlgLinks(elementsToExclude); @@ -256,26 +232,24 @@ public class PceConstraintsCalc { case CLLI: /// Retrieve nodes into dedicated CLLI list /// during node validation check their CLLI and build CLLI exclude list - elementsToExclude - .addAll(getAToZNodeList(service.get())); + 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); + LOG.info("in readDiversity unsupported divercity type {}", rt); } } 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()); @@ -291,12 +265,12 @@ public class PceConstraintsCalc { return true; }).map(aToZ -> { Node node = ((Node) aToZ.getResource().getResource()); - return node.getNodeId().toString(); + return node.getNodeId(); }).collect(Collectors.toList()); } 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) { @@ -317,7 +291,7 @@ public class PceConstraintsCalc { } private Optional getPathDescriptionFromDatastore(String serviceName) { - Optional result = Optional.absent(); + Optional result = Optional.empty(); InstanceIdentifier pathDescriptionIID = InstanceIdentifier.create(ServicePathList.class) .child(ServicePaths.class, new ServicePathsKey(serviceName)); try { @@ -331,8 +305,6 @@ public class PceConstraintsCalc { result = Optional.of(path); } } -// return pathDescReadTx.read(LogicalDatastoreType.CONFIGURATION, pathDescriptionIID) -// .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn( "PCE diversity constraints: Exception while getting path description from datastore {} for service {}!", @@ -347,7 +319,6 @@ public class PceConstraintsCalc { if (tmpcoRouting == null) { LOG.info("In readCoRoutingContrains: no General constraints."); - return; } }