Refactoring to eliminate duplicate DefaultTopology and DefaultTopologyGraph; eliminating a few fixmes.
Change-Id: I4461b6f1c8ae60d39f5da909bf6995294cbfa84d
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/DefaultTopology.java b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
similarity index 88%
rename from core/common/src/test/java/org/onosproject/store/trivial/DefaultTopology.java
rename to core/common/src/main/java/org/onosproject/common/DefaultTopology.java
index 9f436b6..51857c7 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/DefaultTopology.java
+++ b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
@@ -13,20 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.store.trivial;
+package org.onosproject.common;
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
-import static org.onosproject.core.CoreService.CORE_PROVIDER_ID;
-import static org.onosproject.net.Link.State.ACTIVE;
-import static org.onosproject.net.Link.State.INACTIVE;
-import static org.onosproject.net.Link.Type.INDIRECT;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.ImmutableSetMultimap.Builder;
import org.onlab.graph.DijkstraGraphSearch;
import org.onlab.graph.GraphPathSearch;
import org.onlab.graph.GraphPathSearch.Result;
@@ -50,14 +44,18 @@
import org.onosproject.net.topology.TopologyGraph;
import org.onosproject.net.topology.TopologyVertex;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.ImmutableSetMultimap.Builder;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
-// FIXME: Move to onos-core-common when ready
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
+import static org.onosproject.core.CoreService.CORE_PROVIDER_ID;
+import static org.onosproject.net.Link.State.ACTIVE;
+import static org.onosproject.net.Link.State.INACTIVE;
+import static org.onosproject.net.Link.Type.INDIRECT;
+
/**
* Default implementation of the topology descriptor. This carries the backing
* topology data.
@@ -83,19 +81,17 @@
/**
* Creates a topology descriptor attributed to the specified provider.
*
- * @param providerId
- * identity of the provider
- * @param description
- * data describing the new topology
+ * @param providerId identity of the provider
+ * @param description data describing the new topology
*/
- DefaultTopology(ProviderId providerId, GraphDescription description) {
+ public DefaultTopology(ProviderId providerId, GraphDescription description) {
super(providerId);
this.time = description.timestamp();
this.creationTime = description.creationTime();
// Build the graph
this.graph = new DefaultTopologyGraph(description.vertexes(),
- description.edges());
+ description.edges());
this.clusterResults = Suppliers.memoize(() -> searchForClusters());
this.clusters = Suppliers.memoize(() -> buildTopologyClusters());
@@ -104,8 +100,7 @@
this.weight = new HopCountLinkWeight(graph.getVertexes().size());
this.broadcastSets = Suppliers.memoize(() -> buildBroadcastSets());
- this.infrastructurePoints = Suppliers
- .memoize(() -> findInfrastructurePoints());
+ this.infrastructurePoints = Suppliers.memoize(() -> findInfrastructurePoints());
this.computeCost = Math.max(0, System.nanoTime() - time);
}
@@ -156,7 +151,7 @@
*
* @return topology graph
*/
- TopologyGraph getGraph() {
+ public TopologyGraph getGraph() {
return graph;
}
@@ -165,7 +160,7 @@
*
* @return set of clusters
*/
- Set<TopologyCluster> getClusters() {
+ public Set<TopologyCluster> getClusters() {
return ImmutableSet.copyOf(clusters.get().values());
}
@@ -173,10 +168,9 @@
* Returns the specified topology cluster.
*
* @param clusterId cluster identifier
- *
* @return topology cluster
*/
- TopologyCluster getCluster(ClusterId clusterId) {
+ public TopologyCluster getCluster(ClusterId clusterId) {
return clusters.get().get(clusterId);
}
@@ -184,10 +178,9 @@
* Returns the topology cluster that contains the given device.
*
* @param deviceId device identifier
- *
* @return topology cluster
*/
- TopologyCluster getCluster(DeviceId deviceId) {
+ public TopologyCluster getCluster(DeviceId deviceId) {
return clustersByDevice().get(deviceId);
}
@@ -195,10 +188,9 @@
* Returns the set of cluster devices.
*
* @param cluster topology cluster
- *
* @return cluster devices
*/
- Set<DeviceId> getClusterDevices(TopologyCluster cluster) {
+ public Set<DeviceId> getClusterDevices(TopologyCluster cluster) {
return devicesByCluster().get(cluster);
}
@@ -206,10 +198,9 @@
* Returns the set of cluster links.
*
* @param cluster topology cluster
- *
* @return cluster links
*/
- Set<Link> getClusterLinks(TopologyCluster cluster) {
+ public Set<Link> getClusterLinks(TopologyCluster cluster) {
return linksByCluster().get(cluster);
}
@@ -217,10 +208,9 @@
* Indicates whether the given point is an infrastructure link end-point.
*
* @param connectPoint connection point
- *
* @return true if infrastructure
*/
- boolean isInfrastructure(ConnectPoint connectPoint) {
+ public boolean isInfrastructure(ConnectPoint connectPoint) {
return infrastructurePoints.get().contains(connectPoint);
}
@@ -228,10 +218,9 @@
* Indicates whether the given point is part of a broadcast set.
*
* @param connectPoint connection point
- *
* @return true if in broadcast set
*/
- boolean isBroadcastPoint(ConnectPoint connectPoint) {
+ public boolean isBroadcastPoint(ConnectPoint connectPoint) {
// Any non-infrastructure, i.e. edge points are assumed to be OK.
if (!isInfrastructure(connectPoint)) {
return true;
@@ -241,7 +230,7 @@
TopologyCluster cluster = clustersByDevice().get(connectPoint.deviceId());
if (cluster == null) {
throw new IllegalArgumentException("No cluster found for device "
- + connectPoint.deviceId());
+ + connectPoint.deviceId());
}
// If the broadcast set is null or empty, or if the point explicitly
@@ -254,10 +243,9 @@
* Returns the size of the cluster broadcast set.
*
* @param clusterId cluster identifier
- *
* @return size of the cluster broadcast set
*/
- int broadcastSetSize(ClusterId clusterId) {
+ public int broadcastSetSize(ClusterId clusterId) {
return broadcastSets.get().get(clusterId).size();
}
@@ -266,12 +254,10 @@
* destination devices.
*
* @param src source device
- *
* @param dst destination device
- *
* @return set of shortest paths
*/
- Set<Path> getPaths(DeviceId src, DeviceId dst) {
+ public Set<Path> getPaths(DeviceId src, DeviceId dst) {
return getPaths(src, dst, null);
}
@@ -279,15 +265,12 @@
* Computes on-demand the set of shortest paths between source and
* destination devices.
*
- * @param src source device
- *
- * @param dst destination device
- *
+ * @param src source device
+ * @param dst destination device
* @param weight link weight function
- *
* @return set of shortest paths
*/
- Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
+ public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
Set<TopologyVertex> vertices = graph.getVertexes();
@@ -349,8 +332,8 @@
private TopologyVertex findRoot(Set<TopologyVertex> vertexSet) {
TopologyVertex minVertex = null;
for (TopologyVertex vertex : vertexSet) {
- if ((minVertex == null) || (minVertex.deviceId().toString()
- .compareTo(minVertex.deviceId().toString()) < 0)) {
+ if ((minVertex == null) || (minVertex.deviceId()
+ .toString().compareTo(minVertex.deviceId().toString()) < 0)) {
minVertex = vertex;
}
}
@@ -359,7 +342,8 @@
// Processes a map of broadcast sets for each cluster.
private ImmutableSetMultimap<ClusterId, ConnectPoint> buildBroadcastSets() {
- Builder<ClusterId, ConnectPoint> builder = ImmutableSetMultimap.builder();
+ Builder<ClusterId, ConnectPoint> builder = ImmutableSetMultimap
+ .builder();
for (TopologyCluster cluster : clusters.get().values()) {
addClusterBroadcastSet(cluster, builder);
}
@@ -371,8 +355,7 @@
// 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, weight, 1);
+ Result<TopologyVertex, TopologyEdge> result = DIJKSTRA.search(graph, cluster.root(), null, weight, 1);
for (Map.Entry<TopologyVertex, Set<TopologyEdge>> entry : result.parents().entrySet()) {
TopologyVertex vertex = entry.getKey();
@@ -433,7 +416,8 @@
// Finalize all indexes.
return new ClusterIndexes(clusterBuilder.build(),
- devicesBuilder.build(), linksBuilder.build());
+ devicesBuilder.build(),
+ linksBuilder.build());
}
// Link weight for measuring link cost as hop count with indirect links
@@ -469,10 +453,9 @@
final ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster;
final ImmutableSetMultimap<TopologyCluster, Link> linksByCluster;
- public ClusterIndexes(
- ImmutableMap<DeviceId, TopologyCluster> clustersByDevice,
- ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster,
- ImmutableSetMultimap<TopologyCluster, Link> linksByCluster) {
+ public ClusterIndexes(ImmutableMap<DeviceId, TopologyCluster> clustersByDevice,
+ ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster,
+ ImmutableSetMultimap<TopologyCluster, Link> linksByCluster) {
this.clustersByDevice = clustersByDevice;
this.devicesByCluster = devicesByCluster;
this.linksByCluster = linksByCluster;
@@ -483,7 +466,7 @@
public String toString() {
return toStringHelper(this)
.add("time", time)
- .add("created", creationTime)
+ .add("creationTime", creationTime)
.add("computeCost", computeCost)
.add("clusters", clusterCount())
.add("devices", deviceCount())
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/DefaultTopologyGraph.java b/core/common/src/main/java/org/onosproject/common/DefaultTopologyGraph.java
similarity index 96%
rename from core/common/src/test/java/org/onosproject/store/trivial/DefaultTopologyGraph.java
rename to core/common/src/main/java/org/onosproject/common/DefaultTopologyGraph.java
index 610d724..b06065e 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/DefaultTopologyGraph.java
+++ b/core/common/src/main/java/org/onosproject/common/DefaultTopologyGraph.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.store.trivial;
+package org.onosproject.common;
import org.onlab.graph.AdjacencyListsGraph;
import org.onosproject.net.topology.TopologyEdge;
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/DefaultTopologyTest.java b/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
similarity index 98%
rename from core/common/src/test/java/org/onosproject/store/trivial/DefaultTopologyTest.java
rename to core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
index 3ff340a..4d435cf 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/DefaultTopologyTest.java
+++ b/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.store.trivial;
+package org.onosproject.common;
import org.junit.Before;
import org.junit.Test;
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/SimpleTopologyStore.java b/core/common/src/test/java/org/onosproject/store/trivial/SimpleTopologyStore.java
index cd564f0..6a89c01 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/SimpleTopologyStore.java
+++ b/core/common/src/test/java/org/onosproject/store/trivial/SimpleTopologyStore.java
@@ -19,6 +19,7 @@
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
+import org.onosproject.common.DefaultTopology;
import org.onosproject.event.Event;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;