blob: 62a9ba0e4640bef93ba5a1dda0a155a506b7a375 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070016package org.onlab.onos.net.host;
17
18import java.util.Set;
19
20import org.junit.Test;
21import org.onlab.onos.event.AbstractEventTest;
22import org.onlab.onos.net.DefaultHost;
23import org.onlab.onos.net.DeviceId;
24import org.onlab.onos.net.Host;
25import org.onlab.onos.net.HostId;
26import org.onlab.onos.net.HostLocation;
27import org.onlab.onos.net.PortNumber;
28import org.onlab.onos.net.provider.ProviderId;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070029import org.onlab.packet.IpAddress;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070030import org.onlab.packet.MacAddress;
31import org.onlab.packet.VlanId;
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070032
33import com.google.common.collect.Sets;
34
35public class HostEventTest extends AbstractEventTest {
36
37 private Host createHost() {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070038 MacAddress mac = MacAddress.valueOf("00:00:11:00:00:01");
39 VlanId vlan = VlanId.vlanId((short) 10);
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070040 HostLocation loc = new HostLocation(
41 DeviceId.deviceId("of:foo"),
42 PortNumber.portNumber(100),
43 123L
44 );
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070045 Set<IpAddress> ipset = Sets.newHashSet(
46 IpAddress.valueOf("10.0.0.1"),
47 IpAddress.valueOf("10.0.0.2")
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070048 );
49 HostId hid = HostId.hostId(mac, vlan);
50
51 return new DefaultHost(
tom7e02cda2014-09-18 12:05:46 -070052 new ProviderId("of", "foo"), hid, mac, vlan, loc, ipset);
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070053 }
54
55 @Override
56 @Test
57 public void withTime() {
58 Host host = createHost();
59 HostEvent event = new HostEvent(HostEvent.Type.HOST_ADDED, host, 123L);
60 validateEvent(event, HostEvent.Type.HOST_ADDED, host, 123L);
61 }
62
63 @Override
64 @Test
65 public void withoutTime() {
66 Host host = createHost();
67 long before = System.currentTimeMillis();
68 HostEvent event = new HostEvent(HostEvent.Type.HOST_ADDED, host, before);
69 long after = System.currentTimeMillis();
70 validateEvent(event, HostEvent.Type.HOST_ADDED, host, before, after);
71 }
72}