BUG-47 : PCEP migration to generated DTOs.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / message / PCEPReplyMessageValidator.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  * PCEPReplyMessage validator. Validates message integrity.
13  */
14 // FIXME: merge with parser
15 class PCEPReplyMessageValidator {
16
17         // private static class SubReplyValidator {
18         //
19         // private boolean requestRejected = true;
20         //
21         // private List<Message> msgs = Lists.newArrayList();
22         //
23         // private PCEPRequestParameterObject rpObj;
24         //
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;
32         //
33         // private void init() {
34         // this.requestRejected = false;
35         // this.msgs = Lists.newArrayList();
36         //
37         // this.noPath = null;
38         // this.lsp = null;
39         // this.lspa = null;
40         // this.iro = null;
41         // this.rpObj = null;
42         // this.metrics = new ArrayList<PCEPMetricObject>();
43         // this.paths = new ArrayList<CompositePathObject>();
44         // }
45         //
46         // public List<Message> validate(final List<Object> objects, final List<CompositeReplySvecObject> svecList) {
47         // this.init();
48         //
49         // if (!(objects.get(0) instanceof PCEPRequestParameterObject))
50         // return null;
51         //
52         // final PCEPRequestParameterObject rpObj = (PCEPRequestParameterObject) objects.get(0);
53         // objects.remove(0);
54         //
55         // Object obj;
56         // int state = 1;
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;
64         // }
65         //
66         // objects.remove(0);
67         // continue;
68         // }
69         //
70         // switch (state) {
71         // case 1:
72         // state = 2;
73         // if (obj instanceof PCEPNoPathObject) {
74         // this.noPath = (PCEPNoPathObject) obj;
75         // break;
76         // }
77         // case 2:
78         // state = 3;
79         // if (obj instanceof PCEPLspObject) {
80         // this.lsp = (PCEPLspObject) obj;
81         // break;
82         // }
83         // case 3:
84         // state = 4;
85         // if (obj instanceof PCEPLspaObject) {
86         // this.lspa = (PCEPLspaObject) obj;
87         // break;
88         // }
89         // case 4:
90         // state = 5;
91         // if (obj instanceof PCEPRequestedPathBandwidthObject) {
92         // this.bandwidth = (PCEPRequestedPathBandwidthObject) obj;
93         // break;
94         // }
95         // case 5:
96         // state = 6;
97         // if (obj instanceof PCEPMetricObject) {
98         // this.metrics.add((PCEPMetricObject) obj);
99         // state = 5;
100         // break;
101         // }
102         // case 6:
103         // state = 7;
104         // if (obj instanceof PCEPIncludeRouteObject) {
105         // this.iro = (PCEPIncludeRouteObject) obj;
106         // state = 8;
107         // break;
108         // }
109         // }
110         //
111         // if (state == 7)
112         // break;
113         //
114         // objects.remove(0);
115         //
116         // if (state == 8)
117         // break;
118         // }
119         //
120         // if (!objects.isEmpty()) {
121         // CompositePathObject path = this.getValidCompositePath(objects);
122         // while (path != null) {
123         // this.paths.add(path);
124         // if (objects.isEmpty())
125         // break;
126         // path = this.getValidCompositePath(objects);
127         // }
128         // }
129         //
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)));
134         // }
135         //
136         // return this.msgs;
137         // }
138         //
139         // private CompositePathObject getValidCompositePath(final List<Object> objects) {
140         // if (!(objects.get(0) instanceof PCEPExplicitRouteObject))
141         // return null;
142         //
143         // final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0);
144         // objects.remove(0);
145         //
146         // PCEPLspaObject pathLspa = null;
147         // PCEPRequestedPathBandwidthObject pathBandwidth = null;
148         // final List<PCEPMetricObject> pathMetrics = new ArrayList<PCEPMetricObject>();
149         // PCEPIncludeRouteObject pathIro = null;
150         //
151         // Object obj;
152         // int state = 1;
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;
160         // }
161         // objects.remove(0);
162         // continue;
163         // }
164         //
165         // switch (state) {
166         // case 1:
167         // state = 2;
168         // if (obj instanceof PCEPLspaObject) {
169         // pathLspa = (PCEPLspaObject) obj;
170         // break;
171         // }
172         // case 2:
173         // state = 3;
174         // if (obj instanceof PCEPRequestedPathBandwidthObject) {
175         // pathBandwidth = (PCEPRequestedPathBandwidthObject) obj;
176         // break;
177         // }
178         // case 3:
179         // state = 4;
180         // if (obj instanceof PCEPMetricObject) {
181         // pathMetrics.add((PCEPMetricObject) obj);
182         // state = 3;
183         // break;
184         // }
185         // case 4:
186         // state = 5;
187         // if (obj instanceof PCEPIncludeRouteObject) {
188         // pathIro = (PCEPIncludeRouteObject) obj;
189         // state = 6;
190         // break;
191         // }
192         //
193         // }
194         //
195         // if (state == 5)
196         // break;
197         //
198         // objects.remove(0);
199         //
200         // if (state == 6)
201         // break;
202         // }
203         //
204         // return new CompositePathObject(explicitRoute, pathLspa, pathBandwidth, pathMetrics, pathIro);
205         // }
206         // }
207         //
208         // @Override
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.");
212         //
213         // final List<Message> msgs = Lists.newArrayList();
214         // final List<CompositeReplySvecObject> svecList = new ArrayList<CompositeReplySvecObject>();
215         //
216         // CompositeReplySvecObject svecComp;
217         // while (!objects.isEmpty()) {
218         // try {
219         // if ((svecComp = this.getValidSvecComposite(objects)) == null)
220         // break;
221         // } catch (final PCEPDocumentedException e) {
222         // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
223         // return msgs;
224         // }
225         //
226         // svecList.add(svecComp);
227         // }
228         //
229         // List<Message> subMessages;
230         // final SubReplyValidator subValidator = new SubReplyValidator();
231         // while (!objects.isEmpty()) {
232         // subMessages = subValidator.validate(objects, svecList);
233         // if (subMessages == null)
234         // break;
235         // msgs.addAll(subMessages);
236         // }
237         //
238         // if (msgs.isEmpty()) {
239         // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING)));
240         // return msgs;
241         // }
242         //
243         // if (!objects.isEmpty())
244         // throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
245         //
246         // return msgs;
247         // }
248         //
249         // private CompositeReplySvecObject getValidSvecComposite(final List<Object> objects) throws PCEPDocumentedException
250         // {
251         // if (objects == null)
252         // throw new IllegalArgumentException("List cannot be null.");
253         //
254         // if (!(objects.get(0) instanceof PCEPSvecObject))
255         // return null;
256         //
257         // final PCEPSvecObject svec = (PCEPSvecObject) objects.get(0);
258         // objects.remove(0);
259         //
260         // PCEPObjectiveFunctionObject of = null;
261         // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
262         //
263         // Object obj;
264         // int state = 1;
265         // while (!objects.isEmpty()) {
266         // obj = objects.get(0);
267         //
268         // if (obj instanceof UnknownObject)
269         // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError());
270         //
271         // switch (state) {
272         // case 1:
273         // state = 2;
274         // if (obj instanceof PCEPObjectiveFunctionObject) {
275         // of = (PCEPObjectiveFunctionObject) obj;
276         // break;
277         // }
278         // case 2:
279         // state = 3;
280         // if (obj instanceof PCEPMetricObject) {
281         // metrics.add((PCEPMetricObject) obj);
282         // state = 2;
283         // break;
284         // }
285         // }
286         //
287         // if (state == 3)
288         // break;
289         //
290         // objects.remove(0);
291         // }
292         //
293         // return new CompositeReplySvecObject(svec, of, metrics);
294         // }
295         //
296         // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean
297         // processed) {
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());
302         // }
303 }