Search in sources :

Example 1 with ConnectedGraph

use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.

the class PathComputationServer method getConstrainedPath.

@Override
public ListenableFuture<RpcResult<GetConstrainedPathOutput>> getConstrainedPath(final GetConstrainedPathInput input) {
    final GetConstrainedPathOutputBuilder output = new GetConstrainedPathOutputBuilder();
    LOG.info("Got Path Computation Service request");
    /* First, get graph */
    final ConnectedGraph cgraph = graphProvider.getConnectedGraph(input.getGraphName());
    if (cgraph == null) {
        output.setStatus(ComputationStatus.Failed);
        return RpcResultBuilder.<GetConstrainedPathOutput>failed().withError(RpcError.ErrorType.RPC, "Unknown Graph Name").buildFuture();
    }
    /* get a new Path Computation Algorithm according to Input choice */
    PathComputationAlgorithm algo = getPathComputationAlgorithm(cgraph, input.getAlgorithm());
    if (algo == null) {
        output.setStatus(ComputationStatus.Failed);
        return RpcResultBuilder.<GetConstrainedPathOutput>failed().withError(RpcError.ErrorType.RPC, "Unknown Path Computation Algorithm").buildFuture();
    }
    /*
         * Request Path Computation for given source, destination and
         * constraints
         */
    final VertexKey source = new VertexKey(input.getSource());
    final VertexKey destination = new VertexKey(input.getDestination());
    LOG.info("Call Path Computation {} algorithm for path from {} to {} with contraints {}", input.getAlgorithm().getName(), source, destination, input.getConstraints());
    final ConstrainedPath cpath = algo.computeP2pPath(source, destination, input.getConstraints());
    /* Send back the Computed Path */
    output.setPathDescription(cpath.getPathDescription()).setStatus(cpath.getStatus()).setComputedMetric(cpath.getMetric()).setComputedTeMetric(cpath.getTeMetric()).setComputedDelay(cpath.getDelay());
    return RpcResultBuilder.success(output.build()).buildFuture();
}
Also used : GetConstrainedPathOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.GetConstrainedPathOutput) ConnectedGraph(org.opendaylight.graph.ConnectedGraph) ConstrainedPath(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPath) GetConstrainedPathOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.GetConstrainedPathOutputBuilder) VertexKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey) PathComputationAlgorithm(org.opendaylight.algo.PathComputationAlgorithm)

Example 2 with ConnectedGraph

use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.

the class ConnectedGraphServer method createConnectedGraph.

@Override
public ConnectedGraph createConnectedGraph(final String name, final DomainScope scope) {
    Graph graph = new GraphBuilder().setName(name).setDomainScope(scope).build();
    addToDataStore(getGraphInstanceIdentifier(name), graph, "Graph(" + name + ")");
    ConnectedGraphImpl cgraph = new ConnectedGraphImpl(graph, this);
    graphs.put(graph.key(), cgraph);
    return cgraph;
}
Also used : ConnectedGraph(org.opendaylight.graph.ConnectedGraph) Graph(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph) GraphBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.GraphBuilder)

Example 3 with ConnectedGraph

use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.

the class GraphListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Graph>> changes) {
    for (DataTreeModification<Graph> change : changes) {
        DataObjectModification<Graph> root = change.getRootNode();
        GraphKey key = change.getRootPath().getRootIdentifier().firstKeyOf(Graph.class);
        switch(root.getModificationType()) {
            case DELETE:
                graphProvider.deleteGraph(key);
                break;
            case SUBTREE_MODIFIED:
            /* getModificationType() returns SUBTREE_MODIFIED only when Data Object is already present in the
                     * Data Store, thus, only for deletion. Thus, to insert children, we must used parseSubTree()
                     * method (See above). This method is called only when the graph already exists.
                     */
            case WRITE:
                /* First look if the Graph was not already configured */
                ConnectedGraph cgraph = this.graphProvider.getConnectedGraph(key);
                if (cgraph == null) {
                    graphProvider.addGraph(root.getDataAfter());
                } else {
                    /* Graph exist, process Children */
                    parseSubTree(cgraph, root.getModifiedChildren());
                }
                break;
            default:
                break;
        }
    }
}
Also used : ConnectedGraph(org.opendaylight.graph.ConnectedGraph) Graph(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph) ConnectedGraph(org.opendaylight.graph.ConnectedGraph) GraphKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.GraphKey)

Example 4 with ConnectedGraph

use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.

the class ConnectedGraphServer method destroyOperationalGraphModel.

/**
 * Destroy the current operational topology data. Note a valid transaction must be provided.
 */
private synchronized FluentFuture<? extends CommitInfo> destroyOperationalGraphModel() {
    requireNonNull(this.chain, "A valid transaction chain must be provided.");
    final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
    trans.delete(LogicalDatastoreType.OPERATIONAL, GRAPH_TOPOLOGY_IDENTIFIER);
    trans.delete(LogicalDatastoreType.CONFIGURATION, GRAPH_TOPOLOGY_IDENTIFIER);
    final FluentFuture<? extends CommitInfo> future = trans.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Operational GraphModel removed {}", GRAPH_TOPOLOGY_IDENTIFIER);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Unable to reset operational GraphModel {} (transaction {})", GRAPH_TOPOLOGY_IDENTIFIER, trans.getIdentifier(), throwable);
        }
    }, MoreExecutors.directExecutor());
    /* Clear Connected Graph */
    for (ConnectedGraph graph : graphs.values()) {
        ((ConnectedGraphImpl) graph).clear();
    }
    return future;
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) ConnectedGraph(org.opendaylight.graph.ConnectedGraph) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Aggregations

ConnectedGraph (org.opendaylight.graph.ConnectedGraph)4 Graph (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph)2 PathComputationAlgorithm (org.opendaylight.algo.PathComputationAlgorithm)1 ReadWriteTransaction (org.opendaylight.mdsal.binding.api.ReadWriteTransaction)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)1 GraphBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.GraphBuilder)1 GraphKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.GraphKey)1 VertexKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey)1 ConstrainedPath (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPath)1 GetConstrainedPathOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.GetConstrainedPathOutput)1 GetConstrainedPathOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.GetConstrainedPathOutputBuilder)1