Fix for [ONOS-3590]
Compare two devices instead of one with itself
Add unit test for root node
Change-Id: If109dd8b05cd77825e182399b321c321865b9786
diff --git a/core/common/src/main/java/org/onosproject/common/DefaultTopology.java b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
index 5b161ff..a2bc4a5 100644
--- a/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
+++ b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
@@ -519,7 +519,7 @@
private TopologyVertex findRoot(Set<TopologyVertex> vertexSet) {
TopologyVertex minVertex = null;
for (TopologyVertex vertex : vertexSet) {
- if ((minVertex == null) || (minVertex.deviceId()
+ if ((minVertex == null) || (vertex.deviceId()
.toString().compareTo(minVertex.deviceId().toString()) < 0)) {
minVertex = vertex;
}
diff --git a/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java b/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
index e7dcd90..2bf8cb7 100644
--- a/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
+++ b/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
@@ -29,9 +29,11 @@
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.topology.ClusterId;
import org.onosproject.net.topology.DefaultGraphDescription;
+import org.onosproject.net.topology.DefaultTopologyVertex;
import org.onosproject.net.topology.GraphDescription;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.TopologyCluster;
+import org.onosproject.net.topology.TopologyVertex;
import java.util.Set;
@@ -53,6 +55,9 @@
public static final DeviceId D4 = deviceId("of:4");
public static final DeviceId D5 = deviceId("of:5");
+ public static final TopologyVertex V1 = new DefaultTopologyVertex(D1);
+ public static final TopologyVertex V5 = new DefaultTopologyVertex(D5);
+
public static final PortNumber P1 = portNumber(1);
public static final PortNumber P2 = portNumber(2);
@@ -62,6 +67,9 @@
private DefaultTopology dt;
+ public static final ClusterId C0 = ClusterId.clusterId(0);
+ public static final ClusterId C1 = ClusterId.clusterId(1);
+
@Before
public void setUp() {
long now = System.currentTimeMillis();
@@ -81,8 +89,9 @@
assertEquals("incorrect device count", 5, dt.deviceCount());
assertEquals("incorrect link count", 8, dt.linkCount());
assertEquals("incorrect cluster count", 2, dt.clusterCount());
- assertEquals("incorrect broadcast set size", 6,
- dt.broadcastSetSize(ClusterId.clusterId(0)));
+ assertEquals("incorrect broadcast set size", 6, dt.broadcastSetSize(C0));
+ assertEquals("incorrect root node", V1, dt.getCluster(C0).root());
+ assertEquals("incorrect root node", V5, dt.getCluster(C1).root());
}
@Test