use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey 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;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey in project bgpcep by opendaylight.
the class AbstractPathComputation method initializePathComputation.
/**
* Initialize the various parameters for Path Computation, in particular the
* Source and Destination CspfPath.
*
* @param src
* Source Vertex Identifier in the Connected Graph
* @param dst
* Destination Vertex Identifier in the Connected Graph
*
* @return Constrained Path Builder with status set to 'OnGoing' if
* initialization success, 'Failed' otherwise
*/
protected ConstrainedPathBuilder initializePathComputation(final VertexKey src, final VertexKey dst) {
ConstrainedPathBuilder cpathBuilder = new ConstrainedPathBuilder().setStatus(ComputationStatus.InProgress);
/* Check that source and destination vertexKey are not identical */
if (src.equals(dst)) {
LOG.warn("Source and Destination are equal: Abort!");
cpathBuilder.setStatus(ComputationStatus.Failed);
return cpathBuilder;
}
/*
* Get the Connected Vertex from the Graph to initialize the source of
* the Cspf Path
*/
ConnectedVertex vertex = graph.getConnectedVertex(src.getVertexId().longValue());
if (vertex == null) {
LOG.warn("Found no source for Vertex Key {}", src);
cpathBuilder.setStatus(ComputationStatus.Failed);
return cpathBuilder;
}
LOG.debug("Create Path Source with Vertex {}", vertex);
pathSource = new CspfPath(vertex).setCost(0).setDelay(0);
cpathBuilder.setSource(vertex.getVertex().getVertexId());
/*
* Get the Connected Vertex from the Graph to initialize the destination
* of the Cspf Path
*/
vertex = graph.getConnectedVertex(dst.getVertexId().longValue());
if (vertex == null) {
LOG.warn("Found no destination for Vertex Key {}", src);
cpathBuilder.setStatus(ComputationStatus.Failed);
return cpathBuilder;
}
LOG.debug("Create Path Destination with Vertex {}", vertex);
pathDestination = new CspfPath(vertex);
cpathBuilder.setDestination(vertex.getVertex().getVertexId());
/* Initialize the Priority Queue, HashMap */
priorityQueue.clear();
priorityQueue.add(pathSource);
processedPath.clear();
processedPath.put(pathSource.getVertexKey(), pathSource);
processedPath.put(pathDestination.getVertexKey(), pathDestination);
return cpathBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey 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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey in project bgpcep by opendaylight.
the class LinkstateGraphBuilder method removeVertex.
private void removeVertex(final NodeCase nodeCase) {
VertexKey vertexKey = new VertexKey(getVertexId(nodeCase.getNodeDescriptors().getCRouterIdentifier()));
if (vertexKey == null || vertexKey.getVertexId() == Uint64.ZERO) {
LOG.warn("Unable to get Vertex Key from descriptor {}, skipping it", nodeCase.getNodeDescriptors());
return;
}
LOG.info("Deleted Vertex {} in TED[{}]", vertexKey, cgraph);
cgraph.deleteVertex(vertexKey);
}
Aggregations