BUG-50: added more object tests.
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPObjectParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import java.io.IOException;
14 import java.util.List;
15
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;
56
57 import com.google.common.collect.Lists;
58 import com.google.common.primitives.UnsignedBytes;
59
60 public class PCEPObjectParserTest {
61
62         private TlvHandlerRegistry tlvRegistry;
63
64         @Before
65         public void setUp() throws Exception {
66                 this.tlvRegistry = PCEPExtensionProviderContextImpl.create().getTlvHandlerRegistry();
67         }
68
69         // @Test
70         // @Ignore
71         // // FIXME: temporary
72         // public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
73         // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
74         // }
75         //
76         // @Test
77         // public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
78         //
79         // final PCEPObject obj =
80         // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get(
81         // 0);
82         //
83         // // assertTrue(obj instanceof UnknownObject);
84         // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
85         // }
86         //
87         // // @Test
88         // // public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
89         // // final PCEPObject obj =
90         // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0);
91         // //
92         // // assertTrue(obj instanceof UnknownObject);
93         // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
94         // // }
95         // //
96
97         @Test
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");
101
102                 final CCloseBuilder builder = new CCloseBuilder();
103                 builder.setProcessingRule(false);
104                 builder.setIgnore(false);
105                 builder.setReason((short) 5);
106
107                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
108                 assertArrayEquals(result, parser.serializeObject(builder.build()));
109         }
110
111         @Test
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");
115
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 }));
121
122                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
123                 assertArrayEquals(result, parser.serializeObject(builder.build()));
124         }
125
126         //
127         // @Test
128         // public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
129         // serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false,
130         // true, false, null));
131         // }
132         //
133         // @Test
134         // public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
135         // final byte[] bytesFromFile =
136         // ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
137         //
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() {
144         //
145         // @Override
146         // public Class<? extends DataContainer> getImplementedInterface() {
147         // // TODO Auto-generated method stub
148         // return null;
149         // }
150         //
151         // @Override
152         // public Boolean isProcessingRule() {
153         // return false;
154         // }
155         //
156         // @Override
157         // public Boolean isIgnore() {
158         // return false;
159         // }
160         // };
161         //
162         // final ExplicitRouteSubobject specObj = (ExplicitRouteSubobject)
163         // registry.getObjectParser(PCEPExplicitRouteObjectParser.TYPE, PCEPExplicitRouteObjectParser.CLASS).parseObject(h,
164         // bytesFromFile);
165         //
166         // System.out.println(specObj.toString());
167         //
168         // //final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
169         // //assertArrayEquals(bytesFromFile, bytesActual);
170         // }
171         //
172         // @Test
173         // public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
174         // final byte[] bytesFromFile =
175         // ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin");
176         //
177         // final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject)
178         // PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
179         //
180         // assertEquals(8, specObj.getSubobjects().size());
181         //
182         // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
183         // assertArrayEquals(bytesFromFile, bytesActual);
184         // }
185         //
186         // @Test
187         // public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
188         // final byte[] bytesFromFile =
189         // ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin");
190         //
191         // final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject)
192         // PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
193         //
194         // assertEquals(6, specObj.getSubobjects().size());
195         //
196         // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
197         // assertArrayEquals(bytesFromFile, bytesActual);
198         // }
199         //
200
201         @Test
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");
205
206                 final BandwidthBuilder builder = new BandwidthBuilder();
207                 builder.setProcessingRule(true);
208                 builder.setIgnore(true);
209                 builder.setBandwidth(new Float32(result));
210
211                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
212                 assertArrayEquals(result, parser.serializeObject(builder.build()));
213
214                 result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin");
215
216                 builder.setBandwidth(new Float32(result));
217
218                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
219                 assertArrayEquals(result, parser.serializeObject(builder.build()));
220         }
221
222         @Test
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 };
226
227                 final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
228                 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin");
229
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());
235
236                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
237                 assertArrayEquals(result, parser.serializeObject(builder.build()));
238         }
239
240         @Test
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 };
246
247                 final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
248                 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin");
249
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());
255
256                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
257                 assertArrayEquals(result, parser.serializeObject(builder.build()));
258         }
259
260         //
261         // /**
262         // * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
263         // * <br/>
264         // * Used resources:<br/>
265         // * - PCEPErrorObject1.bin<br/>
266         // * - PCEPErrorObject3.bin<br/>
267         // *
268         // * @throws PCEPDeserializerException
269         // * @throws IOException
270         // * @throws PCEPDocumentedException
271         // */
272         // @Test
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));
278         // }
279         //
280         // /**
281         // * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.<br/>
282         // * <br/>
283         // * Used resources:<br/>
284         // * - PCEPErrorObject2Invalid.bin<br/>
285         // *
286         // * @throws NoSuchElementException
287         // * @throws IOException
288         // * @throws PCEPDocumentedException
289         // */
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);
293         // }
294         //
295
296         @Test
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");
300
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);
310
311                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
312                 assertArrayEquals(result, parser.serializeObject(builder.build()));
313
314                 result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin");
315
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);
322
323                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
324                 assertArrayEquals(result, parser.serializeObject(builder.build()));
325
326                 result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin");
327
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);
334
335                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
336                 assertArrayEquals(result, parser.serializeObject(builder.build()));
337         }
338
339         @Test
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");
343
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 }));
351
352                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
353                 assertArrayEquals(result, parser.serializeObject(builder.build()));
354
355                 result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
356
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 }));
361
362                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
363                 assertArrayEquals(result, parser.serializeObject(builder.build()));
364         }
365
366         // @Test
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));
372         //
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);
377         //
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);
382         // }
383
384         //
385         // /**
386         // * Specific test with/without tlvs (Ser/Deser)<br/>
387         // * Used resources:<br/>
388         // * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin
389         // *
390         // * @throws PCEPDeserializerException
391         // * @throws IOException
392         // * @throws PCEPDocumentedException
393         // */
394         // @Test
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,
402         // (short) 0xFF));
403         // }
404         //
405         // /**
406         // * Standard ser deser test<br/>
407         // * used resources:<br/>
408         // * - PCEPOpenObject1.bin
409         // *
410         // * @throws PCEPDeserializerException
411         // * @throws IOException
412         // * @throws PCEPDocumentedException
413         // */
414         // @Test
415         // @Ignore
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);
425         // //
426         // // serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject);
427         // }
428         //
429         // /**
430         // * Specific test for upper bounds and without tlvs<br/>
431         // * Used resources:<br/>
432         // * - PCEPOpenObject2UpperBoundsNoTlv.bin
433         // *
434         // * @throws PCEPDeserializerException
435         // * @throws IOException
436         // * @throws PCEPDocumentedException
437         // */
438         // @Test
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,
443         // tlvs));
444         // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF,
445         // null));
446         // }
447         //
448         // /**
449         // * Standard deserialization test<br/>
450         // * Used resources:<br/>
451         // * - PCEPRPObject1.bin
452         // *
453         // * @throws PCEPDeserializerException
454         // * @throws IOException
455         // * @throws PCEPDocumentedException
456         // */
457         // @Test
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,
461         // false, false));
462         // // serDeserTest(
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;
467         // //
468         // // {
469         // // this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
470         // // }
471         // // }, false, false));
472         // }
473         //
474
475         @Test
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");
479
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)));
487
488                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
489                 assertArrayEquals(result, parser.serializeObject(builder.build()));
490
491                 result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin");
492
493                 builder.setProcessingRule(true);
494                 builder.setLinkDiverse(true);
495                 builder.setSrlgDiverse(true);
496
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));
508
509                 builder.setRequestsIds(requestIDs);
510
511                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
512                 assertArrayEquals(result, parser.serializeObject(builder.build()));
513         }
514
515         @Test
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 };
519
520                 final ClassTypeBuilder builder = new ClassTypeBuilder();
521                 builder.setProcessingRule(true);
522                 builder.setIgnore(false);
523                 builder.setClassType(new ClassType((short) 4));
524
525                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
526                 assertArrayEquals(result, parser.serializeObject(builder.build()));
527         }
528
529         //
530         // /**
531         // * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
532         // * Used resources:<br/>
533         // * - PCEPExcludeRouteObject.1.bin<br/>
534         // *
535         // * @throws IOException
536         // * @throws PCEPDeserializerException
537         // * @throws PCEPDocumentedException
538         // */
539         // @Test
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,
543         // (byte) 168,
544         // (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE));
545         // xroSubobjects.add(new XROAsNumberSubobject(new AsNumber(0x1234L), false));
546         //
547         // }
548         //
549
550         @Test
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 };
554
555                 final SrpBuilder builder = new SrpBuilder();
556                 builder.setProcessingRule(false);
557                 builder.setIgnore(false);
558                 builder.setOperationId(new SrpIdNumber(1L));
559
560                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
561                 assertArrayEquals(result, parser.serializeObject(builder.build()));
562         }
563
564         @Test
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");
568
569                 final OfBuilder builder = new OfBuilder();
570                 builder.setProcessingRule(true);
571                 builder.setIgnore(false);
572                 builder.setCode(new OfId(4));
573
574                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
575                 assertArrayEquals(result, parser.serializeObject(builder.build()));
576         }
577
578         @Test
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");
582
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);
590
591                 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
592                 assertArrayEquals(result, parser.serializeObject(builder.build()));
593         }
594
595         // // FIXME: add at least one test with true value
596         // @Test
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));
602         // }
603         //
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>();
608         // // tlvs.add(tlv);
609         // // final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs);
610         // // objs.add(oo);
611         // // final byte[] bytes = PCEPObjectFactory.put(objs);
612         // // final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0);
613         // // assertEquals(oo, obj);
614         // // }
615         //
616         // @Test
617         // public void testErrorsMapping() {
618         // final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance();
619         //
620         // for (final PCEPErrors error : PCEPErrors.values()) {
621         // final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error);
622         // assertEquals(error, mapper.getFromErrorIdentifier(errorId));
623         // }
624         // }
625         //
626         // @Test
627         // public void testOFCodesMapping() {
628         // final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance();
629         //
630         // for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) {
631         // final int ofCodeId = mapper.getFromOFCodesEnum(ofCode);
632         // assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId));
633         // }
634         // }
635         //
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);
642         //
643         // assertEquals(object, deserObj);
644         // }
645         //
646         // @Test
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,
652         // (byte) 168, 2, 1,
653         // (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1 }), 64), false));
654         //
655         // serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false));
656         // }
657         //
658         // @Test
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));
663         //
664         // serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
665         // }
666         //
667         // @Test
668         // public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException {
669         // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(2, this.ipv4addr, Arrays.asList(this.ipv4addr,
670         // this.ipv4addr,
671         // this.ipv4addr), true, false));
672         // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(1, this.ipv4addr, Arrays.asList(this.ipv4addr),
673         // true, false));
674         // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(2, this.ipv6addr, Arrays.asList(this.ipv6addr,
675         // this.ipv6addr,
676         // this.ipv6addr), true, false));
677         // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(1, this.ipv6addr, Arrays.asList(this.ipv6addr),
678         // true, false));
679         // }
680         //
681         // @Test
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,
686         // false));
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,
690         // false));
691         // }
692 }