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