blob: c86c672b6df2d75745c7a8a971eecbb3065c225d [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.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpPrefix;
22import org.onosproject.mapping.addresses.MappingAddress;
23import org.onosproject.mapping.addresses.MappingAddresses;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27
28/**
29 * Unit tests for LispSrcDstAddress extension class.
30 */
31public class LispSrcDstAddressTest {
32
33 private static final IpPrefix IP_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/24");
34 private static final IpPrefix IP_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/24");
35
36 private static final byte MASK_LENGTH_1 = 0x01;
37 private static final byte MASK_LENGTH_2 = 0x02;
38
39 private LispSrcDstAddress address1;
40 private LispSrcDstAddress sameAsAddress1;
41 private LispSrcDstAddress address2;
42
43 @Before
44 public void setUp() {
45
46 MappingAddress ma1 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
47
48 address1 = new LispSrcDstAddress.Builder()
49 .withSrcMaskLength(MASK_LENGTH_1)
50 .withDstMaskLength(MASK_LENGTH_1)
51 .withSrcPrefix(ma1)
52 .withDstPrefix(ma1)
53 .build();
54
55 sameAsAddress1 = new LispSrcDstAddress.Builder()
56 .withSrcMaskLength(MASK_LENGTH_1)
57 .withDstMaskLength(MASK_LENGTH_1)
58 .withSrcPrefix(ma1)
59 .withDstPrefix(ma1)
60 .build();
61
62 MappingAddress ma2 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_2);
63
64 address2 = new LispSrcDstAddress.Builder()
65 .withSrcMaskLength(MASK_LENGTH_2)
66 .withDstMaskLength(MASK_LENGTH_2)
67 .withSrcPrefix(ma2)
68 .withDstPrefix(ma2)
69 .build();
70 }
71
72 @Test
73 public void testEquality() {
74 new EqualsTester()
75 .addEqualityGroup(address1, sameAsAddress1)
76 .addEqualityGroup(address2).testEquals();
77 }
78
79 @Test
80 public void testConstruction() {
81 LispSrcDstAddress address = address1;
82
83 MappingAddress ma = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
84
85 assertThat(address.getSrcMaskLength(), is(MASK_LENGTH_1));
86 assertThat(address.getDstMaskLength(), is(MASK_LENGTH_1));
87 assertThat(address.getSrcPrefix(), is(ma));
88 assertThat(address.getDstPrefix(), is(ma));
89 }
90
91 @Test
92 public void testSerialization() {
93 LispSrcDstAddress other = new LispSrcDstAddress();
94 other.deserialize(address1.serialize());
95
96 new EqualsTester()
97 .addEqualityGroup(address1, other)
98 .testEquals();
99 }
100}