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