BUG-47 : PCEP migration to generated DTOs.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / message / PCEPRequestMessageValidator.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.message;
9
10
11 /**
12  * PCEPRequestMessage validator. Validates message integrity.
13  */
14 // FIXME: merge with parser
15 class PCEPRequestMessageValidator {
16
17         // @Override
18         // public List<Message> validate(final List<Object> objects) {
19         // if (objects == null)
20         // throw new IllegalArgumentException("Passed list can't be null.");
21         //
22         // final List<Message> msgs = Lists.newArrayList();
23         // final List<CompositeRequestSvecObject> svecList = new ArrayList<CompositeRequestSvecObject>();
24         //
25         // CompositeRequestSvecObject svecComp;
26         // while (!objects.isEmpty()) {
27         // try {
28         // if ((svecComp = getValidSvecComposite(objects)) == null)
29         // break;
30         // } catch (final PCEPDocumentedException e) {
31         // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
32         // return msgs;
33         // }
34         //
35         // svecList.add(svecComp);
36         // }
37         //
38         // while (!objects.isEmpty()) {
39         // final List<CompositeRequestObject> requests = new ArrayList<CompositeRequestObject>();
40         // PCEPRequestParameterObject rpObj = null;
41         // boolean requestRejected = false;
42         //
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;
49         // }
50         //
51         // } else {
52         // // if RP obj is missing return error only;
53         // msgs.clear();
54         // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING)));
55         // return msgs;
56         // }
57         //
58         // PCEPEndPointsObject<?> endPoints = null;
59         // if (objects.get(0) instanceof PCEPEndPointsObject<?>) {
60         // endPoints = (PCEPEndPointsObject<?>) objects.get(0);
61         // objects.remove(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;
66         // }
67         // } else {
68         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
69         // PCEPErrorObject(PCEPErrors.END_POINTS_MISSING))));
70         // requestRejected = true;
71         // }
72         //
73         // // ignore all continual end-points objects
74         // while (!objects.isEmpty() && objects.get(0) instanceof PCEPEndPointsObject<?>) {
75         // objects.remove(0);
76         // }
77         //
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;
87         //
88         // int state = 1;
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;
96         // }
97         //
98         // objects.remove(0);
99         // continue;
100         // }
101         // switch (state) {
102         // case 1:
103         // state = 2;
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;
110         // }
111         // break;
112         // }
113         // case 2:
114         // state = 3;
115         // if (obj instanceof PCEPLspObject) {
116         // lsp = (PCEPLspObject) obj;
117         // break;
118         // }
119         // case 3:
120         // state = 4;
121         // if (obj instanceof PCEPLspaObject) {
122         // lspa = (PCEPLspaObject) obj;
123         // break;
124         // }
125         // case 4:
126         // state = 5;
127         // if (obj instanceof PCEPRequestedPathBandwidthObject) {
128         // bandwidth = (PCEPRequestedPathBandwidthObject) obj;
129         // break;
130         // }
131         // case 5:
132         // state = 6;
133         // if (obj instanceof PCEPMetricObject) {
134         // metrics.add((PCEPMetricObject) obj);
135         // state = 5;
136         //
137         // break;
138         // }
139         // case 6:
140         // state = 8;
141         // if (obj instanceof PCEPReportedRouteObject) {
142         // rro = (PCEPReportedRouteObject) obj;
143         // state = 7;
144         // break;
145         // }
146         // case 7:
147         // state = 8;
148         // if (obj instanceof PCEPExistingPathBandwidthObject) {
149         // rroBandwidth = (PCEPExistingPathBandwidthObject) obj;
150         // break;
151         // }
152         // case 8:
153         // state = 9;
154         // if (obj instanceof PCEPIncludeRouteObject) {
155         // iro = (PCEPIncludeRouteObject) obj;
156         // break;
157         // }
158         // case 9:
159         // if (obj instanceof PCEPLoadBalancingObject) {
160         // loadBalancing = (PCEPLoadBalancingObject) obj;
161         // break;
162         // }
163         // state = 10;
164         // }
165         //
166         // if (state == 10) {
167         // break;
168         // }
169         //
170         // objects.remove(obj);
171         // }
172         //
173         // if (rpObj.isReoptimized() && bandwidth != null && bandwidth.getBandwidth() != new Bandwidth(new byte[] { 0 }) &&
174         // rro == null) {
175         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
176         // PCEPErrorObject(PCEPErrors.RRO_MISSING))));
177         // requestRejected = true;
178         // }
179         //
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)));
184         // }
185         // }
186         //
187         // return msgs;
188         // }
189         //
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.");
194         // }
195         //
196         // PCEPSvecObject svec = null;
197         // if (objects.get(0) instanceof PCEPSvecObject) {
198         // svec = (PCEPSvecObject) objects.get(0);
199         // objects.remove(svec);
200         // } else
201         // return null;
202         //
203         // PCEPObjectiveFunctionObject of = null;
204         // PCEPGlobalConstraintsObject gc = null;
205         // PCEPExcludeRouteObject xro = null;
206         // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
207         //
208         // int state = 1;
209         // while (!objects.isEmpty()) {
210         // final Object obj = objects.get(0);
211         //
212         // if (obj instanceof UnknownObject && ((UnknownObject) obj).isProcessingRule()) {
213         // throw new PCEPDocumentedException("Unknown object in SVEC list.", ((UnknownObject) obj).getError());
214         // }
215         //
216         // switch (state) {
217         // case 1:
218         // state = 2;
219         // if (obj instanceof PCEPObjectiveFunctionObject) {
220         // of = (PCEPObjectiveFunctionObject) obj;
221         // break;
222         // }
223         // case 2:
224         // state = 3;
225         // if (obj instanceof PCEPGlobalConstraintsObject) {
226         // gc = (PCEPGlobalConstraintsObject) obj;
227         // break;
228         // }
229         // case 3:
230         // state = 4;
231         // if (obj instanceof PCEPExcludeRouteObject) {
232         // xro = (PCEPExcludeRouteObject) obj;
233         // break;
234         // }
235         // case 4:
236         // state = 5;
237         // if (obj instanceof PCEPMetricObject) {
238         // metrics.add((PCEPMetricObject) obj);
239         // state = 4;
240         //
241         // break;
242         // }
243         // }
244         //
245         // if (state == 5)
246         // break;
247         //
248         // objects.remove(obj);
249         // }
250         //
251         // return new CompositeRequestSvecObject(svec, of, gc, xro, metrics);
252         // }
253         //
254         // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean
255         // processed) {
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());
260         // }
261 }