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.Collections;
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.PCEPEndPointsIpv4ObjectParser;
32 import org.opendaylight.protocol.pcep.parser.object.PCEPEndPointsIpv6ObjectParser;
33 import org.opendaylight.protocol.pcep.parser.object.PCEPErrorObjectParser;
34 import org.opendaylight.protocol.pcep.parser.object.PCEPExcludeRouteObjectParser;
35 import org.opendaylight.protocol.pcep.parser.object.PCEPExistingBandwidthObjectParser;
36 import org.opendaylight.protocol.pcep.parser.object.PCEPExplicitRouteObjectParser;
37 import org.opendaylight.protocol.pcep.parser.object.PCEPGlobalConstraintsObjectParser;
38 import org.opendaylight.protocol.pcep.parser.object.PCEPIncludeRouteObjectParser;
39 import org.opendaylight.protocol.pcep.parser.object.PCEPLoadBalancingObjectParser;
40 import org.opendaylight.protocol.pcep.parser.object.PCEPLspaObjectParser;
41 import org.opendaylight.protocol.pcep.parser.object.PCEPMetricObjectParser;
42 import org.opendaylight.protocol.pcep.parser.object.PCEPMonitoringObjectParser;
43 import org.opendaylight.protocol.pcep.parser.object.PCEPNoPathObjectParser;
44 import org.opendaylight.protocol.pcep.parser.object.PCEPNotificationObjectParser;
45 import org.opendaylight.protocol.pcep.parser.object.PCEPObjectiveFunctionObjectParser;
46 import org.opendaylight.protocol.pcep.parser.object.PCEPOpenObjectParser;
47 import org.opendaylight.protocol.pcep.parser.object.PCEPOverloadObjectParser;
48 import org.opendaylight.protocol.pcep.parser.object.PCEPPathKeyObjectParser;
49 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv4ObjectParser;
50 import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv6ObjectParser;
51 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv4ObjectParser;
52 import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv6ObjectParser;
53 import org.opendaylight.protocol.pcep.parser.object.PCEPProcTimeObjectParser;
54 import org.opendaylight.protocol.pcep.parser.object.PCEPReportedRouteObjectParser;
55 import org.opendaylight.protocol.pcep.parser.object.PCEPRequestParameterObjectParser;
56 import org.opendaylight.protocol.pcep.parser.object.PCEPSecondaryExplicitRouteObjecParser;
57 import org.opendaylight.protocol.pcep.parser.object.PCEPSecondaryRecordRouteObjectParser;
58 import org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser;
59 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
60 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
61 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
62 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
63 import org.opendaylight.protocol.pcep.spi.UnknownObject;
64 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
65 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
66 import org.opendaylight.protocol.util.ByteArray;
67 import org.opendaylight.protocol.util.Ipv4Util;
68 import org.opendaylight.protocol.util.Ipv6Util;
69 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
71 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
72 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
73 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
74 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
120 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;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.secondary.explicit.route.object.SeroBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.secondary.reported.route.object.SrroBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
144 public class PCEPObjectParserTest {
146 private TlvRegistry tlvRegistry;
148 private VendorInformationTlvRegistry viTlvRegistry;
150 private SimplePCEPExtensionProviderContext ctx;
151 private BaseParserExtensionActivator act;
152 private TestVendorInformationActivator viAct;
155 public void setUp() {
156 this.ctx = new SimplePCEPExtensionProviderContext();
157 this.act = new BaseParserExtensionActivator();
158 this.viAct = new TestVendorInformationActivator();
159 this.act.start(this.ctx);
160 this.viAct.start(this.ctx);
161 this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
162 this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
166 public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
167 final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
168 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
170 final OpenBuilder builder = new OpenBuilder();
171 builder.setProcessingRule(false);
172 builder.setIgnore(false);
173 builder.setVersion(new ProtocolVersion((short) 1));
174 builder.setKeepalive((short) 30);
175 builder.setDeadTimer((short) 120);
176 builder.setSessionId((short) 1);
178 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
180 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
181 final ByteBuf buf = Unpooled.buffer();
182 parser.serializeObject(builder.build(), buf);
183 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
186 parser.parseObject(new ObjectHeaderImpl(true, true), null);
188 } catch (final IllegalArgumentException e) {
189 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
192 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
194 } catch (final IllegalArgumentException e) {
195 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
200 public void testCloseObject() throws IOException, PCEPDeserializerException {
201 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
202 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
204 final CCloseBuilder builder = new CCloseBuilder();
205 builder.setProcessingRule(false);
206 builder.setIgnore(false);
207 builder.setReason((short) 5);
208 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
210 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
211 final ByteBuf buf = Unpooled.buffer();
212 parser.serializeObject(builder.build(), buf);
213 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
216 parser.parseObject(new ObjectHeaderImpl(true, true), null);
218 } catch (final IllegalArgumentException e) {
219 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
222 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
224 } catch (final IllegalArgumentException e) {
225 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
230 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
231 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
232 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
234 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
235 builder.setProcessingRule(true);
236 builder.setIgnore(false);
237 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
238 builder.setMinBandwidth(new Bandwidth(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}));
240 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
241 final ByteBuf buf = Unpooled.buffer();
242 parser.serializeObject(builder.build(), buf);
243 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
246 parser.parseObject(new ObjectHeaderImpl(true, true), null);
248 } catch (final IllegalArgumentException e) {
249 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
252 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
254 } catch (final IllegalArgumentException e) {
255 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
260 public void testERObject() throws Exception {
261 final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
262 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
264 final EroBuilder builder = new EroBuilder();
265 builder.setProcessingRule(false);
266 builder.setIgnore(false);
267 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
268 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
269 true).setSubobjectType(
270 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
271 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
272 true).setSubobjectType(
273 new IpPrefixCaseBuilder().setIpPrefix(
274 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
275 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
276 true).setSubobjectType(
277 new UnnumberedCaseBuilder().setUnnumbered(
278 new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
279 builder.setSubobject(subs);
281 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
282 final ByteBuf buf = Unpooled.buffer();
283 parser.serializeObject(builder.build(), buf);
284 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
287 parser.parseObject(new ObjectHeaderImpl(true, true), null);
289 } catch (final IllegalArgumentException e) {
290 assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
295 public void testIRObject() throws Exception {
296 final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
297 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
298 final byte[] ip6PrefixBytes = {(byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
299 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
301 final IroBuilder builder = new IroBuilder();
302 builder.setProcessingRule(false);
303 builder.setIgnore(false);
304 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists.newArrayList();
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 AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).setLoose(true).build());
307 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
308 new IpPrefixCaseBuilder().setIpPrefix(
309 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).setLoose(true).build());
310 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
311 new IpPrefixCaseBuilder().setIpPrefix(
312 new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setLoose(true).build());
313 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
314 new UnnumberedCaseBuilder().setUnnumbered(
315 new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setLoose(true).build());
316 builder.setSubobject(subs);
318 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
319 final ByteBuf buf = Unpooled.buffer();
320 parser.serializeObject(builder.build(), buf);
321 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
324 parser.parseObject(new ObjectHeaderImpl(true, true), null);
326 } catch (final IllegalArgumentException e) {
327 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
330 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
332 } catch (final IllegalArgumentException e) {
333 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
338 public void testRRObject() throws Exception {
339 final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
340 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
341 final byte[] ip6PrefixBytes = {(byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
342 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
344 final RroBuilder builder = new RroBuilder();
345 builder.setProcessingRule(false);
346 builder.setIgnore(false);
347 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
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(new Ipv4Prefix("255.255.255.255/32"))).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.IpPrefixCaseBuilder().setIpPrefix(
355 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
356 new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
358 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
359 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
360 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
361 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
363 builder.setSubobject(subs);
365 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
366 final ByteBuf buf = Unpooled.buffer();
367 parser.serializeObject(builder.build(), buf);
368 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
371 parser.parseObject(new ObjectHeaderImpl(true, true), null);
373 } catch (final IllegalArgumentException e) {
374 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
377 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
379 } catch (final IllegalArgumentException e) {
380 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
385 public void testBandwidthObject() throws IOException, PCEPDeserializerException {
386 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
387 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
389 final BandwidthBuilder builder = new BandwidthBuilder();
390 builder.setProcessingRule(true);
391 builder.setIgnore(true);
392 builder.setBandwidth(new Bandwidth(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}));
394 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
395 final ByteBuf buf = Unpooled.buffer();
396 parser.serializeObject(builder.build(), buf);
397 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
400 parser.parseObject(new ObjectHeaderImpl(true, true), null);
402 } catch (final IllegalArgumentException e) {
403 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
406 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
408 } catch (final IllegalArgumentException e) {
409 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
414 public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
415 final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
416 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
418 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization
419 .bandwidth.object.ReoptimizationBandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
420 .ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
421 builder.setProcessingRule(true);
422 builder.setIgnore(true);
423 builder.setBandwidth(new Bandwidth(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}));
425 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
426 final ByteBuf buf = Unpooled.buffer();
427 parser.serializeObject(builder.build(), buf);
428 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
431 parser.parseObject(new ObjectHeaderImpl(true, true), null);
433 } catch (final IllegalArgumentException e) {
434 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
437 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
439 } catch (final IllegalArgumentException e) {
440 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
445 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
446 final byte[] srcIPBytes = {(byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E};
447 final byte[] destIPBytes = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
449 final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
450 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
452 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
453 builder.setProcessingRule(true);
454 builder.setIgnore(false);
455 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
456 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
457 Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
459 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
460 final ByteBuf buf = Unpooled.buffer();
461 parser.serializeObject(builder.build(), buf);
462 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
465 parser.parseObject(new ObjectHeaderImpl(true, true), null);
467 } catch (final IllegalArgumentException e) {
468 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
471 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
473 } catch (final IllegalArgumentException e) {
474 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
479 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
480 final byte[] destIPBytes = {(byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
481 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,};
482 final byte[] srcIPBytes = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
483 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
485 final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
486 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
488 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
489 builder.setProcessingRule(true);
490 builder.setIgnore(false);
491 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
492 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
493 Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
495 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
496 final ByteBuf buf = Unpooled.buffer();
497 PCEPEndPointsIpv6ObjectParser.serializeObject(builder.build(), buf);
498 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
501 parser.parseObject(new ObjectHeaderImpl(true, true), null);
503 } catch (final IllegalArgumentException e) {
504 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
507 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
509 } catch (final IllegalArgumentException e) {
510 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
515 public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
516 final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
517 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
519 final ErrorObjectBuilder builder = new ErrorObjectBuilder();
520 builder.setProcessingRule(true);
521 builder.setIgnore(true);
522 builder.setType((short) 1);
523 builder.setValue((short) 1);
525 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
526 ByteBuf buf = Unpooled.buffer();
527 parser.serializeObject(builder.build(), buf);
528 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
530 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
532 builder.setType((short) 7);
533 builder.setValue((short) 0);
534 builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
536 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
537 buf = Unpooled.buffer();
538 parser.serializeObject(builder.build(), buf);
539 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
542 parser.parseObject(new ObjectHeaderImpl(true, true), null);
544 } catch (final IllegalArgumentException e) {
545 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
548 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
550 } catch (final IllegalArgumentException e) {
551 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
556 public void testLspaObject() throws IOException, PCEPDeserializerException {
557 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
558 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
560 final LspaBuilder builder = new LspaBuilder();
561 builder.setProcessingRule(true);
562 builder.setIgnore(true);
563 builder.setExcludeAny(new AttributeFilter(0L));
564 builder.setIncludeAny(new AttributeFilter(0L));
565 builder.setIncludeAll(new AttributeFilter(0L));
566 builder.setHoldPriority((short) 0);
567 builder.setSetupPriority((short) 0);
568 builder.setLocalProtectionDesired(false);
569 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
571 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
572 ByteBuf buf = Unpooled.buffer();
573 parser.serializeObject(builder.build(), buf);
574 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
576 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
578 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
579 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
580 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
581 builder.setHoldPriority((short) 0xFF);
582 builder.setSetupPriority((short) 0xFF);
583 builder.setLocalProtectionDesired(true);
585 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
586 buf = Unpooled.buffer();
587 parser.serializeObject(builder.build(), buf);
588 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
591 parser.parseObject(new ObjectHeaderImpl(true, true), null);
593 } catch (final IllegalArgumentException e) {
594 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
597 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
599 } catch (final IllegalArgumentException e) {
600 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
605 public void testMetricObject() throws IOException, PCEPDeserializerException {
606 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
607 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
609 final MetricBuilder builder = new MetricBuilder();
610 builder.setProcessingRule(true);
611 builder.setIgnore(true);
612 builder.setComputed(false);
613 builder.setBound(false);
614 builder.setMetricType((short) 1);
615 builder.setValue(new Float32(new byte[]{0, 0, 0, 0}));
617 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
618 ByteBuf buf = Unpooled.buffer();
619 parser.serializeObject(builder.build(), buf);
620 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
622 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
624 builder.setComputed(true);
625 builder.setBound(false);
626 builder.setMetricType((short) 2);
627 builder.setValue(new Float32(new byte[]{(byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00}));
629 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
630 buf = Unpooled.buffer();
631 parser.serializeObject(builder.build(), buf);
632 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
635 parser.parseObject(new ObjectHeaderImpl(true, true), null);
637 } catch (final IllegalArgumentException e) {
638 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
641 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
643 } catch (final IllegalArgumentException e) {
644 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
649 public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
650 final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
651 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
653 final NoPathBuilder builder = new NoPathBuilder();
654 builder.setProcessingRule(true);
655 builder.setIgnore(true);
656 builder.setNatureOfIssue((short) 1);
657 builder.setUnsatisfiedConstraints(true);
658 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());
660 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
661 ByteBuf buf = Unpooled.buffer();
662 parser.serializeObject(builder.build(), buf);
663 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
665 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
667 builder.setNatureOfIssue((short) 0);
668 builder.setUnsatisfiedConstraints(false);
670 final NoPathVectorBuilder b = new NoPathVectorBuilder();
671 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));
672 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(
675 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
676 buf = Unpooled.buffer();
677 parser.serializeObject(builder.build(), buf);
678 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
681 parser.parseObject(new ObjectHeaderImpl(true, true), null);
683 } catch (final IllegalArgumentException e) {
684 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
687 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
689 } catch (final IllegalArgumentException e) {
690 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
695 public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
696 final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
697 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
699 final CNotificationBuilder builder = new CNotificationBuilder();
700 builder.setProcessingRule(true);
701 builder.setIgnore(true);
702 builder.setType((short) 0xff);
703 builder.setValue((short) 0xff);
705 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
706 ByteBuf buf = Unpooled.buffer();
707 parser.serializeObject(builder.build(), buf);
708 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
710 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
712 builder.setType((short) 2);
713 builder.setValue((short) 1);
714 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
715 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
717 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
718 buf = Unpooled.buffer();
719 parser.serializeObject(builder.build(), buf);
720 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
723 parser.parseObject(new ObjectHeaderImpl(true, true), null);
725 } catch (final IllegalArgumentException e) {
726 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
729 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
731 } catch (final IllegalArgumentException e) {
732 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
737 public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
738 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
739 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
741 final RpBuilder builder = new RpBuilder();
742 builder.setProcessingRule(true);
743 builder.setIgnore(true);
744 builder.setReoptimization(true);
745 builder.setBiDirectional(false);
746 builder.setLoose(true);
747 builder.setMakeBeforeBreak(true);
748 builder.setOrder(false);
749 builder.setPathKey(false);
750 builder.setSupplyOf(false);
751 builder.setFragmentation(false);
752 builder.setP2mp(false);
753 builder.setEroCompression(false);
754 builder.setPriority((short) 5);
755 builder.setRequestId(new RequestId(0xdeadbeefL));
756 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
758 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
759 ByteBuf buf = Unpooled.buffer();
760 parser.serializeObject(builder.build(), buf);
761 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
763 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
765 builder.setReoptimization(false);
766 builder.setFragmentation(true);
767 builder.setEroCompression(true);
769 final OrderBuilder b = new OrderBuilder();
770 b.setDelete(0xffffffffL);
773 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
776 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
777 buf = Unpooled.buffer();
778 parser.serializeObject(builder.build(), buf);
779 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
782 parser.parseObject(new ObjectHeaderImpl(true, true), null);
784 } catch (final IllegalArgumentException e) {
785 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
788 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
790 } catch (final IllegalArgumentException e) {
791 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
796 public void testSvecObject() throws IOException, PCEPDeserializerException {
797 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
798 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
800 final SvecBuilder builder = new SvecBuilder();
801 builder.setProcessingRule(false);
802 builder.setIgnore(false);
803 builder.setLinkDiverse(false);
804 builder.setNodeDiverse(false);
805 builder.setSrlgDiverse(false);
806 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
808 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
809 ByteBuf buf = Unpooled.buffer();
810 parser.serializeObject(builder.build(), buf);
811 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
813 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
815 builder.setProcessingRule(true);
816 builder.setLinkDiverse(true);
817 builder.setSrlgDiverse(true);
819 final List<RequestId> requestIDs = Lists.newArrayList();
820 requestIDs.add(new RequestId(0xFFFFFFFFL));
821 requestIDs.add(new RequestId(0x00000001L));
822 requestIDs.add(new RequestId(0x01234567L));
823 requestIDs.add(new RequestId(0x89ABCDEFL));
824 requestIDs.add(new RequestId(0xFEDCBA98L));
825 requestIDs.add(new RequestId(0x76543210L));
826 requestIDs.add(new RequestId(0x15825266L));
827 requestIDs.add(new RequestId(0x48120BBEL));
828 requestIDs.add(new RequestId(0x25FB7E52L));
829 requestIDs.add(new RequestId(0xB2F2546BL));
831 builder.setRequestsIds(requestIDs);
833 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
834 buf = Unpooled.buffer();
835 parser.serializeObject(builder.build(), buf);
836 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
839 parser.parseObject(new ObjectHeaderImpl(true, true), null);
841 } catch (final IllegalArgumentException e) {
842 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
845 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
847 } catch (final IllegalArgumentException e) {
848 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
853 public void testClassTypeObject() throws PCEPDeserializerException {
854 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
855 final ByteBuf result = Unpooled.wrappedBuffer(new byte[]{(byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04});
857 final ClassTypeBuilder builder = new ClassTypeBuilder();
858 builder.setProcessingRule(true);
859 builder.setIgnore(false);
860 builder.setClassType(new ClassType((short) 4));
862 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
863 final ByteBuf buf = Unpooled.buffer();
864 parser.serializeObject(builder.build(), buf);
865 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
868 parser.parseObject(new ObjectHeaderImpl(true, true), null);
870 } catch (final IllegalArgumentException e) {
871 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
874 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
876 } catch (final IllegalArgumentException e) {
877 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
882 public void testExcludeRouteObject() throws Exception {
883 final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
884 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
886 final XroBuilder builder = new XroBuilder();
887 builder.setProcessingRule(false);
888 builder.setIgnore(false);
889 builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
890 final List<Subobject> subs = Lists.newArrayList();
891 subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
892 new IpPrefixCaseBuilder().setIpPrefix(
893 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
894 Attribute.Node).build());
895 subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
896 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
897 builder.setSubobject(subs);
899 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
900 final ByteBuf buf = Unpooled.buffer();
901 parser.serializeObject(builder.build(), buf);
902 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
905 parser.parseObject(new ObjectHeaderImpl(true, true), null);
907 } catch (final IllegalArgumentException e) {
908 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
911 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
913 } catch (final IllegalArgumentException e) {
914 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
919 public void testPathKeyObject() throws Exception {
920 final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
921 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
923 final PathKeyBuilder builder = new PathKeyBuilder();
924 builder.setProcessingRule(true);
925 builder.setIgnore(false);
926 final List<PathKeys> list = Lists.newArrayList();
927 list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
928 new PceId(new byte[]{(byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00})).build());
929 builder.setPathKeys(list);
931 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
932 final ByteBuf buf = Unpooled.buffer();
933 parser.serializeObject(builder.build(), buf);
934 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
937 parser.parseObject(new ObjectHeaderImpl(true, true), null);
939 } catch (final IllegalArgumentException e) {
940 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
943 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
945 } catch (final IllegalArgumentException e) {
946 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
951 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
952 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
953 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
955 final OfBuilder builder = new OfBuilder();
956 builder.setProcessingRule(true);
957 builder.setIgnore(false);
958 builder.setCode(new OfId(4));
959 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
961 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
962 final ByteBuf buf = Unpooled.buffer();
963 parser.serializeObject(builder.build(), buf);
964 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
967 parser.parseObject(new ObjectHeaderImpl(true, true), null);
969 } catch (final IllegalArgumentException e) {
970 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
973 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
975 } catch (final IllegalArgumentException e) {
976 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
981 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
982 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
983 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
985 final GcBuilder builder = new GcBuilder();
986 builder.setProcessingRule(true);
987 builder.setIgnore(false);
988 builder.setMaxHop((short) 1);
989 builder.setMaxUtilization((short) 0);
990 builder.setMinUtilization((short) 100);
991 builder.setOverBookingFactor((short) 99);
992 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
994 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
995 final ByteBuf buf = Unpooled.buffer();
996 parser.serializeObject(builder.build(), buf);
997 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1000 parser.parseObject(new ObjectHeaderImpl(true, true), null);
1002 } catch (final IllegalArgumentException e) {
1003 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1006 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1008 } catch (final IllegalArgumentException e) {
1009 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1014 public void testIgnoreUknownObject() throws PCEPDeserializerException {
1015 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
1020 public void testUnrecognizedObjectType() throws PCEPDeserializerException {
1021 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
1022 assertNotNull(object);
1023 assertTrue(object instanceof UnknownObject);
1024 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
1028 public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1029 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1030 assertNotNull(object);
1031 assertTrue(object instanceof UnknownObject);
1032 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1036 public void testLspaObjectSerializerDefence() throws IOException {
1037 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1038 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1040 final LspaBuilder builder = new LspaBuilder();
1041 builder.setProcessingRule(true);
1042 builder.setIgnore(true);
1043 builder.setLocalProtectionDesired(false);
1045 final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1046 parser.serializeObject(builder.build(), buf);
1047 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1051 public void testEmptyEroObject() throws PCEPDeserializerException {
1052 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(7, 1,
1053 new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1054 assertNotNull(object);
1055 assertTrue(object instanceof Ero);
1056 final Ero eroObject = (Ero) object;
1057 assertTrue(eroObject.getSubobject().isEmpty());
1059 final ByteBuf buffer = Unpooled.buffer();
1060 this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1061 final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1062 assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1066 public void testCloseObjectWithVendorInformationTlv() throws PCEPDeserializerException {
1067 final byte[] closeBytes = {
1068 0x0f, 0x10, 0x00, 0x14,
1069 0x00, 0x00, 0x00, 0x05,
1070 /* vendor-information TLV */
1071 0x00, 0x07, 0x00, 0x08,
1072 /* enterprise number */
1073 0x00, 0x00, 0x00, 0x00,
1074 /* enterprise specific information */
1075 0x00, 0x00, 0x00, 0x05
1077 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1078 final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1080 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1081 final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1082 .setEnterpriseSpecificInformation(esInfo).build();
1083 final CCloseBuilder builder = new CCloseBuilder();
1084 builder.setProcessingRule(false);
1085 builder.setIgnore(false);
1086 builder.setReason((short) 5);
1087 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
1088 .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1090 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1092 final ByteBuf buf = Unpooled.buffer();
1093 parser.serializeObject(builder.build(), buf);
1094 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1098 public void testVendorInformationObject() throws PCEPDeserializerException {
1099 final byte[] viObjBytes = {
1100 /* vendor-information object */
1101 0x22, 0x10, 0x00, 0x0C,
1102 /* enterprise number */
1103 0x00, 0x00, 0x00, 0x00,
1104 /* enterprise specific information */
1105 0x00, 0x00, 0x00, 0x05
1107 final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1108 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1109 final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1110 .setEnterpriseSpecificInformation(esInfo).build();
1111 final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1112 result.readerIndex(8);
1113 final VendorInformationObject o = (VendorInformationObject) parser.parseObject(new ObjectHeaderImpl(false, false), result.readSlice(result.readableBytes()));
1114 assertEquals(viObj, o);
1116 final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1117 parser.serializeObject(viObj, buf);
1118 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1122 public void testMonitoringObject() throws PCEPDeserializerException {
1123 final byte[] monitoringBytes = {
1125 0x13, 0x10, 0x00, 0x0C,
1127 0x00, 0x00, 0x00, 0x01,
1128 /* monitoring-id=16 */
1129 0x00, 0x00, 0x00, 0x10
1131 final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
1132 final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
1133 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
1134 final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
1135 assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1137 final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
1138 parser.serializeObject(monitoring, buf);
1139 assertArrayEquals(monitoringBytes, buf.array());
1143 public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
1144 final byte[] pccIdReqBytes = {
1146 0x14, 0x10, 0x00, 0x08,
1148 0x7f, 0x00, 0x00, 0x01
1150 final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
1151 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1"))).build();
1152 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1153 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1155 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1156 parser.serializeObject(pccIdReq, buf);
1157 assertArrayEquals(pccIdReqBytes, buf.array());
1161 public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
1162 final byte[] pccIdReqBytes = {
1164 0x14, 0x20, 0x00, 0x14,
1166 0x00, 0x00, 0x00, 0x00,
1167 0x00, 0x00, 0x00, 0x00,
1168 0x00, 0x00, 0x00, 0x00,
1169 0x00, 0x00, 0x00, 0x01
1171 final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
1172 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv6AddressNoZone("::1"))).build();
1173 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1174 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1176 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1177 parser.serializeObject(pccIdReq, buf);
1178 assertArrayEquals(pccIdReqBytes, buf.array());
1182 public void testPceIdIPv4Object() throws PCEPDeserializerException {
1183 final byte[] pccIdReqBytes = {
1185 0x19, 0x10, 0x00, 0x08,
1187 0x7f, 0x00, 0x00, 0x01
1189 final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
1190 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pceId = new PceIdBuilder().setIpAddress(new IpAddressNoZone(
1191 new Ipv4AddressNoZone("127.0.0.1"))).build();
1192 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1193 assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1195 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1196 parser.serializeObject(pceId, buf);
1197 assertArrayEquals(pccIdReqBytes, buf.array());
1201 public void testPceIdIPv6Object() throws PCEPDeserializerException {
1202 final byte[] pccIdReqBytes = {
1204 0x19, 0x20, 0x00, 0x14,
1206 0x00, 0x00, 0x00, 0x00,
1207 0x00, 0x00, 0x00, 0x00,
1208 0x00, 0x00, 0x00, 0x00,
1209 0x00, 0x00, 0x00, 0x01
1211 final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
1212 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddressNoZone(
1213 new Ipv6AddressNoZone("::1"))).build();
1214 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1215 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1217 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1218 parser.serializeObject(pccIdReq, buf);
1219 assertArrayEquals(pccIdReqBytes, buf.array());
1223 public void testProcTimeObject() throws PCEPDeserializerException {
1224 final byte[] proctimeBytes = {
1226 0x1A, 0x10, 0x00, 0x1C,
1228 0x00, 0x00, 0x00, 0x01,
1229 /* current proc. time */
1230 0x00, 0x00, 0x00, 0x01,
1231 /* min proc. time */
1232 0x00, 0x00, 0x00, 0x02,
1234 0x00, 0x00, 0x00, 0x03,
1235 /* average proc time */
1236 0x00, 0x00, 0x00, 0x04,
1237 /* variance proc time */
1238 0x00, 0x00, 0x00, 0x05,
1240 final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
1241 final ProcTime procTime = new ProcTimeBuilder()
1243 .setAverageProcTime(4L)
1244 .setCurrentProcTime(1L)
1247 .setVarianceProcTime(5L).build();
1248 final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
1249 assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1251 final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
1252 parser.serializeObject(procTime, buf);
1253 assertArrayEquals(proctimeBytes, buf.array());
1257 public void testOverloadObject() throws PCEPDeserializerException {
1258 final byte[] overloadBytes = {
1260 0x1B, 0x10, 0x00, 0x08,
1261 /* overload duration */
1262 0x00, 0x00, 0x00, 0x78
1264 final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
1265 final Overload overload = new OverloadBuilder().setDuration(120).build();
1266 final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
1267 assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1269 final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
1270 parser.serializeObject(overload, buf);
1271 assertArrayEquals(overloadBytes, buf.array());
1275 public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
1277 final byte[] rpObjectWithPstTlvBytes = {0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
1278 (byte) 0xad, (byte) 0xbe, (byte) 0xef,
1280 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0};
1282 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
1283 final RpBuilder builder = new RpBuilder();
1284 builder.setProcessingRule(false);
1285 builder.setIgnore(false);
1286 builder.setReoptimization(true);
1287 builder.setBiDirectional(false);
1288 builder.setLoose(true);
1289 builder.setMakeBeforeBreak(true);
1290 builder.setOrder(false);
1291 builder.setPathKey(false);
1292 builder.setSupplyOf(false);
1293 builder.setFragmentation(false);
1294 builder.setP2mp(false);
1295 builder.setEroCompression(false);
1296 builder.setPriority((short) 5);
1297 builder.setRequestId(new RequestId(0xdeadbeefL));
1298 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setPathSetupType(
1299 new PathSetupTypeBuilder().setPst((short) 0).build()).build());
1301 final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
1302 assertEquals(builder.build(),
1303 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1304 final ByteBuf buf = Unpooled.buffer();
1305 parser.serializeObject(builder.build(), buf);
1306 assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
1310 public void testPCEPSecondaryExplicitRouteObjecParser() throws PCEPDeserializerException {
1312 final byte[] expected = {
1313 0x1d, 0x10, 0x0, 0x08, 0x20, 0x4, 0x12, 0x34
1316 final PCEPSecondaryExplicitRouteObjecParser parser
1317 = new PCEPSecondaryExplicitRouteObjecParser(this.ctx.getEROSubobjectHandlerRegistry());
1318 final SeroBuilder builder = new SeroBuilder();
1319 builder.setProcessingRule(false);
1320 builder.setIgnore(false);
1321 builder.setSubobject(Collections.singletonList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
1322 .yang.pcep.types.rev131005.secondary.explicit.route.object.sero.SubobjectBuilder()
1323 .setSubobjectType(new AsNumberCaseBuilder()
1324 .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build())
1328 final ByteBuf result = Unpooled.wrappedBuffer(expected);
1329 assertEquals(builder.build(),
1330 parser.parseObject(new ObjectHeaderImpl(false, false),
1331 result.slice(4, result.readableBytes() - 4)));
1332 final ByteBuf buf = Unpooled.buffer();
1333 parser.serializeObject(builder.build(), buf);
1334 assertArrayEquals(expected, ByteArray.getAllBytes(buf));
1338 public void testPCEPSecondaryRecordRouteObjecParser() throws PCEPDeserializerException {
1340 final byte[] expected = {
1341 0x1e, 0x10, 0x0, 0x0c,
1342 0x1, 0x8, (byte) 0xff, (byte) 0xff,
1343 (byte) 0xff, (byte) 0xff, 0x20, 0x0
1346 final PCEPSecondaryRecordRouteObjectParser parser
1347 = new PCEPSecondaryRecordRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
1348 final SrroBuilder builder = new SrroBuilder();
1349 builder.setProcessingRule(false);
1350 builder.setIgnore(false);
1351 builder.setSubobject(Collections.singletonList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
1352 .yang.pcep.types.rev131005.secondary.reported.route.object.srro.SubobjectBuilder().setSubobjectType(
1353 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
1354 .subobject.type.IpPrefixCaseBuilder()
1355 .setIpPrefix(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820
1356 .record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
1357 new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build())
1358 .setProtectionAvailable(false).setProtectionInUse(false).build()));
1360 final ByteBuf result = Unpooled.wrappedBuffer(expected);
1361 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
1362 result.slice(4, result.readableBytes() - 4)));
1363 final ByteBuf buf = Unpooled.buffer();
1364 parser.serializeObject(builder.build(), buf);
1365 assertArrayEquals(expected, ByteArray.getAllBytes(buf));