Search in sources :

Example 11 with Vertex

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

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

the class ConnectedGraphImpl method createConnectedGraph.

/**
 * Transform the associated Graph in a Connected Graph. This method will automatically create associated Connected
 * Vertices, from the Graph Vertices, Connected Edges, from the Graph Edges and Prefix from the Graph Prefix.
 */
private void createConnectedGraph() {
    if (this.graph == null) {
        return;
    }
    /* Add all vertices */
    for (Vertex vertex : this.graph.nonnullVertex().values()) {
        ConnectedVertexImpl cvertex = new ConnectedVertexImpl(vertex);
        vertices.put(cvertex.getKey(), cvertex);
    }
    /* Add all edges */
    for (Edge edge : this.graph.nonnullEdge().values()) {
        ConnectedEdgeImpl cedge = new ConnectedEdgeImpl(edge);
        edges.put(cedge.getKey(), cedge);
    }
    /* Add all prefixes */
    for (Prefix prefix : this.graph.nonnullPrefix().values()) {
        ConnectedVertexImpl cvertex = vertices.get(prefix.getVertexId().longValue());
        if (cvertex != null) {
            cvertex.addPrefix(prefix);
        }
        prefixes.putIfAbsent(prefix.getPrefix(), prefix);
    }
}
Also used : Vertex(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Vertex) ConnectedVertex(org.opendaylight.graph.ConnectedVertex) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) Prefix(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix) Edge(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Edge) ConnectedEdge(org.opendaylight.graph.ConnectedEdge)

Example 13 with Vertex

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

the class LinkstateGraphBuilder method removeEdge.

private void removeEdge(final LinkCase linkCase) {
    /* Get Source and Destination Connected Vertex */
    if (linkCase.getLinkDescriptors() == null) {
        LOG.warn("Missing Link descriptor in link {}, skipping it", linkCase);
        return;
    }
    EdgeKey edgeKey = new EdgeKey(getEdgeId(linkCase));
    if (edgeKey == null || edgeKey.getEdgeId() == Uint64.ZERO) {
        LOG.warn("Unable to get the Edge Key from link {}, skipping it", linkCase);
        return;
    }
    LOG.info("Deleted Edge {} from TED[{}]", edgeKey, cgraph);
    cgraph.deleteEdge(edgeKey);
}
Also used : EdgeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.EdgeKey)

Example 14 with Vertex

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

the class LinkstateGraphBuilder method createPrefix.

/**
 * Create new Prefix in the Connected Graph.
 *
 * @param value       The complete Linkstate route information
 * @param prefixCase  The Prefix part of the Linkstate route
 * @param attributes  The Prefix attributes
 */
private void createPrefix(final LinkstateRoute value, final PrefixCase prefixCase, final Attributes attributes) {
    final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
    if (ippfx == null) {
        LOG.warn("IP reachability not present in prefix {} route {}, skipping it", prefixCase, value);
        return;
    }
    /* Verify that all mandatory information are present */
    final PrefixAttributes pa;
    final Attributes1 attr = attributes.augmentation(Attributes1.class);
    if (attr != null) {
        final LinkStateAttribute attrType = attr.getLinkStateAttribute();
        if (attrType instanceof PrefixAttributesCase) {
            pa = ((PrefixAttributesCase) attrType).getPrefixAttributes();
        } else {
            LOG.warn("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
            return;
        }
    } else {
        LOG.warn("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
        return;
    }
    /*
         * Get Connected Vertex from Connected Graph corresponding to the
         * Advertising Node Descriptor
         */
    Uint64 vertexId = getVertexId(prefixCase.getAdvertisingNodeDescriptors().getCRouterIdentifier());
    if (vertexId == Uint64.ZERO) {
        LOG.warn("Unable to get the Vertex Identifier from descriptor {}, skipping it", prefixCase.getAdvertisingNodeDescriptors());
        return;
    }
    /* Create Prefix */
    PrefixBuilder builder = new PrefixBuilder().setVertexId(vertexId).setPrefix(ippfx);
    if (pa.getSrPrefix() != null && pa.getSrPrefix().getSidLabelIndex() instanceof SidCase) {
        builder.setPrefixSid(((SidCase) pa.getSrPrefix().getSidLabelIndex()).getSid());
        if (pa.getSrPrefix().getFlags() instanceof IsisPrefixFlagsCase) {
            builder.setNodeSid(((IsisPrefixFlagsCase) pa.getSrPrefix().getFlags()).getIsisPrefixFlags().getNodeSid());
        } else {
            /*
                 * Seems that OSPF Flags are not accessible. Assuming that the
                 * Prefix is a Node SID
                 */
            builder.setNodeSid(true);
        }
    }
    Prefix prefix = builder.build();
    /* Add the Prefix to the Connected Vertex within the Connected Graph */
    LOG.info("Add prefix {} in TED[{}]", builder.getPrefix(), cgraph);
    cgraph.addPrefix(prefix);
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IsisPrefixFlagsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.prefix.sid.tlv.flags.IsisPrefixFlagsCase) PrefixAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes) PrefixAttributesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.linkstate.route.Attributes1) 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) LinkStateAttribute(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute) SidCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCase) 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 15 with Vertex

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

