Ayaka Koshibe

Tests for HostDescriptions and Events

Change-Id: I0b9f164b4d71ca5df80855ba22b9b8fdff27fcdf
package org.onlab.onos.net.host;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import org.junit.Test;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.HostLocation;
import org.onlab.onos.net.PortNumber;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import com.google.common.collect.Sets;
/**
* Test for the default host description.
*/
public class DefualtHostDecriptionTest {
private static final MACAddress MAC = MACAddress.valueOf("00:00:11:00:00:01");
private static final VLANID VLAN = VLANID.vlanId((short) 10);
private static final HostLocation LOC = new HostLocation(
DeviceId.deviceId("of:foo"),
PortNumber.portNumber(100),
123L
);
private static final Set<IPAddress> IPS = Sets.newHashSet(
IPAddress.valueOf("10.0.0.1"),
IPAddress.valueOf("10.0.0.2")
);
@Test
public void basics() {
HostDescription host =
new DefaultHostDescription(MAC, VLAN, LOC, IPS);
assertEquals("incorrect mac", MAC, host.hwAddress());
assertEquals("incorrect vlan", VLAN, host.vlan());
assertEquals("incorrect location", LOC, host.location());
assertTrue("incorrect ip's", IPS.equals(host.ipAddresses()));
assertTrue("incorrect toString", host.toString().contains("vlan=10"));
}
}
package org.onlab.onos.net.host;
import java.util.Set;
import org.junit.Test;
import org.onlab.onos.event.AbstractEventTest;
import org.onlab.onos.net.DefaultHost;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.HostLocation;
import org.onlab.onos.net.PortNumber;
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;
public class HostEventTest extends AbstractEventTest {
private Host createHost() {
MACAddress mac = MACAddress.valueOf("00:00:11:00:00:01");
VLANID vlan = VLANID.vlanId((short) 10);
HostLocation loc = new HostLocation(
DeviceId.deviceId("of:foo"),
PortNumber.portNumber(100),
123L
);
Set<IPAddress> ipset = Sets.newHashSet(
IPAddress.valueOf("10.0.0.1"),
IPAddress.valueOf("10.0.0.2")
);
HostId hid = HostId.hostId(mac, vlan);
return new DefaultHost(
new ProviderId("foo"), hid, mac, vlan, loc, ipset);
}
@Override
@Test
public void withTime() {
Host host = createHost();
HostEvent event = new HostEvent(HostEvent.Type.HOST_ADDED, host, 123L);
validateEvent(event, HostEvent.Type.HOST_ADDED, host, 123L);
}
@Override
@Test
public void withoutTime() {
Host host = createHost();
long before = System.currentTimeMillis();
HostEvent event = new HostEvent(HostEvent.Type.HOST_ADDED, host, before);
long after = System.currentTimeMillis();
validateEvent(event, HostEvent.Type.HOST_ADDED, host, before, after);
}
}