blob: e212a1cc2fe8f8221325ac46743c54067d32911f [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.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.is;
25
26/**
27 * Unit tests for LispSourceDestLcafAddress class.
28 */
29public class LispSourceDestLcafAddressTest {
30
31 private LispSourceDestLcafAddress address1;
32 private LispSourceDestLcafAddress sameAsAddress1;
33 private LispSourceDestLcafAddress address2;
34
35 @Before
36 public void setup() {
37
Jian Li115d8602016-08-15 20:21:53 +090038 LispSourceDestLcafAddress.SourceDestAddressBuilder builder1 =
39 new LispSourceDestLcafAddress.SourceDestAddressBuilder();
40
Jian Lie9af3b42016-08-08 15:50:01 +090041 LispIpv4Address srcAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
42 LispIpv4Address dstAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
43
Jian Li115d8602016-08-15 20:21:53 +090044 address1 = builder1
45 .withReserved((short) 1)
46 .withSrcMaskLength((byte) 0x01)
47 .withDstMaskLength((byte) 0x01)
48 .withSrcPrefix(srcAddress1)
49 .withDstPrefix(dstAddress1)
50 .build();
Jian Lie9af3b42016-08-08 15:50:01 +090051
Jian Li115d8602016-08-15 20:21:53 +090052 LispSourceDestLcafAddress.SourceDestAddressBuilder builder2 =
53 new LispSourceDestLcafAddress.SourceDestAddressBuilder();
54
55 sameAsAddress1 = builder2
56 .withReserved((short) 1)
57 .withSrcMaskLength((byte) 0x01)
58 .withDstMaskLength((byte) 0x01)
59 .withSrcPrefix(srcAddress1)
60 .withDstPrefix(dstAddress1)
61 .build();
62
63 LispSourceDestLcafAddress.SourceDestAddressBuilder builder3 =
64 new LispSourceDestLcafAddress.SourceDestAddressBuilder();
Jian Lie9af3b42016-08-08 15:50:01 +090065
66 LispIpv4Address srcAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
67 LispIpv4Address dstAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2"));
68
Jian Li115d8602016-08-15 20:21:53 +090069 address2 = builder3
70 .withReserved((short) 2)
71 .withSrcMaskLength((byte) 0x02)
72 .withDstMaskLength((byte) 0x02)
73 .withSrcPrefix(srcAddress2)
74 .withDstPrefix(dstAddress2)
75 .build();
Jian Lie9af3b42016-08-08 15:50:01 +090076 }
77
78 @Test
79 public void testEquality() {
80 new EqualsTester()
81 .addEqualityGroup(address1, sameAsAddress1)
82 .addEqualityGroup(address2).testEquals();
83 }
84
85 @Test
86 public void testConstruction() {
87 LispSourceDestLcafAddress sourceDestLcafAddress = address1;
88
89 LispIpv4Address srcAddress = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
90 LispIpv4Address dstAddress = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
91
92 assertThat(sourceDestLcafAddress.getReserved(), is((short) 1));
93 assertThat(sourceDestLcafAddress.getSrcMaskLength(), is((byte) 0x01));
94 assertThat(sourceDestLcafAddress.getDstMaskLength(), is((byte) 0x01));
95 assertThat(sourceDestLcafAddress.getSrcPrefix(), is(srcAddress));
96 assertThat(sourceDestLcafAddress.getDstPrefix(), is(dstAddress));
97 }
98}