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 io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
15 import java.io.IOException;
16 import java.math.BigInteger;
17 import java.util.List;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
22 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
23 import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
24 import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
25 import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
26 import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
27 import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
28 import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
29 import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageParser;
30 import org.opendaylight.protocol.pcep.impl.message.PCEPUpdateRequestMessageParser;
31 import org.opendaylight.protocol.pcep.impl.message.PcinitiateMessageParser;
32 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
33 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
34 import org.opendaylight.protocol.util.ByteArray;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcinitiateBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcntfBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrepBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrptBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcupdBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OperationalStatus;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PlspId;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobjects;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectsBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.Metrics;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.db.version.tlv.LspDbVersion;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.db.version.tlv.LspDbVersionBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.Lsp;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.LspBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.RequestBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.PcinitiateMessageBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.Requests;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.RequestsBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.PcntfMessageBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.NotificationsBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Rps;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.RpsBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessageBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.Replies;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.RepliesBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.FailureBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.SuccessBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPath;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPathBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success.Paths;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success.PathsBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessageBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.Reports;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.ReportsBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.reports.PathBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.PcupdMessageBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.Updates;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.UpdatesBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.srp.object.Srp;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.srp.object.SrpBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful.Flags;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.StatefulBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumber;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.Unnumbered;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedBuilder;
123 import com.google.common.collect.Lists;
125 public class PCEPValidatorTest {
127 private ObjectHandlerRegistry objectRegistry;
131 private NoPath noPath;
133 private Bandwidth bandwidth;
134 private Metrics metrics;
142 private AsNumber eroASSubobject;
143 private Unnumbered rroUnnumberedSub;
146 public void setUp() throws Exception {
147 this.objectRegistry = ServiceLoaderPCEPExtensionProviderContext.create().getObjectHandlerRegistry();
148 final RpBuilder rpBuilder = new RpBuilder();
149 rpBuilder.setProcessingRule(false);
150 rpBuilder.setIgnore(false);
151 rpBuilder.setReoptimization(false);
152 rpBuilder.setBiDirectional(false);
153 rpBuilder.setLoose(true);
154 rpBuilder.setMakeBeforeBreak(false);
155 rpBuilder.setOrder(false);
156 rpBuilder.setSupplyOf(false);
157 rpBuilder.setFragmentation(false);
158 rpBuilder.setP2mp(false);
159 rpBuilder.setEroCompression(false);
160 rpBuilder.setPriority((short) 1);
161 rpBuilder.setRequestId(new RequestId(10L));
162 this.rp = rpBuilder.build();
164 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder openBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder();
165 openBuilder.setProcessingRule(false);
166 openBuilder.setIgnore(false);
167 openBuilder.setDeadTimer((short) 1);
168 openBuilder.setKeepalive((short) 1);
169 openBuilder.setSessionId((short) 0);
170 openBuilder.setVersion(new ProtocolVersion((short) 1));
171 openBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
172 this.open = openBuilder.build();
174 final NoPathBuilder npbuilder = new NoPathBuilder();
175 npbuilder.setProcessingRule(false);
176 npbuilder.setIgnore(false);
177 npbuilder.setNatureOfIssue((short) 0);
178 npbuilder.setUnsatisfiedConstraints(false);
179 this.noPath = npbuilder.build();
181 final LspaBuilder lspaBuilder = new LspaBuilder();
182 lspaBuilder.setProcessingRule(false);
183 lspaBuilder.setIgnore(false);
184 lspaBuilder.setLocalProtectionDesired(false);
185 lspaBuilder.setHoldPriority((short) 0);
186 lspaBuilder.setSetupPriority((short) 0);
187 lspaBuilder.setExcludeAny(new AttributeFilter(0L));
188 lspaBuilder.setIncludeAll(new AttributeFilter(0L));
189 lspaBuilder.setIncludeAny(new AttributeFilter(0L));
190 this.lspa = lspaBuilder.build();
192 final BandwidthBuilder bBuilder = new BandwidthBuilder();
193 bBuilder.setIgnore(false);
194 bBuilder.setProcessingRule(false);
195 bBuilder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth(new Float32(new byte[4])));
196 this.bandwidth = bBuilder.build();
198 final MetricBuilder mBuilder = new MetricBuilder();
199 mBuilder.setIgnore(false);
200 mBuilder.setProcessingRule(false);
201 mBuilder.setComputed(false);
202 mBuilder.setBound(false);
203 mBuilder.setMetricType((short) 1);
204 mBuilder.setValue(new Float32(new byte[4]));
205 this.metrics = new MetricsBuilder().setMetric(mBuilder.build()).build();
207 this.eroASSubobject = new AsNumberBuilder().setAsNumber(
208 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber(0xFFFFL)).build();
210 this.rroUnnumberedSub = new UnnumberedBuilder().setRouterId(0x00112233L).setInterfaceId(0x00ff00ffL).build();
212 final IroBuilder iroBuilder = new IroBuilder();
213 iroBuilder.setIgnore(false);
214 iroBuilder.setProcessingRule(false);
215 final List<Subobjects> iroSubs = Lists.newArrayList();
216 iroSubs.add(new SubobjectsBuilder().setSubobjectType(this.eroASSubobject).build());
217 iroBuilder.setSubobjects(iroSubs);
218 this.iro = iroBuilder.build();
220 final EroBuilder eroBuilder = new EroBuilder();
221 eroBuilder.setIgnore(false);
222 eroBuilder.setProcessingRule(false);
223 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobjects> eroSubs = Lists.newArrayList();
224 eroSubs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectsBuilder().setSubobjectType(
225 this.eroASSubobject).setLoose(false).build());
226 eroBuilder.setSubobjects(eroSubs);
227 this.ero = eroBuilder.build();
229 final RroBuilder rroBuilder = new RroBuilder();
230 rroBuilder.setIgnore(false);
231 rroBuilder.setProcessingRule(false);
232 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobjects> rroSubs = Lists.newArrayList();
233 rroSubs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectsBuilder().setSubobjectType(
234 this.rroUnnumberedSub).setProtectionAvailable(false).setProtectionInUse(false).build());
235 rroBuilder.setSubobjects(rroSubs);
236 this.rro = rroBuilder.build();
238 final OfBuilder ofBuilder = new OfBuilder();
239 ofBuilder.setIgnore(false);
240 ofBuilder.setProcessingRule(false);
241 ofBuilder.setCode(new OfId(0));
242 this.of = ofBuilder.build();
244 final SrpBuilder srpBuilder = new SrpBuilder();
245 srpBuilder.setIgnore(false);
246 srpBuilder.setProcessingRule(false);
247 srpBuilder.setOperationId(new SrpIdNumber(1L));
248 this.srp = srpBuilder.build();
250 final LspBuilder lspBuilder = new LspBuilder();
251 lspBuilder.setIgnore(false);
252 lspBuilder.setProcessingRule(false);
253 lspBuilder.setAdministrative(false);
254 lspBuilder.setDelegate(false);
255 lspBuilder.setPlspId(new PlspId(0L));
256 lspBuilder.setOperational(OperationalStatus.Down);
257 lspBuilder.setSync(false);
258 lspBuilder.setRemove(false);
259 lspBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.lsp.TlvsBuilder().build());
260 this.lsp = lspBuilder.build();
264 public void testOpenMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
265 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin");
266 final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.objectRegistry);
267 final OpenMessageBuilder builder = new OpenMessageBuilder();
269 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder();
270 b.setProcessingRule(false);
272 b.setVersion(new ProtocolVersion((short) 1));
273 b.setKeepalive((short) 30);
274 b.setDeadTimer((short) 120);
275 b.setSessionId((short) 1);
276 final Stateful tlv1 = new StatefulBuilder().setFlags(new Flags(true, false, true)).build();
277 final LspDbVersion tlv2 = new LspDbVersionBuilder().setVersion(BigInteger.valueOf(0x80L)).build();
278 b.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().setStateful(
279 tlv1).setLspDbVersion(tlv2).build());
280 builder.setOpen(b.build());
282 assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result));
283 final ByteBuf buf = Unpooled.buffer(result.length);
284 parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf);
285 assertArrayEquals(result, buf.array());
289 public void testKeepAliveMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
290 final byte[] result = new byte[] { 0, 0, 0, 0 };
291 final PCEPKeepAliveMessageParser parser = new PCEPKeepAliveMessageParser(this.objectRegistry);
292 final KeepaliveBuilder builder = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build());
294 assertEquals(builder.build(), parser.parseMessage(result));
295 final ByteBuf buf = Unpooled.buffer(result.length);
296 parser.serializeMessage(builder.build(), buf);
297 assertArrayEquals(result, buf.array());
301 public void testCloseMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
302 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPCloseMessage1.bin");
304 final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry);
305 final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(
306 new CCloseBuilder().setIgnore(false).setProcessingRule(false).setReason((short) 5).build()).build());
308 assertEquals(builder.build(), parser.parseMessage(result));
309 final ByteBuf buf = Unpooled.buffer(result.length);
310 parser.serializeMessage(builder.build(), buf);
311 assertArrayEquals(result, buf.array());
315 // public void testRequestMessageValidationFromBin() throws IOException, PCEPDeserializerException,
316 // PCEPDocumentedException,
317 // DeserializerException, DocumentedException {
318 // List<CompositeRequestObject> requests = new ArrayList<CompositeRequestObject>();
319 // final byte[] ipAdress = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
320 // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false, false,
321 // false, false, (short) 5, 0xDEADBEEFL, true, false), new PCEPEndPointsObject<IPv4Address>(new
322 // IPv4Address(ipAdress), new IPv4Address(ipAdress))));
323 // PCEPRequestMessage specMessage = new PCEPRequestMessage(requests);
324 // List<Message> deserMsgs = deserMsg("src/test/resources/PCEPRequestMessage1.bin");
325 // final List<Message> specMessages = Lists.newArrayList();
326 // specMessages.add(specMessage);
328 // assertEquals(deserMsgs.toString(), specMessages.toString());
330 // requests = new ArrayList<CompositeRequestObject>();
331 // final byte[] ipAdress2 = { (byte) 0x7F, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
332 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
333 // IPv4Address(ipAdress2), new IPv4Address(ipAdress2))));
334 // specMessage = new PCEPRequestMessage(requests);
335 // deserMsgs = deserMsg("src/test/resources/PCReq.1.bin");
336 // specMessages.clear();
337 // specMessages.add(specMessage);
338 // assertEquals(deserMsgs.toString(), specMessages.toString());
340 // requests = new ArrayList<CompositeRequestObject>();
341 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
342 // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, new
343 // PCEPLoadBalancingObject(3, new Bandwidth(ByteArray.floatToBytes((float) 1024.75)), false)));
344 // specMessage = new PCEPRequestMessage(requests);
345 // deserMsgs = deserMsg("src/test/resources/PCReq.2.bin");
346 // specMessages.clear();
347 // specMessages.add(specMessage);
348 // assertEquals(deserMsgs.toString(), specMessages.toString());
350 // requests = new ArrayList<CompositeRequestObject>();
351 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
352 // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, new PCEPLspObject(1, false, false, true, false),
353 // PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false,
354 // false), new ArrayList<PCEPMetricObject>() {
355 // private static final long serialVersionUID = 1L;
358 // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false));
360 // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new
361 // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false,
362 // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false)));
364 // List<CompositeRequestSvecObject> svecList = new ArrayList<CompositeRequestSvecObject>();
365 // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false, this.requestIds,
368 // specMessage = new PCEPRequestMessage(svecList, requests);
369 // deserMsgs = deserMsg("src/test/resources/PCReq.3.bin");
370 // specMessages.clear();
371 // specMessages.add(specMessage);
373 // // assertEquals(deserMsgs, specMessages);
375 // specMessages.clear();
376 // requests = new ArrayList<CompositeRequestObject>();
377 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
378 // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null));
379 // specMessages.add(new PCEPRequestMessage(requests));
381 // final byte[] ipAdress3 = { (byte) 0x7F, (byte) 0x00, (byte) 0x30, (byte) 0x01 };
382 // requests = new ArrayList<CompositeRequestObject>();
383 // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(false, false, false, false, false, false,
384 // false, false, (short) 4, 1, true, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(ipAdress3), new
385 // IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null));
386 // specMessages.add(new PCEPRequestMessage(requests));
388 // final byte[] ipAdress4 = { (byte) 0x7F, (byte) 0x30, (byte) 0x00, (byte) 0x01 };
389 // requests = new ArrayList<CompositeRequestObject>();
390 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
391 // IPv4Address(ipAdress2), new IPv4Address(ipAdress4)), null, null, null, null, null, null, null, null, null));
392 // specMessages.add(new PCEPRequestMessage(requests));
394 // final byte[] ipAdress5 = { (byte) 0x7F, (byte) 0xd0, (byte) 0x00, (byte) 0x01 };
395 // requests = new ArrayList<CompositeRequestObject>();
396 // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false, false,
397 // false, false, (short) 1, 1, true, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(ipAdress5), new
398 // IPv4Address(ipAdress5)), null, null, null, null, null, null, null, null, null));
400 // specMessages.add(new PCEPRequestMessage(requests));
401 // deserMsgs = deserMsg("src/test/resources/PCReq.4.bin");
402 // assertEquals(deserMsgs.toString(), specMessages.toString());
404 // specMessages.clear();
405 // svecList = new ArrayList<CompositeRequestSvecObject>();
406 // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false, this.requestIds,
408 // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(false, true, true, false, false, this.requestIds,
409 // false), new PCEPObjectiveFunctionObject(PCEPOFCodes.MCC, true, false), new PCEPGlobalConstraintsObject((short)
410 // 0x55, (short) 1, (short) 100, (short) 0x26, true, false), new PCEPExcludeRouteObject(new
411 // ArrayList<ExcludeRouteSubobject>() {
412 // private static final long serialVersionUID = 1L;
415 // this.add(new XROAsNumberSubobject(new AsNumber((long) 0x12), true));
417 // }, true, true, false), new ArrayList<PCEPMetricObject>() {
418 // private static final long serialVersionUID = 1L;
421 // this.add(new PCEPMetricObject(true, true, new TEMetric(123456L), true, false));
425 // requests = new ArrayList<CompositeRequestObject>();
426 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
427 // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, PCEPValidatorTest.lspa, new
428 // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new
429 // ArrayList<PCEPMetricObject>() {
430 // private static final long serialVersionUID = 1L;
433 // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false));
434 // this.add(new PCEPMetricObject(true, true, new IGPMetric(5335L), false, false));
435 // this.add(new PCEPMetricObject(true, true, new IGPMetric(128256), false, false));
437 // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new
438 // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false,
439 // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false)));
441 // final byte[] ipAdress6 = { (byte) 0x7F, (byte) 0xF0, (byte) 0x00, (byte) 0x01 };
442 // specMessages.add(new PCEPRequestMessage(svecList, requests));
444 // requests = new ArrayList<CompositeRequestObject>();
445 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
446 // IPv4Address(ipAdress6), new IPv4Address(ipAdress6)), null, null, PCEPValidatorTest.lspa, new
447 // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new
448 // ArrayList<PCEPMetricObject>() {
449 // private static final long serialVersionUID = 1L;
452 // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false));
454 // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new
455 // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false,
456 // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3f)), false)));
457 // deserMsgs = deserMsg("src/test/resources/PCReq.5.bin");
458 // specMessages.add(new PCEPRequestMessage(svecList, requests));
460 // // assertEquals(deserMsgs, specMessages);
462 // // FIXME: need construct with invalid processed parameter
463 // // assertEquals(deserMsg("src/test/resources/PCReq.6.invalid.bin"),
465 // // new PCEPErrorMessage(new CompositeErrorObject(new
466 // // PCEPRequestParameterObject(true, false, false, false, false, false,
467 // // false, false, (short) 3,
468 // // 1L, false, false), new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))),
469 // // new PCEPRequestMessage(asList(new
470 // // CompositeRequestObject(this.requestParameter, new
471 // // PCEPEndPointsObject<IPv4Address>(IPv4Address
472 // // .getNetworkAddressFactory().getNetworkAddressForBytes(new byte[] {
473 // // 127, 0, 0, 1 }), IPv4Address.getNetworkAddressFactory()
474 // // .getNetworkAddressForBytes(new byte[] { 127, 0, 0, 1 })), null, null,
475 // // null, null, null, null, null, null, new PCEPLoadBalancingObject(
476 // // 3, new Bandwidth(1024.75), false))))));
481 // public void testRequestMessageValidationFromRawMsg() throws PCEPDeserializerException {
482 // List<PCEPObject> objs = new ArrayList<PCEPObject>();
483 // List<Message> msgs;
484 // PCEPRequestParameterObject tmpRP;
486 // // test unrecognized object in svec list
487 // objs.add(this.svecObj);
488 // objs.add(new UnknownObject(true, false, PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
489 // objs.add(new PCEPSvecObject(true, true, true, false, false, PCEPValidatorTest.this.requestIds, true));
491 // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs);
493 // assertEquals(msgs.get(0).toString(), new PCEPErrorMessage(new ArrayList<PCEPErrorObject>() {
494 // private static final long serialVersionUID = 1L;
497 // this.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
501 // // test with request p flag not set and ignoracion of more than one
502 // // end-points objects
503 // objs = new ArrayList<PCEPObject>();
504 // objs.add(this.svecObj);
505 // objs.add(this.svecObj);
506 // tmpRP = new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1,
509 // objs.add(this.endPoints);
511 // objs.add(this.requestParameter);
512 // objs.add(this.endPoints);
513 // objs.add(this.endPoints);
514 // // FIXME:mv use object constructor with set processed flag
515 // // objs.add(this.classTypeProvider);
516 // // objs.add(this.requestParameter);
517 // // objs.add(this.endPointsProvider);
518 // // objs.add(new PCEPClassTypeObjectProvider((short) 7, false));
520 // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs);
521 // // FIXME:mv use object constructor with set processed flag
522 // // assertEquals(msgs.get(0), new PCEPErrorMessage(new
523 // // CompositeErrorObject(tmpRP, new
524 // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
527 // // new PCEPRequestMessage(asList(new
528 // // CompositeRequestSvecObject(this.svecObj), new
529 // // CompositeRequestSvecObject(this.svecObj)), Util
530 // // .asList(new CompositeRequestObject(this.requestParameter,
531 // // this.endPoints, this.classType, null, null, null, null, null, null,
534 // // assertEquals(msgs.get(2), new PCEPErrorMessage(new
535 // // CompositeErrorObject(tmpRP, new
536 // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
541 public void testReplyMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
543 byte[] result = ByteArray.fileToBytes("src/test/resources/PCRep.1.bin");
545 final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
547 final PcrepMessageBuilder builder = new PcrepMessageBuilder();
548 RepliesBuilder rBuilder = new RepliesBuilder();
550 final List<Replies> replies1 = Lists.newArrayList();
551 rBuilder.setRp(this.rp);
552 replies1.add(rBuilder.build());
553 builder.setReplies(replies1);
555 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result));
556 ByteBuf buf = Unpooled.buffer(result.length);
557 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
558 assertArrayEquals(result, buf.array());
561 result = ByteArray.fileToBytes("src/test/resources/PCRep.2.bin");
562 final List<Replies> replies2 = Lists.newArrayList();
563 rBuilder = new RepliesBuilder();
564 rBuilder.setRp(this.rp);
565 replies2.add(rBuilder.build());
566 final RepliesBuilder rBuilder2 = new RepliesBuilder();
567 rBuilder2.setRp(this.rp);
568 rBuilder2.setResult(new FailureBuilder().setNoPath(this.noPath).build());
569 replies2.add(rBuilder2.build());
570 builder.setReplies(replies2);
572 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result));
573 buf = Unpooled.buffer(result.length);
574 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
575 assertArrayEquals(result, buf.array());
577 // Failure with attributes
578 result = ByteArray.fileToBytes("src/test/resources/PCRep.3.bin");
579 final List<Replies> replies3 = Lists.newArrayList();
580 rBuilder = new RepliesBuilder();
581 rBuilder.setRp(this.rp);
582 rBuilder.setResult(new FailureBuilder().setNoPath(this.noPath).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(
584 replies3.add(rBuilder.build());
585 builder.setReplies(replies3);
587 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result));
588 buf = Unpooled.buffer(result.length);
589 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
590 assertArrayEquals(result, buf.array());
593 result = ByteArray.fileToBytes("src/test/resources/PCRep.5.bin");
594 final List<Replies> replies4 = Lists.newArrayList();
595 rBuilder = new RepliesBuilder();
596 rBuilder.setRp(this.rp);
597 final List<Paths> paths = Lists.newArrayList();
598 final PathsBuilder paBuilder = new PathsBuilder();
599 paBuilder.setEro(this.ero);
600 paBuilder.setLspa(this.lspa);
601 paBuilder.setMetrics(Lists.newArrayList(this.metrics));
602 paBuilder.setIro(this.iro);
603 paBuilder.setOf(this.of);
604 paths.add(paBuilder.build());
605 rBuilder.setResult(new SuccessBuilder().setPaths(paths).build()).build();
606 replies4.add(rBuilder.build());
607 builder.setReplies(replies4);
609 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result));
610 buf = Unpooled.buffer(result.length);
611 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
612 assertArrayEquals(result, buf.array());
616 public void testUpdMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
617 byte[] result = ByteArray.fileToBytes("src/test/resources/PCUpd.2.bin");
619 final PCEPUpdateRequestMessageParser parser = new PCEPUpdateRequestMessageParser(this.objectRegistry);
621 final PcupdMessageBuilder builder = new PcupdMessageBuilder();
623 final List<Updates> updates = Lists.newArrayList();
624 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.PathBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.PathBuilder();
625 pBuilder.setEro(this.ero);
626 pBuilder.setLspa(this.lspa);
627 updates.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
628 builder.setUpdates(updates);
630 assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(), parser.parseMessage(result));
631 ByteBuf buf = Unpooled.buffer(result.length);
632 parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf);
633 assertArrayEquals(result, buf.array());
635 result = ByteArray.fileToBytes("src/test/resources/PCUpd.5.bin");
637 final List<Updates> updates1 = Lists.newArrayList();
638 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.PathBuilder pBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.PathBuilder();
639 pBuilder1.setEro(this.ero);
640 pBuilder1.setLspa(this.lspa);
641 updates1.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
642 updates1.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder1.build()).build());
643 builder.setUpdates(updates1);
645 assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(), parser.parseMessage(result));
646 buf = Unpooled.buffer(result.length);
647 parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf);
648 assertArrayEquals(result, buf.array());
652 public void testRptMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
653 byte[] result = ByteArray.fileToBytes("src/test/resources/PCRpt.1.bin");
655 final PCEPReportMessageParser parser = new PCEPReportMessageParser(this.objectRegistry);
657 final PcrptMessageBuilder builder = new PcrptMessageBuilder();
659 final List<Reports> reports = Lists.newArrayList();
660 reports.add(new ReportsBuilder().setLsp(this.lsp).build());
661 builder.setReports(reports);
663 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result));
664 ByteBuf buf = Unpooled.buffer(result.length);
665 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
666 assertArrayEquals(result, buf.array());
668 result = ByteArray.fileToBytes("src/test/resources/PCRpt.2.bin");
670 final List<Reports> reports1 = Lists.newArrayList();
671 reports1.add(new ReportsBuilder().setLsp(this.lsp).setPath(new PathBuilder().setEro(this.ero).setLspa(this.lspa).build()).build());
672 builder.setReports(reports1);
674 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result));
675 buf = Unpooled.buffer(result.length);
676 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
677 assertArrayEquals(result, buf.array());
679 result = ByteArray.fileToBytes("src/test/resources/PCRpt.3.bin");
681 final List<Reports> reports2 = Lists.newArrayList();
682 final PathBuilder pBuilder = new PathBuilder();
683 pBuilder.setEro(this.ero);
684 pBuilder.setLspa(this.lspa);
685 pBuilder.setMetrics(Lists.newArrayList(this.metrics, this.metrics));
686 pBuilder.setRro(this.rro);
687 reports2.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
688 builder.setReports(reports2);
690 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result));
691 buf = Unpooled.buffer(result.length);
692 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
693 assertArrayEquals(result, buf.array());
695 result = ByteArray.fileToBytes("src/test/resources/PCRpt.5.bin");
697 final List<Reports> reports3 = Lists.newArrayList();
698 final PathBuilder pBuilder1 = new PathBuilder();
699 pBuilder1.setEro(this.ero);
700 pBuilder1.setLspa(this.lspa);
701 pBuilder1.setMetrics(Lists.newArrayList(this.metrics, this.metrics));
702 pBuilder1.setRro(this.rro);
703 reports3.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
704 reports3.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder1.build()).build());
705 builder.setReports(reports3);
707 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result));
708 buf = Unpooled.buffer(result.length);
709 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
710 assertArrayEquals(result, buf.array());
714 public void testPcinitMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
715 final byte[] result = ByteArray.fileToBytes("src/test/resources/Pcinit.bin");
717 final PcinitiateMessageParser parser = new PcinitiateMessageParser(this.objectRegistry);
719 final PcinitiateMessageBuilder builder = new PcinitiateMessageBuilder();
720 final RequestsBuilder rBuilder = new RequestsBuilder();
722 final List<Requests> reqs = Lists.newArrayList();
723 rBuilder.setSrp(this.srp);
724 rBuilder.setLsp(this.lsp);
725 rBuilder.setEro(this.ero);
726 rBuilder.setLspa(this.lspa);
727 rBuilder.setMetrics(Lists.newArrayList(this.metrics));
728 rBuilder.setIro(this.iro);
729 reqs.add(rBuilder.build());
730 builder.setRequests(reqs);
732 assertEquals(new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build(), parser.parseMessage(result));
733 final ByteBuf buf = Unpooled.buffer(result.length);
734 parser.serializeMessage(new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build(), buf);
735 assertArrayEquals(result, buf.array());
739 public void testNotificationMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
740 final CNotification cn1 = new CNotificationBuilder().setIgnore(false).setProcessingRule(false).setType((short) 1).setValue(
743 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> innerNot = Lists.newArrayList();
744 innerNot.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(
746 final List<Rps> rps = Lists.newArrayList();
747 rps.add(new RpsBuilder().setRp(this.rp).build());
749 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCNtf.5.bin");
751 final PCEPNotificationMessageParser parser = new PCEPNotificationMessageParser(this.objectRegistry);
752 final PcntfMessageBuilder builder = new PcntfMessageBuilder();
754 final List<Notifications> nots = Lists.newArrayList();
755 final NotificationsBuilder b = new NotificationsBuilder();
756 b.setNotifications(innerNot);
760 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> innerNot1 = Lists.newArrayList();
761 innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(
763 innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(
765 final List<Rps> rps1 = Lists.newArrayList();
766 rps1.add(new RpsBuilder().setRp(this.rp).build());
767 rps1.add(new RpsBuilder().setRp(this.rp).build());
769 b.setNotifications(innerNot1);
772 builder.setNotifications(nots);
774 assertEquals(new PcntfBuilder().setPcntfMessage(builder.build()).build(), parser.parseMessage(result));
775 final ByteBuf buf = Unpooled.buffer(result.length);
776 parser.serializeMessage(new PcntfBuilder().setPcntfMessage(builder.build()).build(), buf);
777 assertArrayEquals(result, buf.array());
781 public void testErrorMsg() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
782 byte[] result = ByteArray.fileToBytes("src/test/resources/PCErr.3.bin");
784 final ErrorObject error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3).setValue((short) 1).build();
786 final PCEPErrorMessageParser parser = new PCEPErrorMessageParser(this.objectRegistry);
788 List<Errors> innerErr = Lists.newArrayList();
789 innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
791 final PcerrMessageBuilder builder = new PcerrMessageBuilder();
792 builder.setErrors(innerErr);
793 builder.setErrorType(new SessionBuilder().setOpen(this.open).build());
795 assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result));
796 ByteBuf buf = Unpooled.buffer(result.length);
797 parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
798 assertArrayEquals(result, buf.array());
800 result = ByteArray.fileToBytes("src/test/resources/PCErr.5.bin");
802 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request.Rps> rps = Lists.newArrayList();
803 rps.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request.RpsBuilder().setRp(
806 innerErr = Lists.newArrayList();
807 innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
809 builder.setErrors(innerErr);
810 builder.setErrorType(new RequestBuilder().setRps(rps).build());
812 assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result));
813 buf = Unpooled.buffer(result.length);
814 parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
815 assertArrayEquals(result, buf.array());