use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder in project openflowplugin by opendaylight.
the class RoleRequestInputMessageFactory method deserialize.
@Override
public RoleRequestInput deserialize(ByteBuf rawMessage) {
RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
builder.setRole(ControllerRole.forValue(rawMessage.readInt()));
rawMessage.skipBytes(PADDING);
byte[] generationId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(generationId);
builder.setGenerationId(new BigInteger(1, generationId));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder in project openflowplugin by opendaylight.
the class RoleRequestInputMessageFactoryTest method testRoleRequestInputMessage.
/**
* Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testRoleRequestInputMessage() throws Exception {
RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setRole(ControllerRole.forValue(2));
byte[] generationId = new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 };
builder.setGenerationId(new BigInteger(1, generationId));
RoleRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
roleFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());
out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE);
byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.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.RoleRequestInputBuilder 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.RoleRequestInputBuilder 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