blob: 29cd5cca6751aaba2df2b35976b23c8ef20bffd6 [file] [log] [blame]
Jian Li3ddd5532017-03-18 02:58:23 +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 LispListAddress extension class.
30 */
31public class LispListAddressTest {
32
33 private static final IpPrefix IPV4_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/24");
34 private static final IpPrefix IPV4_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/24");
35
36 private static final IpPrefix IPV6_ADDRESS_1 = IpPrefix.valueOf("1111:2222:3333:4444:5555:6666:7777:8886/96");
37 private static final IpPrefix IPV6_ADDRESS_2 = IpPrefix.valueOf("2222:3333:4444:5555:6666:7777:8888:9999/96");
38
39 private LispListAddress address1;
40 private LispListAddress sameAsAddress1;
41 private LispListAddress address2;
42
43 @Before
44 public void setUp() {
45
46 MappingAddress ipv4Addr1 = MappingAddresses.ipv4MappingAddress(IPV4_ADDRESS_1);
47 MappingAddress ipv6Addr1 = MappingAddresses.ipv6MappingAddress(IPV6_ADDRESS_1);
48
49 address1 = new LispListAddress.Builder()
50 .withIpv4(ipv4Addr1)
51 .withIpv6(ipv6Addr1)
52 .build();
53
54 sameAsAddress1 = new LispListAddress.Builder()
55 .withIpv4(ipv4Addr1)
56 .withIpv6(ipv6Addr1)
57 .build();
58
59 MappingAddress ipv4Addr2 = MappingAddresses.ipv4MappingAddress(IPV4_ADDRESS_2);
60 MappingAddress ipv6Addr2 = MappingAddresses.ipv6MappingAddress(IPV6_ADDRESS_2);
61
62 address2 = new LispListAddress.Builder()
63 .withIpv4(ipv4Addr2)
64 .withIpv6(ipv6Addr2)
65 .build();
66 }
67
68 @Test
69 public void testEquality() {
70 new EqualsTester()
71 .addEqualityGroup(address1, sameAsAddress1)
72 .addEqualityGroup(address2).testEquals();
73 }
74
75 @Test
76 public void testConstruction() {
77 LispListAddress address = address1;
78
79 MappingAddress ipv4 = MappingAddresses.ipv4MappingAddress(IPV4_ADDRESS_1);
80 MappingAddress ipv6 = MappingAddresses.ipv6MappingAddress(IPV6_ADDRESS_1);
81
82 assertThat(address.getIpv4(), is(ipv4));
83 assertThat(address.getIpv6(), is(ipv6));
84 }
85
86 @Test
87 public void testSerialization() {
88 LispListAddress other = new LispListAddress();
89 other.deserialize(address1.serialize());
90
91 new EqualsTester()
92 .addEqualityGroup(address1, other)
93 .testEquals();
94 }
95}