Search in sources :

Example 1 with SessionCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase in project bgpcep by opendaylight.

the class PCEPErrorMessageParser method serializeMessage.

@Override
public void serializeMessage(final Message message, final ByteBuf out) {
    Preconditions.checkArgument(message instanceof PcerrMessage, "Wrong instance of Message. Passed instance of %s. Need PcerrMessage.", message.getClass());
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessage err = ((PcerrMessage) message).getPcerrMessage();
    Preconditions.checkArgument(err.getErrors() != null && !err.nonnullErrors().isEmpty(), "Errors should not be empty.");
    final ByteBuf buffer = Unpooled.buffer();
    serializeCases(err, buffer);
    for (final Errors e : err.nonnullErrors()) {
        serializeObject(e.getErrorObject(), buffer);
    }
    if (err.getErrorType() instanceof SessionCase) {
        serializeObject(((SessionCase) err.getErrorType()).getSession().getOpen(), buffer);
    }
    MessageUtil.formatMessage(TYPE, buffer, out);
}
Also used : PcerrMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.PcerrMessage) Preconditions(com.google.common.base.Preconditions) ByteBuf(io.netty.buffer.ByteBuf) SessionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase) Errors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors) PCEPErrors(org.opendaylight.protocol.pcep.spi.PCEPErrors)

Example 2 with SessionCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase in project bgpcep by opendaylight.

the class UtilTest method testCreateErrorMessageWithOpen.

@Test
public void testCreateErrorMessageWithOpen() {
    final Pcerr errMsg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, OPEN);
    assertThat(errMsg.getPcerrMessage().getErrorType(), isA(SessionCase.class));
    final SessionCase sessionCase = (SessionCase) errMsg.getPcerrMessage().getErrorType();
    assertEquals(OPEN, sessionCase.getSession().getOpen());
    final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
    assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType());
    assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue());
}
Also used : Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObject) SessionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase) Test(org.junit.Test)

Example 3 with SessionCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase in project bgpcep by opendaylight.

the class AbstractPCEPSessionNegotiator method handleMessagePcerr.

private boolean handleMessagePcerr(final Message msg) {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessage err = ((Pcerr) msg).getPcerrMessage();
    if (err.getErrorType() == null) {
        final ErrorObject obj = err.getErrors().get(0).getErrorObject();
        LOG.warn("Unexpected error received from PCC: type {} value {}", obj.getType(), obj.getValue());
        negotiationFailed(new IllegalStateException("Unexpected error received from PCC."));
        this.state = State.IDLE;
        return true;
    }
    this.localPrefs = getRevisedProposal(((SessionCase) err.getErrorType()).getSession().getOpen());
    if (this.localPrefs == null) {
        sendErrorMessage(PCEPErrors.PCERR_NON_ACC_SESSION_CHAR);
        negotiationFailed(new IllegalStateException("Peer suggested unacceptable retry proposal"));
        this.state = State.FINISHED;
        return true;
    }
    this.sendMessage(new OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen(this.localPrefs).build()).build());
    if (!this.remoteOK) {
        this.state = State.OPEN_WAIT;
    }
    scheduleFailTimer();
    return true;
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder) Preconditions(com.google.common.base.Preconditions) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObject) OpenMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder)

Aggregations

Preconditions (com.google.common.base.Preconditions)2 Pcerr (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr)2 ErrorObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObject)2 SessionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1 PCEPErrors (org.opendaylight.protocol.pcep.spi.PCEPErrors)1 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder)1 PcerrMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.PcerrMessage)1 OpenMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder)1 Errors (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors)1