Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPObjectParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import java.io.IOException;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18 import java.util.NoSuchElementException;
19
20 import org.junit.Ignore;
21 import org.junit.Test;
22 import org.opendaylight.protocol.concepts.IGPMetric;
23 import org.opendaylight.protocol.concepts.IPv4Address;
24 import org.opendaylight.protocol.concepts.IPv4Prefix;
25 import org.opendaylight.protocol.concepts.IPv6Address;
26 import org.opendaylight.protocol.concepts.IPv6Prefix;
27 import org.opendaylight.protocol.concepts.TEMetric;
28 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
29 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
30 import org.opendaylight.protocol.pcep.PCEPErrors;
31 import org.opendaylight.protocol.pcep.PCEPOFCodes;
32 import org.opendaylight.protocol.pcep.PCEPObject;
33 import org.opendaylight.protocol.pcep.PCEPTlv;
34 import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
35 import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
36 import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.PCEPErrorIdentifier;
37 import org.opendaylight.protocol.pcep.impl.object.UnknownObject;
38 import org.opendaylight.protocol.pcep.object.PCEPBranchNodeListObject;
39 import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject;
40 import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
41 import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason;
42 import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
43 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
44 import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
45 import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject;
46 import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject;
47 import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject;
48 import org.opendaylight.protocol.pcep.object.PCEPLspObject;
49 import org.opendaylight.protocol.pcep.object.PCEPLspaObject;
50 import org.opendaylight.protocol.pcep.object.PCEPMetricObject;
51 import org.opendaylight.protocol.pcep.object.PCEPNoPathObject;
52 import org.opendaylight.protocol.pcep.object.PCEPNonBranchNodeListObject;
53 import org.opendaylight.protocol.pcep.object.PCEPNotificationObject;
54 import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject;
55 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
56 import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject;
57 import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject;
58 import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject;
59 import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject;
60 import org.opendaylight.protocol.pcep.object.PCEPSecondaryExplicitRouteObject;
61 import org.opendaylight.protocol.pcep.object.PCEPSecondaryRecordRouteObject;
62 import org.opendaylight.protocol.pcep.object.PCEPSvecObject;
63 import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject;
64 import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
65 import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
66 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
67 import org.opendaylight.protocol.pcep.subobject.RROIPAddressSubobject;
68 import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject;
69 import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject;
70 import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject;
71 import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute;
72 import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv;
73 import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv;
74 import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv;
75 import org.opendaylight.protocol.pcep.tlv.OrderTlv;
76 import org.opendaylight.protocol.pcep.tlv.OverloadedDurationTlv;
77 import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv;
78 import org.opendaylight.protocol.util.ByteArray;
79 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth;
81
82 /**
83  * Used resources<br/>
84  * <br/>
85  * PCEPOpenObject3.bin<br/>
86  * objClass: 1<br/>
87  * objType: 1<br/>
88  * objLength: 8<br/>
89  * version: 1<br/>
90  * Flags:<br/>
91  * - processing: true<br/>
92  * - ignored: true<br/>
93  * <br/>
94  * keepAlive: 30<br/>
95  * deadTimer: 120<br/>
96  * sessionId: 1<br/>
97  * tlvs:NO<br/>
98  * <br/>
99  * PCEPBandwidthObject1LowerBounds.bin<br/>
100  * objClass: 5 <br/>
101  * objType: 1<br/>
102  * objLength: 16<br/>
103  * version: 1<br/>
104  * Flags:<br/>
105  * - processing: true<br/>
106  * - ignored: true<br/>
107  * <br/>
108  * Bandwidth: 0<br/>
109  * <br/>
110  * PCEPBandwidthObject2UpperBounds.bin<br/>
111  * objClass: 5 <br/>
112  * objType: 1<br/>
113  * objLength: 16<br/>
114  * version: 1<br/>
115  * Flags:<br/>
116  * - processing: true<br/>
117  * - ignored: true<br/>
118  * <br/>
119  * Bandwidth: 0xFFFFFFFF<br/>
120  * <br/>
121  * PCEPEndPointsObject1IPv4.bin<br/>
122  * objClass: 4 <br/>
123  * objType: 1<br/>
124  * objLength: 12<br/>
125  * version: 1<br/>
126  * Flags:<br/>
127  * - processing: true<br/>
128  * - ignored: true<br/>
129  * <br/>
130  * src IP: 0xA2F5110E <br/>
131  * dest IP: 0xFFFFFFFF <br/>
132  * <br/>
133  * PCEPEndPointsObject2IPv6.bin<br/>
134  * objClass: 4 <br/>
135  * objType: 2<br/>
136  * objLength: 36<br/>
137  * version: 1<br/>
138  * Flags:<br/>
139  * - processing: true<br/>
140  * - ignored: true<br/>
141  * <br/>
142  * src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF<br/>
143  * dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000 <br/>
144  * <br/>
145  * PCEPErrorObject1.bin<br/>
146  * objClass: 13 (RP)<br/>
147  * objType: 1<br/>
148  * objLength: 8<br/>
149  * version: 1<br/>
150  * Flags:<br/>
151  * - processing: false<br/>
152  * - ignored: false<br/>
153  * <br/>
154  * Error-type: 1<br/>
155  * Error-value: 1<br/>
156  * Tlvs: NO<br/>
157  * <br/>
158  * PCEPErrorObject2Invalid.bin<br/>
159  * objClass: 13 (RP)<br/>
160  * objType: 1<br/>
161  * objLength: 8<br/>
162  * version: 1<br/>
163  * Flags:<br/>
164  * - processing: false<br/>
165  * - ignored: false<br/>
166  * <br/>
167  * Error-type: 3<br/>
168  * Error-value: 0<br/>
169  * Tlvs: NO<br/>
170  * <br/>
171  * PCEPErrorObject3.bin<br/>
172  * objClass: 13 (RP)<br/>
173  * objType: 1<br/>
174  * objLength: 8<br/>
175  * version: 1<br/>
176  * Flags:<br/>
177  * - processing: false<br/>
178  * - ignored: false<br/>
179  * <br/>
180  * Error-type: 2<br/>
181  * Error-value: 0<br/>
182  * Tlvs: NO<br/>
183  * <br/>
184  * PCEPLspaObject1LowerBounds.bin<br/>
185  * objClass: 9<br/>
186  * objType: 1<br/>
187  * objLength: 20<br/>
188  * version: 1<br/>
189  * Flags:<br/>
190  * - processing: true<br/>
191  * - ignored: true<br/>
192  * <br/>
193  * Exclude-any: 0x00000000L<br/>
194  * Include-any: 0x00000000L<br/>
195  * Include-all: 0x00000000L<br/>
196  * Setup Prio: 0x00<br/>
197  * Holding Prio: 0x00<br/>
198  * Flags: - L : false<br/>
199  * <br/>
200  * PCEPLspaObject2UpperBounds.bin<br/>
201  * objClass: 9<br/>
202  * objType: 1<br/>
203  * objLength: 20<br/>
204  * version: 1<br/>
205  * Flags:<br/>
206  * - processing: true<br/>
207  * - ignored: true<br/>
208  * <br/>
209  * Exclude-any: 0xFFFFFFFFL<br/>
210  * Include-any: 0xFFFFFFFFL<br/>
211  * Include-all: 0xFFFFFFFFL<br/>
212  * Setup Prio: 0xFF<br/>
213  * Holding Prio: 0xFF<br/>
214  * Flags: - L : true<br/>
215  * <br/>
216  * PCEPLspaObject3RandVals.bin<br/>
217  * objClass: 9<br/>
218  * objType: 1<br/>
219  * objLength: 20<br/>
220  * version: 1<br/>
221  * Flags:<br/>
222  * - processing: true<br/>
223  * - ignored: true<br/>
224  * <br/>
225  * Exclude-any: 0x20A1FEE3L<br/>
226  * Include-any: 0x1A025CC7L<br/>
227  * Include-all: 0x2BB66532L<br/>
228  * Setup Prio: 0x03<br/>
229  * Holding Prio: 0x02<br/>
230  * Flags: - L : true<br/>
231  * <br/>
232  * NoPathObject1WithTLV.bin<br/>
233  * objClass: 3 (RP)<br/>
234  * objType: 1<br/>
235  * objLength: 16<br/>
236  * version: 1<br/>
237  * Flags:<br/>
238  * - processing: false<br/>
239  * - ignored: false<br/>
240  * <br/>
241  * Nature of Issue: 2<br/>
242  * No-Path flags:<br/>
243  * - C: true<br/>
244  * <br/>
245  * tlvs:<br/>
246  * -- NO-PATH-VECTOR<br/>
247  * - flags (0x4000):<br/>
248  * - PCE currently unavailable: false<br/>
249  * - unknown destination: true<br/>
250  * - unknown source: false<br/>
251  * 
252  * <br/>
253  * NoPathObject2WithoutTLV.bin<br/>
254  * objClass: 3 (RP)<br/>
255  * objType: 1<br/>
256  * objLength: 8<br/>
257  * version: 1<br/>
258  * Flags:<br/>
259  * - processing: false<br/>
260  * - ignored: true<br/>
261  * <br/>
262  * Nature of Issue: 16<br/>
263  * No-Path flags:<br/>
264  * - C: false<br/>
265  * <br/>
266  * tlvs:NO<br/>
267  * <br/>
268  * PCEPNotificationObject1WithTlv.bin <br/>
269  * objClass: 12<br/>
270  * objType: 1<br/>
271  * objLength: 16<br/>
272  * version: 1<br/>
273  * Flags:<br/>
274  * - processing: false<br/>
275  * - ignored: false<br/>
276  * <br/>
277  * NT: 1<br/>
278  * NV: 1<br/>
279  * Tlvs:<br/>
280  * - OverloaderDuration(0xFF0000A2L)<br/>
281  * <br/>
282  * PCEPNotificationObject2WithoutTlv.bin <br/>
283  * objClass: 12<br/>
284  * objType: 1<br/>
285  * objLength: 8<br/>
286  * version: 1<br/>
287  * Flags:<br/>
288  * - processing: false<br/>
289  * - ignored: false<br/>
290  * <br/>
291  * NT: 0xFF<br/>
292  * NV: 0xFF<br/>
293  * Tlvs: NO<br/>
294  * <br/>
295  * PCEPOpenObject1.bin<br/>
296  * objClass: 1<br/>
297  * objType: 1<br/>
298  * objLength: 28<br/>
299  * version: 1<br/>
300  * Flags:<br/>
301  * - processing: false<br/>
302  * - ignored: false<br/>
303  * <br/>
304  * keepAlive: 30<br/>
305  * deadTimer: 120<br/>
306  * sessionId: 1<br/>
307  * tlvs:<br/>
308  * - PCEPStatefulCapability<br/>
309  * - LSPStateDBVersionTlv<br/>
310  * - NodeIdentifierTlv<br/>
311  * <br/>
312  * PCEPOpenObject2UpperBoundsNoTlv.bin<br/>
313  * objClass: 1<br/>
314  * objType: 1<br/>
315  * objLength: 34<br/>
316  * version: 1<br/>
317  * Flags:<br/>
318  * - processing: false<br/>
319  * - ignored: false<br/>
320  * <br/>
321  * keepAlive: 0xFF<br/>
322  * deadTimer: 0xFF<br/>
323  * sessionId: 0xFF<br/>
324  * tlvs: NO<br/>
325  * <br/>
326  * PCEPRPObject1.bin<br/>
327  * objClass: 2 (RP)<br/>
328  * objType: 1<br/>
329  * objLength: 12<br/>
330  * version: 1<br/>
331  * Flags:<br/>
332  * - processing: false<br/>
333  * - ignored: false<br/>
334  * <br/>
335  * RP flags:<br/>
336  * - loose/strict: true<br/>
337  * - Bi-directional: false<br/>
338  * - Reoptimization: false<br/>
339  * - Priority: 5<br/>
340  * Request ID: 0xDEADBEEF<br/>
341  * tlvs: NO<br/>
342  * <br/>
343  * PCEPSvecObject1_10ReqIDs.bin <br/>
344  * objClass: 11<br/>
345  * objType: 1<br/>
346  * objLength: 48<br/>
347  * version: 1<br/>
348  * Flags:<br/>
349  * - processing: true<br/>
350  * - ignored: false<br/>
351  * <br/>
352  * Flags:<br/>
353  * - Link diverse: true<br/>
354  * - Node diverse: false<br/>
355  * - SRLG diverse: true<br/>
356  * Reques-ID-numbers:<br/>
357  * #1 - 0xFFFFFFFFL<br/>
358  * #2 - 0x00000000L<br/>
359  * #3 - 0x01234567L<br/>
360  * #4 - 0x89ABCDEFL<br/>
361  * #5 - 0xFEDCBA98L<br/>
362  * #6 - 0x76543210L<br/>
363  * #7 - 0x15825266L<br/>
364  * #8 - 0x48120BBEL<br/>
365  * #9 - 0x25FB7E52L<br/>
366  * #10 - 0xB2F2546BL<br/>
367  * <br/>
368  * PCEPSvecObject2.bin <br/>
369  * objClass: 11<br/>
370  * objType: 1<br/>
371  * objLength: 08<br/>
372  * version: 1<br/>
373  * Flags:<br/>
374  * - processing: false<br/>
375  * - ignored: false<br/>
376  * <br/>
377  * Flags:<br/>
378  * - Link diverse: false<br/>
379  * - Node diverse: false<br/>
380  * - SRLG diverse: false<br/>
381  * Reques-ID-numbers:<br/>
382  * #1 - 0x000000FFL<br/>
383  * PCEPExcludeRouteObject.1.bin <br/>
384  * objClass: 17 <br/>
385  * objType: 1 <br/>
386  * objLength: 20 <br/>
387  * version: 1 <br/>
388  * Flags: <br/>
389  * - fail: true <br/>
390  * Subobjects: <br/>
391  * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node) <br/>
392  * - XROASnumber(0x1234) <br/>
393  */
394
395 public class PCEPObjectParserTest {
396
397         IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
398
399         IPv6Address ipv6addr = new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168,
400                         2, 1, (byte) 192, (byte) 168, 2, 1 });
401
402         @SuppressWarnings("unchecked")
403         private static <T extends PCEPObject> void serDeserTest(final String srcFile, final T specObject) throws IOException,
404                         PCEPDeserializerException, PCEPDocumentedException {
405                 final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
406                 final T deserSpecObj = (T) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
407                 final byte[] serSpecObj = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObject));
408
409                 assertEquals(specObject, deserSpecObj);
410                 assertArrayEquals(bytesFromFile, serSpecObj);
411         }
412
413         /**
414          * Standard serialization test<br/>
415          * Used resources:<br/>
416          * - PCEPOpenObject1.bin<br/>
417          * 
418          * @throws PCEPDeserializerException
419          * @throws IOException
420          * @throws PCEPDocumentedException
421          */
422         @Test
423         @Ignore
424         // FIXME: temporary
425         public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
426                 PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
427         }
428
429         @Test
430         public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
431
432                 final PCEPObject obj = PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get(
433                                 0);
434
435                 assertTrue(obj instanceof UnknownObject);
436                 assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
437         }
438
439         @Test
440         public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
441                 final PCEPObject obj = PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0);
442
443                 assertTrue(obj instanceof UnknownObject);
444                 assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
445         }
446
447         @Test
448         public void testCloseObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
449                 serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG));
450         }
451
452         @Test
453         @Ignore
454         // FIXME BUG-89
455         public void testLoadBalancingObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
456                 serDeserTest("src/test/resources/PCEPLoadBalancingObject1.bin", new PCEPLoadBalancingObject(0xF1, new Bandwidth(new byte[] {
457                                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }), true));
458         }
459
460         @Test
461         public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
462                 serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false, true, false, null));
463         }
464
465         @Test
466         public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
467                 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
468
469                 final PCEPExplicitRouteObject specObj = (PCEPExplicitRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
470
471                 assertEquals(8, specObj.getSubobjects().size());
472
473                 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
474                 assertArrayEquals(bytesFromFile, bytesActual);
475         }
476
477         @Test
478         public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
479                 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin");
480
481                 final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
482
483                 assertEquals(8, specObj.getSubobjects().size());
484
485                 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
486                 assertArrayEquals(bytesFromFile, bytesActual);
487         }
488
489         @Test
490         public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
491                 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin");
492
493                 final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
494
495                 assertEquals(6, specObj.getSubobjects().size());
496
497                 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
498                 assertArrayEquals(bytesFromFile, bytesActual);
499         }
500
501         /**
502          * Test for upper/lower bounds (Serialization/Deserialization)<br/>
503          * Used resources:<br/>
504          * - PCEPBandwidthObject2UpperBounds.bin<br/>
505          * - PCEPBandwidthObject1LowerBounds.bin<br/>
506          * 
507          * @throws IOException
508          * @throws PCEPDeserializerException
509          * @throws PCEPDocumentedException
510          */
511         @Test
512         @Ignore
513         // FIXME BUG-89
514         public void testBandwidthObjectBounds() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
515                 serDeserTest("src/test/resources/PCEPBandwidthObject1LowerBounds.bin",
516                                 new PCEPRequestedPathBandwidthObject(new Bandwidth(new byte[] { 0, 0, 0, 0 }), true, true));
517         }
518
519         /**
520          * Test for upper/lower bounds of IPv4 EndPoints (Serialization/Deserialization)<br/>
521          * Used resources:<br/>
522          * - PCEPEndPointsObject1IPv4.bin<br/>
523          * 
524          * @throws IOException
525          * @throws PCEPDeserializerException
526          * @throws PCEPDocumentedException
527          */
528         @Test
529         public void testEndPointsObjectSerDeserIPv4() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
530                 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
531                 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
532                 serDeserTest("src/test/resources/PCEPEndPointsObject1IPv4.bin",
533                                 new PCEPEndPointsObject<IPv4Address>(new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes)));
534         }
535
536         /**
537          * Test for upper/lower bounds of IPv6 EndPoints (Serialization/Deserialization)<br/>
538          * Used resources:<br/>
539          * - PCEPEndPointsObject2IPv6.bin<br/>
540          * 
541          * @throws IOException
542          * @throws PCEPDeserializerException
543          * @throws PCEPDocumentedException
544          */
545         @Test
546         public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
547                 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
548                                 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
549                 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
550                                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
551
552                 serDeserTest("src/test/resources/PCEPEndPointsObject2IPv6.bin",
553                                 new PCEPEndPointsObject<IPv6Address>(new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes)));
554         }
555
556         /**
557          * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
558          * <br/>
559          * Used resources:<br/>
560          * - PCEPErrorObject1.bin<br/>
561          * - PCEPErrorObject3.bin<br/>
562          * 
563          * @throws PCEPDeserializerException
564          * @throws IOException
565          * @throws PCEPDocumentedException
566          */
567         @Test
568         public void testErrorObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
569                 serDeserTest("src/test/resources/PCEPErrorObject1.bin", new PCEPErrorObject(PCEPErrors.NON_OR_INVALID_OPEN_MSG));
570                 serDeserTest("src/test/resources/PCEPErrorObject3.bin", new PCEPErrorObject(PCEPErrors.CAPABILITY_NOT_SUPPORTED));
571         }
572
573         /**
574          * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.<br/>
575          * <br/>
576          * Used resources:<br/>
577          * - PCEPErrorObject2Invalid.bin<br/>
578          * 
579          * @throws NoSuchElementException
580          * @throws IOException
581          * @throws PCEPDocumentedException
582          */
583         @Test(expected = PCEPDeserializerException.class)
584         public void testUnknownError() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
585                 PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0);
586         }
587
588         /**
589          * Test for upper/lower bounds of PCEPLspaObject (Serialization/Deserialization)<br/>
590          * Used resources:<br/>
591          * - PCEPLspaObject1LowerBounds.bin<br/>
592          * - PCEPLspaObject2UpperBounds.bin<br/>
593          * - PCEPLspaObject3RandVals.bin<br/>
594          * 
595          * @throws IOException
596          * @throws PCEPDeserializerException
597          * @throws PCEPDocumentedException
598          */
599         @Test
600         public void testLspaObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
601                 serDeserTest("src/test/resources/PCEPLspaObject2UpperBounds.bin",
602                                 new PCEPLspaObject(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, (short) 0xFF, (short) 0xFF, false, true, true, true));
603                 serDeserTest("src/test/resources/PCEPLspaObject1LowerBounds.bin",
604                                 new PCEPLspaObject(0x00000000L, 0x00000000L, 0x00000000L, (short) 0x00, (short) 0x00, false, false, true, true));
605                 serDeserTest("src/test/resources/PCEPLspaObject3RandVals.bin",
606                                 new PCEPLspaObject(0x20A1FEE3L, 0x1A025CC7L, 0x2BB66532L, (short) 0x03, (short) 0x02, false, true, true, true));
607         }
608
609         @Test
610         public void testMetricObjectSerDeserBounds() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
611                 final byte[] bytesFromFileUB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
612                 final byte[] bytesFromFileLB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
613
614                 final PCEPMetricObject metricObjectLB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(bytesFromFileLB).get(0);
615                 final PCEPMetricObject metricObjectUB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(bytesFromFileUB).get(0);
616
617                 assertEquals(new PCEPMetricObject(false, false, new IGPMetric(0), true, true), metricObjectLB);
618                 assertEquals(new PCEPMetricObject(false, true, new TEMetric(4026531840L), true, true), metricObjectUB);
619
620                 final byte[] bytesActualLB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectLB));
621                 final byte[] bytesActualUB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectUB));
622                 assertArrayEquals(bytesFromFileLB, bytesActualLB);
623                 assertArrayEquals(bytesFromFileUB, bytesActualUB);
624         }
625
626         /**
627          * Standard deserialization test + specific test without tlv<br/>
628          * Used resources:<br/>
629          * - NoPathObject1WithTLV.bin<br/>
630          * - NoPathObject2WithoutTLV.bin<br/>
631          * 
632          * @throws PCEPDeserializerException
633          * @throws IOException
634          * @throws PCEPDocumentedException
635          */
636         @Test
637         public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
638                 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
639                 tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
640                 serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs, false));
641                 serDeserTest("src/test/resources/NoPathObject2WithoutTLV.bin", new PCEPNoPathObject((short) 0x10, false, true));
642
643         }
644
645         /**
646          * Standard serialization test + without tlv<br/>
647          * Used resources:<br/>
648          * - NoPathObject1WithTLV.bin<br/>
649          * - NoPathObject2WithoutTLV.bin<br/>
650          * 
651          * @throws PCEPDeserializerException
652          * @throws IOException
653          * @throws PCEPDocumentedException
654          */
655         @Test
656         public void testNoPathObjectSerialization() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
657                 byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject2WithoutTLV.bin");
658                 PCEPNoPathObject noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
659                 byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
660                 assertArrayEquals(bytesFromFile, bytesActual);
661
662                 bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject1WithTLV.bin");
663                 noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
664                 bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
665                 assertArrayEquals(bytesFromFile, bytesActual);
666         }
667
668         /**
669          * Specific test with/without tlvs (Ser/Deser)<br/>
670          * Used resources:<br/>
671          * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin
672          * 
673          * @throws PCEPDeserializerException
674          * @throws IOException
675          * @throws PCEPDocumentedException
676          */
677         @Test
678         public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
679                 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
680                 tlvs.add(new OverloadedDurationTlv(0xFF0000A2));
681                 serDeserTest("src/test/resources/PCEPNotificationObject1WithTlv.bin", new PCEPNotificationObject((short) 1, (short) 1, tlvs));
682                 serDeserTest("src/test/resources/PCEPNotificationObject2WithoutTlv.bin", new PCEPNotificationObject((short) 0xFF, (short) 0xFF));
683         }
684
685         /**
686          * Standard ser deser test<br/>
687          * used resources:<br/>
688          * - PCEPOpenObject1.bin
689          * 
690          * @throws PCEPDeserializerException
691          * @throws IOException
692          * @throws PCEPDocumentedException
693          */
694         @Test
695         @Ignore
696         // FIXME: temporary
697         public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
698                 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
699                 tlvs.add(new PCEStatefulCapabilityTlv(false, true, true));
700                 tlvs.add(new LSPStateDBVersionTlv(0x80));
701                 final byte[] valueBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 };
702                 tlvs.add(new NodeIdentifierTlv(valueBytes));
703                 final PCEPOpenObject specObject = new PCEPOpenObject(30, 120, 1, tlvs);
704
705                 serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject);
706         }
707
708         /**
709          * Specific test for upper bounds and without tlvs<br/>
710          * Used resources:<br/>
711          * - PCEPOpenObject2UpperBoundsNoTlv.bin
712          * 
713          * @throws PCEPDeserializerException
714          * @throws IOException
715          * @throws PCEPDocumentedException
716          */
717         @Test
718         public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
719                 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
720                 serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF, tlvs));
721                 serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF, null));
722         }
723
724         /**
725          * Standard deserialization test<br/>
726          * Used resources:<br/>
727          * - PCEPRPObject1.bin
728          * 
729          * @throws PCEPDeserializerException
730          * @throws IOException
731          * @throws PCEPDocumentedException
732          */
733         @Test
734         public void testRPObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
735                 serDeserTest("src/test/resources/PCEPRPObject1.bin",
736                                 new PCEPRequestParameterObject(true, false, true, true, false, false, false, false, (short) 5, 0xdeadbeefL, false, false));
737                 serDeserTest(
738                                 "src/test/resources/PCEPRPObject2.bin",
739                                 new PCEPRequestParameterObject(true, false, false, false, true, false, true, false, true, (short) 5, 0xdeadbeefL, new ArrayList<PCEPTlv>() {
740                                         private static final long serialVersionUID = 1L;
741
742                                         {
743                                                 this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
744                                         }
745                                 }, false, false));
746         }
747
748         /**
749          * Test for upper/lower bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
750          * Used resources:<br/>
751          * - PCEPSvecObject1_10ReqIDs.bin<br/>
752          * 
753          * @throws IOException
754          * @throws PCEPDeserializerException
755          * @throws PCEPDocumentedException
756          */
757         @Test
758         public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
759                 final List<Long> requestIDs = new ArrayList<Long>(10);
760                 requestIDs.add(0xFFFFFFFFL);
761                 requestIDs.add(0x00000000L);
762                 requestIDs.add(0x01234567L);
763                 requestIDs.add(0x89ABCDEFL);
764                 requestIDs.add(0xFEDCBA98L);
765                 requestIDs.add(0x76543210L);
766                 requestIDs.add(0x15825266L);
767                 requestIDs.add(0x48120BBEL);
768                 requestIDs.add(0x25FB7E52L);
769                 requestIDs.add(0xB2F2546BL);
770
771                 serDeserTest("src/test/resources/PCEPSvecObject1_10ReqIDs.bin",
772                                 new PCEPSvecObject(true, false, true, false, true, requestIDs, true));
773         }
774
775         /**
776          * Test for lowest bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
777          * Used resources:<br/>
778          * - PCEPSvecObject2.bin<br/>
779          * 
780          * @throws IOException
781          * @throws PCEPDeserializerException
782          * @throws PCEPDocumentedException
783          */
784         @Test
785         public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
786                 final List<Long> requestIDs = new ArrayList<Long>();
787                 requestIDs.add(0xFFL);
788                 serDeserTest("src/test/resources/PCEPSvecObject2.bin", new PCEPSvecObject(false, false, false, false, false, requestIDs, false));
789         }
790
791         @Test
792         public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
793                 final PCEPClassTypeObject ct = new PCEPClassTypeObject((short) 4);
794                 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
795                 final byte[] bytes = parser.put(ct);
796                 assertEquals(ct, parser.parse(bytes, true, false));
797         }
798
799         /**
800          * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
801          * Used resources:<br/>
802          * - PCEPExcludeRouteObject.1.bin<br/>
803          * 
804          * @throws IOException
805          * @throws PCEPDeserializerException
806          * @throws PCEPDocumentedException
807          */
808         @Test
809         public void testExcludeRouteObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
810                 final List<ExcludeRouteSubobject> xroSubobjects = new ArrayList<ExcludeRouteSubobject>();
811                 xroSubobjects.add(new XROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, (byte) 168,
812                                 (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE));
813                 xroSubobjects.add(new XROAsNumberSubobject(new AsNumber(0x1234L), false));
814
815         }
816
817         @Test
818         public void tesObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
819                 serDeserTest("src/test/resources/PCEPObjectiveFunctionObject.1.bin", new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false));
820         }
821
822         @Test
823         public void tesGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
824                 serDeserTest("src/test/resources/PCEPGlobalConstraintsObject.1.bin",
825                                 new PCEPGlobalConstraintsObject((short) 1, (short) 0, (short) 100, (short) 0xFF, true, false));
826         }
827
828         // FIXME: add at least one test with true value
829         @Test
830         public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException {
831                 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, false));
832                 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, true));
833                 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, false));
834                 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, true));
835         }
836
837         private void testOpenObjectWithSpecTlv(final PCEPTlv tlv) throws PCEPDeserializerException, PCEPDocumentedException {
838                 final List<PCEPObject> objs = new ArrayList<PCEPObject>();
839                 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
840                 tlvs.add(tlv);
841                 final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs);
842                 objs.add(oo);
843                 final byte[] bytes = PCEPObjectFactory.put(objs);
844                 final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0);
845                 assertEquals(oo, obj);
846         }
847
848         @Test
849         public void testErrorsMapping() {
850                 final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance();
851
852                 for (final PCEPErrors error : PCEPErrors.values()) {
853                         final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error);
854                         assertEquals(error, mapper.getFromErrorIdentifier(errorId));
855                 }
856         }
857
858         @Test
859         public void testOFCodesMapping() {
860                 final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance();
861
862                 for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) {
863                         final int ofCodeId = mapper.getFromOFCodesEnum(ofCode);
864                         assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId));
865                 }
866         }
867
868         @SuppressWarnings("unchecked")
869         private static <T extends PCEPObject> void serDeserTestWithoutBin(final T object) throws PCEPDeserializerException,
870                         PCEPDocumentedException {
871                 final byte[] serBytes = PCEPObjectFactory.put(Arrays.asList((PCEPObject) object));
872                 final T deserObj = (T) PCEPObjectFactory.parseObjects(serBytes).get(0);
873
874                 assertEquals(object, deserObj);
875         }
876
877         /*
878          * tests without the need of binary files
879          */
880         @Test
881         public void testBranchNodeObjects() throws PCEPDocumentedException, PCEPDeserializerException {
882                 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
883                 eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 }), 16), false));
884                 eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1,
885                                 (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1 }), 64), false));
886
887                 serDeserTestWithoutBin(new PCEPBranchNodeListObject(eroSubobjects, true, false));
888                 serDeserTestWithoutBin(new PCEPNonBranchNodeListObject(eroSubobjects, true, false));
889
890         }
891
892         @Test
893         public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException {
894                 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
895                 eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 }), 16), false));
896                 eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1,
897                                 (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1 }), 64), false));
898
899                 serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false));
900         }
901
902         @Test
903         public void testSRRObject() throws PCEPDocumentedException, PCEPDeserializerException {
904                 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>();
905                 rroSubobjects.add(new RROIPAddressSubobject<IPv4Prefix>(new IPv4Prefix(this.ipv4addr, 16), true, false));
906                 rroSubobjects.add(new RROIPAddressSubobject<IPv6Prefix>(new IPv6Prefix(this.ipv6addr, 64), false, true));
907
908                 serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
909         }
910
911         @Test
912         public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException {
913                 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(2, this.ipv4addr, Arrays.asList(this.ipv4addr, this.ipv4addr,
914                                 this.ipv4addr), true, false));
915                 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(1, this.ipv4addr, Arrays.asList(this.ipv4addr), true, false));
916                 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(2, this.ipv6addr, Arrays.asList(this.ipv6addr, this.ipv6addr,
917                                 this.ipv6addr), true, false));
918                 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(1, this.ipv6addr, Arrays.asList(this.ipv6addr), true, false));
919         }
920
921         @Test
922         public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException {
923                 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr, this.ipv4addr, this.ipv4addr), true, false));
924                 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr), true, false));
925                 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr, this.ipv6addr, this.ipv6addr), true, false));
926                 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr), true, false));
927         }
928 }