Fix model names and imports
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPValidatorTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
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;
14
15 import java.io.IOException;
16 import java.math.BigInteger;
17 import java.util.Collections;
18 import java.util.List;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
23 import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
24 import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
25 import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
26 import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
27 import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
28 import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageParser;
29 import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
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.PCEPDeserializerException;
34 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
35 import org.opendaylight.protocol.util.ByteArray;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcinitiateBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcntfBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrepBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcreqBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrptBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcupdBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OperationalStatus;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PlspId;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Builder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobjects;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectsBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.Metrics;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.db.version.tlv.LspDbVersion;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.db.version.tlv.LspDbVersionBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.Lsp;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.LspBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.RequestBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.PcinitiateMessageBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.Requests;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.RequestsBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.PcntfMessageBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.NotificationsBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Rps;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.RpsBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessageBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.Replies;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.RepliesBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.FailureBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.SuccessBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPath;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPathBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success.Paths;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success.PathsBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessageBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.SegmentComputationBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.P2pBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessageBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.Reports;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.ReportsBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.reports.PathBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.PcupdMessageBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.Updates;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.UpdatesBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.srp.object.Srp;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.srp.object.SrpBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful.Flags;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.StatefulBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumber;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.Unnumbered;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedBuilder;
134
135 import com.google.common.collect.Lists;
136
137 public class PCEPValidatorTest {
138
139         private ObjectHandlerRegistry objectRegistry;
140
141         private Rp rpTrue;
142         private Rp rpFalse;
143         private Open open;
144         private NoPath noPath;
145         private Lspa lspa;
146         private Bandwidth bandwidth;
147         private Metrics metrics;
148         private Iro iro;
149         private Ero ero;
150         private Rro rro;
151         private Of of;
152         private Srp srp;
153         private Lsp lsp;
154         private EndpointsObj endpoints;
155         private Svec svec;
156
157         private AsNumber eroASSubobject;
158         private Unnumbered rroUnnumberedSub;
159
160         @Before
161         public void setUp() throws Exception {
162                 this.objectRegistry = ServiceLoaderPCEPExtensionProviderContext.create().getObjectHandlerRegistry();
163                 final RpBuilder rpBuilder = new RpBuilder();
164                 rpBuilder.setProcessingRule(true);
165                 rpBuilder.setIgnore(false);
166                 rpBuilder.setReoptimization(false);
167                 rpBuilder.setBiDirectional(false);
168                 rpBuilder.setLoose(true);
169                 rpBuilder.setMakeBeforeBreak(false);
170                 rpBuilder.setOrder(false);
171                 rpBuilder.setPathKey(false);
172                 rpBuilder.setSupplyOf(false);
173                 rpBuilder.setFragmentation(false);
174                 rpBuilder.setP2mp(false);
175                 rpBuilder.setEroCompression(false);
176                 rpBuilder.setPriority((short) 1);
177                 rpBuilder.setRequestId(new RequestId(10L));
178                 this.rpTrue = rpBuilder.build();
179                 rpBuilder.setProcessingRule(false);
180                 this.rpFalse = rpBuilder.build();
181
182                 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();
183                 openBuilder.setProcessingRule(false);
184                 openBuilder.setIgnore(false);
185                 openBuilder.setDeadTimer((short) 1);
186                 openBuilder.setKeepalive((short) 1);
187                 openBuilder.setSessionId((short) 0);
188                 openBuilder.setVersion(new ProtocolVersion((short) 1));
189                 openBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
190                 this.open = openBuilder.build();
191
192                 final NoPathBuilder npbuilder = new NoPathBuilder();
193                 npbuilder.setProcessingRule(false);
194                 npbuilder.setIgnore(false);
195                 npbuilder.setNatureOfIssue((short) 0);
196                 npbuilder.setUnsatisfiedConstraints(false);
197                 this.noPath = npbuilder.build();
198
199                 final LspaBuilder lspaBuilder = new LspaBuilder();
200                 lspaBuilder.setProcessingRule(false);
201                 lspaBuilder.setIgnore(false);
202                 lspaBuilder.setLocalProtectionDesired(false);
203                 lspaBuilder.setHoldPriority((short) 0);
204                 lspaBuilder.setSetupPriority((short) 0);
205                 lspaBuilder.setExcludeAny(new AttributeFilter(0L));
206                 lspaBuilder.setIncludeAll(new AttributeFilter(0L));
207                 lspaBuilder.setIncludeAny(new AttributeFilter(0L));
208                 this.lspa = lspaBuilder.build();
209
210                 final BandwidthBuilder bBuilder = new BandwidthBuilder();
211                 bBuilder.setIgnore(false);
212                 bBuilder.setProcessingRule(false);
213                 bBuilder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new Float32(new byte[4])));
214                 this.bandwidth = bBuilder.build();
215
216                 final MetricBuilder mBuilder = new MetricBuilder();
217                 mBuilder.setIgnore(false);
218                 mBuilder.setProcessingRule(false);
219                 mBuilder.setComputed(false);
220                 mBuilder.setBound(false);
221                 mBuilder.setMetricType((short) 1);
222                 mBuilder.setValue(new Float32(new byte[4]));
223                 this.metrics = new MetricsBuilder().setMetric(mBuilder.build()).build();
224
225                 this.eroASSubobject = new AsNumberBuilder().setAsNumber(
226                                 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber(0xFFFFL)).build();
227
228                 this.rroUnnumberedSub = new UnnumberedBuilder().setRouterId(0x00112233L).setInterfaceId(0x00ff00ffL).build();
229
230                 final IroBuilder iroBuilder = new IroBuilder();
231                 iroBuilder.setIgnore(false);
232                 iroBuilder.setProcessingRule(false);
233                 final List<Subobjects> iroSubs = Lists.newArrayList();
234                 iroSubs.add(new SubobjectsBuilder().setSubobjectType(this.eroASSubobject).build());
235                 iroBuilder.setSubobjects(iroSubs);
236                 this.iro = iroBuilder.build();
237
238                 final EroBuilder eroBuilder = new EroBuilder();
239                 eroBuilder.setIgnore(false);
240                 eroBuilder.setProcessingRule(false);
241                 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobjects> eroSubs = Lists.newArrayList();
242                 eroSubs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectsBuilder().setSubobjectType(
243                                 this.eroASSubobject).setLoose(false).build());
244                 eroBuilder.setSubobjects(eroSubs);
245                 this.ero = eroBuilder.build();
246
247                 final RroBuilder rroBuilder = new RroBuilder();
248                 rroBuilder.setIgnore(false);
249                 rroBuilder.setProcessingRule(false);
250                 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobjects> rroSubs = Lists.newArrayList();
251                 rroSubs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectsBuilder().setSubobjectType(
252                                 this.rroUnnumberedSub).setProtectionAvailable(false).setProtectionInUse(false).build());
253                 rroBuilder.setSubobjects(rroSubs);
254                 this.rro = rroBuilder.build();
255
256                 final OfBuilder ofBuilder = new OfBuilder();
257                 ofBuilder.setIgnore(false);
258                 ofBuilder.setProcessingRule(false);
259                 ofBuilder.setCode(new OfId(0));
260                 this.of = ofBuilder.build();
261
262                 final SrpBuilder srpBuilder = new SrpBuilder();
263                 srpBuilder.setIgnore(false);
264                 srpBuilder.setProcessingRule(false);
265                 srpBuilder.setOperationId(new SrpIdNumber(1L));
266                 this.srp = srpBuilder.build();
267
268                 final LspBuilder lspBuilder = new LspBuilder();
269                 lspBuilder.setIgnore(false);
270                 lspBuilder.setProcessingRule(false);
271                 lspBuilder.setAdministrative(false);
272                 lspBuilder.setDelegate(false);
273                 lspBuilder.setPlspId(new PlspId(0L));
274                 lspBuilder.setOperational(OperationalStatus.Down);
275                 lspBuilder.setSync(false);
276                 lspBuilder.setRemove(false);
277                 lspBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.lsp.TlvsBuilder().build());
278                 this.lsp = lspBuilder.build();
279
280                 final Ipv4Builder afi = new Ipv4Builder();
281                 afi.setSourceIpv4Address(new Ipv4Address("255.255.255.255"));
282                 afi.setDestinationIpv4Address(new Ipv4Address("255.255.255.255"));
283
284                 final EndpointsObjBuilder epBuilder = new EndpointsObjBuilder();
285                 epBuilder.setIgnore(false);
286                 epBuilder.setProcessingRule(true);
287                 epBuilder.setAddressFamily(afi.build());
288                 this.endpoints = epBuilder.build();
289
290                 final SvecBuilder sBuilder = new SvecBuilder();
291                 sBuilder.setIgnore(false);
292                 sBuilder.setProcessingRule(false);
293                 sBuilder.setLinkDiverse(false);
294                 sBuilder.setNodeDiverse(false);
295                 sBuilder.setSrlgDiverse(false);
296                 sBuilder.setRequestsIds(Lists.newArrayList(new RequestId(1L)));
297                 this.svec = sBuilder.build();
298         }
299
300         @Test
301         public void testOpenMsg() throws IOException, PCEPDeserializerException {
302                 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin");
303                 final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.objectRegistry);
304                 final OpenMessageBuilder builder = new OpenMessageBuilder();
305
306                 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();
307                 b.setProcessingRule(false);
308                 b.setIgnore(false);
309                 b.setVersion(new ProtocolVersion((short) 1));
310                 b.setKeepalive((short) 30);
311                 b.setDeadTimer((short) 120);
312                 b.setSessionId((short) 1);
313                 final Stateful tlv1 = new StatefulBuilder().setFlags(new Flags(true, false, true)).build();
314                 final LspDbVersion tlv2 = new LspDbVersionBuilder().setVersion(BigInteger.valueOf(0x80L)).build();
315                 b.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().setStateful(
316                                 tlv1).setLspDbVersion(tlv2).build());
317                 builder.setOpen(b.build());
318
319                 assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(),
320                                 parser.parseMessage(result, Collections.<Message> emptyList()));
321                 final ByteBuf buf = Unpooled.buffer(result.length);
322                 parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf);
323                 assertArrayEquals(result, buf.array());
324         }
325
326         @Test
327         public void testKeepAliveMsg() throws IOException, PCEPDeserializerException {
328                 final byte[] result = new byte[] {};
329                 final PCEPKeepAliveMessageParser parser = new PCEPKeepAliveMessageParser(this.objectRegistry);
330                 final KeepaliveBuilder builder = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build());
331
332                 assertEquals(builder.build(), parser.parseMessage(result, Collections.<Message> emptyList()));
333                 final ByteBuf buf = Unpooled.buffer(result.length);
334                 parser.serializeMessage(builder.build(), buf);
335                 assertArrayEquals(result, buf.array());
336         }
337
338         @Test
339         public void testCloseMsg() throws IOException, PCEPDeserializerException {
340                 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPCloseMessage1.bin");
341
342                 final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry);
343                 final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(
344                                 new CCloseBuilder().setIgnore(false).setProcessingRule(false).setReason((short) 5).build()).build());
345
346                 assertEquals(builder.build(), parser.parseMessage(result, Collections.<Message> emptyList()));
347                 final ByteBuf buf = Unpooled.buffer(result.length);
348                 parser.serializeMessage(builder.build(), buf);
349                 assertArrayEquals(result, buf.array());
350         }
351
352         @Test
353         public void testRequestMsg() throws IOException, PCEPDeserializerException {
354                 byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPRequestMessage1.bin");
355
356                 final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry);
357
358                 final PcreqMessageBuilder builder = new PcreqMessageBuilder();
359                 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs1 = Lists.newArrayList();
360                 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
361                 rBuilder.setRp(this.rpTrue);
362                 rBuilder.setSegmentComputation(new SegmentComputationBuilder().setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).build()).build());
363                 reqs1.add(rBuilder.build());
364                 builder.setRequests(reqs1);
365
366                 assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(),
367                                 parser.parseMessage(result, Collections.<Message> emptyList()));
368                 ByteBuf buf = Unpooled.buffer(result.length);
369                 parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
370
371                 assertArrayEquals(result, buf.array());
372
373                 result = ByteArray.fileToBytes("src/test/resources/PCReq.3.bin");
374
375                 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs2 = Lists.newArrayList();
376                 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
377                 rBuilder1.setRp(this.rpTrue);
378                 final P2pBuilder p2pBuilder = new P2pBuilder();
379                 p2pBuilder.setEndpointsObj(this.endpoints);
380                 p2pBuilder.setLsp(this.lsp);
381                 p2pBuilder.setMetrics(Lists.newArrayList(this.metrics));
382                 p2pBuilder.setIro(this.iro);
383                 rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build());
384                 reqs2.add(rBuilder1.build());
385                 builder.setRequests(reqs2);
386                 builder.setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder().setSvec(
387                                 this.svec).build()));
388
389                 assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(),
390                                 parser.parseMessage(result, Collections.<Message> emptyList()));
391                 buf = Unpooled.buffer(result.length);
392                 parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
393                 assertArrayEquals(result, buf.array());
394
395                 // specMessages.clear();
396                 // requests = new ArrayList<CompositeRequestObject>();
397                 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
398                 // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null));
399                 // specMessages.add(new PCEPRequestMessage(requests));
400                 //
401                 // final byte[] ipAdress3 = { (byte) 0x7F, (byte) 0x00, (byte) 0x30, (byte) 0x01 };
402                 // requests = new ArrayList<CompositeRequestObject>();
403                 // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(false, false, false, false, false,
404                 // false,
405                 // false, false, (short) 4, 1, true, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(ipAdress3),
406                 // new
407                 // IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null));
408                 // specMessages.add(new PCEPRequestMessage(requests));
409                 //
410                 // final byte[] ipAdress4 = { (byte) 0x7F, (byte) 0x30, (byte) 0x00, (byte) 0x01 };
411                 // requests = new ArrayList<CompositeRequestObject>();
412                 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
413                 // IPv4Address(ipAdress2), new IPv4Address(ipAdress4)), null, null, null, null, null, null, null, null, null));
414                 // specMessages.add(new PCEPRequestMessage(requests));
415                 //
416                 // final byte[] ipAdress5 = { (byte) 0x7F, (byte) 0xd0, (byte) 0x00, (byte) 0x01 };
417                 // requests = new ArrayList<CompositeRequestObject>();
418                 // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false,
419                 // false,
420                 // false, false, (short) 1, 1, true, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(ipAdress5),
421                 // new
422                 // IPv4Address(ipAdress5)), null, null, null, null, null, null, null, null, null));
423                 //
424                 // specMessages.add(new PCEPRequestMessage(requests));
425                 // deserMsgs = deserMsg("src/test/resources/PCReq.4.bin");
426                 // assertEquals(deserMsgs.toString(), specMessages.toString());
427                 //
428                 // specMessages.clear();
429                 // svecList = new ArrayList<CompositeRequestSvecObject>();
430                 // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false,
431                 // this.requestIds,
432                 // false)));
433                 // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(false, true, true, false, false,
434                 // this.requestIds,
435                 // false), new PCEPObjectiveFunctionObject(PCEPOFCodes.MCC, true, false), new
436                 // PCEPGlobalConstraintsObject((short)
437                 // 0x55, (short) 1, (short) 100, (short) 0x26, true, false), new PCEPExcludeRouteObject(new
438                 // ArrayList<ExcludeRouteSubobject>() {
439                 // private static final long serialVersionUID = 1L;
440                 //
441                 // {
442                 // this.add(new XROAsNumberSubobject(new AsNumber((long) 0x12), true));
443                 // }
444                 // }, true, true, false), new ArrayList<PCEPMetricObject>() {
445                 // private static final long serialVersionUID = 1L;
446                 //
447                 // {
448                 // this.add(new PCEPMetricObject(true, true, new TEMetric(123456L), true, false));
449                 // }
450                 // }));
451                 //
452                 // requests = new ArrayList<CompositeRequestObject>();
453                 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
454                 // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, PCEPValidatorTest.lspa, new
455                 // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new
456                 // ArrayList<PCEPMetricObject>() {
457                 // private static final long serialVersionUID = 1L;
458                 //
459                 // {
460                 // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false));
461                 // this.add(new PCEPMetricObject(true, true, new IGPMetric(5335L), false, false));
462                 // this.add(new PCEPMetricObject(true, true, new IGPMetric(128256), false, false));
463                 // }
464                 // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new
465                 // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false,
466                 // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false)));
467                 //
468                 // final byte[] ipAdress6 = { (byte) 0x7F, (byte) 0xF0, (byte) 0x00, (byte) 0x01 };
469                 // specMessages.add(new PCEPRequestMessage(svecList, requests));
470                 //
471                 // requests = new ArrayList<CompositeRequestObject>();
472                 // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
473                 // IPv4Address(ipAdress6), new IPv4Address(ipAdress6)), null, null, PCEPValidatorTest.lspa, new
474                 // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new
475                 // ArrayList<PCEPMetricObject>() {
476                 // private static final long serialVersionUID = 1L;
477                 //
478                 // {
479                 // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false));
480                 // }
481                 // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new
482                 // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false,
483                 // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3f)), false)));
484                 // deserMsgs = deserMsg("src/test/resources/PCReq.5.bin");
485                 // specMessages.add(new PCEPRequestMessage(svecList, requests));
486                 // // FIXME
487                 // // assertEquals(deserMsgs, specMessages);
488                 //
489                 // // FIXME: need construct with invalid processed parameter
490                 // // assertEquals(deserMsg("src/test/resources/PCReq.6.invalid.bin"),
491                 // // asList(
492                 // // new PCEPErrorMessage(new CompositeErrorObject(new
493                 // // PCEPRequestParameterObject(true, false, false, false, false, false,
494                 // // false, false, (short) 3,
495                 // // 1L, false, false), new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))),
496                 // // new PCEPRequestMessage(asList(new
497                 // // CompositeRequestObject(this.requestParameter, new
498                 // // PCEPEndPointsObject<IPv4Address>(IPv4Address
499                 // // .getNetworkAddressFactory().getNetworkAddressForBytes(new byte[] {
500                 // // 127, 0, 0, 1 }), IPv4Address.getNetworkAddressFactory()
501                 // // .getNetworkAddressForBytes(new byte[] { 127, 0, 0, 1 })), null, null,
502                 // // null, null, null, null, null, null, new PCEPLoadBalancingObject(
503                 // // 3, new Bandwidth(1024.75), false))))));
504                 //
505                 // }
506                 //
507                 // @Test
508                 // public void testRequestMessageValidationFromRawMsg() throws PCEPDeserializerException {
509                 // List<PCEPObject> objs = new ArrayList<PCEPObject>();
510                 // List<Message> msgs;
511                 // PCEPRequestParameterObject tmpRP;
512                 //
513                 // // test unrecognized object in svec list
514                 // objs.add(this.svecObj);
515                 // objs.add(new UnknownObject(true, false, PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
516                 // objs.add(new PCEPSvecObject(true, true, true, false, false, PCEPValidatorTest.this.requestIds, true));
517                 //
518                 // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs);
519                 //
520                 // assertEquals(msgs.get(0).toString(), new PCEPErrorMessage(new ArrayList<PCEPErrorObject>() {
521                 // private static final long serialVersionUID = 1L;
522                 //
523                 // {
524                 // this.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
525                 // }
526                 // }).toString());
527                 //
528                 // // test with request p flag not set and ignoracion of more than one
529                 // // end-points objects
530                 // objs = new ArrayList<PCEPObject>();
531                 // objs.add(this.svecObj);
532                 // objs.add(this.svecObj);
533                 // tmpRP = new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1,
534                 // false, false);
535                 // objs.add(tmpRP);
536                 // objs.add(this.endPoints);
537                 //
538                 // objs.add(this.requestParameter);
539                 // objs.add(this.endPoints);
540                 // objs.add(this.endPoints);
541                 // // FIXME:mv use object constructor with set processed flag
542                 // // objs.add(this.classTypeProvider);
543                 // // objs.add(this.requestParameter);
544                 // // objs.add(this.endPointsProvider);
545                 // // objs.add(new PCEPClassTypeObjectProvider((short) 7, false));
546                 //
547                 // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs);
548                 // // FIXME:mv use object constructor with set processed flag
549                 // // assertEquals(msgs.get(0), new PCEPErrorMessage(new
550                 // // CompositeErrorObject(tmpRP, new
551                 // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
552                 // // assertEquals(
553                 // // msgs.get(1),
554                 // // new PCEPRequestMessage(asList(new
555                 // // CompositeRequestSvecObject(this.svecObj), new
556                 // // CompositeRequestSvecObject(this.svecObj)), Util
557                 // // .asList(new CompositeRequestObject(this.requestParameter,
558                 // // this.endPoints, this.classType, null, null, null, null, null, null,
559                 // // null,
560                 // // null))));
561                 // // assertEquals(msgs.get(2), new PCEPErrorMessage(new
562                 // // CompositeErrorObject(tmpRP, new
563                 // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
564         }
565
566         @Test
567         public void testReplyMsg() throws IOException, PCEPDeserializerException {
568                 // only RP
569                 byte[] result = ByteArray.fileToBytes("src/test/resources/PCRep.1.bin");
570
571                 final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
572
573                 final PcrepMessageBuilder builder = new PcrepMessageBuilder();
574                 RepliesBuilder rBuilder = new RepliesBuilder();
575
576                 final List<Replies> replies1 = Lists.newArrayList();
577                 rBuilder.setRp(this.rpTrue);
578                 replies1.add(rBuilder.build());
579                 builder.setReplies(replies1);
580
581                 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(),
582                                 parser.parseMessage(result, Collections.<Message> emptyList()));
583                 ByteBuf buf = Unpooled.buffer(result.length);
584                 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
585                 assertArrayEquals(result, buf.array());
586
587                 // simple Failure
588                 result = ByteArray.fileToBytes("src/test/resources/PCRep.2.bin");
589                 final List<Replies> replies2 = Lists.newArrayList();
590                 rBuilder = new RepliesBuilder();
591                 rBuilder.setRp(this.rpTrue);
592                 replies2.add(rBuilder.build());
593                 final RepliesBuilder rBuilder2 = new RepliesBuilder();
594                 rBuilder2.setRp(this.rpTrue);
595                 rBuilder2.setResult(new FailureBuilder().setNoPath(this.noPath).build());
596                 replies2.add(rBuilder2.build());
597                 builder.setReplies(replies2);
598
599                 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(),
600                                 parser.parseMessage(result, Collections.<Message> emptyList()));
601                 buf = Unpooled.buffer(result.length);
602                 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
603                 assertArrayEquals(result, buf.array());
604
605                 // Failure with attributes
606                 result = ByteArray.fileToBytes("src/test/resources/PCRep.3.bin");
607                 final List<Replies> replies3 = Lists.newArrayList();
608                 rBuilder = new RepliesBuilder();
609                 rBuilder.setRp(this.rpTrue);
610                 rBuilder.setResult(new FailureBuilder().setNoPath(this.noPath).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(
611                                 this.iro).build());
612                 replies3.add(rBuilder.build());
613                 builder.setReplies(replies3);
614
615                 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(),
616                                 parser.parseMessage(result, Collections.<Message> emptyList()));
617                 buf = Unpooled.buffer(result.length);
618                 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
619                 assertArrayEquals(result, buf.array());
620
621                 // Success
622                 result = ByteArray.fileToBytes("src/test/resources/PCRep.5.bin");
623                 final List<Replies> replies4 = Lists.newArrayList();
624                 rBuilder = new RepliesBuilder();
625                 rBuilder.setRp(this.rpTrue);
626                 final List<Paths> paths = Lists.newArrayList();
627                 final PathsBuilder paBuilder = new PathsBuilder();
628                 paBuilder.setEro(this.ero);
629                 paBuilder.setLspa(this.lspa);
630                 paBuilder.setMetrics(Lists.newArrayList(this.metrics));
631                 paBuilder.setIro(this.iro);
632                 paBuilder.setOf(this.of);
633                 paths.add(paBuilder.build());
634                 rBuilder.setResult(new SuccessBuilder().setPaths(paths).build()).build();
635                 replies4.add(rBuilder.build());
636                 builder.setReplies(replies4);
637
638                 assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(),
639                                 parser.parseMessage(result, Collections.<Message> emptyList()));
640                 buf = Unpooled.buffer(result.length);
641                 parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
642                 assertArrayEquals(result, buf.array());
643         }
644
645         @Test
646         public void testUpdMsg() throws IOException, PCEPDeserializerException {
647                 byte[] result = ByteArray.fileToBytes("src/test/resources/PCUpd.2.bin");
648
649                 final PCEPUpdateRequestMessageParser parser = new PCEPUpdateRequestMessageParser(this.objectRegistry);
650
651                 final PcupdMessageBuilder builder = new PcupdMessageBuilder();
652
653                 final List<Updates> updates = Lists.newArrayList();
654                 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();
655                 pBuilder.setEro(this.ero);
656                 pBuilder.setLspa(this.lspa);
657                 updates.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
658                 builder.setUpdates(updates);
659
660                 assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(),
661                                 parser.parseMessage(result, Collections.<Message> emptyList()));
662                 ByteBuf buf = Unpooled.buffer(result.length);
663                 parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf);
664                 assertArrayEquals(result, buf.array());
665
666                 result = ByteArray.fileToBytes("src/test/resources/PCUpd.5.bin");
667
668                 final List<Updates> updates1 = Lists.newArrayList();
669                 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();
670                 pBuilder1.setEro(this.ero);
671                 pBuilder1.setLspa(this.lspa);
672                 updates1.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
673                 updates1.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder1.build()).build());
674                 builder.setUpdates(updates1);
675
676                 assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(),
677                                 parser.parseMessage(result, Collections.<Message> emptyList()));
678                 buf = Unpooled.buffer(result.length);
679                 parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf);
680                 assertArrayEquals(result, buf.array());
681         }
682
683         @Test
684         public void testRptMsg() throws IOException, PCEPDeserializerException {
685                 byte[] result = ByteArray.fileToBytes("src/test/resources/PCRpt.1.bin");
686
687                 final PCEPReportMessageParser parser = new PCEPReportMessageParser(this.objectRegistry);
688
689                 final PcrptMessageBuilder builder = new PcrptMessageBuilder();
690
691                 final List<Reports> reports = Lists.newArrayList();
692                 reports.add(new ReportsBuilder().setLsp(this.lsp).build());
693                 builder.setReports(reports);
694
695                 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(),
696                                 parser.parseMessage(result, Collections.<Message> emptyList()));
697                 ByteBuf buf = Unpooled.buffer(result.length);
698                 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
699                 assertArrayEquals(result, buf.array());
700
701                 result = ByteArray.fileToBytes("src/test/resources/PCRpt.2.bin");
702
703                 final List<Reports> reports1 = Lists.newArrayList();
704                 reports1.add(new ReportsBuilder().setLsp(this.lsp).setPath(new PathBuilder().setEro(this.ero).setLspa(this.lspa).build()).build());
705                 builder.setReports(reports1);
706
707                 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(),
708                                 parser.parseMessage(result, Collections.<Message> emptyList()));
709                 buf = Unpooled.buffer(result.length);
710                 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
711                 assertArrayEquals(result, buf.array());
712
713                 result = ByteArray.fileToBytes("src/test/resources/PCRpt.3.bin");
714
715                 final List<Reports> reports2 = Lists.newArrayList();
716                 final PathBuilder pBuilder = new PathBuilder();
717                 pBuilder.setEro(this.ero);
718                 pBuilder.setLspa(this.lspa);
719                 pBuilder.setMetrics(Lists.newArrayList(this.metrics, this.metrics));
720                 pBuilder.setRro(this.rro);
721                 reports2.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
722                 builder.setReports(reports2);
723
724                 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(),
725                                 parser.parseMessage(result, Collections.<Message> emptyList()));
726                 buf = Unpooled.buffer(result.length);
727                 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
728                 assertArrayEquals(result, buf.array());
729
730                 result = ByteArray.fileToBytes("src/test/resources/PCRpt.5.bin");
731
732                 final List<Reports> reports3 = Lists.newArrayList();
733                 final PathBuilder pBuilder1 = new PathBuilder();
734                 pBuilder1.setEro(this.ero);
735                 pBuilder1.setLspa(this.lspa);
736                 pBuilder1.setMetrics(Lists.newArrayList(this.metrics, this.metrics));
737                 pBuilder1.setRro(this.rro);
738                 reports3.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder.build()).build());
739                 reports3.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lsp).setPath(pBuilder1.build()).build());
740                 builder.setReports(reports3);
741
742                 assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(),
743                                 parser.parseMessage(result, Collections.<Message> emptyList()));
744                 buf = Unpooled.buffer(result.length);
745                 parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
746                 assertArrayEquals(result, buf.array());
747         }
748
749         @Test
750         public void testPcinitMsg() throws IOException, PCEPDeserializerException {
751                 final byte[] result = ByteArray.fileToBytes("src/test/resources/Pcinit.bin");
752
753                 final PcinitiateMessageParser parser = new PcinitiateMessageParser(this.objectRegistry);
754
755                 final PcinitiateMessageBuilder builder = new PcinitiateMessageBuilder();
756                 final RequestsBuilder rBuilder = new RequestsBuilder();
757
758                 final List<Requests> reqs = Lists.newArrayList();
759                 rBuilder.setSrp(this.srp);
760                 rBuilder.setLsp(this.lsp);
761                 rBuilder.setEro(this.ero);
762                 rBuilder.setLspa(this.lspa);
763                 rBuilder.setMetrics(Lists.newArrayList(this.metrics));
764                 rBuilder.setIro(this.iro);
765                 reqs.add(rBuilder.build());
766                 builder.setRequests(reqs);
767
768                 assertEquals(new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build(),
769                                 parser.parseMessage(result, Collections.<Message> emptyList()));
770                 final ByteBuf buf = Unpooled.buffer(result.length);
771                 parser.serializeMessage(new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build(), buf);
772                 assertArrayEquals(result, buf.array());
773         }
774
775         @Test
776         public void testNotificationMsg() throws IOException, PCEPDeserializerException {
777                 final CNotification cn1 = new CNotificationBuilder().setIgnore(false).setProcessingRule(false).setType((short) 1).setValue(
778                                 (short) 1).build();
779
780                 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();
781                 innerNot.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(
782                                 cn1).build());
783                 final List<Rps> rps = Lists.newArrayList();
784                 rps.add(new RpsBuilder().setRp(this.rpFalse).build());
785
786                 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCNtf.5.bin");
787
788                 final PCEPNotificationMessageParser parser = new PCEPNotificationMessageParser(this.objectRegistry);
789                 final PcntfMessageBuilder builder = new PcntfMessageBuilder();
790
791                 final List<Notifications> nots = Lists.newArrayList();
792                 final NotificationsBuilder b = new NotificationsBuilder();
793                 b.setNotifications(innerNot);
794                 b.setRps(rps);
795                 nots.add(b.build());
796
797                 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();
798                 innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(
799                                 cn1).build());
800                 innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(
801                                 cn1).build());
802                 final List<Rps> rps1 = Lists.newArrayList();
803                 rps1.add(new RpsBuilder().setRp(this.rpFalse).build());
804                 rps1.add(new RpsBuilder().setRp(this.rpFalse).build());
805
806                 b.setNotifications(innerNot1);
807                 b.setRps(rps1);
808                 nots.add(b.build());
809                 builder.setNotifications(nots);
810
811                 assertEquals(new PcntfBuilder().setPcntfMessage(builder.build()).build(),
812                                 parser.parseMessage(result, Collections.<Message> emptyList()));
813                 final ByteBuf buf = Unpooled.buffer(result.length);
814                 parser.serializeMessage(new PcntfBuilder().setPcntfMessage(builder.build()).build(), buf);
815                 assertArrayEquals(result, buf.array());
816         }
817
818         @Test
819         public void testErrorMsg() throws IOException, PCEPDeserializerException {
820                 byte[] result = ByteArray.fileToBytes("src/test/resources/PCErr.3.bin");
821
822                 final ErrorObject error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3).setValue((short) 1).build();
823
824                 final PCEPErrorMessageParser parser = new PCEPErrorMessageParser(this.objectRegistry);
825
826                 List<Errors> innerErr = Lists.newArrayList();
827                 innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
828
829                 final PcerrMessageBuilder builder = new PcerrMessageBuilder();
830                 builder.setErrors(innerErr);
831                 builder.setErrorType(new SessionBuilder().setOpen(this.open).build());
832
833                 assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(),
834                                 parser.parseMessage(result, Collections.<Message> emptyList()));
835                 ByteBuf buf = Unpooled.buffer(result.length);
836                 parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
837                 assertArrayEquals(result, buf.array());
838
839                 result = ByteArray.fileToBytes("src/test/resources/PCErr.5.bin");
840
841                 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();
842                 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(
843                                 this.rpFalse).build());
844
845                 innerErr = Lists.newArrayList();
846                 innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
847
848                 builder.setErrors(innerErr);
849                 builder.setErrorType(new RequestBuilder().setRps(rps).build());
850
851                 assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(),
852                                 parser.parseMessage(result, Collections.<Message> emptyList()));
853                 buf = Unpooled.buffer(result.length);
854                 parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
855                 assertArrayEquals(result, buf.array());
856         }
857 }