Search in sources :

Example 1 with PathConstraints

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints in project bgpcep by opendaylight.

the class ConstrainedShortestPathFirst method computeP2pPath.

@Override
public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
    LOG.info("Start CSPF Path Computation from {} to {} with constraints {}", src, dst, cts);
    /* Initialize algorithm */
    this.constraints = cts;
    ConstrainedPathBuilder cpathBuilder = initializePathComputation(src, dst);
    if (cpathBuilder.getStatus() == ComputationStatus.Failed) {
        return cpathBuilder.build();
    }
    cpathBuilder.setBandwidth(cts.getBandwidth()).setClassType(cts.getClassType());
    visitedVertices.clear();
    /* Process all Connected Vertex until priority queue becomes empty. Connected Vertices are added into the
         * priority queue when processing the next Connected Vertex: see relaxMC() method */
    int currentCost = Integer.MAX_VALUE;
    while (priorityQueue.size() != 0) {
        CspfPath currentPath = priorityQueue.poll();
        visitedVertices.put(currentPath.getVertexKey(), currentPath);
        LOG.debug("Got path to Vertex {} from Priority Queue", currentPath.getVertex());
        List<ConnectedEdge> edges = currentPath.getVertex().getOutputConnectedEdges();
        for (ConnectedEdge edge : edges) {
            /* Skip Connected Edges that must be prune i.e. Edges that not satisfy the given constraints,
                 * in particular the Bandwidth, TE Metric and Delay. */
            if (pruneEdge(edge, currentPath)) {
                LOG.trace("  Prune Edge {}", edge);
                continue;
            }
            if (relaxMultiConstraints(edge, currentPath) && pathDestination.getCost() < currentCost) {
                currentCost = pathDestination.getCost();
                cpathBuilder.setPathDescription(getPathDescription(pathDestination.getPath())).setMetric(Uint32.valueOf(pathDestination.getCost())).setStatus(ComputationStatus.Active);
                LOG.debug("  Found a valid path up to destination {}", cpathBuilder.getPathDescription());
            }
        }
    }
    /* The priority queue is empty => all the possible (vertex, path) elements have been explored
         * The "ConstrainedPathBuilder" object contains the optimal path if it exists
         * Otherwise an empty path with status failed is returned
         */
    if (cpathBuilder.getStatus() == ComputationStatus.InProgress || cpathBuilder.getPathDescription().size() == 0) {
        cpathBuilder.setStatus(ComputationStatus.Failed);
    } else {
        cpathBuilder.setStatus(ComputationStatus.Completed);
    }
    return cpathBuilder.build();
}
Also used : ConstrainedPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder) ConnectedEdge(org.opendaylight.graph.ConnectedEdge)

Example 2 with PathConstraints

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints in project bgpcep by opendaylight.

the class Samcra method computeP2pPath.

/* Samcra Algo:
     *
     * To limit the modification outside the Samcra method the same set of parameters as
     * the CSPF method is used (related to pseudo code, the path length is computed inside
     * the method based on the individual constraint parameters).
     *
     * On contrast to a simple CSPF algo, with Samcra a connected vertex might be associated to several
     * metric vectors from which different path lengths are computed. However a connected vertex is only
     * present once in the priority queue, associated to the minimal path weight, which is used as key
     * to address the priority queue.
     *
     * For a given metric the path weight is an integer value computed as the entire part of
     * the quantity:
     *      100 * (vector_path_metric/target_metric)
     * The path weight correspond to the maximum length computed from either the delay or TE metric.
     *
     * To maintain the priority queue behavior unchanged, a "SamcraPath" classes is created to manage
     * the set of possible paths associated to a given vertex (see above).
     *
     */
