3c2599b65cd4b42425aacfa32292f053e17ca3e2
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / message / PCEPRequestMessageParser.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 import io.netty.buffer.ByteBuf;
11
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrepMessage;
16
17 /**
18  * Parser for {@link PcrepMessage}
19  */
20 // FIXME finish
21 public class PCEPRequestMessageParser extends AbstractMessageParser {
22
23         public static final int TYPE = 3;
24
25         public PCEPRequestMessageParser(final ObjectHandlerRegistry registry) {
26                 super(registry);
27         }
28
29         @Override
30         public void serializeMessage(final Message message, final ByteBuf buffer) {
31                 if (!(message instanceof PcrepMessage)) {
32                         throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + message.getClass()
33                                         + ". Needed PcrepMessage.");
34                 }
35         }
36
37         @Override
38         public PcrepMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException {
39                 // TODO Auto-generated method stub
40                 return null;
41         }
42
43         // public List<Message> validate(final List<Object> objects) {
44         // if (objects == null)
45         // throw new IllegalArgumentException("Passed list can't be null.");
46         //
47         // final List<Message> msgs = Lists.newArrayList();
48         // final List<CompositeRequestSvecObject> svecList = new ArrayList<CompositeRequestSvecObject>();
49         //
50         // CompositeRequestSvecObject svecComp;
51         // while (!objects.isEmpty()) {
52         // try {
53         // if ((svecComp = getValidSvecComposite(objects)) == null)
54         // break;
55         // } catch (final PCEPDocumentedException e) {
56         // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
57         // return msgs;
58         // }
59         //
60         // svecList.add(svecComp);
61         // }
62         //
63         // while (!objects.isEmpty()) {
64         // final List<CompositeRequestObject> requests = new ArrayList<CompositeRequestObject>();
65         // PCEPRequestParameterObject rpObj = null;
66         // boolean requestRejected = false;
67         //
68         // if (objects.get(0) instanceof PCEPRequestParameterObject) {
69         // rpObj = (PCEPRequestParameterObject) objects.get(0);
70         // objects.remove(rpObj);
71         // if (!rpObj.isProcessed()) {
72         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(rpObj, new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
73         // requestRejected = true;
74         // }
75         //
76         // } else {
77         // // if RP obj is missing return error only;
78         // msgs.clear();
79         // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING)));
80         // return msgs;
81         // }
82         //
83         // PCEPEndPointsObject<?> endPoints = null;
84         // if (objects.get(0) instanceof PCEPEndPointsObject<?>) {
85         // endPoints = (PCEPEndPointsObject<?>) objects.get(0);
86         // objects.remove(0);
87         // if (!endPoints.isProcessed()) {
88         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
89         // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
90         // requestRejected = true;
91         // }
92         // } else {
93         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
94         // PCEPErrorObject(PCEPErrors.END_POINTS_MISSING))));
95         // requestRejected = true;
96         // }
97         //
98         // // ignore all continual end-points objects
99         // while (!objects.isEmpty() && objects.get(0) instanceof PCEPEndPointsObject<?>) {
100         // objects.remove(0);
101         // }
102         //
103         // PCEPClassTypeObject classType = null;
104         // PCEPLspObject lsp = null;
105         // PCEPLspaObject lspa = null;
106         // PCEPRequestedPathBandwidthObject bandwidth = null;
107         // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
108         // PCEPReportedRouteObject rro = null;
109         // PCEPExistingPathBandwidthObject rroBandwidth = null;
110         // PCEPIncludeRouteObject iro = null;
111         // PCEPLoadBalancingObject loadBalancing = null;
112         //
113         // int state = 1;
114         // while (!objects.isEmpty()) {
115         // final Object obj = objects.get(0);
116         // if (obj instanceof UnknownObject) {
117         // if (((UnknownObject) obj).isProcessingRule()) {
118         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(((UnknownObject)
119         // obj).getError()))));
120         // requestRejected = true;
121         // }
122         //
123         // objects.remove(0);
124         // continue;
125         // }
126         // switch (state) {
127         // case 1:
128         // state = 2;
129         // if (obj instanceof PCEPClassTypeObject) {
130         // classType = (PCEPClassTypeObject) obj;
131         // if (!classType.isProcessed()) {
132         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
133         // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
134         // requestRejected = true;
135         // }
136         // break;
137         // }
138         // case 2:
139         // state = 3;
140         // if (obj instanceof PCEPLspObject) {
141         // lsp = (PCEPLspObject) obj;
142         // break;
143         // }
144         // case 3:
145         // state = 4;
146         // if (obj instanceof PCEPLspaObject) {
147         // lspa = (PCEPLspaObject) obj;
148         // break;
149         // }
150         // case 4:
151         // state = 5;
152         // if (obj instanceof PCEPRequestedPathBandwidthObject) {
153         // bandwidth = (PCEPRequestedPathBandwidthObject) obj;
154         // break;
155         // }
156         // case 5:
157         // state = 6;
158         // if (obj instanceof PCEPMetricObject) {
159         // metrics.add((PCEPMetricObject) obj);
160         // state = 5;
161         //
162         // break;
163         // }
164         // case 6:
165         // state = 8;
166         // if (obj instanceof PCEPReportedRouteObject) {
167         // rro = (PCEPReportedRouteObject) obj;
168         // state = 7;
169         // break;
170         // }
171         // case 7:
172         // state = 8;
173         // if (obj instanceof PCEPExistingPathBandwidthObject) {
174         // rroBandwidth = (PCEPExistingPathBandwidthObject) obj;
175         // break;
176         // }
177         // case 8:
178         // state = 9;
179         // if (obj instanceof PCEPIncludeRouteObject) {
180         // iro = (PCEPIncludeRouteObject) obj;
181         // break;
182         // }
183         // case 9:
184         // if (obj instanceof PCEPLoadBalancingObject) {
185         // loadBalancing = (PCEPLoadBalancingObject) obj;
186         // break;
187         // }
188         // state = 10;
189         // }
190         //
191         // if (state == 10) {
192         // break;
193         // }
194         //
195         // objects.remove(obj);
196         // }
197         //
198         // if (rpObj.isReoptimized() && bandwidth != null && bandwidth.getBandwidth() != new Bandwidth(new byte[] { 0 }) &&
199         // rro == null) {
200         // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
201         // PCEPErrorObject(PCEPErrors.RRO_MISSING))));
202         // requestRejected = true;
203         // }
204         //
205         // if (!requestRejected) {
206         // requests.add(new CompositeRequestObject(rpObj, endPoints, classType, lsp, lspa, bandwidth, metrics, rro,
207         // rroBandwidth, iro, loadBalancing));
208         // msgs.add(new PCEPRequestMessage(Collections.unmodifiableList(svecList), Collections.unmodifiableList(requests)));
209         // }
210         // }
211         //
212         // return msgs;
213         // }
214         //
215         // private static CompositeRequestSvecObject getValidSvecComposite(final List<Object> objects) throws
216         // PCEPDocumentedException {
217         // if (objects == null || objects.isEmpty()) {
218         // throw new IllegalArgumentException("List cannot be null or empty.");
219         // }
220         //
221         // PCEPSvecObject svec = null;
222         // if (objects.get(0) instanceof PCEPSvecObject) {
223         // svec = (PCEPSvecObject) objects.get(0);
224         // objects.remove(svec);
225         // } else
226         // return null;
227         //
228         // PCEPObjectiveFunctionObject of = null;
229         // PCEPGlobalConstraintsObject gc = null;
230         // PCEPExcludeRouteObject xro = null;
231         // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
232         //
233         // int state = 1;
234         // while (!objects.isEmpty()) {
235         // final Object obj = objects.get(0);
236         //
237         // if (obj instanceof UnknownObject && ((UnknownObject) obj).isProcessingRule()) {
238         // throw new PCEPDocumentedException("Unknown object in SVEC list.", ((UnknownObject) obj).getError());
239         // }
240         //
241         // switch (state) {
242         // case 1:
243         // state = 2;
244         // if (obj instanceof PCEPObjectiveFunctionObject) {
245         // of = (PCEPObjectiveFunctionObject) obj;
246         // break;
247         // }
248         // case 2:
249         // state = 3;
250         // if (obj instanceof PCEPGlobalConstraintsObject) {
251         // gc = (PCEPGlobalConstraintsObject) obj;
252         // break;
253         // }
254         // case 3:
255         // state = 4;
256         // if (obj instanceof PCEPExcludeRouteObject) {
257         // xro = (PCEPExcludeRouteObject) obj;
258         // break;
259         // }
260         // case 4:
261         // state = 5;
262         // if (obj instanceof PCEPMetricObject) {
263         // metrics.add((PCEPMetricObject) obj);
264         // state = 4;
265         //
266         // break;
267         // }
268         // }
269         //
270         // if (state == 5)
271         // break;
272         //
273         // objects.remove(obj);
274         // }
275         //
276         // return new CompositeRequestSvecObject(svec, of, gc, xro, metrics);
277         // }
278         //
279         // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean
280         // processed) {
281         // return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(),
282         // origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(),
283         // origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(),
284         // origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored());
285         // }
286
287         @Override
288         public int getMessageType() {
289                 return TYPE;
290         }
291 }