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;
10 import io.netty.buffer.ByteBuf;
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;
19 * Parser for {@link PcrepMessage}
22 public class PCEPReplyMessageParser extends AbstractMessageParser {
24 public static final int TYPE = 4;
26 public PCEPReplyMessageParser(final ObjectHandlerRegistry registry) {
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.");
40 public PcrepMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException {
44 // private static class SubReplyValidator {
46 // private boolean requestRejected = true;
48 // private List<Message> msgs = Lists.newArrayList();
50 // private PCEPRequestParameterObject rpObj;
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;
60 // private void init() {
61 // this.requestRejected = false;
62 // this.msgs = Lists.newArrayList();
64 // this.noPath = null;
69 // this.metrics = new ArrayList<PCEPMetricObject>();
70 // this.paths = new ArrayList<CompositePathObject>();
73 // public List<Message> validate(final List<Object> objects, final List<CompositeReplySvecObject> svecList) {
76 // if (!(objects.get(0) instanceof PCEPRequestParameterObject))
79 // final PCEPRequestParameterObject rpObj = (PCEPRequestParameterObject) objects.get(0);
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;
100 // if (obj instanceof PCEPNoPathObject) {
101 // this.noPath = (PCEPNoPathObject) obj;
106 // if (obj instanceof PCEPLspObject) {
107 // this.lsp = (PCEPLspObject) obj;
112 // if (obj instanceof PCEPLspaObject) {
113 // this.lspa = (PCEPLspaObject) obj;
118 // if (obj instanceof PCEPRequestedPathBandwidthObject) {
119 // this.bandwidth = (PCEPRequestedPathBandwidthObject) obj;
124 // if (obj instanceof PCEPMetricObject) {
125 // this.metrics.add((PCEPMetricObject) obj);
131 // if (obj instanceof PCEPIncludeRouteObject) {
132 // this.iro = (PCEPIncludeRouteObject) obj;
141 // objects.remove(0);
147 // if (!objects.isEmpty()) {
148 // CompositePathObject path = this.getValidCompositePath(objects);
149 // while (path != null) {
150 // this.paths.add(path);
151 // if (objects.isEmpty())
153 // path = this.getValidCompositePath(objects);
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)));
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);
171 // final Rp rp = (Rp) objects.get(0);
172 // objects.remove(0);
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;
182 // State state = State.Init;
183 // while (!objects.isEmpty()) {
184 // obj = objects.get(0);
188 // state = State.EroIn;
189 // if (obj instanceof NoPath) {
190 // nopath = (NoPath) obj;
191 // state = State.End;
195 // state = State.LspaIn;
196 // if (obj instanceof Lspa) {
197 // lspa = (Lspa) obj;
201 // state = State.BandwidthIn;
202 // if (obj instanceof Bandwidth) {
203 // bandwidth = (Bandwidth) obj;
207 // state = State.IroIn;
208 // if (obj instanceof Metric) {
209 // pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
210 // state = State.MetricIn;
214 // state = State.End;
215 // if (obj instanceof Iro) {
216 // pathIro = (Iro) obj;
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;
228 // objects.remove(0);
232 // objects.remove(0);
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();
244 // private Result parseResult(List<Object> objs) {
249 Init, NoPathIn, EroIn, LspaIn, BandwidthIn, MetricIn, IroIn, End
253 public int getMessageType() {