Search in sources :

Example 1 with ExperimenterMessageOfChoice

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice 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();
}
Also used : OFDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) ConvertorMessageFromOFJava(org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava) MultipartReplyExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.multipart.reply.multipart.reply.body.MultipartReplyExperimenterBuilder) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) ExperimenterIdTypeDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)

Example 2 with ExperimenterMessageOfChoice

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice 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());
    }
}
Also used : ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) MessagePath(org.opendaylight.openflowplugin.extension.api.path.MessagePath) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) ExperimenterMessageFromDevBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDevBuilder) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)

Example 3 with ExperimenterMessageOfChoice

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice in project openflowplugin by opendaylight.

the class SalExperimenterMessageServiceImpl method buildRequest.

@Override
protected OfHeader buildRequest(Xid xid, SendExperimenterInput input) throws ServiceException {
    final TypeVersionKey key = new TypeVersionKey(input.getExperimenterMessageOfChoice().getImplementedInterface(), getVersion());
    final ConverterMessageToOFJava<ExperimenterMessageOfChoice, ExperimenterDataOfChoice> messageConverter = extensionConverterProvider.getMessageConverter(key);
    if (messageConverter == null) {
        throw new ServiceException(new ConverterNotFoundException(key.toString()));
    }
    final ExperimenterInputBuilder experimenterInputBld;
    if (messageConverter instanceof BundleMessageDataInjector) {
        ((BundleMessageDataInjector) messageConverter).setNode(input.getNode());
        ((BundleMessageDataInjector) messageConverter).setXid(xid.getValue());
    }
    try {
        experimenterInputBld = new ExperimenterInputBuilder().setExperimenter(messageConverter.getExperimenterId()).setExpType(messageConverter.getType()).setExperimenterDataOfChoice(messageConverter.convert(input.getExperimenterMessageOfChoice())).setVersion(getVersion()).setXid(xid.getValue());
    } catch (ConversionException e) {
        throw new ServiceException(e);
    }
    return experimenterInputBld.build();
}
Also used : TypeVersionKey(org.opendaylight.openflowplugin.extension.api.TypeVersionKey) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) ExperimenterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ConverterNotFoundException(org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException) BundleMessageDataInjector(org.opendaylight.openflowplugin.extension.api.BundleMessageDataInjector) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)

Example 4 with ExperimenterMessageOfChoice

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice in project openflowplugin by opendaylight.

the class MultiLayerExperimenterMultipartService method buildRequest.

@Override
@SuppressWarnings("unchecked")
protected OfHeader buildRequest(Xid xid, SendExperimenterMpRequestInput input) throws ServiceException {
    final TypeVersionKey key = new TypeVersionKey<>(input.getExperimenterMessageOfChoice().getImplementedInterface(), getVersion());
    final ConverterMessageToOFJava<ExperimenterMessageOfChoice, ExperimenterDataOfChoice> messageConverter = getExtensionConverterProvider().getMessageConverter(key);
    if (Objects.isNull(messageConverter)) {
        throw new ServiceException(new ConverterNotFoundException(key.toString()));
    }
    try {
        return RequestInputUtils.createMultipartHeader(MultipartType.OFPMPEXPERIMENTER, xid.getValue(), getVersion()).setMultipartRequestBody(new MultipartRequestExperimenterCaseBuilder().setMultipartRequestExperimenter(new MultipartRequestExperimenterBuilder().setExperimenter(messageConverter.getExperimenterId()).setExpType(messageConverter.getType()).setExperimenterDataOfChoice(messageConverter.convert(input.getExperimenterMessageOfChoice())).build()).build()).build();
    } catch (final ConversionException e) {
        throw new ServiceException(e);
    }
}
Also used : TypeVersionKey(org.opendaylight.openflowplugin.extension.api.TypeVersionKey) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) MultipartRequestExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ConverterNotFoundException(org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException) MultipartRequestExperimenterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCaseBuilder) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)

Example 5 with ExperimenterMessageOfChoice

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice in project openflowplugin by opendaylight.

the class MultiLayerExperimenterMultipartService method handleAndReply.

