import org.opendaylight.protocol.pcep.PCEPErrorMapping;
import org.opendaylight.protocol.pcep.PCEPErrors;
import org.opendaylight.protocol.pcep.UnknownObject;
-import org.opendaylight.protocol.pcep.impl.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcntfBuilder;
}
@Override
- public Message parseMessage(final byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException {
- if (buffer == null || buffer.length == 0) {
- throw new PCEPDeserializerException("Notification message cannot be empty.");
- }
- final List<Object> objs = parseObjects(buffer);
-
- return validate(objs);
- }
-
- public Message validate(final List<Object> objects) throws PCEPDeserializerException {
+ protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
if (objects == null) {
throw new IllegalArgumentException("Passed list can't be null.");
}
+ if (objects.isEmpty()) {
+ throw new PCEPDeserializerException("Notification message cannot be empty.");
+ }
+
final PCEPErrorMapping maping = PCEPErrorMapping.getInstance();
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications> compositeNotifications = Lists.newArrayList();
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> notifications = Lists.newArrayList();
Object obj;
- int state = 1;
- while (!objects.isEmpty()) {
+ State state = State.Init;
+ while (!objects.isEmpty() && !state.equals(State.End)) {
obj = objects.get(0);
if (obj instanceof UnknownObject) {
}
switch (state) {
- case 1:
- state = 2;
+ case Init:
+ state = State.RpIn;
if (obj instanceof Rp) {
final Rp rp = (Rp) obj;
if (rp.isProcessingRule()) {
throw new PCEPDocumentedException("Invalid setting of P flag.", PCEPErrors.P_FLAG_NOT_SET);
}
requestParameters.add(new RpsBuilder().setRp(rp).build());
- state = 1;
+ state = State.Init;
break;
}
- case 2:
+ case RpIn:
+ state = State.NotificationIn;
if (obj instanceof CNotification) {
final CNotification n = (CNotification) obj;
notifications.add(new NotificationsBuilder().setCNotification(n).build());
- state = 2;
+ state = State.RpIn;
break;
}
- state = 3;
- }
-
- if (state == 3) {
+ case NotificationIn:
+ state = State.End;
+ break;
+ case End:
break;
}
-
- objects.remove(obj);
+ if (!state.equals(State.End)) {
+ objects.remove(0);
+ }
}
if (notifications.isEmpty()) {
notifications).setRps(requestParameters).build();
}
+ private enum State {
+ Init, RpIn, NotificationIn, End
+ }
+
@Override
public int getMessageType() {
return TYPE;