fca250b95f9572d7ecb7483e5b7e4e968f9b9d90
[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 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
16
17 import com.google.common.collect.Lists;
18 import com.google.common.primitives.UnsignedBytes;
19 import io.netty.buffer.ByteBuf;
20 import io.netty.buffer.Unpooled;
21 import java.io.IOException;
22 import java.util.List;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
26 import org.opendaylight.protocol.pcep.parser.BaseParserExtensionActivator;
27 import org.opendaylight.protocol.pcep.parser.object.PCEPBandwidthObjectParser;
28 import org.opendaylight.protocol.pcep.parser.object.PCEPClassTypeObjectParser;
29 import org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser;
30 import org.opendaylight.protocol.pcep.parser.object.PCEPEndPointsIpv4ObjectParser;
31 import org.opendaylight.protocol.pcep.parser.object.PCEPEndPointsIpv6ObjectParser;
32 import org.opendaylight.protocol.pcep.parser.object.PCEPErrorObjectParser;
33 import org.opendaylight.protocol.pcep.parser.object.PCEPExcludeRouteObjectParser;
34 import org.opendaylight.protocol.pcep.parser.object.PCEPExistingBandwidthObjectParser;
35 import org.opendaylight.protocol.pcep.parser.object.PCEPExplicitRouteObjectParser;
36 import org.opendaylight.protocol.pcep.parser.object.PCEPGlobalConstraintsObjectParser;
37 import org.opendaylight.protocol.pcep.parser.object.PCEPIncludeRouteObjectParser;
38 import org.opendaylight.protocol.pcep.parser.object.PCEPLoadBalancingObjectParser;
39 import org.opendaylight.protocol.pcep.parser.object.PCEPLspaObjectParser;
40 import org.opendaylight.protocol.pcep.parser.object.PCEPMetricObjectParser;
41 import org.opendaylight.protocol.pcep.parser.object.PCEPMonitoringObjectParser;
42 import org.opendaylight.protocol.pcep.parser.object.PCEPNoPathObjectParser;
43 import org.opendaylight.protocol.pcep.parser.object.PCEPNotificationObjectParser;
44 import org.opendaylight.protocol.pcep.parser.object.PCEPObjectiveFunctionObjectParser;
45 import org.opendaylight.protocol.pcep.parser.object.PCEPOpenObjectParser;
46 import org.opendaylight.protocol.pcep.parser.object.PCEPOverloadObjectParser;
47 import org.opendaylight.protocol.pcep.parser.object.PCEPPathKeyObjectParser;
48 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv4ObjectParser;
49 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv6ObjectParser;
50 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv4ObjectParser;
51 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv6ObjectParser;
52 import org.opendaylight.protocol.pcep.parser.object.PCEPProcTimeObjectParser;
53 import org.opendaylight.protocol.pcep.parser.object.PCEPReportedRouteObjectParser;
54 import org.opendaylight.protocol.pcep.parser.object.PCEPRequestParameterObjectParser;
55 import org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser;
56 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
57 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
58 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
59 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
60 import org.opendaylight.protocol.pcep.spi.UnknownObject;
61 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
62 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
63 import org.opendaylight.protocol.util.ByteArray;
64 import org.opendaylight.protocol.util.Ipv4Util;
65 import org.opendaylight.protocol.util.Ipv6Util;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
68 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
69 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
71 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
138
139 public class PCEPObjectParserTest {
140
141     private TlvRegistry tlvRegistry;
142
143     private VendorInformationTlvRegistry viTlvRegistry;
144
145     private SimplePCEPExtensionProviderContext ctx;
146     private BaseParserExtensionActivator act;
147     private TestVendorInformationActivator viAct;
148
149     @Before
150     public void setUp() {
151         this.ctx = new SimplePCEPExtensionProviderContext();
152         this.act = new BaseParserExtensionActivator();
153         this.viAct = new TestVendorInformationActivator();
154         this.act.start(this.ctx);
155         this.viAct.start(this.ctx);
156         this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
157         this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
158     }
159
160     @Test
161     public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
162         final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
163         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
164
165         final OpenBuilder builder = new OpenBuilder();
166         builder.setProcessingRule(false);
167         builder.setIgnore(false);
168         builder.setVersion(new ProtocolVersion((short) 1));
169         builder.setKeepalive((short) 30);
170         builder.setDeadTimer((short) 120);
171         builder.setSessionId((short) 1);
172
173         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
174
175         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
176         final ByteBuf buf = Unpooled.buffer();
177         parser.serializeObject(builder.build(), buf);
178         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
179
180         try {
181             parser.parseObject(new ObjectHeaderImpl(true, true), null);
182             fail();
183         } catch (final IllegalArgumentException e) {
184             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
185         }
186         try {
187             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
188             fail();
189         } catch (final IllegalArgumentException e) {
190             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
191         }
192     }
193
194     @Test
195     public void testCloseObject() throws IOException, PCEPDeserializerException {
196         final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
197         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
198
199         final CCloseBuilder builder = new CCloseBuilder();
200         builder.setProcessingRule(false);
201         builder.setIgnore(false);
202         builder.setReason((short) 5);
203         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
204
205         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
206         final ByteBuf buf = Unpooled.buffer();
207         parser.serializeObject(builder.build(), buf);
208         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
209
210         try {
211             parser.parseObject(new ObjectHeaderImpl(true, true), null);
212             fail();
213         } catch (final IllegalArgumentException e) {
214             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
215         }
216         try {
217             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
218             fail();
219         } catch (final IllegalArgumentException e) {
220             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
221         }
222     }
223
224     @Test
225     public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
226         final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
227         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
228
229         final LoadBalancingBuilder builder = new LoadBalancingBuilder();
230         builder.setProcessingRule(true);
231         builder.setIgnore(false);
232         builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
233         builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
234
235         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
236         final ByteBuf buf = Unpooled.buffer();
237         parser.serializeObject(builder.build(), buf);
238         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
239
240         try {
241             parser.parseObject(new ObjectHeaderImpl(true, true), null);
242             fail();
243         } catch (final IllegalArgumentException e) {
244             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
245         }
246         try {
247             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
248             fail();
249         } catch (final IllegalArgumentException e) {
250             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
251         }
252     }
253
254     @Test
255     public void testERObject() throws Exception {
256         final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
257         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
258
259         final EroBuilder builder = new EroBuilder();
260         builder.setProcessingRule(false);
261         builder.setIgnore(false);
262         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
263         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
264                 true).setSubobjectType(
265                         new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
266         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
267                 true).setSubobjectType(
268                         new IpPrefixCaseBuilder().setIpPrefix(
269                                 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
270         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
271                 true).setSubobjectType(
272                         new UnnumberedCaseBuilder().setUnnumbered(
273                                 new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
274         builder.setSubobject(subs);
275
276         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
277         final ByteBuf buf = Unpooled.buffer();
278         parser.serializeObject(builder.build(), buf);
279         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
280
281         try {
282             parser.parseObject(new ObjectHeaderImpl(true, true), null);
283             fail();
284         } catch (final IllegalArgumentException e) {
285             assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
286         }
287     }
288
289     @Test
290     public void testIRObject() throws Exception {
291         final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
292         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
293         final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
294             (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
295
296         final IroBuilder builder = new IroBuilder();
297         builder.setProcessingRule(false);
298         builder.setIgnore(false);
299         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists.newArrayList();
300         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
301                 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).setLoose(true).build());
302         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
303                 new IpPrefixCaseBuilder().setIpPrefix(
304                         new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).setLoose(true).build());
305         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
306                 new IpPrefixCaseBuilder().setIpPrefix(
307                         new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setLoose(true).build());
308         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
309                 new UnnumberedCaseBuilder().setUnnumbered(
310                         new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setLoose(true).build());
311         builder.setSubobject(subs);
312
313         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
314         final ByteBuf buf = Unpooled.buffer();
315         parser.serializeObject(builder.build(), buf);
316         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
317
318         try {
319             parser.parseObject(new ObjectHeaderImpl(true, true), null);
320             fail();
321         } catch (final IllegalArgumentException e) {
322             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
323         }
324         try {
325             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
326             fail();
327         } catch (final IllegalArgumentException e) {
328             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
329         }
330     }
331
332     @Test
333     public void testRRObject() throws Exception {
334         final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
335         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
336         final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
337             (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
338
339         final RroBuilder builder = new RroBuilder();
340         builder.setProcessingRule(false);
341         builder.setIgnore(false);
342         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
343         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
344                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
345                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
346                                 new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
347                                         false).build());
348         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
349                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
350                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
351                                 new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
352                                         false).build());
353         subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
354                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
355                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
356                                 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
357                                         false).build());
358         builder.setSubobject(subs);
359
360         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
361         final ByteBuf buf = Unpooled.buffer();
362         parser.serializeObject(builder.build(), buf);
363         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
364
365         try {
366             parser.parseObject(new ObjectHeaderImpl(true, true), null);
367             fail();
368         } catch (final IllegalArgumentException e) {
369             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
370         }
371         try {
372             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
373             fail();
374         } catch (final IllegalArgumentException e) {
375             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
376         }
377     }
378
379     @Test
380     public void testBandwidthObject() throws IOException, PCEPDeserializerException {
381         final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
382         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
383
384         final BandwidthBuilder builder = new BandwidthBuilder();
385         builder.setProcessingRule(true);
386         builder.setIgnore(true);
387         builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
388
389         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
390         final ByteBuf buf = Unpooled.buffer();
391         parser.serializeObject(builder.build(), buf);
392         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
393
394         try {
395             parser.parseObject(new ObjectHeaderImpl(true, true), null);
396             fail();
397         } catch (final IllegalArgumentException e) {
398             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
399         }
400         try {
401             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
402             fail();
403         } catch (final IllegalArgumentException e) {
404             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
405         }
406     }
407
408     @Test
409     public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
410         final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
411         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
412
413         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization
414             .bandwidth.object.ReoptimizationBandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
415             .ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
416         builder.setProcessingRule(true);
417         builder.setIgnore(true);
418         builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
419
420         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
421         final ByteBuf buf = Unpooled.buffer();
422         parser.serializeObject(builder.build(), buf);
423         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
424
425         try {
426             parser.parseObject(new ObjectHeaderImpl(true, true), null);
427             fail();
428         } catch (final IllegalArgumentException e) {
429             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
430         }
431         try {
432             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
433             fail();
434         } catch (final IllegalArgumentException e) {
435             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
436         }
437     }
438
439     @Test
440     public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
441         final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
442         final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
443
444         final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
445         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
446
447         final EndpointsObjBuilder builder = new EndpointsObjBuilder();
448         builder.setProcessingRule(true);
449         builder.setIgnore(false);
450         builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
451                 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
452                         Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
453
454         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
455         final ByteBuf buf = Unpooled.buffer();
456         parser.serializeObject(builder.build(), buf);
457         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
458
459         try {
460             parser.parseObject(new ObjectHeaderImpl(true, true), null);
461             fail();
462         } catch (final IllegalArgumentException e) {
463             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
464         }
465         try {
466             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
467             fail();
468         } catch (final IllegalArgumentException e) {
469             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
470         }
471     }
472
473     @Test
474     public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
475         final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
476             (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
477         final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
478             (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
479
480         final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
481         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
482
483         final EndpointsObjBuilder builder = new EndpointsObjBuilder();
484         builder.setProcessingRule(true);
485         builder.setIgnore(false);
486         builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
487                 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
488                         Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
489
490         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
491         final ByteBuf buf = Unpooled.buffer();
492         PCEPEndPointsIpv6ObjectParser.serializeObject(builder.build(), buf);
493         assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
494
495         try {
496             parser.parseObject(new ObjectHeaderImpl(true, true), null);
497             fail();
498         } catch (final IllegalArgumentException e) {
499             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
500         }
501         try {
502             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
503             fail();
504         } catch (final IllegalArgumentException e) {
505             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
506         }
507     }
508
509     @Test
510     public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
511         final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
512         ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
513
514         final ErrorObjectBuilder builder = new ErrorObjectBuilder();
515         builder.setProcessingRule(true);
516         builder.setIgnore(true);
517         builder.setType((short) 1);
518         builder.setValue((short) 1);
519
520         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
521         ByteBuf buf = Unpooled.buffer();
522         parser.serializeObject(builder.build(), buf);
523         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
524
525         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
526
527         builder.setType((short) 7);
528         builder.setValue((short) 0);
529         builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
530
531         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
532         buf = Unpooled.buffer();
533         parser.serializeObject(builder.build(), buf);
534         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
535
536         try {
537             parser.parseObject(new ObjectHeaderImpl(true, true), null);
538             fail();
539         } catch (final IllegalArgumentException e) {
540             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
541         }
542         try {
543             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
544             fail();
545         } catch (final IllegalArgumentException e) {
546             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
547         }
548     }
549
550     @Test
551     public void testLspaObject() throws IOException, PCEPDeserializerException {
552         final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
553         ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
554
555         final LspaBuilder builder = new LspaBuilder();
556         builder.setProcessingRule(true);
557         builder.setIgnore(true);
558         builder.setExcludeAny(new AttributeFilter(0L));
559         builder.setIncludeAny(new AttributeFilter(0L));
560         builder.setIncludeAll(new AttributeFilter(0L));
561         builder.setHoldPriority((short) 0);
562         builder.setSetupPriority((short) 0);
563         builder.setLocalProtectionDesired(false);
564         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
565
566         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
567         ByteBuf buf = Unpooled.buffer();
568         parser.serializeObject(builder.build(), buf);
569         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
570
571         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
572
573         builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
574         builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
575         builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
576         builder.setHoldPriority((short) 0xFF);
577         builder.setSetupPriority((short) 0xFF);
578         builder.setLocalProtectionDesired(true);
579
580         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
581         buf = Unpooled.buffer();
582         parser.serializeObject(builder.build(), buf);
583         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
584
585         try {
586             parser.parseObject(new ObjectHeaderImpl(true, true), null);
587             fail();
588         } catch (final IllegalArgumentException e) {
589             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
590         }
591         try {
592             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
593             fail();
594         } catch (final IllegalArgumentException e) {
595             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
596         }
597     }
598
599     @Test
600     public void testMetricObject() throws IOException, PCEPDeserializerException {
601         final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
602         ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
603
604         final MetricBuilder builder = new MetricBuilder();
605         builder.setProcessingRule(true);
606         builder.setIgnore(true);
607         builder.setComputed(false);
608         builder.setBound(false);
609         builder.setMetricType((short) 1);
610         builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
611
612         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
613         ByteBuf buf = Unpooled.buffer();
614         parser.serializeObject(builder.build(), buf);
615         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
616
617         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
618
619         builder.setComputed(true);
620         builder.setBound(false);
621         builder.setMetricType((short) 2);
622         builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
623
624         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
625         buf = Unpooled.buffer();
626         parser.serializeObject(builder.build(), buf);
627         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
628
629         try {
630             parser.parseObject(new ObjectHeaderImpl(true, true), null);
631             fail();
632         } catch (final IllegalArgumentException e) {
633             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
634         }
635         try {
636             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
637             fail();
638         } catch (final IllegalArgumentException e) {
639             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
640         }
641     }
642
643     @Test
644     public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
645         final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
646         ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
647
648         final NoPathBuilder builder = new NoPathBuilder();
649         builder.setProcessingRule(true);
650         builder.setIgnore(true);
651         builder.setNatureOfIssue((short) 1);
652         builder.setUnsatisfiedConstraints(true);
653         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().build());
654
655         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
656         ByteBuf buf = Unpooled.buffer();
657         parser.serializeObject(builder.build(), buf);
658         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
659
660         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
661
662         builder.setNatureOfIssue((short) 0);
663         builder.setUnsatisfiedConstraints(false);
664
665         final NoPathVectorBuilder b = new NoPathVectorBuilder();
666         b.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true));
667         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().setNoPathVector(
668                 b.build()).build());
669
670         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
671         buf = Unpooled.buffer();
672         parser.serializeObject(builder.build(), buf);
673         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
674
675         try {
676             parser.parseObject(new ObjectHeaderImpl(true, true), null);
677             fail();
678         } catch (final IllegalArgumentException e) {
679             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
680         }
681         try {
682             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
683             fail();
684         } catch (final IllegalArgumentException e) {
685             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
686         }
687     }
688
689     @Test
690     public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
691         final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
692         ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
693
694         final CNotificationBuilder builder = new CNotificationBuilder();
695         builder.setProcessingRule(true);
696         builder.setIgnore(true);
697         builder.setType((short) 0xff);
698         builder.setValue((short) 0xff);
699
700         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
701         ByteBuf buf = Unpooled.buffer();
702         parser.serializeObject(builder.build(), buf);
703         assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
704
705         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
706
707         builder.setType((short) 2);
708         builder.setValue((short) 1);
709         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
710                 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
711
712         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
713         buf = Unpooled.buffer();
714         parser.serializeObject(builder.build(), buf);
715         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
716
717         try {
718             parser.parseObject(new ObjectHeaderImpl(true, true), null);
719             fail();
720         } catch (final IllegalArgumentException e) {
721             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
722         }
723         try {
724             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
725             fail();
726         } catch (final IllegalArgumentException e) {
727             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
728         }
729     }
730
731     @Test
732     public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
733         final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
734         ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
735
736         final RpBuilder builder = new RpBuilder();
737         builder.setProcessingRule(true);
738         builder.setIgnore(true);
739         builder.setReoptimization(true);
740         builder.setBiDirectional(false);
741         builder.setLoose(true);
742         builder.setMakeBeforeBreak(true);
743         builder.setOrder(false);
744         builder.setPathKey(false);
745         builder.setSupplyOf(false);
746         builder.setFragmentation(false);
747         builder.setP2mp(false);
748         builder.setEroCompression(false);
749         builder.setPriority((short) 5);
750         builder.setRequestId(new RequestId(0xdeadbeefL));
751         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
752
753         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
754         ByteBuf buf = Unpooled.buffer();
755         parser.serializeObject(builder.build(), buf);
756         assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
757
758         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
759
760         builder.setReoptimization(false);
761         builder.setFragmentation(true);
762         builder.setEroCompression(true);
763
764         final OrderBuilder b = new OrderBuilder();
765         b.setDelete(0xffffffffL);
766         b.setSetup(1L);
767
768         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
769                 b.build()).build());
770
771         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
772         buf = Unpooled.buffer();
773         parser.serializeObject(builder.build(), buf);
774         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
775
776         try {
777             parser.parseObject(new ObjectHeaderImpl(true, true), null);
778             fail();
779         } catch (final IllegalArgumentException e) {
780             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
781         }
782         try {
783             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
784             fail();
785         } catch (final IllegalArgumentException e) {
786             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
787         }
788     }
789
790     @Test
791     public void testSvecObject() throws IOException, PCEPDeserializerException {
792         final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
793         ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
794
795         final SvecBuilder builder = new SvecBuilder();
796         builder.setProcessingRule(false);
797         builder.setIgnore(false);
798         builder.setLinkDiverse(false);
799         builder.setNodeDiverse(false);
800         builder.setSrlgDiverse(false);
801         builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
802
803         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
804         ByteBuf buf = Unpooled.buffer();
805         parser.serializeObject(builder.build(), buf);
806         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
807
808         result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
809
810         builder.setProcessingRule(true);
811         builder.setLinkDiverse(true);
812         builder.setSrlgDiverse(true);
813
814         final List<RequestId> requestIDs = Lists.newArrayList();
815         requestIDs.add(new RequestId(0xFFFFFFFFL));
816         requestIDs.add(new RequestId(0x00000001L));
817         requestIDs.add(new RequestId(0x01234567L));
818         requestIDs.add(new RequestId(0x89ABCDEFL));
819         requestIDs.add(new RequestId(0xFEDCBA98L));
820         requestIDs.add(new RequestId(0x76543210L));
821         requestIDs.add(new RequestId(0x15825266L));
822         requestIDs.add(new RequestId(0x48120BBEL));
823         requestIDs.add(new RequestId(0x25FB7E52L));
824         requestIDs.add(new RequestId(0xB2F2546BL));
825
826         builder.setRequestsIds(requestIDs);
827
828         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
829         buf = Unpooled.buffer();
830         parser.serializeObject(builder.build(), buf);
831         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
832
833         try {
834             parser.parseObject(new ObjectHeaderImpl(true, true), null);
835             fail();
836         } catch (final IllegalArgumentException e) {
837             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
838         }
839         try {
840             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
841             fail();
842         } catch (final IllegalArgumentException e) {
843             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
844         }
845     }
846
847     @Test
848     public void testClassTypeObject() throws PCEPDeserializerException {
849         final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
850         final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
851
852         final ClassTypeBuilder builder = new ClassTypeBuilder();
853         builder.setProcessingRule(true);
854         builder.setIgnore(false);
855         builder.setClassType(new ClassType((short) 4));
856
857         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
858         final ByteBuf buf = Unpooled.buffer();
859         parser.serializeObject(builder.build(), buf);
860         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
861
862         try {
863             parser.parseObject(new ObjectHeaderImpl(true, true), null);
864             fail();
865         } catch (final IllegalArgumentException e) {
866             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
867         }
868         try {
869             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
870             fail();
871         } catch (final IllegalArgumentException e) {
872             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
873         }
874     }
875
876     @Test
877     public void testExcludeRouteObject() throws Exception {
878         final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
879         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
880
881         final XroBuilder builder = new XroBuilder();
882         builder.setProcessingRule(false);
883         builder.setIgnore(false);
884         builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
885         final List<Subobject> subs = Lists.newArrayList();
886         subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
887                 new IpPrefixCaseBuilder().setIpPrefix(
888                         new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
889                                 Attribute.Node).build());
890         subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
891                 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
892         builder.setSubobject(subs);
893
894         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
895         final ByteBuf buf = Unpooled.buffer();
896         parser.serializeObject(builder.build(), buf);
897         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
898
899         try {
900             parser.parseObject(new ObjectHeaderImpl(true, true), null);
901             fail();
902         } catch (final IllegalArgumentException e) {
903             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
904         }
905         try {
906             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
907             fail();
908         } catch (final IllegalArgumentException e) {
909             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
910         }
911     }
912
913     @Test
914     public void testPathKeyObject() throws Exception {
915         final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
916         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
917
918         final PathKeyBuilder builder = new PathKeyBuilder();
919         builder.setProcessingRule(true);
920         builder.setIgnore(false);
921         final List<PathKeys> list = Lists.newArrayList();
922         list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
923                 new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
924         builder.setPathKeys(list);
925
926         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
927         final ByteBuf buf = Unpooled.buffer();
928         parser.serializeObject(builder.build(), buf);
929         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
930
931         try {
932             parser.parseObject(new ObjectHeaderImpl(true, true), null);
933             fail();
934         } catch (final IllegalArgumentException e) {
935             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
936         }
937         try {
938             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
939             fail();
940         } catch (final IllegalArgumentException e) {
941             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
942         }
943     }
944
945     @Test
946     public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
947         final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
948         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
949
950         final OfBuilder builder = new OfBuilder();
951         builder.setProcessingRule(true);
952         builder.setIgnore(false);
953         builder.setCode(new OfId(4));
954         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
955
956         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
957         final ByteBuf buf = Unpooled.buffer();
958         parser.serializeObject(builder.build(), buf);
959         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
960
961         try {
962             parser.parseObject(new ObjectHeaderImpl(true, true), null);
963             fail();
964         } catch (final IllegalArgumentException e) {
965             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
966         }
967         try {
968             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
969             fail();
970         } catch (final IllegalArgumentException e) {
971             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
972         }
973     }
974
975     @Test
976     public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
977         final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
978         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
979
980         final GcBuilder builder = new GcBuilder();
981         builder.setProcessingRule(true);
982         builder.setIgnore(false);
983         builder.setMaxHop((short) 1);
984         builder.setMaxUtilization((short) 0);
985         builder.setMinUtilization((short) 100);
986         builder.setOverBookingFactor((short) 99);
987         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
988
989         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
990         final ByteBuf buf = Unpooled.buffer();
991         parser.serializeObject(builder.build(), buf);
992         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
993
994         try {
995             parser.parseObject(new ObjectHeaderImpl(true, true), null);
996             fail();
997         } catch (final IllegalArgumentException e) {
998             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
999         }
1000         try {
1001             parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1002             fail();
1003         } catch (final IllegalArgumentException e) {
1004             assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1005         }
1006     }
1007
1008     @Test
1009     public void testIgnoreUknownObject() throws PCEPDeserializerException {
1010         final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
1011         assertNull(object);
1012     }
1013
1014     @Test
1015     public void testUnrecognizedObjectType() throws PCEPDeserializerException {
1016         final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
1017         assertNotNull(object);
1018         assertTrue(object instanceof UnknownObject);
1019         assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
1020     }
1021
1022     @Test
1023     public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1024         final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1025         assertNotNull(object);
1026         assertTrue(object instanceof UnknownObject);
1027         assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1028     }
1029
1030     @Test
1031     public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
1032         final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1033         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1034
1035         final LspaBuilder builder = new LspaBuilder();
1036         builder.setProcessingRule(true);
1037         builder.setIgnore(true);
1038         builder.setLocalProtectionDesired(false);
1039
1040         final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1041         parser.serializeObject(builder.build(), buf);
1042         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1043     }
1044
1045     @Test
1046     public void testEmptyEroObject() throws PCEPDeserializerException {
1047         final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1048         assertNotNull(object);
1049         assertTrue(object instanceof Ero);
1050         final Ero eroObject = (Ero) object;
1051         assertTrue(eroObject.getSubobject().isEmpty());
1052
1053         final ByteBuf buffer = Unpooled.buffer();
1054         this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1055         final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1056         assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1057     }
1058
1059     @Test
1060     public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
1061         final byte[] closeBytes = {
1062             0x0f, 0x10, 0x00, 0x14,
1063             0x00, 0x00, 0x00, 0x05,
1064             /* vendor-information TLV */
1065             0x00, 0x07, 0x00, 0x08,
1066             /* enterprise number */
1067             0x00, 0x00, 0x00, 0x00,
1068             /* enterprise specific information */
1069             0x00, 0x00, 0x00, 0x05
1070         };
1071         final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1072         final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1073
1074         final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1075         final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1076                 .setEnterpriseSpecificInformation(esInfo).build();
1077         final CCloseBuilder builder = new CCloseBuilder();
1078         builder.setProcessingRule(false);
1079         builder.setIgnore(false);
1080         builder.setReason((short) 5);
1081         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
1082             .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1083
1084         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1085
1086         final ByteBuf buf = Unpooled.buffer();
1087         parser.serializeObject(builder.build(), buf);
1088         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1089     }
1090
1091     @Test
1092     public void testVendorInformationObject() throws PCEPDeserializerException {
1093         final byte[] viObjBytes = {
1094             /* vendor-information object */
1095             0x22, 0x10, 0x00, 0x0C,
1096             /* enterprise number */
1097             0x00, 0x00, 0x00, 0x00,
1098             /* enterprise specific information */
1099             0x00, 0x00, 0x00, 0x05
1100         };
1101         final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1102         final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1103         final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1104                 .setEnterpriseSpecificInformation(esInfo).build();
1105         final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1106         result.readerIndex(8);
1107         final VendorInformationObject o = (VendorInformationObject) parser.parseObject(new ObjectHeaderImpl(false, false), result.readSlice(result.readableBytes()));
1108         assertEquals(viObj, o);
1109
1110         final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1111         parser.serializeObject(viObj, buf);
1112         assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1113     }
1114
1115     @Test
1116     public void testMonitoringObject() throws PCEPDeserializerException {
1117         final byte[] monitoringBytes = {
1118             /* object header */
1119             0x13, 0x10, 0x00, 0x0C,
1120             /* flags */
1121             0x00, 0x00, 0x00, 0x01,
1122             /* monitoring-id=16 */
1123             0x00, 0x00, 0x00, 0x10
1124         };
1125         final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
1126         final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
1127                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
1128         final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
1129         assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1130
1131         final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
1132         parser.serializeObject(monitoring, buf);
1133         assertArrayEquals(monitoringBytes, buf.array());
1134     }
1135
1136     @Test
1137     public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
1138         final byte[] pccIdReqBytes = {
1139             /* object header */
1140             0x14, 0x10, 0x00, 0x08,
1141             /* ipv4 address */
1142             0x7f, 0x00, 0x00, 0x01
1143         };
1144         final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
1145         final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
1146         final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1147         assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1148
1149         final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1150         parser.serializeObject(pccIdReq, buf);
1151         assertArrayEquals(pccIdReqBytes, buf.array());
1152     }
1153
1154     @Test
1155     public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
1156         final byte[] pccIdReqBytes = {
1157             /* object header */
1158             0x14, 0x20, 0x00, 0x14,
1159             /* ipv6 address */
1160             0x00, 0x00, 0x00, 0x00,
1161             0x00, 0x00, 0x00, 0x00,
1162             0x00, 0x00, 0x00, 0x00,
1163             0x00, 0x00, 0x00, 0x01
1164         };
1165         final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
1166         final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build();
1167         final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1168         assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1169
1170         final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1171         parser.serializeObject(pccIdReq, buf);
1172         assertArrayEquals(pccIdReqBytes, buf.array());
1173     }
1174
1175     @Test
1176     public void testPceIdIPv4Object() throws PCEPDeserializerException {
1177         final byte[] pccIdReqBytes = {
1178             /* object header */
1179             0x19, 0x10, 0x00, 0x08,
1180             /* ipv4 address */
1181             0x7f, 0x00, 0x00, 0x01
1182         };
1183         final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
1184         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pceId = new PceIdBuilder().setIpAddress(new IpAddress(
1185                 new Ipv4Address("127.0.0.1"))).build();
1186         final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1187         assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1188
1189         final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1190         parser.serializeObject(pceId, buf);
1191         assertArrayEquals(pccIdReqBytes, buf.array());
1192     }
1193
1194     @Test
1195     public void testPceIdIPv6Object() throws PCEPDeserializerException {
1196         final byte[] pccIdReqBytes = {
1197             /* object header */
1198             0x19, 0x20, 0x00, 0x14,
1199             /* ipv6 header */
1200             0x00, 0x00, 0x00, 0x00,
1201             0x00, 0x00, 0x00, 0x00,
1202             0x00, 0x00, 0x00, 0x00,
1203             0x00, 0x00, 0x00, 0x01
1204         };
1205         final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
1206         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddress(
1207                 new Ipv6Address("::1"))).build();
1208         final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1209         assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1210
1211         final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1212         parser.serializeObject(pccIdReq, buf);
1213         assertArrayEquals(pccIdReqBytes, buf.array());
1214     }
1215
1216     @Test
1217     public void testProcTimeObject() throws PCEPDeserializerException {
1218         final byte[] proctimeBytes = {
1219             /* object header */
1220             0x1A, 0x10, 0x00, 0x1C,
1221             /* E flag */
1222             0x00, 0x00, 0x00, 0x01,
1223             /* current proc. time */
1224             0x00, 0x00, 0x00, 0x01,
1225             /* min proc. time */
1226             0x00, 0x00, 0x00, 0x02,
1227             /* max proc time */
1228             0x00, 0x00, 0x00, 0x03,
1229             /* average proc time */
1230             0x00, 0x00, 0x00, 0x04,
1231             /* variance proc time */
1232             0x00, 0x00, 0x00, 0x05,
1233         };
1234         final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
1235         final ProcTime procTime = new ProcTimeBuilder()
1236             .setEstimated(true)
1237             .setAverageProcTime(4L)
1238             .setCurrentProcTime(1L)
1239             .setMaxProcTime(3L)
1240             .setMinProcTime(2L)
1241             .setVarianceProcTime(5L).build();
1242         final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
1243         assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1244
1245         final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
1246         parser.serializeObject(procTime, buf);
1247         assertArrayEquals(proctimeBytes, buf.array());
1248     }
1249
1250     @Test
1251     public void testOverloadObject() throws PCEPDeserializerException {
1252         final byte[] overloadBytes = {
1253             /* object header */
1254             0x1B, 0x10, 0x00, 0x08,
1255             /* overload duration */
1256             0x00, 0x00, 0x00, 0x78
1257         };
1258         final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
1259         final Overload overload = new OverloadBuilder().setDuration(120).build();
1260         final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
1261         assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1262
1263         final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
1264         parser.serializeObject(overload, buf);
1265         assertArrayEquals(overloadBytes, buf.array());
1266     }
1267
1268     @Test
1269     public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
1270
1271         final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
1272             (byte) 0xad, (byte) 0xbe, (byte) 0xef,
1273             /* pst-tlv */
1274             0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
1275
1276         final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
1277         final RpBuilder builder = new RpBuilder();
1278         builder.setProcessingRule(false);
1279         builder.setIgnore(false);
1280         builder.setReoptimization(true);
1281         builder.setBiDirectional(false);
1282         builder.setLoose(true);
1283         builder.setMakeBeforeBreak(true);
1284         builder.setOrder(false);
1285         builder.setPathKey(false);
1286         builder.setSupplyOf(false);
1287         builder.setFragmentation(false);
1288         builder.setP2mp(false);
1289         builder.setEroCompression(false);
1290         builder.setPriority((short) 5);
1291         builder.setRequestId(new RequestId(0xdeadbeefL));
1292         builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setPathSetupType(
1293                 new PathSetupTypeBuilder().setPst((short) 0).build()).build());
1294
1295         final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
1296         assertEquals(builder.build(),
1297                 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1298         final ByteBuf buf = Unpooled.buffer();
1299         parser.serializeObject(builder.build(), buf);
1300         assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
1301     }
1302 }