use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput in project openflowplugin by opendaylight.
the class RoleReplyMessageFactoryTest method testSerialize.
@Test
public void testSerialize() throws Exception {
RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setRole(ControllerRole.forValue(0));
builder.setGenerationId(BigInteger.valueOf(1L));
RoleRequestOutput message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24);
Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) serializedBuffer.readUnsignedInt()).getIntValue());
serializedBuffer.skipBytes(PADDING);
byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
serializedBuffer.readBytes(genId);
Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput in project openflowplugin by opendaylight.
the class RoleService method getGenerationIdFromDevice.
public Future<BigInteger> getGenerationIdFromDevice(final Short version) {
LOG.info("getGenerationIdFromDevice called for device: {}", getDeviceInfo().getNodeId().getValue());
// send a dummy no-change role request to get the generation-id of the switch
final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
roleRequestInputBuilder.setRole(toOFJavaRole(OfpRole.NOCHANGE));
roleRequestInputBuilder.setVersion(version);
roleRequestInputBuilder.setGenerationId(BigInteger.ZERO);
final SettableFuture<BigInteger> finalFuture = SettableFuture.create();
final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture = handleServiceCall(roleRequestInputBuilder);
Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@Override
public void onSuccess(@Nonnull final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
if (roleRequestOutputRpcResult.isSuccessful()) {
final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
if (roleRequestOutput != null) {
LOG.debug("roleRequestOutput.getGenerationId()={}", roleRequestOutput.getGenerationId());
finalFuture.set(roleRequestOutput.getGenerationId());
} else {
LOG.info("roleRequestOutput is null in getGenerationIdFromDevice");
finalFuture.setException(new RoleChangeException("Exception in getting generationId for device:" + getDeviceInfo().getNodeId().getValue()));
}
} else {
LOG.error("getGenerationIdFromDevice RPC error " + roleRequestOutputRpcResult.getErrors().iterator().next().getInfo());
finalFuture.setException(new RoleChangeException(ErrorUtil.errorsToString(roleRequestOutputRpcResult.getErrors())));
}
}
@Override
public void onFailure(final Throwable throwable) {
LOG.info("onFailure - getGenerationIdFromDevice RPC error {}", throwable);
finalFuture.setException(new ExecutionException(throwable));
}
}, MoreExecutors.directExecutor());
return finalFuture;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput in project openflowplugin by opendaylight.
the class RoleService method submitRoleChange.
public Future<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Short version, final BigInteger generationId) {
LOG.info("submitRoleChange called for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
roleRequestInputBuilder.setRole(toOFJavaRole(ofpRole));
roleRequestInputBuilder.setVersion(version);
roleRequestInputBuilder.setGenerationId(generationId);
final ListenableFuture<RpcResult<RoleRequestOutput>> roleListenableFuture = handleServiceCall(roleRequestInputBuilder);
final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@Override
public void onSuccess(@Nonnull final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
LOG.info("submitRoleChange onSuccess for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
if (roleRequestOutput != null) {
final SetRoleOutputBuilder setRoleOutputBuilder = new SetRoleOutputBuilder();
setRoleOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(roleRequestOutput.getXid())));
finalFuture.set(RpcResultBuilder.<SetRoleOutput>success().withResult(setRoleOutputBuilder.build()).build());
} else if (rpcErrors != null) {
LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
for (RpcError rpcError : rpcErrors) {
LOG.warn("RpcError on submitRoleChange for {}: {}", deviceContext.getPrimaryConnectionContext().getNodeId(), rpcError.toString());
}
finalFuture.set(RpcResultBuilder.<SetRoleOutput>failed().withRpcErrors(rpcErrors).build());
}
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("submitRoleChange onFailure for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole, throwable);
finalFuture.setException(throwable);
}
}, MoreExecutors.directExecutor());
return finalFuture;
}
Aggregations