2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.impl;
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;
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.PCEPNoPathObjectParser;
41 import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
42 import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
43 import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
44 import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
45 import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
46 import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
47 import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
48 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
49 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
50 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
51 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
52 import org.opendaylight.protocol.pcep.spi.UnknownObject;
53 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
54 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
55 import org.opendaylight.protocol.util.ByteArray;
56 import org.opendaylight.protocol.util.Ipv4Util;
57 import org.opendaylight.protocol.util.Ipv6Util;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
99 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;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
117 public class PCEPObjectParserTest {
119 private TlvRegistry tlvRegistry;
121 private VendorInformationTlvRegistry viTlvRegistry;
123 private SimplePCEPExtensionProviderContext ctx;
124 private Activator act;
125 private TestVendorInformationActivator viAct;
128 public void setUp() {
129 this.ctx = new SimplePCEPExtensionProviderContext();
130 this.act = new Activator();
131 this.viAct = new TestVendorInformationActivator();
132 this.act.start(this.ctx);
133 this.viAct.start(this.ctx);
134 this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
135 this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
139 public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
140 final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
141 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
143 final OpenBuilder builder = new OpenBuilder();
144 builder.setProcessingRule(false);
145 builder.setIgnore(false);
146 builder.setVersion(new ProtocolVersion((short) 1));
147 builder.setKeepalive((short) 30);
148 builder.setDeadTimer((short) 120);
149 builder.setSessionId((short) 1);
151 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
153 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
154 final ByteBuf buf = Unpooled.buffer();
155 parser.serializeObject(builder.build(), buf);
156 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
159 parser.parseObject(new ObjectHeaderImpl(true, true), null);
161 } catch (final IllegalArgumentException e) {
162 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
165 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
167 } catch (final IllegalArgumentException e) {
168 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
173 public void testCloseObject() throws IOException, PCEPDeserializerException {
174 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
175 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
177 final CCloseBuilder builder = new CCloseBuilder();
178 builder.setProcessingRule(false);
179 builder.setIgnore(false);
180 builder.setReason((short) 5);
181 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
183 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
184 final ByteBuf buf = Unpooled.buffer();
185 parser.serializeObject(builder.build(), buf);
186 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
189 parser.parseObject(new ObjectHeaderImpl(true, true), null);
191 } catch (final IllegalArgumentException e) {
192 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
195 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
197 } catch (final IllegalArgumentException e) {
198 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
203 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
204 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
205 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
207 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
208 builder.setProcessingRule(true);
209 builder.setIgnore(false);
210 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
211 builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
213 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
214 final ByteBuf buf = Unpooled.buffer();
215 parser.serializeObject(builder.build(), buf);
216 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
219 parser.parseObject(new ObjectHeaderImpl(true, true), null);
221 } catch (final IllegalArgumentException e) {
222 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
225 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
227 } catch (final IllegalArgumentException e) {
228 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
233 public void testERObject() throws Exception {
234 final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
235 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
237 final EroBuilder builder = new EroBuilder();
238 builder.setProcessingRule(false);
239 builder.setIgnore(false);
240 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
241 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
242 true).setSubobjectType(
243 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
244 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
245 true).setSubobjectType(
246 new IpPrefixCaseBuilder().setIpPrefix(
247 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
248 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
249 true).setSubobjectType(
250 new UnnumberedCaseBuilder().setUnnumbered(
251 new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
252 builder.setSubobject(subs);
254 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
255 final ByteBuf buf = Unpooled.buffer();
256 parser.serializeObject(builder.build(), buf);
257 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
260 parser.parseObject(new ObjectHeaderImpl(true, true), null);
262 } catch (final IllegalArgumentException e) {
263 assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
268 public void testIRObject() throws Exception {
269 final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
270 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
271 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
272 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
274 final IroBuilder builder = new IroBuilder();
275 builder.setProcessingRule(false);
276 builder.setIgnore(false);
277 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists.newArrayList();
278 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
279 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).build());
280 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
281 new IpPrefixCaseBuilder().setIpPrefix(
282 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).build());
283 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
284 new IpPrefixCaseBuilder().setIpPrefix(
285 new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).build());
286 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
287 new UnnumberedCaseBuilder().setUnnumbered(
288 new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).build());
289 builder.setSubobject(subs);
291 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
292 final ByteBuf buf = Unpooled.buffer();
293 parser.serializeObject(builder.build(), buf);
294 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
297 parser.parseObject(new ObjectHeaderImpl(true, true), null);
299 } catch (final IllegalArgumentException e) {
300 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
303 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
305 } catch (final IllegalArgumentException e) {
306 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
311 public void testRRObject() throws Exception {
312 final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
313 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
314 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
315 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
317 final RroBuilder builder = new RroBuilder();
318 builder.setProcessingRule(false);
319 builder.setIgnore(false);
320 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
321 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
322 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
323 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
324 new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
326 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
327 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
328 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
329 new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
331 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
332 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
333 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
334 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
336 builder.setSubobject(subs);
338 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
339 final ByteBuf buf = Unpooled.buffer();
340 parser.serializeObject(builder.build(), buf);
341 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
344 parser.parseObject(new ObjectHeaderImpl(true, true), null);
346 } catch (final IllegalArgumentException e) {
347 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
350 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
352 } catch (final IllegalArgumentException e) {
353 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
358 public void testBandwidthObject() throws IOException, PCEPDeserializerException {
359 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
360 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
362 final BandwidthBuilder builder = new BandwidthBuilder();
363 builder.setProcessingRule(true);
364 builder.setIgnore(true);
365 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
367 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
368 final ByteBuf buf = Unpooled.buffer();
369 parser.serializeObject(builder.build(), buf);
370 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
373 parser.parseObject(new ObjectHeaderImpl(true, true), null);
375 } catch (final IllegalArgumentException e) {
376 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
379 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
381 } catch (final IllegalArgumentException e) {
382 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
387 public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
388 final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
389 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
391 final BandwidthBuilder builder = new BandwidthBuilder();
392 builder.setProcessingRule(true);
393 builder.setIgnore(true);
394 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
396 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
397 final ByteBuf buf = Unpooled.buffer();
398 parser.serializeObject(builder.build(), buf);
399 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
402 parser.parseObject(new ObjectHeaderImpl(true, true), null);
404 } catch (final IllegalArgumentException e) {
405 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
408 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
410 } catch (final IllegalArgumentException e) {
411 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
416 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
417 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
418 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
420 final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
421 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
423 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
424 builder.setProcessingRule(true);
425 builder.setIgnore(false);
426 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
427 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
428 Ipv4Util.addressForBytes(destIPBytes)).build()).build());
430 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
431 final ByteBuf buf = Unpooled.buffer();
432 parser.serializeObject(builder.build(), buf);
433 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
436 parser.parseObject(new ObjectHeaderImpl(true, true), null);
438 } catch (final IllegalArgumentException e) {
439 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
442 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
444 } catch (final IllegalArgumentException e) {
445 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
450 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
451 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
452 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
453 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
454 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
456 final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
457 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
459 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
460 builder.setProcessingRule(true);
461 builder.setIgnore(false);
462 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
463 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
464 Ipv6Util.addressForBytes(destIPBytes)).build()).build());
466 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
467 final ByteBuf buf = Unpooled.buffer();
468 parser.serializeObject(builder.build(), buf);
469 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
472 parser.parseObject(new ObjectHeaderImpl(true, true), null);
474 } catch (final IllegalArgumentException e) {
475 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
478 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
480 } catch (final IllegalArgumentException e) {
481 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
486 public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
487 final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
488 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
490 final ErrorObjectBuilder builder = new ErrorObjectBuilder();
491 builder.setProcessingRule(true);
492 builder.setIgnore(true);
493 builder.setType((short) 1);
494 builder.setValue((short) 1);
496 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
497 ByteBuf buf = Unpooled.buffer();
498 parser.serializeObject(builder.build(), buf);
499 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
501 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
503 builder.setType((short) 7);
504 builder.setValue((short) 0);
505 builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
507 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
508 buf = Unpooled.buffer();
509 parser.serializeObject(builder.build(), buf);
510 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
513 parser.parseObject(new ObjectHeaderImpl(true, true), null);
515 } catch (final IllegalArgumentException e) {
516 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
519 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
521 } catch (final IllegalArgumentException e) {
522 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
527 public void testLspaObject() throws IOException, PCEPDeserializerException {
528 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
529 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
531 final LspaBuilder builder = new LspaBuilder();
532 builder.setProcessingRule(true);
533 builder.setIgnore(true);
534 builder.setExcludeAny(new AttributeFilter(0L));
535 builder.setIncludeAny(new AttributeFilter(0L));
536 builder.setIncludeAll(new AttributeFilter(0L));
537 builder.setHoldPriority((short) 0);
538 builder.setSetupPriority((short) 0);
539 builder.setLocalProtectionDesired(false);
540 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
542 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
543 ByteBuf buf = Unpooled.buffer();
544 parser.serializeObject(builder.build(), buf);
545 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
547 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
549 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
550 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
551 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
552 builder.setHoldPriority((short) 0xFF);
553 builder.setSetupPriority((short) 0xFF);
554 builder.setLocalProtectionDesired(true);
556 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
557 buf = Unpooled.buffer();
558 parser.serializeObject(builder.build(), buf);
559 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
562 parser.parseObject(new ObjectHeaderImpl(true, true), null);
564 } catch (final IllegalArgumentException e) {
565 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
568 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
570 } catch (final IllegalArgumentException e) {
571 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
576 public void testMetricObject() throws IOException, PCEPDeserializerException {
577 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
578 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
580 final MetricBuilder builder = new MetricBuilder();
581 builder.setProcessingRule(true);
582 builder.setIgnore(true);
583 builder.setComputed(false);
584 builder.setBound(false);
585 builder.setMetricType((short) 1);
586 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
588 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
589 ByteBuf buf = Unpooled.buffer();
590 parser.serializeObject(builder.build(), buf);
591 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
593 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
595 builder.setComputed(true);
596 builder.setBound(false);
597 builder.setMetricType((short) 2);
598 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
600 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
601 buf = Unpooled.buffer();
602 parser.serializeObject(builder.build(), buf);
603 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
606 parser.parseObject(new ObjectHeaderImpl(true, true), null);
608 } catch (final IllegalArgumentException e) {
609 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
612 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
614 } catch (final IllegalArgumentException e) {
615 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
620 public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
621 final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
622 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
624 final NoPathBuilder builder = new NoPathBuilder();
625 builder.setProcessingRule(true);
626 builder.setIgnore(true);
627 builder.setNatureOfIssue((short) 1);
628 builder.setUnsatisfiedConstraints(true);
629 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());
631 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
632 ByteBuf buf = Unpooled.buffer();
633 parser.serializeObject(builder.build(), buf);
634 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
636 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
638 builder.setNatureOfIssue((short) 0);
639 builder.setUnsatisfiedConstraints(false);
641 final NoPathVectorBuilder b = new NoPathVectorBuilder();
642 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));
643 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(
646 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
647 buf = Unpooled.buffer();
648 parser.serializeObject(builder.build(), buf);
649 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
652 parser.parseObject(new ObjectHeaderImpl(true, true), null);
654 } catch (final IllegalArgumentException e) {
655 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
658 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
660 } catch (final IllegalArgumentException e) {
661 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
666 public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
667 final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
668 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
670 final CNotificationBuilder builder = new CNotificationBuilder();
671 builder.setProcessingRule(true);
672 builder.setIgnore(true);
673 builder.setType((short) 0xff);
674 builder.setValue((short) 0xff);
676 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
677 ByteBuf buf = Unpooled.buffer();
678 parser.serializeObject(builder.build(), buf);
679 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
681 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
683 builder.setType((short) 2);
684 builder.setValue((short) 1);
685 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
686 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
688 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
689 buf = Unpooled.buffer();
690 parser.serializeObject(builder.build(), buf);
691 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
694 parser.parseObject(new ObjectHeaderImpl(true, true), null);
696 } catch (final IllegalArgumentException e) {
697 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
700 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
702 } catch (final IllegalArgumentException e) {
703 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
708 public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
709 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
710 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
712 final RpBuilder builder = new RpBuilder();
713 builder.setProcessingRule(true);
714 builder.setIgnore(true);
715 builder.setReoptimization(true);
716 builder.setBiDirectional(false);
717 builder.setLoose(true);
718 builder.setMakeBeforeBreak(true);
719 builder.setOrder(false);
720 builder.setPathKey(false);
721 builder.setSupplyOf(false);
722 builder.setFragmentation(false);
723 builder.setP2mp(false);
724 builder.setEroCompression(false);
725 builder.setPriority((short) 5);
726 builder.setRequestId(new RequestId(0xdeadbeefL));
727 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
729 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
730 ByteBuf buf = Unpooled.buffer();
731 parser.serializeObject(builder.build(), buf);
732 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
734 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
736 builder.setReoptimization(false);
737 builder.setFragmentation(true);
738 builder.setEroCompression(true);
740 final OrderBuilder b = new OrderBuilder();
741 b.setDelete(0xffffffffL);
744 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
747 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
748 buf = Unpooled.buffer();
749 parser.serializeObject(builder.build(), buf);
750 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
753 parser.parseObject(new ObjectHeaderImpl(true, true), null);
755 } catch (final IllegalArgumentException e) {
756 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
759 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
761 } catch (final IllegalArgumentException e) {
762 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
767 public void testSvecObject() throws IOException, PCEPDeserializerException {
768 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
769 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
771 final SvecBuilder builder = new SvecBuilder();
772 builder.setProcessingRule(false);
773 builder.setIgnore(false);
774 builder.setLinkDiverse(false);
775 builder.setNodeDiverse(false);
776 builder.setSrlgDiverse(false);
777 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
779 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
780 ByteBuf buf = Unpooled.buffer();
781 parser.serializeObject(builder.build(), buf);
782 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
784 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
786 builder.setProcessingRule(true);
787 builder.setLinkDiverse(true);
788 builder.setSrlgDiverse(true);
790 final List<RequestId> requestIDs = Lists.newArrayList();
791 requestIDs.add(new RequestId(0xFFFFFFFFL));
792 requestIDs.add(new RequestId(0x00000001L));
793 requestIDs.add(new RequestId(0x01234567L));
794 requestIDs.add(new RequestId(0x89ABCDEFL));
795 requestIDs.add(new RequestId(0xFEDCBA98L));
796 requestIDs.add(new RequestId(0x76543210L));
797 requestIDs.add(new RequestId(0x15825266L));
798 requestIDs.add(new RequestId(0x48120BBEL));
799 requestIDs.add(new RequestId(0x25FB7E52L));
800 requestIDs.add(new RequestId(0xB2F2546BL));
802 builder.setRequestsIds(requestIDs);
804 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
805 buf = Unpooled.buffer();
806 parser.serializeObject(builder.build(), buf);
807 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
810 parser.parseObject(new ObjectHeaderImpl(true, true), null);
812 } catch (final IllegalArgumentException e) {
813 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
816 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
818 } catch (final IllegalArgumentException e) {
819 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
824 public void testClassTypeObject() throws PCEPDeserializerException {
825 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
826 final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
828 final ClassTypeBuilder builder = new ClassTypeBuilder();
829 builder.setProcessingRule(true);
830 builder.setIgnore(false);
831 builder.setClassType(new ClassType((short) 4));
833 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
834 final ByteBuf buf = Unpooled.buffer();
835 parser.serializeObject(builder.build(), buf);
836 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
839 parser.parseObject(new ObjectHeaderImpl(true, true), null);
841 } catch (final IllegalArgumentException e) {
842 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
845 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
847 } catch (final IllegalArgumentException e) {
848 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
853 public void testExcludeRouteObject() throws Exception {
854 final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
855 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
857 final XroBuilder builder = new XroBuilder();
858 builder.setProcessingRule(false);
859 builder.setIgnore(false);
860 builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
861 final List<Subobject> subs = Lists.newArrayList();
862 subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
863 new IpPrefixCaseBuilder().setIpPrefix(
864 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
865 Attribute.Node).build());
866 subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
867 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
868 builder.setSubobject(subs);
870 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
871 final ByteBuf buf = Unpooled.buffer();
872 parser.serializeObject(builder.build(), buf);
873 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
876 parser.parseObject(new ObjectHeaderImpl(true, true), null);
878 } catch (final IllegalArgumentException e) {
879 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
882 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
884 } catch (final IllegalArgumentException e) {
885 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
890 public void testPathKeyObject() throws Exception {
891 final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
892 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
894 final PathKeyBuilder builder = new PathKeyBuilder();
895 builder.setProcessingRule(true);
896 builder.setIgnore(false);
897 final List<PathKeys> list = Lists.newArrayList();
898 list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
899 new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
900 builder.setPathKeys(list);
902 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
903 final ByteBuf buf = Unpooled.buffer();
904 parser.serializeObject(builder.build(), buf);
905 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
908 parser.parseObject(new ObjectHeaderImpl(true, true), null);
910 } catch (final IllegalArgumentException e) {
911 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
914 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
916 } catch (final IllegalArgumentException e) {
917 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
922 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
923 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
924 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
926 final OfBuilder builder = new OfBuilder();
927 builder.setProcessingRule(true);
928 builder.setIgnore(false);
929 builder.setCode(new OfId(4));
930 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
932 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
933 final ByteBuf buf = Unpooled.buffer();
934 parser.serializeObject(builder.build(), buf);
935 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
938 parser.parseObject(new ObjectHeaderImpl(true, true), null);
940 } catch (final IllegalArgumentException e) {
941 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
944 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
946 } catch (final IllegalArgumentException e) {
947 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
952 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
953 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
954 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
956 final GcBuilder builder = new GcBuilder();
957 builder.setProcessingRule(true);
958 builder.setIgnore(false);
959 builder.setMaxHop((short) 1);
960 builder.setMaxUtilization((short) 0);
961 builder.setMinUtilization((short) 100);
962 builder.setOverBookingFactor((short) 99);
963 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
965 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
966 final ByteBuf buf = Unpooled.buffer();
967 parser.serializeObject(builder.build(), buf);
968 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
971 parser.parseObject(new ObjectHeaderImpl(true, true), null);
973 } catch (final IllegalArgumentException e) {
974 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
977 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
979 } catch (final IllegalArgumentException e) {
980 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
985 public void testIgnoreUknownObject() throws PCEPDeserializerException {
986 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
991 public void testUnrecognizedObjectType() throws PCEPDeserializerException {
992 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
993 assertNotNull(object);
994 assertTrue(object instanceof UnknownObject);
995 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
999 public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1000 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1001 assertNotNull(object);
1002 assertTrue(object instanceof UnknownObject);
1003 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1007 public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
1008 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1009 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1011 final LspaBuilder builder = new LspaBuilder();
1012 builder.setProcessingRule(true);
1013 builder.setIgnore(true);
1014 builder.setLocalProtectionDesired(false);
1016 final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1017 parser.serializeObject(builder.build(), buf);
1018 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1022 public void testEmptyEroObject() throws PCEPDeserializerException {
1023 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1024 assertNotNull(object);
1025 assertTrue(object instanceof Ero);
1026 final Ero eroObject = (Ero) object;
1027 assertTrue(eroObject.getSubobject().isEmpty());
1029 final ByteBuf buffer = Unpooled.buffer();
1030 this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1031 final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1032 assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1036 public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
1037 final byte[] closeBytes = {
1038 0x0f, 0x10, 0x00, 0x14,
1039 0x00, 0x00, 0x00, 0x05,
1040 /* vendor-information TLV */
1041 0x00, 0x07, 0x00, 0x08,
1042 /* enterprise number */
1043 0x00, 0x00, 0x00, 0x00,
1044 /* enterprise specific information */
1045 0x00, 0x00, 0x00, 0x05
1047 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1048 final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1050 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1051 final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1052 .setEnterpriseSpecificInformation(esInfo).build();
1053 final CCloseBuilder builder = new CCloseBuilder();
1054 builder.setProcessingRule(false);
1055 builder.setIgnore(false);
1056 builder.setReason((short) 5);
1057 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
1058 .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1060 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1062 final ByteBuf buf = Unpooled.buffer();
1063 parser.serializeObject(builder.build(), buf);
1064 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1068 public void testVendorInformationObject() throws PCEPDeserializerException {
1069 final byte[] viObjBytes = {
1070 /* vendor-information object */
1071 0x22, 0x10, 0x00, 0x0C,
1072 /* enterprise number */
1073 0x00, 0x00, 0x00, 0x00,
1074 /* enterprise specific information */
1075 0x00, 0x00, 0x00, 0x05
1077 final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1078 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1079 final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1080 .setEnterpriseSpecificInformation(esInfo).build();
1081 final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1083 assertEquals(viObj, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1085 final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1086 parser.serializeObject(viObj, buf);
1087 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));