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