Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.lisp.msg.types; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.is; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for LispSourceDestLcafAddress class. |
| 28 | */ |
| 29 | public class LispSourceDestLcafAddressTest { |
| 30 | |
| 31 | private LispSourceDestLcafAddress address1; |
| 32 | private LispSourceDestLcafAddress sameAsAddress1; |
| 33 | private LispSourceDestLcafAddress address2; |
| 34 | |
| 35 | @Before |
| 36 | public void setup() { |
| 37 | |
Jian Li | 115d860 | 2016-08-15 20:21:53 +0900 | [diff] [blame] | 38 | LispSourceDestLcafAddress.SourceDestAddressBuilder builder1 = |
| 39 | new LispSourceDestLcafAddress.SourceDestAddressBuilder(); |
| 40 | |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 41 | LispIpv4Address srcAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
| 42 | LispIpv4Address dstAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); |
| 43 | |
Jian Li | 115d860 | 2016-08-15 20:21:53 +0900 | [diff] [blame] | 44 | address1 = builder1 |
| 45 | .withReserved((short) 1) |
| 46 | .withSrcMaskLength((byte) 0x01) |
| 47 | .withDstMaskLength((byte) 0x01) |
| 48 | .withSrcPrefix(srcAddress1) |
| 49 | .withDstPrefix(dstAddress1) |
| 50 | .build(); |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 51 | |
Jian Li | 115d860 | 2016-08-15 20:21:53 +0900 | [diff] [blame] | 52 | 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 Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 65 | |
| 66 | LispIpv4Address srcAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); |
| 67 | LispIpv4Address dstAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2")); |
| 68 | |
Jian Li | 115d860 | 2016-08-15 20:21:53 +0900 | [diff] [blame] | 69 | address2 = builder3 |
| 70 | .withReserved((short) 2) |
| 71 | .withSrcMaskLength((byte) 0x02) |
| 72 | .withDstMaskLength((byte) 0x02) |
| 73 | .withSrcPrefix(srcAddress2) |
| 74 | .withDstPrefix(dstAddress2) |
| 75 | .build(); |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 76 | } |
| 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 | } |