use of org.opendaylight.openflowplugin.extension.api.exception.ConversionException 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.exception.ConversionException in project openflowplugin by opendaylight.
the class BundleAddMessageConverter method convert.
@Override
public BundleAddMessageOnf convert(BundleAddMessageSal experimenterMessageCase) throws ConversionException {
final OnfAddMessageGroupingDataBuilder dataBuilder = new OnfAddMessageGroupingDataBuilder();
dataBuilder.setBundleId(experimenterMessageCase.getSalAddMessageData().getBundleId());
dataBuilder.setFlags(experimenterMessageCase.getSalAddMessageData().getFlags());
dataBuilder.setBundleProperty(experimenterMessageCase.getSalAddMessageData().getBundleProperty());
final BundleInnerMessage innerMessage = experimenterMessageCase.getSalAddMessageData().getBundleInnerMessage();
final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
data.setDatapathId(digDatapathId(node));
if (innerMessage.getImplementedInterface().equals(BundleAddFlowCase.class) || innerMessage.getImplementedInterface().equals(BundleUpdateFlowCase.class) || innerMessage.getImplementedInterface().equals(BundleRemoveFlowCase.class)) {
dataBuilder.setBundleInnerMessage(convertBundleFlowCase(innerMessage, data));
} else if (innerMessage.getImplementedInterface().equals(BundleAddGroupCase.class) || innerMessage.getImplementedInterface().equals(BundleUpdateGroupCase.class) || innerMessage.getImplementedInterface().equals(BundleRemoveGroupCase.class)) {
dataBuilder.setBundleInnerMessage(convertBundleGroupCase(innerMessage, data));
} else if (innerMessage.getImplementedInterface().equals(BundleUpdatePortCase.class)) {
dataBuilder.setBundleInnerMessage(convertBundlePortCase(innerMessage, data));
} else {
throw new ConversionException("Unsupported inner message");
}
return new BundleAddMessageOnfBuilder().setOnfAddMessageGroupingData(dataBuilder.build()).build();
}
use of org.opendaylight.openflowplugin.extension.api.exception.ConversionException in project openflowplugin by opendaylight.
the class BundleAddMessageConverter method convertBundleGroupCase.
private BundleGroupModCase convertBundleGroupCase(final BundleInnerMessage messageCase, final VersionDatapathIdConvertorData data) throws ConversionException {
Optional<GroupModInputBuilder> groupModInput = Optional.empty();
final Class clazz = messageCase.getImplementedInterface();
if (clazz.equals(BundleAddGroupCase.class)) {
groupModInput = CONVERTER_EXECUTOR.convert(new AddGroupInputBuilder(((BundleAddGroupCase) messageCase).getAddGroupCaseData()).build(), data);
} else if (clazz.equals(BundleUpdateGroupCase.class)) {
groupModInput = CONVERTER_EXECUTOR.convert(new UpdatedGroupBuilder(((BundleUpdateGroupCase) messageCase).getUpdateGroupCaseData()).build(), data);
} else if (clazz.equals(BundleRemoveGroupCase.class)) {
groupModInput = CONVERTER_EXECUTOR.convert(new RemoveGroupInputBuilder(((BundleRemoveGroupCase) messageCase).getRemoveGroupCaseData()).build(), data);
}
if (groupModInput.isPresent()) {
return new BundleGroupModCaseBuilder().setGroupModCaseData(new GroupModCaseDataBuilder(groupModInput.get().setXid(xid).build()).build()).build();
} else {
throw new ConversionException("BundleGroupCase conversion unsuccessful.");
}
}
use of org.opendaylight.openflowplugin.extension.api.exception.ConversionException in project openflowplugin by opendaylight.
the class BundleAddMessageConverter method convertBundleFlowCase.
private BundleFlowModCase convertBundleFlowCase(final BundleInnerMessage messageCase, final VersionDatapathIdConvertorData data) throws ConversionException {
Optional<List<FlowModInputBuilder>> flowModInputs = Optional.empty();
final Class clazz = messageCase.getImplementedInterface();
if (clazz.equals(BundleAddFlowCase.class)) {
flowModInputs = CONVERTER_EXECUTOR.convert(new AddFlowInputBuilder(((BundleAddFlowCase) messageCase).getAddFlowCaseData()).build(), data);
} else if (clazz.equals(BundleUpdateFlowCase.class)) {
flowModInputs = CONVERTER_EXECUTOR.convert(new UpdatedFlowBuilder(((BundleUpdateFlowCase) messageCase).getUpdateFlowCaseData()).build(), data);
} else if (clazz.equals(BundleRemoveFlowCase.class)) {
flowModInputs = CONVERTER_EXECUTOR.convert(new RemoveFlowInputBuilder(((BundleRemoveFlowCase) messageCase).getRemoveFlowCaseData()).build(), data);
}
if (flowModInputs.isPresent()) {
if (flowModInputs.get().size() == 1) {
return new BundleFlowModCaseBuilder().setFlowModCaseData(new FlowModCaseDataBuilder(flowModInputs.get().get(0).setXid(xid).build()).build()).build();
} else {
throw new ConversionException("BundleFlowCase conversion unsuccessful - not able to convert to multiple flows.");
}
} else {
throw new ConversionException("BundleFlowCase conversion unsuccessful.");
}
}
use of org.opendaylight.openflowplugin.extension.api.exception.ConversionException in project openflowplugin by opendaylight.
the class DeviceContextImpl method processExperimenterMessage.
@Override
public void processExperimenterMessage(final ExperimenterMessage notification) {
if (isMasterOfDevice()) {
// lookup converter
final ExperimenterDataOfChoice vendorData = notification.getExperimenterDataOfChoice();
final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(getDeviceInfo().getVersion(), (Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = extensionConverterProvider.getMessageConverter(key);
if (messageConverter == null) {
LOG.warn("custom converter for {}[OF:{}] not found", notification.getExperimenterDataOfChoice().getImplementedInterface(), getDeviceInfo().getVersion());
return;
}
// build notification
final ExperimenterMessageOfChoice messageOfChoice;
try {
messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new ExperimenterMessageFromDevBuilder().setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier())).setExperimenterMessageOfChoice(messageOfChoice);
// publish
notificationPublishService.offerNotification(experimenterMessageFromDevBld.build());
} catch (final ConversionException e) {
LOG.error("Conversion of experimenter notification failed", e);
}
} else {
LOG.debug("Controller is not owner of the device {}, skipping experimenter message", deviceInfo.getLOGValue());
}
}
Aggregations