the class LinkstateGraphBuilder method getVertex.

/**
 * Create Vertex from the Node Attributes.
 *
 * @param na       Node Attributes
 * @param cvertex  Connected Vertex associated to this Vertex
 * @param as       As number
 *
 * @return New Vertex
 */
private static Vertex getVertex(final NodeAttributes na, final Uint64 id, final Uint32 as) {
    VertexBuilder builder = new VertexBuilder().setVertexId(id).setAsn(as);
    if (na.getIpv4RouterId() != null) {
        builder.setRouterId(new IpAddress(na.getIpv4RouterId()));
    }
    if (na.getIpv6RouterId() != null) {
        builder.setRouterId(new IpAddress(na.getIpv6RouterId()));
    }
    /*
         * Set Router Name with dynamic hostname (IS-IS) or IPv4 address in dot decimal format (OSPF)
         */
    if (na.getDynamicHostname() != null) {
        builder.setName(na.getDynamicHostname());
    } else {
        int key = id.intValue();
        builder.setName((key << 24 & 0xFF) + "." + (key << 16 & 0xFF) + "." + (key << 8 & 0xFF) + "." + (key & 0xFF));
    }
    if (na.getSrCapabilities() != null) {
        final SidLabelIndex labelIndex = na.getSrCapabilities().getSidLabelIndex();
        if (labelIndex instanceof LocalLabelCase) {
            builder.setSrgb(new SrgbBuilder().setLowerBound(((LocalLabelCase) labelIndex).getLocalLabel().getValue()).setRangeSize(na.getSrCapabilities().getRangeSize().getValue()).build());
        } else if (labelIndex instanceof SidCase) {
            builder.setSrgb(new SrgbBuilder().setLowerBound(((SidCase) labelIndex).getSid()).setRangeSize(na.getSrCapabilities().getRangeSize().getValue()).build());
        }
    }
    if (na.getNodeFlags() != null) {
        if (na.getNodeFlags().getAbr()) {
            builder.setVertexType(VertexType.Abr);
        }
        if (na.getNodeFlags().getExternal()) {
            builder.setVertexType(VertexType.AsbrOut);
        }
    } else {
        builder.setVertexType(VertexType.Standard);
    }
    return builder.build();
}
Also used : SrgbBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.vertex.SrgbBuilder) VertexBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexBuilder) LocalLabelCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase) SidLabelIndex(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.SidLabelIndex) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) SidCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCase)

Aggregations

ConnectedVertex (org.opendaylight.graph.ConnectedVertex)5 ConnectedEdge (org.opendaylight.graph.ConnectedEdge)4 ConstrainedPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder)4 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)4 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)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 Vertex (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Vertex)3 SidCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCase)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 Ipv4Case (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case)2 Ipv6Case (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv6Case)2 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 LinkStateAttribute (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute)1 PrefixAttributesCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase)1 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)1 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)1 PrefixAttributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes)1