import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import org.opendaylight.controller.sal.common.util.RpcErrors;
-import org.opendaylight.controller.sal.common.util.Rpcs;
+
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowplugin.ConnectionException;
-import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.openflow.md.util.RpcResultUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder;
-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 org.slf4j.LoggerFactory;
import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
import java.util.concurrent.Future;
/**
public class MessageDispatchServiceImpl implements IMessageDispatchService {
private static final Logger LOG = LoggerFactory.getLogger(MessageDispatchServiceImpl.class);
- private static final String CONNECTION_ERROR_MESSAGE = "Session for the cookie is invalid. Reason: "
- + "the switch has been recently disconnected OR inventory provides outdated information.";
-
private SessionContext session;
/**
private ConnectionAdapter getConnectionAdapter(SwitchConnectionDistinguisher cookie) throws ConnectionException {
if (!session.isValid()) {
- LOG.warn("Session for the cookie {} is invalid.", cookie);
+ LOG.warn("No valid connection found for the node [datapath-id : {}]", session.getSessionKey().getId());
throw new ConnectionException(CONNECTION_ERROR_MESSAGE);
}
LOG.debug("finding connecton for cookie value {}. ", cookie);
try {
return getConnectionAdapter(cookie).barrier(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
- private <T> SettableFuture<RpcResult<T>> getRpcErrorFuture(ConnectionException e) {
- List<RpcError> rpcErrorList = getConnectionErrorAsRpcErrors(e);
- SettableFuture<RpcResult<T>> futureWithError = SettableFuture.create();
- futureWithError.set(Rpcs.<T>getRpcResult(false, rpcErrorList));
- return futureWithError;
- }
-
- private List<RpcError> getConnectionErrorAsRpcErrors(ConnectionException e) {
- List<RpcError> rpcErrorList = new ArrayList<>();
- rpcErrorList.add(RpcErrors.getRpcError(OFConstants.APPLICATION_TAG,
- OFConstants.ERROR_TAG_TIMEOUT,
- CONNECTION_ERROR_MESSAGE,
- RpcError.ErrorSeverity.WARNING,
- e.getMessage(),
- RpcError.ErrorType.TRANSPORT,
- e.getCause()));
- return rpcErrorList;
- }
-
@Override
public Future<RpcResult<Void>> experimenter(ExperimenterInput input, SwitchConnectionDistinguisher cookie) {
try {
return getConnectionAdapter(cookie).experimenter(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
response = getConnectionAdapter(cookie).flowMod(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
// appending xid
flowModOutput.setTransactionId(new TransactionId(bigIntXid));
UpdateFlowOutput result = flowModOutput.build();
- RpcResult<UpdateFlowOutput> rpcResult = Rpcs.getRpcResult(
- inputArg.isSuccessful(), result, inputArg.getErrors());
+ RpcResult<UpdateFlowOutput> rpcResult = RpcResultBuilder
+ .<UpdateFlowOutput>status(inputArg.isSuccessful())
+ .withResult(result).withRpcErrors(inputArg.getErrors())
+ .build();
return rpcResult;
}
});
try {
return getConnectionAdapter(cookie).getAsync(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
return getConnectionAdapter(cookie).getConfig(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
return getConnectionAdapter(cookie).getFeatures(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
return getConnectionAdapter(cookie).getQueueConfig(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
response = getConnectionAdapter(cookie).groupMod(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
// appending xid
groupModOutput.setTransactionId(new TransactionId(bigIntXid));
UpdateGroupOutput result = groupModOutput.build();
- RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(
- inputArg.isSuccessful(), result, inputArg.getErrors());
+ RpcResult<UpdateGroupOutput> rpcResult = RpcResultBuilder
+ .<UpdateGroupOutput>status(inputArg.isSuccessful()).withResult(result)
+ .withRpcErrors(inputArg.getErrors()).build();
return rpcResult;
}
});
try {
response = getConnectionAdapter(cookie).meterMod(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
// appending xid
meterModOutput.setTransactionId(new TransactionId(bigIntXid));
UpdateMeterOutput result = meterModOutput.build();
- RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(
- inputArg.isSuccessful(), result, inputArg.getErrors());
+ RpcResult<UpdateMeterOutput> rpcResult = RpcResultBuilder
+ .<UpdateMeterOutput>status(inputArg.isSuccessful()).withResult(result)
+ .withRpcErrors(inputArg.getErrors()).build();
return rpcResult;
}
});
try {
return getConnectionAdapter(cookie).multipartRequest(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
return getConnectionAdapter(cookie).packetOut(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
response = getConnectionAdapter(cookie).portMod(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
// appending xid
portModOutput.setTransactionId(new TransactionId(bigIntXid));
UpdatePortOutput result = portModOutput.build();
- RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(
- inputArg.isSuccessful(), result, inputArg.getErrors());
+ RpcResult<UpdatePortOutput> rpcResult = RpcResultBuilder
+ .<UpdatePortOutput>status(inputArg.isSuccessful()).withResult(result)
+ .withRpcErrors(inputArg.getErrors()).build();
return rpcResult;
}
});
try {
return getConnectionAdapter(cookie).roleRequest(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
return getConnectionAdapter(cookie).setAsync(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
return getConnectionAdapter(cookie).setConfig(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
try {
return getConnectionAdapter(cookie).tableMod(input);
} catch (ConnectionException e) {
- return getRpcErrorFuture(e);
+ return RpcResultUtil.getRpcErrorFuture(e);
}
}
}