Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.net.config.basics; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import org.junit.Test; |
Jonghwan Hyun | 2c95acf | 2018-03-14 16:47:34 -0700 | [diff] [blame] | 23 | import org.onlab.packet.EthType; |
Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
Jonghwan Hyun | 2c95acf | 2018-03-14 16:47:34 -0700 | [diff] [blame] | 25 | import org.onlab.packet.VlanId; |
Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 26 | import org.onosproject.net.HostId; |
| 27 | import org.onosproject.net.HostLocation; |
| 28 | import org.onosproject.net.NetTestTools; |
| 29 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 30 | |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import static org.hamcrest.MatcherAssert.assertThat; |
| 34 | import static org.hamcrest.Matchers.hasItems; |
| 35 | import static org.hamcrest.Matchers.hasSize; |
| 36 | import static org.hamcrest.Matchers.is; |
| 37 | |
| 38 | public class BasicHostConfigTest { |
| 39 | |
| 40 | /** |
Jonghwan Hyun | 2c95acf | 2018-03-14 16:47:34 -0700 | [diff] [blame] | 41 | * Tests construction, setters and getters of a BasicHostConfig object. |
Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 42 | */ |
| 43 | @Test |
| 44 | public void testConstruction() { |
| 45 | BasicHostConfig config = new BasicHostConfig(); |
| 46 | ConfigApplyDelegate delegate = configApply -> { }; |
| 47 | ObjectMapper mapper = new ObjectMapper(); |
| 48 | HostId hostId = NetTestTools.hid("12:34:56:78:90:ab/1"); |
| 49 | IpAddress ip1 = IpAddress.valueOf("1.1.1.1"); |
| 50 | IpAddress ip2 = IpAddress.valueOf("1.1.1.2"); |
| 51 | IpAddress ip3 = IpAddress.valueOf("1.1.1.3"); |
| 52 | Set<IpAddress> ips = ImmutableSet.of(ip1, ip2, ip3); |
| 53 | HostLocation loc1 = new HostLocation( |
| 54 | NetTestTools.connectPoint("d1", 1), System.currentTimeMillis()); |
| 55 | HostLocation loc2 = new HostLocation( |
| 56 | NetTestTools.connectPoint("d2", 2), System.currentTimeMillis()); |
| 57 | Set<HostLocation> locs = ImmutableSet.of(loc1, loc2); |
Jonghwan Hyun | 2c95acf | 2018-03-14 16:47:34 -0700 | [diff] [blame] | 58 | VlanId vlanId = VlanId.vlanId((short) 10); |
| 59 | EthType ethType = EthType.EtherType.lookup((short) 0x88a8).ethType(); |
Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 60 | |
| 61 | config.init(hostId, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 62 | |
| 63 | config.setIps(ips) |
Jonghwan Hyun | 2c95acf | 2018-03-14 16:47:34 -0700 | [diff] [blame] | 64 | .setLocations(locs) |
| 65 | .setInnerVlan(vlanId) |
| 66 | .setOuterTpid(ethType); |
Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 67 | |
| 68 | assertThat(config.isValid(), is(true)); |
| 69 | assertThat(config.name(), is("-")); |
| 70 | assertThat(config.ipAddresses(), hasSize(3)); |
| 71 | assertThat(config.ipAddresses(), hasItems(ip1, ip2, ip3)); |
| 72 | assertThat(config.locations(), hasSize(2)); |
| 73 | assertThat(config.locations(), hasItems(loc1, loc2)); |
Jonghwan Hyun | 2c95acf | 2018-03-14 16:47:34 -0700 | [diff] [blame] | 74 | assertThat(config.innerVlan(), is(vlanId)); |
| 75 | assertThat(config.outerTpid(), is(ethType)); |
Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } |