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.PathKey;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.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.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
344 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.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.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
349 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.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.rev130820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
354 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.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 BandwidthBuilder builder = new BandwidthBuilder();
413 builder.setProcessingRule(true);
414 builder.setIgnore(true);
415 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
417 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
418 final ByteBuf buf = Unpooled.buffer();
419 parser.serializeObject(builder.build(), buf);
420 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
423 parser.parseObject(new ObjectHeaderImpl(true, true), null);
425 } catch (final IllegalArgumentException e) {
426 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
429 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
431 } catch (final IllegalArgumentException e) {
432 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
437 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
438 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
439 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
441 final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
442 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
444 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
445 builder.setProcessingRule(true);
446 builder.setIgnore(false);
447 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
448 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
449 Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
451 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
452 final ByteBuf buf = Unpooled.buffer();
453 parser.serializeObject(builder.build(), buf);
454 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
457 parser.parseObject(new ObjectHeaderImpl(true, true), null);
459 } catch (final IllegalArgumentException e) {
460 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
463 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
465 } catch (final IllegalArgumentException e) {
466 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
471 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
472 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
473 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
474 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
475 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
477 final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
478 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
480 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
481 builder.setProcessingRule(true);
482 builder.setIgnore(false);
483 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
484 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
485 Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
487 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
488 final ByteBuf buf = Unpooled.buffer();
489 parser.serializeObject(builder.build(), buf);
490 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
493 parser.parseObject(new ObjectHeaderImpl(true, true), null);
495 } catch (final IllegalArgumentException e) {
496 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
499 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
501 } catch (final IllegalArgumentException e) {
502 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
507 public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
508 final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
509 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
511 final ErrorObjectBuilder builder = new ErrorObjectBuilder();
512 builder.setProcessingRule(true);
513 builder.setIgnore(true);
514 builder.setType((short) 1);
515 builder.setValue((short) 1);
517 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
518 ByteBuf buf = Unpooled.buffer();
519 parser.serializeObject(builder.build(), buf);
520 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
522 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
524 builder.setType((short) 7);
525 builder.setValue((short) 0);
526 builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
528 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
529 buf = Unpooled.buffer();
530 parser.serializeObject(builder.build(), buf);
531 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
534 parser.parseObject(new ObjectHeaderImpl(true, true), null);
536 } catch (final IllegalArgumentException e) {
537 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
540 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
542 } catch (final IllegalArgumentException e) {
543 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
548 public void testLspaObject() throws IOException, PCEPDeserializerException {
549 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
550 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
552 final LspaBuilder builder = new LspaBuilder();
553 builder.setProcessingRule(true);
554 builder.setIgnore(true);
555 builder.setExcludeAny(new AttributeFilter(0L));
556 builder.setIncludeAny(new AttributeFilter(0L));
557 builder.setIncludeAll(new AttributeFilter(0L));
558 builder.setHoldPriority((short) 0);
559 builder.setSetupPriority((short) 0);
560 builder.setLocalProtectionDesired(false);
561 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
563 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
564 ByteBuf buf = Unpooled.buffer();
565 parser.serializeObject(builder.build(), buf);
566 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
568 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
570 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
571 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
572 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
573 builder.setHoldPriority((short) 0xFF);
574 builder.setSetupPriority((short) 0xFF);
575 builder.setLocalProtectionDesired(true);
577 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
578 buf = Unpooled.buffer();
579 parser.serializeObject(builder.build(), buf);
580 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
583 parser.parseObject(new ObjectHeaderImpl(true, true), null);
585 } catch (final IllegalArgumentException e) {
586 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
589 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
591 } catch (final IllegalArgumentException e) {
592 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
597 public void testMetricObject() throws IOException, PCEPDeserializerException {
598 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
599 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
601 final MetricBuilder builder = new MetricBuilder();
602 builder.setProcessingRule(true);
603 builder.setIgnore(true);
604 builder.setComputed(false);
605 builder.setBound(false);
606 builder.setMetricType((short) 1);
607 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
609 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
610 ByteBuf buf = Unpooled.buffer();
611 parser.serializeObject(builder.build(), buf);
612 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
614 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
616 builder.setComputed(true);
617 builder.setBound(false);
618 builder.setMetricType((short) 2);
619 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
621 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
622 buf = Unpooled.buffer();
623 parser.serializeObject(builder.build(), buf);
624 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
627 parser.parseObject(new ObjectHeaderImpl(true, true), null);
629 } catch (final IllegalArgumentException e) {
630 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
633 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
635 } catch (final IllegalArgumentException e) {
636 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
641 public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
642 final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
643 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
645 final NoPathBuilder builder = new NoPathBuilder();
646 builder.setProcessingRule(true);
647 builder.setIgnore(true);
648 builder.setNatureOfIssue((short) 1);
649 builder.setUnsatisfiedConstraints(true);
650 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().build());
652 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
653 ByteBuf buf = Unpooled.buffer();
654 parser.serializeObject(builder.build(), buf);
655 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
657 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
659 builder.setNatureOfIssue((short) 0);
660 builder.setUnsatisfiedConstraints(false);
662 final NoPathVectorBuilder b = new NoPathVectorBuilder();
663 b.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true));
664 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().setNoPathVector(
667 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
668 buf = Unpooled.buffer();
669 parser.serializeObject(builder.build(), buf);
670 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
673 parser.parseObject(new ObjectHeaderImpl(true, true), null);
675 } catch (final IllegalArgumentException e) {
676 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
679 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
681 } catch (final IllegalArgumentException e) {
682 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
687 public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
688 final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
689 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
691 final CNotificationBuilder builder = new CNotificationBuilder();
692 builder.setProcessingRule(true);
693 builder.setIgnore(true);
694 builder.setType((short) 0xff);
695 builder.setValue((short) 0xff);
697 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
698 ByteBuf buf = Unpooled.buffer();
699 parser.serializeObject(builder.build(), buf);
700 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
702 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
704 builder.setType((short) 2);
705 builder.setValue((short) 1);
706 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
707 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
709 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
710 buf = Unpooled.buffer();
711 parser.serializeObject(builder.build(), buf);
712 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
715 parser.parseObject(new ObjectHeaderImpl(true, true), null);
717 } catch (final IllegalArgumentException e) {
718 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
721 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
723 } catch (final IllegalArgumentException e) {
724 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
729 public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
730 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
731 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
733 final RpBuilder builder = new RpBuilder();
734 builder.setProcessingRule(true);
735 builder.setIgnore(true);
736 builder.setReoptimization(true);
737 builder.setBiDirectional(false);
738 builder.setLoose(true);
739 builder.setMakeBeforeBreak(true);
740 builder.setOrder(false);
741 builder.setPathKey(false);
742 builder.setSupplyOf(false);
743 builder.setFragmentation(false);
744 builder.setP2mp(false);
745 builder.setEroCompression(false);
746 builder.setPriority((short) 5);
747 builder.setRequestId(new RequestId(0xdeadbeefL));
748 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
750 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
751 ByteBuf buf = Unpooled.buffer();
752 parser.serializeObject(builder.build(), buf);
753 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
755 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
757 builder.setReoptimization(false);
758 builder.setFragmentation(true);
759 builder.setEroCompression(true);
761 final OrderBuilder b = new OrderBuilder();
762 b.setDelete(0xffffffffL);
765 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
768 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
769 buf = Unpooled.buffer();
770 parser.serializeObject(builder.build(), buf);
771 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
774 parser.parseObject(new ObjectHeaderImpl(true, true), null);
776 } catch (final IllegalArgumentException e) {
777 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
780 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
782 } catch (final IllegalArgumentException e) {
783 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
788 public void testSvecObject() throws IOException, PCEPDeserializerException {
789 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
790 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
792 final SvecBuilder builder = new SvecBuilder();
793 builder.setProcessingRule(false);
794 builder.setIgnore(false);
795 builder.setLinkDiverse(false);
796 builder.setNodeDiverse(false);
797 builder.setSrlgDiverse(false);
798 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
800 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
801 ByteBuf buf = Unpooled.buffer();
802 parser.serializeObject(builder.build(), buf);
803 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
805 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
807 builder.setProcessingRule(true);
808 builder.setLinkDiverse(true);
809 builder.setSrlgDiverse(true);
811 final List<RequestId> requestIDs = Lists.newArrayList();
812 requestIDs.add(new RequestId(0xFFFFFFFFL));
813 requestIDs.add(new RequestId(0x00000001L));
814 requestIDs.add(new RequestId(0x01234567L));
815 requestIDs.add(new RequestId(0x89ABCDEFL));
816 requestIDs.add(new RequestId(0xFEDCBA98L));
817 requestIDs.add(new RequestId(0x76543210L));
818 requestIDs.add(new RequestId(0x15825266L));
819 requestIDs.add(new RequestId(0x48120BBEL));
820 requestIDs.add(new RequestId(0x25FB7E52L));
821 requestIDs.add(new RequestId(0xB2F2546BL));
823 builder.setRequestsIds(requestIDs);
825 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
826 buf = Unpooled.buffer();
827 parser.serializeObject(builder.build(), buf);
828 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
831 parser.parseObject(new ObjectHeaderImpl(true, true), null);
833 } catch (final IllegalArgumentException e) {
834 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
837 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
839 } catch (final IllegalArgumentException e) {
840 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
845 public void testClassTypeObject() throws PCEPDeserializerException {
846 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
847 final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
849 final ClassTypeBuilder builder = new ClassTypeBuilder();
850 builder.setProcessingRule(true);
851 builder.setIgnore(false);
852 builder.setClassType(new ClassType((short) 4));
854 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
855 final ByteBuf buf = Unpooled.buffer();
856 parser.serializeObject(builder.build(), buf);
857 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
860 parser.parseObject(new ObjectHeaderImpl(true, true), null);
862 } catch (final IllegalArgumentException e) {
863 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
866 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
868 } catch (final IllegalArgumentException e) {
869 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
874 public void testExcludeRouteObject() throws Exception {
875 final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
876 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
878 final XroBuilder builder = new XroBuilder();
879 builder.setProcessingRule(false);
880 builder.setIgnore(false);
881 builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
882 final List<Subobject> subs = Lists.newArrayList();
883 subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
884 new IpPrefixCaseBuilder().setIpPrefix(
885 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
886 Attribute.Node).build());
887 subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
888 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
889 builder.setSubobject(subs);
891 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
892 final ByteBuf buf = Unpooled.buffer();
893 parser.serializeObject(builder.build(), buf);
894 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
897 parser.parseObject(new ObjectHeaderImpl(true, true), null);
899 } catch (final IllegalArgumentException e) {
900 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
903 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
905 } catch (final IllegalArgumentException e) {
906 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
911 public void testPathKeyObject() throws Exception {
912 final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
913 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
915 final PathKeyBuilder builder = new PathKeyBuilder();
916 builder.setProcessingRule(true);
917 builder.setIgnore(false);
918 final List<PathKeys> list = Lists.newArrayList();
919 list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
920 new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
921 builder.setPathKeys(list);
923 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
924 final ByteBuf buf = Unpooled.buffer();
925 parser.serializeObject(builder.build(), buf);
926 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
929 parser.parseObject(new ObjectHeaderImpl(true, true), null);
931 } catch (final IllegalArgumentException e) {
932 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
935 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
937 } catch (final IllegalArgumentException e) {
938 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
943 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
944 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
945 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
947 final OfBuilder builder = new OfBuilder();
948 builder.setProcessingRule(true);
949 builder.setIgnore(false);
950 builder.setCode(new OfId(4));
951 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
953 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
954 final ByteBuf buf = Unpooled.buffer();
955 parser.serializeObject(builder.build(), buf);
956 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
959 parser.parseObject(new ObjectHeaderImpl(true, true), null);
961 } catch (final IllegalArgumentException e) {
962 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
965 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
967 } catch (final IllegalArgumentException e) {
968 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
973 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
974 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
975 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
977 final GcBuilder builder = new GcBuilder();
978 builder.setProcessingRule(true);
979 builder.setIgnore(false);
980 builder.setMaxHop((short) 1);
981 builder.setMaxUtilization((short) 0);
982 builder.setMinUtilization((short) 100);
983 builder.setOverBookingFactor((short) 99);
984 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
986 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
987 final ByteBuf buf = Unpooled.buffer();
988 parser.serializeObject(builder.build(), buf);
989 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
992 parser.parseObject(new ObjectHeaderImpl(true, true), null);
994 } catch (final IllegalArgumentException e) {
995 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
998 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1000 } catch (final IllegalArgumentException e) {
1001 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1006 public void testIgnoreUknownObject() throws PCEPDeserializerException {
1007 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
1012 public void testUnrecognizedObjectType() throws PCEPDeserializerException {
1013 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
1014 assertNotNull(object);
1015 assertTrue(object instanceof UnknownObject);
1016 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
1020 public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1021 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1022 assertNotNull(object);
1023 assertTrue(object instanceof UnknownObject);
1024 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1028 public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
1029 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1030 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1032 final LspaBuilder builder = new LspaBuilder();
1033 builder.setProcessingRule(true);
1034 builder.setIgnore(true);
1035 builder.setLocalProtectionDesired(false);
1037 final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1038 parser.serializeObject(builder.build(), buf);
1039 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1043 public void testEmptyEroObject() throws PCEPDeserializerException {
1044 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1045 assertNotNull(object);
1046 assertTrue(object instanceof Ero);
1047 final Ero eroObject = (Ero) object;
1048 assertTrue(eroObject.getSubobject().isEmpty());
1050 final ByteBuf buffer = Unpooled.buffer();
1051 this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1052 final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1053 assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1057 public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
1058 final byte[] closeBytes = {
1059 0x0f, 0x10, 0x00, 0x14,
1060 0x00, 0x00, 0x00, 0x05,
1061 /* vendor-information TLV */
1062 0x00, 0x07, 0x00, 0x08,
1063 /* enterprise number */
1064 0x00, 0x00, 0x00, 0x00,
1065 /* enterprise specific information */
1066 0x00, 0x00, 0x00, 0x05
1068 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1069 final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1071 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1072 final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1073 .setEnterpriseSpecificInformation(esInfo).build();
1074 final CCloseBuilder builder = new CCloseBuilder();
1075 builder.setProcessingRule(false);
1076 builder.setIgnore(false);
1077 builder.setReason((short) 5);
1078 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
1079 .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1081 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1083 final ByteBuf buf = Unpooled.buffer();
1084 parser.serializeObject(builder.build(), buf);
1085 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1089 public void testVendorInformationObject() throws PCEPDeserializerException {
1090 final byte[] viObjBytes = {
1091 /* vendor-information object */
1092 0x22, 0x10, 0x00, 0x0C,
1093 /* enterprise number */
1094 0x00, 0x00, 0x00, 0x00,
1095 /* enterprise specific information */
1096 0x00, 0x00, 0x00, 0x05
1098 final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1099 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1100 final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1101 .setEnterpriseSpecificInformation(esInfo).build();
1102 final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1104 assertEquals(viObj, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1106 final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1107 parser.serializeObject(viObj, buf);
1108 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1112 public void testMonitoringObject() throws PCEPDeserializerException {
1113 final byte[] monitoringBytes = {
1115 0x13, 0x10, 0x00, 0x0C,
1117 0x00, 0x00, 0x00, 0x01,
1118 /* monitoring-id=16 */
1119 0x00, 0x00, 0x00, 0x10
1121 final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
1122 final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
1123 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
1124 final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
1125 assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1127 final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
1128 parser.serializeObject(monitoring, buf);
1129 assertArrayEquals(monitoringBytes, buf.array());
1133 public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
1134 final byte[] pccIdReqBytes = {
1136 0x14, 0x10, 0x00, 0x08,
1138 0x7f, 0x00, 0x00, 0x01
1140 final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
1141 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
1142 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1143 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1145 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1146 parser.serializeObject(pccIdReq, buf);
1147 assertArrayEquals(pccIdReqBytes, buf.array());
1151 public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
1152 final byte[] pccIdReqBytes = {
1154 0x14, 0x20, 0x00, 0x14,
1156 0x00, 0x00, 0x00, 0x00,
1157 0x00, 0x00, 0x00, 0x00,
1158 0x00, 0x00, 0x00, 0x00,
1159 0x00, 0x00, 0x00, 0x01
1161 final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
1162 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build();
1163 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1164 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1166 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1167 parser.serializeObject(pccIdReq, buf);
1168 assertArrayEquals(pccIdReqBytes, buf.array());
1172 public void testPceIdIPv4Object() throws PCEPDeserializerException {
1173 final byte[] pccIdReqBytes = {
1175 0x19, 0x10, 0x00, 0x08,
1177 0x7f, 0x00, 0x00, 0x01
1179 final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
1180 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(
1181 new Ipv4Address("127.0.0.1"))).build();
1182 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1183 assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1185 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1186 parser.serializeObject(pceId, buf);
1187 assertArrayEquals(pccIdReqBytes, buf.array());
1191 public void testPceIdIPv6Object() throws PCEPDeserializerException {
1192 final byte[] pccIdReqBytes = {
1194 0x19, 0x20, 0x00, 0x14,
1196 0x00, 0x00, 0x00, 0x00,
1197 0x00, 0x00, 0x00, 0x00,
1198 0x00, 0x00, 0x00, 0x00,
1199 0x00, 0x00, 0x00, 0x01
1201 final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
1202 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(
1203 new Ipv6Address("::1"))).build();
1204 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1205 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1207 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1208 parser.serializeObject(pccIdReq, buf);
1209 assertArrayEquals(pccIdReqBytes, buf.array());
1213 public void testProcTimeObject() throws PCEPDeserializerException {
1214 final byte[] proctimeBytes = {
1216 0x1A, 0x10, 0x00, 0x1C,
1218 0x00, 0x00, 0x00, 0x01,
1219 /* current proc. time */
1220 0x00, 0x00, 0x00, 0x01,
1221 /* min proc. time */
1222 0x00, 0x00, 0x00, 0x02,
1224 0x00, 0x00, 0x00, 0x03,
1225 /* average proc time */
1226 0x00, 0x00, 0x00, 0x04,
1227 /* variance proc time */
1228 0x00, 0x00, 0x00, 0x05,
1230 final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
1231 final ProcTime procTime = new ProcTimeBuilder()
1233 .setAverageProcTime(4L)
1234 .setCurrentProcTime(1L)
1237 .setVarianceProcTime(5L).build();
1238 final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
1239 assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1241 final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
1242 parser.serializeObject(procTime, buf);
1243 assertArrayEquals(proctimeBytes, buf.array());
1247 public void testOverloadObject() throws PCEPDeserializerException {
1248 final byte[] overloadBytes = {
1250 0x1B, 0x10, 0x00, 0x08,
1251 /* overload duration */
1252 0x00, 0x00, 0x00, 0x78
1254 final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
1255 final Overload overload = new OverloadBuilder().setDuration(120).build();
1256 final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
1257 assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1259 final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
1260 parser.serializeObject(overload, buf);
1261 assertArrayEquals(overloadBytes, buf.array());
1265 public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
1267 final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
1268 (byte) 0xad, (byte) 0xbe, (byte) 0xef,
1270 0x0, 0x1b, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
1272 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
1273 final RpBuilder builder = new RpBuilder();
1274 builder.setProcessingRule(false);
1275 builder.setIgnore(false);
1276 builder.setReoptimization(true);
1277 builder.setBiDirectional(false);
1278 builder.setLoose(true);
1279 builder.setMakeBeforeBreak(true);
1280 builder.setOrder(false);
1281 builder.setPathKey(false);
1282 builder.setSupplyOf(false);
1283 builder.setFragmentation(false);
1284 builder.setP2mp(false);
1285 builder.setEroCompression(false);
1286 builder.setPriority((short) 5);
1287 builder.setRequestId(new RequestId(0xdeadbeefL));
1288 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setPathSetupType(
1289 new PathSetupTypeBuilder().setPst((short) 0).build()).build());
1291 final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
1292 assertEquals(builder.build(),
1293 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1294 final ByteBuf buf = Unpooled.buffer();
1295 parser.serializeObject(builder.build(), buf);
1296 assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));