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();
}
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());
}
}
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());
}
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());
}
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;
}
});
}
}
Aggregations