Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.host; |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Set; |
| 19 | |
| 20 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.event.AbstractEventTest; |
| 22 | import org.onosproject.net.DefaultHost; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.Host; |
| 25 | import org.onosproject.net.HostId; |
| 26 | import org.onosproject.net.HostLocation; |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.provider.ProviderId; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 29 | import org.onlab.packet.IpAddress; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 30 | import org.onlab.packet.MacAddress; |
| 31 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 32 | |
| 33 | import com.google.common.collect.Sets; |
| 34 | |
| 35 | public class HostEventTest extends AbstractEventTest { |
| 36 | |
| 37 | private Host createHost() { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 38 | MacAddress mac = MacAddress.valueOf("00:00:11:00:00:01"); |
| 39 | VlanId vlan = VlanId.vlanId((short) 10); |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 40 | HostLocation loc = new HostLocation( |
| 41 | DeviceId.deviceId("of:foo"), |
| 42 | PortNumber.portNumber(100), |
| 43 | 123L |
| 44 | ); |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 45 | Set<IpAddress> ipset = Sets.newHashSet( |
| 46 | IpAddress.valueOf("10.0.0.1"), |
| 47 | IpAddress.valueOf("10.0.0.2") |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 48 | ); |
| 49 | HostId hid = HostId.hostId(mac, vlan); |
| 50 | |
| 51 | return new DefaultHost( |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 52 | new ProviderId("of", "foo"), hid, mac, vlan, loc, ipset); |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 53 | } |
| 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 | } |