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