Fix for commit 75b14cd92b9f5bb4ced99fae55b3fcdd7236c2d4.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / message / PCEPReplyMessageParser.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.impl.AbstractMessageParser;
14 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrepMessage;
17
18 /**
19  * Parser for {@link PcrepMessage}
20  */
21 // FIXME: finish
22 public class PCEPReplyMessageParser extends AbstractMessageParser {
23
24         public static final int TYPE = 4;
25
26         public PCEPReplyMessageParser(final ObjectHandlerRegistry registry) {
27                 super(registry);
28         }
29
30         @Override
31         public void serializeMessage(final Message message, final ByteBuf buffer) {
32                 if (!(message instanceof PcrepMessage)) {
33                         throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass()
34                                         + ". Nedded PcrepMessage.");
35                 }
36
37         }
38
39         @Override
40         public PcrepMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException {
41                 return null;
42         }
43
44         // private static class SubReplyValidator {
45         //
46         // private boolean requestRejected = true;
47         //
48         // private List<Message> msgs = Lists.newArrayList();
49         //
50         // private PCEPRequestParameterObject rpObj;
51         //
52         // private PCEPNoPathObject noPath;
53         // private PCEPLspObject lsp;
54         // private PCEPLspaObject lspa;
55         // private PCEPRequestedPathBandwidthObject bandwidth;
56         // private List<PCEPMetricObject> metrics;
57         // private PCEPIncludeRouteObject iro;
58         // private List<CompositePathObject> paths;
59         //
60         // private void init() {
61         // this.requestRejected = false;
62         // this.msgs = Lists.newArrayList();
63         //
64         // this.noPath = null;
65         // this.lsp = null;
66         // this.lspa = null;
67         // this.iro = null;
68         // this.rpObj = null;
69         // this.metrics = new ArrayList<PCEPMetricObject>();
70         // this.paths = new ArrayList<CompositePathObject>();
71         // }
72         //
73         // public List<Message> validate(final List<Object> objects, final List<CompositeReplySvecObject> svecList) {
74         // this.init();
75         //
76         // if (!(objects.get(0) instanceof PCEPRequestParameterObject))
77         // return null;
78         //
79         // final PCEPRequestParameterObject rpObj = (PCEPRequestParameterObject) objects.get(0);
80         // objects.remove(0);
81         //
82         // Object obj;
83         // int state = 1;
84         // while (!objects.isEmpty()) {
85         // obj = objects.get(0);
86         // if (obj instanceof UnknownObject) {
87         // if (((UnknownObject) obj).isProcessingRule()) {
88         // this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
89         // PCEPErrorObject(((UnknownObject) obj).getError()))));
90         // this.requestRejected = true;
91         // }
92         //
93         // objects.remove(0);
94         // continue;
95         // }
96         //
97         // switch (state) {
98         // case 1:
99         // state = 2;
100         // if (obj instanceof PCEPNoPathObject) {
101         // this.noPath = (PCEPNoPathObject) obj;
102         // break;
103         // }
104         // case 2:
105         // state = 3;
106         // if (obj instanceof PCEPLspObject) {
107         // this.lsp = (PCEPLspObject) obj;
108         // break;
109         // }
110         // case 3:
111         // state = 4;
112         // if (obj instanceof PCEPLspaObject) {
113         // this.lspa = (PCEPLspaObject) obj;
114         // break;
115         // }
116         // case 4:
117         // state = 5;
118         // if (obj instanceof PCEPRequestedPathBandwidthObject) {
119         // this.bandwidth = (PCEPRequestedPathBandwidthObject) obj;
120         // break;
121         // }
122         // case 5:
123         // state = 6;
124         // if (obj instanceof PCEPMetricObject) {
125         // this.metrics.add((PCEPMetricObject) obj);
126         // state = 5;
127         // break;
128         // }
129         // case 6:
130         // state = 7;
131         // if (obj instanceof PCEPIncludeRouteObject) {
132         // this.iro = (PCEPIncludeRouteObject) obj;
133         // state = 8;
134         // break;
135         // }
136         // }
137         //
138         // if (state == 7)
139         // break;
140         //
141         // objects.remove(0);
142         //
143         // if (state == 8)
144         // break;
145         // }
146         //
147         // if (!objects.isEmpty()) {
148         // CompositePathObject path = this.getValidCompositePath(objects);
149         // while (path != null) {
150         // this.paths.add(path);
151         // if (objects.isEmpty())
152         // break;
153         // path = this.getValidCompositePath(objects);
154         // }
155         // }
156         //
157         // if (!this.requestRejected) {
158         // this.msgs.add(new PCEPReplyMessage(Collections.unmodifiableList(Arrays.asList(new CompositeResponseObject(rpObj,
159         // this.noPath, this.lsp, this.lspa, this.bandwidth, this.metrics, this.iro, this.paths))),
160         // Collections.unmodifiableList(svecList)));
161         // }
162         //
163         // return this.msgs;
164         // }
165         //
166
167         // private Replies getValidCompositePath(final List<Object> objects) {
168         // if (!(objects.get(0) instanceof Rp)) {
169         // throw new PCEPDocumentedException("Pcrep message must contain at least one RP object.", PCEPErrors.RP_MISSING);
170         // }
171         // final Rp rp = (Rp) objects.get(0);
172         // objects.remove(0);
173         //
174         // NoPath nopath = null;
175         // final Ero ero = null;
176         // final Lspa lspa = null;
177         // final Bandwidth bandwidth = null;
178         // final List<Metrics> pathMetrics = Lists.newArrayList();
179         // Iro pathIro = null;
180         //
181         // Object obj;
182         // State state = State.Init;
183         // while (!objects.isEmpty()) {
184         // obj = objects.get(0);
185         //
186         // switch (state) {
187         // case Init:
188         // state = State.EroIn;
189         // if (obj instanceof NoPath) {
190         // nopath = (NoPath) obj;
191         // state = State.End;
192         // break;
193         // }
194         // case EroIn:
195         // state = State.LspaIn;
196         // if (obj instanceof Lspa) {
197         // lspa = (Lspa) obj;
198         // break;
199         // }
200         // case LspaIn:
201         // state = State.BandwidthIn;
202         // if (obj instanceof Bandwidth) {
203         // bandwidth = (Bandwidth) obj;
204         // break;
205         // }
206         // case MetricIn:
207         // state = State.IroIn;
208         // if (obj instanceof Metric) {
209         // pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
210         // state = State.MetricIn;
211         // break;
212         // }
213         // case IroIn:
214         // state = State.End;
215         // if (obj instanceof Iro) {
216         // pathIro = (Iro) obj;
217         // break;
218         // }
219         // case End:
220         // break;
221         // default:
222         // if (obj instanceof UnknownObject) {
223         // if (((UnknownObject) obj).isProcessingRule()) {
224         // this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(this.rpObj, false), new
225         // PCEPErrorObject(((UnknownObject) obj).getError()))));
226         // this.requestRejected = true;
227         // }
228         // objects.remove(0);
229         // continue;
230         // }
231         // }
232         // objects.remove(0);
233         // }
234         //
235         // final PathBuilder builder = new PathBuilder();
236         // builder.setEro(ero);
237         // builder.setLspa(lspa);
238         // builder.setBandwidth(bandwidth);
239         // builder.setMetrics(pathMetrics);
240         // builder.setIro(pathIro);
241         // return new RepliesBuilder().setRp(rp).setResult(value).build();
242         // }
243         //
244         // private Result parseResult(List<Object> objs) {
245         //
246         // }
247
248         private enum State {
249                 Init, NoPathIn, EroIn, LspaIn, BandwidthIn, MetricIn, IroIn, End
250         }
251
252         @Override
253         public int getMessageType() {
254                 return TYPE;
255         }
256 }