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.message;
12 * PCEPReplyMessage validator. Validates message integrity.
14 // FIXME: merge with parser
15 class PCEPReplyMessageValidator {
17 // private static class SubReplyValidator {
19 // private boolean requestRejected = true;
21 // private List<Message> msgs = Lists.newArrayList();
23 // private PCEPRequestParameterObject rpObj;
25 // private PCEPNoPathObject noPath;
26 // private PCEPLspObject lsp;
27 // private PCEPLspaObject lspa;
28 // private PCEPRequestedPathBandwidthObject bandwidth;
29 // private List<PCEPMetricObject> metrics;
30 // private PCEPIncludeRouteObject iro;
31 // private List<CompositePathObject> paths;
33 // private void init() {
34 // this.requestRejected = false;
35 // this.msgs = Lists.newArrayList();
37 // this.noPath = null;
42 // this.metrics = new ArrayList<PCEPMetricObject>();
43 // this.paths = new ArrayList<CompositePathObject>();
46 // public List<Message> validate(final List<Object> objects, final List<CompositeReplySvecObject> svecList) {
49 // if (!(objects.get(0) instanceof PCEPRequestParameterObject))
52 // final PCEPRequestParameterObject rpObj = (PCEPRequestParameterObject) objects.get(0);
57 // while (!objects.isEmpty()) {
58 // obj = objects.get(0);
59 // if (obj instanceof UnknownObject) {
60 // if (((UnknownObject) obj).isProcessingRule()) {
61 // this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
62 // PCEPErrorObject(((UnknownObject) obj).getError()))));
63 // this.requestRejected = true;
73 // if (obj instanceof PCEPNoPathObject) {
74 // this.noPath = (PCEPNoPathObject) obj;
79 // if (obj instanceof PCEPLspObject) {
80 // this.lsp = (PCEPLspObject) obj;
85 // if (obj instanceof PCEPLspaObject) {
86 // this.lspa = (PCEPLspaObject) obj;
91 // if (obj instanceof PCEPRequestedPathBandwidthObject) {
92 // this.bandwidth = (PCEPRequestedPathBandwidthObject) obj;
97 // if (obj instanceof PCEPMetricObject) {
98 // this.metrics.add((PCEPMetricObject) obj);
104 // if (obj instanceof PCEPIncludeRouteObject) {
105 // this.iro = (PCEPIncludeRouteObject) obj;
114 // objects.remove(0);
120 // if (!objects.isEmpty()) {
121 // CompositePathObject path = this.getValidCompositePath(objects);
122 // while (path != null) {
123 // this.paths.add(path);
124 // if (objects.isEmpty())
126 // path = this.getValidCompositePath(objects);
130 // if (!this.requestRejected) {
131 // this.msgs.add(new PCEPReplyMessage(Collections.unmodifiableList(Arrays.asList(new CompositeResponseObject(rpObj,
132 // this.noPath, this.lsp, this.lspa, this.bandwidth, this.metrics, this.iro, this.paths))),
133 // Collections.unmodifiableList(svecList)));
139 // private CompositePathObject getValidCompositePath(final List<Object> objects) {
140 // if (!(objects.get(0) instanceof PCEPExplicitRouteObject))
143 // final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0);
144 // objects.remove(0);
146 // PCEPLspaObject pathLspa = null;
147 // PCEPRequestedPathBandwidthObject pathBandwidth = null;
148 // final List<PCEPMetricObject> pathMetrics = new ArrayList<PCEPMetricObject>();
149 // PCEPIncludeRouteObject pathIro = null;
153 // while (!objects.isEmpty()) {
154 // obj = objects.get(0);
155 // if (obj instanceof UnknownObject) {
156 // if (((UnknownObject) obj).isProcessingRule()) {
157 // this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(this.rpObj, false), new
158 // PCEPErrorObject(((UnknownObject) obj).getError()))));
159 // this.requestRejected = true;
161 // objects.remove(0);
168 // if (obj instanceof PCEPLspaObject) {
169 // pathLspa = (PCEPLspaObject) obj;
174 // if (obj instanceof PCEPRequestedPathBandwidthObject) {
175 // pathBandwidth = (PCEPRequestedPathBandwidthObject) obj;
180 // if (obj instanceof PCEPMetricObject) {
181 // pathMetrics.add((PCEPMetricObject) obj);
187 // if (obj instanceof PCEPIncludeRouteObject) {
188 // pathIro = (PCEPIncludeRouteObject) obj;
198 // objects.remove(0);
204 // return new CompositePathObject(explicitRoute, pathLspa, pathBandwidth, pathMetrics, pathIro);
209 // public List<Message> validate(final List<Object> objects) throws PCEPDeserializerException {
210 // if (objects == null)
211 // throw new IllegalArgumentException("Passed list can't be null.");
213 // final List<Message> msgs = Lists.newArrayList();
214 // final List<CompositeReplySvecObject> svecList = new ArrayList<CompositeReplySvecObject>();
216 // CompositeReplySvecObject svecComp;
217 // while (!objects.isEmpty()) {
219 // if ((svecComp = this.getValidSvecComposite(objects)) == null)
221 // } catch (final PCEPDocumentedException e) {
222 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
226 // svecList.add(svecComp);
229 // List<Message> subMessages;
230 // final SubReplyValidator subValidator = new SubReplyValidator();
231 // while (!objects.isEmpty()) {
232 // subMessages = subValidator.validate(objects, svecList);
233 // if (subMessages == null)
235 // msgs.addAll(subMessages);
238 // if (msgs.isEmpty()) {
239 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING)));
243 // if (!objects.isEmpty())
244 // throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
249 // private CompositeReplySvecObject getValidSvecComposite(final List<Object> objects) throws PCEPDocumentedException
251 // if (objects == null)
252 // throw new IllegalArgumentException("List cannot be null.");
254 // if (!(objects.get(0) instanceof PCEPSvecObject))
257 // final PCEPSvecObject svec = (PCEPSvecObject) objects.get(0);
258 // objects.remove(0);
260 // PCEPObjectiveFunctionObject of = null;
261 // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
265 // while (!objects.isEmpty()) {
266 // obj = objects.get(0);
268 // if (obj instanceof UnknownObject)
269 // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError());
274 // if (obj instanceof PCEPObjectiveFunctionObject) {
275 // of = (PCEPObjectiveFunctionObject) obj;
280 // if (obj instanceof PCEPMetricObject) {
281 // metrics.add((PCEPMetricObject) obj);
290 // objects.remove(0);
293 // return new CompositeReplySvecObject(svec, of, metrics);
296 // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean
298 // return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(),
299 // origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(),
300 // origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(),
301 // origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored());