blob: 464e5e3e160e686cc34f114d607f6b00768c7026 [file] [log] [blame]
Jian Lie47e21a2017-03-18 13:39:51 +09001/*
2 * Copyright 2017-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.drivers.lisp.extensions;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpPrefix;
22import org.onosproject.mapping.addresses.MappingAddress;
23import org.onosproject.mapping.addresses.MappingAddresses;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27
28/**
29 * Unit tests for LispMulticastAddress extension class.
30 */
31public class LispMulticastAddressTest {
32
33 private static final IpPrefix IP_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/24");
34 private static final IpPrefix IP_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/24");
35
36 private static final int INSTANCE_ID_1 = 1;
37 private static final int INSTANCE_ID_2 = 2;
38 private static final byte MASK_LENGTH = (byte) 0x24;
39
40 private LispMulticastAddress address1;
41 private LispMulticastAddress sameAsAddress1;
42 private LispMulticastAddress address2;
43
44 @Before
45 public void setUp() {
46
47 MappingAddress ma1 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
48
49 address1 = new LispMulticastAddress.Builder()
50 .withInstanceId(INSTANCE_ID_1)
51 .withSrcMaskLength(MASK_LENGTH)
52 .withGrpMaskLength(MASK_LENGTH)
53 .withSrcAddress(ma1)
54 .withGrpAddress(ma1)
55 .build();
56
57 sameAsAddress1 = new LispMulticastAddress.Builder()
58 .withInstanceId(INSTANCE_ID_1)
59 .withSrcMaskLength(MASK_LENGTH)
60 .withGrpMaskLength(MASK_LENGTH)
61 .withSrcAddress(ma1)
62 .withGrpAddress(ma1)
63 .build();
64
65 MappingAddress ma2 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_2);
66
67 address2 = new LispMulticastAddress.Builder()
68 .withInstanceId(INSTANCE_ID_2)
69 .withSrcMaskLength(MASK_LENGTH)
70 .withGrpMaskLength(MASK_LENGTH)
71 .withSrcAddress(ma2)
72 .withGrpAddress(ma2)
73 .build();
74 }
75
76 @Test
77 public void testEquality() {
78 new EqualsTester()
79 .addEqualityGroup(address1, sameAsAddress1)
80 .addEqualityGroup(address2).testEquals();
81 }
82
83 @Test
84 public void testConstruction() {
85 LispMulticastAddress address = address1;
86
87 MappingAddress ma = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
88
89 assertThat(address.getInstanceId(), is(INSTANCE_ID_1));
90 assertThat(address.getSrcMaskLength(), is(MASK_LENGTH));
91 assertThat(address.getGrpMaskLength(), is(MASK_LENGTH));
92 assertThat(address.getSrcAddress(), is(ma));
93 assertThat(address.getGrpAddress(), is(ma));
94 }
95
96 @Test
97 public void testSerialization() {
98 LispMulticastAddress other = new LispMulticastAddress();
99 other.deserialize(address1.serialize());
100
101 new EqualsTester()
102 .addEqualityGroup(address1, other)
103 .testEquals();
104 }
105}