2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.impl;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
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;
20 import org.junit.Ignore;
21 import org.junit.Test;
23 import org.opendaylight.protocol.util.ByteArray;
24 import org.opendaylight.protocol.concepts.ASNumber;
25 import org.opendaylight.protocol.concepts.Bandwidth;
26 import org.opendaylight.protocol.concepts.IGPMetric;
27 import org.opendaylight.protocol.concepts.IPv4Address;
28 import org.opendaylight.protocol.concepts.IPv4Prefix;
29 import org.opendaylight.protocol.concepts.IPv6Address;
30 import org.opendaylight.protocol.concepts.IPv6Prefix;
31 import org.opendaylight.protocol.concepts.TEMetric;
32 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
33 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
34 import org.opendaylight.protocol.pcep.PCEPErrors;
35 import org.opendaylight.protocol.pcep.PCEPOFCodes;
36 import org.opendaylight.protocol.pcep.PCEPObject;
37 import org.opendaylight.protocol.pcep.PCEPTlv;
38 import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
39 import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
40 import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.PCEPErrorIdentifier;
41 import org.opendaylight.protocol.pcep.impl.object.UnknownObject;
42 import org.opendaylight.protocol.pcep.object.PCEPBranchNodeListObject;
43 import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject;
44 import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
45 import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason;
46 import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
47 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
48 import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
49 import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject;
50 import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject;
51 import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject;
52 import org.opendaylight.protocol.pcep.object.PCEPLspObject;
53 import org.opendaylight.protocol.pcep.object.PCEPLspaObject;
54 import org.opendaylight.protocol.pcep.object.PCEPMetricObject;
55 import org.opendaylight.protocol.pcep.object.PCEPNoPathObject;
56 import org.opendaylight.protocol.pcep.object.PCEPNonBranchNodeListObject;
57 import org.opendaylight.protocol.pcep.object.PCEPNotificationObject;
58 import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject;
59 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
60 import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject;
61 import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject;
62 import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject;
63 import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject;
64 import org.opendaylight.protocol.pcep.object.PCEPSecondaryExplicitRouteObject;
65 import org.opendaylight.protocol.pcep.object.PCEPSecondaryRecordRouteObject;
66 import org.opendaylight.protocol.pcep.object.PCEPSvecObject;
67 import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject;
68 import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
69 import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
70 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
71 import org.opendaylight.protocol.pcep.subobject.RROIPAddressSubobject;
72 import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject;
73 import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject;
74 import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject;
75 import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute;
76 import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv;
77 import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv;
78 import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv;
79 import org.opendaylight.protocol.pcep.tlv.OrderTlv;
80 import org.opendaylight.protocol.pcep.tlv.OverloadedDurationTlv;
81 import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv;
86 * PCEPOpenObject3.bin<br/>
92 * - processing: true<br/>
93 * - ignored: true<br/>
100 * PCEPBandwidthObject1LowerBounds.bin<br/>
106 * - processing: true<br/>
107 * - ignored: true<br/>
111 * PCEPBandwidthObject2UpperBounds.bin<br/>
117 * - processing: true<br/>
118 * - ignored: true<br/>
120 * Bandwidth: 0xFFFFFFFF<br/>
122 * PCEPEndPointsObject1IPv4.bin<br/>
128 * - processing: true<br/>
129 * - ignored: true<br/>
131 * src IP: 0xA2F5110E <br/>
132 * dest IP: 0xFFFFFFFF <br/>
134 * PCEPEndPointsObject2IPv6.bin<br/>
140 * - processing: true<br/>
141 * - ignored: true<br/>
143 * src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF<br/>
144 * dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000 <br/>
146 * PCEPErrorObject1.bin<br/>
147 * objClass: 13 (RP)<br/>
152 * - processing: false<br/>
153 * - ignored: false<br/>
156 * Error-value: 1<br/>
159 * PCEPErrorObject2Invalid.bin<br/>
160 * objClass: 13 (RP)<br/>
165 * - processing: false<br/>
166 * - ignored: false<br/>
169 * Error-value: 0<br/>
172 * PCEPErrorObject3.bin<br/>
173 * objClass: 13 (RP)<br/>
178 * - processing: false<br/>
179 * - ignored: false<br/>
182 * Error-value: 0<br/>
185 * PCEPLspaObject1LowerBounds.bin<br/>
191 * - processing: true<br/>
192 * - ignored: true<br/>
194 * Exclude-any: 0x00000000L<br/>
195 * Include-any: 0x00000000L<br/>
196 * Include-all: 0x00000000L<br/>
197 * Setup Prio: 0x00<br/>
198 * Holding Prio: 0x00<br/>
199 * Flags: - L : false<br/>
201 * PCEPLspaObject2UpperBounds.bin<br/>
207 * - processing: true<br/>
208 * - ignored: true<br/>
210 * Exclude-any: 0xFFFFFFFFL<br/>
211 * Include-any: 0xFFFFFFFFL<br/>
212 * Include-all: 0xFFFFFFFFL<br/>
213 * Setup Prio: 0xFF<br/>
214 * Holding Prio: 0xFF<br/>
215 * Flags: - L : true<br/>
217 * PCEPLspaObject3RandVals.bin<br/>
223 * - processing: true<br/>
224 * - ignored: true<br/>
226 * Exclude-any: 0x20A1FEE3L<br/>
227 * Include-any: 0x1A025CC7L<br/>
228 * Include-all: 0x2BB66532L<br/>
229 * Setup Prio: 0x03<br/>
230 * Holding Prio: 0x02<br/>
231 * Flags: - L : true<br/>
233 * NoPathObject1WithTLV.bin<br/>
234 * objClass: 3 (RP)<br/>
239 * - processing: false<br/>
240 * - ignored: false<br/>
242 * Nature of Issue: 2<br/>
243 * No-Path flags:<br/>
247 * -- NO-PATH-VECTOR<br/>
248 * - flags (0x4000):<br/>
249 * - PCE currently unavailable: false<br/>
250 * - unknown destination: true<br/>
251 * - unknown source: false<br/>
254 * NoPathObject2WithoutTLV.bin<br/>
255 * objClass: 3 (RP)<br/>
260 * - processing: false<br/>
261 * - ignored: true<br/>
263 * Nature of Issue: 16<br/>
264 * No-Path flags:<br/>
269 * PCEPNotificationObject1WithTlv.bin <br/>
275 * - processing: false<br/>
276 * - ignored: false<br/>
281 * - OverloaderDuration(0xFF0000A2L)<br/>
283 * PCEPNotificationObject2WithoutTlv.bin <br/>
289 * - processing: false<br/>
290 * - ignored: false<br/>
296 * PCEPOpenObject1.bin<br/>
302 * - processing: false<br/>
303 * - ignored: false<br/>
306 * deadTimer: 120<br/>
309 * - PCEPStatefulCapability<br/>
310 * - LSPStateDBVersionTlv<br/>
311 * - NodeIdentifierTlv<br/>
313 * PCEPOpenObject2UpperBoundsNoTlv.bin<br/>
319 * - processing: false<br/>
320 * - ignored: false<br/>
322 * keepAlive: 0xFF<br/>
323 * deadTimer: 0xFF<br/>
324 * sessionId: 0xFF<br/>
327 * PCEPRPObject1.bin<br/>
328 * objClass: 2 (RP)<br/>
333 * - processing: false<br/>
334 * - ignored: false<br/>
337 * - loose/strict: true<br/>
338 * - Bi-directional: false<br/>
339 * - Reoptimization: false<br/>
341 * Request ID: 0xDEADBEEF<br/>
344 * PCEPSvecObject1_10ReqIDs.bin <br/>
350 * - processing: true<br/>
351 * - ignored: false<br/>
354 * - Link diverse: true<br/>
355 * - Node diverse: false<br/>
356 * - SRLG diverse: true<br/>
357 * Reques-ID-numbers:<br/>
358 * #1 - 0xFFFFFFFFL<br/>
359 * #2 - 0x00000000L<br/>
360 * #3 - 0x01234567L<br/>
361 * #4 - 0x89ABCDEFL<br/>
362 * #5 - 0xFEDCBA98L<br/>
363 * #6 - 0x76543210L<br/>
364 * #7 - 0x15825266L<br/>
365 * #8 - 0x48120BBEL<br/>
366 * #9 - 0x25FB7E52L<br/>
367 * #10 - 0xB2F2546BL<br/>
369 * PCEPSvecObject2.bin <br/>
375 * - processing: false<br/>
376 * - ignored: false<br/>
379 * - Link diverse: false<br/>
380 * - Node diverse: false<br/>
381 * - SRLG diverse: false<br/>
382 * Reques-ID-numbers:<br/>
383 * #1 - 0x000000FFL<br/>
384 * PCEPExcludeRouteObject.1.bin <br/>
387 * objLength: 20 <br/>
392 * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node) <br/>
393 * - XROASnumber(0x1234) <br/>
396 public class PCEPObjectParserTest {
398 IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
400 IPv6Address ipv6addr = new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168,
401 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1 });
403 @SuppressWarnings("unchecked")
404 private static <T extends PCEPObject> void serDeserTest(final String srcFile, final T specObject) throws IOException,
405 PCEPDeserializerException, PCEPDocumentedException {
406 final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
407 final T deserSpecObj = (T) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
408 final byte[] serSpecObj = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObject));
410 assertEquals(specObject, deserSpecObj);
411 assertArrayEquals(bytesFromFile, serSpecObj);
415 * Standard serialization test<br/>
416 * Used resources:<br/>
417 * - PCEPOpenObject1.bin<br/>
419 * @throws PCEPDeserializerException
420 * @throws IOException
421 * @throws PCEPDocumentedException
424 @Ignore //FIXME: temporary
425 public void testObjectDeserialization() throws PCEPDeserializerException, IOException,
426 PCEPDocumentedException {
427 PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
431 public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
433 final PCEPObject obj = PCEPObjectFactory.parseObjects(
434 ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get(0);
436 assertTrue(obj instanceof UnknownObject);
437 assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
441 public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
442 final PCEPObject obj = PCEPObjectFactory.parseObjects(
443 ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0);
445 assertTrue(obj instanceof UnknownObject);
446 assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
450 public void testCloseObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
451 serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(
452 Reason.TOO_MANY_UNKNOWN_MSG));
456 public void testLoadBalancingObjSerDeser() throws IOException, PCEPDeserializerException,
457 PCEPDocumentedException {
458 serDeserTest("src/test/resources/PCEPLoadBalancingObject1.bin", new PCEPLoadBalancingObject(0xF1,
459 new Bandwidth(Float.intBitsToFloat(0xFFFFFFFF)), true));
463 public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException,
464 PCEPDocumentedException {
465 serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF,
466 true, false, true, false, null));
470 public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
471 final byte[] bytesFromFile = ByteArray
472 .fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
474 final PCEPExplicitRouteObject specObj = (PCEPExplicitRouteObject) PCEPObjectFactory.parseObjects(
475 bytesFromFile).get(0);
477 assertEquals(8, specObj.getSubobjects().size());
479 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
480 assertArrayEquals(bytesFromFile, bytesActual);
484 public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
485 final byte[] bytesFromFile = ByteArray
486 .fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin");
488 final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject) PCEPObjectFactory.parseObjects(
489 bytesFromFile).get(0);
491 assertEquals(8, specObj.getSubobjects().size());
493 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
494 assertArrayEquals(bytesFromFile, bytesActual);
498 public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
499 final byte[] bytesFromFile = ByteArray
500 .fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin");
502 final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject) PCEPObjectFactory.parseObjects(
503 bytesFromFile).get(0);
505 assertEquals(6, specObj.getSubobjects().size());
507 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
508 assertArrayEquals(bytesFromFile, bytesActual);
512 * Test for upper/lower bounds (Serialization/Deserialization)<br/>
513 * Used resources:<br/>
514 * - PCEPBandwidthObject2UpperBounds.bin<br/>
515 * - PCEPBandwidthObject1LowerBounds.bin<br/>
517 * @throws IOException
518 * @throws PCEPDeserializerException
519 * @throws PCEPDocumentedException
522 public void testBandwidthObjectBounds() throws IOException, PCEPDeserializerException,
523 PCEPDocumentedException {
524 final byte[] bytesFloat = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
525 serDeserTest("src/test/resources/PCEPBandwidthObject2UpperBounds.bin",
526 new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.bytesToFloat(bytesFloat)), true,
528 serDeserTest("src/test/resources/PCEPBandwidthObject1LowerBounds.bin",
529 new PCEPRequestedPathBandwidthObject(new Bandwidth(0), true, true));
533 * Test for upper/lower bounds of IPv4 EndPoints
534 * (Serialization/Deserialization)<br/>
535 * Used resources:<br/>
536 * - PCEPEndPointsObject1IPv4.bin<br/>
538 * @throws IOException
539 * @throws PCEPDeserializerException
540 * @throws PCEPDocumentedException
543 public void testEndPointsObjectSerDeserIPv4() throws IOException, PCEPDeserializerException,
544 PCEPDocumentedException {
545 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
546 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
547 serDeserTest("src/test/resources/PCEPEndPointsObject1IPv4.bin", new PCEPEndPointsObject<IPv4Address>(
548 new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes)));
552 * Test for upper/lower bounds of IPv6 EndPoints
553 * (Serialization/Deserialization)<br/>
554 * Used resources:<br/>
555 * - PCEPEndPointsObject2IPv6.bin<br/>
557 * @throws IOException
558 * @throws PCEPDeserializerException
559 * @throws PCEPDocumentedException
562 public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException,
563 PCEPDocumentedException {
564 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF,
565 (byte) 0xEC, (byte) 0xA1, (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50,
566 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
567 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
568 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
569 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
571 serDeserTest("src/test/resources/PCEPEndPointsObject2IPv6.bin", new PCEPEndPointsObject<IPv6Address>(
572 new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes)));
576 * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
578 * Used resources:<br/>
579 * - PCEPErrorObject1.bin<br/>
580 * - PCEPErrorObject3.bin<br/>
582 * @throws PCEPDeserializerException
583 * @throws IOException
584 * @throws PCEPDocumentedException
587 public void testErrorObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
588 PCEPDocumentedException {
589 serDeserTest("src/test/resources/PCEPErrorObject1.bin", new PCEPErrorObject(
590 PCEPErrors.NON_OR_INVALID_OPEN_MSG));
591 serDeserTest("src/test/resources/PCEPErrorObject3.bin", new PCEPErrorObject(
592 PCEPErrors.CAPABILITY_NOT_SUPPORTED));
596 * Test of validity of PCEPErrorObjectParser. Expect throwed
597 * NoSuchElementException.<br/>
599 * Used resources:<br/>
600 * - PCEPErrorObject2Invalid.bin<br/>
602 * @throws NoSuchElementException
603 * @throws IOException
604 * @throws PCEPDocumentedException
606 @Test(expected = PCEPDeserializerException.class)
607 public void testUnknownError() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
608 PCEPObjectFactory.parseObjects(
609 ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0);
613 * Test for upper/lower bounds of PCEPLspaObject
614 * (Serialization/Deserialization)<br/>
615 * Used resources:<br/>
616 * - PCEPLspaObject1LowerBounds.bin<br/>
617 * - PCEPLspaObject2UpperBounds.bin<br/>
618 * - PCEPLspaObject3RandVals.bin<br/>
620 * @throws IOException
621 * @throws PCEPDeserializerException
622 * @throws PCEPDocumentedException
625 public void testLspaObjectSerDeser() throws IOException, PCEPDeserializerException,
626 PCEPDocumentedException {
627 serDeserTest("src/test/resources/PCEPLspaObject2UpperBounds.bin", new PCEPLspaObject(0xFFFFFFFFL,
628 0xFFFFFFFFL, 0xFFFFFFFFL, (short) 0xFF, (short) 0xFF, false, true, true, true));
629 serDeserTest("src/test/resources/PCEPLspaObject1LowerBounds.bin", new PCEPLspaObject(0x00000000L,
630 0x00000000L, 0x00000000L, (short) 0x00, (short) 0x00, false, false, true, true));
631 serDeserTest("src/test/resources/PCEPLspaObject3RandVals.bin", new PCEPLspaObject(0x20A1FEE3L,
632 0x1A025CC7L, 0x2BB66532L, (short) 0x03, (short) 0x02, false, true, true, true));
636 public void testMetricObjectSerDeserBounds() throws IOException, PCEPDeserializerException,
637 PCEPDocumentedException {
638 final byte[] bytesFromFileUB = ByteArray
639 .fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
640 final byte[] bytesFromFileLB = ByteArray
641 .fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
643 final PCEPMetricObject metricObjectLB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(
644 bytesFromFileLB).get(0);
645 final PCEPMetricObject metricObjectUB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(
646 bytesFromFileUB).get(0);
648 assertEquals(new PCEPMetricObject(false, false, new IGPMetric(0), true, true), metricObjectLB);
649 assertEquals(new PCEPMetricObject(false, true, new TEMetric(4026531840L), true, true), metricObjectUB);
651 final byte[] bytesActualLB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectLB));
652 final byte[] bytesActualUB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectUB));
653 assertArrayEquals(bytesFromFileLB, bytesActualLB);
654 assertArrayEquals(bytesFromFileUB, bytesActualUB);
658 * Standard deserialization test + specific test without tlv<br/>
659 * Used resources:<br/>
660 * - NoPathObject1WithTLV.bin<br/>
661 * - NoPathObject2WithoutTLV.bin<br/>
663 * @throws PCEPDeserializerException
664 * @throws IOException
665 * @throws PCEPDocumentedException
668 public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException,
669 PCEPDocumentedException {
670 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
671 tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
672 serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true,
674 serDeserTest("src/test/resources/NoPathObject2WithoutTLV.bin", new PCEPNoPathObject((short) 0x10,
680 * Standard serialization test + without tlv<br/>
681 * Used resources:<br/>
682 * - NoPathObject1WithTLV.bin<br/>
683 * - NoPathObject2WithoutTLV.bin<br/>
685 * @throws PCEPDeserializerException
686 * @throws IOException
687 * @throws PCEPDocumentedException
690 public void testNoPathObjectSerialization() throws IOException, PCEPDeserializerException,
691 PCEPDocumentedException {
692 byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject2WithoutTLV.bin");
693 PCEPNoPathObject noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(
695 byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
696 assertArrayEquals(bytesFromFile, bytesActual);
698 bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject1WithTLV.bin");
699 noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
700 bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
701 assertArrayEquals(bytesFromFile, bytesActual);
705 * Specific test with/without tlvs (Ser/Deser)<br/>
706 * Used resources:<br/>
707 * - PCEPNotificationObject1WithTlv.bin -
708 * PCEPNotificationObject2WithoutTlv.bin
710 * @throws PCEPDeserializerException
711 * @throws IOException
712 * @throws PCEPDocumentedException
715 public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
716 PCEPDocumentedException {
717 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
718 tlvs.add(new OverloadedDurationTlv(0xFF0000A2));
719 serDeserTest("src/test/resources/PCEPNotificationObject1WithTlv.bin", new PCEPNotificationObject(
720 (short) 1, (short) 1, tlvs));
721 serDeserTest("src/test/resources/PCEPNotificationObject2WithoutTlv.bin", new PCEPNotificationObject(
722 (short) 0xFF, (short) 0xFF));
726 * Standard ser deser test<br/>
727 * used resources:<br/>
728 * - PCEPOpenObject1.bin
730 * @throws PCEPDeserializerException
731 * @throws IOException
732 * @throws PCEPDocumentedException
735 @Ignore //FIXME: temporary
736 public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException,
737 PCEPDocumentedException {
738 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
739 tlvs.add(new PCEStatefulCapabilityTlv(false, true, true));
740 tlvs.add(new LSPStateDBVersionTlv(0x80));
741 final byte[] valueBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
742 (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 };
743 tlvs.add(new NodeIdentifierTlv(valueBytes));
744 final PCEPOpenObject specObject = new PCEPOpenObject(30, 120, 1, tlvs);
746 serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject);
750 * Specific test for upper bounds and without tlvs<br/>
751 * Used resources:<br/>
752 * - PCEPOpenObject2UpperBoundsNoTlv.bin
754 * @throws PCEPDeserializerException
755 * @throws IOException
756 * @throws PCEPDocumentedException
759 public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException,
760 PCEPDocumentedException {
761 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
762 serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF,
764 serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF,
769 * Standard deserialization test<br/>
770 * Used resources:<br/>
771 * - PCEPRPObject1.bin
773 * @throws PCEPDeserializerException
774 * @throws IOException
775 * @throws PCEPDocumentedException
778 public void testRPObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
779 serDeserTest("src/test/resources/PCEPRPObject1.bin", new PCEPRequestParameterObject(true, false,
780 true, true, false, false, false, false, (short) 5, 0xdeadbeefL, false, false));
781 serDeserTest("src/test/resources/PCEPRPObject2.bin", new PCEPRequestParameterObject(true, false,
782 false, false, true, false, true, false, true, (short) 5, 0xdeadbeefL,
783 new ArrayList<PCEPTlv>() {
784 private static final long serialVersionUID = 1L;
787 this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
793 * Test for upper/lower bounds of PCEPSvecObject
794 * (Serialization/Deserialization)<br/>
795 * Used resources:<br/>
796 * - PCEPSvecObject1_10ReqIDs.bin<br/>
798 * @throws IOException
799 * @throws PCEPDeserializerException
800 * @throws PCEPDocumentedException
803 public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException,
804 PCEPDocumentedException {
805 final List<Long> requestIDs = new ArrayList<Long>(10);
806 requestIDs.add(0xFFFFFFFFL);
807 requestIDs.add(0x00000000L);
808 requestIDs.add(0x01234567L);
809 requestIDs.add(0x89ABCDEFL);
810 requestIDs.add(0xFEDCBA98L);
811 requestIDs.add(0x76543210L);
812 requestIDs.add(0x15825266L);
813 requestIDs.add(0x48120BBEL);
814 requestIDs.add(0x25FB7E52L);
815 requestIDs.add(0xB2F2546BL);
817 serDeserTest("src/test/resources/PCEPSvecObject1_10ReqIDs.bin", new PCEPSvecObject(true, false, true,
818 false, true, requestIDs, true));
822 * Test for lowest bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
823 * Used resources:<br/>
824 * - PCEPSvecObject2.bin<br/>
826 * @throws IOException
827 * @throws PCEPDeserializerException
828 * @throws PCEPDocumentedException
831 public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException,
832 PCEPDocumentedException {
833 final List<Long> requestIDs = new ArrayList<Long>();
834 requestIDs.add(0xFFL);
835 serDeserTest("src/test/resources/PCEPSvecObject2.bin", new PCEPSvecObject(false, false, false, false,
836 false, requestIDs, false));
840 public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
841 final PCEPClassTypeObject ct = new PCEPClassTypeObject((short) 4);
842 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
843 final byte[] bytes = parser.put(ct);
844 assertEquals(ct, parser.parse(bytes, true, false));
848 * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
849 * Used resources:<br/>
850 * - PCEPExcludeRouteObject.1.bin<br/>
852 * @throws IOException
853 * @throws PCEPDeserializerException
854 * @throws PCEPDocumentedException
857 public void testExcludeRouteObject() throws IOException, PCEPDeserializerException,
858 PCEPDocumentedException {
859 final List<ExcludeRouteSubobject> xroSubobjects = new ArrayList<ExcludeRouteSubobject>();
860 xroSubobjects.add(new XROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] {
861 (byte) 192, (byte) 168, (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE));
862 xroSubobjects.add(new XROAsNumberSubobject(new ASNumber(0x1234L), false));
867 public void tesObjectiveFunctionObject() throws IOException, PCEPDeserializerException,
868 PCEPDocumentedException {
869 serDeserTest("src/test/resources/PCEPObjectiveFunctionObject.1.bin", new PCEPObjectiveFunctionObject(
870 PCEPOFCodes.MBC, true, false));
874 public void tesGlobalConstraintsObject() throws IOException, PCEPDeserializerException,
875 PCEPDocumentedException {
876 serDeserTest("src/test/resources/PCEPGlobalConstraintsObject.1.bin", new PCEPGlobalConstraintsObject(
877 (short) 1, (short) 0, (short) 100, (short) 0xFF, true, false));
880 // FIXME: add at least one test with true value
882 public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException {
883 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, false));
884 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, true));
885 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, false));
886 this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, true));
889 private void testOpenObjectWithSpecTlv(final PCEPTlv tlv) throws PCEPDeserializerException,
890 PCEPDocumentedException {
891 final List<PCEPObject> objs = new ArrayList<PCEPObject>();
892 final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
894 final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs);
896 final byte[] bytes = PCEPObjectFactory.put(objs);
897 final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0);
898 assertEquals(oo, obj);
902 public void testErrorsMapping() {
903 final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping
906 for (final PCEPErrors error : PCEPErrors.values()) {
907 final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error);
908 assertEquals(error, mapper.getFromErrorIdentifier(errorId));
913 public void testOFCodesMapping() {
914 final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance();
916 for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) {
917 final int ofCodeId = mapper.getFromOFCodesEnum(ofCode);
918 assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId));
922 @SuppressWarnings("unchecked")
923 private static <T extends PCEPObject> void serDeserTestWithoutBin(final T object)
924 throws PCEPDeserializerException, PCEPDocumentedException {
925 final byte[] serBytes = PCEPObjectFactory.put(Arrays.asList((PCEPObject) object));
926 final T deserObj = (T) PCEPObjectFactory.parseObjects(serBytes).get(0);
928 assertEquals(object, deserObj);
932 * tests without the need of binary files
935 public void testBranchNodeObjects() throws PCEPDocumentedException, PCEPDeserializerException {
936 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
937 eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] {
938 (byte) 192, (byte) 168, 1, 8 }), 16), false));
939 eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(new byte[] {
940 (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1,
941 (byte) 192, (byte) 168, 2, 1 }), 64), false));
943 serDeserTestWithoutBin(new PCEPBranchNodeListObject(eroSubobjects, true, false));
944 serDeserTestWithoutBin(new PCEPNonBranchNodeListObject(eroSubobjects, true, false));
949 public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException {
950 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
951 eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] {
952 (byte) 192, (byte) 168, 1, 8 }), 16), false));
953 eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(new byte[] {
954 (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1,
955 (byte) 192, (byte) 168, 2, 1 }), 64), false));
957 serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false));
961 public void testSRRObject() throws PCEPDocumentedException, PCEPDeserializerException {
962 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>();
963 rroSubobjects.add(new RROIPAddressSubobject<IPv4Prefix>(new IPv4Prefix(this.ipv4addr, 16), true,
965 rroSubobjects.add(new RROIPAddressSubobject<IPv6Prefix>(new IPv6Prefix(this.ipv6addr, 64), false,
968 serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
972 public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException {
973 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(2, this.ipv4addr, Arrays.asList(
974 this.ipv4addr, this.ipv4addr, this.ipv4addr), true, false));
975 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(1, this.ipv4addr,
976 Arrays.asList(this.ipv4addr), true, false));
977 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(2, this.ipv6addr, Arrays.asList(
978 this.ipv6addr, this.ipv6addr, this.ipv6addr), true, false));
979 serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(1, this.ipv6addr,
980 Arrays.asList(this.ipv6addr), true, false));
984 public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException {
985 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr,
986 this.ipv4addr, this.ipv4addr), true, false));
987 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr),
989 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr,
990 this.ipv6addr, this.ipv6addr), true, false));
991 serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr),