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