@Override
public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
    ConstrainedPathBuilder cpathBuilder;
    List<ConnectedEdge> edges;
    CspfPath currentPath;
    LOG.info("Start SAMCRA Path Computation from {} to {} with constraints {}", src, dst, cts);
    /* Initialize SAMCRA variables */
    this.constraints = cts;
    cpathBuilder = initializePathComputation(src, dst);
    if (cpathBuilder.getStatus() == ComputationStatus.Failed) {
        return cpathBuilder.build();
    }
    cpathBuilder.setBandwidth(cts.getBandwidth()).setClassType(cts.getClassType());
    samcraPaths.clear();
    samcraPaths.put(pathSource.getVertexKey(), new SamcraPath(pathSource.getVertex()));
    samcraPaths.put(pathDestination.getVertexKey(), new SamcraPath(pathDestination.getVertex()));
    /* Exploration of the priority queue:
         * Each connected vertex is represented only once in the priority queue associated to the path
         * with the minimal length (other path are stored in the SamcraPath object).
         * The top of the queue, i.e. the element with the minimal key( path weight), is processed at each loop
         */
    while (priorityQueue.size() != 0) {
        currentPath = priorityQueue.poll();
        LOG.debug(" - Process path up to Vertex {} from Priority Queue", currentPath.getVertex());
        /* Prepare Samcra Path from current CSP Path except for the source */
        if (!currentPath.equals(pathSource)) {
            SamcraPath currentSamcraPath = samcraPaths.get(currentPath.getVertexKey());
            CspfPath currentCspfPath = currentSamcraPath.getCurrentPath();
            float queuePathLength = currentCspfPath.getPathLength();
            LOG.trace(" - Priority Queue output SamcraPaths {} CurrentPath {} with PathLength {}", currentSamcraPath.currentPath, currentCspfPath, queuePathLength);
        }
        edges = currentPath.getVertex().getOutputConnectedEdges();
        float currentPathLength = 1.0F;
        for (ConnectedEdge edge : edges) {
            /* Connected Vertex's edges processing:
                 * Prune the connected edges that do not satisfy the constraints (Bandwidth, TE Metric, Delay, Loss)
                 * For each remaining edge process the path to the remote vertex using the "relaxSamcra" procedure
                 *
                 * If the return path length is positive, the destination is reached and the
                 * obtained route satisfies the requested constraints.
                 * The path length is checked to record only the optimal route (i.e. the route with
                 * the minimal path length) info obtained from the destination vertex
                 */
            if (pruneEdge(edge, currentPath)) {
                LOG.trace(" - Prune Edge {}", edge);
                continue;
            }
            float pathLength = relaxSamcra(edge, currentPath, pathSource);
            /* Check if we found a valid and better path */
            if (pathLength > 0F && pathLength <= currentPathLength) {
                final SamcraPath finalPath = samcraPaths.get(pathDestination.getVertexKey());
                cpathBuilder.setPathDescription(getPathDescription(finalPath.getCurrentPath().getPath())).setMetric(Uint32.valueOf(finalPath.getCurrentPath().getCost())).setDelay(new Delay(Uint32.valueOf(finalPath.getCurrentPath().getDelay()))).setStatus(ComputationStatus.Active);
                LOG.debug(" - Path to destination found and registered {}", cpathBuilder.getPathDescription());
                currentPathLength = pathLength;
            }
        }
        /* The connected vertex that has been removed from the priority queue may have to be re-inserted with
             * the minimal length non-dominated path associated to the connected vertex if it exists (to be done
             * except for the source). Otherwise, the current path associated to the connected vertex is reset to
             * null to allow the connected vertex addition to the priority queue later on with a new path
             * (refer to "relaxSamcra" for addition of a connected vertex to the priority queue).
             */
        float previousLength = 1.0F;
        CspfPath selectedPath = null;
        if (!currentPath.equals(pathSource)) {
            LOG.debug(" - Processing current path {} up to {} from Priority Queue", currentPath, currentPath.getVertex());
            SamcraPath currentSamcraPath = samcraPaths.get(currentPath.getVertexKey());
            currentSamcraPath.decrementPathCount();
            /*
                 * The list of paths associated to the connected vertex is retrieved
                 * The path used to represent the connected vertex in the Priority Queue is marked from "selected"
                 * to "processed". The list of paths is analyzed to check if other "active" path(s) exist(s).
                 * If it is the case the shortest length is used to re-inject the connected vertex in the Priority Queue
                 */
            for (CspfPath testedPath : currentSamcraPath.getPathList()) {
                LOG.debug(" - Testing path {} with status {} ", testedPath, testedPath.getPathStatus());
                if (testedPath.getPathStatus() == CspfPath.SELECTED) {
                    testedPath.setPathStatus(CspfPath.PROCESSED);
                } else if (testedPath.getPathStatus() == CspfPath.ACTIVE && testedPath.getPathLength() < previousLength) {
                    selectedPath = testedPath;
                    previousLength = testedPath.getPathLength();
                }
            }
            /* If a path is found it is marked as "selected", used as "current path" for the connected vertex
                 * and added to the priority queue
                 */
            if (selectedPath != null) {
                selectedPath.setPathStatus(CspfPath.SELECTED);
                currentSamcraPath.setCurrentPath(selectedPath);
                priorityQueue.add(selectedPath);
                LOG.debug(" - Add path {} to Priority Queue. New path count {} ", selectedPath, currentSamcraPath.getPathCount());
            } else {
                currentSamcraPath.setCurrentPath(null);
            }
        }
    }
    /* The priority queue is empty => all the possible (vertex, path) elements have been explored
         * The "ConstrainedPathBuilder" object contains the optimal path if it exists
         * Otherwise an empty path with status failed is returned
         */
    if (cpathBuilder.getStatus() == ComputationStatus.InProgress || cpathBuilder.getPathDescription().size() == 0) {
        cpathBuilder.setStatus(ComputationStatus.Failed);
    } else {
        cpathBuilder.setStatus(ComputationStatus.Completed);
    }
    return cpathBuilder.build();
}
Also used : ConstrainedPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder) ConnectedEdge(org.opendaylight.graph.ConnectedEdge) Delay(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.Delay)

