use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class ClustersListCommand method doExecute.
@Override
protected void doExecute() {
init();
List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
Collections.sort(clusters, Comparators.CLUSTER_COMPARATOR);
if (outputJson()) {
print("%s", json(clusters));
} else {
for (TopologyCluster cluster : clusters) {
print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
}
}
}
use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class DefaultTopology method isBroadcastPoint.
/**
* Indicates whether the given point is part of a broadcast set.
*
* @param connectPoint connection point
* @return true if in broadcast set
*/
public boolean isBroadcastPoint(ConnectPoint connectPoint) {
if (broadcastFunction != null) {
return broadcastFunction.apply(connectPoint);
}
// Any non-infrastructure, i.e. edge points are assumed to be OK.
if (!isInfrastructure(connectPoint)) {
return true;
}
// Find the cluster to which the device belongs.
TopologyCluster cluster = clustersByDevice().get(connectPoint.deviceId());
checkArgument(cluster != null, "No cluster found for device %s", connectPoint.deviceId());
// If the broadcast set is null or empty, or if the point explicitly
// belongs to it, return true.
Set<ConnectPoint> points = broadcastSets.get().get(cluster.id());
return isNullOrEmpty(points) || points.contains(connectPoint);
}
use of org.onosproject.net.topology.TopologyCluster 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.TopologyCluster in project onos by opennetworkinglab.
the class VirtualNetworkTopologyManagerTest method testGetClusterLinksUsingNullCluster.
/**
* Test getClusterLinks() methods with a null cluster.
*/
@Test(expected = NullPointerException.class)
public void testGetClusterLinksUsingNullCluster() {
VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
Topology topology = topologyService.currentTopology();
Set<TopologyCluster> clusters = topologyService.getClusters(topology);
// test the getClusterLinks() method using a null cluster.
Object[] objects = clusters.stream().toArray();
assertNotNull("The cluster should not be null.", objects);
Set<Link> clusterLinks = topologyService.getClusterLinks(topology, null);
}
use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class VirtualNetworkTopologyManagerTest method testGetClusterDevicesLinks.
/**
* Test getClusterDevices() and getClusterLinks() methods.
*/
@Test
public void testGetClusterDevicesLinks() {
VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
Topology topology = topologyService.currentTopology();
Set<TopologyCluster> clusters = topologyService.getClusters(topology);
assertNotNull("The clusters should not be null.", clusters);
assertEquals("The clusters size did not match.", 2, clusters.size());
// test the getClusterDevices() method.
Object[] objects = clusters.stream().toArray();
assertNotNull("The cluster should not be null.", objects);
Set<DeviceId> clusterDevices = topologyService.getClusterDevices(topology, (TopologyCluster) objects[0]);
assertNotNull("The devices should not be null.", clusterDevices);
assertEquals("The devices size did not match.", 3, clusterDevices.size());
Set<DeviceId> clusterDevices1 = topologyService.getClusterDevices(topology, (TopologyCluster) objects[1]);
assertNotNull("The devices should not be null.", clusterDevices1);
assertEquals("The devices size did not match.", 1, clusterDevices1.size());
// test the getClusterLinks() method.
Set<Link> clusterLinks = topologyService.getClusterLinks(topology, (TopologyCluster) objects[0]);
assertNotNull("The links should not be null.", clusterLinks);
assertEquals("The links size did not match.", 6, clusterLinks.size());
Set<Link> clusterLinks1 = topologyService.getClusterLinks(topology, (TopologyCluster) objects[1]);
assertNotNull("The links should not be null.", clusterLinks1);
assertEquals("The links size did not match.", 0, clusterLinks1.size());
}
Aggregations