Ayaka Koshibe

added Host-related unit tests

Change-Id: Ia3c0610f5bdd91ddd554dd477af7ad3640a6cef3
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());
}
}
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();
}
......
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);
}
......@@ -57,7 +57,7 @@ public class IPAddress {
* @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 @@ public class IPAddress {
return true;
}
if (obj instanceof IPAddress) {
IPAddress other = (IPAddress) obj;
if (!(this.version.equals(other.version))) {
return false;
}
......
......@@ -37,13 +37,13 @@ public class VLANID {
}
if (obj instanceof VLANID) {
return true;
}
VLANID other = (VLANID) obj;
if (this.value == other.value) {
return true;
}
}
return false;
}
......