*/
package org.opendaylight.openflowplugin.impl.rpc;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-
import com.google.common.util.concurrent.SettableFuture;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.RpcResult;
*/
public class RequestContextImpl<T extends DataObject> implements RequestContext<T> {
- private final RpcContext rpcContext;
+ private final RequestContextStack requestContextStack;
private SettableFuture<RpcResult<T>> rpcResultFuture;
private long waitTimeout;
private Xid xid;
- public RequestContextImpl(RpcContext rpcContext) {
- this.rpcContext = rpcContext;
+ public RequestContextImpl(RequestContextStack requestContextStack) {
+ this.requestContextStack = requestContextStack;
}
@Override
public void close() {
- rpcContext.forgetRequestContext(this);
+ requestContextStack.forgetRequestContext(this);
}
@Override
@Override
public void deviceConnected(final DeviceContext deviceContext) {
final RpcContext rpcContext = new RpcContextImpl(providerContext, deviceContext);
- MdSalRegistratorUtils.registerServices(rpcContext);
+ MdSalRegistratorUtils.registerServices(rpcContext, deviceContext);
}
}
package org.opendaylight.openflowplugin.impl.services;
import com.google.common.base.Function;
-import com.google.common.util.concurrent.SettableFuture;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import com.google.common.util.concurrent.Futures;
-import java.math.BigInteger;
-import java.util.concurrent.Future;
+import com.google.common.util.concurrent.SettableFuture;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
+import java.math.BigInteger;
+import java.util.concurrent.Future;
public abstract class CommonService {
private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(CommonService.class);
private static final long WAIT_TIME = 2000;
protected final static Future<RpcResult<Void>> ERROR_RPC_RESULT = Futures.immediateFuture(RpcResultBuilder
- .<Void> failed().withError(ErrorType.APPLICATION, "", "Request quota exceeded.").build());
+ .<Void>failed().withError(ErrorType.APPLICATION, "", "Request quota exceeded.").build());
protected static final BigInteger PRIMARY_CONNECTION = new BigInteger("0");
// protected OFRpcTaskContext rpcTaskContext;
protected short version;
protected BigInteger datapathId;
- protected RpcContext rpcContext;
+ protected RequestContextStack requestContextStack;
protected DeviceContext deviceContext;
private ConnectionAdapter primaryConnectionAdapter;
public CommonService() {
}
- public CommonService(final RpcContext rpcContext) {
- this.rpcContext = rpcContext;
+ public CommonService(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
+ this.requestContextStack = requestContextStack;
- this.deviceContext = rpcContext.getDeviceContext();
+ this.deviceContext = deviceContext;
final FeaturesReply features = this.deviceContext.getPrimaryConnectionContext().getFeatures();
this.datapathId = features.getDatapathId();
this.version = features.getVersion();
}
<T extends DataObject, F> Future<RpcResult<T>> handleServiceCall(final BigInteger connectionID,
- final Function<DataCrate<T>, Future<RpcResult<F>>> function) {
+ final Function<DataCrate<T>, Future<RpcResult<F>>> function) {
LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
- final RequestContext<T> requestContext = rpcContext.createRequestContext();
- final SettableFuture<RpcResult<T>> result = rpcContext.storeOrFail(requestContext);
- final DataCrate<T> dataCrate = DataCrateBuilder.<T> builder().setiDConnection(connectionID)
+ final RequestContext<T> requestContext = requestContextStack.createRequestContext();
+ final SettableFuture<RpcResult<T>> result = requestContextStack.storeOrFail(requestContext);
+ final DataCrate<T> dataCrate = DataCrateBuilder.<T>builder().setiDConnection(connectionID)
.setRequestContext(requestContext).build();
if (!result.isDone()) {
final Future<RpcResult<F>> resultFromOFLib = function.apply(dataCrate);
@Override
public Future<RpcResult<SetConfigOutput>> setConfig(final SetConfigInput input) {
- final RequestContext requestContext = rpcContext.createRequestContext();
- final SettableFuture<RpcResult<SetConfigOutput>> result = rpcContext.storeOrFail(requestContext);
+ final RequestContext requestContext = requestContextStack.createRequestContext();
+ final SettableFuture<RpcResult<SetConfigOutput>> result = requestContextStack.storeOrFail(requestContext);
if (!result.isDone()) {
SetConfigInputBuilder builder = new SetConfigInputBuilder();
SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
@Override
public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(final GetAllMeterStatisticsInput input) {
- final RequestContext<GetAllMeterStatisticsOutput> requestContext = rpcContext.createRequestContext();
- final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = rpcContext.storeOrFail(requestContext);
+ final RequestContext<GetAllMeterStatisticsOutput> requestContext = requestContextStack.createRequestContext();
+ final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = requestContextStack.storeOrFail(requestContext);
if (!result.isDone()) {
@Override
public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(final GetMeterFeaturesInput input) {
- final RequestContext requestContext = rpcContext.createRequestContext();
- final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = rpcContext.storeOrFail(requestContext);
+ final RequestContext requestContext = requestContextStack.createRequestContext();
+ final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = requestContextStack.storeOrFail(requestContext);
if (!result.isDone()) {
@Override
public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(final GetMeterStatisticsInput input) {
- final RequestContext requestContext = rpcContext.createRequestContext();
- final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = rpcContext.storeOrFail(requestContext);
+ final RequestContext requestContext = requestContextStack.createRequestContext();
+ final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = requestContextStack.storeOrFail(requestContext);
if (!result.isDone()) {
*/
package org.opendaylight.openflowplugin.impl.services;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalFlowServiceImpl.class);
- public SalFlowServiceImpl(final RpcContext rpcContext) {
- super(rpcContext);
+
+ public SalFlowServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext);
}
<T extends DataObject, F> ListenableFuture<RpcResult<T>> handleServiceCall(final BigInteger connectionID,
final FlowModInputBuilder flowModInputBuilder, final Function<DataCrate<T>, Future<RpcResult<F>>> function) {
LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
- final RequestContext<T> requestContext = rpcContext.createRequestContext();
- final SettableFuture<RpcResult<T>> result = rpcContext.storeOrFail(requestContext);
+ final RequestContext<T> requestContext = requestContextStack.createRequestContext();
+ final SettableFuture<RpcResult<T>> result = requestContextStack.storeOrFail(requestContext);
final DataCrate<T> dataCrate = DataCrateBuilder.<T> builder().setiDConnection(connectionID)
.setRequestContext(requestContext).setFlowModInputBuilder(flowModInputBuilder).build();
*/
package org.opendaylight.openflowplugin.impl.util;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.openflowplugin.impl.services.NodeConfigServiceImpl;
import org.opendaylight.openflowplugin.impl.services.OpendaylightFlowStatisticsServiceImpl;
throw new IllegalStateException();
}
- public static void registerServices(final RpcContext rpcContext) {
- rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext));
+ public static void registerServices(final RpcContext rpcContext, final DeviceContext deviceContext) {
+ rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext, deviceContext));
rpcContext.registerRpcServiceImplementation(SalMeterService.class, new SalMeterServiceImpl());
rpcContext.registerRpcServiceImplementation(SalGroupService.class, new SalGroupServiceImpl());
rpcContext.registerRpcServiceImplementation(SalTableService.class, new SalTableServiceImpl());
/**
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.math.BigInteger;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.math.BigInteger;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
public class RpcManagerImplTest {
ExecutionException {
// TODO: how to invoke service remotely?
final RpcContextImpl rpcContext = new RpcContextImpl(mockedProviderContext, mockedDeviceContext);
- when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(new SalFlowServiceImpl(rpcContext));
+ when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(new SalFlowServiceImpl(rpcContext, mockedDeviceContext));
rpcContext.setRequestContextQuota(capacity);
final SalFlowService salFlowService = mockedProviderContext.getRpcService(SalFlowService.class);