Example 3 with PathConstraints

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints in project bgpcep by opendaylight.

the class PathComputationImpl method computeEro.

@Override
public Ero computeEro(final EndpointsObj endpoints, final Bandwidth bandwidth, final ClassType classType, final List<Metrics> metrics, final boolean segmentRouting) {
    VertexKey source = getSourceVertexKey(endpoints);
    VertexKey destination = getDestinationVertexKey(endpoints);
    if (source == null) {
        return null;
    }
    if (destination == null) {
        return null;
    }
    /* Create new Constraints Object from the request */
    PathConstraints cts = getConstraints(endpoints, bandwidth, classType, metrics, segmentRouting);
    /* Determine Path Computation Algorithm according to parameters */
    AlgorithmType algoType;
    if (cts.getTeMetric() == null && cts.getDelay() == null && cts.getBandwidth() == null) {
        algoType = AlgorithmType.Spf;
    } else if (cts.getDelay() == null) {
        algoType = AlgorithmType.Cspf;
    } else {
        algoType = AlgorithmType.Samcra;
    }
    PathComputationAlgorithm algo = algoProvider.getPathComputationAlgorithm(tedGraph, algoType);
    if (algo == null) {
        return null;
    }
    /*
         * Request Path Computation for given source, destination and
         * constraints
         */
    final ConstrainedPath cpath = algo.computeP2pPath(source, destination, cts);
    LOG.info("Computed ERO: {}", cpath.getPathDescription());
    /* Check if we got a valid Path and return appropriate ERO */
    if (cpath.getStatus() == ComputationStatus.Completed) {
        return MessagesUtil.getEro(cpath.getPathDescription());
    } else {
        return null;
    }
}
Also used : AlgorithmType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.AlgorithmType) ConstrainedPath(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPath) VertexKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey) PathComputationAlgorithm(org.opendaylight.algo.PathComputationAlgorithm) PathConstraints(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints)

Example 4 with PathConstraints

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints in project bgpcep by opendaylight.

the class ShortestPathFirst method computeP2pPath.

