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 java.util.List;
14 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
15 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrepMessage;
20 * Parser for {@link PcrepMessage}
23 public class PCEPRequestMessageParser extends AbstractMessageParser {
25 public static final int TYPE = 3;
27 public PCEPRequestMessageParser(final ObjectHandlerRegistry registry) {
32 public void serializeMessage(final Message message, final ByteBuf buffer) {
33 if (!(message instanceof PcrepMessage)) {
34 throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + message.getClass()
35 + ". Needed PcrepMessage.");
40 protected Message validate(
41 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object> objects,
42 final List<Message> errors) throws PCEPDeserializerException {
43 // if (objects == null)
44 // throw new IllegalArgumentException("Passed list can't be null.");
46 // final List<Message> msgs = Lists.newArrayList();
47 // final List<CompositeRequestSvecObject> svecList = new ArrayList<CompositeRequestSvecObject>();
49 // CompositeRequestSvecObject svecComp;
50 // while (!objects.isEmpty()) {
52 // if ((svecComp = getValidSvecComposite(objects)) == null)
54 // } catch (final PCEPDocumentedException e) {
55 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
59 // svecList.add(svecComp);
62 // while (!objects.isEmpty()) {
63 // final List<CompositeRequestObject> requests = new ArrayList<CompositeRequestObject>();
64 // PCEPRequestParameterObject rpObj = null;
65 // boolean requestRejected = false;
67 // if (objects.get(0) instanceof PCEPRequestParameterObject) {
68 // rpObj = (PCEPRequestParameterObject) objects.get(0);
69 // objects.remove(rpObj);
70 // if (!rpObj.isProcessed()) {
71 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(rpObj, new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
72 // requestRejected = true;
76 // // if RP obj is missing return error only;
78 // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING)));
82 // PCEPEndPointsObject<?> endPoints = null;
83 // if (objects.get(0) instanceof PCEPEndPointsObject<?>) {
84 // endPoints = (PCEPEndPointsObject<?>) objects.get(0);
86 // if (!endPoints.isProcessed()) {
87 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
88 // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
89 // requestRejected = true;
92 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
93 // PCEPErrorObject(PCEPErrors.END_POINTS_MISSING))));
94 // requestRejected = true;
97 // // ignore all continual end-points objects
98 // while (!objects.isEmpty() && objects.get(0) instanceof PCEPEndPointsObject<?>) {
102 // PCEPClassTypeObject classType = null;
103 // PCEPLspObject lsp = null;
104 // PCEPLspaObject lspa = null;
105 // PCEPRequestedPathBandwidthObject bandwidth = null;
106 // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
107 // PCEPReportedRouteObject rro = null;
108 // PCEPExistingPathBandwidthObject rroBandwidth = null;
109 // PCEPIncludeRouteObject iro = null;
110 // PCEPLoadBalancingObject loadBalancing = null;
113 // while (!objects.isEmpty()) {
114 // final Object obj = objects.get(0);
115 // if (obj instanceof UnknownObject) {
116 // if (((UnknownObject) obj).isProcessingRule()) {
117 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(((UnknownObject)
118 // obj).getError()))));
119 // requestRejected = true;
122 // objects.remove(0);
128 // if (obj instanceof PCEPClassTypeObject) {
129 // classType = (PCEPClassTypeObject) obj;
130 // if (!classType.isProcessed()) {
131 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
132 // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
133 // requestRejected = true;
139 // if (obj instanceof PCEPLspObject) {
140 // lsp = (PCEPLspObject) obj;
145 // if (obj instanceof PCEPLspaObject) {
146 // lspa = (PCEPLspaObject) obj;
151 // if (obj instanceof PCEPRequestedPathBandwidthObject) {
152 // bandwidth = (PCEPRequestedPathBandwidthObject) obj;
157 // if (obj instanceof PCEPMetricObject) {
158 // metrics.add((PCEPMetricObject) obj);
165 // if (obj instanceof PCEPReportedRouteObject) {
166 // rro = (PCEPReportedRouteObject) obj;
172 // if (obj instanceof PCEPExistingPathBandwidthObject) {
173 // rroBandwidth = (PCEPExistingPathBandwidthObject) obj;
178 // if (obj instanceof PCEPIncludeRouteObject) {
179 // iro = (PCEPIncludeRouteObject) obj;
183 // if (obj instanceof PCEPLoadBalancingObject) {
184 // loadBalancing = (PCEPLoadBalancingObject) obj;
190 // if (state == 10) {
194 // objects.remove(obj);
197 // if (rpObj.isReoptimized() && bandwidth != null && bandwidth.getBandwidth() != new Bandwidth(new byte[] { 0 }) &&
199 // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new
200 // PCEPErrorObject(PCEPErrors.RRO_MISSING))));
201 // requestRejected = true;
204 // if (!requestRejected) {
205 // requests.add(new CompositeRequestObject(rpObj, endPoints, classType, lsp, lspa, bandwidth, metrics, rro,
206 // rroBandwidth, iro, loadBalancing));
207 // msgs.add(new PCEPRequestMessage(Collections.unmodifiableList(svecList), Collections.unmodifiableList(requests)));
214 // private static CompositeRequestSvecObject getValidSvecComposite(final List<Object> objects) throws
215 // PCEPDocumentedException {
216 // if (objects == null || objects.isEmpty()) {
217 // throw new IllegalArgumentException("List cannot be null or empty.");
220 // PCEPSvecObject svec = null;
221 // if (objects.get(0) instanceof PCEPSvecObject) {
222 // svec = (PCEPSvecObject) objects.get(0);
223 // objects.remove(svec);
227 // PCEPObjectiveFunctionObject of = null;
228 // PCEPGlobalConstraintsObject gc = null;
229 // PCEPExcludeRouteObject xro = null;
230 // final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
233 // while (!objects.isEmpty()) {
234 // final Object obj = objects.get(0);
236 // if (obj instanceof UnknownObject && ((UnknownObject) obj).isProcessingRule()) {
237 // throw new PCEPDocumentedException("Unknown object in SVEC list.", ((UnknownObject) obj).getError());
243 // if (obj instanceof PCEPObjectiveFunctionObject) {
244 // of = (PCEPObjectiveFunctionObject) obj;
249 // if (obj instanceof PCEPGlobalConstraintsObject) {
250 // gc = (PCEPGlobalConstraintsObject) obj;
255 // if (obj instanceof PCEPExcludeRouteObject) {
256 // xro = (PCEPExcludeRouteObject) obj;
261 // if (obj instanceof PCEPMetricObject) {
262 // metrics.add((PCEPMetricObject) obj);
272 // objects.remove(obj);
275 // return new CompositeRequestSvecObject(svec, of, gc, xro, metrics);
278 // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean
280 // return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(),
281 // origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(),
282 // origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(),
283 // origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored());
290 public int getMessageType() {