blob: 771a2a74965e6a2efa0f8435b78f5397718d9409 [file] [log] [blame]
Jian Lie9af3b42016-08-08 15:50:01 +09001/*
2 * Copyright 2016-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.lisp.msg.types;
17
18import com.google.common.collect.Lists;
19import com.google.common.testing.EqualsTester;
Jian Li76ea0572016-08-29 12:41:16 +090020import io.netty.buffer.ByteBuf;
21import io.netty.buffer.Unpooled;
Jian Lie9af3b42016-08-08 15:50:01 +090022import org.junit.Before;
23import org.junit.Test;
24import org.onlab.packet.IpAddress;
Jian Li76ea0572016-08-29 12:41:16 +090025import org.onosproject.lisp.msg.exceptions.LispParseError;
26import org.onosproject.lisp.msg.exceptions.LispReaderException;
27import org.onosproject.lisp.msg.exceptions.LispWriterException;
Jian Lie9af3b42016-08-08 15:50:01 +090028
29import java.util.List;
30
31import static org.hamcrest.MatcherAssert.assertThat;
32import static org.hamcrest.Matchers.is;
Jian Li76ea0572016-08-29 12:41:16 +090033import static org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressReader;
34import static org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressWriter;
Jian Lie9af3b42016-08-08 15:50:01 +090035
36/**
37 * Unit tests for LispListLcafAddress class.
38 */
39public class LispListLcafAddressTest {
40
41 private LispListLcafAddress address1;
42 private LispListLcafAddress sameAsAddress1;
43 private LispListLcafAddress address2;
44
45 @Before
46 public void setup() {
47
48 LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
49 LispAfiAddress ipv6Address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"));
50
51 List<LispAfiAddress> afiAddresses1 = Lists.newArrayList();
52 afiAddresses1.add(ipv4Address1);
53 afiAddresses1.add(ipv6Address1);
54
55 address1 = new LispListLcafAddress(afiAddresses1);
56
57 sameAsAddress1 = new LispListLcafAddress(afiAddresses1);
58
59 LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
60 LispAfiAddress ipv6Address2 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8886"));
61
62 List<LispAfiAddress> afiAddresses2 = Lists.newArrayList();
63 afiAddresses2.add(ipv4Address2);
64 afiAddresses2.add(ipv6Address2);
65
66 address2 = new LispListLcafAddress(afiAddresses2);
67 }
68
69 @Test
70 public void testEquality() {
71 new EqualsTester()
72 .addEqualityGroup(address1, sameAsAddress1)
73 .addEqualityGroup(address2).testEquals();
74 }
75
76 @Test
77 public void testConstruction() {
78 LispListLcafAddress listLcafAddress = address1;
79
80 LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
81 LispAfiAddress ipv6Address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"));
82
83 List<LispAfiAddress> afiAddresses1 = Lists.newArrayList();
84 afiAddresses1.add(ipv4Address1);
85 afiAddresses1.add(ipv6Address1);
86
87 assertThat(listLcafAddress.getAddresses(), is(afiAddresses1));
88 }
Jian Li76ea0572016-08-29 12:41:16 +090089
90 @Test
91 public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
92 ByteBuf byteBuf = Unpooled.buffer();
93
94 ListLcafAddressWriter writer = new ListLcafAddressWriter();
95 writer.writeTo(byteBuf, address1);
96
97 ListLcafAddressReader reader = new ListLcafAddressReader();
98 LispListLcafAddress deserialized = reader.readFrom(byteBuf);
99
100 new EqualsTester()
101 .addEqualityGroup(address1, deserialized).testEquals();
102 }
Jian Lie9af3b42016-08-08 15:50:01 +0900103}