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