use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder in project openflowplugin by opendaylight.
the class RoleReplyMessageFactory method deserialize.
@Override
public RoleRequestOutput deserialize(ByteBuf rawMessage) {
RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
builder.setRole(ControllerRole.forValue((int) rawMessage.readUnsignedInt()));
rawMessage.skipBytes(PADDING_IN_ROLE_REPLY_HEADER);
byte[] generationID = new byte[8];
rawMessage.readBytes(generationID);
builder.setGenerationId(new BigInteger(1, generationID));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder in project openflowplugin by opendaylight.
the class SalRoleServiceImplTest method testSetRole.
@Test
public void testSetRole() throws Exception {
RoleRequestOutput roleRequestOutput = (new RoleRequestOutputBuilder()).setXid(testXid).setGenerationId(BigInteger.valueOf(1)).build();
ListenableFuture<RpcResult<RoleRequestOutput>> futureOutput = RpcResultBuilder.<RoleRequestOutput>success().withResult(roleRequestOutput).buildFuture();
Mockito.when(mockRequestContext.getFuture()).thenReturn(futureOutput);
SalRoleService salRoleService = new SalRoleServiceImpl(mockRequestContextStack, mockDeviceContext);
SetRoleInput setRoleInput = new SetRoleInputBuilder().setControllerRole(OfpRole.BECOMESLAVE).setNode(nodeRef).build();
Future<RpcResult<SetRoleOutput>> future = salRoleService.setRole(setRoleInput);
RpcResult<SetRoleOutput> roleOutputRpcResult = future.get(5, TimeUnit.SECONDS);
assertNotNull("RpcResult from future cannot be null.", roleOutputRpcResult);
assertTrue("RpcResult from future is not successful.", roleOutputRpcResult.isSuccessful());
SetRoleOutput setRoleOutput = roleOutputRpcResult.getResult();
assertNotNull(setRoleOutput);
assertEquals(BigInteger.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder in project openflowplugin by opendaylight.
the class SalRoleServiceImplTest method testDuplicateRoles.
@Test
public void testDuplicateRoles() throws Exception {
// set role to slave
RoleRequestOutput roleRequestOutput = (new RoleRequestOutputBuilder()).setXid(testXid).setGenerationId(BigInteger.valueOf(1)).build();
ListenableFuture<RpcResult<RoleRequestOutput>> futureOutput = RpcResultBuilder.<RoleRequestOutput>success().withResult(roleRequestOutput).buildFuture();
Mockito.when(mockRequestContext.getFuture()).thenReturn(futureOutput);
SalRoleService salRoleService = new SalRoleServiceImpl(mockRequestContextStack, mockDeviceContext);
SetRoleInput setRoleInput = new SetRoleInputBuilder().setControllerRole(OfpRole.BECOMESLAVE).setNode(nodeRef).build();
Future<RpcResult<SetRoleOutput>> future = salRoleService.setRole(setRoleInput);
RpcResult<SetRoleOutput> roleOutputRpcResult = future.get(5, TimeUnit.SECONDS);
assertNotNull("RpcResult from future cannot be null.", roleOutputRpcResult);
assertTrue("RpcResult from future is not successful.", roleOutputRpcResult.isSuccessful());
SetRoleOutput setRoleOutput = roleOutputRpcResult.getResult();
assertNotNull(setRoleOutput);
assertEquals(BigInteger.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
// make another role change with the same role - slave
Future<RpcResult<SetRoleOutput>> future2 = salRoleService.setRole(setRoleInput);
RpcResult<SetRoleOutput> roleOutputRpcResult2 = future2.get(5, TimeUnit.SECONDS);
assertNotNull("RpcResult from future cannot be null.", roleOutputRpcResult2);
assertTrue("RpcResult from future for duplicate role is not successful.", roleOutputRpcResult2.isSuccessful());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder 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));
}
Aggregations