blob: dab2c9dc65ff3354726b8c08be046543ccfb0f16 [file] [log] [blame]
Ray Milkeyd29bc1c2018-03-13 11:57:11 -07001/*
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
17package org.onosproject.net.config.basics;
18
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.JsonNodeFactory;
21import com.google.common.collect.ImmutableSet;
22import org.junit.Test;
Jonghwan Hyun2c95acf2018-03-14 16:47:34 -070023import org.onlab.packet.EthType;
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070024import org.onlab.packet.IpAddress;
Jonghwan Hyun2c95acf2018-03-14 16:47:34 -070025import org.onlab.packet.VlanId;
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070026import org.onosproject.net.HostId;
27import org.onosproject.net.HostLocation;
28import org.onosproject.net.NetTestTools;
29import org.onosproject.net.config.ConfigApplyDelegate;
30
31import java.util.Set;
32
33import static org.hamcrest.MatcherAssert.assertThat;
34import static org.hamcrest.Matchers.hasItems;
35import static org.hamcrest.Matchers.hasSize;
36import static org.hamcrest.Matchers.is;
37
38public class BasicHostConfigTest {
39
40 /**
Jonghwan Hyun2c95acf2018-03-14 16:47:34 -070041 * Tests construction, setters and getters of a BasicHostConfig object.
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070042 */
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 Hyun2c95acf2018-03-14 16:47:34 -070058 VlanId vlanId = VlanId.vlanId((short) 10);
59 EthType ethType = EthType.EtherType.lookup((short) 0x88a8).ethType();
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070060
61 config.init(hostId, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
62
63 config.setIps(ips)
Jonghwan Hyun2c95acf2018-03-14 16:47:34 -070064 .setLocations(locs)
65 .setInnerVlan(vlanId)
66 .setOuterTpid(ethType);
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070067
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 Hyun2c95acf2018-03-14 16:47:34 -070074 assertThat(config.innerVlan(), is(vlanId));
75 assertThat(config.outerTpid(), is(ethType));
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070076 }
77
78}