2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.impl;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
17 import com.google.common.collect.Lists;
18 import com.google.common.primitives.UnsignedBytes;
19 import io.netty.buffer.ByteBuf;
20 import io.netty.buffer.Unpooled;
21 import java.io.IOException;
22 import java.util.List;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
26 import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
27 import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
28 import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
29 import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIpv4ObjectParser;
30 import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIpv6ObjectParser;
31 import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
32 import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser;
33 import org.opendaylight.protocol.pcep.impl.object.PCEPExistingBandwidthObjectParser;
34 import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
35 import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
36 import org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser;
37 import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
38 import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
39 import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
40 import org.opendaylight.protocol.pcep.impl.object.PCEPMonitoringObjectParser;
41 import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
42 import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
43 import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
44 import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
45 import org.opendaylight.protocol.pcep.impl.object.PCEPOverloadObjectParser;
46 import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
47 import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv4ObjectParser;
48 import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv6ObjectParser;
49 import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv4ObjectParser;
50 import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv6ObjectParser;
51 import org.opendaylight.protocol.pcep.impl.object.PCEPProcTimeObjectParser;
52 import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
53 import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
54 import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
55 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
56 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
57 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
58 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
59 import org.opendaylight.protocol.pcep.spi.UnknownObject;
60 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
61 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
62 import org.opendaylight.protocol.util.ByteArray;
63 import org.opendaylight.protocol.util.Ipv4Util;
64 import org.opendaylight.protocol.util.Ipv6Util;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
68 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
69 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
137 public class PCEPObjectParserTest {
139 private TlvRegistry tlvRegistry;
141 private VendorInformationTlvRegistry viTlvRegistry;
143 private SimplePCEPExtensionProviderContext ctx;
144 private Activator act;
145 private TestVendorInformationActivator viAct;
148 public void setUp() {
149 this.ctx = new SimplePCEPExtensionProviderContext();
150 this.act = new Activator();
151 this.viAct = new TestVendorInformationActivator();
152 this.act.start(this.ctx);
153 this.viAct.start(this.ctx);
154 this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
155 this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
159 public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
160 final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
161 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
163 final OpenBuilder builder = new OpenBuilder();
164 builder.setProcessingRule(false);
165 builder.setIgnore(false);
166 builder.setVersion(new ProtocolVersion((short) 1));
167 builder.setKeepalive((short) 30);
168 builder.setDeadTimer((short) 120);
169 builder.setSessionId((short) 1);
171 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
173 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
174 final ByteBuf buf = Unpooled.buffer();
175 parser.serializeObject(builder.build(), buf);
176 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
179 parser.parseObject(new ObjectHeaderImpl(true, true), null);
181 } catch (final IllegalArgumentException e) {
182 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
185 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
187 } catch (final IllegalArgumentException e) {
188 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
193 public void testCloseObject() throws IOException, PCEPDeserializerException {
194 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
195 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
197 final CCloseBuilder builder = new CCloseBuilder();
198 builder.setProcessingRule(false);
199 builder.setIgnore(false);
200 builder.setReason((short) 5);
201 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
203 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
204 final ByteBuf buf = Unpooled.buffer();
205 parser.serializeObject(builder.build(), buf);
206 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
209 parser.parseObject(new ObjectHeaderImpl(true, true), null);
211 } catch (final IllegalArgumentException e) {
212 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
215 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
217 } catch (final IllegalArgumentException e) {
218 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
223 public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
224 final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
225 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
227 final LoadBalancingBuilder builder = new LoadBalancingBuilder();
228 builder.setProcessingRule(true);
229 builder.setIgnore(false);
230 builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
231 builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
233 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
234 final ByteBuf buf = Unpooled.buffer();
235 parser.serializeObject(builder.build(), buf);
236 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
239 parser.parseObject(new ObjectHeaderImpl(true, true), null);
241 } catch (final IllegalArgumentException e) {
242 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
245 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
247 } catch (final IllegalArgumentException e) {
248 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
253 public void testERObject() throws Exception {
254 final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
255 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
257 final EroBuilder builder = new EroBuilder();
258 builder.setProcessingRule(false);
259 builder.setIgnore(false);
260 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
261 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
262 true).setSubobjectType(
263 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
264 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
265 true).setSubobjectType(
266 new IpPrefixCaseBuilder().setIpPrefix(
267 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
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 UnnumberedCaseBuilder().setUnnumbered(
271 new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
272 builder.setSubobject(subs);
274 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
275 final ByteBuf buf = Unpooled.buffer();
276 parser.serializeObject(builder.build(), buf);
277 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
280 parser.parseObject(new ObjectHeaderImpl(true, true), null);
282 } catch (final IllegalArgumentException e) {
283 assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
288 public void testIRObject() throws Exception {
289 final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
290 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
291 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
292 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
294 final IroBuilder builder = new IroBuilder();
295 builder.setProcessingRule(false);
296 builder.setIgnore(false);
297 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists.newArrayList();
298 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
299 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).build());
300 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
301 new IpPrefixCaseBuilder().setIpPrefix(
302 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).build());
303 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
304 new IpPrefixCaseBuilder().setIpPrefix(
305 new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).build());
306 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
307 new UnnumberedCaseBuilder().setUnnumbered(
308 new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).build());
309 builder.setSubobject(subs);
311 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
312 final ByteBuf buf = Unpooled.buffer();
313 parser.serializeObject(builder.build(), buf);
314 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
317 parser.parseObject(new ObjectHeaderImpl(true, true), null);
319 } catch (final IllegalArgumentException e) {
320 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
323 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
325 } catch (final IllegalArgumentException e) {
326 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
331 public void testRRObject() throws Exception {
332 final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
333 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
334 final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
335 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
337 final RroBuilder builder = new RroBuilder();
338 builder.setProcessingRule(false);
339 builder.setIgnore(false);
340 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
341 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
342 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
343 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
344 new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
346 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
347 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
348 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
349 new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
351 subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
352 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
353 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
354 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
356 builder.setSubobject(subs);
358 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
359 final ByteBuf buf = Unpooled.buffer();
360 parser.serializeObject(builder.build(), buf);
361 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
364 parser.parseObject(new ObjectHeaderImpl(true, true), null);
366 } catch (final IllegalArgumentException e) {
367 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
370 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
372 } catch (final IllegalArgumentException e) {
373 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
378 public void testBandwidthObject() throws IOException, PCEPDeserializerException {
379 final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
380 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
382 final BandwidthBuilder builder = new BandwidthBuilder();
383 builder.setProcessingRule(true);
384 builder.setIgnore(true);
385 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
387 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
388 final ByteBuf buf = Unpooled.buffer();
389 parser.serializeObject(builder.build(), buf);
390 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
393 parser.parseObject(new ObjectHeaderImpl(true, true), null);
395 } catch (final IllegalArgumentException e) {
396 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
399 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
401 } catch (final IllegalArgumentException e) {
402 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
407 public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
408 final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
409 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
411 final BandwidthBuilder builder = new BandwidthBuilder();
412 builder.setProcessingRule(true);
413 builder.setIgnore(true);
414 builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
416 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
417 final ByteBuf buf = Unpooled.buffer();
418 parser.serializeObject(builder.build(), buf);
419 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
422 parser.parseObject(new ObjectHeaderImpl(true, true), null);
424 } catch (final IllegalArgumentException e) {
425 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
428 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
430 } catch (final IllegalArgumentException e) {
431 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
436 public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
437 final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
438 final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
440 final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
441 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
443 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
444 builder.setProcessingRule(true);
445 builder.setIgnore(false);
446 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
447 new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
448 Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
450 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
451 final ByteBuf buf = Unpooled.buffer();
452 parser.serializeObject(builder.build(), buf);
453 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
456 parser.parseObject(new ObjectHeaderImpl(true, true), null);
458 } catch (final IllegalArgumentException e) {
459 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
462 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
464 } catch (final IllegalArgumentException e) {
465 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
470 public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
471 final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
472 (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
473 final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
474 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
476 final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
477 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
479 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
480 builder.setProcessingRule(true);
481 builder.setIgnore(false);
482 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
483 new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
484 Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
486 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
487 final ByteBuf buf = Unpooled.buffer();
488 parser.serializeObject(builder.build(), buf);
489 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
492 parser.parseObject(new ObjectHeaderImpl(true, true), null);
494 } catch (final IllegalArgumentException e) {
495 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
498 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
500 } catch (final IllegalArgumentException e) {
501 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
506 public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
507 final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
508 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
510 final ErrorObjectBuilder builder = new ErrorObjectBuilder();
511 builder.setProcessingRule(true);
512 builder.setIgnore(true);
513 builder.setType((short) 1);
514 builder.setValue((short) 1);
516 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
517 ByteBuf buf = Unpooled.buffer();
518 parser.serializeObject(builder.build(), buf);
519 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
521 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
523 builder.setType((short) 7);
524 builder.setValue((short) 0);
525 builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
527 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
528 buf = Unpooled.buffer();
529 parser.serializeObject(builder.build(), buf);
530 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
533 parser.parseObject(new ObjectHeaderImpl(true, true), null);
535 } catch (final IllegalArgumentException e) {
536 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
539 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
541 } catch (final IllegalArgumentException e) {
542 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
547 public void testLspaObject() throws IOException, PCEPDeserializerException {
548 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
549 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
551 final LspaBuilder builder = new LspaBuilder();
552 builder.setProcessingRule(true);
553 builder.setIgnore(true);
554 builder.setExcludeAny(new AttributeFilter(0L));
555 builder.setIncludeAny(new AttributeFilter(0L));
556 builder.setIncludeAll(new AttributeFilter(0L));
557 builder.setHoldPriority((short) 0);
558 builder.setSetupPriority((short) 0);
559 builder.setLocalProtectionDesired(false);
560 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
562 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
563 ByteBuf buf = Unpooled.buffer();
564 parser.serializeObject(builder.build(), buf);
565 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
567 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
569 builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
570 builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
571 builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
572 builder.setHoldPriority((short) 0xFF);
573 builder.setSetupPriority((short) 0xFF);
574 builder.setLocalProtectionDesired(true);
576 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
577 buf = Unpooled.buffer();
578 parser.serializeObject(builder.build(), buf);
579 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
582 parser.parseObject(new ObjectHeaderImpl(true, true), null);
584 } catch (final IllegalArgumentException e) {
585 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
588 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
590 } catch (final IllegalArgumentException e) {
591 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
596 public void testMetricObject() throws IOException, PCEPDeserializerException {
597 final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
598 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin"));
600 final MetricBuilder builder = new MetricBuilder();
601 builder.setProcessingRule(true);
602 builder.setIgnore(true);
603 builder.setComputed(false);
604 builder.setBound(false);
605 builder.setMetricType((short) 1);
606 builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
608 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
609 ByteBuf buf = Unpooled.buffer();
610 parser.serializeObject(builder.build(), buf);
611 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
613 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin"));
615 builder.setComputed(true);
616 builder.setBound(false);
617 builder.setMetricType((short) 2);
618 builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
620 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
621 buf = Unpooled.buffer();
622 parser.serializeObject(builder.build(), buf);
623 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
626 parser.parseObject(new ObjectHeaderImpl(true, true), null);
628 } catch (final IllegalArgumentException e) {
629 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
632 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
634 } catch (final IllegalArgumentException e) {
635 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
640 public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
641 final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
642 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
644 final NoPathBuilder builder = new NoPathBuilder();
645 builder.setProcessingRule(true);
646 builder.setIgnore(true);
647 builder.setNatureOfIssue((short) 1);
648 builder.setUnsatisfiedConstraints(true);
649 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());
651 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
652 ByteBuf buf = Unpooled.buffer();
653 parser.serializeObject(builder.build(), buf);
654 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
656 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
658 builder.setNatureOfIssue((short) 0);
659 builder.setUnsatisfiedConstraints(false);
661 final NoPathVectorBuilder b = new NoPathVectorBuilder();
662 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));
663 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(
666 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
667 buf = Unpooled.buffer();
668 parser.serializeObject(builder.build(), buf);
669 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
672 parser.parseObject(new ObjectHeaderImpl(true, true), null);
674 } catch (final IllegalArgumentException e) {
675 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
678 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
680 } catch (final IllegalArgumentException e) {
681 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
686 public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
687 final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
688 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
690 final CNotificationBuilder builder = new CNotificationBuilder();
691 builder.setProcessingRule(true);
692 builder.setIgnore(true);
693 builder.setType((short) 0xff);
694 builder.setValue((short) 0xff);
696 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
697 ByteBuf buf = Unpooled.buffer();
698 parser.serializeObject(builder.build(), buf);
699 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
701 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
703 builder.setType((short) 2);
704 builder.setValue((short) 1);
705 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
706 new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
708 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
709 buf = Unpooled.buffer();
710 parser.serializeObject(builder.build(), buf);
711 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
714 parser.parseObject(new ObjectHeaderImpl(true, true), null);
716 } catch (final IllegalArgumentException e) {
717 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
720 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
722 } catch (final IllegalArgumentException e) {
723 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
728 public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
729 final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
730 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
732 final RpBuilder builder = new RpBuilder();
733 builder.setProcessingRule(true);
734 builder.setIgnore(true);
735 builder.setReoptimization(true);
736 builder.setBiDirectional(false);
737 builder.setLoose(true);
738 builder.setMakeBeforeBreak(true);
739 builder.setOrder(false);
740 builder.setPathKey(false);
741 builder.setSupplyOf(false);
742 builder.setFragmentation(false);
743 builder.setP2mp(false);
744 builder.setEroCompression(false);
745 builder.setPriority((short) 5);
746 builder.setRequestId(new RequestId(0xdeadbeefL));
747 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
749 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
750 ByteBuf buf = Unpooled.buffer();
751 parser.serializeObject(builder.build(), buf);
752 assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
754 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
756 builder.setReoptimization(false);
757 builder.setFragmentation(true);
758 builder.setEroCompression(true);
760 final OrderBuilder b = new OrderBuilder();
761 b.setDelete(0xffffffffL);
764 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
767 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
768 buf = Unpooled.buffer();
769 parser.serializeObject(builder.build(), buf);
770 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
773 parser.parseObject(new ObjectHeaderImpl(true, true), null);
775 } catch (final IllegalArgumentException e) {
776 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
779 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
781 } catch (final IllegalArgumentException e) {
782 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
787 public void testSvecObject() throws IOException, PCEPDeserializerException {
788 final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
789 ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
791 final SvecBuilder builder = new SvecBuilder();
792 builder.setProcessingRule(false);
793 builder.setIgnore(false);
794 builder.setLinkDiverse(false);
795 builder.setNodeDiverse(false);
796 builder.setSrlgDiverse(false);
797 builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
799 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
800 ByteBuf buf = Unpooled.buffer();
801 parser.serializeObject(builder.build(), buf);
802 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
804 result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
806 builder.setProcessingRule(true);
807 builder.setLinkDiverse(true);
808 builder.setSrlgDiverse(true);
810 final List<RequestId> requestIDs = Lists.newArrayList();
811 requestIDs.add(new RequestId(0xFFFFFFFFL));
812 requestIDs.add(new RequestId(0x00000001L));
813 requestIDs.add(new RequestId(0x01234567L));
814 requestIDs.add(new RequestId(0x89ABCDEFL));
815 requestIDs.add(new RequestId(0xFEDCBA98L));
816 requestIDs.add(new RequestId(0x76543210L));
817 requestIDs.add(new RequestId(0x15825266L));
818 requestIDs.add(new RequestId(0x48120BBEL));
819 requestIDs.add(new RequestId(0x25FB7E52L));
820 requestIDs.add(new RequestId(0xB2F2546BL));
822 builder.setRequestsIds(requestIDs);
824 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), 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 testClassTypeObject() throws PCEPDeserializerException {
845 final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
846 final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
848 final ClassTypeBuilder builder = new ClassTypeBuilder();
849 builder.setProcessingRule(true);
850 builder.setIgnore(false);
851 builder.setClassType(new ClassType((short) 4));
853 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
854 final ByteBuf buf = Unpooled.buffer();
855 parser.serializeObject(builder.build(), buf);
856 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
859 parser.parseObject(new ObjectHeaderImpl(true, true), null);
861 } catch (final IllegalArgumentException e) {
862 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
865 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
867 } catch (final IllegalArgumentException e) {
868 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
873 public void testExcludeRouteObject() throws Exception {
874 final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
875 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
877 final XroBuilder builder = new XroBuilder();
878 builder.setProcessingRule(false);
879 builder.setIgnore(false);
880 builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
881 final List<Subobject> subs = Lists.newArrayList();
882 subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
883 new IpPrefixCaseBuilder().setIpPrefix(
884 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
885 Attribute.Node).build());
886 subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
887 new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
888 builder.setSubobject(subs);
890 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
891 final ByteBuf buf = Unpooled.buffer();
892 parser.serializeObject(builder.build(), buf);
893 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
896 parser.parseObject(new ObjectHeaderImpl(true, true), null);
898 } catch (final IllegalArgumentException e) {
899 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
902 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
904 } catch (final IllegalArgumentException e) {
905 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
910 public void testPathKeyObject() throws Exception {
911 final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
912 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
914 final PathKeyBuilder builder = new PathKeyBuilder();
915 builder.setProcessingRule(true);
916 builder.setIgnore(false);
917 final List<PathKeys> list = Lists.newArrayList();
918 list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
919 new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
920 builder.setPathKeys(list);
922 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
923 final ByteBuf buf = Unpooled.buffer();
924 parser.serializeObject(builder.build(), buf);
925 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
928 parser.parseObject(new ObjectHeaderImpl(true, true), null);
930 } catch (final IllegalArgumentException e) {
931 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
934 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
936 } catch (final IllegalArgumentException e) {
937 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
942 public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
943 final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
944 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
946 final OfBuilder builder = new OfBuilder();
947 builder.setProcessingRule(true);
948 builder.setIgnore(false);
949 builder.setCode(new OfId(4));
950 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
952 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
953 final ByteBuf buf = Unpooled.buffer();
954 parser.serializeObject(builder.build(), buf);
955 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
958 parser.parseObject(new ObjectHeaderImpl(true, true), null);
960 } catch (final IllegalArgumentException e) {
961 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
964 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
966 } catch (final IllegalArgumentException e) {
967 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
972 public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
973 final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
974 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
976 final GcBuilder builder = new GcBuilder();
977 builder.setProcessingRule(true);
978 builder.setIgnore(false);
979 builder.setMaxHop((short) 1);
980 builder.setMaxUtilization((short) 0);
981 builder.setMinUtilization((short) 100);
982 builder.setOverBookingFactor((short) 99);
983 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
985 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
986 final ByteBuf buf = Unpooled.buffer();
987 parser.serializeObject(builder.build(), buf);
988 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
991 parser.parseObject(new ObjectHeaderImpl(true, true), null);
993 } catch (final IllegalArgumentException e) {
994 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
997 parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
999 } catch (final IllegalArgumentException e) {
1000 assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
1005 public void testIgnoreUknownObject() throws PCEPDeserializerException {
1006 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
1011 public void testUnrecognizedObjectType() throws PCEPDeserializerException {
1012 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
1013 assertNotNull(object);
1014 assertTrue(object instanceof UnknownObject);
1015 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
1019 public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
1020 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
1021 assertNotNull(object);
1022 assertTrue(object instanceof UnknownObject);
1023 assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
1027 public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
1028 final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
1029 final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
1031 final LspaBuilder builder = new LspaBuilder();
1032 builder.setProcessingRule(true);
1033 builder.setIgnore(true);
1034 builder.setLocalProtectionDesired(false);
1036 final ByteBuf buf = Unpooled.buffer(result.readableBytes());
1037 parser.serializeObject(builder.build(), buf);
1038 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1042 public void testEmptyEroObject() throws PCEPDeserializerException {
1043 final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
1044 assertNotNull(object);
1045 assertTrue(object instanceof Ero);
1046 final Ero eroObject = (Ero) object;
1047 assertTrue(eroObject.getSubobject().isEmpty());
1049 final ByteBuf buffer = Unpooled.buffer();
1050 this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
1051 final byte[] expected = {0x07, 0x13, 0x00, 0x04};
1052 assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
1056 public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
1057 final byte[] closeBytes = {
1058 0x0f, 0x10, 0x00, 0x14,
1059 0x00, 0x00, 0x00, 0x05,
1060 /* vendor-information TLV */
1061 0x00, 0x07, 0x00, 0x08,
1062 /* enterprise number */
1063 0x00, 0x00, 0x00, 0x00,
1064 /* enterprise specific information */
1065 0x00, 0x00, 0x00, 0x05
1067 final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
1068 final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
1070 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1071 final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1072 .setEnterpriseSpecificInformation(esInfo).build();
1073 final CCloseBuilder builder = new CCloseBuilder();
1074 builder.setProcessingRule(false);
1075 builder.setIgnore(false);
1076 builder.setReason((short) 5);
1077 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
1078 .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
1080 assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1082 final ByteBuf buf = Unpooled.buffer();
1083 parser.serializeObject(builder.build(), buf);
1084 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1088 public void testVendorInformationObject() throws PCEPDeserializerException {
1089 final byte[] viObjBytes = {
1090 /* vendor-information object */
1091 0x22, 0x10, 0x00, 0x0C,
1092 /* enterprise number */
1093 0x00, 0x00, 0x00, 0x00,
1094 /* enterprise specific information */
1095 0x00, 0x00, 0x00, 0x05
1097 final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
1098 final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
1099 final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
1100 .setEnterpriseSpecificInformation(esInfo).build();
1101 final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
1103 assertEquals(viObj, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1105 final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
1106 parser.serializeObject(viObj, buf);
1107 assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
1111 public void testMonitoringObject() throws PCEPDeserializerException {
1112 final byte[] monitoringBytes = {
1114 0x13, 0x10, 0x00, 0x0C,
1116 0x00, 0x00, 0x00, 0x01,
1117 /* monitoring-id=16 */
1118 0x00, 0x00, 0x00, 0x10
1120 final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
1121 final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
1122 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
1123 final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
1124 assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1126 final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
1127 parser.serializeObject(monitoring, buf);
1128 assertArrayEquals(monitoringBytes, buf.array());
1132 public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
1133 final byte[] pccIdReqBytes = {
1135 0x14, 0x10, 0x00, 0x08,
1137 0x7f, 0x00, 0x00, 0x01
1139 final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
1140 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
1141 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1142 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1144 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1145 parser.serializeObject(pccIdReq, buf);
1146 assertArrayEquals(pccIdReqBytes, buf.array());
1150 public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
1151 final byte[] pccIdReqBytes = {
1153 0x14, 0x20, 0x00, 0x14,
1155 0x00, 0x00, 0x00, 0x00,
1156 0x00, 0x00, 0x00, 0x00,
1157 0x00, 0x00, 0x00, 0x00,
1158 0x00, 0x00, 0x00, 0x01
1160 final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
1161 final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build();
1162 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1163 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1165 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1166 parser.serializeObject(pccIdReq, buf);
1167 assertArrayEquals(pccIdReqBytes, buf.array());
1171 public void testPceIdIPv4Object() throws PCEPDeserializerException {
1172 final byte[] pccIdReqBytes = {
1174 0x19, 0x10, 0x00, 0x08,
1176 0x7f, 0x00, 0x00, 0x01
1178 final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
1179 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pceId = new PceIdBuilder().setIpAddress(new IpAddress(
1180 new Ipv4Address("127.0.0.1"))).build();
1181 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1182 assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1184 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1185 parser.serializeObject(pceId, buf);
1186 assertArrayEquals(pccIdReqBytes, buf.array());
1190 public void testPceIdIPv6Object() throws PCEPDeserializerException {
1191 final byte[] pccIdReqBytes = {
1193 0x19, 0x20, 0x00, 0x14,
1195 0x00, 0x00, 0x00, 0x00,
1196 0x00, 0x00, 0x00, 0x00,
1197 0x00, 0x00, 0x00, 0x00,
1198 0x00, 0x00, 0x00, 0x01
1200 final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
1201 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddress(
1202 new Ipv6Address("::1"))).build();
1203 final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
1204 assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1206 final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
1207 parser.serializeObject(pccIdReq, buf);
1208 assertArrayEquals(pccIdReqBytes, buf.array());
1212 public void testProcTimeObject() throws PCEPDeserializerException {
1213 final byte[] proctimeBytes = {
1215 0x1A, 0x10, 0x00, 0x1C,
1217 0x00, 0x00, 0x00, 0x01,
1218 /* current proc. time */
1219 0x00, 0x00, 0x00, 0x01,
1220 /* min proc. time */
1221 0x00, 0x00, 0x00, 0x02,
1223 0x00, 0x00, 0x00, 0x03,
1224 /* average proc time */
1225 0x00, 0x00, 0x00, 0x04,
1226 /* variance proc time */
1227 0x00, 0x00, 0x00, 0x05,
1229 final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
1230 final ProcTime procTime = new ProcTimeBuilder()
1232 .setAverageProcTime(4L)
1233 .setCurrentProcTime(1L)
1236 .setVarianceProcTime(5L).build();
1237 final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
1238 assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1240 final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
1241 parser.serializeObject(procTime, buf);
1242 assertArrayEquals(proctimeBytes, buf.array());
1246 public void testOverloadObject() throws PCEPDeserializerException {
1247 final byte[] overloadBytes = {
1249 0x1B, 0x10, 0x00, 0x08,
1250 /* overload duration */
1251 0x00, 0x00, 0x00, 0x78
1253 final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
1254 final Overload overload = new OverloadBuilder().setDuration(120).build();
1255 final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
1256 assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
1258 final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
1259 parser.serializeObject(overload, buf);
1260 assertArrayEquals(overloadBytes, buf.array());