blob: 4ffd1f11415efea65be9923dcd7dfa40f179ee9a [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
Jian Li5e505c62016-12-05 02:44:24 +090029import org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressWriter;
30import org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressReader;
31
Jian Lie9af3b42016-08-08 15:50:01 +090032import java.util.List;
33
34import static org.hamcrest.MatcherAssert.assertThat;
35import static org.hamcrest.Matchers.is;
36
37/**
38 * Unit tests for LispListLcafAddress class.
39 */
40public class LispListLcafAddressTest {
41
42 private LispListLcafAddress address1;
43 private LispListLcafAddress sameAsAddress1;
44 private LispListLcafAddress address2;
45
46 @Before
47 public void setup() {
48
49 LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
50 LispAfiAddress ipv6Address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"));
51
52 List<LispAfiAddress> afiAddresses1 = Lists.newArrayList();
53 afiAddresses1.add(ipv4Address1);
54 afiAddresses1.add(ipv6Address1);
55
56 address1 = new LispListLcafAddress(afiAddresses1);
57
58 sameAsAddress1 = new LispListLcafAddress(afiAddresses1);
59
60 LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
61 LispAfiAddress ipv6Address2 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8886"));
62
63 List<LispAfiAddress> afiAddresses2 = Lists.newArrayList();
64 afiAddresses2.add(ipv4Address2);
65 afiAddresses2.add(ipv6Address2);
66
67 address2 = new LispListLcafAddress(afiAddresses2);
68 }
69
70 @Test
71 public void testEquality() {
72 new EqualsTester()
73 .addEqualityGroup(address1, sameAsAddress1)
74 .addEqualityGroup(address2).testEquals();
75 }
76
77 @Test
78 public void testConstruction() {
79 LispListLcafAddress listLcafAddress = address1;
80
81 LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
82 LispAfiAddress ipv6Address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"));
83
84 List<LispAfiAddress> afiAddresses1 = Lists.newArrayList();
85 afiAddresses1.add(ipv4Address1);
86 afiAddresses1.add(ipv6Address1);
87
88 assertThat(listLcafAddress.getAddresses(), is(afiAddresses1));
89 }
Jian Li76ea0572016-08-29 12:41:16 +090090
91 @Test
92 public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
93 ByteBuf byteBuf = Unpooled.buffer();
94
95 ListLcafAddressWriter writer = new ListLcafAddressWriter();
96 writer.writeTo(byteBuf, address1);
97
98 ListLcafAddressReader reader = new ListLcafAddressReader();
99 LispListLcafAddress deserialized = reader.readFrom(byteBuf);
100
Jian Li5e505c62016-12-05 02:44:24 +0900101 new EqualsTester().addEqualityGroup(address1, deserialized).testEquals();
Jian Li76ea0572016-08-29 12:41:16 +0900102 }
Jian Lie9af3b42016-08-08 15:50:01 +0900103}