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.ArrayList;
11 import java.util.Arrays;
12 import java.util.List;
14 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
15 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
16 import org.opendaylight.protocol.pcep.PCEPErrors;
17 import org.opendaylight.protocol.pcep.PCEPObject;
18 import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator;
19 import org.opendaylight.protocol.pcep.impl.object.UnknownObject;
20 import org.opendaylight.protocol.pcep.message.PCEPErrorMessage;
21 import org.opendaylight.protocol.pcep.message.PCEPNotificationMessage;
22 import org.opendaylight.protocol.pcep.object.CompositeNotifyObject;
23 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
24 import org.opendaylight.protocol.pcep.object.PCEPNotificationObject;
25 import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
29 * PCEPNotificationMessage validator. Validates message integrity.
31 public class PCEPNotificationMessageValidator extends PCEPMessageValidator {
34 public List<Message> validate(final List<PCEPObject> objects) throws PCEPDeserializerException {
36 throw new IllegalArgumentException("Passed list can't be null.");
38 final List<CompositeNotifyObject> compositeNotifications = new ArrayList<CompositeNotifyObject>();
40 while (!objects.isEmpty()) {
41 CompositeNotifyObject comObj;
43 comObj = getValidNotificationComposite(objects);
44 } catch (final PCEPDocumentedException e) {
45 return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError())));
51 compositeNotifications.add(comObj);
54 if (compositeNotifications.isEmpty())
55 throw new PCEPDeserializerException("Atleast one CompositeNotifiObject is mandatory.");
57 if (!objects.isEmpty())
58 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
60 return Arrays.asList((Message) new PCEPNotificationMessage(compositeNotifications));
63 private static CompositeNotifyObject getValidNotificationComposite(final List<PCEPObject> objects) throws PCEPDocumentedException {
64 final List<PCEPRequestParameterObject> requestParameters = new ArrayList<PCEPRequestParameterObject>();
65 final List<PCEPNotificationObject> notifications = new ArrayList<PCEPNotificationObject>();
69 while (!objects.isEmpty()) {
72 if (obj instanceof UnknownObject)
73 throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError());
78 if (obj instanceof PCEPRequestParameterObject) {
79 if (((PCEPRequestParameterObject) obj).isProcessed())
80 throw new PCEPDocumentedException("Invalid setting of P flag.", PCEPErrors.P_FLAG_NOT_SET);
81 requestParameters.add((PCEPRequestParameterObject) obj);
86 if (obj instanceof PCEPNotificationObject) {
87 notifications.add((PCEPNotificationObject) obj);
100 if (notifications.isEmpty())
103 return new CompositeNotifyObject(requestParameters, notifications);