blob: afccf87aec690d7aa91e3d747cea4862d67a9b0a [file] [log] [blame]
Jian Li50b51ee2017-03-19 03:23:29 +09001/*
2 * Copyright 2017-present Open Networking Laboratory
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 */
16package org.onosproject.drivers.lisp.extensions;
17
18import com.google.common.collect.ImmutableList;
19import com.google.common.testing.EqualsTester;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.IpPrefix;
23import org.onosproject.mapping.addresses.MappingAddress;
24import org.onosproject.mapping.addresses.MappingAddresses;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28
29/**
30 * Unit tests for LispTeAddress extension class.
31 */
32public class LispTeAddressTest {
33
34 private static final IpPrefix IP_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/24");
35 private static final IpPrefix IP_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/24");
36
37 private static final boolean IS_LOOKUP_1 = false;
38 private static final boolean IS_RLOC_PROBE_1 = true;
39 private static final boolean IS_STRICT_1 = false;
40
41 private static final boolean IS_LOOKUP_2 = true;
42 private static final boolean IS_RLOC_PROBE_2 = false;
43 private static final boolean IS_STRICT_2 = true;
44
45 private LispTeAddress address1;
46 private LispTeAddress sameAsAddress1;
47 private LispTeAddress address2;
48
49 @Before
50 public void setUp() {
51
52 MappingAddress ma1 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
53 MappingAddress ma2 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_2);
54
55 LispTeAddress.TeRecord tr1 = new LispTeAddress.TeRecord.Builder()
56 .withIsLookup(IS_LOOKUP_1)
57 .withIsRlocProbe(IS_RLOC_PROBE_1)
58 .withIsStrict(IS_STRICT_1)
59 .withRtrRlocAddress(ma1)
60 .build();
61
62 LispTeAddress.TeRecord tr2 = new LispTeAddress.TeRecord.Builder()
63 .withIsLookup(IS_LOOKUP_2)
64 .withIsRlocProbe(IS_RLOC_PROBE_2)
65 .withIsStrict(IS_STRICT_2)
66 .withRtrRlocAddress(ma2)
67 .build();
68
69 address1 = new LispTeAddress.Builder()
70 .withTeRecords(ImmutableList.of(tr1, tr2))
71 .build();
72
73 sameAsAddress1 = new LispTeAddress.Builder()
74 .withTeRecords(ImmutableList.of(tr1, tr2))
75 .build();
76
77 address2 = new LispTeAddress.Builder()
78 .withTeRecords(ImmutableList.of(tr2, tr1))
79 .build();
80 }
81
82 @Test
83 public void testEquality() {
84 new EqualsTester()
85 .addEqualityGroup(address1, sameAsAddress1)
86 .addEqualityGroup(address2).testEquals();
87 }
88
89 @Test
90 public void testConstruction() {
91 LispTeAddress address = address1;
92
93 MappingAddress ma = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
94
95 assertThat(address.getTeRecords().get(0).isLookup(), is(IS_LOOKUP_1));
96 assertThat(address.getTeRecords().get(0).isRlocProbe(), is(IS_RLOC_PROBE_1));
97 assertThat(address.getTeRecords().get(0).isStrict(), is(IS_STRICT_1));
98 assertThat(address.getTeRecords().get(0).getAddress(), is(ma));
99 }
100
101 @Test
102 public void testSerialization() {
103 LispTeAddress other = new LispTeAddress();
104 other.deserialize(address1.serialize());
105
106 new EqualsTester()
107 .addEqualityGroup(address1, other)
108 .testEquals();
109 }
110}