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