Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/core/api/src/test/java/org/onlab/onos/net/DefaultHostTest.java b/core/api/src/test/java/org/onlab/onos/net/DefaultHostTest.java
new file mode 100644
index 0000000..4f23231
--- /dev/null
+++ b/core/api/src/test/java/org/onlab/onos/net/DefaultHostTest.java
@@ -0,0 +1,36 @@
+package org.onlab.onos.net;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+public class DefaultHostTest extends TestDeviceParams {
+
+ @Test
+ public void testEquality() {
+ Host h1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, IPSET1);
+ Host h2 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, IPSET1);
+ Host h3 = new DefaultHost(PID, HID2, MAC2, VLAN2, LOC2, IPSET2);
+ Host h4 = new DefaultHost(PID, HID2, MAC2, VLAN2, LOC2, IPSET2);
+ Host h5 = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC2, IPSET1);
+
+ new EqualsTester().addEqualityGroup(h1, h2)
+ .addEqualityGroup(h3, h4)
+ .addEqualityGroup(h5)
+ .testEquals();
+ }
+
+ @Test
+ public void basics() {
+ Host host = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, IPSET1);
+ assertEquals("incorrect provider", PID, host.providerId());
+ assertEquals("incorrect id", HID1, host.id());
+ assertEquals("incorrect type", MAC1, host.mac());
+ assertEquals("incorrect VLAN", VLAN1, host.vlan());
+ assertEquals("incorrect location", LOC1, host.location());
+ assertEquals("incorrect IP's", IPSET1, host.ipAddresses());
+ }
+
+}
diff --git a/core/api/src/test/java/org/onlab/onos/net/HostIdTest.java b/core/api/src/test/java/org/onlab/onos/net/HostIdTest.java
index 3adcabc..fefc499 100644
--- a/core/api/src/test/java/org/onlab/onos/net/HostIdTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/HostIdTest.java
@@ -1,21 +1,30 @@
package org.onlab.onos.net;
import com.google.common.testing.EqualsTester;
+
import org.junit.Test;
+import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
import static org.onlab.onos.net.HostId.hostId;
/**
- * Test of the host identifier.
+ * Test for the host identifier.
*/
public class HostIdTest extends ElementIdTest {
+ private static final MACAddress MAC1 = MACAddress.valueOf("00:11:00:00:00:01");
+ private static final MACAddress MAC2 = MACAddress.valueOf("00:22:00:00:00:02");
+ private static final VLANID VLAN1 = VLANID.vlanId((short) 11);
+ private static final VLANID VLAN2 = VLANID.vlanId((short) 22);
+
+ @Override
@Test
public void basics() {
new EqualsTester()
- .addEqualityGroup(hostId("nic:foo"),
- hostId("nic:foo"))
- .addEqualityGroup(hostId("nic:bar"))
+ .addEqualityGroup(hostId("nic:00:11:00:00:00:01/11"),
+ hostId(MAC1, VLAN1))
+ .addEqualityGroup(hostId(MAC2, VLAN2))
.testEquals();
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/TestDeviceParams.java b/core/api/src/test/java/org/onlab/onos/net/TestDeviceParams.java
new file mode 100644
index 0000000..930cb3b
--- /dev/null
+++ b/core/api/src/test/java/org/onlab/onos/net/TestDeviceParams.java
@@ -0,0 +1,40 @@
+package org.onlab.onos.net;
+
+import static org.onlab.onos.net.DeviceId.deviceId;
+
+import java.util.Set;
+
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.packet.IPAddress;
+import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Provides a set of test DefaultDevice parameters for use with Host-
+ * related tests.
+ */
+public abstract class TestDeviceParams {
+
+ protected static final ProviderId PID = new ProviderId("foo");
+ protected static final DeviceId DID1 = deviceId("of:foo");
+ protected static final DeviceId DID2 = deviceId("of:bar");
+ protected static final MACAddress MAC1 = MACAddress.valueOf("00:11:00:00:00:01");
+ protected static final MACAddress MAC2 = MACAddress.valueOf("00:22:00:00:00:02");
+ protected static final VLANID VLAN1 = VLANID.vlanId((short) 11);
+ protected static final VLANID VLAN2 = VLANID.vlanId((short) 22);
+ protected static final IPAddress IP1 = IPAddress.valueOf("10.0.0.1");
+ protected static final IPAddress IP2 = IPAddress.valueOf("10.0.0.2");
+ protected static final IPAddress IP3 = IPAddress.valueOf("10.0.0.3");
+
+ protected static final PortNumber P1 = PortNumber.portNumber(100);
+ protected static final PortNumber P2 = PortNumber.portNumber(200);
+ protected static final HostId HID1 = HostId.hostId(MAC1, VLAN1);
+ protected static final HostId HID2 = HostId.hostId(MAC2, VLAN2);
+ protected static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L);
+ protected static final HostLocation LOC2 = new HostLocation(DID2, P2, 123L);
+ protected static final Set<IPAddress> IPSET1 = Sets.newHashSet(IP1, IP2);
+ protected static final Set<IPAddress> IPSET2 = Sets.newHashSet(IP1, IP3);
+
+}
diff --git a/utils/misc/src/main/java/org/onlab/packet/IPAddress.java b/utils/misc/src/main/java/org/onlab/packet/IPAddress.java
index 94c2d54..4e898f4 100644
--- a/utils/misc/src/main/java/org/onlab/packet/IPAddress.java
+++ b/utils/misc/src/main/java/org/onlab/packet/IPAddress.java
@@ -57,7 +57,7 @@
* @return an IP address
*/
public static IPAddress valueOf(String address) {
- final String [] parts = address.split(".");
+ final String [] parts = address.split("\\.");
if (parts.length != INET_LEN) {
throw new IllegalArgumentException("Malformed IP address string; "
+ "Addres must have four decimal values separated by dots (.)");
@@ -119,7 +119,9 @@
return true;
}
if (obj instanceof IPAddress) {
+
IPAddress other = (IPAddress) obj;
+
if (!(this.version.equals(other.version))) {
return false;
}
diff --git a/utils/misc/src/main/java/org/onlab/packet/VLANID.java b/utils/misc/src/main/java/org/onlab/packet/VLANID.java
index 31cdecb..5b26d04 100644
--- a/utils/misc/src/main/java/org/onlab/packet/VLANID.java
+++ b/utils/misc/src/main/java/org/onlab/packet/VLANID.java
@@ -37,12 +37,12 @@
}
if (obj instanceof VLANID) {
- return true;
- }
- VLANID other = (VLANID) obj;
- if (this.value == other.value) {
- return true;
+ VLANID other = (VLANID) obj;
+
+ if (this.value == other.value) {
+ return true;
+ }
}
return false;