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 | |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 18 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.HostLocation; |
| 21 | import org.onosproject.net.PortNumber; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpAddress; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 25 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 26 | import com.google.common.collect.ImmutableSet; |
| 27 | |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 28 | import static org.junit.Assert.assertEquals; |
| 29 | import static org.junit.Assert.assertTrue; |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Test for the default host description. |
| 33 | */ |
Pavlin Radoslavov | 3a7c1f8 | 2014-10-24 13:42:38 -0700 | [diff] [blame] | 34 | public class DefaultHostDecriptionTest { |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 35 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 36 | private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01"); |
| 37 | private static final VlanId VLAN = VlanId.vlanId((short) 10); |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 38 | private static final IpAddress IP = IpAddress.valueOf("10.0.0.1"); |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 39 | |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 40 | private static final HostLocation LOC = new HostLocation( |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 41 | DeviceId.deviceId("of:foo"), |
| 42 | PortNumber.portNumber(100), |
| 43 | 123L |
| 44 | ); |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 45 | |
| 46 | @Test |
| 47 | public void basics() { |
| 48 | HostDescription host = |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 49 | new DefaultHostDescription(MAC, VLAN, LOC, IP); |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 50 | assertEquals("incorrect mac", MAC, host.hwAddress()); |
| 51 | assertEquals("incorrect vlan", VLAN, host.vlan()); |
| 52 | assertEquals("incorrect location", LOC, host.location()); |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 53 | assertEquals("incorrect ip's", ImmutableSet.of(IP), host.ipAddress()); |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 54 | assertTrue("incorrect toString", host.toString().contains("vlan=10")); |
| 55 | } |
| 56 | |
| 57 | } |