Search in sources :

Example 1 with SessionCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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.rev131005.pcerr.message.PcerrMessage err = ((PcerrMessage) message).getPcerrMessage();
    Preconditions.checkArgument(err.getErrors() != null && !err.getErrors().isEmpty(), "Errors should not be empty.");
    final ByteBuf buffer = Unpooled.buffer();
    serializeCases(err, buffer);
    for (final Errors e : err.getErrors()) {
        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.rev131005.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.rev131005.pcerr.message.pcerr.message.error.type.SessionCase) 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)

Example 2 with SessionCase

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

the class UtilTest method testCreateErrorMessageWithOpen.

@Test
public void testCreateErrorMessageWithOpen() {
    final Message msg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, OPEN);
    Assert.assertTrue(msg instanceof Pcerr);
    final Pcerr errMsg = (Pcerr) msg;
    Assert.assertTrue(errMsg.getPcerrMessage().getErrorType() instanceof SessionCase);
    final SessionCase sessionCase = (SessionCase) errMsg.getPcerrMessage().getErrorType();
    Assert.assertEquals(OPEN, sessionCase.getSession().getOpen());
    final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
    Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType().shortValue());
    Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue().shortValue());
}
Also used : Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) SessionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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.rev131005.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.rev131005.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.rev131007.OpenBuilder) Preconditions(com.google.common.base.Preconditions) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) OpenMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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.rev131007.Pcerr)2 ErrorObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject)2 SessionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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.rev131007.OpenBuilder)1 Message (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message)1 PcerrMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage)1 OpenMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder)1 Errors (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors)1