Committed by
Gerrit Code Review
ONOS-4085, ONOS-4096, ONOS-4097: JUNIT for ISIS PDU data structures
Change-Id: If2ef21201d4d86a2f3f4b95365d41a01d8feda98
Showing
13 changed files
with
2585 additions
and
1 deletions
protocols/isis/isisio/src/main/java/org/onosproject/isis/io/isispacket/pdu/Psnp.java
100644 → 100755
... | @@ -79,11 +79,25 @@ public class Psnp extends IsisHeader { | ... | @@ -79,11 +79,25 @@ public class Psnp extends IsisHeader { |
79 | populateHeader(isisHeader); | 79 | populateHeader(isisHeader); |
80 | } | 80 | } |
81 | 81 | ||
82 | + /** | ||
83 | + * Adds the TLV to list. | ||
84 | + * | ||
85 | + * @param isisTlv ISIS TLV instance | ||
86 | + */ | ||
82 | public void addTlv(IsisTlv isisTlv) { | 87 | public void addTlv(IsisTlv isisTlv) { |
83 | variableLengths.add(isisTlv); | 88 | variableLengths.add(isisTlv); |
84 | } | 89 | } |
85 | 90 | ||
86 | /** | 91 | /** |
92 | + * Returns the list of all tlvs. | ||
93 | + * | ||
94 | + * @return variableLengths list of tlvs | ||
95 | + */ | ||
96 | + public List<IsisTlv> getAllTlv() { | ||
97 | + return variableLengths; | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
87 | * Returns the source ID of csnp. | 101 | * Returns the source ID of csnp. |
88 | * | 102 | * |
89 | * @return sourceId source ID | 103 | * @return sourceId source ID |
... | @@ -136,7 +150,9 @@ public class Psnp extends IsisHeader { | ... | @@ -136,7 +150,9 @@ public class Psnp extends IsisHeader { |
136 | TlvType tlvValue = TlvType.get(tlvHeader.tlvType()); | 150 | TlvType tlvValue = TlvType.get(tlvHeader.tlvType()); |
137 | if (tlvValue != null) { | 151 | if (tlvValue != null) { |
138 | IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength())); | 152 | IsisTlv tlv = TlvFinder.findTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength())); |
153 | + if (tlv != null) { | ||
139 | this.variableLengths.add(tlv); | 154 | this.variableLengths.add(tlv); |
155 | + } | ||
140 | } else { | 156 | } else { |
141 | channelBuffer.readBytes(tlvHeader.tlvLength()); | 157 | channelBuffer.readBytes(tlvHeader.tlvLength()); |
142 | } | 158 | } | ... | ... |
... | @@ -654,7 +654,7 @@ public final class IsisUtil { | ... | @@ -654,7 +654,7 @@ public final class IsisUtil { |
654 | * @return given number as bytes | 654 | * @return given number as bytes |
655 | */ | 655 | */ |
656 | public static byte[] convertToThreeBytes(int numberToConvert) { | 656 | public static byte[] convertToThreeBytes(int numberToConvert) { |
657 | - byte[] numInBytes = new byte[4]; | 657 | + byte[] numInBytes = new byte[3]; |
658 | String s1 = Integer.toHexString(numberToConvert); | 658 | String s1 = Integer.toHexString(numberToConvert); |
659 | if (s1.length() % 2 != 0) { | 659 | if (s1.length() % 2 != 0) { |
660 | s1 = "0" + s1; | 660 | s1 = "0" + s1; | ... | ... |
protocols/isis/isisio/src/test/java/org/onosproject/isis/io/isispacket/IsisHeaderTest.java
0 → 100644
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.isis.io.isispacket; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.MacAddress; | ||
24 | +import org.onosproject.isis.controller.IsisPduType; | ||
25 | + | ||
26 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
27 | +import static org.hamcrest.Matchers.is; | ||
28 | +import static org.hamcrest.Matchers.notNullValue; | ||
29 | + | ||
30 | +/** | ||
31 | + * Unit test class for IsisHeader. | ||
32 | + */ | ||
33 | +public class IsisHeaderTest { | ||
34 | + | ||
35 | + private IsisHeader isisHeader; | ||
36 | + private MacAddress macAddress = MacAddress.valueOf("a4:23:05:00:00:00"); | ||
37 | + private int result; | ||
38 | + private MacAddress result1; | ||
39 | + private byte result2; | ||
40 | + private IsisPduType result3; | ||
41 | + private ChannelBuffer channelBuffer; | ||
42 | + | ||
43 | + @Before | ||
44 | + public void setUp() throws Exception { | ||
45 | + isisHeader = new IsisHeader(); | ||
46 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
47 | + } | ||
48 | + | ||
49 | + @After | ||
50 | + public void tearDown() throws Exception { | ||
51 | + isisHeader = null; | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * Tests interfaceIndex() getter method. | ||
56 | + */ | ||
57 | + @Test | ||
58 | + public void testInterfaceIndex() throws Exception { | ||
59 | + isisHeader.setInterfaceIndex(1); | ||
60 | + result = isisHeader.interfaceIndex(); | ||
61 | + assertThat(result, is(1)); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Tests interfaceIndex() setter method. | ||
66 | + */ | ||
67 | + @Test | ||
68 | + public void testSetInterfaceIndex() throws Exception { | ||
69 | + isisHeader.setInterfaceIndex(1); | ||
70 | + result = isisHeader.interfaceIndex(); | ||
71 | + assertThat(result, is(1)); | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Tests interfaceMac() getter method. | ||
76 | + */ | ||
77 | + @Test | ||
78 | + public void testInterfaceMac() throws Exception { | ||
79 | + isisHeader.setInterfaceMac(macAddress); | ||
80 | + result1 = isisHeader.interfaceMac(); | ||
81 | + assertThat(result1, is(macAddress)); | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Tests sourceMac() getter method. | ||
86 | + */ | ||
87 | + @Test | ||
88 | + public void testSourceMac() throws Exception { | ||
89 | + isisHeader.setSourceMac(macAddress); | ||
90 | + result1 = isisHeader.sourceMac(); | ||
91 | + assertThat(result1, is(macAddress)); | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Tests sourceMac() setter method. | ||
96 | + */ | ||
97 | + @Test | ||
98 | + public void testSetSourceMac() throws Exception { | ||
99 | + isisHeader.setSourceMac(macAddress); | ||
100 | + result1 = isisHeader.sourceMac(); | ||
101 | + assertThat(result1, is(macAddress)); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * Tests interfaceMac() setter method. | ||
106 | + */ | ||
107 | + @Test | ||
108 | + public void testSetInterfaceMac() throws Exception { | ||
109 | + isisHeader.setSourceMac(macAddress); | ||
110 | + result1 = isisHeader.sourceMac(); | ||
111 | + assertThat(result1, is(macAddress)); | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * Tests version2() getter method. | ||
116 | + */ | ||
117 | + @Test | ||
118 | + public void testVersion2() throws Exception { | ||
119 | + isisHeader.setVersion2((byte) 1); | ||
120 | + result2 = isisHeader.version2(); | ||
121 | + assertThat(result2, is((byte) 1)); | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * Tests version2() setter method. | ||
126 | + */ | ||
127 | + @Test | ||
128 | + public void testSetVersion2() throws Exception { | ||
129 | + isisHeader.setVersion2((byte) 1); | ||
130 | + result2 = isisHeader.version2(); | ||
131 | + assertThat(result2, is((byte) 1)); | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * Tests maximumAreaAddresses() getter method. | ||
136 | + */ | ||
137 | + @Test | ||
138 | + public void testMaximumAreaAddresses() throws Exception { | ||
139 | + isisHeader.setMaximumAreaAddresses((byte) 1); | ||
140 | + result2 = isisHeader.maximumAreaAddresses(); | ||
141 | + assertThat(result2, is((byte) 1)); | ||
142 | + } | ||
143 | + | ||
144 | + /** | ||
145 | + * Tests maximumAreaAddresses() setter method. | ||
146 | + */ | ||
147 | + @Test | ||
148 | + public void testSetMaximumAreaAddresses() throws Exception { | ||
149 | + isisHeader.setMaximumAreaAddresses((byte) 1); | ||
150 | + result2 = isisHeader.maximumAreaAddresses(); | ||
151 | + assertThat(result2, is((byte) 1)); | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * Tests reserved() getter method. | ||
156 | + */ | ||
157 | + @Test | ||
158 | + public void testReserved() throws Exception { | ||
159 | + isisHeader.setReserved((byte) 1); | ||
160 | + result2 = isisHeader.reserved(); | ||
161 | + assertThat(result2, is((byte) 1)); | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * Tests reserved() setter method. | ||
166 | + */ | ||
167 | + @Test | ||
168 | + public void testSetReserved() throws Exception { | ||
169 | + isisHeader.setReserved((byte) 1); | ||
170 | + result2 = isisHeader.reserved(); | ||
171 | + assertThat(result2, is((byte) 1)); | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * Tests version() getter method. | ||
176 | + */ | ||
177 | + @Test | ||
178 | + public void testVersion() throws Exception { | ||
179 | + isisHeader.setVersion((byte) 1); | ||
180 | + result2 = isisHeader.version(); | ||
181 | + assertThat(result2, is((byte) 1)); | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Tests version() setter method. | ||
186 | + */ | ||
187 | + @Test | ||
188 | + public void testSetVersion() throws Exception { | ||
189 | + isisHeader.setVersion((byte) 1); | ||
190 | + result2 = isisHeader.version(); | ||
191 | + assertThat(result2, is((byte) 1)); | ||
192 | + } | ||
193 | + | ||
194 | + /** | ||
195 | + * Tests idLength() getter method. | ||
196 | + */ | ||
197 | + @Test | ||
198 | + public void testIdLength() throws Exception { | ||
199 | + isisHeader.setIdLength((byte) 1); | ||
200 | + result2 = isisHeader.idLength(); | ||
201 | + assertThat(result2, is((byte) 1)); | ||
202 | + } | ||
203 | + | ||
204 | + /** | ||
205 | + * Tests idLength() setter method. | ||
206 | + */ | ||
207 | + @Test | ||
208 | + public void testSetIdLength() throws Exception { | ||
209 | + isisHeader.setIdLength((byte) 1); | ||
210 | + result2 = isisHeader.idLength(); | ||
211 | + assertThat(result2, is((byte) 1)); | ||
212 | + } | ||
213 | + | ||
214 | + /** | ||
215 | + * Tests pduType() getter method. | ||
216 | + */ | ||
217 | + @Test | ||
218 | + public void testPduType() throws Exception { | ||
219 | + isisHeader.setIsisPduType(1); | ||
220 | + result = isisHeader.pduType(); | ||
221 | + assertThat(result, is(1)); | ||
222 | + } | ||
223 | + | ||
224 | + /** | ||
225 | + * Tests pduType() setter method. | ||
226 | + */ | ||
227 | + @Test | ||
228 | + public void testSetIsisPduType() throws Exception { | ||
229 | + isisHeader.setIsisPduType(1); | ||
230 | + result = isisHeader.pduType(); | ||
231 | + assertThat(result, is(1)); | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * Tests pduHeaderLength() getter method. | ||
236 | + */ | ||
237 | + @Test | ||
238 | + public void testPduHeaderLength() throws Exception { | ||
239 | + isisHeader.setPduHeaderLength((byte) 1); | ||
240 | + result2 = isisHeader.pduHeaderLength(); | ||
241 | + assertThat(result2, is((byte) 1)); | ||
242 | + } | ||
243 | + | ||
244 | + /** | ||
245 | + * Tests pduHeaderLength() setter method. | ||
246 | + */ | ||
247 | + @Test | ||
248 | + public void testSetPduHeaderLength() throws Exception { | ||
249 | + isisHeader.setPduHeaderLength((byte) 1); | ||
250 | + result2 = isisHeader.pduHeaderLength(); | ||
251 | + assertThat(result2, is((byte) 1)); | ||
252 | + } | ||
253 | + | ||
254 | + /** | ||
255 | + * Tests irpDiscriminator() getter method. | ||
256 | + */ | ||
257 | + @Test | ||
258 | + public void testIrpDiscriminator() throws Exception { | ||
259 | + isisHeader.setIrpDiscriminator((byte) 1); | ||
260 | + result2 = isisHeader.irpDiscriminator(); | ||
261 | + assertThat(result2, is((byte) 1)); | ||
262 | + } | ||
263 | + | ||
264 | + /** | ||
265 | + * Tests irpDiscriminator() setter method. | ||
266 | + */ | ||
267 | + @Test | ||
268 | + public void testSetIrpDiscriminator() throws Exception { | ||
269 | + isisHeader.setIrpDiscriminator((byte) 1); | ||
270 | + result2 = isisHeader.irpDiscriminator(); | ||
271 | + assertThat(result2, is((byte) 1)); | ||
272 | + } | ||
273 | + | ||
274 | + /** | ||
275 | + * Tests irpDiscriminator() setter method. | ||
276 | + */ | ||
277 | + @Test | ||
278 | + public void testIsisPduType() throws Exception { | ||
279 | + isisHeader.setIsisPduType(IsisPduType.L1HELLOPDU.value()); | ||
280 | + result3 = isisHeader.isisPduType(); | ||
281 | + assertThat(result3, is(IsisPduType.L1HELLOPDU)); | ||
282 | + } | ||
283 | + | ||
284 | + /** | ||
285 | + * Tests readFrom() method. | ||
286 | + */ | ||
287 | + @Test | ||
288 | + public void testReadFrom() throws Exception { | ||
289 | + isisHeader.readFrom(channelBuffer); | ||
290 | + assertThat(isisHeader, is(notNullValue())); | ||
291 | + } | ||
292 | + | ||
293 | + /** | ||
294 | + * Tests asBytes() method. | ||
295 | + */ | ||
296 | + @Test | ||
297 | + public void testAsBytes() throws Exception { | ||
298 | + isisHeader.asBytes(); | ||
299 | + assertThat(isisHeader, is(notNullValue())); | ||
300 | + } | ||
301 | + | ||
302 | + /** | ||
303 | + * Tests populateHeader() method. | ||
304 | + */ | ||
305 | + @Test | ||
306 | + public void testPopulateHeader() throws Exception { | ||
307 | + isisHeader.populateHeader(new IsisHeader()); | ||
308 | + assertThat(isisHeader, is(notNullValue())); | ||
309 | + } | ||
310 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/test/java/org/onosproject/isis/io/isispacket/IsisMessageReaderTest.java
0 → 100644
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.isis.io.isispacket; | ||
17 | + | ||
18 | +import com.google.common.primitives.Bytes; | ||
19 | +import org.easymock.EasyMock; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
22 | +import org.junit.After; | ||
23 | +import org.junit.Before; | ||
24 | +import org.junit.Test; | ||
25 | +import org.onosproject.isis.controller.IsisMessage; | ||
26 | +import org.onosproject.isis.io.isispacket.pdu.Csnp; | ||
27 | +import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; | ||
28 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
29 | +import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu; | ||
30 | +import org.onosproject.isis.io.isispacket.pdu.Psnp; | ||
31 | +import org.onosproject.isis.io.util.IsisUtil; | ||
32 | + | ||
33 | +import static org.hamcrest.CoreMatchers.instanceOf; | ||
34 | +import static org.hamcrest.CoreMatchers.is; | ||
35 | +import static org.junit.Assert.assertThat; | ||
36 | + | ||
37 | +/** | ||
38 | + * Unit test class for IsisMessageReader. | ||
39 | + */ | ||
40 | +public class IsisMessageReaderTest { | ||
41 | + | ||
42 | + private final byte[] helloP2P = { | ||
43 | + -125, 20, 1, 0, 17, 1, 0, 0, | ||
44 | + 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3, | ||
45 | + 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102, 8, -1, | ||
46 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
114 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
115 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
116 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
117 | + 0, 0, 0, 0, 0, 0, 0, 8, -81, 0, 0, 0, 0, 0, 0, 0, 0, | ||
118 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
119 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
120 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
121 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
122 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
123 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
124 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
125 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
126 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
127 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
128 | + }; | ||
129 | + private final byte[] helloL1L2 = { | ||
130 | + -125, 27, 1, 0, 15, 1, 0, 0, 1, 34, 34, 34, 34, 34, 34, 0, | ||
131 | + 30, 5, -39, 64, 34, 34, 34, 34, 34, 34, 1, -127, 1, -52, 1, | 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
186 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
187 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
188 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
189 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, -93, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
190 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
191 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
192 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
193 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
194 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
195 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
196 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
197 | + }; | ||
198 | + private final byte[] l1Lsp = { | ||
199 | + -125, 27, 1, 0, 18, 1, 0, 0, 0, 86, 4, -81, 34, 34, 34, | ||
200 | + 34, 34, 34, 0, 0, 0, 0, 0, 9, 99, 11, 1, 1, 4, 3, 73, | ||
201 | + 0, 10, -127, 1, -52, -119, 2, 82, 50, -124, 4, -64, -88, 10, 1, -128, | ||
202 | + 24, 10, -128, -128, -128, 10, 0, 10, 0, -1, -1, -1, -4, 10, -128, -128, | ||
203 | + -128, -64, -88, 10, 0, -1, -1, -1, 0, 2, 12, 0, 10, -128, -128, -128, | ||
204 | + 51, 51, 51, 51, 51, 51, 2 | ||
205 | + }; | ||
206 | + private final byte[] csnp = { | ||
207 | + -125, 33, 1, 6, 25, 1, 0, 3, 0, 67, 18, 52, 18, 52, 0, | ||
208 | + 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, | ||
209 | + -1, -1, 9, 32, 4, -81, 18, 52, 18, 52, 0, 18, 0, 0, 0, | ||
210 | + 0, 0, 41, -92, -30, 4, -81, 41, 41, 41, 41, 41, 41, 0, | ||
211 | + 0, 0, 0, 0, 1, 91, 126 | ||
212 | + }; | ||
213 | + private final byte[] psnp = { | ||
214 | + -125, 17, 1, 0, 27, 1, 0, 0, 0, 35, 41, 41, | ||
215 | + 41, 41, 41, 41, 0, 9, 16, 4, -81, 18, 52, 18, | ||
216 | + 52, 0, 18, 0, 0, 0, 0, 0, 42, -94, -29 | ||
217 | + | ||
218 | + }; | ||
219 | + private IsisMessageReader reader; | ||
220 | + private ChannelBuffer channelBuffer; | ||
221 | + private IsisMessage message; | ||
222 | + | ||
223 | + @Before | ||
224 | + public void setUp() throws Exception { | ||
225 | + reader = new IsisMessageReader(); | ||
226 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
227 | + } | ||
228 | + | ||
229 | + @After | ||
230 | + public void tearDown() throws Exception { | ||
231 | + reader = null; | ||
232 | + channelBuffer = null; | ||
233 | + message = null; | ||
234 | + } | ||
235 | + | ||
236 | + /** | ||
237 | + * Tests readFromBuffer() method. | ||
238 | + */ | ||
239 | + @Test | ||
240 | + public void testReadFromBuffer() throws Exception { | ||
241 | + channelBuffer = ChannelBuffers.copiedBuffer(helloP2P); | ||
242 | + message = reader.readFromBuffer(channelBuffer); | ||
243 | + assertThat(message, is(instanceOf(P2PHelloPdu.class))); | ||
244 | + | ||
245 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
246 | + message = reader.readFromBuffer(channelBuffer); | ||
247 | + assertThat(message, is(instanceOf(L1L2HelloPdu.class))); | ||
248 | + | ||
249 | + byte[] tlv1 = Bytes.concat(l1Lsp, (IsisUtil.getPaddingTlvs(l1Lsp.length))); | ||
250 | + channelBuffer = ChannelBuffers.copiedBuffer(tlv1); | ||
251 | + message = reader.readFromBuffer(channelBuffer); | ||
252 | + assertThat(message, is(instanceOf(LsPdu.class))); | ||
253 | + | ||
254 | + tlv1 = Bytes.concat(csnp, (IsisUtil.getPaddingTlvs(csnp.length))); | ||
255 | + channelBuffer = ChannelBuffers.copiedBuffer(tlv1); | ||
256 | + message = reader.readFromBuffer(channelBuffer); | ||
257 | + assertThat(message, is(instanceOf(Csnp.class))); | ||
258 | + | ||
259 | + tlv1 = Bytes.concat(psnp, (IsisUtil.getPaddingTlvs(psnp.length))); | ||
260 | + channelBuffer = ChannelBuffers.copiedBuffer(tlv1); | ||
261 | + message = reader.readFromBuffer(channelBuffer); | ||
262 | + assertThat(message, is(instanceOf(Psnp.class))); | ||
263 | + } | ||
264 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.isis.io.isispacket.pdu; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
21 | +import org.junit.After; | ||
22 | +import org.junit.Before; | ||
23 | +import org.junit.Test; | ||
24 | +import org.onosproject.isis.controller.IsisPduType; | ||
25 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
29 | + | ||
30 | +import java.util.List; | ||
31 | + | ||
32 | +import static org.hamcrest.CoreMatchers.is; | ||
33 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
34 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
35 | + | ||
36 | +/** | ||
37 | + * Unit test class for Csnp. | ||
38 | + */ | ||
39 | +public class CsnpTest { | ||
40 | + | ||
41 | + private final String srcId = "1111.1111.1111"; | ||
42 | + private final byte[] csnpBytes = { | ||
43 | + 0, 67, 18, 52, 18, 52, 0, 0, 67, 18, 52, 18, 52, 0, | ||
44 | + 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, | ||
45 | + -1, -1, 9, 32, 4, -81, 18, 52, 18, 52, 0, 18, 0, 0, 0, | ||
46 | + 0, 0, 41, -92, -30, 4, -81, 41, 41, 41, 41, 41, 41, 0, | ||
47 | + 0, 0, 0, 0, 1, 91, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
48 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
49 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
50 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
51 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
52 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
53 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
54 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
55 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
56 | + 0, 0, 0 | ||
57 | + }; | ||
58 | + private Csnp csnp; | ||
59 | + private IsisHeader isisHeader; | ||
60 | + private IsisTlv isisTlv; | ||
61 | + private TlvHeader tlvHeader; | ||
62 | + private List<IsisTlv> resultList; | ||
63 | + private String resultStr; | ||
64 | + private int resultInt; | ||
65 | + private ChannelBuffer channelBuffer; | ||
66 | + private byte[] result; | ||
67 | + | ||
68 | + @Before | ||
69 | + public void setUp() throws Exception { | ||
70 | + isisHeader = new IsisHeader(); | ||
71 | + isisHeader.setIsisPduType(IsisPduType.L1CSNP.value()); | ||
72 | + csnp = new Csnp(isisHeader); | ||
73 | + tlvHeader = new TlvHeader(); | ||
74 | + isisTlv = new AdjacencyStateTlv(tlvHeader); | ||
75 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
76 | + } | ||
77 | + | ||
78 | + @After | ||
79 | + public void tearDown() throws Exception { | ||
80 | + isisHeader = null; | ||
81 | + csnp = null; | ||
82 | + tlvHeader = null; | ||
83 | + isisTlv = null; | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Tests getAllTlv() method. | ||
88 | + */ | ||
89 | + @Test | ||
90 | + public void testGetAllTlv() throws Exception { | ||
91 | + channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); | ||
92 | + csnp.readFrom(channelBuffer); | ||
93 | + resultList = csnp.getAllTlv(); | ||
94 | + assertThat(resultList.size(), is(0)); | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * Tests sourceId() getter method. | ||
99 | + */ | ||
100 | + @Test | ||
101 | + public void testSourceId() throws Exception { | ||
102 | + csnp.setSourceId(srcId); | ||
103 | + resultStr = csnp.sourceId(); | ||
104 | + assertThat(resultStr, is(srcId)); | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * Tests sourceId() setter method. | ||
109 | + */ | ||
110 | + @Test | ||
111 | + public void testSetSourceId() throws Exception { | ||
112 | + csnp.setSourceId(srcId); | ||
113 | + resultStr = csnp.sourceId(); | ||
114 | + assertThat(resultStr, is(srcId)); | ||
115 | + } | ||
116 | + | ||
117 | + | ||
118 | + /** | ||
119 | + * Tests startLspId() getter method. | ||
120 | + */ | ||
121 | + @Test | ||
122 | + public void testStartLspId() throws Exception { | ||
123 | + csnp.setStartLspId(srcId); | ||
124 | + resultStr = csnp.startLspId(); | ||
125 | + assertThat(resultStr, is(srcId)); | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Tests startLspId() setter method. | ||
130 | + */ | ||
131 | + @Test | ||
132 | + public void testSetStartLspId() throws Exception { | ||
133 | + csnp.setStartLspId(srcId); | ||
134 | + resultStr = csnp.startLspId(); | ||
135 | + assertThat(resultStr, is(srcId)); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Tests endLspId() getter method. | ||
140 | + */ | ||
141 | + @Test | ||
142 | + public void testEndLspId() throws Exception { | ||
143 | + csnp.setEndLspId(srcId); | ||
144 | + resultStr = csnp.endLspId(); | ||
145 | + assertThat(resultStr, is(srcId)); | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Tests endLspId() setter method. | ||
150 | + */ | ||
151 | + @Test | ||
152 | + public void testSetEndLspId() throws Exception { | ||
153 | + csnp.setEndLspId(srcId); | ||
154 | + resultStr = csnp.endLspId(); | ||
155 | + assertThat(resultStr, is(srcId)); | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * Tests pduLength() getter method. | ||
160 | + */ | ||
161 | + @Test | ||
162 | + public void testPduLength() throws Exception { | ||
163 | + csnp.setPduLength(10); | ||
164 | + resultInt = csnp.pduLength(); | ||
165 | + assertThat(resultInt, is(10)); | ||
166 | + } | ||
167 | + | ||
168 | + /** | ||
169 | + * Tests pduLength() setter method. | ||
170 | + */ | ||
171 | + @Test | ||
172 | + public void testSetPduLength() throws Exception { | ||
173 | + csnp.setPduLength(10); | ||
174 | + resultInt = csnp.pduLength(); | ||
175 | + assertThat(resultInt, is(10)); | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * Tests readFrom() method. | ||
180 | + */ | ||
181 | + @Test | ||
182 | + public void testReadFrom() throws Exception { | ||
183 | + channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); | ||
184 | + csnp.readFrom(channelBuffer); | ||
185 | + assertThat(csnp, is(notNullValue())); | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * Tests asBytes() method. | ||
190 | + */ | ||
191 | + @Test | ||
192 | + public void testAsBytes() throws Exception { | ||
193 | + channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); | ||
194 | + csnp.readFrom(channelBuffer); | ||
195 | + result = csnp.asBytes(); | ||
196 | + assertThat(csnp, is(notNullValue())); | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * Tests isisPduHeader() method. | ||
201 | + */ | ||
202 | + @Test | ||
203 | + public void testIsisPduHeader() throws Exception { | ||
204 | + result = csnp.isisPduHeader(); | ||
205 | + assertThat(result, is(notNullValue())); | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * Tests completeSequenceNumberPduBody() method. | ||
210 | + */ | ||
211 | + @Test | ||
212 | + public void testCompleteSequenceNumberPduBody() throws Exception { | ||
213 | + channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); | ||
214 | + csnp.readFrom(channelBuffer); | ||
215 | + result = csnp.completeSequenceNumberPduBody(); | ||
216 | + assertThat(result, is(notNullValue())); | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * Tests toString() method. | ||
221 | + */ | ||
222 | + @Test | ||
223 | + public void testToString() throws Exception { | ||
224 | + assertThat((csnp.toString()), is(notNullValue())); | ||
225 | + } | ||
226 | + | ||
227 | + /** | ||
228 | + * Tests equals() method. | ||
229 | + */ | ||
230 | + @Test | ||
231 | + public void testEquals() throws Exception { | ||
232 | + assertThat(csnp.equals(new Csnp(new IsisHeader())), is(true)); | ||
233 | + } | ||
234 | + | ||
235 | + /** | ||
236 | + * Tests hashCode() method. | ||
237 | + */ | ||
238 | + @Test | ||
239 | + public void testHashCode() throws Exception { | ||
240 | + int hashCode = csnp.hashCode(); | ||
241 | + assertThat(hashCode, is(notNullValue())); | ||
242 | + } | ||
243 | +} | ||
244 | + | ||
245 | + | ||
246 | + |
protocols/isis/isisio/src/test/java/org/onosproject/isis/io/isispacket/pdu/HelloPduTest.java
0 → 100644
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.isis.io.isispacket.pdu; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
21 | +import org.junit.After; | ||
22 | +import org.junit.Before; | ||
23 | +import org.junit.Test; | ||
24 | +import org.onlab.packet.Ip4Address; | ||
25 | +import org.onlab.packet.MacAddress; | ||
26 | +import org.onosproject.isis.controller.IsisInterfaceState; | ||
27 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; | ||
29 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
30 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
31 | + | ||
32 | +import java.util.List; | ||
33 | + | ||
34 | +import static org.hamcrest.CoreMatchers.*; | ||
35 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
36 | + | ||
37 | +/** | ||
38 | + * Unit test class for HelloPdu. | ||
39 | + */ | ||
40 | +public class HelloPduTest { | ||
41 | + | ||
42 | + private final byte[] macAddr = new byte[]{ | ||
43 | + (byte) 0xa4, (byte) 0x22, (byte) 0xc2, 0x00, 0x00, 0x00 | ||
44 | + }; | ||
45 | + private final String srcId = "1111.1111.1111"; | ||
46 | + private final byte[] helloL1L2 = { | ||
47 | + 1, 34, 34, 34, 34, 34, 34, 0, | ||
48 | + 30, 5, -39, 64, 34, 34, 34, 34, 34, 34, 1, -127, 1, -52, 1, | ||
49 | + 4, 3, 73, 0, 10, -124, 4, 10, 0, 10, 2, -45, 3, 0, 0, 0, | ||
50 | + 8, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
51 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
52 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
53 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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, 0, 0, 0, 0, | ||
107 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
108 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
109 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
110 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
111 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
112 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
113 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
114 | + }; | ||
115 | + | ||
116 | + private HelloPdu helloPdu; | ||
117 | + private IsisHeader isisHeader; | ||
118 | + private IsisTlv isisTlv; | ||
119 | + private TlvHeader tlvHeader; | ||
120 | + private MacAddress macAddress; | ||
121 | + private List<IsisTlv> resultList; | ||
122 | + private List<String> resultListStr; | ||
123 | + private List<Ip4Address> resultListIPv4; | ||
124 | + private List<MacAddress> resultListMac; | ||
125 | + private IsisInterfaceState resultAdjState; | ||
126 | + private String resultStr; | ||
127 | + private int resultInt; | ||
128 | + private byte resultByte; | ||
129 | + private ChannelBuffer channelBuffer; | ||
130 | + private HelloPdu pdu; | ||
131 | + | ||
132 | + @Before | ||
133 | + public void setUp() throws Exception { | ||
134 | + isisHeader = new IsisHeader(); | ||
135 | + helloPdu = new L1L2HelloPdu(isisHeader); | ||
136 | + tlvHeader = new TlvHeader(); | ||
137 | + isisTlv = new AdjacencyStateTlv(tlvHeader); | ||
138 | + macAddress = new MacAddress(macAddr); | ||
139 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
140 | + pdu = helloPdu; | ||
141 | + } | ||
142 | + | ||
143 | + @After | ||
144 | + public void tearDown() throws Exception { | ||
145 | + isisHeader = null; | ||
146 | + helloPdu = null; | ||
147 | + isisTlv = null; | ||
148 | + tlvHeader = null; | ||
149 | + macAddress = null; | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Tests addTlv() getter method. | ||
154 | + */ | ||
155 | + @Test | ||
156 | + public void testAddTlv() throws Exception { | ||
157 | + helloPdu.addTlv(isisTlv); | ||
158 | + resultList = helloPdu.tlvs(); | ||
159 | + assertThat(resultList.size(), is(1)); | ||
160 | + } | ||
161 | + | ||
162 | + /** | ||
163 | + * Tests tlvs() method. | ||
164 | + */ | ||
165 | + @Test | ||
166 | + public void testTlvs() throws Exception { | ||
167 | + helloPdu.addTlv(isisTlv); | ||
168 | + resultList = helloPdu.tlvs(); | ||
169 | + assertThat(resultList.size(), is(1)); | ||
170 | + } | ||
171 | + | ||
172 | + /** | ||
173 | + * Tests areaAddres() method. | ||
174 | + */ | ||
175 | + @Test | ||
176 | + public void testAreaAddress() throws Exception { | ||
177 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
178 | + helloPdu.readFrom(channelBuffer); | ||
179 | + resultListStr = helloPdu.areaAddress(); | ||
180 | + assertThat(resultListStr.size(), is(1)); | ||
181 | + } | ||
182 | + | ||
183 | + /** | ||
184 | + * Tests interfaceIpAddresse() method. | ||
185 | + */ | ||
186 | + @Test | ||
187 | + public void testInterfaceIpAddresses() throws Exception { | ||
188 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
189 | + helloPdu.readFrom(channelBuffer); | ||
190 | + resultListIPv4 = helloPdu.interfaceIpAddresses(); | ||
191 | + assertThat(resultListIPv4.size(), is(1)); | ||
192 | + } | ||
193 | + | ||
194 | + /** | ||
195 | + * Tests neighborList() method. | ||
196 | + */ | ||
197 | + @Test | ||
198 | + public void testNeighborList() throws Exception { | ||
199 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
200 | + helloPdu.readFrom(channelBuffer); | ||
201 | + resultListMac = helloPdu.neighborList(); | ||
202 | + assertThat(resultListMac, is(nullValue())); | ||
203 | + } | ||
204 | + | ||
205 | + /** | ||
206 | + * Tests adjacencyState() method. | ||
207 | + */ | ||
208 | + @Test | ||
209 | + public void testAdjacencyState() throws Exception { | ||
210 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
211 | + helloPdu.readFrom(channelBuffer); | ||
212 | + resultAdjState = helloPdu.adjacencyState(); | ||
213 | + assertThat(resultAdjState, is(nullValue())); | ||
214 | + } | ||
215 | + | ||
216 | + /** | ||
217 | + * Tests sourceId() getter method. | ||
218 | + */ | ||
219 | + @Test | ||
220 | + public void testSourceId() throws Exception { | ||
221 | + helloPdu.setSourceId(srcId); | ||
222 | + resultStr = helloPdu.sourceId(); | ||
223 | + assertThat(resultStr, is(srcId)); | ||
224 | + } | ||
225 | + | ||
226 | + /** | ||
227 | + * Tests sourceId() setter method. | ||
228 | + */ | ||
229 | + @Test | ||
230 | + public void testSetSourceId() throws Exception { | ||
231 | + helloPdu.setSourceId(srcId); | ||
232 | + resultStr = helloPdu.sourceId(); | ||
233 | + assertThat(resultStr, is(srcId)); | ||
234 | + } | ||
235 | + | ||
236 | + /** | ||
237 | + * Tests pduLength() getter method. | ||
238 | + */ | ||
239 | + @Test | ||
240 | + public void testPduLength() throws Exception { | ||
241 | + helloPdu.setPduLength(10); | ||
242 | + resultInt = helloPdu.pduLength(); | ||
243 | + assertThat(resultInt, is(10)); | ||
244 | + | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
248 | + * Tests pduLength() setter method. | ||
249 | + */ | ||
250 | + @Test | ||
251 | + public void testSetPduLength() throws Exception { | ||
252 | + helloPdu.setPduLength(10); | ||
253 | + resultInt = helloPdu.pduLength(); | ||
254 | + assertThat(resultInt, is(10)); | ||
255 | + } | ||
256 | + | ||
257 | + /** | ||
258 | + * Tests holdingTime() getter method. | ||
259 | + */ | ||
260 | + @Test | ||
261 | + public void testHoldingTime() throws Exception { | ||
262 | + helloPdu.setHoldingTime(10); | ||
263 | + resultInt = helloPdu.holdingTime(); | ||
264 | + assertThat(resultInt, is(10)); | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
268 | + * Tests holdingTime() setter method. | ||
269 | + */ | ||
270 | + @Test | ||
271 | + public void testSetHoldingTime() throws Exception { | ||
272 | + helloPdu.setHoldingTime(10); | ||
273 | + resultInt = helloPdu.holdingTime(); | ||
274 | + assertThat(resultInt, is(10)); | ||
275 | + } | ||
276 | + | ||
277 | + /** | ||
278 | + * Tests circuitType() getter method. | ||
279 | + */ | ||
280 | + @Test | ||
281 | + public void testCircuitType() throws Exception { | ||
282 | + helloPdu.setCircuitType((byte) 1); | ||
283 | + resultByte = helloPdu.circuitType(); | ||
284 | + assertThat(resultByte, is((byte) 1)); | ||
285 | + } | ||
286 | + | ||
287 | + /** | ||
288 | + * Tests circuitType() setter method. | ||
289 | + */ | ||
290 | + @Test | ||
291 | + public void testSetCircuitType() throws Exception { | ||
292 | + helloPdu.setCircuitType((byte) 1); | ||
293 | + resultByte = helloPdu.circuitType(); | ||
294 | + assertThat(resultByte, is((byte) 1)); | ||
295 | + } | ||
296 | + | ||
297 | + /** | ||
298 | + * Tests toString() getter method. | ||
299 | + */ | ||
300 | + @Test | ||
301 | + public void testToString() throws Exception { | ||
302 | + pdu = helloPdu; | ||
303 | + assertThat(pdu.toString(), is(notNullValue())); | ||
304 | + } | ||
305 | + | ||
306 | + /** | ||
307 | + * Tests equals() method. | ||
308 | + */ | ||
309 | + @Test | ||
310 | + public void testEquals() throws Exception { | ||
311 | + pdu = helloPdu; | ||
312 | + assertThat(pdu.equals(new L1L2HelloPdu(new IsisHeader())), is(true)); | ||
313 | + } | ||
314 | + | ||
315 | + /** | ||
316 | + * Tests hashCode() method. | ||
317 | + */ | ||
318 | + @Test | ||
319 | + public void testHashCode() throws Exception { | ||
320 | + pdu = helloPdu; | ||
321 | + resultInt = pdu.hashCode(); | ||
322 | + assertThat(resultInt, is(notNullValue())); | ||
323 | + } | ||
324 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/isisio/src/test/java/org/onosproject/isis/io/isispacket/pdu/L1L2HelloPduTest.java
0 → 100644
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.isis.io.isispacket.pdu; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
21 | +import org.junit.After; | ||
22 | +import org.junit.Before; | ||
23 | +import org.junit.Test; | ||
24 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
25 | + | ||
26 | +import static org.hamcrest.CoreMatchers.is; | ||
27 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
28 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
29 | + | ||
30 | +/** | ||
31 | + * Unit test class for L1L2HelloPdu. | ||
32 | + */ | ||
33 | +public class L1L2HelloPduTest { | ||
34 | + private final String lanId = "1111.1111.1111"; | ||
35 | + private final byte[] helloL1L2 = { | ||
36 | + 1, 34, 34, 34, 34, 34, 34, 0, | ||
37 | + 30, 5, -39, 64, 34, 34, 34, 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, 0, 0, 0, 0, 0, 0, 0, | ||
92 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
93 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
94 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
95 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, -93, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
96 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
97 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
98 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
99 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
100 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
101 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
102 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
103 | + }; | ||
104 | + private L1L2HelloPdu l1L2HelloPdu; | ||
105 | + private IsisHeader isisHeader; | ||
106 | + private String resultStr; | ||
107 | + private byte resultByte; | ||
108 | + private int resultInt; | ||
109 | + private ChannelBuffer channelBuffer; | ||
110 | + private byte[] result; | ||
111 | + | ||
112 | + @Before | ||
113 | + public void setUp() throws Exception { | ||
114 | + isisHeader = new IsisHeader(); | ||
115 | + isisHeader.setIsisPduType(15); | ||
116 | + l1L2HelloPdu = new L1L2HelloPdu(isisHeader); | ||
117 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
118 | + } | ||
119 | + | ||
120 | + @After | ||
121 | + public void tearDown() throws Exception { | ||
122 | + isisHeader = null; | ||
123 | + l1L2HelloPdu = null; | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * Tests setLanId() getter method. | ||
128 | + */ | ||
129 | + @Test | ||
130 | + public void testLanId() throws Exception { | ||
131 | + l1L2HelloPdu.setLanId(lanId); | ||
132 | + resultStr = l1L2HelloPdu.lanId(); | ||
133 | + assertThat(resultStr, is(lanId)); | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
137 | + * Tests setLanId() setter method. | ||
138 | + */ | ||
139 | + @Test | ||
140 | + public void testSetLanId() throws Exception { | ||
141 | + l1L2HelloPdu.setLanId(lanId); | ||
142 | + resultStr = l1L2HelloPdu.lanId(); | ||
143 | + assertThat(resultStr, is(lanId)); | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * Tests priority() getter method. | ||
148 | + */ | ||
149 | + @Test | ||
150 | + public void testPriority() throws Exception { | ||
151 | + l1L2HelloPdu.setPriority((byte) 1); | ||
152 | + resultByte = l1L2HelloPdu.priority(); | ||
153 | + assertThat(resultByte, is((byte) 1)); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Tests priority() setter method. | ||
158 | + */ | ||
159 | + @Test | ||
160 | + public void testSetPriority() throws Exception { | ||
161 | + l1L2HelloPdu.setPriority((byte) 1); | ||
162 | + resultByte = l1L2HelloPdu.priority(); | ||
163 | + assertThat(resultByte, is((byte) 1)); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Tests readFrom() method. | ||
168 | + */ | ||
169 | + @Test | ||
170 | + public void testReadFrom() throws Exception { | ||
171 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
172 | + l1L2HelloPdu.readFrom(channelBuffer); | ||
173 | + assertThat(l1L2HelloPdu, is(notNullValue())); | ||
174 | + } | ||
175 | + | ||
176 | + /** | ||
177 | + * Tests asByte() method. | ||
178 | + */ | ||
179 | + @Test | ||
180 | + public void testAsBytes() throws Exception { | ||
181 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
182 | + l1L2HelloPdu.readFrom(channelBuffer); | ||
183 | + result = l1L2HelloPdu.asBytes(); | ||
184 | + assertThat(l1L2HelloPdu, is(notNullValue())); | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Tests l1l2IsisPduHeader() method. | ||
189 | + */ | ||
190 | + @Test | ||
191 | + public void testL1l2IsisPduHeader() throws Exception { | ||
192 | + result = l1L2HelloPdu.l1l2IsisPduHeader(); | ||
193 | + assertThat(l1L2HelloPdu, is(notNullValue())); | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Tests l1l2HelloPduBody() method. | ||
198 | + */ | ||
199 | + @Test | ||
200 | + public void testL1l2HelloPduBody() throws Exception { | ||
201 | + channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); | ||
202 | + l1L2HelloPdu.readFrom(channelBuffer); | ||
203 | + result = l1L2HelloPdu.l1l2HelloPduBody(); | ||
204 | + assertThat(result, is(notNullValue())); | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * Tests toString() method. | ||
209 | + */ | ||
210 | + @Test | ||
211 | + public void testToString() throws Exception { | ||
212 | + assertThat(l1L2HelloPdu.toString(), is(notNullValue())); | ||
213 | + } | ||
214 | + | ||
215 | + /** | ||
216 | + * Tests equals() method. | ||
217 | + */ | ||
218 | + @Test | ||
219 | + public void testEquals() throws Exception { | ||
220 | + assertThat(l1L2HelloPdu.equals(new L1L2HelloPdu(new IsisHeader())), is(true)); | ||
221 | + } | ||
222 | + | ||
223 | + /** | ||
224 | + * Tests hashCode() method. | ||
225 | + */ | ||
226 | + @Test | ||
227 | + public void testHashCode() throws Exception { | ||
228 | + resultInt = l1L2HelloPdu.hashCode(); | ||
229 | + assertThat(resultInt, is(notNullValue())); | ||
230 | + } | ||
231 | +} |
protocols/isis/isisio/src/test/java/org/onosproject/isis/io/isispacket/pdu/LsPduTest.java
0 → 100644
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 | + | ||
17 | +package org.onosproject.isis.io.isispacket.pdu; | ||
18 | + | ||
19 | +import org.easymock.EasyMock; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
22 | +import org.junit.After; | ||
23 | +import org.junit.Before; | ||
24 | +import org.junit.Test; | ||
25 | +import org.onosproject.isis.controller.IsisPduType; | ||
26 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.HostNameTlv; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
29 | + | ||
30 | +import static org.hamcrest.CoreMatchers.is; | ||
31 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
32 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
33 | + | ||
34 | +/** | ||
35 | + * Unit test class for LsPdu. | ||
36 | + */ | ||
37 | +public class LsPduTest { | ||
38 | + private final String lspId = "1111.1111.1111"; | ||
39 | + private final byte[] l1Lsp = { | ||
40 | + 0, 86, 4, -81, 34, 34, 34, 34, 34, 34, 0, 0, 0, 0, 0, 9, 99, 11, 1, 1, 4, 3, 73, | ||
41 | + 0, 10, -127, 1, -52, -119, 2, 82, 50, -124, 4, -64, -88, 10, 1, -128, 24, 10, | ||
42 | + -128, -128, -128, 10, 0, 10, 0, -1, -1, -1, -4, 10, -128, -128, -128, -64, -88, | ||
43 | + 10, 0, -1, -1, -1, 0, 2, 12, 0, 10, -128, -128, -128, 51, 51, 51, 51, 51, 51, 2 | ||
44 | + }; | ||
45 | + private LsPdu lsPdu; | ||
46 | + private IsisHeader isisHeader; | ||
47 | + private TlvHeader tlvHeader; | ||
48 | + private int resultInt; | ||
49 | + private boolean resultBool; | ||
50 | + private byte resultByte; | ||
51 | + private AttachedToOtherAreas resultObj; | ||
52 | + private String resultStr; | ||
53 | + private ChannelBuffer channelBuffer; | ||
54 | + private byte[] result; | ||
55 | + | ||
56 | + @Before | ||
57 | + public void setUp() throws Exception { | ||
58 | + isisHeader = new IsisHeader(); | ||
59 | + tlvHeader = new TlvHeader(); | ||
60 | + isisHeader.setIsisPduType(IsisPduType.L1LSPDU.value()); | ||
61 | + lsPdu = new LsPdu(isisHeader); | ||
62 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
63 | + } | ||
64 | + | ||
65 | + @After | ||
66 | + public void tearDown() throws Exception { | ||
67 | + isisHeader = null; | ||
68 | + lsPdu = null; | ||
69 | + tlvHeader = null; | ||
70 | + channelBuffer = null; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Tests addTlv() method. | ||
75 | + */ | ||
76 | + @Test | ||
77 | + public void testAddTlv() throws Exception { | ||
78 | + lsPdu.addTlv(new HostNameTlv(tlvHeader)); | ||
79 | + assertThat(lsPdu, is(notNullValue())); | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * Tests remainingLifeTime() getter method. | ||
84 | + */ | ||
85 | + @Test | ||
86 | + public void testRemainingLifeTime() throws Exception { | ||
87 | + lsPdu.setRemainingLifeTime(10); | ||
88 | + resultInt = lsPdu.remainingLifeTime(); | ||
89 | + assertThat(resultInt, is(10)); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Tests remainingLifeTime() setter method. | ||
94 | + */ | ||
95 | + @Test | ||
96 | + public void testSetRemainingLifeTime() throws Exception { | ||
97 | + lsPdu.setRemainingLifeTime(10); | ||
98 | + resultInt = lsPdu.remainingLifeTime(); | ||
99 | + assertThat(resultInt, is(10)); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Tests lspDbol() getter method. | ||
104 | + */ | ||
105 | + @Test | ||
106 | + public void testLspDbol() throws Exception { | ||
107 | + lsPdu.setLspDbol(true); | ||
108 | + resultBool = lsPdu.lspDbol(); | ||
109 | + assertThat(resultBool, is(true)); | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Tests lspDbol() setter method. | ||
114 | + */ | ||
115 | + @Test | ||
116 | + public void testSetLspDbol() throws Exception { | ||
117 | + lsPdu.setLspDbol(true); | ||
118 | + resultBool = lsPdu.lspDbol(); | ||
119 | + assertThat(resultBool, is(true)); | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Tests typeBlock() getter method. | ||
124 | + */ | ||
125 | + @Test | ||
126 | + public void testTypeBlock() throws Exception { | ||
127 | + lsPdu.setTypeBlock((byte) 1); | ||
128 | + resultByte = lsPdu.typeBlock(); | ||
129 | + assertThat(resultByte, is((byte) 1)); | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Tests typeBlock() setter method. | ||
134 | + */ | ||
135 | + @Test | ||
136 | + public void testSetTypeBlock() throws Exception { | ||
137 | + lsPdu.setTypeBlock((byte) 1); | ||
138 | + resultByte = lsPdu.typeBlock(); | ||
139 | + assertThat(resultByte, is((byte) 1)); | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Tests sequenceNumber() getter method. | ||
144 | + */ | ||
145 | + @Test | ||
146 | + public void testSequenceNumber() throws Exception { | ||
147 | + lsPdu.setSequenceNumber(1); | ||
148 | + resultInt = lsPdu.sequenceNumber(); | ||
149 | + assertThat(resultInt, is(1)); | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Tests sequenceNumber() setter method. | ||
154 | + */ | ||
155 | + @Test | ||
156 | + public void testSetSequenceNumber() throws Exception { | ||
157 | + lsPdu.setSequenceNumber(1); | ||
158 | + resultInt = lsPdu.sequenceNumber(); | ||
159 | + assertThat(resultInt, is(1)); | ||
160 | + } | ||
161 | + | ||
162 | + /** | ||
163 | + * Tests checkSum() getter method. | ||
164 | + */ | ||
165 | + @Test | ||
166 | + public void testCheckSum() throws Exception { | ||
167 | + lsPdu.setCheckSum(1); | ||
168 | + resultInt = lsPdu.checkSum(); | ||
169 | + assertThat(resultInt, is(1)); | ||
170 | + } | ||
171 | + | ||
172 | + /** | ||
173 | + * Tests checkSum() setter method. | ||
174 | + */ | ||
175 | + @Test | ||
176 | + public void testSetCheckSum() throws Exception { | ||
177 | + lsPdu.setCheckSum(1); | ||
178 | + resultInt = lsPdu.checkSum(); | ||
179 | + assertThat(resultInt, is(1)); | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * Tests partitionRepair() getter method. | ||
184 | + */ | ||
185 | + @Test | ||
186 | + public void testPartitionRepair() throws Exception { | ||
187 | + lsPdu.setPartitionRepair(true); | ||
188 | + resultBool = lsPdu.partitionRepair(); | ||
189 | + assertThat(resultBool, is(true)); | ||
190 | + } | ||
191 | + | ||
192 | + /** | ||
193 | + * Tests partitionRepair() setter method. | ||
194 | + */ | ||
195 | + @Test | ||
196 | + public void testSetPartitionRepair() throws Exception { | ||
197 | + lsPdu.setPartitionRepair(true); | ||
198 | + resultBool = lsPdu.partitionRepair(); | ||
199 | + assertThat(resultBool, is(true)); | ||
200 | + } | ||
201 | + | ||
202 | + /** | ||
203 | + * Tests attachedToOtherAreas() getter method. | ||
204 | + */ | ||
205 | + @Test | ||
206 | + public void testAttachedToOtherAreas() throws Exception { | ||
207 | + lsPdu.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC); | ||
208 | + resultObj = lsPdu.attachedToOtherAreas(); | ||
209 | + assertThat(resultObj, is(AttachedToOtherAreas.DEFAULTMETRIC)); | ||
210 | + } | ||
211 | + | ||
212 | + /** | ||
213 | + * Tests attachedToOtherAreas() setter method. | ||
214 | + */ | ||
215 | + @Test | ||
216 | + public void testSetAttachedToOtherAreas() throws Exception { | ||
217 | + lsPdu.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC); | ||
218 | + resultObj = lsPdu.attachedToOtherAreas(); | ||
219 | + assertThat(resultObj, is(AttachedToOtherAreas.DEFAULTMETRIC)); | ||
220 | + } | ||
221 | + | ||
222 | + /** | ||
223 | + * Tests intermediateSystemType() getter method. | ||
224 | + */ | ||
225 | + @Test | ||
226 | + public void testIntermediateSystemType() throws Exception { | ||
227 | + lsPdu.setIntermediateSystemType((byte) 1); | ||
228 | + resultByte = lsPdu.intermediateSystemType(); | ||
229 | + assertThat(resultByte, is((byte) 1)); | ||
230 | + } | ||
231 | + | ||
232 | + /** | ||
233 | + * Tests intermediateSystemType() setter method. | ||
234 | + */ | ||
235 | + @Test | ||
236 | + public void testSetIntermediateSystemType() throws Exception { | ||
237 | + lsPdu.setIntermediateSystemType((byte) 1); | ||
238 | + resultByte = lsPdu.intermediateSystemType(); | ||
239 | + assertThat(resultByte, is((byte) 1)); | ||
240 | + } | ||
241 | + | ||
242 | + /** | ||
243 | + * Tests lspId() getter method. | ||
244 | + */ | ||
245 | + @Test | ||
246 | + public void testLspId() throws Exception { | ||
247 | + lsPdu.setLspId(lspId); | ||
248 | + resultStr = lsPdu.lspId(); | ||
249 | + assertThat(resultStr, is(lspId)); | ||
250 | + } | ||
251 | + | ||
252 | + /** | ||
253 | + * Tests lspId() setter method. | ||
254 | + */ | ||
255 | + @Test | ||
256 | + public void testSetLspId() throws Exception { | ||
257 | + lsPdu.setLspId(lspId); | ||
258 | + resultStr = lsPdu.lspId(); | ||
259 | + assertThat(resultStr, is(lspId)); | ||
260 | + } | ||
261 | + | ||
262 | + /** | ||
263 | + * Tests pduLength() getter method. | ||
264 | + */ | ||
265 | + @Test | ||
266 | + public void testPduLength() throws Exception { | ||
267 | + lsPdu.setPduLength(10); | ||
268 | + resultInt = lsPdu.pduLength(); | ||
269 | + assertThat(resultInt, is(10)); | ||
270 | + } | ||
271 | + | ||
272 | + /** | ||
273 | + * Tests pduLength() setter method. | ||
274 | + */ | ||
275 | + @Test | ||
276 | + public void testSetPduLength() throws Exception { | ||
277 | + lsPdu.setPduLength(10); | ||
278 | + resultInt = lsPdu.pduLength(); | ||
279 | + assertThat(resultInt, is(10)); | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
283 | + * Tests readFrom() method. | ||
284 | + */ | ||
285 | + @Test | ||
286 | + public void testReadFrom() throws Exception { | ||
287 | + channelBuffer = ChannelBuffers.copiedBuffer(l1Lsp); | ||
288 | + lsPdu.readFrom(channelBuffer); | ||
289 | + assertThat(lsPdu, is(notNullValue())); | ||
290 | + } | ||
291 | + | ||
292 | + /** | ||
293 | + * Tests asBytes() method. | ||
294 | + */ | ||
295 | + @Test | ||
296 | + public void testAsBytes() throws Exception { | ||
297 | + channelBuffer = ChannelBuffers.copiedBuffer(l1Lsp); | ||
298 | + lsPdu.readFrom(channelBuffer); | ||
299 | + result = lsPdu.asBytes(); | ||
300 | + assertThat(result, is(notNullValue())); | ||
301 | + } | ||
302 | + | ||
303 | + /** | ||
304 | + * Tests l1l2IsisPduHeader() method. | ||
305 | + */ | ||
306 | + @Test | ||
307 | + public void testL1l2IsisPduHeader() throws Exception { | ||
308 | + result = lsPdu.l1l2IsisPduHeader(); | ||
309 | + assertThat(result, is(notNullValue())); | ||
310 | + } | ||
311 | + | ||
312 | + /** | ||
313 | + * Tests l1l2LsPduBody() method. | ||
314 | + */ | ||
315 | + @Test | ||
316 | + public void testL1l2LsPduBody() throws Exception { | ||
317 | + channelBuffer = ChannelBuffers.copiedBuffer(l1Lsp); | ||
318 | + lsPdu.readFrom(channelBuffer); | ||
319 | + result = lsPdu.l1l2LsPduBody(); | ||
320 | + assertThat(result, is(notNullValue())); | ||
321 | + } | ||
322 | + | ||
323 | + /** | ||
324 | + * Tests toString() method. | ||
325 | + */ | ||
326 | + @Test | ||
327 | + public void testToString() throws Exception { | ||
328 | + assertThat(lsPdu.toString(), is(notNullValue())); | ||
329 | + } | ||
330 | + | ||
331 | + /** | ||
332 | + * Tests equals() method. | ||
333 | + */ | ||
334 | + @Test | ||
335 | + public void testEquals() throws Exception { | ||
336 | + assertThat(lsPdu.equals(new LsPdu(new IsisHeader())), is(true)); | ||
337 | + } | ||
338 | + | ||
339 | + /** | ||
340 | + * Tests hashCode() method. | ||
341 | + */ | ||
342 | + @Test | ||
343 | + public void testHashCode() throws Exception { | ||
344 | + resultInt = lsPdu.hashCode(); | ||
345 | + assertThat(resultInt, is(notNullValue())); | ||
346 | + } | ||
347 | +} |
protocols/isis/isisio/src/test/java/org/onosproject/isis/io/isispacket/pdu/P2PHelloPduTest.java
0 → 100644
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 | + | ||
17 | +package org.onosproject.isis.io.isispacket.pdu; | ||
18 | + | ||
19 | +import org.easymock.EasyMock; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
22 | +import org.junit.After; | ||
23 | +import org.junit.Before; | ||
24 | +import org.junit.Test; | ||
25 | +import org.onosproject.isis.controller.IsisPduType; | ||
26 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
27 | + | ||
28 | +import static org.hamcrest.CoreMatchers.is; | ||
29 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
30 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
31 | + | ||
32 | +/** | ||
33 | + * Unit test class for P2PHelloPdu. | ||
34 | + */ | ||
35 | +public class P2PHelloPduTest { | ||
36 | + private final byte[] p2p = { | ||
37 | + 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3, | ||
38 | + 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102, 8, -1, | ||
39 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
40 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
41 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
42 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
43 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
44 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
45 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
46 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
47 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
48 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
116 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
117 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
118 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
119 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
120 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
121 | + }; | ||
122 | + private P2PHelloPdu p2PHelloPdu; | ||
123 | + private IsisHeader isisHeader; | ||
124 | + private byte resultByte; | ||
125 | + private ChannelBuffer channelBuffer; | ||
126 | + private byte[] result; | ||
127 | + private int resultInt; | ||
128 | + | ||
129 | + @Before | ||
130 | + public void setUp() throws Exception { | ||
131 | + isisHeader = new IsisHeader(); | ||
132 | + isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); | ||
133 | + p2PHelloPdu = new P2PHelloPdu(isisHeader); | ||
134 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
135 | + | ||
136 | + | ||
137 | + } | ||
138 | + | ||
139 | + @After | ||
140 | + public void tearDown() throws Exception { | ||
141 | + isisHeader = null; | ||
142 | + p2PHelloPdu = null; | ||
143 | + channelBuffer = null; | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * Tests localCircuitId() getter method. | ||
148 | + */ | ||
149 | + @Test | ||
150 | + public void testLocalCircuitId() throws Exception { | ||
151 | + p2PHelloPdu.setLocalCircuitId((byte) 1); | ||
152 | + resultByte = p2PHelloPdu.localCircuitId(); | ||
153 | + assertThat(resultByte, is((byte) 1)); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Tests localCircuitId() setter method. | ||
158 | + */ | ||
159 | + @Test | ||
160 | + public void testSetLocalCircuitId() throws Exception { | ||
161 | + p2PHelloPdu.setLocalCircuitId((byte) 1); | ||
162 | + resultByte = p2PHelloPdu.localCircuitId(); | ||
163 | + assertThat(resultByte, is((byte) 1)); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Tests setVariableLengths() method. | ||
168 | + */ | ||
169 | + @Test | ||
170 | + public void testSetVariableLengths() throws Exception { | ||
171 | + | ||
172 | + | ||
173 | + } | ||
174 | + | ||
175 | + /** | ||
176 | + * Tests readFrom() method. | ||
177 | + */ | ||
178 | + @Test | ||
179 | + public void testReadFrom() throws Exception { | ||
180 | + channelBuffer = ChannelBuffers.copiedBuffer(p2p); | ||
181 | + p2PHelloPdu.readFrom(channelBuffer); | ||
182 | + assertThat(p2PHelloPdu, is(notNullValue())); | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * Tests asBytes() method. | ||
187 | + */ | ||
188 | + @Test | ||
189 | + public void testAsBytes() throws Exception { | ||
190 | + channelBuffer = ChannelBuffers.copiedBuffer(p2p); | ||
191 | + p2PHelloPdu.readFrom(channelBuffer); | ||
192 | + result = p2PHelloPdu.asBytes(); | ||
193 | + assertThat(result, is(notNullValue())); | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Tests p2PHeader() method. | ||
198 | + */ | ||
199 | + @Test | ||
200 | + public void testP2PHeader() throws Exception { | ||
201 | + result = p2PHelloPdu.p2PHeader(); | ||
202 | + assertThat(result, is(notNullValue())); | ||
203 | + } | ||
204 | + | ||
205 | + /** | ||
206 | + * Tests p2P2HelloPduBody() method. | ||
207 | + */ | ||
208 | + @Test | ||
209 | + public void testP2P2HelloPduBody() throws Exception { | ||
210 | + channelBuffer = ChannelBuffers.copiedBuffer(p2p); | ||
211 | + p2PHelloPdu.readFrom(channelBuffer); | ||
212 | + result = p2PHelloPdu.p2P2HelloPduBody(); | ||
213 | + assertThat(result, is(notNullValue())); | ||
214 | + | ||
215 | + } | ||
216 | + | ||
217 | + /** | ||
218 | + * Tests toString() method. | ||
219 | + */ | ||
220 | + @Test | ||
221 | + public void testToString() throws Exception { | ||
222 | + assertThat(p2PHelloPdu.toString(), is(notNullValue())); | ||
223 | + } | ||
224 | + | ||
225 | + /** | ||
226 | + * Tests equals() method. | ||
227 | + */ | ||
228 | + @Test | ||
229 | + public void testEquals() throws Exception { | ||
230 | + assertThat(p2PHelloPdu.equals(new P2PHelloPdu(new IsisHeader())), is(true)); | ||
231 | + } | ||
232 | + | ||
233 | + /** | ||
234 | + * Tests hashCode() method. | ||
235 | + */ | ||
236 | + @Test | ||
237 | + public void testHashCode() throws Exception { | ||
238 | + resultInt = p2PHelloPdu.hashCode(); | ||
239 | + assertThat(resultInt, is(notNullValue())); | ||
240 | + } | ||
241 | +} |
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.isis.io.isispacket.pdu; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
21 | +import org.junit.After; | ||
22 | +import org.junit.Before; | ||
23 | +import org.junit.Test; | ||
24 | +import org.onosproject.isis.controller.IsisPduType; | ||
25 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
26 | +import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; | ||
27 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
28 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
29 | + | ||
30 | +import java.util.List; | ||
31 | + | ||
32 | +import static org.hamcrest.CoreMatchers.is; | ||
33 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
34 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
35 | + | ||
36 | +/** | ||
37 | + * Unit test class for Psnp. | ||
38 | + */ | ||
39 | +public class PsnpTest { | ||
40 | + private final String srcId = "1111.1111.1111"; | ||
41 | + private final byte[] psnpPkt = { | ||
42 | + 0, 35, 41, 41, 41, 41, 41, 41, 0, 9, 16, 4, -81, 18, 52, 18, | ||
43 | + 52, 0, 18, 0, 0, 0, 0, 0, 42, -94, -29 | ||
44 | + }; | ||
45 | + private Psnp psnp; | ||
46 | + private IsisHeader isisHeader; | ||
47 | + private ChannelBuffer channelBuffer; | ||
48 | + private IsisTlv isisTlv; | ||
49 | + private TlvHeader tlvHeader; | ||
50 | + private List<IsisTlv> resultList; | ||
51 | + private String resultStr; | ||
52 | + private int resultInt; | ||
53 | + private byte[] result; | ||
54 | + | ||
55 | + @Before | ||
56 | + public void setUp() throws Exception { | ||
57 | + isisHeader = new IsisHeader(); | ||
58 | + isisHeader.setIsisPduType(IsisPduType.L1PSNP.value()); | ||
59 | + psnp = new Psnp(isisHeader); | ||
60 | + tlvHeader = new TlvHeader(); | ||
61 | + channelBuffer = EasyMock.createMock(ChannelBuffer.class); | ||
62 | + isisTlv = new AdjacencyStateTlv(tlvHeader); | ||
63 | + | ||
64 | + } | ||
65 | + | ||
66 | + @After | ||
67 | + public void tearDown() throws Exception { | ||
68 | + isisHeader = null; | ||
69 | + psnp = null; | ||
70 | + channelBuffer = null; | ||
71 | + tlvHeader = null; | ||
72 | + isisTlv = null; | ||
73 | + tlvHeader = null; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Tests addTlv() method. | ||
78 | + */ | ||
79 | + @Test | ||
80 | + public void testAddTlv() throws Exception { | ||
81 | + psnp.addTlv(isisTlv); | ||
82 | + resultList = psnp.getAllTlv(); | ||
83 | + assertThat(resultList.size(), is(1)); | ||
84 | + | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Tests getAllTlv() method. | ||
89 | + */ | ||
90 | + @Test | ||
91 | + public void testGetAllTlv() throws Exception { | ||
92 | + psnp.addTlv(isisTlv); | ||
93 | + resultList = psnp.getAllTlv(); | ||
94 | + assertThat(resultList.size(), is(1)); | ||
95 | + | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * Tests sourceId() getter method. | ||
100 | + */ | ||
101 | + @Test | ||
102 | + public void testSourceId() throws Exception { | ||
103 | + psnp.setSourceId(srcId); | ||
104 | + resultStr = psnp.sourceId(); | ||
105 | + assertThat(resultStr, is(srcId)); | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * Tests sourceId() setter method. | ||
110 | + */ | ||
111 | + @Test | ||
112 | + public void testSetSourceId() throws Exception { | ||
113 | + psnp.setSourceId(srcId); | ||
114 | + resultStr = psnp.sourceId(); | ||
115 | + assertThat(resultStr, is(srcId)); | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * Tests pduLength() getter method. | ||
120 | + */ | ||
121 | + @Test | ||
122 | + public void testPduLength() throws Exception { | ||
123 | + psnp.setPduLength(10); | ||
124 | + resultInt = psnp.pduLength(); | ||
125 | + assertThat(resultInt, is(10)); | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Tests pduLength() setter method. | ||
130 | + */ | ||
131 | + @Test | ||
132 | + public void testSetPduLength() throws Exception { | ||
133 | + psnp.setPduLength(10); | ||
134 | + resultInt = psnp.pduLength(); | ||
135 | + assertThat(resultInt, is(10)); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Tests readFrom() method. | ||
140 | + */ | ||
141 | + @Test | ||
142 | + public void testReadFrom() throws Exception { | ||
143 | + channelBuffer = ChannelBuffers.copiedBuffer(psnpPkt); | ||
144 | + psnp.readFrom(channelBuffer); | ||
145 | + assertThat(psnp, is(notNullValue())); | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Tests lasBytes() method. | ||
150 | + */ | ||
151 | + @Test | ||
152 | + public void testAsBytes() throws Exception { | ||
153 | + channelBuffer = ChannelBuffers.copiedBuffer(psnpPkt); | ||
154 | + psnp.readFrom(channelBuffer); | ||
155 | + result = psnp.asBytes(); | ||
156 | + assertThat(result, is(notNullValue())); | ||
157 | + } | ||
158 | + | ||
159 | + /** | ||
160 | + * Tests isisPduHeader() method. | ||
161 | + */ | ||
162 | + @Test | ||
163 | + public void testIsisPduHeader() throws Exception { | ||
164 | + result = psnp.isisPduHeader(); | ||
165 | + assertThat(result, is(notNullValue())); | ||
166 | + } | ||
167 | + | ||
168 | + /** | ||
169 | + * Tests partialSequenceNumberPduBody() method. | ||
170 | + */ | ||
171 | + @Test | ||
172 | + public void testPartialSequenceNumberPduBody() throws Exception { | ||
173 | + channelBuffer = ChannelBuffers.copiedBuffer(psnpPkt); | ||
174 | + psnp.readFrom(channelBuffer); | ||
175 | + result = psnp.partialSequenceNumberPduBody(); | ||
176 | + assertThat(result, is(notNullValue())); | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Tests toString() method. | ||
181 | + */ | ||
182 | + @Test | ||
183 | + public void testToString() throws Exception { | ||
184 | + assertThat((psnp.toString()), is(notNullValue())); | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Tests equals() method. | ||
189 | + */ | ||
190 | + @Test | ||
191 | + public void testEquals() throws Exception { | ||
192 | + assertThat(psnp.equals(new Psnp(new IsisHeader())), is(true)); | ||
193 | + } | ||
194 | + | ||
195 | + /** | ||
196 | + * Tests hashCode() method. | ||
197 | + */ | ||
198 | + @Test | ||
199 | + public void testHashCode() throws Exception { | ||
200 | + int hashCode = psnp.hashCode(); | ||
201 | + assertThat(hashCode, is(notNullValue())); | ||
202 | + } | ||
203 | +} |
protocols/isis/isisio/src/test/java/org/onosproject/isis/io/util/ChecksumCalculatorTest.java
0 → 100644
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.isis.io.util; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | + | ||
22 | +import static org.hamcrest.CoreMatchers.is; | ||
23 | +import static org.junit.Assert.assertThat; | ||
24 | + | ||
25 | +/** | ||
26 | + * Unit test class for ChecksumCalculator. | ||
27 | + */ | ||
28 | +public class ChecksumCalculatorTest { | ||
29 | + | ||
30 | + private final byte[] l1Lsp = { | ||
31 | + -125, 27, 1, 0, 18, 1, 0, 0, 0, 86, 4, -81, 34, 34, 34, | ||
32 | + 34, 34, 34, 0, 0, 0, 0, 0, 9, 99, 11, 1, 1, 4, 3, 73, | ||
33 | + 0, 10, -127, 1, -52, -119, 2, 82, 50, -124, 4, -64, -88, 10, 1, -128, | ||
34 | + 24, 10, -128, -128, -128, 10, 0, 10, 0, -1, -1, -1, -4, 10, -128, -128, | ||
35 | + -128, -64, -88, 10, 0, -1, -1, -1, 0, 2, 12, 0, 10, -128, -128, -128, | ||
36 | + 51, 51, 51, 51, 51, 51, 2 | ||
37 | + }; | ||
38 | + private ChecksumCalculator calculator; | ||
39 | + private byte[] result; | ||
40 | + private boolean result1; | ||
41 | + | ||
42 | + @Before | ||
43 | + public void setUp() throws Exception { | ||
44 | + calculator = new ChecksumCalculator(); | ||
45 | + } | ||
46 | + | ||
47 | + @After | ||
48 | + public void tearDown() throws Exception { | ||
49 | + calculator = null; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Tests validateLspCheckSum() method. | ||
54 | + */ | ||
55 | + @Test | ||
56 | + public void testValidateLspCheckSum() throws Exception { | ||
57 | + result1 = calculator.validateLspCheckSum(l1Lsp, IsisConstants.CHECKSUMPOSITION, | ||
58 | + IsisConstants.CHECKSUMPOSITION + 1); | ||
59 | + | ||
60 | + assertThat(result1, is(true)); | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Tests calculateLspChecksum() method. | ||
65 | + */ | ||
66 | + @Test | ||
67 | + public void testCalculateLspChecksum() throws Exception { | ||
68 | + result = calculator.calculateLspChecksum(l1Lsp, IsisConstants.CHECKSUMPOSITION, | ||
69 | + IsisConstants.CHECKSUMPOSITION + 1); | ||
70 | + assertThat(result[0], | ||
71 | + is(l1Lsp[IsisConstants.CHECKSUMPOSITION])); | ||
72 | + assertThat(result[1], | ||
73 | + is(l1Lsp[IsisConstants.CHECKSUMPOSITION + 1])); | ||
74 | + } | ||
75 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.isis.io.util; | ||
17 | + | ||
18 | +import com.google.common.primitives.Bytes; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onlab.packet.Ip4Address; | ||
23 | +import org.onosproject.isis.controller.IsisPduType; | ||
24 | + | ||
25 | +import static org.hamcrest.CoreMatchers.is; | ||
26 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
27 | +import static org.junit.Assert.assertThat; | ||
28 | + | ||
29 | +/** | ||
30 | + * Unit test class for IsisUtil. | ||
31 | + */ | ||
32 | +public class IsisUtilTest { | ||
33 | + | ||
34 | + private final String systemId = "2929.2929.2929"; | ||
35 | + private final String lanId = "2929.2929.2929.01"; | ||
36 | + private final String areaAddres = "490001"; | ||
37 | + private final byte[] l1Lsp = { | ||
38 | + -125, 27, 1, 0, 18, 1, 0, 0, 0, 86, 4, -81, 34, 34, 34, | ||
39 | + 34, 34, 34, 0, 0, 0, 0, 0, 9, 99, 11, 1, 1, 4, 3, 73, | ||
40 | + 0, 10, -127, 1, -52, -119, 2, 82, 50, -124, 4, -64, -88, 10, 1, -128, | ||
41 | + 24, 10, -128, -128, -128, 10, 0, 10, 0, -1, -1, -1, -4, 10, -128, -128, | ||
42 | + -128, -64, -88, 10, 0, -1, -1, -1, 0, 2, 12, 0, 10, -128, -128, -128, | ||
43 | + 51, 51, 51, 51, 51, 51, 2 | ||
44 | + }; | ||
45 | + private final byte[] intger = {0, 0, 0, 1}; | ||
46 | + private Ip4Address ip4Address1 = Ip4Address.valueOf("10.10.10.10"); | ||
47 | + private Ip4Address ip4Address2 = Ip4Address.valueOf("10.10.10.11"); | ||
48 | + private Ip4Address mask = Ip4Address.valueOf("255.255.255.0"); | ||
49 | + private boolean result; | ||
50 | + private String result1; | ||
51 | + private byte[] result2; | ||
52 | + private int result3; | ||
53 | + private long result4; | ||
54 | + private byte[] prefixBytes = {0, 0, 0, 1}; | ||
55 | + private String prefix = "192.16.17"; | ||
56 | + | ||
57 | + @Before | ||
58 | + public void setUp() throws Exception { | ||
59 | + | ||
60 | + } | ||
61 | + | ||
62 | + @After | ||
63 | + public void tearDown() throws Exception { | ||
64 | + | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Tests sameNetwork() method. | ||
69 | + */ | ||
70 | + @Test | ||
71 | + public void testSameNetwork() throws Exception { | ||
72 | + result = IsisUtil.sameNetwork(ip4Address1, ip4Address2, mask.toOctets()); | ||
73 | + assertThat(result, is(true)); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Tests systemId() method. | ||
78 | + */ | ||
79 | + @Test | ||
80 | + public void testSystemId() throws Exception { | ||
81 | + result1 = IsisUtil.systemId(Bytes.toArray( | ||
82 | + IsisUtil.sourceAndLanIdToBytes(systemId))); | ||
83 | + assertThat(result1, is(systemId)); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Tests systemIdPlus() method. | ||
88 | + */ | ||
89 | + @Test | ||
90 | + public void testSystemIdPlus() throws Exception { | ||
91 | + result1 = IsisUtil.systemIdPlus(Bytes.toArray( | ||
92 | + IsisUtil.sourceAndLanIdToBytes(lanId))); | ||
93 | + assertThat(result1, is(lanId)); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Tests areaAddres() method. | ||
98 | + */ | ||
99 | + @Test | ||
100 | + public void testAreaAddres() throws Exception { | ||
101 | + result1 = IsisUtil.areaAddres(Bytes.toArray( | ||
102 | + IsisUtil.areaAddressToBytes(areaAddres))); | ||
103 | + assertThat(result1, is(areaAddres)); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Tests areaAddressToBytes() method. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void testAreaAddressToBytes() throws Exception { | ||
111 | + result2 = Bytes.toArray(IsisUtil.areaAddressToBytes(areaAddres)); | ||
112 | + assertThat(result2, is(notNullValue())); | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Tests getPduHeaderLength() method. | ||
117 | + */ | ||
118 | + @Test | ||
119 | + public void testGetPduHeaderLength() throws Exception { | ||
120 | + result3 = IsisUtil.getPduHeaderLength(IsisPduType.L1CSNP.value()); | ||
121 | + assertThat(result3, is(33)); | ||
122 | + result3 = IsisUtil.getPduHeaderLength(IsisPduType.L1PSNP.value()); | ||
123 | + assertThat(result3, is(17)); | ||
124 | + result3 = IsisUtil.getPduHeaderLength(IsisPduType.L1HELLOPDU.value()); | ||
125 | + assertThat(result3, is(27)); | ||
126 | + result3 = IsisUtil.getPduHeaderLength(IsisPduType.P2PHELLOPDU.value()); | ||
127 | + assertThat(result3, is(20)); | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Tests addLengthAndMarkItInReserved() method. | ||
132 | + */ | ||
133 | + @Test | ||
134 | + public void testAddLengthAndMarkItInReserved() throws Exception { | ||
135 | + result2 = IsisUtil.addLengthAndMarkItInReserved(l1Lsp, | ||
136 | + IsisConstants.LENGTHPOSITION, IsisConstants.LENGTHPOSITION + 1, | ||
137 | + IsisConstants.RESERVEDPOSITION); | ||
138 | + assertThat(result2, is(notNullValue())); | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * Tests addChecksum() method. | ||
143 | + */ | ||
144 | + @Test | ||
145 | + public void testAddChecksum() throws Exception { | ||
146 | + result2 = IsisUtil.addChecksum(l1Lsp, | ||
147 | + IsisConstants.CHECKSUMPOSITION, IsisConstants.CHECKSUMPOSITION + 1); | ||
148 | + assertThat(result2, is(notNullValue())); | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Tests framePacket() method. | ||
153 | + */ | ||
154 | + @Test | ||
155 | + public void testFramePacket() throws Exception { | ||
156 | + result2 = IsisUtil.framePacket(l1Lsp, 2); | ||
157 | + assertThat(result2, is(notNullValue())); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Tests sourceAndLanIdToBytes() method. | ||
162 | + */ | ||
163 | + @Test | ||
164 | + public void testSourceAndLanIdToBytes() throws Exception { | ||
165 | + result2 = Bytes.toArray(IsisUtil.sourceAndLanIdToBytes(lanId)); | ||
166 | + assertThat(result2, is(notNullValue())); | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * Tests getPaddingTlvs() method. | ||
171 | + */ | ||
172 | + @Test | ||
173 | + public void testGetPaddingTlvs() throws Exception { | ||
174 | + result2 = IsisUtil.getPaddingTlvs(250); | ||
175 | + assertThat(result2, is(notNullValue())); | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * Tests convertToTwoBytes() method. | ||
180 | + */ | ||
181 | + @Test | ||
182 | + public void testConvertToTwoBytes() throws Exception { | ||
183 | + result2 = IsisUtil.convertToTwoBytes(250); | ||
184 | + assertThat(result2.length, is(2)); | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Tests convertToFourBytes() method. | ||
189 | + */ | ||
190 | + @Test | ||
191 | + public void testConvertToFourBytes() throws Exception { | ||
192 | + result2 = IsisUtil.convertToFourBytes(250); | ||
193 | + assertThat(result2.length, is(4)); | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Tests byteToInteger() method. | ||
198 | + */ | ||
199 | + @Test | ||
200 | + public void testByteToInteger() throws Exception { | ||
201 | + result3 = IsisUtil.byteToInteger(intger); | ||
202 | + assertThat(result3, is(1)); | ||
203 | + } | ||
204 | + | ||
205 | + /** | ||
206 | + * Tests byteToInteger() method. | ||
207 | + */ | ||
208 | + @Test | ||
209 | + public void testByteToLong() throws Exception { | ||
210 | + result4 = IsisUtil.byteToLong(intger); | ||
211 | + assertThat(result4, is(1L)); | ||
212 | + } | ||
213 | + | ||
214 | + /** | ||
215 | + * Tests convertToFourBytes() method. | ||
216 | + */ | ||
217 | + @Test | ||
218 | + public void testConvertToFourBytes1() throws Exception { | ||
219 | + result2 = IsisUtil.convertToFourBytes(250L); | ||
220 | + assertThat(result2.length, is(4)); | ||
221 | + } | ||
222 | + | ||
223 | + /** | ||
224 | + * Tests toFourBitBinary() method. | ||
225 | + */ | ||
226 | + @Test | ||
227 | + public void testToEightBitBinary() throws Exception { | ||
228 | + result1 = IsisUtil.toEightBitBinary("01"); | ||
229 | + assertThat(result1.length(), is(8)); | ||
230 | + } | ||
231 | + | ||
232 | + /** | ||
233 | + * Tests toFourBitBinary() method. | ||
234 | + */ | ||
235 | + @Test | ||
236 | + public void testToFourBitBinary() throws Exception { | ||
237 | + result1 = IsisUtil.toFourBitBinary("01"); | ||
238 | + assertThat(result1.length(), is(4)); | ||
239 | + } | ||
240 | + | ||
241 | + /** | ||
242 | + * Tests convertToThreeBytes() method. | ||
243 | + */ | ||
244 | + @Test | ||
245 | + public void testConvertToThreeBytes() throws Exception { | ||
246 | + result2 = IsisUtil.convertToThreeBytes(30); | ||
247 | + assertThat(result2.length, is(3)); | ||
248 | + } | ||
249 | + | ||
250 | + /** | ||
251 | + * Tests prefixConversion() method. | ||
252 | + */ | ||
253 | + @Test | ||
254 | + public void testPrefixConversion() throws Exception { | ||
255 | + result1 = IsisUtil.prefixConversion(prefixBytes); | ||
256 | + assertThat(result1, is(notNullValue())); | ||
257 | + } | ||
258 | + | ||
259 | + /** | ||
260 | + * Tests prefixToBytes() method. | ||
261 | + */ | ||
262 | + @Test | ||
263 | + public void testPrefixToBytes() throws Exception { | ||
264 | + result2 = IsisUtil.prefixToBytes(prefix); | ||
265 | + assertThat(result2, is(notNullValue())); | ||
266 | + } | ||
267 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.isis.io.util; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.isis.controller.IsisInterface; | ||
23 | +import org.onosproject.isis.controller.IsisLsdb; | ||
24 | +import org.onosproject.isis.controller.IsisPduType; | ||
25 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
26 | + | ||
27 | +import static org.hamcrest.CoreMatchers.instanceOf; | ||
28 | +import static org.hamcrest.CoreMatchers.is; | ||
29 | +import static org.junit.Assert.assertThat; | ||
30 | + | ||
31 | +/** | ||
32 | + * Unit test class for LspGenerator. | ||
33 | + */ | ||
34 | +public class LspGeneratorTest { | ||
35 | + private LspGenerator generator; | ||
36 | + private IsisHeader isisHeader; | ||
37 | + private IsisInterface isisInterface; | ||
38 | + private IsisLsdb isisLsdb; | ||
39 | + | ||
40 | + @Before | ||
41 | + public void setUp() throws Exception { | ||
42 | + generator = new LspGenerator(); | ||
43 | + isisLsdb = EasyMock.createMock(IsisLsdb.class); | ||
44 | + isisInterface = EasyMock.createMock(IsisInterface.class); | ||
45 | + } | ||
46 | + | ||
47 | + @After | ||
48 | + public void tearDown() throws Exception { | ||
49 | + generator = null; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Tests getHeader() method. | ||
54 | + */ | ||
55 | + @Test | ||
56 | + public void testGetHeader() throws Exception { | ||
57 | + isisHeader = generator.getHeader(IsisPduType.L1CSNP); | ||
58 | + assertThat(isisHeader, is(instanceOf(IsisHeader.class))); | ||
59 | + } | ||
60 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment