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;
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;
85 * PCEPOpenObject3.bin<br/>
91 * - processing: true<br/>
92 * - ignored: true<br/>
99 * PCEPBandwidthObject1LowerBounds.bin<br/>
105 * - processing: true<br/>
106 * - ignored: true<br/>
110 * PCEPBandwidthObject2UpperBounds.bin<br/>
116 * - processing: true<br/>
117 * - ignored: true<br/>
119 * Bandwidth: 0xFFFFFFFF<br/>
121 * PCEPEndPointsObject1IPv4.bin<br/>
127 * - processing: true<br/>
128 * - ignored: true<br/>
130 * src IP: 0xA2F5110E <br/>
131 * dest IP: 0xFFFFFFFF <br/>
133 * PCEPEndPointsObject2IPv6.bin<br/>
139 * - processing: true<br/>
140 * - ignored: true<br/>
142 * src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF<br/>
143 * dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000 <br/>
145 * PCEPErrorObject1.bin<br/>
146 * objClass: 13 (RP)<br/>
151 * - processing: false<br/>
152 * - ignored: false<br/>
155 * Error-value: 1<br/>
158 * PCEPErrorObject2Invalid.bin<br/>
159 * objClass: 13 (RP)<br/>
164 * - processing: false<br/>
165 * - ignored: false<br/>
168 * Error-value: 0<br/>
171 * PCEPErrorObject3.bin<br/>
172 * objClass: 13 (RP)<br/>
177 * - processing: false<br/>
178 * - ignored: false<br/>
181 * Error-value: 0<br/>
184 * PCEPLspaObject1LowerBounds.bin<br/>
190 * - processing: true<br/>
191 * - ignored: true<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/>
200 * PCEPLspaObject2UpperBounds.bin<br/>
206 * - processing: true<br/>
207 * - ignored: true<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/>
216 * PCEPLspaObject3RandVals.bin<br/>
222 * - processing: true<br/>
223 * - ignored: true<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/>
232 * NoPathObject1WithTLV.bin<br/>
233 * objClass: 3 (RP)<br/>
238 * - processing: false<br/>
239 * - ignored: false<br/>
241 * Nature of Issue: 2<br/>
242 * No-Path flags:<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/>
253 * NoPathObject2WithoutTLV.bin<br/>
254 * objClass: 3 (RP)<br/>
259 * - processing: false<br/>
260 * - ignored: true<br/>
262 * Nature of Issue: 16<br/>
263 * No-Path flags:<br/>
268 * PCEPNotificationObject1WithTlv.bin <br/>
274 * - processing: false<br/>
275 * - ignored: false<br/>
280 * - OverloaderDuration(0xFF0000A2L)<br/>
282 * PCEPNotificationObject2WithoutTlv.bin <br/>
288 * - processing: false<br/>
289 * - ignored: false<br/>
295 * PCEPOpenObject1.bin<br/>
301 * - processing: false<br/>
302 * - ignored: false<br/>
305 * deadTimer: 120<br/>
308 * - PCEPStatefulCapability<br/>
309 * - LSPStateDBVersionTlv<br/>
310 * - NodeIdentifierTlv<br/>
312 * PCEPOpenObject2UpperBoundsNoTlv.bin<br/>
318 * - processing: false<br/>
319 * - ignored: false<br/>
321 * keepAlive: 0xFF<br/>
322 * deadTimer: 0xFF<br/>
323 * sessionId: 0xFF<br/>
326 * PCEPRPObject1.bin<br/>
327 * objClass: 2 (RP)<br/>
332 * - processing: false<br/>
333 * - ignored: false<br/>
336 * - loose/strict: true<br/>
337 * - Bi-directional: false<br/>
338 * - Reoptimization: false<br/>
340 * Request ID: 0xDEADBEEF<br/>
343 * PCEPSvecObject1_10ReqIDs.bin <br/>
349 * - processing: true<br/>
350 * - ignored: false<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/>
368 * PCEPSvecObject2.bin <br/>
374 * - processing: false<br/>
375 * - ignored: false<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/>
386 * objLength: 20 <br/>
391 * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node) <br/>
392 * - XROASnumber(0x1234) <br/>
395 public class PCEPObjectParserTest {
397 IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
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 });
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));
409 assertEquals(specObject, deserSpecObj);
410 assertArrayEquals(bytesFromFile, serSpecObj);
414 * Standard serialization test<br/>
415 * Used resources:<br/>
416 * - PCEPOpenObject1.bin<br/>
418 * @throws PCEPDeserializerException
419 * @throws IOException
420 * @throws PCEPDocumentedException
425 public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
426 PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
430 public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
432 final PCEPObject obj = PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get(
435 assertTrue(obj instanceof UnknownObject);
436 assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
440 public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
441 final PCEPObject obj = PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0);
443 assertTrue(obj instanceof UnknownObject);
444 assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
448 public void testCloseObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
449 serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG));
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));
461 public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
462 serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false, true, false, null));
466 public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
467 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
469 final PCEPExplicitRouteObject specObj = (PCEPExplicitRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
471 assertEquals(8, specObj.getSubobjects().size());
473 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
474 assertArrayEquals(bytesFromFile, bytesActual);
478 public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
479 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin");
481 final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
483 assertEquals(8, specObj.getSubobjects().size());
485 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
486 assertArrayEquals(bytesFromFile, bytesActual);
490 public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
491 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin");
493 final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
495 assertEquals(6, specObj.getSubobjects().size());
497 final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
498 assertArrayEquals(bytesFromFile, bytesActual);
502 * Test for upper/lower bounds (Serialization/Deserialization)<br/>
503 * Used resources:<br/>
504 * - PCEPBandwidthObject2UpperBounds.bin<br/>
505 * - PCEPBandwidthObject1LowerBounds.bin<br/>
507 * @throws IOException
508 * @throws PCEPDeserializerException
509 * @throws PCEPDocumentedException
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));
520 * Test for upper/lower bounds of IPv4 EndPoints (Serialization/Deserialization)<br/>
521 * Used resources:<br/>
522 * - PCEPEndPointsObject1IPv4.bin<br/>
524 * @throws IOException
525 * @throws PCEPDeserializerException
526 * @throws PCEPDocumentedException
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)));
537 * Test for upper/lower bounds of IPv6 EndPoints (Serialization/Deserialization)<br/>
538 * Used resources:<br/>
539 * - PCEPEndPointsObject2IPv6.bin<br/>
541 * @throws IOException
542 * @throws PCEPDeserializerException
543 * @throws PCEPDocumentedException
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 };
552 serDeserTest("src/test/resources/PCEPEndPointsObject2IPv6.bin",
553 new PCEPEndPointsObject<IPv6Address>(new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes)));
557 * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
559 * Used resources:<br/>
560 * - PCEPErrorObject1.bin<br/>
561 * - PCEPErrorObject3.bin<br/>
563 * @throws PCEPDeserializerException
564 * @throws IOException
565 * @throws PCEPDocumentedException
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));
574 * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.<br/>
576 * Used resources:<br/>
577 * - PCEPErrorObject2Invalid.bin<br/>
579 * @throws NoSuchElementException
580 * @throws IOException
581 * @throws PCEPDocumentedException
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);
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/>
595 * @throws IOException
596 * @throws PCEPDeserializerException
597 * @throws PCEPDocumentedException
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));
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");
614 final PCEPMetricObject metricObjectLB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(bytesFromFileLB).get(0);
615 final PCEPMetricObject metricObjectUB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(bytesFromFileUB).get(0);
617 assertEquals(new PCEPMetricObject(false, false, new IGPMetric(0), true, true), metricObjectLB);
618 assertEquals(new PCEPMetricObject(false, true, new TEMetric(4026531840L), true, true), metricObjectUB);
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);
627 * Standard deserialization test + specific test without tlv<br/>
628 * Used resources:<br/>
629 * - NoPathObject1WithTLV.bin<br/>
630 * - NoPathObject2WithoutTLV.bin<br/>
632 * @throws PCEPDeserializerException
633 * @throws IOException
634 * @throws PCEPDocumentedException
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));
646 * Standard serialization test + without tlv<br/>
647 * Used resources:<br/>
648 * - NoPathObject1WithTLV.bin<br/>
649 * - NoPathObject2WithoutTLV.bin<br/>
651 * @throws PCEPDeserializerException
652 * @throws IOException
653 * @throws PCEPDocumentedException
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);
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);
669 * Specific test with/without tlvs (Ser/Deser)<br/>
670 * Used resources:<br/>
671 * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin
673 * @throws PCEPDeserializerException
674 * @throws IOException
675 * @throws PCEPDocumentedException
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));
686 * Standard ser deser test<br/>
687 * used resources:<br/>
688 * - PCEPOpenObject1.bin
690 * @throws PCEPDeserializerException
691 * @throws IOException
692 * @throws PCEPDocumentedException
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);
705 serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject);
709 * Specific test for upper bounds and without tlvs<br/>
710 * Used resources:<br/>
711 * - PCEPOpenObject2UpperBoundsNoTlv.bin
713 * @throws PCEPDeserializerException
714 * @throws IOException
715 * @throws PCEPDocumentedException
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));
725 * Standard deserialization test<br/>
726 * Used resources:<br/>
727 * - PCEPRPObject1.bin
729 * @throws PCEPDeserializerException
730 * @throws IOException
731 * @throws PCEPDocumentedException
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));
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;
743 this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
749 * Test for upper/lower bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
750 * Used resources:<br/>
751 * - PCEPSvecObject1_10ReqIDs.bin<br/>
753 * @throws IOException
754 * @throws PCEPDeserializerException
755 * @throws PCEPDocumentedException
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);
771 serDeserTest("src/test/resources/PCEPSvecObject1_10ReqIDs.bin",
772 new PCEPSvecObject(true, false, true, false, true, requestIDs, true));
776 * Test for lowest bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
777 * Used resources:<br/>
778 * - PCEPSvecObject2.bin<br/>
780 * @throws IOException
781 * @throws PCEPDeserializerException
782 * @throws PCEPDocumentedException
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));
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));
800 * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
801 * Used resources:<br/>
802 * - PCEPExcludeRouteObject.1.bin<br/>
804 * @throws IOException
805 * @throws PCEPDeserializerException
806 * @throws PCEPDocumentedException
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));
818 public void tesObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
819 serDeserTest("src/test/resources/PCEPObjectiveFunctionObject.1.bin", new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false));
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));
828 // FIXME: add at least one test with true value
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));
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>();
841 final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs);
843 final byte[] bytes = PCEPObjectFactory.put(objs);
844 final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0);
845 assertEquals(oo, obj);
849 public void testErrorsMapping() {
850 final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance();
852 for (final PCEPErrors error : PCEPErrors.values()) {
853 final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error);
854 assertEquals(error, mapper.getFromErrorIdentifier(errorId));
859 public void testOFCodesMapping() {
860 final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance();
862 for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) {
863 final int ofCodeId = mapper.getFromOFCodesEnum(ofCode);
864 assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId));
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);
874 assertEquals(object, deserObj);
878 * tests without the need of binary files
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));
887 serDeserTestWithoutBin(new PCEPBranchNodeListObject(eroSubobjects, true, false));
888 serDeserTestWithoutBin(new PCEPNonBranchNodeListObject(eroSubobjects, true, false));
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));
899 serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false));
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));
908 serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
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));
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));