X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fservices%2FSalMeterServiceImpl.java;h=f7061b9e4e109bea2fc7e2b60e60d667398a1fe8;hb=0def27b981bf0c830c6d4fb618e1a74b729e8255;hp=fd23e573808391bbb4c99a980b65c274e6141401;hpb=eddac25d5068906d838dff433df60190c08984f0;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java index fd23e57380..f7061b9e4e 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java @@ -7,10 +7,17 @@ */ package org.opendaylight.openflowplugin.impl.services; -import com.google.common.util.concurrent.JdkFutureAdapters; +import com.google.common.base.Function; +import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.SettableFuture; +import java.util.concurrent.Future; +import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import com.google.common.base.Function; +import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; @@ -20,53 +27,80 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Sal import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; -import java.util.concurrent.Future; public class SalMeterServiceImpl extends CommonService implements SalMeterService { private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalMeterServiceImpl.class); + public SalMeterServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { + super(requestContextStack, deviceContext); + } + @Override public Future> addMeter(final AddMeterInput input) { - return this.handleServiceCall( PRIMARY_CONNECTION, - new Function,ListenableFuture>>() { - @Override - public ListenableFuture> apply(final DataCrate data) { - return convertAndSend(input, data); - } - }); + getDeviceContext().getDeviceMeterRegistry().store(input.getMeterId()); + return handleServiceCall(new Function, ListenableFuture>>() { + @Override + public ListenableFuture> apply(final RequestContext requestContext) { + return convertAndSend(input, requestContext); + } + }); } @Override public Future> updateMeter(final UpdateMeterInput input) { - return this.handleServiceCall( PRIMARY_CONNECTION, - new Function,ListenableFuture>>() { - @Override - public ListenableFuture> apply(final DataCrate data) { - return convertAndSend(input.getUpdatedMeter(), data); - } - }); + return handleServiceCall(new Function, ListenableFuture>>() { + @Override + public ListenableFuture> apply(final RequestContext requestContext) { + return convertAndSend(input.getUpdatedMeter(), requestContext); + } + }); } @Override public Future> removeMeter(final RemoveMeterInput input) { - return this.handleServiceCall( PRIMARY_CONNECTION, - new Function,ListenableFuture>>() { - @Override - public ListenableFuture> apply(final DataCrate data) { - return convertAndSend(input, data); - } - }); + getDeviceContext().getDeviceMeterRegistry().markToBeremoved(input.getMeterId()); + return handleServiceCall(new Function, ListenableFuture>>() { + @Override + public ListenableFuture> apply(final RequestContext requestContext) { + return convertAndSend(input, requestContext); + } + }); } - ListenableFuture> convertAndSend(final Meter iputMeter, final DataCrate data) { - final MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(iputMeter, version); - Xid xid = deviceContext.getNextXid(); + ListenableFuture> convertAndSend(final Meter iputMeter, final RequestContext requestContext) { + getMessageSpy().spyMessage(iputMeter.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS); + final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider(); + + final MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(iputMeter, getVersion()); + final Xid xid = requestContext.getXid(); ofMeterModInput.setXid(xid.getValue()); - data.getRequestContext().setXid(xid); - return JdkFutureAdapters.listenInPoolThread(provideConnectionAdapter(data.getiDConnection()).meterMod(ofMeterModInput.build())); + final SettableFuture> settableFuture = SettableFuture.create(); + final MeterModInput meterModInput = ofMeterModInput.build(); + outboundQueue.commitEntry(xid.getValue(), meterModInput, new FutureCallback() { + @Override + public void onSuccess(final OfHeader ofHeader) { + RequestContextUtil.closeRequstContext(requestContext); + getMessageSpy().spyMessage(meterModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS); + + settableFuture.set(RpcResultBuilder.success().build()); + } + + @Override + public void onFailure(final Throwable throwable) { + RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable); + RequestContextUtil.closeRequstContext(requestContext); + getMessageSpy().spyMessage(meterModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE); + settableFuture.set(rpcResultBuilder.build()); + } + }); + return settableFuture; } }