X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fgnpy%2FGnpyResult.java;h=d5e27d18fc2785a9d9b6a740c0d4c21e399a7013;hb=refs%2Fchanges%2F46%2F100646%2F27;hp=b13bc009730ce7b1e88d87c84a2bffbf5600a945;hpb=8e32e3ed33d22d148cc46bb2653ecf7ed8b34f64;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java index b13bc0097..d5e27d18f 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java @@ -8,36 +8,24 @@ package org.opendaylight.transportpce.pce.gnpy; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; +import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.Result; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.explicit.route.hop.type.NumUnnumHop; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathMetric; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathRouteObjects; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.Response; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.NoPathCase; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.PathCase; -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.GeneralBuilder; -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.IncludeBuilder; -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.constraints.sp.co.routing.or.general.general.include_.OrderedHopsBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ordered.constraints.sp.HopType; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ordered.constraints.sp.HopTypeBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.NodeBuilder; -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.HardConstraintsBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yangtools.yang.common.Uint16; +import java.util.Set; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.explicit.route.hop.type.NumUnnumHop; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathRouteObjects; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.Response; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase; +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.Include; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.IncludeBuilder; +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.HardConstraintsBuilder; +import org.opendaylight.yangtools.yang.common.Decimal64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,17 +40,16 @@ public class GnpyResult { private static final Logger LOG = LoggerFactory.getLogger(GnpyResult.class); private Response response = null; - private Map mapNodeRefIp = new HashMap<>(); + private List ordNodeList = new ArrayList<>(); public GnpyResult(Result result, GnpyTopoImpl gnpyTopo) throws GnpyException { - this.mapNodeRefIp = gnpyTopo.getMapNodeRefIp(); + this.ordNodeList = gnpyTopo.getElementsList(); List responses = new ArrayList<>(result.nonnullResponse().values()); if (responses.isEmpty()) { throw new GnpyException("In GnpyResult: the response from GNpy is null!"); } LOG.info("The response id is {}; ", responses.get(0).getResponseId()); this.response = responses.get(0); - analyzeResult(); } public boolean getPathFeasibility() { @@ -93,7 +80,7 @@ public class GnpyResult { LOG.info("GNPy : path is not feasible : {}", noPathType); for (PathMetric pathMetric : pathMetricList) { String metricType = pathMetric.getMetricType().getSimpleName(); - BigDecimal accumulativeValue = pathMetric.getAccumulativeValue(); + Decimal64 accumulativeValue = pathMetric.getAccumulativeValue(); LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue); } } @@ -105,7 +92,7 @@ public class GnpyResult { // Path metrics for (PathMetric pathMetric : pathMetricList) { String metricType = pathMetric.getMetricType().getSimpleName(); - BigDecimal accumulativeValue = pathMetric.getAccumulativeValue(); + Decimal64 accumulativeValue = pathMetric.getAccumulativeValue(); LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue); } // Path route objects @@ -120,51 +107,20 @@ public class GnpyResult { HardConstraints hardConstraints = null; // Includes the list of nodes in the GNPy computed path as constraints // for the PCE - List orderedHopsList = new ArrayList<>(); - int counter = 0; + Set nodeIdList = new HashSet<>(); for (PathRouteObjects pathRouteObjects : pathRouteObjectList) { if (pathRouteObjects.getPathRouteObject().getType() instanceof NumUnnumHop) { - NumUnnumHop numUnnumHop = (org.opendaylight.yang.gen.v1.gnpy.path.rev200909.explicit.route.hop.type - .NumUnnumHop) pathRouteObjects.getPathRouteObject().getType(); - String nodeIp = numUnnumHop.getNumUnnumHop().getNodeId(); - try { - IpAddress nodeIpAddress = new IpAddress(new Ipv4Address(nodeIp)); - // find the corresponding node-id (in ord-ntw) corresponding to nodeId (in gnpy response) - String nodeId = findOrdNetworkNodeId(nodeIpAddress); - if (nodeId != null) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017 - .ordered.constraints.sp.hop.type.hop.type.Node node = new NodeBuilder().setNodeId(nodeId) - .build(); - HopType hopType = new HopTypeBuilder().setHopType(node).build(); - OrderedHops orderedHops = new OrderedHopsBuilder() - .setHopNumber(Uint16.valueOf(counter)).setHopType(hopType) - .build(); - orderedHopsList.add(orderedHops); - counter++; - } - } catch (IllegalArgumentException e) { - LOG.debug(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp); + NumUnnumHop numUnnumHop = (NumUnnumHop) pathRouteObjects.getPathRouteObject().getType(); + String nodeId = numUnnumHop.getNumUnnumHop().getNodeId(); + if (nodeId != null && this.ordNodeList.contains(nodeId)) { + nodeIdList.add(new NodeIdType(nodeId)); } } } - Include include = new IncludeBuilder() - .setOrderedHops(orderedHopsList.stream() - .collect(Collectors.toMap(OrderedHops::key, orderedHops -> orderedHops))) - .build(); - General general = new GeneralBuilder().setInclude(include).build(); - hardConstraints = new HardConstraintsBuilder().setCoRoutingOrGeneral(general).build(); - return hardConstraints; - } - private String findOrdNetworkNodeId(IpAddress nodeIpAddress) { - Iterator> it = this.mapNodeRefIp.entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - if (entry.getValue().equals(nodeIpAddress)) { - return entry.getKey(); - } - } - return null; + Include include = new IncludeBuilder().setNodeId(nodeIdList).build(); + hardConstraints = new HardConstraintsBuilder().setInclude(include).build(); + return hardConstraints; } public Response getResponse() {