Search in sources :

Example 6 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Algorithm 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 7 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Algorithm in project lispflowmapping by opendaylight.

the class LispMapCacheStringifier method prettyPrintKeys.

@SuppressWarnings("unchecked")
public static String prettyPrintKeys(ILispDAO dao) {
    final StringBuilder sb = new StringBuilder();
    final IRowVisitor innerVisitor = (new IRowVisitor() {

        public void visitRow(Object keyId, String valueKey, Object value) {
            switch(valueKey) {
                case SubKeys.AUTH_KEY:
                    String eid = LispAddressStringifier.getString((Eid) keyId);
                    sb.append("     ");
                    sb.append(eid);
                    int padLen = Math.max(2, Constants.INET6_ADDRSTRLEN - eid.length());
                    sb.append(Stringifier.getSpacesAsString(padLen));
                    MappingAuthkey authKey = (MappingAuthkey) value;
                    String hmac = LispKeyIDEnum.valueOf(authKey.getKeyType().shortValue()).getAuthenticationName();
                    sb.append(hmac);
                    sb.append(Stringifier.getSpacesAsString(Math.max(2, 22 - hmac.length())));
                    sb.append(authKey.getKeyString());
                    sb.append("\n");
                    break;
                default:
                    break;
            }
        }
    });
    dao.getAll(new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append("Instance ID " + keyId + "\n");
                sb.append("  -> EID                                           HMAC Algorithm        Shared Key\n");
            }
            if (valueKey.equals(SubKeys.VNI)) {
                ((ILispDAO) value).getAll(innerVisitor);
            }
            lastKey = key;
        }
    });
    return sb.toString();
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) IRowVisitor(org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)

Example 8 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Algorithm in project lispflowmapping by opendaylight.

the class MappingSystem method mergeNegativePrefixes.

/*
     * Merges adjacent negative prefixes and notifies their subscribers.
     */
private void mergeNegativePrefixes(Eid eid) {
    LOG.debug("Merging negative prefixes starting from EID {}", LispAddressStringifier.getString(eid));
    // If we delete nodes while we walk up the radix trie the algorithm will give incorrect results, because
    // removals rearrange relationships in the trie. So we save prefixes to be removed into a HashMap.
    Map<Eid, MappingData> mergedMappings = new HashMap<>();
    Eid currentNode = smc.getSiblingPrefix(eid);
    MappingData mapping = (MappingData) smc.getMapping(null, currentNode);
    if (mapping != null && mapping.isNegative().or(false)) {
        mergedMappings.put(currentNode, mapping);
    } else {
        return;
    }
    Eid previousNode = currentNode;
    currentNode = smc.getVirtualParentSiblingPrefix(currentNode);
    while (currentNode != null) {
        mapping = (MappingData) smc.getMapping(null, currentNode);
        if (mapping != null && mapping.isNegative().or(false)) {
            mergedMappings.put(currentNode, mapping);
        } else {
            break;
        }
        previousNode = currentNode;
        currentNode = smc.getVirtualParentSiblingPrefix(previousNode);
    }
    for (Eid key : mergedMappings.keySet()) {
        removeSbMapping(key, mergedMappings.get(key));
    }
    smc.removeMapping(eid);
    addNegativeMapping(getVirtualParent(previousNode));
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Example 9 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Algorithm 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 10 with Algorithm

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Algorithm in project bgpcep by opendaylight.

the class PathComputationImpl method computePath.

@Override
public Message computePath(final Requests req) {
    LOG.info("Received Compute Path request");
    /* Check that Request Parameter Object is present */
    if (req == null || req.getRp() == null) {
        LOG.error("Missing Request Parameter Objects. Abort!");
        return MessagesUtil.createErrorMsg(PCEPErrors.RP_MISSING, Uint32.ZERO);
    }
    LOG.debug("Request for path computation {}", req);
    /*
         * Check that mandatory End Point Objects are present and Source /
         * Destination are know in the TED Graph
         */
    P2p input = req.getSegmentComputation().getP2p();
    if (input == null || input.getEndpointsObj() == null) {
        LOG.error("Missing End Point Objects. Abort!");
        Uint32 reqID = req.getRp().getRequestId().getValue();
        return MessagesUtil.createErrorMsg(PCEPErrors.END_POINTS_MISSING, reqID);
    }
    VertexKey source = getSourceVertexKey(input.getEndpointsObj());
    VertexKey destination = getDestinationVertexKey(input.getEndpointsObj());
    if (source == null) {
        return MessagesUtil.createNoPathMessage(req.getRp(), MessagesUtil.UNKNOWN_SOURCE);
    }
    if (destination == null) {
        return MessagesUtil.createNoPathMessage(req.getRp(), MessagesUtil.UNKNOWN_DESTINATION);
    }
    /* Create new Constraints Object from the request */
    PathConstraints cts = getConstraints(input, !PSTUtil.isDefaultPST(req.getRp().getTlvs().getPathSetupType()));
    /* Determine Path Computation Algorithm according to Input choice */
    AlgorithmType algoType;
    if (cts.getTeMetric() == null && cts.getDelay() == 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 MessagesUtil.createErrorMsg(PCEPErrors.RESOURCE_LIMIT_EXCEEDED, Uint32.ZERO);
    }
    /* Request Path Computation for given source, destination and constraints */
    LOG.debug("Call Path Computation {} algorithm for path from {} to {} with contraints {}", algoType, source, destination, cts);
    final ConstrainedPath cpath = algo.computeP2pPath(source, destination, cts);
    LOG.info("Computed path: {}", cpath.getPathDescription());
    /* Check if we got a valid Path and return appropriate message */
    if (cpath.getStatus() == ComputationStatus.Completed) {
        return MessagesUtil.createPcRepMessage(req.getRp(), req.getSegmentComputation().getP2p(), cpath);
    } else {
        return MessagesUtil.createNoPathMessage(req.getRp(), MessagesUtil.NO_PATH);
    }
}
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) Uint32(org.opendaylight.yangtools.yang.common.Uint32) P2p(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.segment.computation.P2p)

Aggregations

PathComputationAlgorithm (org.opendaylight.algo.PathComputationAlgorithm)3 VertexKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey)3 ConstrainedPath (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPath)3 ConnectedEdge (org.opendaylight.graph.ConnectedEdge)2 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)2 AlgorithmType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.AlgorithmType)2 ConstrainedPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder)2 PathConstraints (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.PathConstraints)2 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConnectedGraph (org.opendaylight.graph.ConnectedGraph)1 IRowVisitor (org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor)1 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)1 MappingAuthkey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)1 SrAlgorithm (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.state.SrAlgorithm)1 SrAlgorithmBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.state.SrAlgorithmBuilder)1 Algorithm (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Algorithm)1 BgpOrigin (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin)1