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