Search in sources :

Example 6 with TopologyVertex

use of org.onosproject.net.topology.TopologyVertex in project onos by opennetworkinglab.

the class DefaultTopology method getPaths.

/**
 * Computes on-demand the set of shortest paths between source and
 * destination devices, the set of returned paths will be no more than,
 * maxPaths in size.  The first {@code maxPaths} paths will be returned
 * maintaining any ordering guarantees provided by the underlying
 * (default or if no default is specified {@link DijkstraGraphSearch})
 * search. If returning all paths of a given length would exceed
 * {@code maxPaths} a subset of paths of that length will be returned,
 * which paths will be returned depends on the currently specified
 * {@code GraphPathSearch}. See {@link #setDefaultGraphPathSearch}.
 *
 * @param src      source device
 * @param dst      destination device
 * @param weigher  link weight function
 * @param maxPaths maximum number of paths
 * @return set of shortest paths
 */
public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeigher weigher, int maxPaths) {
    DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }
    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = graphPathSearch().search(graph, srcV, dstV, weigher, maxPaths);
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkPath(path));
    }
    return builder.build();
}
Also used : DefaultDisjointPath(org.onosproject.net.DefaultDisjointPath) Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DisjointPath(org.onosproject.net.DisjointPath) DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyEdge(org.onosproject.net.topology.TopologyEdge) GraphPathSearch(org.onlab.graph.GraphPathSearch)

Example 7 with TopologyVertex

use of org.onosproject.net.topology.TopologyVertex in project onos by opennetworkinglab.

the class DefaultTopology method addClusterBroadcastSet.

// Finds all broadcast points for the cluster. These are those connection
// points which lie along the shortest paths between the cluster root and
// all other devices within the cluster.
private void addClusterBroadcastSet(TopologyCluster cluster, Builder<ClusterId, ConnectPoint> builder) {
    // Use the graph root search results to build the broadcast set.
    Result<TopologyVertex, TopologyEdge> result = DIJKSTRA.search(graph, cluster.root(), null, hopCountWeigher, 1);
    for (Map.Entry<TopologyVertex, Set<TopologyEdge>> entry : result.parents().entrySet()) {
        TopologyVertex vertex = entry.getKey();
        // Ignore any parents that lead outside the cluster.
        if (clustersByDevice().get(vertex.deviceId()) != cluster) {
            continue;
        }
        // Ignore any back-link sets that are empty.
        Set<TopologyEdge> parents = entry.getValue();
        if (parents.isEmpty()) {
            continue;
        }
        // Use the first back-link source and destinations to add to the
        // broadcast set.
        Link link = parents.iterator().next().link();
        builder.put(cluster.id(), link.src());
        builder.put(cluster.id(), link.dst());
    }
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TopologyEdge(org.onosproject.net.topology.TopologyEdge) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Link(org.onosproject.net.Link)

Example 8 with TopologyVertex

use of org.onosproject.net.topology.TopologyVertex in project onos by opennetworkinglab.

the class DefaultTopology method getKShortestPaths.

/**
 * Computes on-demand the k-shortest paths between source and
 * destination devices.
 * <p>
 * The first {@code maxPaths} paths will be returned
 * in ascending order according to the provided {@code weigher}
 *
 * @param src      source device
 * @param dst      destination device
 * @param weigher  link weight function
 * @param maxPaths maximum number of paths (k)
 * @return set of k-shortest paths
 */
public Set<Path> getKShortestPaths(DeviceId src, DeviceId dst, LinkWeigher weigher, int maxPaths) {
    DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }
    return KSHORTEST.search(graph, srcV, dstV, weigher, maxPaths).paths().stream().map(this::networkPath).collect(ImmutableSet.toImmutableSet());
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex)

Example 9 with TopologyVertex

use of org.onosproject.net.topology.TopologyVertex in project onos by opennetworkinglab.

the class DefaultTopology method buildIndexes.

