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.PCEPClassTypeObjectParser;
24 import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
25 import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
26 import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
27 import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
28 import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
29 import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
30 import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
31 import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
32 import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
33 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
34 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
35 import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
36 import org.opendaylight.protocol.util.ByteArray;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv4Builder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv6Builder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.ClassTypeBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.LspaBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.OfBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.SrpBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
52 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;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.GcBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
57 import com.google.common.collect.Lists;
58 import com.google.common.primitives.UnsignedBytes;
60 public class PCEPObjectParserTest {
62 private TlvHandlerRegistry tlvRegistry;
65 public void setUp() throws Exception {
66 this.tlvRegistry = PCEPExtensionProviderContextImpl.create().getTlvHandlerRegistry();
71 // // FIXME: temporary
72 // public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
73 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
77 // public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
79 // final PCEPObject obj =
80 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get(
83 // // assertTrue(obj instanceof UnknownObject);
84 // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
88 // // public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
89 // // final PCEPObject obj =
90 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0);
92 // // assertTrue(obj instanceof UnknownObject);
93 // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
98 public void testCloseObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
99 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry);
100 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin");
102 final CCloseBuilder builder = new CCloseBuilder();
103 builder.setProcessingRule(false);
104 builder.setIgnore(false);
105 builder.setReason((short) 5);
107 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
108 assertArrayEquals(result, parser.serializeObject(builder.build()));
112 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
113 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser(this.tlvRegistry);
114 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin");
116 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
117 builder.setProcessingRule(true);
118 builder.setIgnore(false);
119 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
120 builder.setMinBandwidth(new Float32(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
122 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
123 assertArrayEquals(result, parser.serializeObject(builder.build()));
128 // public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
129 // serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false,
130 // true, false, null));
134 // public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
135 // final byte[] bytesFromFile =
136 // ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
138 // MockitoAnnotations.initMocks(this);
139 // PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(registry);
140 // doReturn(parser).when(registry).getObjectParser(PCEPExplicitRouteObjectParser.TYPE,
141 // PCEPExplicitRouteObjectParser.CLASS);
142 // doReturn(new EROAsNumberSubobjectParser()).when(registry).getSubobjectParser(EROAsNumberSubobjectParser.TYPE);
143 // ObjectHeader h = new ObjectHeader() {
146 // public Class<? extends DataContainer> getImplementedInterface() {
147 // // TODO Auto-generated method stub
152 // public Boolean isProcessingRule() {
157 // public Boolean isIgnore() {
162 // final ExplicitRouteSubobject specObj = (ExplicitRouteSubobject)
163 // registry.getObjectParser(PCEPExplicitRouteObjectParser.TYPE, PCEPExplicitRouteObjectParser.CLASS).parseObject(h,
166 // System.out.println(specObj.toString());
168 // //final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
169 // //assertArrayEquals(bytesFromFile, bytesActual);
173 // public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
174 // final byte[] bytesFromFile =
175 // ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin");
177 // final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject)
178 // PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
180 // assertEquals(8, specObj.getSubobjects().size());
182 // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
183 // assertArrayEquals(bytesFromFile, bytesActual);
187 // public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
188 // final byte[] bytesFromFile =
189 // ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin");
191 // final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject)
192 // PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
194 // assertEquals(6, specObj.getSubobjects().size());
196 // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
197 // assertArrayEquals(bytesFromFile, bytesActual);
202 public void testBandwidthObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
203 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser(this.tlvRegistry);
204 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin");
206 final BandwidthBuilder builder = new BandwidthBuilder();
207 builder.setProcessingRule(true);
208 builder.setIgnore(true);
209 builder.setBandwidth(new Float32(result));
211 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
212 assertArrayEquals(result, parser.serializeObject(builder.build()));
214 result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin");
216 builder.setBandwidth(new Float32(result));
218 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
219 assertArrayEquals(result, parser.serializeObject(builder.build()));
223 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
224 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
225 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
227 final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
228 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin");
230 final EndpointsBuilder builder = new EndpointsBuilder();
231 builder.setProcessingRule(true);
232 builder.setIgnore(false);
233 builder.setAddressFamily(new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
234 Ipv4Util.addressForBytes(destIPBytes)).build());
236 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
237 assertArrayEquals(result, parser.serializeObject(builder.build()));
241 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
242 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
243 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
244 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
245 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
247 final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
248 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin");
250 final EndpointsBuilder builder = new EndpointsBuilder();
251 builder.setProcessingRule(true);
252 builder.setIgnore(false);
253 builder.setAddressFamily(new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
254 Ipv6Util.addressForBytes(destIPBytes)).build());
256 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
257 assertArrayEquals(result, parser.serializeObject(builder.build()));
262 // * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
264 // * Used resources:<br/>
265 // * - PCEPErrorObject1.bin<br/>
266 // * - PCEPErrorObject3.bin<br/>
268 // * @throws PCEPDeserializerException
269 // * @throws IOException
270 // * @throws PCEPDocumentedException
273 // public void testErrorObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
274 // PCEPDocumentedException {
275 // serDeserTest("src/test/resources/PCEPErrorObject1.bin", new PCEPErrorObject(PCEPErrors.NON_OR_INVALID_OPEN_MSG));
276 // serDeserTest("src/test/resources/PCEPErrorObject3.bin", new
277 // PCEPErrorObject(PCEPErrors.CAPABILITY_NOT_SUPPORTED));
281 // * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.<br/>
283 // * Used resources:<br/>
284 // * - PCEPErrorObject2Invalid.bin<br/>
286 // * @throws NoSuchElementException
287 // * @throws IOException
288 // * @throws PCEPDocumentedException
290 // @Test(expected = PCEPDeserializerException.class)
291 // public void testUnknownError() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
292 // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0);
297 public void testLspaObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
298 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry);
299 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin");
301 final LspaBuilder builder = new LspaBuilder();
302 builder.setProcessingRule(true);
303 builder.setIgnore(true);
304 builder.setExcludeAny(new AttributeFilter(0L));
305 builder.setIncludeAny(new AttributeFilter(0L));
306 builder.setIncludeAll(new AttributeFilter(0L));
307 builder.setHoldPriority((short) 0);
308 builder.setSetupPriority((short) 0);
309 builder.setLocalProtectionDesired(false);
311 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
312 assertArrayEquals(result, parser.serializeObject(builder.build()));
314 result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin");
316 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
317 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
318 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
319 builder.setHoldPriority((short) 0xFF);
320 builder.setSetupPriority((short) 0xFF);
321 builder.setLocalProtectionDesired(true);
323 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
324 assertArrayEquals(result, parser.serializeObject(builder.build()));
326 result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin");
328 builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L));
329 builder.setIncludeAny(new AttributeFilter(0x1A025CC7L));
330 builder.setIncludeAll(new AttributeFilter(0x2BB66532L));
331 builder.setHoldPriority((short) 0x02);
332 builder.setSetupPriority((short) 0x03);
333 builder.setLocalProtectionDesired(true);
335 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
336 assertArrayEquals(result, parser.serializeObject(builder.build()));
340 public void testMetricObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
341 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser(this.tlvRegistry);
342 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
344 final MetricBuilder builder = new MetricBuilder();
345 builder.setProcessingRule(true);
346 builder.setIgnore(true);
347 builder.setComputed(false);
348 builder.setBound(false);
349 builder.setMetricType((short) 1);
350 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
352 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
353 assertArrayEquals(result, parser.serializeObject(builder.build()));
355 result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
357 builder.setComputed(true);
358 builder.setBound(false);
359 builder.setMetricType((short) 2);
360 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
362 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
363 assertArrayEquals(result, parser.serializeObject(builder.build()));
367 // public void testNoPathObject() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
368 // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
369 // tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
370 // serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs, false));
371 // serDeserTest("src/test/resources/NoPathObject2WithoutTLV.bin", new PCEPNoPathObject((short) 0x10, false, true));
373 // byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject2WithoutTLV.bin");
374 // PCEPNoPathObject noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
375 // byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
376 // assertArrayEquals(bytesFromFile, bytesActual);
378 // bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject1WithTLV.bin");
379 // noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
380 // bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
381 // assertArrayEquals(bytesFromFile, bytesActual);
386 // * Specific test with/without tlvs (Ser/Deser)<br/>
387 // * Used resources:<br/>
388 // * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin
390 // * @throws PCEPDeserializerException
391 // * @throws IOException
392 // * @throws PCEPDocumentedException
395 // public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
396 // PCEPDocumentedException {
397 // // FINAL LIST<PCEPTLV> TLVS = NEW ARRAYLIST<PCEPTLV>(1);
398 // // TLVS.ADD(NEW OVERLOADEDDURATIONTLV(0XFF0000A2));
399 // // SERDESERTEST("src/test/resources/PCEPNotificationObject1WithTlv.bin", new PCEPNotificationObject((short) 1,
400 // (short) 1, tlvs));
401 // serDeserTest("src/test/resources/PCEPNotificationObject2WithoutTlv.bin", new PCEPNotificationObject((short) 0xFF,
406 // * Standard ser deser test<br/>
407 // * used resources:<br/>
408 // * - PCEPOpenObject1.bin
410 // * @throws PCEPDeserializerException
411 // * @throws IOException
412 // * @throws PCEPDocumentedException
416 // // FIXME: temporary
417 // public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
418 // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
419 // // tlvs.add(new PCEStatefulCapabilityTlv(false, true, true));
420 // // tlvs.add(new LSPStateDBVersionTlv(0x80));
421 // // final byte[] valueBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC,
422 // (byte) 0xDE, (byte) 0xF0 };
423 // // tlvs.add(new NodeIdentifierTlv(valueBytes));
424 // // final PCEPOpenObject specObject = new PCEPOpenObject(30, 120, 1, tlvs);
426 // // serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject);
430 // * Specific test for upper bounds and without tlvs<br/>
431 // * Used resources:<br/>
432 // * - PCEPOpenObject2UpperBoundsNoTlv.bin
434 // * @throws PCEPDeserializerException
435 // * @throws IOException
436 // * @throws PCEPDocumentedException
439 // public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException,
440 // PCEPDocumentedException {
441 // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
442 // // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF,
444 // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF,
449 // * Standard deserialization test<br/>
450 // * Used resources:<br/>
451 // * - PCEPRPObject1.bin
453 // * @throws PCEPDeserializerException
454 // * @throws IOException
455 // * @throws PCEPDocumentedException
458 // public void testRPObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
459 // serDeserTest("src/test/resources/PCEPRPObject1.bin",
460 // new PCEPRequestParameterObject(true, false, true, true, false, false, false, false, (short) 5, 0xdeadbeefL,
463 // // "src/test/resources/PCEPRPObject2.bin",
464 // // new PCEPRequestParameterObject(true, false, false, false, true, false, true, false, true, (short) 5,
465 // 0xdeadbeefL, new ArrayList<PCEPTlv>() {
466 // // private static final long serialVersionUID = 1L;
469 // // this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
471 // // }, false, false));
476 public void testSvecObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
477 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser(this.tlvRegistry);
478 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin");
480 final SvecBuilder builder = new SvecBuilder();
481 builder.setProcessingRule(false);
482 builder.setIgnore(false);
483 builder.setLinkDiverse(false);
484 builder.setNodeDiverse(false);
485 builder.setSrlgDiverse(false);
486 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
488 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
489 assertArrayEquals(result, parser.serializeObject(builder.build()));
491 result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin");
493 builder.setProcessingRule(true);
494 builder.setLinkDiverse(true);
495 builder.setSrlgDiverse(true);
497 final List<RequestId> requestIDs = Lists.newArrayList();
498 requestIDs.add(new RequestId(0xFFFFFFFFL));
499 requestIDs.add(new RequestId(0x00000000L));
500 requestIDs.add(new RequestId(0x01234567L));
501 requestIDs.add(new RequestId(0x89ABCDEFL));
502 requestIDs.add(new RequestId(0xFEDCBA98L));
503 requestIDs.add(new RequestId(0x76543210L));
504 requestIDs.add(new RequestId(0x15825266L));
505 requestIDs.add(new RequestId(0x48120BBEL));
506 requestIDs.add(new RequestId(0x25FB7E52L));
507 requestIDs.add(new RequestId(0xB2F2546BL));
509 builder.setRequestsIds(requestIDs);
511 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
512 assertArrayEquals(result, parser.serializeObject(builder.build()));
516 public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
517 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser(this.tlvRegistry);
518 final byte[] result = new byte[] { 0, 0, 0, (byte) 0x04 };
520 final ClassTypeBuilder builder = new ClassTypeBuilder();
521 builder.setProcessingRule(true);
522 builder.setIgnore(false);
523 builder.setClassType(new ClassType((short) 4));
525 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
526 assertArrayEquals(result, parser.serializeObject(builder.build()));
531 // * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
532 // * Used resources:<br/>
533 // * - PCEPExcludeRouteObject.1.bin<br/>
535 // * @throws IOException
536 // * @throws PCEPDeserializerException
537 // * @throws PCEPDocumentedException
540 // public void testExcludeRouteObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
541 // final List<ExcludeRouteSubobject> xroSubobjects = new ArrayList<ExcludeRouteSubobject>();
542 // xroSubobjects.add(new XROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192,
544 // (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE));
545 // xroSubobjects.add(new XROAsNumberSubobject(new AsNumber(0x1234L), false));
551 public void testSrpObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
552 final PCEPSrpObjectParser parser = new PCEPSrpObjectParser(this.tlvRegistry);
553 final byte[] result = new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte) 0x01 };
555 final SrpBuilder builder = new SrpBuilder();
556 builder.setProcessingRule(false);
557 builder.setIgnore(false);
558 builder.setOperationId(new SrpIdNumber(1L));
560 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
561 assertArrayEquals(result, parser.serializeObject(builder.build()));
565 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
566 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry);
567 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin");
569 final OfBuilder builder = new OfBuilder();
570 builder.setProcessingRule(true);
571 builder.setIgnore(false);
572 builder.setCode(new OfId(4));
574 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
575 assertArrayEquals(result, parser.serializeObject(builder.build()));
579 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
580 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry);
581 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin");
583 final GcBuilder builder = new GcBuilder();
584 builder.setProcessingRule(true);
585 builder.setIgnore(false);
586 builder.setMaxHop((short) 1);
587 builder.setMaxUtilization((short) 0);
588 builder.setMinUtilization((short) 100);
589 builder.setOverBookingFactor((short) 0xFF);
591 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
592 assertArrayEquals(result, parser.serializeObject(builder.build()));
595 // // FIXME: add at least one test with true value
597 // public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException {
598 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, false));
599 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, true));
600 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, false));
601 // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, true));
604 // // private void testOpenObjectWithSpecTlv(final PCEPTlv tlv) throws PCEPDeserializerException,
605 // PCEPDocumentedException {
606 // // final List<PCEPObject> objs = new ArrayList<PCEPObject>();
607 // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
609 // // final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs);
611 // // final byte[] bytes = PCEPObjectFactory.put(objs);
612 // // final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0);
613 // // assertEquals(oo, obj);
617 // public void testErrorsMapping() {
618 // final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance();
620 // for (final PCEPErrors error : PCEPErrors.values()) {
621 // final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error);
622 // assertEquals(error, mapper.getFromErrorIdentifier(errorId));
627 // public void testOFCodesMapping() {
628 // final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance();
630 // for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) {
631 // final int ofCodeId = mapper.getFromOFCodesEnum(ofCode);
632 // assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId));
636 // @SuppressWarnings("unchecked")
637 // private static <T extends PCEPObject> void serDeserTestWithoutBin(final T object) throws
638 // PCEPDeserializerException,
639 // PCEPDocumentedException {
640 // final byte[] serBytes = PCEPObjectFactory.put(Arrays.asList((PCEPObject) object));
641 // final T deserObj = (T) PCEPObjectFactory.parseObjects(serBytes).get(0);
643 // assertEquals(object, deserObj);
647 // public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException {
648 // final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
649 // eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192,
650 // (byte) 168, 1, 8 }), 16), false));
651 // eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(new byte[] { (byte) 192,
653 // (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1 }), 64), false));
655 // serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false));
659 // public void testSRRObject() throws PCEPDocumentedException, PCEPDeserializerException {
660 // final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>();
661 // rroSubobjects.add(new RROIPAddressSubobject<IPv4Prefix>(new IPv4Prefix(this.ipv4addr, 16), true, false));
662 // rroSubobjects.add(new RROIPAddressSubobject<IPv6Prefix>(new IPv6Prefix(this.ipv6addr, 64), false, true));
664 // serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
668 // public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException {
669 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(2, this.ipv4addr, Arrays.asList(this.ipv4addr,
671 // this.ipv4addr), true, false));
672 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(1, this.ipv4addr, Arrays.asList(this.ipv4addr),
674 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(2, this.ipv6addr, Arrays.asList(this.ipv6addr,
676 // this.ipv6addr), true, false));
677 // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(1, this.ipv6addr, Arrays.asList(this.ipv6addr),
682 // public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException {
683 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr,
684 // this.ipv4addr, this.ipv4addr), true, false));
685 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr), true,
687 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr,
688 // this.ipv6addr, this.ipv6addr), true, false));
689 // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr), true,