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.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;
18 * Parser for {@link PcrepMessage}
21 public class PCEPRequestMessageParser extends AbstractMessageParser {
23 public static final int TYPE = 3;
25 public PCEPRequestMessageParser(final ObjectHandlerRegistry registry) {
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.");
38 public PcrepMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException {
39 // TODO Auto-generated method stub
43 // public List<Message> validate(final List<Object> objects) {
44 // if (objects == null)
45 // throw new IllegalArgumentException("Passed list can't be null.");
47 // final List<Message> msgs = Lists.newArrayList();
48 // final List<CompositeRequestSvecObject> svecList = new ArrayList<CompositeRequestSvecObject>();
50 // CompositeRequestSvecObject svecComp;
51 // while (!objects.isEmpty()) {
53 // if ((svecComp = getValidSvecComposite(objects)) == null)
55 // } catch (final PCEPDocumentedException e) {
56 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
60 // svecList.add(svecComp);
63 // while (!objects.isEmpty()) {
64 // final List<CompositeRequestObject> requests = new ArrayList<CompositeRequestObject>();
65 // PCEPRequestParameterObject rpObj = null;
66 // boolean requestRejected = false;
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;
77 // // if RP obj is missing return error only;
79 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING)));
83 // PCEPEndPointsObject<?> endPoints = null;
84 // if (objects.get(0) instanceof PCEPEndPointsObject<?>) {
85 // endPoints = (PCEPEndPointsObject<?>) objects.get(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;
93 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
94 // PCEPErrorObject(PCEPErrors.END_POINTS_MISSING))));
95 // requestRejected = true;
98 // // ignore all continual end-points objects
99 // while (!objects.isEmpty() && objects.get(0) instanceof PCEPEndPointsObject<?>) {
100 // objects.remove(0);
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;
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;
123 // objects.remove(0);
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;
140 // if (obj instanceof PCEPLspObject) {
141 // lsp = (PCEPLspObject) obj;
146 // if (obj instanceof PCEPLspaObject) {
147 // lspa = (PCEPLspaObject) obj;
152 // if (obj instanceof PCEPRequestedPathBandwidthObject) {
153 // bandwidth = (PCEPRequestedPathBandwidthObject) obj;
158 // if (obj instanceof PCEPMetricObject) {
159 // metrics.add((PCEPMetricObject) obj);
166 // if (obj instanceof PCEPReportedRouteObject) {
167 // rro = (PCEPReportedRouteObject) obj;
173 // if (obj instanceof PCEPExistingPathBandwidthObject) {
174 // rroBandwidth = (PCEPExistingPathBandwidthObject) obj;
179 // if (obj instanceof PCEPIncludeRouteObject) {
180 // iro = (PCEPIncludeRouteObject) obj;
184 // if (obj instanceof PCEPLoadBalancingObject) {
185 // loadBalancing = (PCEPLoadBalancingObject) obj;
191 // if (state == 10) {
195 // objects.remove(obj);
198 // if (rpObj.isReoptimized() && bandwidth != null && bandwidth.getBandwidth() != new Bandwidth(new byte[] { 0 }) &&
200 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
201 // PCEPErrorObject(PCEPErrors.RRO_MISSING))));
202 // requestRejected = true;
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)));
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.");
221 // PCEPSvecObject svec = null;
222 // if (objects.get(0) instanceof PCEPSvecObject) {
223 // svec = (PCEPSvecObject) objects.get(0);
224 // objects.remove(svec);
228 // PCEPObjectiveFunctionObject of = null;
229 // PCEPGlobalConstraintsObject gc = null;
230 // PCEPExcludeRouteObject xro = null;
231 // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
234 // while (!objects.isEmpty()) {
235 // final Object obj = objects.get(0);
237 // if (obj instanceof UnknownObject && ((UnknownObject) obj).isProcessingRule()) {
238 // throw new PCEPDocumentedException("Unknown object in SVEC list.", ((UnknownObject) obj).getError());
244 // if (obj instanceof PCEPObjectiveFunctionObject) {
245 // of = (PCEPObjectiveFunctionObject) obj;
250 // if (obj instanceof PCEPGlobalConstraintsObject) {
251 // gc = (PCEPGlobalConstraintsObject) obj;
256 // if (obj instanceof PCEPExcludeRouteObject) {
257 // xro = (PCEPExcludeRouteObject) obj;
262 // if (obj instanceof PCEPMetricObject) {
263 // metrics.add((PCEPMetricObject) obj);
273 // objects.remove(obj);
276 // return new CompositeRequestSvecObject(svec, of, gc, xro, metrics);
279 // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean
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());
288 public int getMessageType() {