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