blob: 0b360355153fc0dd6970720ffb217d98eb412f1f [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.host;
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070017
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070018import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.HostLocation;
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070020
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070021import com.google.common.collect.ImmutableSet;
Charles Chancd06c692017-04-27 20:46:06 -070022import org.onosproject.net.TestDeviceParams;
23
24import java.util.Set;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070025
tom093340b2014-10-10 00:15:36 -070026import static org.junit.Assert.assertEquals;
27import static org.junit.Assert.assertTrue;
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070028
29/**
30 * Test for the default host description.
31 */
Charles Chancd06c692017-04-27 20:46:06 -070032public class DefaultHostDecriptionTest extends TestDeviceParams {
33 private static final Set<HostLocation> LOCATIONS = ImmutableSet.of(LOC1, LOC2, LOC3);
34 private static final HostDescription SINGLE_HOMED_HOST_DESCR =
35 new DefaultHostDescription(MAC1, VLAN1, LOC1, IP1);
36 private static final HostDescription MULTI_HOMED_HOST_DESCR =
37 new DefaultHostDescription(MAC1, VLAN1, LOCATIONS, IPSET1, false);
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070038
39 @Test
40 public void basics() {
Charles Chancd06c692017-04-27 20:46:06 -070041 assertEquals("incorrect mac", MAC1, SINGLE_HOMED_HOST_DESCR.hwAddress());
42 assertEquals("incorrect vlan", VLAN1, SINGLE_HOMED_HOST_DESCR.vlan());
43 assertEquals("incorrect location", LOC1, SINGLE_HOMED_HOST_DESCR.location());
44 assertEquals("incorrect IPs", ImmutableSet.of(IP1), SINGLE_HOMED_HOST_DESCR.ipAddress());
45 assertTrue("incorrect toString", SINGLE_HOMED_HOST_DESCR.toString().contains("vlan=11"));
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070046 }
47
Charles Chancd06c692017-04-27 20:46:06 -070048 @Test
49 public void testLocation() {
50 assertEquals("Latest location should be LOC3", LOC3, MULTI_HOMED_HOST_DESCR.location());
51 }
52
53 @Test
54 public void testLocations() {
55 Set<HostLocation> locations = MULTI_HOMED_HOST_DESCR.locations();
56
57 assertEquals("There should be 3 locations", locations.size(), 3);
58 assertTrue("Host location contains 1st location", locations.contains(LOC1));
59 assertTrue("Host location contains 2nd location", locations.contains(LOC2));
60 assertTrue("Host location contains 3rd location", locations.contains(LOC3));
61 }
Ayaka Koshibe93afebc2014-09-15 13:25:22 -070062}