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=87b5491eec6987d60f7e6d44ecd6f006f261850e;hb=3745263f280dd337f03c8e7b7e60dc5f6e290620;hp=4d17b71c8209b3d40552752e6921cde4fa911aca;hpb=3792907e703200b05f96dd51b31d3e3bf8187021;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 4d17b71c82..87b5491eec 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 @@ -8,10 +8,13 @@ package org.opendaylight.openflowplugin.impl.services; import com.google.common.base.Function; -import com.google.common.util.concurrent.JdkFutureAdapters; +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 org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; @@ -24,8 +27,12 @@ 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; public class SalMeterServiceImpl extends CommonService implements SalMeterService { @@ -38,45 +45,64 @@ public class SalMeterServiceImpl extends CommonService implements SalMeterServic @Override public Future> addMeter(final AddMeterInput input) { - deviceContext.getDeviceMeterRegistry().store(input.getMeterId()); - 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 this.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 this.handleServiceCall(new Function, ListenableFuture>>() { + @Override + public ListenableFuture> apply(final RequestContext requestContext) { + return convertAndSend(input.getUpdatedMeter(), requestContext); + } + }); } @Override public Future> removeMeter(final RemoveMeterInput input) { - deviceContext.getDeviceMeterRegistry().markToBeremoved(input.getMeterId()); - 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 this.handleServiceCall(new Function, ListenableFuture>>() { + @Override + public ListenableFuture> apply(final RequestContext requestContext) { + return convertAndSend(input, requestContext); + } + }); } - ListenableFuture> convertAndSend(final Meter iputMeter, final DataCrate data) { - messageSpy.spyMessage(iputMeter, MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMITTED_SUCCESS); + 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, version); - final Xid xid = data.getRequestContext().getXid(); + final MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(iputMeter, getVersion()); + final Xid xid = requestContext.getXid(); ofMeterModInput.setXid(xid.getValue()); - 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); + getDeviceContext().unhookRequestCtx(requestContext.getXid()); + 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); + getDeviceContext().unhookRequestCtx(requestContext.getXid()); + getMessageSpy().spyMessage(meterModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE); + settableFuture.set(rpcResultBuilder.build()); + } + }); + return settableFuture; } }