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