@Override
@SuppressWarnings("unchecked")
public Future<RpcResult<SendExperimenterMpRequestOutput>> handleAndReply(SendExperimenterMpRequestInput input) {
    final ListenableFuture<RpcResult<List<MultipartReply>>> multipartFuture = handleServiceCall(input);
    final SettableFuture<RpcResult<SendExperimenterMpRequestOutput>> finalFuture = SettableFuture.create();
    class CallBackImpl implements FutureCallback<RpcResult<List<MultipartReply>>> {

        @Override
        public void onSuccess(@Nonnull final RpcResult<List<MultipartReply>> result) {
            if (result.isSuccessful()) {
                final List<MultipartReply> multipartReplies = result.getResult();
                if (multipartReplies.isEmpty()) {
                    LOG.warn("Multipart reply to Experimenter-Mp request shouldn't be empty list.");
                    finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Multipart reply list is empty.").build());
                } else {
                    LOG.debug("OnSuccess, rpc result successful," + " multipart response for rpc sendExperimenterMpRequest with xid {} obtained.", multipartReplies.get(0).getXid());
                    final SendExperimenterMpRequestOutputBuilder sendExpMpReqOutputBuilder = new SendExperimenterMpRequestOutputBuilder();
                    final List<ExperimenterCoreMessageItem> expCoreMessageItem = new ArrayList<>();
                    for (MultipartReply multipartReply : multipartReplies) {
                        final MultipartReplyExperimenterCase caseBody = (MultipartReplyExperimenterCase) multipartReply.getMultipartReplyBody();
                        final MultipartReplyExperimenter replyBody = caseBody.getMultipartReplyExperimenter();
                        final ExperimenterDataOfChoice vendorData = replyBody.getExperimenterDataOfChoice();
                        final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(getVersion(), (Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
                        final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = getExtensionConverterProvider().getMessageConverter(key);
                        if (messageConverter == null) {
                            LOG.warn("Custom converter for {}[OF:{}] not found", vendorData.getImplementedInterface(), getVersion());
                            finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Custom converter not found.").build());
                            return;
                        }
                        try {
                            final ExperimenterMessageOfChoice messageOfChoice = messageConverter.convert(vendorData, MessagePath.MPMESSAGE_RPC_OUTPUT);
                            final ExperimenterCoreMessageItemBuilder expCoreMessageItemBuilder = new ExperimenterCoreMessageItemBuilder();
                            expCoreMessageItemBuilder.setExperimenterMessageOfChoice(messageOfChoice);
                            expCoreMessageItem.add(expCoreMessageItemBuilder.build());
                        } catch (final ConversionException e) {
                            LOG.error("Conversion of experimenter message reply failed. Exception: {}", e);
                            finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Conversion of experimenter rpc output failed.").build());
                            return;
                        }
                    }
                    sendExpMpReqOutputBuilder.setExperimenterCoreMessageItem(expCoreMessageItem);
                    finalFuture.set(RpcResultBuilder.success(sendExpMpReqOutputBuilder.build()).build());
                }
            } else {
                LOG.warn("OnSuccess, rpc result unsuccessful," + " multipart response for rpc sendExperimenterMpRequest was unsuccessful.");
                finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withRpcErrors(result.getErrors()).build());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Failure multipart response for Experimenter-Mp request. Exception: {}", throwable);
            finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Future error", throwable).build());
        }
    }
    Futures.addCallback(multipartFuture, new CallBackImpl(), MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) ArrayList(java.util.ArrayList) MultipartReplyExperimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) ArrayList(java.util.ArrayList) List(java.util.List) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) FutureCallback(com.google.common.util.concurrent.FutureCallback) MultipartReplyExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) ExperimenterCoreMessageItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItemBuilder) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MessagePath(org.opendaylight.openflowplugin.extension.api.path.MessagePath) SendExperimenterMpRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutputBuilder) ExperimenterCoreMessageItem(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItem) SendExperimenterMpRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutput)

Aggregations

ConversionException (org.opendaylight.openflowplugin.extension.api.exception.ConversionException)5 ExperimenterDataOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)5 ExperimenterMessageOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice)5 MessageTypeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)3 TypeVersionKey (org.opendaylight.openflowplugin.extension.api.TypeVersionKey)2 ConverterNotFoundException (org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException)2 MessagePath (org.opendaylight.openflowplugin.extension.api.path.MessagePath)2 ServiceException (org.opendaylight.openflowplugin.impl.services.util.ServiceException)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 OFDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer)1 ExperimenterIdTypeDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey)1 BundleMessageDataInjector (org.opendaylight.openflowplugin.extension.api.BundleMessageDataInjector)1 ConvertorMessageFromOFJava (org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava)1 ExperimenterMessageFromDevBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDevBuilder)1 SendExperimenterMpRequestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutput)1 SendExperimenterMpRequestOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutputBuilder)1 ExperimenterCoreMessageItem (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItem)1