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 | |
| 38 | LispIpv4Address srcAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
| 39 | LispIpv4Address dstAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); |
| 40 | |
| 41 | address1 = new LispSourceDestLcafAddress((short) 1, (byte) 0x01, |
| 42 | (byte) 0x01, srcAddress1, dstAddress1); |
| 43 | |
| 44 | sameAsAddress1 = new LispSourceDestLcafAddress((short) 1, (byte) 0x01, |
| 45 | (byte) 0x01, srcAddress1, dstAddress1); |
| 46 | |
| 47 | LispIpv4Address srcAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); |
| 48 | LispIpv4Address dstAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2")); |
| 49 | |
| 50 | address2 = new LispSourceDestLcafAddress((short) 2, (byte) 0x02, |
| 51 | (byte) 0x02, srcAddress2, dstAddress2); |
| 52 | } |
| 53 | |
| 54 | @Test |
| 55 | public void testEquality() { |
| 56 | new EqualsTester() |
| 57 | .addEqualityGroup(address1, sameAsAddress1) |
| 58 | .addEqualityGroup(address2).testEquals(); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void testConstruction() { |
| 63 | LispSourceDestLcafAddress sourceDestLcafAddress = address1; |
| 64 | |
| 65 | LispIpv4Address srcAddress = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
| 66 | LispIpv4Address dstAddress = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); |
| 67 | |
| 68 | assertThat(sourceDestLcafAddress.getReserved(), is((short) 1)); |
| 69 | assertThat(sourceDestLcafAddress.getSrcMaskLength(), is((byte) 0x01)); |
| 70 | assertThat(sourceDestLcafAddress.getDstMaskLength(), is((byte) 0x01)); |
| 71 | assertThat(sourceDestLcafAddress.getSrcPrefix(), is(srcAddress)); |
| 72 | assertThat(sourceDestLcafAddress.getDstPrefix(), is(dstAddress)); |
| 73 | } |
| 74 | } |