Tests for HostDescriptions and Events
Change-Id: I0b9f164b4d71ca5df80855ba22b9b8fdff27fcdf
Showing
2 changed files
with
103 additions
and
0 deletions
1 | +package org.onlab.onos.net.host; | ||
2 | + | ||
3 | +import static org.junit.Assert.assertEquals; | ||
4 | +import static org.junit.Assert.assertTrue; | ||
5 | + | ||
6 | +import java.util.Set; | ||
7 | + | ||
8 | +import org.junit.Test; | ||
9 | +import org.onlab.onos.net.DeviceId; | ||
10 | +import org.onlab.onos.net.HostLocation; | ||
11 | +import org.onlab.onos.net.PortNumber; | ||
12 | +import org.onlab.packet.IPAddress; | ||
13 | +import org.onlab.packet.MACAddress; | ||
14 | +import org.onlab.packet.VLANID; | ||
15 | + | ||
16 | +import com.google.common.collect.Sets; | ||
17 | + | ||
18 | +/** | ||
19 | + * Test for the default host description. | ||
20 | + */ | ||
21 | +public class DefualtHostDecriptionTest { | ||
22 | + | ||
23 | + private static final MACAddress MAC = MACAddress.valueOf("00:00:11:00:00:01"); | ||
24 | + private static final VLANID VLAN = VLANID.vlanId((short) 10); | ||
25 | + private static final HostLocation LOC = new HostLocation( | ||
26 | + DeviceId.deviceId("of:foo"), | ||
27 | + PortNumber.portNumber(100), | ||
28 | + 123L | ||
29 | + ); | ||
30 | + private static final Set<IPAddress> IPS = Sets.newHashSet( | ||
31 | + IPAddress.valueOf("10.0.0.1"), | ||
32 | + IPAddress.valueOf("10.0.0.2") | ||
33 | + ); | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + HostDescription host = | ||
38 | + new DefaultHostDescription(MAC, VLAN, LOC, IPS); | ||
39 | + assertEquals("incorrect mac", MAC, host.hwAddress()); | ||
40 | + assertEquals("incorrect vlan", VLAN, host.vlan()); | ||
41 | + assertEquals("incorrect location", LOC, host.location()); | ||
42 | + assertTrue("incorrect ip's", IPS.equals(host.ipAddresses())); | ||
43 | + assertTrue("incorrect toString", host.toString().contains("vlan=10")); | ||
44 | + } | ||
45 | + | ||
46 | +} |
1 | +package org.onlab.onos.net.host; | ||
2 | + | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +import org.junit.Test; | ||
6 | +import org.onlab.onos.event.AbstractEventTest; | ||
7 | +import org.onlab.onos.net.DefaultHost; | ||
8 | +import org.onlab.onos.net.DeviceId; | ||
9 | +import org.onlab.onos.net.Host; | ||
10 | +import org.onlab.onos.net.HostId; | ||
11 | +import org.onlab.onos.net.HostLocation; | ||
12 | +import org.onlab.onos.net.PortNumber; | ||
13 | +import org.onlab.onos.net.provider.ProviderId; | ||
14 | +import org.onlab.packet.IPAddress; | ||
15 | +import org.onlab.packet.MACAddress; | ||
16 | +import org.onlab.packet.VLANID; | ||
17 | + | ||
18 | +import com.google.common.collect.Sets; | ||
19 | + | ||
20 | +public class HostEventTest extends AbstractEventTest { | ||
21 | + | ||
22 | + private Host createHost() { | ||
23 | + MACAddress mac = MACAddress.valueOf("00:00:11:00:00:01"); | ||
24 | + VLANID vlan = VLANID.vlanId((short) 10); | ||
25 | + HostLocation loc = new HostLocation( | ||
26 | + DeviceId.deviceId("of:foo"), | ||
27 | + PortNumber.portNumber(100), | ||
28 | + 123L | ||
29 | + ); | ||
30 | + Set<IPAddress> ipset = Sets.newHashSet( | ||
31 | + IPAddress.valueOf("10.0.0.1"), | ||
32 | + IPAddress.valueOf("10.0.0.2") | ||
33 | + ); | ||
34 | + HostId hid = HostId.hostId(mac, vlan); | ||
35 | + | ||
36 | + return new DefaultHost( | ||
37 | + new ProviderId("foo"), hid, mac, vlan, loc, ipset); | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + @Test | ||
42 | + public void withTime() { | ||
43 | + Host host = createHost(); | ||
44 | + HostEvent event = new HostEvent(HostEvent.Type.HOST_ADDED, host, 123L); | ||
45 | + validateEvent(event, HostEvent.Type.HOST_ADDED, host, 123L); | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + @Test | ||
50 | + public void withoutTime() { | ||
51 | + Host host = createHost(); | ||
52 | + long before = System.currentTimeMillis(); | ||
53 | + HostEvent event = new HostEvent(HostEvent.Type.HOST_ADDED, host, before); | ||
54 | + long after = System.currentTimeMillis(); | ||
55 | + validateEvent(event, HostEvent.Type.HOST_ADDED, host, before, after); | ||
56 | + } | ||
57 | +} |
-
Please register or login to post a comment