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;
13 import java.io.IOException;
14 import java.util.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.protocol.concepts.Ipv4Util;
19 import org.opendaylight.protocol.concepts.Ipv6Util;
20 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
21 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
22 import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
23 import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
24 import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
25 import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
26 import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
27 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
28 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
29 import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
30 import org.opendaylight.protocol.util.ByteArray;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv4Builder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv6Builder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.reported.route.BandwidthBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
41 import com.google.common.collect.Lists;
42 import com.google.common.primitives.UnsignedBytes;
47 * PCEPOpenObject3.bin<br/>
53 * - processing: true<br/>
54 * - ignored: true<br/>
61 * PCEPBandwidthObject1LowerBounds.bin<br/>
67 * - processing: true<br/>
68 * - ignored: true<br/>
72 * PCEPBandwidthObject2UpperBounds.bin<br/>
78 * - processing: true<br/>
79 * - ignored: true<br/>
81 * Bandwidth: 0xFFFFFFFF<br/>
83 * PCEPEndPointsObject1IPv4.bin<br/>
89 * - processing: true<br/>
90 * - ignored: true<br/>
92 * src IP: 0xA2F5110E <br/>
93 * dest IP: 0xFFFFFFFF <br/>
95 * PCEPEndPointsObject2IPv6.bin<br/>
101 * - processing: true<br/>
102 * - ignored: true<br/>
104 * src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF<br/>
105 * dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000 <br/>
107 * PCEPErrorObject1.bin<br/>
108 * objClass: 13 (RP)<br/>
113 * - processing: false<br/>
114 * - ignored: false<br/>
117 * Error-value: 1<br/>
120 * PCEPErrorObject2Invalid.bin<br/>
121 * objClass: 13 (RP)<br/>
126 * - processing: false<br/>
127 * - ignored: false<br/>
130 * Error-value: 0<br/>
133 * PCEPErrorObject3.bin<br/>
134 * objClass: 13 (RP)<br/>
139 * - processing: false<br/>
140 * - ignored: false<br/>
143 * Error-value: 0<br/>
146 * PCEPLspaObject1LowerBounds.bin<br/>
152 * - processing: true<br/>
153 * - ignored: true<br/>
155 * Exclude-any: 0x00000000L<br/>
156 * Include-any: 0x00000000L<br/>
157 * Include-all: 0x00000000L<br/>
158 * Setup Prio: 0x00<br/>
159 * Holding Prio: 0x00<br/>
160 * Flags: - L : false<br/>
162 * PCEPLspaObject2UpperBounds.bin<br/>
168 * - processing: true<br/>
169 * - ignored: true<br/>
171 * Exclude-any: 0xFFFFFFFFL<br/>
172 * Include-any: 0xFFFFFFFFL<br/>
173 * Include-all: 0xFFFFFFFFL<br/>
174 * Setup Prio: 0xFF<br/>
175 * Holding Prio: 0xFF<br/>
176 * Flags: - L : true<br/>
178 * PCEPLspaObject3RandVals.bin<br/>
184 * - processing: true<br/>
185 * - ignored: true<br/>
187 * Exclude-any: 0x20A1FEE3L<br/>
188 * Include-any: 0x1A025CC7L<br/>
189 * Include-all: 0x2BB66532L<br/>
190 * Setup Prio: 0x03<br/>
191 * Holding Prio: 0x02<br/>
192 * Flags: - L : true<br/>
194 * NoPathObject1WithTLV.bin<br/>
195 * objClass: 3 (RP)<br/>
200 * - processing: false<br/>
201 * - ignored: false<br/>
203 * Nature of Issue: 2<br/>
204 * No-Path flags:<br/>
208 * -- NO-PATH-VECTOR<br/>
209 * - flags (0x4000):<br/>
210 * - PCE currently unavailable: false<br/>
211 * - unknown destination: true<br/>
212 * - unknown source: false<br/>
215 * NoPathObject2WithoutTLV.bin<br/>
216 * objClass: 3 (RP)<br/>
221 * - processing: false<br/>
222 * - ignored: true<br/>
224 * Nature of Issue: 16<br/>
225 * No-Path flags:<br/>
230 * PCEPNotificationObject1WithTlv.bin <br/>
236 * - processing: false<br/>
237 * - ignored: false<br/>
242 * - OverloaderDuration(0xFF0000A2L)<br/>
244 * PCEPNotificationObject2WithoutTlv.bin <br/>
250 * - processing: false<br/>
251 * - ignored: false<br/>
257 * PCEPOpenObject1.bin<br/>
263 * - processing: false<br/>
264 * - ignored: false<br/>
267 * deadTimer: 120<br/>
270 * - PCEPStatefulCapability<br/>
271 * - LSPStateDBVersionTlv<br/>
272 * - NodeIdentifierTlv<br/>
274 * PCEPOpenObject2UpperBoundsNoTlv.bin<br/>
280 * - processing: false<br/>
281 * - ignored: false<br/>
283 * keepAlive: 0xFF<br/>
284 * deadTimer: 0xFF<br/>
285 * sessionId: 0xFF<br/>
288 * PCEPRPObject1.bin<br/>
289 * objClass: 2 (RP)<br/>
294 * - processing: false<br/>
295 * - ignored: false<br/>
298 * - loose/strict: true<br/>
299 * - Bi-directional: false<br/>
300 * - Reoptimization: false<br/>
302 * Request ID: 0xDEADBEEF<br/>
305 * PCEPSvecObject1_10ReqIDs.bin <br/>
311 * - processing: true<br/>
312 * - ignored: false<br/>
315 * - Link diverse: true<br/>
316 * - Node diverse: false<br/>
317 * - SRLG diverse: true<br/>
318 * Reques-ID-numbers:<br/>
319 * #1 - 0xFFFFFFFFL<br/>
320 * #2 - 0x00000000L<br/>
321 * #3 - 0x01234567L<br/>
322 * #4 - 0x89ABCDEFL<br/>
323 * #5 - 0xFEDCBA98L<br/>
324 * #6 - 0x76543210L<br/>
325 * #7 - 0x15825266L<br/>
326 * #8 - 0x48120BBEL<br/>
327 * #9 - 0x25FB7E52L<br/>
328 * #10 - 0xB2F2546BL<br/>
330 * PCEPSvecObject2.bin <br/>
336 * - processing: false<br/>
337 * - ignored: false<br/>
340 * - Link diverse: false<br/>
341 * - Node diverse: false<br/>
342 * - SRLG diverse: false<br/>
343 * Reques-ID-numbers:<br/>
344 * #1 - 0x000000FFL<br/>
345 * PCEPExcludeRouteObject.1.bin <br/>
348 * objLength: 20 <br/>
353 * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node) <br/>
354 * - XROASnumber(0x1234) <br/>
356 public class PCEPObjectParserTest {
358 private TlvHandlerRegistry tlvRegistry;
361 public void setUp() throws Exception {
362 this.tlvRegistry = PCEPExtensionProviderContextImpl.create().getTlvHandlerRegistry();
365 // IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
367 // IPv6Address ipv6addr = new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1,
368 // (byte) 192, (byte) 168,
369 // 2, 1, (byte) 192, (byte) 168, 2, 1 });
373 // * Standard serialization test<br/>
374 // * Used resources:<br/>
375 // * - PCEPOpenObject1.bin<br/>
377 // * @throws PCEPDeserializerException
378 // * @throws IOException
379 // * @throws PCEPDocumentedException
383 // // FIXME: temporary
384 // public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
385 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
389 // public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
391 // final PCEPObject obj =
392 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get(
395 // // assertTrue(obj instanceof UnknownObject);
396 // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
400 // // public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
401 // // final PCEPObject obj =
402 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0);
404 // // assertTrue(obj instanceof UnknownObject);
405 // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
409 // // public void testCloseObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
410 // // serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG));
414 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
415 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser(this.tlvRegistry);
416 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin");
418 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
419 builder.setProcessingRule(true);
420 builder.setIgnore(false);
421 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
422 builder.setMinBandwidth(new Float32(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
424 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
425 assertArrayEquals(result, parser.serializeObject(builder.build()));
430 // public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
431 // serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false,
432 // true, false, null));
436 // public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
437 // final byte[] bytesFromFile =
438 // ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
440 // MockitoAnnotations.initMocks(this);
441 // PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(registry);
442 // doReturn(parser).when(registry).getObjectParser(PCEPExplicitRouteObjectParser.TYPE,
443 // PCEPExplicitRouteObjectParser.CLASS);
444 // doReturn(new EROAsNumberSubobjectParser()).when(registry).getSubobjectParser(EROAsNumberSubobjectParser.TYPE);
445 // ObjectHeader h = new ObjectHeader() {
448 // public Class<? extends DataContainer> getImplementedInterface() {
449 // // TODO Auto-generated method stub
454 // public Boolean isProcessingRule() {
459 // public Boolean isIgnore() {
464 // final ExplicitRouteSubobject specObj = (ExplicitRouteSubobject)
465 // registry.getObjectParser(PCEPExplicitRouteObjectParser.TYPE, PCEPExplicitRouteObjectParser.CLASS).parseObject(h,
468 // System.out.println(specObj.toString());
470 // //final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
471 // //assertArrayEquals(bytesFromFile, bytesActual);
475 // public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
476 // final byte[] bytesFromFile =
477 // ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin");
479 // final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject)
480 // PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
482 // assertEquals(8, specObj.getSubobjects().size());
484 // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
485 // assertArrayEquals(bytesFromFile, bytesActual);
489 // public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
490 // final byte[] bytesFromFile =
491 // ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin");
493 // final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject)
494 // PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
496 // assertEquals(6, specObj.getSubobjects().size());
498 // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
499 // assertArrayEquals(bytesFromFile, bytesActual);
504 public void testBandwidthObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
505 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser(this.tlvRegistry);
506 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin");
508 final BandwidthBuilder builder = new BandwidthBuilder();
509 builder.setProcessingRule(true);
510 builder.setIgnore(true);
511 builder.setBandwidth(new Float32(result));
513 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
514 assertArrayEquals(result, parser.serializeObject(builder.build()));
516 result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin");
518 builder.setBandwidth(new Float32(result));
520 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
521 assertArrayEquals(result, parser.serializeObject(builder.build()));
525 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
526 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
527 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
529 final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
530 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin");
532 final EndpointsBuilder builder = new EndpointsBuilder();
533 builder.setProcessingRule(true);
534 builder.setIgnore(false);
535 builder.setAddressFamily(new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
536 Ipv4Util.addressForBytes(destIPBytes)).build());
538 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
539 assertArrayEquals(result, parser.serializeObject(builder.build()));
543 public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
544 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
545 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
546 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
547 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
549 final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
550 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin");
552 final EndpointsBuilder builder = new EndpointsBuilder();
553 builder.setProcessingRule(true);
554 builder.setIgnore(false);
555 builder.setAddressFamily(new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
556 Ipv6Util.addressForBytes(destIPBytes)).build());
558 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
559 assertArrayEquals(result, parser.serializeObject(builder.build()));
564 // * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
566 // * Used resources:<br/>
567 // * - PCEPErrorObject1.bin<br/>
568 // * - PCEPErrorObject3.bin<br/>
570 // * @throws PCEPDeserializerException
571 // * @throws IOException
572 // * @throws PCEPDocumentedException
575 // public void testErrorObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
576 // PCEPDocumentedException {
577 // serDeserTest("src/test/resources/PCEPErrorObject1.bin", new PCEPErrorObject(PCEPErrors.NON_OR_INVALID_OPEN_MSG));
578 // serDeserTest("src/test/resources/PCEPErrorObject3.bin", new
579 // PCEPErrorObject(PCEPErrors.CAPABILITY_NOT_SUPPORTED));
583 // * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.<br/>
585 // * Used resources:<br/>
586 // * - PCEPErrorObject2Invalid.bin<br/>
588 // * @throws NoSuchElementException
589 // * @throws IOException
590 // * @throws PCEPDocumentedException
592 // @Test(expected = PCEPDeserializerException.class)
593 // public void testUnknownError() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
594 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0);
598 // * Test for upper/lower bounds of PCEPLspaObject (Serialization/Deserialization)<br/>
599 // * Used resources:<br/>
600 // * - PCEPLspaObject1LowerBounds.bin<br/>
601 // * - PCEPLspaObject2UpperBounds.bin<br/>
602 // * - PCEPLspaObject3RandVals.bin<br/>
604 // * @throws IOException
605 // * @throws PCEPDeserializerException
606 // * @throws PCEPDocumentedException
609 // public void testLspaObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
610 // serDeserTest("src/test/resources/PCEPLspaObject2UpperBounds.bin",
611 // new PCEPLspaObject(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, (short) 0xFF, (short) 0xFF, false, true, true, true));
612 // serDeserTest("src/test/resources/PCEPLspaObject1LowerBounds.bin",
613 // new PCEPLspaObject(0x00000000L, 0x00000000L, 0x00000000L, (short) 0x00, (short) 0x00, false, false, true, true));
614 // serDeserTest("src/test/resources/PCEPLspaObject3RandVals.bin",
615 // new PCEPLspaObject(0x20A1FEE3L, 0x1A025CC7L, 0x2BB66532L, (short) 0x03, (short) 0x02, false, true, true, true));
620 public void testMetricObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
621 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser(this.tlvRegistry);
622 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
624 final MetricBuilder builder = new MetricBuilder();
625 builder.setProcessingRule(true);
626 builder.setIgnore(true);
627 builder.setComputed(false);
628 builder.setBound(false);
629 builder.setMetricType((short) 1);
630 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
632 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
633 assertArrayEquals(result, parser.serializeObject(builder.build()));
635 result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
637 builder.setComputed(true);
638 builder.setBound(false);
639 builder.setMetricType((short) 2);
640 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
642 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
643 assertArrayEquals(result, parser.serializeObject(builder.build()));
648 // * Standard deserialization test + specific test without tlv<br/>
649 // * Used resources:<br/>
650 // * - NoPathObject1WithTLV.bin<br/>
651 // * - NoPathObject2WithoutTLV.bin<br/>
653 // * @throws PCEPDeserializerException
654 // * @throws IOException
655 // * @throws PCEPDocumentedException
658 // public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException,
659 // PCEPDocumentedException {
660 // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
661 // // tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
662 // // serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs,
664 // serDeserTest("src/test/resources/NoPathObject2WithoutTLV.bin", new PCEPNoPathObject((short) 0x10, false, true));
669 // * Standard serialization test + without tlv<br/>
670 // * Used resources:<br/>
671 // * - NoPathObject1WithTLV.bin<br/>
672 // * - NoPathObject2WithoutTLV.bin<br/>
674 // * @throws PCEPDeserializerException
675 // * @throws IOException
676 // * @throws PCEPDocumentedException
679 // public void testNoPathObjectSerialization() throws IOException, PCEPDeserializerException,
680 // PCEPDocumentedException {
681 // byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject2WithoutTLV.bin");
682 // PCEPNoPathObject noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
683 // byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
684 // assertArrayEquals(bytesFromFile, bytesActual);
686 // bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject1WithTLV.bin");
687 // noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
688 // bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
689 // assertArrayEquals(bytesFromFile, bytesActual);
693 // * Specific test with/without tlvs (Ser/Deser)<br/>
694 // * Used resources:<br/>
695 // * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin
697 // * @throws PCEPDeserializerException
698 // * @throws IOException
699 // * @throws PCEPDocumentedException
702 // public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
703 // PCEPDocumentedException {
704 // // FINAL LIST<PCEPTLV> TLVS = NEW ARRAYLIST<PCEPTLV>(1);
705 // // TLVS.ADD(NEW OVERLOADEDDURATIONTLV(0XFF0000A2));
706 // // SERDESERTEST("src/test/resources/PCEPNotificationObject1WithTlv.bin", new PCEPNotificationObject((short) 1,
707 // (short) 1, tlvs));
708 // serDeserTest("src/test/resources/PCEPNotificationObject2WithoutTlv.bin", new PCEPNotificationObject((short) 0xFF,
713 // * Standard ser deser test<br/>
714 // * used resources:<br/>
715 // * - PCEPOpenObject1.bin
717 // * @throws PCEPDeserializerException
718 // * @throws IOException
719 // * @throws PCEPDocumentedException
723 // // FIXME: temporary
724 // public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
725 // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
726 // // tlvs.add(new PCEStatefulCapabilityTlv(false, true, true));
727 // // tlvs.add(new LSPStateDBVersionTlv(0x80));
728 // // final byte[] valueBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC,
729 // (byte) 0xDE, (byte) 0xF0 };
730 // // tlvs.add(new NodeIdentifierTlv(valueBytes));
731 // // final PCEPOpenObject specObject = new PCEPOpenObject(30, 120, 1, tlvs);
733 // // serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject);
737 // * Specific test for upper bounds and without tlvs<br/>
738 // * Used resources:<br/>
739 // * - PCEPOpenObject2UpperBoundsNoTlv.bin
741 // * @throws PCEPDeserializerException
742 // * @throws IOException
743 // * @throws PCEPDocumentedException
746 // public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException,
747 // PCEPDocumentedException {
748 // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
749 // // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF,
751 // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF,
756 // * Standard deserialization test<br/>
757 // * Used resources:<br/>
758 // * - PCEPRPObject1.bin
760 // * @throws PCEPDeserializerException
761 // * @throws IOException
762 // * @throws PCEPDocumentedException
765 // public void testRPObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
766 // serDeserTest("src/test/resources/PCEPRPObject1.bin",
767 // new PCEPRequestParameterObject(true, false, true, true, false, false, false, false, (short) 5, 0xdeadbeefL,
770 // // "src/test/resources/PCEPRPObject2.bin",
771 // // new PCEPRequestParameterObject(true, false, false, false, true, false, true, false, true, (short) 5,
772 // 0xdeadbeefL, new ArrayList<PCEPTlv>() {
773 // // private static final long serialVersionUID = 1L;
776 // // this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
778 // // }, false, false));
783 public void testSvecObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
784 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser(this.tlvRegistry);
785 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin");
787 final SvecBuilder builder = new SvecBuilder();
788 builder.setProcessingRule(false);
789 builder.setIgnore(false);
790 builder.setLinkDiverse(false);
791 builder.setNodeDiverse(false);
792 builder.setSrlgDiverse(false);
793 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
795 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
796 assertArrayEquals(result, parser.serializeObject(builder.build()));
798 result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin");
800 builder.setProcessingRule(true);
801 builder.setLinkDiverse(true);
802 builder.setSrlgDiverse(true);
804 final List<RequestId> requestIDs = Lists.newArrayList();
805 requestIDs.add(new RequestId(0xFFFFFFFFL));
806 requestIDs.add(new RequestId(0x00000000L));
807 requestIDs.add(new RequestId(0x01234567L));
808 requestIDs.add(new RequestId(0x89ABCDEFL));
809 requestIDs.add(new RequestId(0xFEDCBA98L));
810 requestIDs.add(new RequestId(0x76543210L));
811 requestIDs.add(new RequestId(0x15825266L));
812 requestIDs.add(new RequestId(0x48120BBEL));
813 requestIDs.add(new RequestId(0x25FB7E52L));
814 requestIDs.add(new RequestId(0xB2F2546BL));
816 builder.setRequestsIds(requestIDs);
818 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
819 assertArrayEquals(result, parser.serializeObject(builder.build()));
824 // public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
825 // final PCEPClassTypeObject ct = new PCEPClassTypeObject((short) 4);
826 // // final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
827 // // final byte[] bytes = parser.put(ct);
828 // // assertEquals(ct, parser.parse(bytes, true, false));
832 // * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
833 // * Used resources:<br/>
834 // * - PCEPExcludeRouteObject.1.bin<br/>
836 // * @throws IOException
837 // * @throws PCEPDeserializerException
838 // * @throws PCEPDocumentedException
841 // public void testExcludeRouteObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
842 // final List<ExcludeRouteSubobject> xroSubobjects = new ArrayList<ExcludeRouteSubobject>();
843 // xroSubobjects.add(new XROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192,
845 // (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE));
846 // xroSubobjects.add(new XROAsNumberSubobject(new AsNumber(0x1234L), false));
851 // public void tesObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
852 // serDeserTest("src/test/resources/PCEPObjectiveFunctionObject.1.bin", new
853 // PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false));
857 // public void tesGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
858 // serDeserTest("src/test/resources/PCEPGlobalConstraintsObject.1.bin",
859 // new PCEPGlobalConstraintsObject((short) 1, (short) 0, (short) 100, (short) 0xFF, true, false));
862 // // FIXME: add at least one test with true value
864 // public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException {
865 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, false));
866 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, true));
867 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, false));
868 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, true));
871 // // private void testOpenObjectWithSpecTlv(final PCEPTlv tlv) throws PCEPDeserializerException,
872 // PCEPDocumentedException {
873 // // final List<PCEPObject> objs = new ArrayList<PCEPObject>();
874 // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
876 // // final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs);
878 // // final byte[] bytes = PCEPObjectFactory.put(objs);
879 // // final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0);
880 // // assertEquals(oo, obj);
884 // public void testErrorsMapping() {
885 // final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance();
887 // for (final PCEPErrors error : PCEPErrors.values()) {
888 // final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error);
889 // assertEquals(error, mapper.getFromErrorIdentifier(errorId));
894 // public void testOFCodesMapping() {
895 // final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance();
897 // for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) {
898 // final int ofCodeId = mapper.getFromOFCodesEnum(ofCode);
899 // assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId));
903 // @SuppressWarnings("unchecked")
904 // private static <T extends PCEPObject> void serDeserTestWithoutBin(final T object) throws
905 // PCEPDeserializerException,
906 // PCEPDocumentedException {
907 // final byte[] serBytes = PCEPObjectFactory.put(Arrays.asList((PCEPObject) object));
908 // final T deserObj = (T) PCEPObjectFactory.parseObjects(serBytes).get(0);
910 // assertEquals(object, deserObj);
914 // public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException {
915 // final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
916 // eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192,
917 // (byte) 168, 1, 8 }), 16), false));
918 // eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(new byte[] { (byte) 192,
920 // (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1 }), 64), false));
922 // serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false));
926 // public void testSRRObject() throws PCEPDocumentedException, PCEPDeserializerException {
927 // final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>();
928 // rroSubobjects.add(new RROIPAddressSubobject<IPv4Prefix>(new IPv4Prefix(this.ipv4addr, 16), true, false));
929 // rroSubobjects.add(new RROIPAddressSubobject<IPv6Prefix>(new IPv6Prefix(this.ipv6addr, 64), false, true));
931 // serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
935 // public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException {
936 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(2, this.ipv4addr, Arrays.asList(this.ipv4addr,
938 // this.ipv4addr), true, false));
939 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(1, this.ipv4addr, Arrays.asList(this.ipv4addr),
941 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(2, this.ipv6addr, Arrays.asList(this.ipv6addr,
943 // this.ipv6addr), true, false));
944 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(1, this.ipv6addr, Arrays.asList(this.ipv6addr),
949 // public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException {
950 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr,
951 // this.ipv4addr, this.ipv4addr), true, false));
952 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr), true,
954 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr,
955 // this.ipv6addr, this.ipv6addr), true, false));
956 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr), true,