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 java.util.List;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * PCEPUpdateRequestMessage validator. Validates message integrity.
20 // FIXME: merge with parser
21 class PCEPUpdateRequestMessageValidator {
23 private static final Logger logger = LoggerFactory.getLogger(PCEPUpdateRequestMessageValidator.class);
25 public List<Message> validate(final List<Object> objects) throws PCEPDeserializerException {
27 throw new IllegalArgumentException("Passed list can't be null.");
29 // final List<CompositeUpdateRequestObject> updateRequests = new ArrayList<CompositeUpdateRequestObject>();
31 // while (!objects.isEmpty()) {
32 // if (objects.get(0) instanceof UnknownObject) {
33 // logger.warn("Unknown object found (should be Lsp) - {}.", objects.get(0));
34 // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject)
35 // objects.get(0)).getError())));
37 // if (!(objects.get(0) instanceof PCEPLspObject))
38 // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING)));
40 // final PCEPLspObject lsp = (PCEPLspObject) objects.get(0);
43 // final List<CompositeUpdPathObject> paths = new ArrayList<CompositeUpdPathObject>();
45 // if (!objects.isEmpty()) {
47 // CompositeUpdPathObject path;
48 // path = this.getValidCompositePath(objects);
49 // while (path != null) {
51 // if (objects.isEmpty())
53 // path = this.getValidCompositePath(objects);
55 // } catch (final PCEPDocumentedException e) {
56 // logger.warn("Serializing failed: {}.", e);
57 // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
61 // updateRequests.add(new CompositeUpdateRequestObject(lsp, paths));
64 // if (updateRequests.isEmpty())
65 // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING)));
67 // if (!objects.isEmpty())
68 // throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
70 // return Arrays.asList((Message) new PCEPUpdateRequestMessage(updateRequests));
74 // private CompositeUpdPathObject getValidCompositePath(final List<Object> objects) throws PCEPDocumentedException {
75 // if (!(objects.get(0) instanceof PCEPExplicitRouteObject))
78 // if (objects.get(0) instanceof UnknownObject)
79 // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError());
80 // final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0);
83 // PCEPLspaObject pathLspa = null;
84 // PCEPRequestedPathBandwidthObject pathBandwidth = null;
85 // final List<PCEPMetricObject> pathMetrics = new ArrayList<PCEPMetricObject>();
89 // while (!objects.isEmpty()) {
90 // obj = objects.get(0);
91 // if (obj instanceof UnknownObject) {
92 // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError());
98 // if (obj instanceof PCEPLspaObject) {
99 // pathLspa = (PCEPLspaObject) obj;
104 // if (obj instanceof PCEPRequestedPathBandwidthObject) {
105 // pathBandwidth = (PCEPRequestedPathBandwidthObject) obj;
110 // if (obj instanceof PCEPMetricObject) {
111 // pathMetrics.add((PCEPMetricObject) obj);
120 // objects.remove(0);
123 // return new CompositeUpdPathObject(explicitRoute, pathLspa, pathBandwidth, pathMetrics);