// Builds cluster-devices, cluster-links and device-cluster indexes.
private ClusterIndexes buildIndexes() {
    // Prepare the index builders
    ImmutableMap.Builder<DeviceId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
    ImmutableSetMultimap.Builder<TopologyCluster, DeviceId> devicesBuilder = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<TopologyCluster, Link> linksBuilder = ImmutableSetMultimap.builder();
    // Now scan through all the clusters
    for (TopologyCluster cluster : clusters.get().values()) {
        int i = cluster.id().index();
        // Scan through all the cluster vertexes.
        for (TopologyVertex vertex : clusterResults.get().clusterVertexes().get(i)) {
            devicesBuilder.put(cluster, vertex.deviceId());
            clusterBuilder.put(vertex.deviceId(), cluster);
        }
        // Scan through all the cluster edges.
        for (TopologyEdge edge : clusterResults.get().clusterEdges().get(i)) {
            linksBuilder.put(cluster, edge.link());
        }
    }
    // Finalize all indexes.
    return new ClusterIndexes(clusterBuilder.build(), devicesBuilder.build(), linksBuilder.build());
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) DeviceId(org.onosproject.net.DeviceId) TopologyCluster(org.onosproject.net.topology.TopologyCluster) DefaultTopologyCluster(org.onosproject.net.topology.DefaultTopologyCluster) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ImmutableMap(com.google.common.collect.ImmutableMap) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 10 with TopologyVertex

use of org.onosproject.net.topology.TopologyVertex in project onos by opennetworkinglab.

the class MockLinkService method addLink.

public void addLink(String device, long port, String device2, long port2) {
    ElementId d1;
    if (device.charAt(0) == 'H') {
        device = device.substring(1, device.length());
        d1 = HostId.hostId(device);
    } else {
        d1 = DeviceId.deviceId(device);
    }
    ElementId d2;
    if (device2.charAt(0) == 'H') {
        d2 = HostId.hostId(device2.substring(1, device2.length()));
    } else {
        d2 = DeviceId.deviceId(device2);
    }
    ConnectPoint src = new ConnectPoint(d1, PortNumber.portNumber(port));
    ConnectPoint dst = new ConnectPoint(d2, PortNumber.portNumber(port2));
    Link curLink;
    curLink = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).build();
    links.add(curLink);
    if (d1 instanceof DeviceId && d2 instanceof DeviceId) {
        TopologyVertex v1 = () -> (DeviceId) d1, v2 = () -> (DeviceId) d2;
        createdGraph.addVertex(v1);
        createdGraph.addVertex(v2);
        createdGraph.addEdge(new TopologyEdge() {

            @Override
            public Link link() {
                return curLink;
            }

            @Override
            public TopologyVertex src() {
                return v1;
            }

            @Override
            public TopologyVertex dst() {
                return v2;
            }
        });
    }
}
Also used : TopologyVertex(org.onosproject.net.topology.TopologyVertex) DeviceId(org.onosproject.net.DeviceId) ConnectPoint(org.onosproject.net.ConnectPoint) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ElementId(org.onosproject.net.ElementId) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link)

Aggregations

TopologyVertex (org.onosproject.net.topology.TopologyVertex)10 DefaultTopologyVertex (org.onosproject.net.topology.DefaultTopologyVertex)8 TopologyEdge (org.onosproject.net.topology.TopologyEdge)7 ImmutableSet (com.google.common.collect.ImmutableSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 GraphPathSearch (org.onlab.graph.GraphPathSearch)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultDisjointPath (org.onosproject.net.DefaultDisjointPath)3 DeviceId (org.onosproject.net.DeviceId)3 DisjointPath (org.onosproject.net.DisjointPath)3 Link (org.onosproject.net.Link)3 Set (java.util.Set)2 DefaultTopologyCluster (org.onosproject.net.topology.DefaultTopologyCluster)2 TopologyCluster (org.onosproject.net.topology.TopologyCluster)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SrlgGraphSearch (org.onlab.graph.SrlgGraphSearch)1 DefaultLink (org.onosproject.net.DefaultLink)1