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.parser.BaseParserExtensionActivator;
27 import org.opendaylight.protocol.pcep.parser.object.PCEPBandwidthObjectParser;
28 import org.opendaylight.protocol.pcep.parser.object.PCEPClassTypeObjectParser;
29 import org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser;
30 import org.opendaylight.protocol.pcep.parser.object.PCEPEndPointsIpv4ObjectParser;
31 import org.opendaylight.protocol.pcep.parser.object.PCEPEndPointsIpv6ObjectParser;
32 import org.opendaylight.protocol.pcep.parser.object.PCEPErrorObjectParser;
33 import org.opendaylight.protocol.pcep.parser.object.PCEPExcludeRouteObjectParser;
34 import org.opendaylight.protocol.pcep.parser.object.PCEPExistingBandwidthObjectParser;
35 import org.opendaylight.protocol.pcep.parser.object.PCEPExplicitRouteObjectParser;
36 import org.opendaylight.protocol.pcep.parser.object.PCEPGlobalConstraintsObjectParser;
37 import org.opendaylight.protocol.pcep.parser.object.PCEPIncludeRouteObjectParser;
38 import org.opendaylight.protocol.pcep.parser.object.PCEPLoadBalancingObjectParser;
39 import org.opendaylight.protocol.pcep.parser.object.PCEPLspaObjectParser;
40 import org.opendaylight.protocol.pcep.parser.object.PCEPMetricObjectParser;
41 import org.opendaylight.protocol.pcep.parser.object.PCEPMonitoringObjectParser;
42 import org.opendaylight.protocol.pcep.parser.object.PCEPNoPathObjectParser;
43 import org.opendaylight.protocol.pcep.parser.object.PCEPNotificationObjectParser;
44 import org.opendaylight.protocol.pcep.parser.object.PCEPObjectiveFunctionObjectParser;
45 import org.opendaylight.protocol.pcep.parser.object.PCEPOpenObjectParser;
46 import org.opendaylight.protocol.pcep.parser.object.PCEPOverloadObjectParser;
47 import org.opendaylight.protocol.pcep.parser.object.PCEPPathKeyObjectParser;
48 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv4ObjectParser;
49 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv6ObjectParser;
50 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv4ObjectParser;
51 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv6ObjectParser;
52 import org.opendaylight.protocol.pcep.parser.object.PCEPProcTimeObjectParser;
53 import org.opendaylight.protocol.pcep.parser.object.PCEPReportedRouteObjectParser;
54 import org.opendaylight.protocol.pcep.parser.object.PCEPRequestParameterObjectParser;
55 import org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser;
56 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
57 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
58 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
59 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
60 import org.opendaylight.protocol.pcep.spi.UnknownObject;
61 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
62 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
63 import org.opendaylight.protocol.util.ByteArray;
64 import org.opendaylight.protocol.util.Ipv4Util;
65 import org.opendaylight.protocol.util.Ipv6Util;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
68 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
69 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
71 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
117 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;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
139 public class PCEPObjectParserTest {
141 private TlvRegistry tlvRegistry;
143 private VendorInformationTlvRegistry viTlvRegistry;
145 private SimplePCEPExtensionProviderContext ctx;
146 private BaseParserExtensionActivator act;
147 private TestVendorInformationActivator viAct;
150 public void setUp() {
151 this.ctx = new SimplePCEPExtensionProviderContext();
152 this.act = new BaseParserExtensionActivator();
153 this.viAct = new TestVendorInformationActivator();
154 this.act.start(this.ctx);
155 this.viAct.start(this.ctx);
156 this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
157 this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
161 public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
162 final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
163 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
165 final OpenBuilder builder = new OpenBuilder();
166 builder.setProcessingRule(false);
167 builder.setIgnore(false);
168 builder.setVersion(new ProtocolVersion((short) 1));
169 builder.setKeepalive((short) 30);
170 builder.setDeadTimer((short) 120);
171 builder.setSessionId((short) 1);
173 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
175 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
176 final ByteBuf buf = Unpooled.buffer();
177 parser.serializeObject(builder.build(), buf);
178 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
181 parser.parseObject(new ObjectHeaderImpl(true, true), null);
183 } catch (final IllegalArgumentException e) {
184 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
187 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
189 } catch (final IllegalArgumentException e) {
190 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
195 public void testCloseObject() throws IOException, PCEPDeserializerException {
196 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
197 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
199 final CCloseBuilder builder = new CCloseBuilder();
200 builder.setProcessingRule(false);
201 builder.setIgnore(false);
202 builder.setReason((short) 5);
203 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
205 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
206 final ByteBuf buf = Unpooled.buffer();
207 parser.serializeObject(builder.build(), buf);
208 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
211 parser.parseObject(new ObjectHeaderImpl(true, true), null);
213 } catch (final IllegalArgumentException e) {
214 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
217 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
219 } catch (final IllegalArgumentException e) {
220 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
225 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
226 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
227 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
229 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
230 builder.setProcessingRule(true);
231 builder.setIgnore(false);
232 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
233 builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
235 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
236 final ByteBuf buf = Unpooled.buffer();
237 parser.serializeObject(builder.build(), buf);
238 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
241 parser.parseObject(new ObjectHeaderImpl(true, true), null);
243 } catch (final IllegalArgumentException e) {
244 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
247 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
249 } catch (final IllegalArgumentException e) {
250 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
255 public void testERObject() throws Exception {
256 final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
257 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
259 final EroBuilder builder = new EroBuilder();
260 builder.setProcessingRule(false);
261 builder.setIgnore(false);
262 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
263 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
264 true).setSubobjectType(
265 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
266 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
267 true).setSubobjectType(
268 new IpPrefixCaseBuilder().setIpPrefix(
269 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
270 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
271 true).setSubobjectType(
272 new UnnumberedCaseBuilder().setUnnumbered(
273 new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
274 builder.setSubobject(subs);
276 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
277 final ByteBuf buf = Unpooled.buffer();
278 parser.serializeObject(builder.build(), buf);
279 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
282 parser.parseObject(new ObjectHeaderImpl(true, true), null);
284 } catch (final IllegalArgumentException e) {
285 assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
290 public void testIRObject() throws Exception {
291 final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
292 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
293 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
294 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
296 final IroBuilder builder = new IroBuilder();
297 builder.setProcessingRule(false);
298 builder.setIgnore(false);
299 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists.newArrayList();
300 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
301 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).setLoose(true).build());
302 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
303 new IpPrefixCaseBuilder().setIpPrefix(
304 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).setLoose(true).build());
305 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
306 new IpPrefixCaseBuilder().setIpPrefix(
307 new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setLoose(true).build());
308 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
309 new UnnumberedCaseBuilder().setUnnumbered(
310 new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setLoose(true).build());
311 builder.setSubobject(subs);
313 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
314 final ByteBuf buf = Unpooled.buffer();
315 parser.serializeObject(builder.build(), buf);
316 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
319 parser.parseObject(new ObjectHeaderImpl(true, true), null);
321 } catch (final IllegalArgumentException e) {
322 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
325 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
327 } catch (final IllegalArgumentException e) {
328 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
333 public void testRRObject() throws Exception {
334 final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
335 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
336 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
337 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
339 final RroBuilder builder = new RroBuilder();
340 builder.setProcessingRule(false);
341 builder.setIgnore(false);
342 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
343 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
344 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
345 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
346 new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
348 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
349 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
350 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
351 new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
353 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
354 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
355 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
356 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
358 builder.setSubobject(subs);
360 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
361 final ByteBuf buf = Unpooled.buffer();
362 parser.serializeObject(builder.build(), buf);
363 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
366 parser.parseObject(new ObjectHeaderImpl(true, true), null);
368 } catch (final IllegalArgumentException e) {
369 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
372 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
374 } catch (final IllegalArgumentException e) {
375 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
380 public void testBandwidthObject() throws IOException, PCEPDeserializerException {
381 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
382 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
384 final BandwidthBuilder builder = new BandwidthBuilder();
385 builder.setProcessingRule(true);
386 builder.setIgnore(true);
387 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
389 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
390 final ByteBuf buf = Unpooled.buffer();
391 parser.serializeObject(builder.build(), buf);
392 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
395 parser.parseObject(new ObjectHeaderImpl(true, true), null);
397 } catch (final IllegalArgumentException e) {
398 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
401 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
403 } catch (final IllegalArgumentException e) {
404 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
409 public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
410 final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
411 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
413 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization
414 .bandwidth.object.ReoptimizationBandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
415 .ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
416 builder.setProcessingRule(true);
417 builder.setIgnore(true);
418 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
420 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
421 final ByteBuf buf = Unpooled.buffer();
422 parser.serializeObject(builder.build(), buf);
423 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
426 parser.parseObject(new ObjectHeaderImpl(true, true), null);
428 } catch (final IllegalArgumentException e) {
429 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
432 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
434 } catch (final IllegalArgumentException e) {
435 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
440 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
441 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
442 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
444 final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
445 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
447 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
448 builder.setProcessingRule(true);
449 builder.setIgnore(false);
450 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
451 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
452 Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
454 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
455 final ByteBuf buf = Unpooled.buffer();
456 parser.serializeObject(builder.build(), buf);
457 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
460 parser.parseObject(new ObjectHeaderImpl(true, true), null);
462 } catch (final IllegalArgumentException e) {
463 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
466 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
468 } catch (final IllegalArgumentException e) {
469 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
474 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
475 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
476 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
477 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
478 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
480 final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
481 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
483 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
484 builder.setProcessingRule(true);
485 builder.setIgnore(false);
486 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
487 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
488 Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
490 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
491 final ByteBuf buf = Unpooled.buffer();
492 PCEPEndPointsIpv6ObjectParser.serializeObject(builder.build(), buf);
493 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
496 parser.parseObject(new ObjectHeaderImpl(true, true), null);
498 } catch (final IllegalArgumentException e) {
499 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
502 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
504 } catch (final IllegalArgumentException e) {
505 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
510 public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
511 final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
512 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
514 final ErrorObjectBuilder builder = new ErrorObjectBuilder();
515 builder.setProcessingRule(true);
516 builder.setIgnore(true);
517 builder.setType((short) 1);
518 builder.setValue((short) 1);
520 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
521 ByteBuf buf = Unpooled.buffer();
522 parser.serializeObject(builder.build(), buf);
523 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
525 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
527 builder.setType((short) 7);
528 builder.setValue((short) 0);
529 builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
531 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
532 buf = Unpooled.buffer();
533 parser.serializeObject(builder.build(), buf);
534 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
537 parser.parseObject(new ObjectHeaderImpl(true, true), null);
539 } catch (final IllegalArgumentException e) {
540 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
543 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
545 } catch (final IllegalArgumentException e) {
546 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
551 public void testLspaObject() throws IOException, PCEPDeserializerException {
552 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
553 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
555 final LspaBuilder builder = new LspaBuilder();
556 builder.setProcessingRule(true);
557 builder.setIgnore(true);
558 builder.setExcludeAny(new AttributeFilter(0L));
559 builder.setIncludeAny(new AttributeFilter(0L));
560 builder.setIncludeAll(new AttributeFilter(0L));
561 builder.setHoldPriority((short) 0);
562 builder.setSetupPriority((short) 0);
563 builder.setLocalProtectionDesired(false);
564 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
566 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
567 ByteBuf buf = Unpooled.buffer();
568 parser.serializeObject(builder.build(), buf);
569 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
571 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
573 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
574 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
575 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
576 builder.setHoldPriority((short) 0xFF);
577 builder.setSetupPriority((short) 0xFF);
578 builder.setLocalProtectionDesired(true);
580 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
581 buf = Unpooled.buffer();
582 parser.serializeObject(builder.build(), buf);
583 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
586 parser.parseObject(new ObjectHeaderImpl(true, true), null);
588 } catch (final IllegalArgumentException e) {
589 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
592 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
594 } catch (final IllegalArgumentException e) {
595 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
600 public void testMetricObject() throws IOException, PCEPDeserializerException {
601 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
602 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
604 final MetricBuilder builder = new MetricBuilder();
605 builder.setProcessingRule(true);
606 builder.setIgnore(true);
607 builder.setComputed(false);
608 builder.setBound(false);
609 builder.setMetricType((short) 1);
610 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
612 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
613 ByteBuf buf = Unpooled.buffer();
614 parser.serializeObject(builder.build(), buf);
615 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
617 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
619 builder.setComputed(true);
620 builder.setBound(false);
621 builder.setMetricType((short) 2);
622 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
624 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
625 buf = Unpooled.buffer();
626 parser.serializeObject(builder.build(), buf);
627 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
630 parser.parseObject(new ObjectHeaderImpl(true, true), null);
632 } catch (final IllegalArgumentException e) {
633 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
636 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
638 } catch (final IllegalArgumentException e) {
639 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
644 public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
645 final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
646 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
648 final NoPathBuilder builder = new NoPathBuilder();
649 builder.setProcessingRule(true);
650 builder.setIgnore(true);
651 builder.setNatureOfIssue((short) 1);
652 builder.setUnsatisfiedConstraints(true);
653 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());
655 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
656 ByteBuf buf = Unpooled.buffer();
657 parser.serializeObject(builder.build(), buf);
658 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
660 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
662 builder.setNatureOfIssue((short) 0);
663 builder.setUnsatisfiedConstraints(false);
665 final NoPathVectorBuilder b = new NoPathVectorBuilder();
666 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));
667 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(
670 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
671 buf = Unpooled.buffer();
672 parser.serializeObject(builder.build(), buf);
673 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
676 parser.parseObject(new ObjectHeaderImpl(true, true), null);
678 } catch (final IllegalArgumentException e) {
679 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
682 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
684 } catch (final IllegalArgumentException e) {
685 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
690 public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
691 final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
692 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
694 final CNotificationBuilder builder = new CNotificationBuilder();
695 builder.setProcessingRule(true);
696 builder.setIgnore(true);
697 builder.setType((short) 0xff);
698 builder.setValue((short) 0xff);
700 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
701 ByteBuf buf = Unpooled.buffer();
702 parser.serializeObject(builder.build(), buf);
703 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
705 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
707 builder.setType((short) 2);
708 builder.setValue((short) 1);
709 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
710 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
712 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
713 buf = Unpooled.buffer();
714 parser.serializeObject(builder.build(), buf);
715 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
718 parser.parseObject(new ObjectHeaderImpl(true, true), null);
720 } catch (final IllegalArgumentException e) {
721 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
724 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
726 } catch (final IllegalArgumentException e) {
727 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
732 public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
733 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
734 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
736 final RpBuilder builder = new RpBuilder();
737 builder.setProcessingRule(true);
738 builder.setIgnore(true);
739 builder.setReoptimization(true);
740 builder.setBiDirectional(false);
741 builder.setLoose(true);
742 builder.setMakeBeforeBreak(true);
743 builder.setOrder(false);
744 builder.setPathKey(false);
745 builder.setSupplyOf(false);
746 builder.setFragmentation(false);
747 builder.setP2mp(false);
748 builder.setEroCompression(false);
749 builder.setPriority((short) 5);
750 builder.setRequestId(new RequestId(0xdeadbeefL));
751 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
753 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
754 ByteBuf buf = Unpooled.buffer();
755 parser.serializeObject(builder.build(), buf);
756 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
758 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
760 builder.setReoptimization(false);
761 builder.setFragmentation(true);
762 builder.setEroCompression(true);
764 final OrderBuilder b = new OrderBuilder();
765 b.setDelete(0xffffffffL);
768 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
771 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
772 buf = Unpooled.buffer();
773 parser.serializeObject(builder.build(), buf);
774 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
777 parser.parseObject(new ObjectHeaderImpl(true, true), null);
779 } catch (final IllegalArgumentException e) {
780 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
783 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
785 } catch (final IllegalArgumentException e) {
786 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
791 public void testSvecObject() throws IOException, PCEPDeserializerException {
792 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
793 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
795 final SvecBuilder builder = new SvecBuilder();
796 builder.setProcessingRule(false);
797 builder.setIgnore(false);
798 builder.setLinkDiverse(false);
799 builder.setNodeDiverse(false);
800 builder.setSrlgDiverse(false);
801 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
803 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
804 ByteBuf buf = Unpooled.buffer();
805 parser.serializeObject(builder.build(), buf);
806 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
808 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
810 builder.setProcessingRule(true);
811 builder.setLinkDiverse(true);
812 builder.setSrlgDiverse(true);
814 final List<RequestId> requestIDs = Lists.newArrayList();
815 requestIDs.add(new RequestId(0xFFFFFFFFL));
816 requestIDs.add(new RequestId(0x00000001L));
817 requestIDs.add(new RequestId(0x01234567L));
818 requestIDs.add(new RequestId(0x89ABCDEFL));
819 requestIDs.add(new RequestId(0xFEDCBA98L));
820 requestIDs.add(new RequestId(0x76543210L));
821 requestIDs.add(new RequestId(0x15825266L));
822 requestIDs.add(new RequestId(0x48120BBEL));
823 requestIDs.add(new RequestId(0x25FB7E52L));
824 requestIDs.add(new RequestId(0xB2F2546BL));
826 builder.setRequestsIds(requestIDs);
828 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
829 buf = Unpooled.buffer();
830 parser.serializeObject(builder.build(), buf);
831 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
834 parser.parseObject(new ObjectHeaderImpl(true, true), null);
836 } catch (final IllegalArgumentException e) {
837 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
840 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
842 } catch (final IllegalArgumentException e) {
843 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
848 public void testClassTypeObject() throws PCEPDeserializerException {
849 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
850 final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
852 final ClassTypeBuilder builder = new ClassTypeBuilder();
853 builder.setProcessingRule(true);
854 builder.setIgnore(false);
855 builder.setClassType(new ClassType((short) 4));
857 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
858 final ByteBuf buf = Unpooled.buffer();
859 parser.serializeObject(builder.build(), buf);
860 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
863 parser.parseObject(new ObjectHeaderImpl(true, true), null);
865 } catch (final IllegalArgumentException e) {
866 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
869 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
871 } catch (final IllegalArgumentException e) {
872 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
877 public void testExcludeRouteObject() throws Exception {
878 final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
879 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
881 final XroBuilder builder = new XroBuilder();
882 builder.setProcessingRule(false);
883 builder.setIgnore(false);
884 builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
885 final List<Subobject> subs = Lists.newArrayList();
886 subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
887 new IpPrefixCaseBuilder().setIpPrefix(
888 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
889 Attribute.Node).build());
890 subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
891 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
892 builder.setSubobject(subs);
894 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
895 final ByteBuf buf = Unpooled.buffer();
896 parser.serializeObject(builder.build(), buf);
897 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
900 parser.parseObject(new ObjectHeaderImpl(true, true), null);
902 } catch (final IllegalArgumentException e) {
903 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
906 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
908 } catch (final IllegalArgumentException e) {
909 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
914 public void testPathKeyObject() throws Exception {
915 final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
916 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
918 final PathKeyBuilder builder = new PathKeyBuilder();
919 builder.setProcessingRule(true);
920 builder.setIgnore(false);
921 final List<PathKeys> list = Lists.newArrayList();
922 list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
923 new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
924 builder.setPathKeys(list);
926 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
927 final ByteBuf buf = Unpooled.buffer();
928 parser.serializeObject(builder.build(), buf);
929 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
932 parser.parseObject(new ObjectHeaderImpl(true, true), null);
934 } catch (final IllegalArgumentException e) {
935 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
938 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
940 } catch (final IllegalArgumentException e) {
941 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
946 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
947 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
948 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
950 final OfBuilder builder = new OfBuilder();
951 builder.setProcessingRule(true);
952 builder.setIgnore(false);
953 builder.setCode(new OfId(4));
954 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
956 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
957 final ByteBuf buf = Unpooled.buffer();
958 parser.serializeObject(builder.build(), buf);
959 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
962 parser.parseObject(new ObjectHeaderImpl(true, true), null);
964 } catch (final IllegalArgumentException e) {
965 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
968 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
970 } catch (final IllegalArgumentException e) {
971 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
976 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
977 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
978 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
980 final GcBuilder builder = new GcBuilder();
981 builder.setProcessingRule(true);
982 builder.setIgnore(false);
983 builder.setMaxHop((short) 1);
984 builder.setMaxUtilization((short) 0);
985 builder.setMinUtilization((short) 100);
986 builder.setOverBookingFactor((short) 99);
987 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
989 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
990 final ByteBuf buf = Unpooled.buffer();
991 parser.serializeObject(builder.build(), buf);
992 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
995 parser.parseObject(new ObjectHeaderImpl(true, true), null);
997 } catch (final IllegalArgumentException e) {
998 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1001 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1003 } catch (final IllegalArgumentException e) {
1004 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1009 public void testIgnoreUknownObject() throws PCEPDeserializerException {
1010 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
1015 public void testUnrecognizedObjectType() throws PCEPDeserializerException {
1016 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
1017 assertNotNull(object);
1018 assertTrue(object instanceof UnknownObject);
1019 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
1023 public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1024 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1025 assertNotNull(object);
1026 assertTrue(object instanceof UnknownObject);
1027 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1031 public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
1032 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1033 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1035 final LspaBuilder builder = new LspaBuilder();
1036 builder.setProcessingRule(true);
1037 builder.setIgnore(true);
1038 builder.setLocalProtectionDesired(false);
1040 final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1041 parser.serializeObject(builder.build(), buf);
1042 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1046 public void testEmptyEroObject() throws PCEPDeserializerException {
1047 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1048 assertNotNull(object);
1049 assertTrue(object instanceof Ero);
1050 final Ero eroObject = (Ero) object;
1051 assertTrue(eroObject.getSubobject().isEmpty());
1053 final ByteBuf buffer = Unpooled.buffer();
1054 this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1055 final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1056 assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1060 public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
1061 final byte[] closeBytes = {
1062 0x0f, 0x10, 0x00, 0x14,
1063 0x00, 0x00, 0x00, 0x05,
1064 /* vendor-information TLV */
1065 0x00, 0x07, 0x00, 0x08,
1066 /* enterprise number */
1067 0x00, 0x00, 0x00, 0x00,
1068 /* enterprise specific information */
1069 0x00, 0x00, 0x00, 0x05
1071 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1072 final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1074 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1075 final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1076 .setEnterpriseSpecificInformation(esInfo).build();
1077 final CCloseBuilder builder = new CCloseBuilder();
1078 builder.setProcessingRule(false);
1079 builder.setIgnore(false);
1080 builder.setReason((short) 5);
1081 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
1082 .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1084 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1086 final ByteBuf buf = Unpooled.buffer();
1087 parser.serializeObject(builder.build(), buf);
1088 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1092 public void testVendorInformationObject() throws PCEPDeserializerException {
1093 final byte[] viObjBytes = {
1094 /* vendor-information object */
1095 0x22, 0x10, 0x00, 0x0C,
1096 /* enterprise number */
1097 0x00, 0x00, 0x00, 0x00,
1098 /* enterprise specific information */
1099 0x00, 0x00, 0x00, 0x05
1101 final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1102 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1103 final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1104 .setEnterpriseSpecificInformation(esInfo).build();
1105 final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1106 result.readerIndex(8);
1107 final VendorInformationObject o = (VendorInformationObject) parser.parseObject(new ObjectHeaderImpl(false, false), result.readSlice(result.readableBytes()));
1108 assertEquals(viObj, o);
1110 final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1111 parser.serializeObject(viObj, buf);
1112 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1116 public void testMonitoringObject() throws PCEPDeserializerException {
1117 final byte[] monitoringBytes = {
1119 0x13, 0x10, 0x00, 0x0C,
1121 0x00, 0x00, 0x00, 0x01,
1122 /* monitoring-id=16 */
1123 0x00, 0x00, 0x00, 0x10
1125 final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
1126 final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
1127 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
1128 final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
1129 assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1131 final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
1132 parser.serializeObject(monitoring, buf);
1133 assertArrayEquals(monitoringBytes, buf.array());
1137 public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
1138 final byte[] pccIdReqBytes = {
1140 0x14, 0x10, 0x00, 0x08,
1142 0x7f, 0x00, 0x00, 0x01
1144 final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
1145 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
1146 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1147 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1149 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1150 parser.serializeObject(pccIdReq, buf);
1151 assertArrayEquals(pccIdReqBytes, buf.array());
1155 public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
1156 final byte[] pccIdReqBytes = {
1158 0x14, 0x20, 0x00, 0x14,
1160 0x00, 0x00, 0x00, 0x00,
1161 0x00, 0x00, 0x00, 0x00,
1162 0x00, 0x00, 0x00, 0x00,
1163 0x00, 0x00, 0x00, 0x01
1165 final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
1166 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build();
1167 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1168 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1170 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1171 parser.serializeObject(pccIdReq, buf);
1172 assertArrayEquals(pccIdReqBytes, buf.array());
1176 public void testPceIdIPv4Object() throws PCEPDeserializerException {
1177 final byte[] pccIdReqBytes = {
1179 0x19, 0x10, 0x00, 0x08,
1181 0x7f, 0x00, 0x00, 0x01
1183 final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
1184 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(
1185 new Ipv4Address("127.0.0.1"))).build();
1186 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1187 assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1189 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1190 parser.serializeObject(pceId, buf);
1191 assertArrayEquals(pccIdReqBytes, buf.array());
1195 public void testPceIdIPv6Object() throws PCEPDeserializerException {
1196 final byte[] pccIdReqBytes = {
1198 0x19, 0x20, 0x00, 0x14,
1200 0x00, 0x00, 0x00, 0x00,
1201 0x00, 0x00, 0x00, 0x00,
1202 0x00, 0x00, 0x00, 0x00,
1203 0x00, 0x00, 0x00, 0x01
1205 final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
1206 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(
1207 new Ipv6Address("::1"))).build();
1208 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1209 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1211 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1212 parser.serializeObject(pccIdReq, buf);
1213 assertArrayEquals(pccIdReqBytes, buf.array());
1217 public void testProcTimeObject() throws PCEPDeserializerException {
1218 final byte[] proctimeBytes = {
1220 0x1A, 0x10, 0x00, 0x1C,
1222 0x00, 0x00, 0x00, 0x01,
1223 /* current proc. time */
1224 0x00, 0x00, 0x00, 0x01,
1225 /* min proc. time */
1226 0x00, 0x00, 0x00, 0x02,
1228 0x00, 0x00, 0x00, 0x03,
1229 /* average proc time */
1230 0x00, 0x00, 0x00, 0x04,
1231 /* variance proc time */
1232 0x00, 0x00, 0x00, 0x05,
1234 final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
1235 final ProcTime procTime = new ProcTimeBuilder()
1237 .setAverageProcTime(4L)
1238 .setCurrentProcTime(1L)
1241 .setVarianceProcTime(5L).build();
1242 final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
1243 assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1245 final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
1246 parser.serializeObject(procTime, buf);
1247 assertArrayEquals(proctimeBytes, buf.array());
1251 public void testOverloadObject() throws PCEPDeserializerException {
1252 final byte[] overloadBytes = {
1254 0x1B, 0x10, 0x00, 0x08,
1255 /* overload duration */
1256 0x00, 0x00, 0x00, 0x78
1258 final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
1259 final Overload overload = new OverloadBuilder().setDuration(120).build();
1260 final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
1261 assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1263 final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
1264 parser.serializeObject(overload, buf);
1265 assertArrayEquals(overloadBytes, buf.array());
1269 public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
1271 final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
1272 (byte) 0xad, (byte) 0xbe, (byte) 0xef,
1274 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
1276 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
1277 final RpBuilder builder = new RpBuilder();
1278 builder.setProcessingRule(false);
1279 builder.setIgnore(false);
1280 builder.setReoptimization(true);
1281 builder.setBiDirectional(false);
1282 builder.setLoose(true);
1283 builder.setMakeBeforeBreak(true);
1284 builder.setOrder(false);
1285 builder.setPathKey(false);
1286 builder.setSupplyOf(false);
1287 builder.setFragmentation(false);
1288 builder.setP2mp(false);
1289 builder.setEroCompression(false);
1290 builder.setPriority((short) 5);
1291 builder.setRequestId(new RequestId(0xdeadbeefL));
1292 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setPathSetupType(
1293 new PathSetupTypeBuilder().setPst((short) 0).build()).build());
1295 final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
1296 assertEquals(builder.build(),
1297 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1298 final ByteBuf buf = Unpooled.buffer();
1299 parser.serializeObject(builder.build(), buf);
1300 assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));