Search in sources :

Example 21 with OfHeader

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

the class SingleLayerFlowService method buildRequest.

@Override
protected OfHeader buildRequest(final Xid xid, final Flow input) throws ServiceException {
    final FlowMessageBuilder flowMessageBuilder = new FlowMessageBuilder(input);
    final Class<? extends DataContainer> clazz = input.getImplementedInterface();
    if (clazz.equals(AddFlowInput.class) || clazz.equals(UpdatedFlow.class)) {
        flowMessageBuilder.setCommand(FlowModCommand.OFPFCADD);
    } else if (clazz.equals(RemoveFlowInput.class) || clazz.equals(OriginalFlow.class)) {
        flowMessageBuilder.setCommand(Boolean.TRUE.equals(input.isStrict()) ? FlowModCommand.OFPFCDELETESTRICT : FlowModCommand.OFPFCDELETE);
    }
    return flowMessageBuilder.setVersion(getVersion()).setXid(xid.getValue()).build();
}
Also used : UpdatedFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) FlowMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder)

Example 22 with OfHeader

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

the class AbstractService method handleServiceCall.

public ListenableFuture<RpcResult<O>> handleServiceCall(@Nonnull final I input, @Nullable final Function<OfHeader, Boolean> isComplete) {
    Preconditions.checkNotNull(input);
    final Class<?> requestType = input instanceof DataContainer ? DataContainer.class.cast(input).getImplementedInterface() : input.getClass();
    getMessageSpy().spyMessage(requestType, MessageSpy.StatisticsGroup.TO_SWITCH_ENTERED);
    LOG.trace("Handling general service call");
    final RequestContext<O> requestContext = requestContextStack.createRequestContext();
    if (Objects.isNull(requestContext)) {
        LOG.trace("Request context refused.");
        getMessageSpy().spyMessage(AbstractService.class, MessageSpy.StatisticsGroup.TO_SWITCH_DISREGARDED);
        return Futures.immediateFuture(RpcResultBuilder.<O>failed().withError(RpcError.ErrorType.APPLICATION, "", "Request quota exceeded").build());
    }
    if (Objects.isNull(requestContext.getXid())) {
        getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_RESERVATION_REJECTED);
        return RequestContextUtil.closeRequestContextWithRpcError(requestContext, "Outbound queue wasn't able to reserve XID.");
    }
    getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_READY_FOR_SUBMIT);
    final Xid xid = requestContext.getXid();
    OfHeader request = null;
    try {
        request = buildRequest(xid, input);
        Verify.verify(xid.getValue().equals(request.getXid()), "Expected XID %s got %s", xid.getValue(), request.getXid());
    } catch (ServiceException ex) {
        LOG.error("Failed to build request for {}, forfeiting request {}", input, xid.getValue(), ex);
        RequestContextUtil.closeRequestContextWithRpcError(requestContext, "failed to build request input: " + ex.getMessage());
    } finally {
        final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
        if (Objects.nonNull(isComplete)) {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType), isComplete);
        } else {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType));
        }
    }
    return requestContext.getFuture();
}
Also used : OutboundQueue(org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)

Example 23 with OfHeader

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

the class FlowsInTableService method buildRequest.

@Override
protected OfHeader buildRequest(final Xid xid, final GetFlowStatisticsFromFlowTableInput input) throws ServiceException {
    final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
    final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
    if (input.getTableId() != null) {
        mprFlowRequestBuilder.setTableId(input.getTableId());
    } else {
        mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
    }
    if (input.getOutPort() != null) {
        mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
    } else {
        mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
    }
    if (input.getOutGroup() != null) {
        mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
    } else {
        mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
    }
    if (input.getCookie() != null) {
        mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
    } else {
        mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
    }
    if (input.getCookieMask() != null) {
        mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
    } else {
        mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
    }
    // convert and inject match
    final Optional<Object> conversionMatch = convertorExecutor.convert(input.getMatch(), data);
    MatchInjector.inject(conversionMatch, mprFlowRequestBuilder, data.getVersion());
    // Set request body to main multipart request
    multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
    final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
    mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
    return mprInput.build();
}
Also used : MultipartRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder) MultipartRequestFlowCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder) MultipartRequestFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder)

Example 24 with OfHeader

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

the class MeterFeaturesService method buildRequest.

@Override
protected OfHeader buildRequest(final Xid xid, final GetMeterFeaturesInput input) throws ServiceException {
    MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(MultipartType.OFPMPMETERFEATURES, xid.getValue(), getVersion());
    mprInput.setMultipartRequestBody(METER_FEATURES_CASE);
    return mprInput.build();
}
Also used : MultipartRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder)

Example 25 with OfHeader

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

the class OneQueueOnePortService method buildRequest.

@Override
protected OfHeader buildRequest(final Xid xid, final GetQueueStatisticsFromGivenPortInput input) throws ServiceException {
    MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
    MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
    // Select specific queue
    mprQueueBuilder.setQueueId(input.getQueueId().getValue());
    // Select specific port
    final short version = getVersion();
    mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.get(version), input.getNodeConnectorId()));
    caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
    // Set request body to main multipart request
    MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(MultipartType.OFPMPQUEUE, xid.getValue(), version);
    mprInput.setMultipartRequestBody(caseBuilder.build());
    return mprInput.build();
}
Also used : MultipartRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder) MultipartRequestQueueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder) MultipartRequestQueueCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder)

Aggregations

OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)30 Test (org.junit.Test)23 MultipartRequestInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder)17 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)5 ExecutionException (java.util.concurrent.ExecutionException)3 ServiceException (org.opendaylight.openflowplugin.impl.services.util.ServiceException)3 GroupMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage)3 MultipartType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 List (java.util.List)2 Future (java.util.concurrent.Future)2 Function (java.util.function.Function)2 OFDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer)2 TypeVersionKey (org.opendaylight.openflowplugin.extension.api.TypeVersionKey)2 ConversionException (org.opendaylight.openflowplugin.extension.api.exception.ConversionException)2 ConverterNotFoundException (org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException)2 ConvertorExecutor (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor)2 PortMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessage)2 FlowMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage)2