blob: bf18878294bbe8061e999c7039891ebda545bad6 [file] [log] [blame]
Jian Li3ddd5532017-03-18 02:58:23 +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 LispGcAddress extension class.
30 */
31public class LispGcAddressTest {
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 boolean NORTH_VALUE_1 = true;
37 private static final boolean EAST_VALUE_1 = false;
38 private static final short UNIQUE_SHORT_VALUE_1 = 1;
39 private static final byte UNIQUE_BYTE_VALUE_1 = 1;
40 private static final int UNIQUE_INT_VALUE_1 = 1;
41
42 private static final boolean NORTH_VALUE_2 = false;
43 private static final boolean EAST_VALUE_2 = true;
44 private static final short UNIQUE_SHORT_VALUE_2 = 2;
45 private static final byte UNIQUE_BYTE_VALUE_2 = 2;
46 private static final int UNIQUE_INT_VALUE_2 = 2;
47
48 private LispGcAddress address1;
49 private LispGcAddress sameAsAddress1;
50 private LispGcAddress address2;
51
52 @Before
53 public void setUp() {
54
55 MappingAddress ma1 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
56
57 address1 = new LispGcAddress.Builder()
58 .withIsNorth(NORTH_VALUE_1)
59 .withLatitudeDegree(UNIQUE_SHORT_VALUE_1)
60 .withLatitudeMinute(UNIQUE_BYTE_VALUE_1)
61 .withLatitudeSecond(UNIQUE_BYTE_VALUE_1)
62 .withIsEast(EAST_VALUE_1)
63 .withLongitudeDegree(UNIQUE_SHORT_VALUE_1)
64 .withLongitudeMinute(UNIQUE_BYTE_VALUE_1)
65 .withLongitudeSecond(UNIQUE_BYTE_VALUE_1)
66 .withAltitude(UNIQUE_INT_VALUE_1)
67 .withAddress(ma1)
68 .build();
69
70 sameAsAddress1 = new LispGcAddress.Builder()
71 .withIsNorth(NORTH_VALUE_1)
72 .withLatitudeDegree(UNIQUE_SHORT_VALUE_1)
73 .withLatitudeMinute(UNIQUE_BYTE_VALUE_1)
74 .withLatitudeSecond(UNIQUE_BYTE_VALUE_1)
75 .withIsEast(EAST_VALUE_1)
76 .withLongitudeDegree(UNIQUE_SHORT_VALUE_1)
77 .withLongitudeMinute(UNIQUE_BYTE_VALUE_1)
78 .withLongitudeSecond(UNIQUE_BYTE_VALUE_1)
79 .withAltitude(UNIQUE_INT_VALUE_1)
80 .withAddress(ma1)
81 .build();
82
83 MappingAddress ma2 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_2);
84
85 address2 = new LispGcAddress.Builder()
86 .withIsNorth(NORTH_VALUE_2)
87 .withLatitudeDegree(UNIQUE_SHORT_VALUE_2)
88 .withLatitudeMinute(UNIQUE_BYTE_VALUE_2)
89 .withLatitudeSecond(UNIQUE_BYTE_VALUE_2)
90 .withIsEast(EAST_VALUE_2)
91 .withLongitudeDegree(UNIQUE_SHORT_VALUE_2)
92 .withLongitudeMinute(UNIQUE_BYTE_VALUE_2)
93 .withLongitudeSecond(UNIQUE_BYTE_VALUE_2)
94 .withAltitude(UNIQUE_INT_VALUE_2)
95 .withAddress(ma2)
96 .build();
97
98 }
99
100 @Test
101 public void testEquality() {
102 new EqualsTester()
103 .addEqualityGroup(address1, sameAsAddress1)
104 .addEqualityGroup(address2).testEquals();
105 }
106
107 @Test
108 public void testConstruction() {
109 LispGcAddress address = address1;
110
111 MappingAddress ma = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
112
113 assertThat(address.isNorth(), is(NORTH_VALUE_1));
114 assertThat(address.getLatitudeDegree(), is(UNIQUE_SHORT_VALUE_1));
115 assertThat(address.getLatitudeMinute(), is(UNIQUE_BYTE_VALUE_1));
116 assertThat(address.getLatitudeSecond(), is(UNIQUE_BYTE_VALUE_1));
117 assertThat(address.isEast(), is(EAST_VALUE_1));
118 assertThat(address.getLongitudeDegree(), is(UNIQUE_SHORT_VALUE_1));
119 assertThat(address.getLongitudeMinute(), is(UNIQUE_BYTE_VALUE_1));
120 assertThat(address.getLongitudeSecond(), is(UNIQUE_BYTE_VALUE_1));
121 assertThat(address.getAltitude(), is(UNIQUE_INT_VALUE_1));
122 assertThat(address.getAddress(), is(ma));
123 }
124
125 @Test
126 public void testSerialization() {
127 LispGcAddress other = new LispGcAddress();
128 other.deserialize(address1.serialize());
129
130 new EqualsTester()
131 .addEqualityGroup(address1, other)
132 .testEquals();
133 }
134}