use of org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava in project openflowplugin by opendaylight.
the class MultipartReplyExperimenterDeserializer method deserialize.
@Override
@SuppressWarnings("unchecked")
public MultipartReplyBody deserialize(ByteBuf message) {
final MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder();
final long expId = message.readUnsignedInt();
final long expType = message.readUnsignedInt();
try {
final OFDeserializer<ExperimenterMessageOfChoice> deserializer = registry.getDeserializer(new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, expType, ExperimenterMessageOfChoice.class));
builder.setExperimenterMessageOfChoice(deserializer.deserialize(message));
} catch (ClassCastException | IllegalStateException es) {
final OFDeserializer<ExperimenterDataOfChoice> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMultipartReplyMessageDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, expType));
final ExperimenterDataOfChoice data = deserializer.deserialize(message);
final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, (Class<? extends ExperimenterDataOfChoice>) data.getImplementedInterface());
final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> convertor = OFSessionUtil.getExtensionConvertorProvider().getMessageConverter(key);
try {
builder.setExperimenterMessageOfChoice(convertor.convert(data, MessagePath.MPMESSAGE_RPC_OUTPUT));
} catch (ConversionException ce) {
LOG.debug("Failed to deserialize multipart reply experimenter for key: {}", key);
}
}
return builder.build();
}
use of org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava in project openflowplugin by opendaylight.
the class DeviceContextImplTest method testProcessExperimenterMessage.
@Test
public void testProcessExperimenterMessage() {
final ConvertorMessageFromOFJava mockedMessageConverter = mock(ConvertorMessageFromOFJava.class);
final ExtensionConverterProvider mockedExtensionConverterProvider = mock(ExtensionConverterProvider.class);
when(mockedExtensionConverterProvider.getMessageConverter(any(MessageTypeKey.class))).thenReturn(mockedMessageConverter);
final ExperimenterDataOfChoice mockedExperimenterDataOfChoice = mock(ExperimenterDataOfChoice.class);
final ExperimenterMessage experimenterMessage = new ExperimenterMessageBuilder().setExperimenterDataOfChoice(mockedExperimenterDataOfChoice).build();
final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
((DeviceContextImpl) deviceContext).setExtensionConverterProvider(mockedExtensionConverterProvider);
deviceContext.processExperimenterMessage(experimenterMessage);
verify(mockedNotificationPublishService).offerNotification(any(ExperimenterMessageFromDev.class));
}
Aggregations