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