@Override
public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
    ConstrainedPathBuilder cpathBuilder;
    List<ConnectedEdge> edges;
    CspfPath currentPath;
    int currentCost = Integer.MAX_VALUE;
    LOG.info("Start SPF Path Computation from {} to {} with constraints {}", src, dst, cts);
    /* Initialize algorithm */
    this.constraints = cts;
    cpathBuilder = initializePathComputation(src, dst);
    if (cpathBuilder.getStatus() == ComputationStatus.Failed) {
        LOG.warn("Initial configurations are not met. Abort!");
        return cpathBuilder.build();
    }
    visitedVertices.clear();
    while (priorityQueue.size() != 0) {
        currentPath = priorityQueue.poll();
        visitedVertices.put(currentPath.getVertexKey(), currentPath);
        LOG.debug("Process path to Vertex {} from Priority Queue", currentPath.getVertex());
        edges = currentPath.getVertex().getOutputConnectedEdges();
        for (ConnectedEdge edge : edges) {
            /* Check that Edge point to a valid Vertex and is suitable for the Constraint Address Family */
            if (pruneEdge(edge, currentPath)) {
                LOG.trace("  Prune Edge {}", edge);
                continue;
            }
            if (relax(edge, currentPath) && pathDestination.getCost() < currentCost) {
                currentCost = pathDestination.getCost();
                cpathBuilder.setPathDescription(getPathDescription(pathDestination.getPath())).setMetric(Uint32.valueOf(pathDestination.getCost())).setStatus(ComputationStatus.Active);
                LOG.debug("  Found a valid path up to destination {}", cpathBuilder.getPathDescription());
            }
        }
    }
    /* The priority queue is empty => all the possible (vertex, path) elements have been explored
         * The "ConstrainedPathBuilder" object contains the optimal path if it exists
         * Otherwise an empty path with status failed is returned
         */
    if (cpathBuilder.getStatus() == ComputationStatus.InProgress || cpathBuilder.getPathDescription().size() == 0) {
        cpathBuilder.setStatus(ComputationStatus.Failed);
    } else {
        cpathBuilder.setStatus(ComputationStatus.Completed);
    }
    return cpathBuilder.build();
}
Also used : ConstrainedPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder) ConnectedEdge(org.opendaylight.graph.ConnectedEdge)

Example 5 with PathConstraints

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints in project bgpcep by opendaylight.

the class PathComputationImpl method getConstraints.

private static PathConstraints getConstraints(final EndpointsObj endpoints, final Bandwidth bandwidth, final ClassType classType, final List<Metrics> metrics, final boolean segmentRouting) {
    ConstraintsBuilder ctsBuilder = new ConstraintsBuilder();
    Float convert;
    /* Set Metrics if any */
    if (metrics != null) {
        for (Metrics metric : metrics) {
            convert = ByteBuffer.wrap(metric.getMetric().getValue().getValue()).getFloat();
            final long value = convert.longValue();
            /* Skip Metric with value equal to 0 */
            if (value == 0) {
                continue;
            }
            switch(metric.getMetric().getMetricType().intValue()) {
                case MessagesUtil.IGP_METRIC:
                    ctsBuilder.setMetric(Uint32.valueOf(value));
                    break;
                case MessagesUtil.TE_METRIC:
                    ctsBuilder.setTeMetric(Uint32.valueOf(value));
                    break;
                case MessagesUtil.PATH_DELAY:
                    ctsBuilder.setDelay(new Delay(Uint32.valueOf(value)));
                    break;
                default:
                    LOG.warn("Metric {} is not handle by Path Computation Constraints", metric);
                    break;
            }
        }
    }
    /* Set Bandwidth and Class Type */
    if (bandwidth != null) {
        convert = ByteBuffer.wrap(bandwidth.getBandwidth().getValue()).getFloat();
        final long value = convert.longValue();
        /* Skip Bandwidth with value equal to 0 */
        if (value != 0) {
            ctsBuilder.setBandwidth(new DecimalBandwidth(BigDecimal.valueOf(value)));
            if (classType != null) {
                ctsBuilder.setClassType(classType.getClassType().getValue());
            }
        }
    }
    /* Set Address Family */
    if (endpoints.getAddressFamily() instanceof Ipv4Case) {
        ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv4 : AddressFamily.Ipv4);
    } else {
        ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv6 : AddressFamily.Ipv6);
    }
    return ctsBuilder.build();
}
Also used : DecimalBandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.DecimalBandwidth) Metrics(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics) ConstraintsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.get.constrained.path.input.ConstraintsBuilder) Ipv4Case(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case) Delay(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.Delay)

Aggregations

ConnectedEdge (org.opendaylight.graph.ConnectedEdge)3 ConstrainedPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder)3 PathComputationAlgorithm (org.opendaylight.algo.PathComputationAlgorithm)2 Delay (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.Delay)2 VertexKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey)2 AlgorithmType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.AlgorithmType)2 ConstrainedPath (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPath)2 PathConstraints (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints)2 DecimalBandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.DecimalBandwidth)1 ConstraintsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.get.constrained.path.input.ConstraintsBuilder)1 Ipv4Case (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case)1 Metrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics)1 P2p (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.segment.computation.P2p)1 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)1