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.PCEPMonitoringObjectParser;
41 import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
42 import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
43 import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
44 import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
45 import org.opendaylight.protocol.pcep.impl.object.PCEPOverloadObjectParser;
46 import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
47 import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv4ObjectParser;
48 import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv6ObjectParser;
49 import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv4ObjectParser;
50 import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv6ObjectParser;
51 import org.opendaylight.protocol.pcep.impl.object.PCEPProcTimeObjectParser;
52 import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
53 import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
54 import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
55 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
56 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
57 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
58 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
59 import org.opendaylight.protocol.pcep.spi.UnknownObject;
60 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
61 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
62 import org.opendaylight.protocol.util.ByteArray;
63 import org.opendaylight.protocol.util.Ipv4Util;
64 import org.opendaylight.protocol.util.Ipv6Util;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
68 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
69 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
116 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;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
138 public class PCEPObjectParserTest {
140 private TlvRegistry tlvRegistry;
142 private VendorInformationTlvRegistry viTlvRegistry;
144 private SimplePCEPExtensionProviderContext ctx;
145 private Activator act;
146 private TestVendorInformationActivator viAct;
149 public void setUp() {
150 this.ctx = new SimplePCEPExtensionProviderContext();
151 this.act = new Activator();
152 this.viAct = new TestVendorInformationActivator();
153 this.act.start(this.ctx);
154 this.viAct.start(this.ctx);
155 this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
156 this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
160 public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
161 final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
162 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
164 final OpenBuilder builder = new OpenBuilder();
165 builder.setProcessingRule(false);
166 builder.setIgnore(false);
167 builder.setVersion(new ProtocolVersion((short) 1));
168 builder.setKeepalive((short) 30);
169 builder.setDeadTimer((short) 120);
170 builder.setSessionId((short) 1);
172 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
174 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
175 final ByteBuf buf = Unpooled.buffer();
176 parser.serializeObject(builder.build(), buf);
177 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
180 parser.parseObject(new ObjectHeaderImpl(true, true), null);
182 } catch (final IllegalArgumentException e) {
183 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
186 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
188 } catch (final IllegalArgumentException e) {
189 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
194 public void testCloseObject() throws IOException, PCEPDeserializerException {
195 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
196 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
198 final CCloseBuilder builder = new CCloseBuilder();
199 builder.setProcessingRule(false);
200 builder.setIgnore(false);
201 builder.setReason((short) 5);
202 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
204 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
205 final ByteBuf buf = Unpooled.buffer();
206 parser.serializeObject(builder.build(), buf);
207 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
210 parser.parseObject(new ObjectHeaderImpl(true, true), null);
212 } catch (final IllegalArgumentException e) {
213 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
216 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
218 } catch (final IllegalArgumentException e) {
219 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
224 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
225 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
226 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
228 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
229 builder.setProcessingRule(true);
230 builder.setIgnore(false);
231 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
232 builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
234 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
235 final ByteBuf buf = Unpooled.buffer();
236 parser.serializeObject(builder.build(), buf);
237 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
240 parser.parseObject(new ObjectHeaderImpl(true, true), null);
242 } catch (final IllegalArgumentException e) {
243 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
246 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
248 } catch (final IllegalArgumentException e) {
249 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
254 public void testERObject() throws Exception {
255 final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
256 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
258 final EroBuilder builder = new EroBuilder();
259 builder.setProcessingRule(false);
260 builder.setIgnore(false);
261 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
262 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
263 true).setSubobjectType(
264 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
265 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
266 true).setSubobjectType(
267 new IpPrefixCaseBuilder().setIpPrefix(
268 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
269 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
270 true).setSubobjectType(
271 new UnnumberedCaseBuilder().setUnnumbered(
272 new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
273 builder.setSubobject(subs);
275 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
276 final ByteBuf buf = Unpooled.buffer();
277 parser.serializeObject(builder.build(), buf);
278 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
281 parser.parseObject(new ObjectHeaderImpl(true, true), null);
283 } catch (final IllegalArgumentException e) {
284 assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
289 public void testIRObject() throws Exception {
290 final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
291 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
292 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
293 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
295 final IroBuilder builder = new IroBuilder();
296 builder.setProcessingRule(false);
297 builder.setIgnore(false);
298 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists.newArrayList();
299 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
300 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).build());
301 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
302 new IpPrefixCaseBuilder().setIpPrefix(
303 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).build());
304 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
305 new IpPrefixCaseBuilder().setIpPrefix(
306 new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).build());
307 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
308 new UnnumberedCaseBuilder().setUnnumbered(
309 new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).build());
310 builder.setSubobject(subs);
312 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
313 final ByteBuf buf = Unpooled.buffer();
314 parser.serializeObject(builder.build(), buf);
315 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
318 parser.parseObject(new ObjectHeaderImpl(true, true), null);
320 } catch (final IllegalArgumentException e) {
321 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
324 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
326 } catch (final IllegalArgumentException e) {
327 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
332 public void testRRObject() throws Exception {
333 final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
334 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
335 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
336 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
338 final RroBuilder builder = new RroBuilder();
339 builder.setProcessingRule(false);
340 builder.setIgnore(false);
341 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
342 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
343 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
344 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
345 new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
347 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
348 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
349 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
350 new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
352 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
353 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
354 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
355 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
357 builder.setSubobject(subs);
359 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
360 final ByteBuf buf = Unpooled.buffer();
361 parser.serializeObject(builder.build(), buf);
362 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
365 parser.parseObject(new ObjectHeaderImpl(true, true), null);
367 } catch (final IllegalArgumentException e) {
368 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
371 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
373 } catch (final IllegalArgumentException e) {
374 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
379 public void testBandwidthObject() throws IOException, PCEPDeserializerException {
380 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
381 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
383 final BandwidthBuilder builder = new BandwidthBuilder();
384 builder.setProcessingRule(true);
385 builder.setIgnore(true);
386 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
388 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
389 final ByteBuf buf = Unpooled.buffer();
390 parser.serializeObject(builder.build(), buf);
391 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
394 parser.parseObject(new ObjectHeaderImpl(true, true), null);
396 } catch (final IllegalArgumentException e) {
397 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
400 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
402 } catch (final IllegalArgumentException e) {
403 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
408 public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
409 final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
410 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
412 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization
413 .bandwidth.object.BandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
414 .ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.BandwidthBuilder();
415 builder.setProcessingRule(true);
416 builder.setIgnore(true);
417 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
419 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
420 final ByteBuf buf = Unpooled.buffer();
421 parser.serializeObject(builder.build(), buf);
422 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
425 parser.parseObject(new ObjectHeaderImpl(true, true), null);
427 } catch (final IllegalArgumentException e) {
428 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
431 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
433 } catch (final IllegalArgumentException e) {
434 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
439 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
440 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
441 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
443 final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
444 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
446 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
447 builder.setProcessingRule(true);
448 builder.setIgnore(false);
449 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
450 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
451 Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
453 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
454 final ByteBuf buf = Unpooled.buffer();
455 parser.serializeObject(builder.build(), buf);
456 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
459 parser.parseObject(new ObjectHeaderImpl(true, true), null);
461 } catch (final IllegalArgumentException e) {
462 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
465 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
467 } catch (final IllegalArgumentException e) {
468 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
473 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
474 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
475 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
476 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
477 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
479 final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
480 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
482 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
483 builder.setProcessingRule(true);
484 builder.setIgnore(false);
485 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
486 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
487 Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
489 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
490 final ByteBuf buf = Unpooled.buffer();
491 parser.serializeObject(builder.build(), buf);
492 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
495 parser.parseObject(new ObjectHeaderImpl(true, true), null);
497 } catch (final IllegalArgumentException e) {
498 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
501 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
503 } catch (final IllegalArgumentException e) {
504 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
509 public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
510 final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
511 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
513 final ErrorObjectBuilder builder = new ErrorObjectBuilder();
514 builder.setProcessingRule(true);
515 builder.setIgnore(true);
516 builder.setType((short) 1);
517 builder.setValue((short) 1);
519 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
520 ByteBuf buf = Unpooled.buffer();
521 parser.serializeObject(builder.build(), buf);
522 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
524 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
526 builder.setType((short) 7);
527 builder.setValue((short) 0);
528 builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
530 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
531 buf = Unpooled.buffer();
532 parser.serializeObject(builder.build(), buf);
533 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
536 parser.parseObject(new ObjectHeaderImpl(true, true), null);
538 } catch (final IllegalArgumentException e) {
539 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
542 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
544 } catch (final IllegalArgumentException e) {
545 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
550 public void testLspaObject() throws IOException, PCEPDeserializerException {
551 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
552 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
554 final LspaBuilder builder = new LspaBuilder();
555 builder.setProcessingRule(true);
556 builder.setIgnore(true);
557 builder.setExcludeAny(new AttributeFilter(0L));
558 builder.setIncludeAny(new AttributeFilter(0L));
559 builder.setIncludeAll(new AttributeFilter(0L));
560 builder.setHoldPriority((short) 0);
561 builder.setSetupPriority((short) 0);
562 builder.setLocalProtectionDesired(false);
563 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
565 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
566 ByteBuf buf = Unpooled.buffer();
567 parser.serializeObject(builder.build(), buf);
568 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
570 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
572 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
573 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
574 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
575 builder.setHoldPriority((short) 0xFF);
576 builder.setSetupPriority((short) 0xFF);
577 builder.setLocalProtectionDesired(true);
579 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
580 buf = Unpooled.buffer();
581 parser.serializeObject(builder.build(), buf);
582 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
585 parser.parseObject(new ObjectHeaderImpl(true, true), null);
587 } catch (final IllegalArgumentException e) {
588 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
591 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
593 } catch (final IllegalArgumentException e) {
594 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
599 public void testMetricObject() throws IOException, PCEPDeserializerException {
600 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
601 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
603 final MetricBuilder builder = new MetricBuilder();
604 builder.setProcessingRule(true);
605 builder.setIgnore(true);
606 builder.setComputed(false);
607 builder.setBound(false);
608 builder.setMetricType((short) 1);
609 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
611 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
612 ByteBuf buf = Unpooled.buffer();
613 parser.serializeObject(builder.build(), buf);
614 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
616 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
618 builder.setComputed(true);
619 builder.setBound(false);
620 builder.setMetricType((short) 2);
621 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
623 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
624 buf = Unpooled.buffer();
625 parser.serializeObject(builder.build(), buf);
626 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
629 parser.parseObject(new ObjectHeaderImpl(true, true), null);
631 } catch (final IllegalArgumentException e) {
632 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
635 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
637 } catch (final IllegalArgumentException e) {
638 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
643 public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
644 final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
645 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
647 final NoPathBuilder builder = new NoPathBuilder();
648 builder.setProcessingRule(true);
649 builder.setIgnore(true);
650 builder.setNatureOfIssue((short) 1);
651 builder.setUnsatisfiedConstraints(true);
652 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());
654 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
655 ByteBuf buf = Unpooled.buffer();
656 parser.serializeObject(builder.build(), buf);
657 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
659 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
661 builder.setNatureOfIssue((short) 0);
662 builder.setUnsatisfiedConstraints(false);
664 final NoPathVectorBuilder b = new NoPathVectorBuilder();
665 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));
666 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(
669 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
670 buf = Unpooled.buffer();
671 parser.serializeObject(builder.build(), buf);
672 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
675 parser.parseObject(new ObjectHeaderImpl(true, true), null);
677 } catch (final IllegalArgumentException e) {
678 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
681 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
683 } catch (final IllegalArgumentException e) {
684 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
689 public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
690 final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
691 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
693 final CNotificationBuilder builder = new CNotificationBuilder();
694 builder.setProcessingRule(true);
695 builder.setIgnore(true);
696 builder.setType((short) 0xff);
697 builder.setValue((short) 0xff);
699 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
700 ByteBuf buf = Unpooled.buffer();
701 parser.serializeObject(builder.build(), buf);
702 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
704 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
706 builder.setType((short) 2);
707 builder.setValue((short) 1);
708 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
709 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
711 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
712 buf = Unpooled.buffer();
713 parser.serializeObject(builder.build(), buf);
714 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
717 parser.parseObject(new ObjectHeaderImpl(true, true), null);
719 } catch (final IllegalArgumentException e) {
720 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
723 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
725 } catch (final IllegalArgumentException e) {
726 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
731 public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
732 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
733 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
735 final RpBuilder builder = new RpBuilder();
736 builder.setProcessingRule(true);
737 builder.setIgnore(true);
738 builder.setReoptimization(true);
739 builder.setBiDirectional(false);
740 builder.setLoose(true);
741 builder.setMakeBeforeBreak(true);
742 builder.setOrder(false);
743 builder.setPathKey(false);
744 builder.setSupplyOf(false);
745 builder.setFragmentation(false);
746 builder.setP2mp(false);
747 builder.setEroCompression(false);
748 builder.setPriority((short) 5);
749 builder.setRequestId(new RequestId(0xdeadbeefL));
750 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
752 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
753 ByteBuf buf = Unpooled.buffer();
754 parser.serializeObject(builder.build(), buf);
755 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
757 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
759 builder.setReoptimization(false);
760 builder.setFragmentation(true);
761 builder.setEroCompression(true);
763 final OrderBuilder b = new OrderBuilder();
764 b.setDelete(0xffffffffL);
767 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
770 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
771 buf = Unpooled.buffer();
772 parser.serializeObject(builder.build(), buf);
773 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
776 parser.parseObject(new ObjectHeaderImpl(true, true), null);
778 } catch (final IllegalArgumentException e) {
779 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
782 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
784 } catch (final IllegalArgumentException e) {
785 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
790 public void testSvecObject() throws IOException, PCEPDeserializerException {
791 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
792 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
794 final SvecBuilder builder = new SvecBuilder();
795 builder.setProcessingRule(false);
796 builder.setIgnore(false);
797 builder.setLinkDiverse(false);
798 builder.setNodeDiverse(false);
799 builder.setSrlgDiverse(false);
800 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
802 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
803 ByteBuf buf = Unpooled.buffer();
804 parser.serializeObject(builder.build(), buf);
805 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
807 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
809 builder.setProcessingRule(true);
810 builder.setLinkDiverse(true);
811 builder.setSrlgDiverse(true);
813 final List<RequestId> requestIDs = Lists.newArrayList();
814 requestIDs.add(new RequestId(0xFFFFFFFFL));
815 requestIDs.add(new RequestId(0x00000001L));
816 requestIDs.add(new RequestId(0x01234567L));
817 requestIDs.add(new RequestId(0x89ABCDEFL));
818 requestIDs.add(new RequestId(0xFEDCBA98L));
819 requestIDs.add(new RequestId(0x76543210L));
820 requestIDs.add(new RequestId(0x15825266L));
821 requestIDs.add(new RequestId(0x48120BBEL));
822 requestIDs.add(new RequestId(0x25FB7E52L));
823 requestIDs.add(new RequestId(0xB2F2546BL));
825 builder.setRequestsIds(requestIDs);
827 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
828 buf = Unpooled.buffer();
829 parser.serializeObject(builder.build(), buf);
830 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
833 parser.parseObject(new ObjectHeaderImpl(true, true), null);
835 } catch (final IllegalArgumentException e) {
836 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
839 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
841 } catch (final IllegalArgumentException e) {
842 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
847 public void testClassTypeObject() throws PCEPDeserializerException {
848 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
849 final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
851 final ClassTypeBuilder builder = new ClassTypeBuilder();
852 builder.setProcessingRule(true);
853 builder.setIgnore(false);
854 builder.setClassType(new ClassType((short) 4));
856 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
857 final ByteBuf buf = Unpooled.buffer();
858 parser.serializeObject(builder.build(), buf);
859 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
862 parser.parseObject(new ObjectHeaderImpl(true, true), null);
864 } catch (final IllegalArgumentException e) {
865 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
868 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
870 } catch (final IllegalArgumentException e) {
871 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
876 public void testExcludeRouteObject() throws Exception {
877 final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
878 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
880 final XroBuilder builder = new XroBuilder();
881 builder.setProcessingRule(false);
882 builder.setIgnore(false);
883 builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
884 final List<Subobject> subs = Lists.newArrayList();
885 subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
886 new IpPrefixCaseBuilder().setIpPrefix(
887 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
888 Attribute.Node).build());
889 subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
890 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
891 builder.setSubobject(subs);
893 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
894 final ByteBuf buf = Unpooled.buffer();
895 parser.serializeObject(builder.build(), buf);
896 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
899 parser.parseObject(new ObjectHeaderImpl(true, true), null);
901 } catch (final IllegalArgumentException e) {
902 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
905 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
907 } catch (final IllegalArgumentException e) {
908 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
913 public void testPathKeyObject() throws Exception {
914 final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
915 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
917 final PathKeyBuilder builder = new PathKeyBuilder();
918 builder.setProcessingRule(true);
919 builder.setIgnore(false);
920 final List<PathKeys> list = Lists.newArrayList();
921 list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
922 new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
923 builder.setPathKeys(list);
925 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
926 final ByteBuf buf = Unpooled.buffer();
927 parser.serializeObject(builder.build(), buf);
928 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
931 parser.parseObject(new ObjectHeaderImpl(true, true), null);
933 } catch (final IllegalArgumentException e) {
934 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
937 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
939 } catch (final IllegalArgumentException e) {
940 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
945 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
946 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
947 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
949 final OfBuilder builder = new OfBuilder();
950 builder.setProcessingRule(true);
951 builder.setIgnore(false);
952 builder.setCode(new OfId(4));
953 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
955 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
956 final ByteBuf buf = Unpooled.buffer();
957 parser.serializeObject(builder.build(), buf);
958 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
961 parser.parseObject(new ObjectHeaderImpl(true, true), null);
963 } catch (final IllegalArgumentException e) {
964 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
967 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
969 } catch (final IllegalArgumentException e) {
970 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
975 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
976 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
977 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
979 final GcBuilder builder = new GcBuilder();
980 builder.setProcessingRule(true);
981 builder.setIgnore(false);
982 builder.setMaxHop((short) 1);
983 builder.setMaxUtilization((short) 0);
984 builder.setMinUtilization((short) 100);
985 builder.setOverBookingFactor((short) 99);
986 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
988 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
989 final ByteBuf buf = Unpooled.buffer();
990 parser.serializeObject(builder.build(), buf);
991 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
994 parser.parseObject(new ObjectHeaderImpl(true, true), null);
996 } catch (final IllegalArgumentException e) {
997 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1000 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1002 } catch (final IllegalArgumentException e) {
1003 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1008 public void testIgnoreUknownObject() throws PCEPDeserializerException {
1009 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
1014 public void testUnrecognizedObjectType() throws PCEPDeserializerException {
1015 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
1016 assertNotNull(object);
1017 assertTrue(object instanceof UnknownObject);
1018 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
1022 public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1023 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1024 assertNotNull(object);
1025 assertTrue(object instanceof UnknownObject);
1026 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1030 public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
1031 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1032 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1034 final LspaBuilder builder = new LspaBuilder();
1035 builder.setProcessingRule(true);
1036 builder.setIgnore(true);
1037 builder.setLocalProtectionDesired(false);
1039 final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1040 parser.serializeObject(builder.build(), buf);
1041 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1045 public void testEmptyEroObject() throws PCEPDeserializerException {
1046 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1047 assertNotNull(object);
1048 assertTrue(object instanceof Ero);
1049 final Ero eroObject = (Ero) object;
1050 assertTrue(eroObject.getSubobject().isEmpty());
1052 final ByteBuf buffer = Unpooled.buffer();
1053 this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1054 final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1055 assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1059 public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
1060 final byte[] closeBytes = {
1061 0x0f, 0x10, 0x00, 0x14,
1062 0x00, 0x00, 0x00, 0x05,
1063 /* vendor-information TLV */
1064 0x00, 0x07, 0x00, 0x08,
1065 /* enterprise number */
1066 0x00, 0x00, 0x00, 0x00,
1067 /* enterprise specific information */
1068 0x00, 0x00, 0x00, 0x05
1070 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1071 final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1073 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1074 final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1075 .setEnterpriseSpecificInformation(esInfo).build();
1076 final CCloseBuilder builder = new CCloseBuilder();
1077 builder.setProcessingRule(false);
1078 builder.setIgnore(false);
1079 builder.setReason((short) 5);
1080 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
1081 .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1083 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1085 final ByteBuf buf = Unpooled.buffer();
1086 parser.serializeObject(builder.build(), buf);
1087 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1091 public void testVendorInformationObject() throws PCEPDeserializerException {
1092 final byte[] viObjBytes = {
1093 /* vendor-information object */
1094 0x22, 0x10, 0x00, 0x0C,
1095 /* enterprise number */
1096 0x00, 0x00, 0x00, 0x00,
1097 /* enterprise specific information */
1098 0x00, 0x00, 0x00, 0x05
1100 final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1101 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1102 final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1103 .setEnterpriseSpecificInformation(esInfo).build();
1104 final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1105 result.readerIndex(8);
1106 final VendorInformationObject o = (VendorInformationObject) parser.parseObject(new ObjectHeaderImpl(false, false), result.readSlice(result.readableBytes()));
1107 assertEquals(viObj, o);
1109 final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1110 parser.serializeObject(viObj, buf);
1111 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1115 public void testMonitoringObject() throws PCEPDeserializerException {
1116 final byte[] monitoringBytes = {
1118 0x13, 0x10, 0x00, 0x0C,
1120 0x00, 0x00, 0x00, 0x01,
1121 /* monitoring-id=16 */
1122 0x00, 0x00, 0x00, 0x10
1124 final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
1125 final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
1126 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
1127 final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
1128 assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1130 final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
1131 parser.serializeObject(monitoring, buf);
1132 assertArrayEquals(monitoringBytes, buf.array());
1136 public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
1137 final byte[] pccIdReqBytes = {
1139 0x14, 0x10, 0x00, 0x08,
1141 0x7f, 0x00, 0x00, 0x01
1143 final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
1144 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
1145 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1146 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1148 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1149 parser.serializeObject(pccIdReq, buf);
1150 assertArrayEquals(pccIdReqBytes, buf.array());
1154 public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
1155 final byte[] pccIdReqBytes = {
1157 0x14, 0x20, 0x00, 0x14,
1159 0x00, 0x00, 0x00, 0x00,
1160 0x00, 0x00, 0x00, 0x00,
1161 0x00, 0x00, 0x00, 0x00,
1162 0x00, 0x00, 0x00, 0x01
1164 final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
1165 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build();
1166 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1167 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1169 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1170 parser.serializeObject(pccIdReq, buf);
1171 assertArrayEquals(pccIdReqBytes, buf.array());
1175 public void testPceIdIPv4Object() throws PCEPDeserializerException {
1176 final byte[] pccIdReqBytes = {
1178 0x19, 0x10, 0x00, 0x08,
1180 0x7f, 0x00, 0x00, 0x01
1182 final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
1183 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pceId = new PceIdBuilder().setIpAddress(new IpAddress(
1184 new Ipv4Address("127.0.0.1"))).build();
1185 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1186 assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1188 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1189 parser.serializeObject(pceId, buf);
1190 assertArrayEquals(pccIdReqBytes, buf.array());
1194 public void testPceIdIPv6Object() throws PCEPDeserializerException {
1195 final byte[] pccIdReqBytes = {
1197 0x19, 0x20, 0x00, 0x14,
1199 0x00, 0x00, 0x00, 0x00,
1200 0x00, 0x00, 0x00, 0x00,
1201 0x00, 0x00, 0x00, 0x00,
1202 0x00, 0x00, 0x00, 0x01
1204 final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
1205 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddress(
1206 new Ipv6Address("::1"))).build();
1207 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1208 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1210 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1211 parser.serializeObject(pccIdReq, buf);
1212 assertArrayEquals(pccIdReqBytes, buf.array());
1216 public void testProcTimeObject() throws PCEPDeserializerException {
1217 final byte[] proctimeBytes = {
1219 0x1A, 0x10, 0x00, 0x1C,
1221 0x00, 0x00, 0x00, 0x01,
1222 /* current proc. time */
1223 0x00, 0x00, 0x00, 0x01,
1224 /* min proc. time */
1225 0x00, 0x00, 0x00, 0x02,
1227 0x00, 0x00, 0x00, 0x03,
1228 /* average proc time */
1229 0x00, 0x00, 0x00, 0x04,
1230 /* variance proc time */
1231 0x00, 0x00, 0x00, 0x05,
1233 final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
1234 final ProcTime procTime = new ProcTimeBuilder()
1236 .setAverageProcTime(4L)
1237 .setCurrentProcTime(1L)
1240 .setVarianceProcTime(5L).build();
1241 final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
1242 assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1244 final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
1245 parser.serializeObject(procTime, buf);
1246 assertArrayEquals(proctimeBytes, buf.array());
1250 public void testOverloadObject() throws PCEPDeserializerException {
1251 final byte[] overloadBytes = {
1253 0x1B, 0x10, 0x00, 0x08,
1254 /* overload duration */
1255 0x00, 0x00, 0x00, 0x78
1257 final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
1258 final Overload overload = new OverloadBuilder().setDuration(120).build();
1259 final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
1260 assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1262 final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
1263 parser.serializeObject(overload, buf);
1264 assertArrayEquals(overloadBytes, buf.array());
1268 public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
1270 final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
1271 (byte) 0xad, (byte) 0xbe, (byte) 0xef,
1273 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
1275 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
1276 final RpBuilder builder = new RpBuilder();
1277 builder.setProcessingRule(false);
1278 builder.setIgnore(false);
1279 builder.setReoptimization(true);
1280 builder.setBiDirectional(false);
1281 builder.setLoose(true);
1282 builder.setMakeBeforeBreak(true);
1283 builder.setOrder(false);
1284 builder.setPathKey(false);
1285 builder.setSupplyOf(false);
1286 builder.setFragmentation(false);
1287 builder.setP2mp(false);
1288 builder.setEroCompression(false);
1289 builder.setPriority((short) 5);
1290 builder.setRequestId(new RequestId(0xdeadbeefL));
1291 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setPathSetupType(
1292 new PathSetupTypeBuilder().setPst((short) 0).build()).build());
1294 final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
1295 assertEquals(builder.build(),
1296 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1297 final ByteBuf buf = Unpooled.buffer();
1298 parser.serializeObject(builder.build(), buf);
1299 assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));