Search in sources :

Example 1 with Graph

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph 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 Graph

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph in project bgpcep by opendaylight.

the class LinkstateGraphBuilder method createEdge.

/**
 * Create new Connected Edge in the Connected Graph.
 *
 * @param value       The complete Linkstate route information
 * @param linkCase    The Link part of the Linkstate route
 * @param attributes  The Link attributes
 */
private void createEdge(final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
    checkArgument(checkLinkState(linkCase), "Missing mandatory information in link {}", linkCase);
    final LinkAttributes la = getLinkAttributes(attributes);
    if (la == null) {
        LOG.warn("Missing attributes in link {} route {}, skipping it", linkCase, value);
        return;
    }
    /* Get Source and Destination Vertex from the graph */
    Uint64 srcId = getVertexId(linkCase.getLocalNodeDescriptors().getCRouterIdentifier());
    Uint64 dstId = getVertexId(linkCase.getRemoteNodeDescriptors().getCRouterIdentifier());
    if (srcId == Uint64.ZERO || dstId == Uint64.ZERO) {
        LOG.warn("Unable to get the Source or Destination Vertex Identifier from link {}, skipping it", linkCase);
        return;
    }
    /* Get Source and Destination Key for the corresponding Edge */
    Uint64 edgeId = getEdgeId(linkCase);
    if (edgeId == Uint64.ZERO) {
        LOG.warn("Unable to get the Edge Identifier from link {}, skipping it", linkCase);
        return;
    }
    /* Add associated Edge */
    Edge edge = new EdgeBuilder().setEdgeId(edgeId).setLocalVertexId(srcId).setRemoteVertexId(dstId).setName(srcId + " - " + dstId).setEdgeAttributes(createEdgeAttributes(la, linkCase.getLinkDescriptors())).build();
    /*
         * Add corresponding Prefix for the Local Address. Remote address will be added with the remote Edge */
    final var localAddress = edge.getEdgeAttributes().getLocalAddress();
    PrefixBuilder prefBuilder = new PrefixBuilder().setVertexId(srcId);
    if (localAddress.getIpv4Address() != null) {
        prefBuilder.setPrefix(new IpPrefix(IetfInetUtil.INSTANCE.ipv4PrefixFor(localAddress.getIpv4Address())));
    }
    if (localAddress.getIpv6Address() != null) {
        prefBuilder.setPrefix(new IpPrefix(IetfInetUtil.INSTANCE.ipv6PrefixFor(localAddress.getIpv6Address())));
    }
    Prefix prefix = prefBuilder.build();
    /* Add the Edge in the Connected Graph */
    LOG.info("Add Edge {} and associated Prefix {} in TED[{}]", edge.getName(), prefix.getPrefix(), cgraph);
    cgraph.addEdge(edge);
    cgraph.addPrefix(prefix);
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) LinkAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes) Prefix(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) Edge(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Edge) EdgeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.EdgeBuilder) Uint64(org.opendaylight.yangtools.yang.common.Uint64) PrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder)

Example 3 with Graph

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph in project bgpcep by opendaylight.

the class LinkstateGraphBuilder method createVertex.

/**
 * Create new Connected Vertex in the Connected Graph.
 *
 * @param value       The complete Linkstate route information
 * @param nodeCase    The node part of the Linkstate route
 * @param attributes  The node attributes
 */
private void createVertex(final LinkstateRoute value, final NodeCase nodeCase, final Attributes attributes) {
    checkArgument(nodeCase != null, "Missing Node Case. Skip this Node");
    checkArgument(nodeCase.getNodeDescriptors() != null, "Missing Node Descriptors. Skip this Node");
    Uint64 vertexId = getVertexId(nodeCase.getNodeDescriptors().getCRouterIdentifier());
    if (vertexId == Uint64.ZERO) {
        LOG.warn("Unable to get Vertex Identifier from descriptor {}, skipping it", nodeCase.getNodeDescriptors());
        return;
    }
    NodeAttributes na = getNodeAttributes(attributes);
    if (na == null) {
        LOG.warn("Missing attributes in node {} route {}, skipping it", nodeCase, value);
        return;
    }
    Uint32 asNumber = Uint32.ZERO;
    if (nodeCase.getNodeDescriptors() != null) {
        asNumber = nodeCase.getNodeDescriptors().getAsNumber().getValue();
    }
    Vertex vertex = getVertex(na, vertexId, asNumber);
    /* Add the Connected Vertex and associated Vertex in the Graph */
    LOG.info("Add Vertex {} in TED[{}]", vertex.getName(), cgraph);
    cgraph.addVertex(vertex);
}
Also used : Vertex(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Vertex) NodeAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 4 with Graph

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph in project bgpcep by opendaylight.

the class LinkstateGraphBuilder method getVertexId.

/**
 * Get Vertex in the Graph by the OSPF Router ID or IS-IS-System ID.
 *
 * @param routerID  The Router Identifier entry
 *
 * @return Vertex in the Connected Graph that corresponds to this Router ID. Vertex is created if not found.
 */
private static Uint64 getVertexId(final CRouterIdentifier routerID) {
    Uint64 rid = Uint64.ZERO;
    if (routerID instanceof IsisNodeCase) {
        final byte[] isoId = ((IsisNodeCase) routerID).getIsisNode().getIsoSystemId().getValue();
        final byte[] convert = { 0, 0, isoId[0], isoId[1], isoId[2], isoId[3], isoId[4], isoId[5] };
        rid = Uint64.fromLongBits(ByteBuffer.wrap(convert).getLong());
    }
    if (routerID instanceof OspfNodeCase) {
        rid = ((OspfNodeCase) routerID).getOspfNode().getOspfRouterId().toUint64();
    }
    LOG.debug("Get Vertex Identifier {}", rid);
    return rid;
}
Also used : IsisNodeCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.IsisNodeCase) OspfNodeCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.OspfNodeCase) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 5 with Graph

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph 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)

Aggregations

Uint64 (org.opendaylight.yangtools.yang.common.Uint64)4 ConnectedGraph (org.opendaylight.graph.ConnectedGraph)3 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)3 Prefix (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix)3 PathComputationAlgorithm (org.opendaylight.algo.PathComputationAlgorithm)2 ConnectedVertex (org.opendaylight.graph.ConnectedVertex)2 Graph (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.Graph)2 Edge (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Edge)2 PrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder)2 Vertex (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Vertex)2 VertexKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey)2 ConstrainedPath (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPath)2 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)2 ArrayList (java.util.ArrayList)1 ConnectedEdge (org.opendaylight.graph.ConnectedEdge)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 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)1 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)1