Search in sources :

Example 6 with PcerrBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder in project bgpcep by opendaylight.

the class Stateful07ErrorMessageParser method validate.

@Override
protected PcerrMessage validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
    Preconditions.checkArgument(objects != null, "Passed list can't be null.");
    if (objects.isEmpty()) {
        throw new PCEPDeserializerException("Error message is empty.");
    }
    final List<Rps> requestParameters = new ArrayList<>();
    final List<Srps> srps = new ArrayList<>();
    final List<Errors> errorObjects = new ArrayList<>();
    final PcerrMessageBuilder b = new PcerrMessageBuilder();
    Object obj = objects.get(0);
    State state = State.INIT;
    if (obj instanceof ErrorObject) {
        final ErrorObject o = (ErrorObject) obj;
        errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
        state = State.ERROR_IN;
    } else if (obj instanceof Rp) {
        final Rp o = (Rp) obj;
        if (o.isProcessingRule()) {
            errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.absent()));
            return null;
        }
        requestParameters.add(new RpsBuilder().setRp(o).build());
        state = State.RP_IN;
    } else if (obj instanceof Srp) {
        final Srp s = (Srp) obj;
        srps.add(new SrpsBuilder().setSrp(s).build());
        state = State.SRP_IN;
    }
    if (!state.equals(State.INIT)) {
        objects.remove(0);
    }
    while (!objects.isEmpty() && !state.equals(State.END)) {
        obj = objects.get(0);
        if (obj instanceof UnknownObject) {
            return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
        }
        state = insertObject(state, obj, errorObjects, requestParameters, srps, b);
        if (!state.equals(State.END)) {
            objects.remove(0);
        }
    }
    if (errorObjects.isEmpty()) {
        throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
    }
    if (!objects.isEmpty()) {
        throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
    }
    if (!requestParameters.isEmpty()) {
        b.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(requestParameters).build()).build());
    }
    if (!srps.isEmpty()) {
        b.setErrorType(new StatefulCaseBuilder().setStateful(new StatefulBuilder().setSrps(srps).build()).build());
    }
    return new PcerrBuilder().setPcerrMessage(b.setErrors(errorObjects).build()).build();
}
Also used : PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder) RequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.RequestBuilder) Srps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcerr.pcerr.message.error.type.stateful._case.stateful.Srps) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) ArrayList(java.util.ArrayList) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder) StatefulBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcerr.pcerr.message.error.type.stateful._case.StatefulBuilder) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) StatefulCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcerr.pcerr.message.error.type.StatefulCaseBuilder) Srp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.srp.object.Srp) PCEPErrors(org.opendaylight.protocol.pcep.spi.PCEPErrors) Errors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors) Rps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.Rps) SrpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcerr.pcerr.message.error.type.stateful._case.stateful.SrpsBuilder) RequestCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.RequestCaseBuilder) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) RpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp)

Example 7 with PcerrBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder in project bgpcep by opendaylight.

the class PCEPErrorMessageParser method validate.

@Override
protected PcerrMessage validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
    Preconditions.checkArgument(objects != null, "Passed list can't be null.");
    if (objects.isEmpty()) {
        throw new PCEPDeserializerException("Error message is empty.");
    }
    final List<Rps> requestParameters = new ArrayList<>();
    final List<Errors> errorObjects = new ArrayList<>();
    final PcerrMessageBuilder b = new PcerrMessageBuilder();
    Object obj = objects.get(0);
    State state = State.INIT;
    if (obj instanceof ErrorObject) {
        final ErrorObject o = (ErrorObject) obj;
        errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
        state = State.ERROR_IN;
    } else if (obj instanceof Rp) {
        final Rp o = (Rp) obj;
        if (o.isProcessingRule()) {
            errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.absent()));
            return null;
        }
        requestParameters.add(new RpsBuilder().setRp(o).build());
        state = State.RP_IN;
    }
    if (state.equals(State.INIT)) {
        throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
    }
    objects.remove(0);
    while (!objects.isEmpty() && !state.equals(State.END)) {
        obj = objects.get(0);
        if (obj instanceof UnknownObject) {
            return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
        }
        state = insertObject(state, errorObjects, obj, requestParameters, b);
        if (!state.equals(State.END)) {
            objects.remove(0);
        }
    }
    if (errorObjects.isEmpty()) {
        throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
    }
    if (!objects.isEmpty()) {
        throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
    }
    if (!requestParameters.isEmpty()) {
        b.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(requestParameters).build()).build());
    }
    return new PcerrBuilder().setPcerrMessage(b.setErrors(errorObjects).build()).build();
}
Also used : PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder) RequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.RequestBuilder) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) ArrayList(java.util.ArrayList) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) PCEPErrors(org.opendaylight.protocol.pcep.spi.PCEPErrors) Errors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors) Rps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.Rps) RequestCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.RequestCaseBuilder) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) RpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp)

Aggregations

PcerrBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder)7 PcerrMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder)7 ErrorsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder)7 ErrorObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject)5 ErrorObjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder)5 ByteBuf (io.netty.buffer.ByteBuf)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Errors (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors)4 RequestCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.RequestCaseBuilder)4 RequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.RequestBuilder)4 SessionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionCaseBuilder)3 SessionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.session._case.SessionBuilder)3 Collections (java.util.Collections)2 CrabbeInitiatedActivator (org.opendaylight.protocol.pcep.ietf.initiated00.CrabbeInitiatedActivator)2 StatefulActivator (org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 PCEPErrors (org.opendaylight.protocol.pcep.spi.PCEPErrors)2 UnknownObject (org.opendaylight.protocol.pcep.spi.UnknownObject)2 StatefulCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcerr.pcerr.message.error.type.StatefulCaseBuilder)2