Search in sources :

Example 1 with ErrorMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder in project openflowplugin by opendaylight.

the class AbstractRequestCallbackTest method testOnFailureWithDeviceRequestFailedException.

@Test
public void testOnFailureWithDeviceRequestFailedException() throws Exception {
    ErrorMessage dummyErrorMessage = new ErrorMessageBuilder().build();
    abstractRequestCallback.onFailure(new DeviceRequestFailedException(DUMMY_EXCEPTION_DESCRIPTION, dummyErrorMessage));
    final ListenableFuture futureResult = dummyRequestContext.getFuture();
    RpcError rpcError = provideRpcError(futureResult);
    assertEquals("Device reported error type null code null", rpcError.getMessage());
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) RpcError(org.opendaylight.yangtools.yang.common.RpcError) DeviceRequestFailedException(org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) Test(org.junit.Test)

Example 2 with ErrorMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder in project openflowplugin by opendaylight.

the class ConnectionAdapterImplTest method testConsume.

/**
 * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with notifications.
 */
@Test
public void testConsume() {
    DataObject message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
    message = new ErrorMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onErrorMessage((ErrorMessage) message);
    message = new ExperimenterMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onExperimenterMessage((ExperimenterMessage) message);
    message = new FlowRemovedMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onFlowRemovedMessage((FlowRemovedMessage) message);
    message = new HelloMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onHelloMessage((HelloMessage) message);
    message = new MultipartReplyMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onMultipartReplyMessage((MultipartReplyMessage) message);
    message = new PacketInMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onPacketInMessage((PacketInMessage) message);
    message = new PortStatusMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onPortStatusMessage((PortStatusMessage) message);
    message = new SwitchIdleEventBuilder().build();
    adapter.consume(message);
    verify(systemListener, times(1)).onSwitchIdleEvent((SwitchIdleEvent) message);
    message = new DisconnectEventBuilder().build();
    adapter.consume(message);
    verify(systemListener, times(1)).onDisconnectEvent((DisconnectEvent) message);
    message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) DisconnectEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder) ExperimenterMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SwitchIdleEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder) PortStatusMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder) HelloMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) FlowRemovedMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder) EchoRequestMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder) Test(org.junit.Test)

Example 3 with ErrorMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder in project openflowplugin by opendaylight.

the class OF10ErrorMessageFactory method deserialize.

@Override
public ErrorMessage deserialize(ByteBuf rawMessage) {
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    int type = rawMessage.readUnsignedShort();
    ErrorTypeV10 errorType = ErrorTypeV10.forValue(type);
    decodeType(builder, errorType, type);
    decodeCode(rawMessage, builder, errorType);
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        byte[] data = new byte[remainingBytes];
        rawMessage.readBytes(data);
        builder.setData(data);
    }
    return builder.build();
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) ErrorTypeV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorTypeV10)

Example 4 with ErrorMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder in project openflowplugin by opendaylight.

the class OnfExperimenterErrorFactory method deserialize.

@Override
public ErrorMessage deserialize(ByteBuf message) {
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(message.readUnsignedInt());
    int type = message.readUnsignedShort();
    ErrorType errorType = ErrorType.forValue(type);
    if (errorType != null && errorType.equals(ErrorType.EXPERIMENTER)) {
        builder.setType(errorType.getIntValue());
        builder.setTypeString(errorType.getName());
    } else {
        LOG.warn("Deserializing other than {} error message with {}", ErrorType.EXPERIMENTER.getName(), this.getClass().getCanonicalName());
        builder.setType(type);
        builder.setTypeString(UNKNOWN_TYPE);
    }
    int code = message.readUnsignedShort();
    OnfExperimenterErrorCode errorCode = OnfExperimenterErrorCode.forValue(code);
    if (errorCode != null) {
        builder.setCode(errorCode.getIntValue());
        builder.setCodeString(errorCode.getName());
    } else {
        builder.setCode(code);
        builder.setCodeString(UNKNOWN_CODE);
    }
    builder.addAugmentation(ExperimenterIdError.class, new ExperimenterIdErrorBuilder().setExperimenter(new ExperimenterId(message.readUnsignedInt())).build());
    if (message.readableBytes() > 0) {
        byte[] data = new byte[message.readableBytes()];
        message.readBytes(data);
        builder.setData(data);
    }
    return builder.build();
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) ErrorType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType) OnfExperimenterErrorCode(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.OnfExperimenterErrorCode) ExperimenterIdErrorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdErrorBuilder) ExperimenterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId)

Example 5 with ErrorMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder in project openflowplugin by opendaylight.

the class ErrorMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public ErrorMessage deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    int startIndex = rawMessage.readerIndex();
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    int type = rawMessage.readUnsignedShort();
    ErrorType errorType = ErrorType.forValue(type);
    if (ErrorType.EXPERIMENTER.equals(errorType)) {
        OFDeserializer<ErrorMessage> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createExperimenterErrorDeserializerKey(EncodeConstants.OF13_VERSION_ID, rawMessage.getUnsignedInt(rawMessage.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES)));
        rawMessage.readerIndex(startIndex);
        return deserializer.deserialize(rawMessage);
    }
    decodeType(builder, errorType, type);
    decodeCode(rawMessage, builder, errorType);
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        byte[] data = new byte[remainingBytes];
        rawMessage.readBytes(data);
        builder.setData(data);
    }
    return builder.build();
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) ErrorType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ErrorMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder)8 Test (org.junit.Test)5 ErrorMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage)4 ErrorType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType)2 EchoRequestMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder)2 ExperimenterMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder)2 FlowRemovedMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder)2 HelloMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder)2 MultipartReplyMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder)2 PacketInMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder)2 PortStatusMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ByteBuf (io.netty.buffer.ByteBuf)1 DeviceRequestFailedException (org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException)1 ExperimenterIdErrorBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdErrorBuilder)1 ErrorTypeV10 (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorTypeV10)1 ExperimenterId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId)1 DisconnectEventBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder)1