Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

This commit is contained in:
alshabib 2014-09-12 17:59:42 -07:00
commit c114d3d081
5 changed files with 97 additions and 10 deletions

View File

@ -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());
}
}

View File

@ -1,21 +1,30 @@
package org.onlab.onos.net; package org.onlab.onos.net;
import com.google.common.testing.EqualsTester; import com.google.common.testing.EqualsTester;
import org.junit.Test; import org.junit.Test;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import static org.onlab.onos.net.HostId.hostId; import static org.onlab.onos.net.HostId.hostId;
/** /**
* Test of the host identifier. * Test for the host identifier.
*/ */
public class HostIdTest extends ElementIdTest { 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 @Test
public void basics() { public void basics() {
new EqualsTester() new EqualsTester()
.addEqualityGroup(hostId("nic:foo"), .addEqualityGroup(hostId("nic:00:11:00:00:00:01/11"),
hostId("nic:foo")) hostId(MAC1, VLAN1))
.addEqualityGroup(hostId("nic:bar")) .addEqualityGroup(hostId(MAC2, VLAN2))
.testEquals(); .testEquals();
} }

View File

@ -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);
}

View File

@ -57,7 +57,7 @@ public class IPAddress {
* @return an IP address * @return an IP address
*/ */
public static IPAddress valueOf(String address) { public static IPAddress valueOf(String address) {
final String [] parts = address.split("."); final String [] parts = address.split("\\.");
if (parts.length != INET_LEN) { if (parts.length != INET_LEN) {
throw new IllegalArgumentException("Malformed IP address string; " throw new IllegalArgumentException("Malformed IP address string; "
+ "Addres must have four decimal values separated by dots (.)"); + "Addres must have four decimal values separated by dots (.)");
@ -119,7 +119,9 @@ public class IPAddress {
return true; return true;
} }
if (obj instanceof IPAddress) { if (obj instanceof IPAddress) {
IPAddress other = (IPAddress) obj; IPAddress other = (IPAddress) obj;
if (!(this.version.equals(other.version))) { if (!(this.version.equals(other.version))) {
return false; return false;
} }

View File

@ -37,12 +37,12 @@ public class VLANID {
} }
if (obj instanceof VLANID) { if (obj instanceof VLANID) {
return true;
}
VLANID other = (VLANID) obj; VLANID other = (VLANID) obj;
if (this.value == other.value) {
return true; if (this.value == other.value) {
return true;
}
} }
return false; return false;