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 * PCEPRequestMessage validator. Validates message integrity.
14 // FIXME: merge with parser
15 class PCEPRequestMessageValidator {
18 // public List<Message> validate(final List<Object> objects) {
19 // if (objects == null)
20 // throw new IllegalArgumentException("Passed list can't be null.");
22 // final List<Message> msgs = Lists.newArrayList();
23 // final List<CompositeRequestSvecObject> svecList = new ArrayList<CompositeRequestSvecObject>();
25 // CompositeRequestSvecObject svecComp;
26 // while (!objects.isEmpty()) {
28 // if ((svecComp = getValidSvecComposite(objects)) == null)
30 // } catch (final PCEPDocumentedException e) {
31 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
35 // svecList.add(svecComp);
38 // while (!objects.isEmpty()) {
39 // final List<CompositeRequestObject> requests = new ArrayList<CompositeRequestObject>();
40 // PCEPRequestParameterObject rpObj = null;
41 // boolean requestRejected = false;
43 // if (objects.get(0) instanceof PCEPRequestParameterObject) {
44 // rpObj = (PCEPRequestParameterObject) objects.get(0);
45 // objects.remove(rpObj);
46 // if (!rpObj.isProcessed()) {
47 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(rpObj, new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
48 // requestRejected = true;
52 // // if RP obj is missing return error only;
54 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING)));
58 // PCEPEndPointsObject<?> endPoints = null;
59 // if (objects.get(0) instanceof PCEPEndPointsObject<?>) {
60 // endPoints = (PCEPEndPointsObject<?>) objects.get(0);
62 // if (!endPoints.isProcessed()) {
63 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
64 // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
65 // requestRejected = true;
68 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
69 // PCEPErrorObject(PCEPErrors.END_POINTS_MISSING))));
70 // requestRejected = true;
73 // // ignore all continual end-points objects
74 // while (!objects.isEmpty() && objects.get(0) instanceof PCEPEndPointsObject<?>) {
78 // PCEPClassTypeObject classType = null;
79 // PCEPLspObject lsp = null;
80 // PCEPLspaObject lspa = null;
81 // PCEPRequestedPathBandwidthObject bandwidth = null;
82 // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
83 // PCEPReportedRouteObject rro = null;
84 // PCEPExistingPathBandwidthObject rroBandwidth = null;
85 // PCEPIncludeRouteObject iro = null;
86 // PCEPLoadBalancingObject loadBalancing = null;
89 // while (!objects.isEmpty()) {
90 // final Object obj = objects.get(0);
91 // if (obj instanceof UnknownObject) {
92 // if (((UnknownObject) obj).isProcessingRule()) {
93 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(((UnknownObject)
94 // obj).getError()))));
95 // requestRejected = true;
104 // if (obj instanceof PCEPClassTypeObject) {
105 // classType = (PCEPClassTypeObject) obj;
106 // if (!classType.isProcessed()) {
107 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
108 // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
109 // requestRejected = true;
115 // if (obj instanceof PCEPLspObject) {
116 // lsp = (PCEPLspObject) obj;
121 // if (obj instanceof PCEPLspaObject) {
122 // lspa = (PCEPLspaObject) obj;
127 // if (obj instanceof PCEPRequestedPathBandwidthObject) {
128 // bandwidth = (PCEPRequestedPathBandwidthObject) obj;
133 // if (obj instanceof PCEPMetricObject) {
134 // metrics.add((PCEPMetricObject) obj);
141 // if (obj instanceof PCEPReportedRouteObject) {
142 // rro = (PCEPReportedRouteObject) obj;
148 // if (obj instanceof PCEPExistingPathBandwidthObject) {
149 // rroBandwidth = (PCEPExistingPathBandwidthObject) obj;
154 // if (obj instanceof PCEPIncludeRouteObject) {
155 // iro = (PCEPIncludeRouteObject) obj;
159 // if (obj instanceof PCEPLoadBalancingObject) {
160 // loadBalancing = (PCEPLoadBalancingObject) obj;
166 // if (state == 10) {
170 // objects.remove(obj);
173 // if (rpObj.isReoptimized() && bandwidth != null && bandwidth.getBandwidth() != new Bandwidth(new byte[] { 0 }) &&
175 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
176 // PCEPErrorObject(PCEPErrors.RRO_MISSING))));
177 // requestRejected = true;
180 // if (!requestRejected) {
181 // requests.add(new CompositeRequestObject(rpObj, endPoints, classType, lsp, lspa, bandwidth, metrics, rro,
182 // rroBandwidth, iro, loadBalancing));
183 // msgs.add(new PCEPRequestMessage(Collections.unmodifiableList(svecList), Collections.unmodifiableList(requests)));
190 // private static CompositeRequestSvecObject getValidSvecComposite(final List<Object> objects) throws
191 // PCEPDocumentedException {
192 // if (objects == null || objects.isEmpty()) {
193 // throw new IllegalArgumentException("List cannot be null or empty.");
196 // PCEPSvecObject svec = null;
197 // if (objects.get(0) instanceof PCEPSvecObject) {
198 // svec = (PCEPSvecObject) objects.get(0);
199 // objects.remove(svec);
203 // PCEPObjectiveFunctionObject of = null;
204 // PCEPGlobalConstraintsObject gc = null;
205 // PCEPExcludeRouteObject xro = null;
206 // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
209 // while (!objects.isEmpty()) {
210 // final Object obj = objects.get(0);
212 // if (obj instanceof UnknownObject && ((UnknownObject) obj).isProcessingRule()) {
213 // throw new PCEPDocumentedException("Unknown object in SVEC list.", ((UnknownObject) obj).getError());
219 // if (obj instanceof PCEPObjectiveFunctionObject) {
220 // of = (PCEPObjectiveFunctionObject) obj;
225 // if (obj instanceof PCEPGlobalConstraintsObject) {
226 // gc = (PCEPGlobalConstraintsObject) obj;
231 // if (obj instanceof PCEPExcludeRouteObject) {
232 // xro = (PCEPExcludeRouteObject) obj;
237 // if (obj instanceof PCEPMetricObject) {
238 // metrics.add((PCEPMetricObject) obj);
248 // objects.remove(obj);
251 // return new CompositeRequestSvecObject(svec, of, gc, xro, metrics);
254 // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean
256 // return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(),
257 // origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(),
258 // origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(),
259 // origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored());