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.Arrays;
23 import java.util.List;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
27 import org.opendaylight.protocol.pcep.parser.BaseParserExtensionActivator;
28 import org.opendaylight.protocol.pcep.parser.object.PCEPBandwidthObjectParser;
29 import org.opendaylight.protocol.pcep.parser.object.PCEPClassTypeObjectParser;
30 import org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser;
31 import org.opendaylight.protocol.pcep.parser.object.PCEPErrorObjectParser;
32 import org.opendaylight.protocol.pcep.parser.object.PCEPExcludeRouteObjectParser;
33 import org.opendaylight.protocol.pcep.parser.object.PCEPExistingBandwidthObjectParser;
34 import org.opendaylight.protocol.pcep.parser.object.PCEPExplicitRouteObjectParser;
35 import org.opendaylight.protocol.pcep.parser.object.PCEPGlobalConstraintsObjectParser;
36 import org.opendaylight.protocol.pcep.parser.object.PCEPIncludeRouteObjectParser;
37 import org.opendaylight.protocol.pcep.parser.object.PCEPLoadBalancingObjectParser;
38 import org.opendaylight.protocol.pcep.parser.object.PCEPLspaObjectParser;
39 import org.opendaylight.protocol.pcep.parser.object.PCEPMetricObjectParser;
40 import org.opendaylight.protocol.pcep.parser.object.PCEPMonitoringObjectParser;
41 import org.opendaylight.protocol.pcep.parser.object.PCEPNoPathObjectParser;
42 import org.opendaylight.protocol.pcep.parser.object.PCEPNotificationObjectParser;
43 import org.opendaylight.protocol.pcep.parser.object.PCEPObjectiveFunctionObjectParser;
44 import org.opendaylight.protocol.pcep.parser.object.PCEPOpenObjectParser;
45 import org.opendaylight.protocol.pcep.parser.object.PCEPOverloadObjectParser;
46 import org.opendaylight.protocol.pcep.parser.object.PCEPPathKeyObjectParser;
47 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv4ObjectParser;
48 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv6ObjectParser;
49 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv4ObjectParser;
50 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv6ObjectParser;
51 import org.opendaylight.protocol.pcep.parser.object.PCEPProcTimeObjectParser;
52 import org.opendaylight.protocol.pcep.parser.object.PCEPReportedRouteObjectParser;
53 import org.opendaylight.protocol.pcep.parser.object.PCEPRequestParameterObjectParser;
54 import org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser;
55 import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsIpv4ObjectParser;
56 import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsIpv6ObjectParser;
57 import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsObjectSerializer;
58 import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPP2MPEndPointsIpv4ObjectParser;
59 import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPP2MPEndPointsIpv6ObjectParser;
60 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
61 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
62 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
63 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
64 import org.opendaylight.protocol.pcep.spi.UnknownObject;
65 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
66 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
67 import org.opendaylight.protocol.util.ByteArray;
68 import org.opendaylight.protocol.util.Ipv4Util;
69 import org.opendaylight.protocol.util.Ipv6Util;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
71 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
72 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
73 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
74 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
75 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OfId;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.P2mpLeaves;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.BandwidthBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassTypeBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4CaseBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv6CaseBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.P2mpIpv4CaseBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.P2mpIpv6CaseBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4Builder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv6._case.Ipv6Builder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.p2mp.ipv4._case.P2mpIpv4Builder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.p2mp.ipv6._case.P2mpIpv6Builder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.object.EndpointsObjBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.XroBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.EroBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.gc.object.GcBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.IroBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.load.balancing.object.LoadBalancingBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lspa.object.LspaBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.MetricBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring.Flags;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.MonitoringBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.notification.object.CNotificationBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.OfBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.order.tlv.OrderBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.duration.tlv.OverloadDurationBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.object.Overload;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.object.OverloadBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.PathKeyBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeysBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupTypeBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReq;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReqBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pce.id.object.PceIdBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObjectBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.error.object.TlvsBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTimeBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.RroBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.req.missing.tlv.ReqMissingBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.RpBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.svec.object.SvecBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlvBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
148 public class PCEPObjectParserTest {
150 private TlvRegistry tlvRegistry;
152 private VendorInformationTlvRegistry viTlvRegistry;
154 private SimplePCEPExtensionProviderContext ctx;
155 private BaseParserExtensionActivator act;
156 private TestVendorInformationActivator viAct;
159 public void setUp() {
160 this.ctx = new SimplePCEPExtensionProviderContext();
161 this.act = new BaseParserExtensionActivator();
162 this.viAct = new TestVendorInformationActivator();
163 this.act.start(this.ctx);
164 this.viAct.start(this.ctx);
165 this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
166 this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
170 public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
171 final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
172 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
174 final OpenBuilder builder = new OpenBuilder();
175 builder.setProcessingRule(false);
176 builder.setIgnore(false);
177 builder.setVersion(new ProtocolVersion((short) 1));
178 builder.setKeepalive((short) 30);
179 builder.setDeadTimer((short) 120);
180 builder.setSessionId((short) 1);
182 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder().build());
184 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
185 final ByteBuf buf = Unpooled.buffer();
186 parser.serializeObject(builder.build(), buf);
187 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
190 parser.parseObject(new ObjectHeaderImpl(true, true), null);
192 } catch (final IllegalArgumentException e) {
193 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
196 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
198 } catch (final IllegalArgumentException e) {
199 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
204 public void testCloseObject() throws IOException, PCEPDeserializerException {
205 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
206 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
208 final CCloseBuilder builder = new CCloseBuilder();
209 builder.setProcessingRule(false);
210 builder.setIgnore(false);
211 builder.setReason((short) 5);
212 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.c.close.TlvsBuilder().build());
214 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
215 final ByteBuf buf = Unpooled.buffer();
216 parser.serializeObject(builder.build(), buf);
217 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
220 parser.parseObject(new ObjectHeaderImpl(true, true), null);
222 } catch (final IllegalArgumentException e) {
223 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
226 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
228 } catch (final IllegalArgumentException e) {
229 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
234 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
235 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
236 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
238 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
239 builder.setProcessingRule(true);
240 builder.setIgnore(false);
241 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
242 builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
244 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
245 final ByteBuf buf = Unpooled.buffer();
246 parser.serializeObject(builder.build(), buf);
247 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
250 parser.parseObject(new ObjectHeaderImpl(true, true), null);
252 } catch (final IllegalArgumentException e) {
253 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
256 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
258 } catch (final IllegalArgumentException e) {
259 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
264 public void testERObject() throws Exception {
265 final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
266 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
268 final EroBuilder builder = new EroBuilder();
269 builder.setProcessingRule(false);
270 builder.setIgnore(false);
271 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
272 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder().setLoose(
273 true).setSubobjectType(
274 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
275 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder().setLoose(
276 true).setSubobjectType(
277 new IpPrefixCaseBuilder().setIpPrefix(
278 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
279 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder().setLoose(
280 true).setSubobjectType(
281 new UnnumberedCaseBuilder().setUnnumbered(
282 new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
283 builder.setSubobject(subs);
285 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
286 final ByteBuf buf = Unpooled.buffer();
287 parser.serializeObject(builder.build(), buf);
288 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
291 parser.parseObject(new ObjectHeaderImpl(true, true), null);
293 } catch (final IllegalArgumentException e) {
294 assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
299 public void testIRObject() throws Exception {
300 final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
301 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
302 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
303 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
305 final IroBuilder builder = new IroBuilder();
306 builder.setProcessingRule(false);
307 builder.setIgnore(false);
308 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.Subobject> subs = Lists.newArrayList();
309 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder().setSubobjectType(
310 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).setLoose(true).build());
311 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder().setSubobjectType(
312 new IpPrefixCaseBuilder().setIpPrefix(
313 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).setLoose(true).build());
314 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder().setSubobjectType(
315 new IpPrefixCaseBuilder().setIpPrefix(
316 new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setLoose(true).build());
317 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder().setSubobjectType(
318 new UnnumberedCaseBuilder().setUnnumbered(
319 new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setLoose(true).build());
320 builder.setSubobject(subs);
322 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
323 final ByteBuf buf = Unpooled.buffer();
324 parser.serializeObject(builder.build(), buf);
325 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
328 parser.parseObject(new ObjectHeaderImpl(true, true), null);
330 } catch (final IllegalArgumentException e) {
331 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
334 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
336 } catch (final IllegalArgumentException e) {
337 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
342 public void testRRObject() throws Exception {
343 final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
344 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
345 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
346 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
348 final RroBuilder builder = new RroBuilder();
349 builder.setProcessingRule(false);
350 builder.setIgnore(false);
351 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
352 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
353 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
354 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
355 new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
357 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
358 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
359 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
360 new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
362 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
363 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
364 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
365 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
367 builder.setSubobject(subs);
369 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
370 final ByteBuf buf = Unpooled.buffer();
371 parser.serializeObject(builder.build(), buf);
372 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
375 parser.parseObject(new ObjectHeaderImpl(true, true), null);
377 } catch (final IllegalArgumentException e) {
378 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
381 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
383 } catch (final IllegalArgumentException e) {
384 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
389 public void testBandwidthObject() throws IOException, PCEPDeserializerException {
390 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
391 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
393 final BandwidthBuilder builder = new BandwidthBuilder();
394 builder.setProcessingRule(true);
395 builder.setIgnore(true);
396 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
398 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
399 final ByteBuf buf = Unpooled.buffer();
400 parser.serializeObject(builder.build(), buf);
401 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
404 parser.parseObject(new ObjectHeaderImpl(true, true), null);
406 } catch (final IllegalArgumentException e) {
407 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
410 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
412 } catch (final IllegalArgumentException e) {
413 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
418 public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
419 final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
420 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
422 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reoptimization
423 .bandwidth.object.ReoptimizationBandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
424 .ns.yang.pcep.types.rev181109.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
425 builder.setProcessingRule(true);
426 builder.setIgnore(true);
427 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
429 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
430 final ByteBuf buf = Unpooled.buffer();
431 parser.serializeObject(builder.build(), buf);
432 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
435 parser.parseObject(new ObjectHeaderImpl(true, true), null);
437 } catch (final IllegalArgumentException e) {
438 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
441 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
443 } catch (final IllegalArgumentException e) {
444 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
449 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
450 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
451 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
453 final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
455 = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
457 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
458 builder.setProcessingRule(true);
459 builder.setIgnore(false);
460 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
461 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes)))
462 .setDestinationIpv4Address(
463 Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
465 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false),
466 result.slice(4, result.readableBytes() - 4)));
467 final ByteBuf buf = Unpooled.buffer();
468 final PCEPEndPointsObjectSerializer serializer = new PCEPEndPointsObjectSerializer();
469 serializer.serializeObject(builder.build(), buf);
470 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
473 parser.parseObject(new ObjectHeaderImpl(true, true), null);
475 } catch (final IllegalArgumentException e) {
476 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
479 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
481 } catch (final IllegalArgumentException e) {
482 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
488 public void testEndPointsObjectP2MPIPv4() throws PCEPDeserializerException {
489 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
490 final byte[] destIPBytes = {
491 (byte) 0x04, (byte) 0x32, (byte) 0x00, (byte) 0x14,
492 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
493 (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E,
494 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
495 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFC};
497 final PCEPP2MPEndPointsIpv4ObjectParser parser = new PCEPP2MPEndPointsIpv4ObjectParser();
498 final ByteBuf result = Unpooled.wrappedBuffer(destIPBytes);
500 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
501 builder.setProcessingRule(true);
502 builder.setIgnore(false);
503 builder.setAddressFamily(new P2mpIpv4CaseBuilder().setP2mpIpv4(new P2mpIpv4Builder()
504 .setP2mpLeaves(P2mpLeaves.NewLeavesToAdd)
505 .setSourceIpv4Address(Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes)))
506 .setDestinationIpv4Address(Arrays.asList(new Ipv4AddressNoZone("255.255.255.255"),
507 new Ipv4AddressNoZone("255.255.255.252"))).build()).build());
509 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false),
510 result.slice(4, result.readableBytes() - 4)));
511 final ByteBuf buf = Unpooled.buffer();
512 final PCEPEndPointsObjectSerializer serializer = new PCEPEndPointsObjectSerializer();
513 serializer.serializeObject(builder.build(), buf);
514 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
517 parser.parseObject(new ObjectHeaderImpl(true, true), null);
519 } catch (final IllegalArgumentException e) {
520 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
523 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
525 } catch (final IllegalArgumentException e) {
526 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
531 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
532 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
533 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
534 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
535 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
537 final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
538 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
540 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
541 builder.setProcessingRule(true);
542 builder.setIgnore(false);
543 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
544 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
545 Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
547 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
548 final ByteBuf buf = Unpooled.buffer();
549 final PCEPEndPointsObjectSerializer serializer = new PCEPEndPointsObjectSerializer();
550 serializer.serializeObject(builder.build(), buf);
551 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
554 parser.parseObject(new ObjectHeaderImpl(true, true), null);
556 } catch (final IllegalArgumentException e) {
557 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
560 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
562 } catch (final IllegalArgumentException e) {
563 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
568 public void testEndPointsObjectP2MPIPv6() throws IOException, PCEPDeserializerException {
569 final byte[] destIPBytes = {
570 (byte) 0x04, (byte) 0x42, (byte) 0x00, (byte) 0x38,
571 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
572 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
573 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
574 (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2,
575 (byte) 0xFF, (byte) 0xEC, (byte) 0xA1, (byte) 0xB6,
576 (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50,
577 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
578 (byte) 0x00, (byte) 0x03, (byte) 0x5D, (byte) 0xD2,
579 (byte) 0xFF, (byte) 0xEC, (byte) 0xA1, (byte) 0xB6,
580 (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50,
581 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
583 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
584 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
586 final PCEPP2MPEndPointsIpv6ObjectParser parser = new PCEPP2MPEndPointsIpv6ObjectParser();
587 final ByteBuf result = Unpooled.wrappedBuffer(destIPBytes);
589 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
590 builder.setProcessingRule(true);
591 builder.setIgnore(false);
592 builder.setAddressFamily(new P2mpIpv6CaseBuilder().setP2mpIpv6(new P2mpIpv6Builder()
593 .setP2mpLeaves(P2mpLeaves.NewLeavesToAdd)
594 .setSourceIpv6Address(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes)))
595 .setDestinationIpv6Address(Arrays.asList(
596 new Ipv6AddressNoZone("2:5dd2:ffec:a1b6:581e:9f50::"),
597 new Ipv6AddressNoZone("3:5dd2:ffec:a1b6:581e:9f50::")
598 )).build()).build());
600 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false),
601 result.slice(4, result.readableBytes() - 4)));
602 final ByteBuf buf = Unpooled.buffer();
603 final PCEPEndPointsObjectSerializer serializer = new PCEPEndPointsObjectSerializer();
604 serializer.serializeObject(builder.build(), buf);
605 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
608 parser.parseObject(new ObjectHeaderImpl(true, true), null);
610 } catch (final IllegalArgumentException e) {
611 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
614 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
616 } catch (final IllegalArgumentException e) {
617 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
622 public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
623 final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
624 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
626 final ErrorObjectBuilder builder = new ErrorObjectBuilder();
627 builder.setProcessingRule(true);
628 builder.setIgnore(true);
629 builder.setType((short) 1);
630 builder.setValue((short) 1);
632 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
633 ByteBuf buf = Unpooled.buffer();
634 parser.serializeObject(builder.build(), buf);
635 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
637 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
639 builder.setType((short) 7);
640 builder.setValue((short) 0);
641 builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
643 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
644 buf = Unpooled.buffer();
645 parser.serializeObject(builder.build(), buf);
646 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
649 parser.parseObject(new ObjectHeaderImpl(true, true), null);
651 } catch (final IllegalArgumentException e) {
652 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
655 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
657 } catch (final IllegalArgumentException e) {
658 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
663 public void testLspaObject() throws IOException, PCEPDeserializerException {
664 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
665 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
667 final LspaBuilder builder = new LspaBuilder();
668 builder.setProcessingRule(true);
669 builder.setIgnore(true);
670 builder.setExcludeAny(new AttributeFilter(0L));
671 builder.setIncludeAny(new AttributeFilter(0L));
672 builder.setIncludeAll(new AttributeFilter(0L));
673 builder.setHoldPriority((short) 0);
674 builder.setSetupPriority((short) 0);
675 builder.setLocalProtectionDesired(false);
676 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lspa.object.lspa.TlvsBuilder().build());
678 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
679 ByteBuf buf = Unpooled.buffer();
680 parser.serializeObject(builder.build(), buf);
681 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
683 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
685 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
686 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
687 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
688 builder.setHoldPriority((short) 0xFF);
689 builder.setSetupPriority((short) 0xFF);
690 builder.setLocalProtectionDesired(true);
692 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
693 buf = Unpooled.buffer();
694 parser.serializeObject(builder.build(), buf);
695 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
698 parser.parseObject(new ObjectHeaderImpl(true, true), null);
700 } catch (final IllegalArgumentException e) {
701 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
704 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
706 } catch (final IllegalArgumentException e) {
707 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
712 public void testMetricObject() throws IOException, PCEPDeserializerException {
713 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
714 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
716 final MetricBuilder builder = new MetricBuilder();
717 builder.setProcessingRule(true);
718 builder.setIgnore(true);
719 builder.setComputed(false);
720 builder.setBound(false);
721 builder.setMetricType((short) 1);
722 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
724 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
725 ByteBuf buf = Unpooled.buffer();
726 parser.serializeObject(builder.build(), buf);
727 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
729 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
731 builder.setComputed(true);
732 builder.setBound(false);
733 builder.setMetricType((short) 2);
734 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
736 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
737 buf = Unpooled.buffer();
738 parser.serializeObject(builder.build(), buf);
739 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
742 parser.parseObject(new ObjectHeaderImpl(true, true), null);
744 } catch (final IllegalArgumentException e) {
745 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
748 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
750 } catch (final IllegalArgumentException e) {
751 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
756 public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
757 final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
758 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
760 final NoPathBuilder builder = new NoPathBuilder();
761 builder.setProcessingRule(true);
762 builder.setIgnore(true);
763 builder.setNatureOfIssue((short) 1);
764 builder.setUnsatisfiedConstraints(true);
765 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().build());
767 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
768 ByteBuf buf = Unpooled.buffer();
769 parser.serializeObject(builder.build(), buf);
770 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
772 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
774 builder.setNatureOfIssue((short) 0);
775 builder.setUnsatisfiedConstraints(false);
777 final NoPathVectorBuilder b = new NoPathVectorBuilder();
778 b.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true));
779 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().setNoPathVector(
782 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
783 buf = Unpooled.buffer();
784 parser.serializeObject(builder.build(), buf);
785 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
788 parser.parseObject(new ObjectHeaderImpl(true, true), null);
790 } catch (final IllegalArgumentException e) {
791 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
794 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
796 } catch (final IllegalArgumentException e) {
797 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
802 public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
803 final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
804 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
806 final CNotificationBuilder builder = new CNotificationBuilder();
807 builder.setProcessingRule(true);
808 builder.setIgnore(true);
809 builder.setType((short) 0xff);
810 builder.setValue((short) 0xff);
812 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
813 ByteBuf buf = Unpooled.buffer();
814 parser.serializeObject(builder.build(), buf);
815 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
817 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
819 builder.setType((short) 2);
820 builder.setValue((short) 1);
821 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
822 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
824 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
825 buf = Unpooled.buffer();
826 parser.serializeObject(builder.build(), buf);
827 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
830 parser.parseObject(new ObjectHeaderImpl(true, true), null);
832 } catch (final IllegalArgumentException e) {
833 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
836 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
838 } catch (final IllegalArgumentException e) {
839 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
844 public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
845 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
846 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
848 final RpBuilder builder = new RpBuilder();
849 builder.setProcessingRule(true);
850 builder.setIgnore(true);
851 builder.setReoptimization(true);
852 builder.setBiDirectional(false);
853 builder.setLoose(true);
854 builder.setMakeBeforeBreak(true);
855 builder.setOrder(false);
856 builder.setPathKey(false);
857 builder.setSupplyOf(false);
858 builder.setFragmentation(false);
859 builder.setP2mp(false);
860 builder.setEroCompression(false);
861 builder.setPriority((short) 5);
862 builder.setRequestId(new RequestId(0xdeadbeefL));
863 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.rp.TlvsBuilder().build());
865 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
866 ByteBuf buf = Unpooled.buffer();
867 parser.serializeObject(builder.build(), buf);
868 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
870 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
872 builder.setReoptimization(false);
873 builder.setFragmentation(true);
874 builder.setEroCompression(true);
876 final OrderBuilder b = new OrderBuilder();
877 b.setDelete(0xffffffffL);
880 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.rp.TlvsBuilder().setOrder(
883 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
884 buf = Unpooled.buffer();
885 parser.serializeObject(builder.build(), buf);
886 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
889 parser.parseObject(new ObjectHeaderImpl(true, true), null);
891 } catch (final IllegalArgumentException e) {
892 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
895 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
897 } catch (final IllegalArgumentException e) {
898 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
903 public void testSvecObject() throws IOException, PCEPDeserializerException {
904 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
905 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
907 final SvecBuilder builder = new SvecBuilder();
908 builder.setProcessingRule(false);
909 builder.setIgnore(false);
910 builder.setLinkDiverse(false);
911 builder.setNodeDiverse(false);
912 builder.setSrlgDiverse(false);
913 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
915 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
916 ByteBuf buf = Unpooled.buffer();
917 parser.serializeObject(builder.build(), buf);
918 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
920 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
922 builder.setProcessingRule(true);
923 builder.setLinkDiverse(true);
924 builder.setSrlgDiverse(true);
926 final List<RequestId> requestIDs = Lists.newArrayList();
927 requestIDs.add(new RequestId(0xFFFFFFFFL));
928 requestIDs.add(new RequestId(0x00000001L));
929 requestIDs.add(new RequestId(0x01234567L));
930 requestIDs.add(new RequestId(0x89ABCDEFL));
931 requestIDs.add(new RequestId(0xFEDCBA98L));
932 requestIDs.add(new RequestId(0x76543210L));
933 requestIDs.add(new RequestId(0x15825266L));
934 requestIDs.add(new RequestId(0x48120BBEL));
935 requestIDs.add(new RequestId(0x25FB7E52L));
936 requestIDs.add(new RequestId(0xB2F2546BL));
938 builder.setRequestsIds(requestIDs);
940 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
941 buf = Unpooled.buffer();
942 parser.serializeObject(builder.build(), buf);
943 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
946 parser.parseObject(new ObjectHeaderImpl(true, true), null);
948 } catch (final IllegalArgumentException e) {
949 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
952 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
954 } catch (final IllegalArgumentException e) {
955 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
960 public void testClassTypeObject() throws PCEPDeserializerException {
961 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
962 final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
964 final ClassTypeBuilder builder = new ClassTypeBuilder();
965 builder.setProcessingRule(true);
966 builder.setIgnore(false);
967 builder.setClassType(new ClassType((short) 4));
969 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
970 final ByteBuf buf = Unpooled.buffer();
971 parser.serializeObject(builder.build(), buf);
972 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
975 parser.parseObject(new ObjectHeaderImpl(true, true), null);
977 } catch (final IllegalArgumentException e) {
978 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
981 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
983 } catch (final IllegalArgumentException e) {
984 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
989 public void testExcludeRouteObject() throws Exception {
990 final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
991 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
993 final XroBuilder builder = new XroBuilder();
994 builder.setProcessingRule(false);
995 builder.setIgnore(false);
996 builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.Xro.Flags(true));
997 final List<Subobject> subs = Lists.newArrayList();
998 subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
999 new IpPrefixCaseBuilder().setIpPrefix(
1000 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
1001 Attribute.Node).build());
1002 subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
1003 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
1004 builder.setSubobject(subs);
1006 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1007 final ByteBuf buf = Unpooled.buffer();
1008 parser.serializeObject(builder.build(), buf);
1009 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1012 parser.parseObject(new ObjectHeaderImpl(true, true), null);
1014 } catch (final IllegalArgumentException e) {
1015 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1018 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1020 } catch (final IllegalArgumentException e) {
1021 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1026 public void testPathKeyObject() throws Exception {
1027 final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
1028 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
1030 final PathKeyBuilder builder = new PathKeyBuilder();
1031 builder.setProcessingRule(true);
1032 builder.setIgnore(false);
1033 final List<PathKeys> list = Lists.newArrayList();
1034 list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
1035 new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
1036 builder.setPathKeys(list);
1038 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
1039 final ByteBuf buf = Unpooled.buffer();
1040 parser.serializeObject(builder.build(), buf);
1041 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1044 parser.parseObject(new ObjectHeaderImpl(true, true), null);
1046 } catch (final IllegalArgumentException e) {
1047 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1050 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1052 } catch (final IllegalArgumentException e) {
1053 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1058 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
1059 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
1060 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
1062 final OfBuilder builder = new OfBuilder();
1063 builder.setProcessingRule(true);
1064 builder.setIgnore(false);
1065 builder.setCode(new OfId(4));
1066 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.of.TlvsBuilder().build());
1068 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
1069 final ByteBuf buf = Unpooled.buffer();
1070 parser.serializeObject(builder.build(), buf);
1071 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1074 parser.parseObject(new ObjectHeaderImpl(true, true), null);
1076 } catch (final IllegalArgumentException e) {
1077 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1080 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1082 } catch (final IllegalArgumentException e) {
1083 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1088 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
1089 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
1090 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
1092 final GcBuilder builder = new GcBuilder();
1093 builder.setProcessingRule(true);
1094 builder.setIgnore(false);
1095 builder.setMaxHop((short) 1);
1096 builder.setMaxUtilization((short) 0);
1097 builder.setMinUtilization((short) 100);
1098 builder.setOverBookingFactor((short) 99);
1099 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.gc.object.gc.TlvsBuilder().build());
1101 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
1102 final ByteBuf buf = Unpooled.buffer();
1103 parser.serializeObject(builder.build(), buf);
1104 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1107 parser.parseObject(new ObjectHeaderImpl(true, true), null);
1109 } catch (final IllegalArgumentException e) {
1110 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1113 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1115 } catch (final IllegalArgumentException e) {
1116 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1121 public void testIgnoreUknownObject() throws PCEPDeserializerException {
1122 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
1127 public void testUnrecognizedObjectType() throws PCEPDeserializerException {
1128 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
1129 assertNotNull(object);
1130 assertTrue(object instanceof UnknownObject);
1131 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
1135 public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1136 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1137 assertNotNull(object);
1138 assertTrue(object instanceof UnknownObject);
1139 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1143 public void testLspaObjectSerializerDefence() throws IOException {
1144 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1145 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1147 final LspaBuilder builder = new LspaBuilder();
1148 builder.setProcessingRule(true);
1149 builder.setIgnore(true);
1150 builder.setLocalProtectionDesired(false);
1152 final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1153 parser.serializeObject(builder.build(), buf);
1154 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1158 public void testEmptyEroObject() throws PCEPDeserializerException {
1159 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(7, 1,
1160 new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1161 assertNotNull(object);
1162 assertTrue(object instanceof Ero);
1163 final Ero eroObject = (Ero) object;
1164 assertTrue(eroObject.getSubobject().isEmpty());
1166 final ByteBuf buffer = Unpooled.buffer();
1167 this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1168 final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1169 assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1173 public void testCloseObjectWithVendorInformationTlv() throws PCEPDeserializerException {
1174 final byte[] closeBytes = {
1175 0x0f, 0x10, 0x00, 0x14,
1176 0x00, 0x00, 0x00, 0x05,
1177 /* vendor-information TLV */
1178 0x00, 0x07, 0x00, 0x08,
1179 /* enterprise number */
1180 0x00, 0x00, 0x00, 0x00,
1181 /* enterprise specific information */
1182 0x00, 0x00, 0x00, 0x05
1184 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1185 final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1187 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1188 final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1189 .setEnterpriseSpecificInformation(esInfo).build();
1190 final CCloseBuilder builder = new CCloseBuilder();
1191 builder.setProcessingRule(false);
1192 builder.setIgnore(false);
1193 builder.setReason((short) 5);
1194 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.c.close.TlvsBuilder()
1195 .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1197 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1199 final ByteBuf buf = Unpooled.buffer();
1200 parser.serializeObject(builder.build(), buf);
1201 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1205 public void testVendorInformationObject() throws PCEPDeserializerException {
1206 final byte[] viObjBytes = {
1207 /* vendor-information object */
1208 0x22, 0x10, 0x00, 0x0C,
1209 /* enterprise number */
1210 0x00, 0x00, 0x00, 0x00,
1211 /* enterprise specific information */
1212 0x00, 0x00, 0x00, 0x05
1214 final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1215 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1216 final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1217 .setEnterpriseSpecificInformation(esInfo).build();
1218 final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1219 result.readerIndex(8);
1220 final VendorInformationObject o = (VendorInformationObject) parser.parseObject(new ObjectHeaderImpl(false, false), result.readSlice(result.readableBytes()));
1221 assertEquals(viObj, o);
1223 final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1224 parser.serializeObject(viObj, buf);
1225 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1229 public void testMonitoringObject() throws PCEPDeserializerException {
1230 final byte[] monitoringBytes = {
1232 0x13, 0x10, 0x00, 0x0C,
1234 0x00, 0x00, 0x00, 0x01,
1235 /* monitoring-id=16 */
1236 0x00, 0x00, 0x00, 0x10
1238 final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
1239 final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
1240 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.monitoring.TlvsBuilder().build()).build();
1241 final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
1242 assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1244 final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
1245 parser.serializeObject(monitoring, buf);
1246 assertArrayEquals(monitoringBytes, buf.array());
1250 public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
1251 final byte[] pccIdReqBytes = {
1253 0x14, 0x10, 0x00, 0x08,
1255 0x7f, 0x00, 0x00, 0x01
1257 final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
1258 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1"))).build();
1259 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1260 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1262 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1263 parser.serializeObject(pccIdReq, buf);
1264 assertArrayEquals(pccIdReqBytes, buf.array());
1268 public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
1269 final byte[] pccIdReqBytes = {
1271 0x14, 0x20, 0x00, 0x14,
1273 0x00, 0x00, 0x00, 0x00,
1274 0x00, 0x00, 0x00, 0x00,
1275 0x00, 0x00, 0x00, 0x00,
1276 0x00, 0x00, 0x00, 0x01
1278 final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
1279 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv6AddressNoZone("::1"))).build();
1280 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1281 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1283 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1284 parser.serializeObject(pccIdReq, buf);
1285 assertArrayEquals(pccIdReqBytes, buf.array());
1289 public void testPceIdIPv4Object() throws PCEPDeserializerException {
1290 final byte[] pccIdReqBytes = {
1292 0x19, 0x10, 0x00, 0x08,
1294 0x7f, 0x00, 0x00, 0x01
1296 final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
1297 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pce.id.object.PceId pceId = new PceIdBuilder().setIpAddress(new IpAddressNoZone(
1298 new Ipv4AddressNoZone("127.0.0.1"))).build();
1299 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1300 assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1302 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1303 parser.serializeObject(pceId, buf);
1304 assertArrayEquals(pccIdReqBytes, buf.array());
1308 public void testPceIdIPv6Object() throws PCEPDeserializerException {
1309 final byte[] pccIdReqBytes = {
1311 0x19, 0x20, 0x00, 0x14,
1313 0x00, 0x00, 0x00, 0x00,
1314 0x00, 0x00, 0x00, 0x00,
1315 0x00, 0x00, 0x00, 0x00,
1316 0x00, 0x00, 0x00, 0x01
1318 final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
1319 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddressNoZone(
1320 new Ipv6AddressNoZone("::1"))).build();
1321 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1322 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1324 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1325 parser.serializeObject(pccIdReq, buf);
1326 assertArrayEquals(pccIdReqBytes, buf.array());
1330 public void testProcTimeObject() throws PCEPDeserializerException {
1331 final byte[] proctimeBytes = {
1333 0x1A, 0x10, 0x00, 0x1C,
1335 0x00, 0x00, 0x00, 0x01,
1336 /* current proc. time */
1337 0x00, 0x00, 0x00, 0x01,
1338 /* min proc. time */
1339 0x00, 0x00, 0x00, 0x02,
1341 0x00, 0x00, 0x00, 0x03,
1342 /* average proc time */
1343 0x00, 0x00, 0x00, 0x04,
1344 /* variance proc time */
1345 0x00, 0x00, 0x00, 0x05,
1347 final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
1348 final ProcTime procTime = new ProcTimeBuilder()
1350 .setAverageProcTime(4L)
1351 .setCurrentProcTime(1L)
1354 .setVarianceProcTime(5L).build();
1355 final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
1356 assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1358 final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
1359 parser.serializeObject(procTime, buf);
1360 assertArrayEquals(proctimeBytes, buf.array());
1364 public void testOverloadObject() throws PCEPDeserializerException {
1365 final byte[] overloadBytes = {
1367 0x1B, 0x10, 0x00, 0x08,
1368 /* overload duration */
1369 0x00, 0x00, 0x00, 0x78
1371 final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
1372 final Overload overload = new OverloadBuilder().setDuration(120).build();
1373 final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
1374 assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1376 final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
1377 parser.serializeObject(overload, buf);
1378 assertArrayEquals(overloadBytes, buf.array());
1382 public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
1384 final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
1385 (byte) 0xad, (byte) 0xbe, (byte) 0xef,
1387 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
1389 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
1390 final RpBuilder builder = new RpBuilder();
1391 builder.setProcessingRule(false);
1392 builder.setIgnore(false);
1393 builder.setReoptimization(true);
1394 builder.setBiDirectional(false);
1395 builder.setLoose(true);
1396 builder.setMakeBeforeBreak(true);
1397 builder.setOrder(false);
1398 builder.setPathKey(false);
1399 builder.setSupplyOf(false);
1400 builder.setFragmentation(false);
1401 builder.setP2mp(false);
1402 builder.setEroCompression(false);
1403 builder.setPriority((short) 5);
1404 builder.setRequestId(new RequestId(0xdeadbeefL));
1405 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.rp.TlvsBuilder().setPathSetupType(
1406 new PathSetupTypeBuilder().setPst((short) 0).build()).build());
1408 final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
1409 assertEquals(builder.build(),
1410 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1411 final ByteBuf buf = Unpooled.buffer();
1412 parser.serializeObject(builder.build(), buf);
1413 assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));