Search in sources :

Example 1 with RoleRequestOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput 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();
}
Also used : RoleRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder) BigInteger(java.math.BigInteger)

Example 2 with RoleRequestOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput 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());
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RoleRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder) SetRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) SetRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput) SalRoleService(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService) Test(org.junit.Test)

Example 3 with RoleRequestOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput in project openflowplugin by opendaylight.

the class RoleReplyMessageFactoryTest method test.

/**
 * Testing of {@link RoleReplyMessageFactory} for correct translation into POJO.
 */
@Test
public void test() {
    ByteBuf bb = BufferHelper.buildBuffer("00 00 00 02 00 00 00 00 00 01 02 03 04 05 06 07");
    RoleRequestOutput builtByFactory = BufferHelper.deserialize(roleFactory, bb);
    BufferHelper.checkHeaderV13(builtByFactory);
    Assert.assertEquals("Wrong role", 0x02, builtByFactory.getRole().getIntValue());
    Assert.assertEquals("Wrong generationId", 0x01020304050607L, builtByFactory.getGenerationId().longValue());
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 4 with RoleRequestOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput in project openflowplugin by opendaylight.

the class SalRoleServiceImplTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    Mockito.when(mockDeviceInfo.getNodeId()).thenReturn(testNodeId);
    Mockito.when(mockDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
    short testVersion = 4;
    Mockito.when(mockFeaturesOutput.getVersion()).thenReturn(testVersion);
    Mockito.when(mockDeviceContext.getDeviceState()).thenReturn(mockDeviceState);
    Mockito.when(mockDeviceContext.getDeviceInfo()).thenReturn(mockDeviceInfo);
    Mockito.when(mockDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext);
    Mockito.when(mockConnectionContext.getFeatures()).thenReturn(mockFeaturesReply);
    Mockito.when(mockConnectionContext.getNodeId()).thenReturn(testNodeId);
    Mockito.when(mockFeaturesReply.getVersion()).thenReturn(testVersion);
    Mockito.when(mockDeviceContext.getMessageSpy()).thenReturn(mockMessageSpy);
    Mockito.when(mockRequestContextStack.<RoleRequestOutput>createRequestContext()).thenReturn(mockRequestContext);
    Mockito.when(mockRequestContext.getXid()).thenReturn(new Xid(testXid));
    Mockito.when(mockConnectionContext.getOutboundQueueProvider()).thenReturn(mockOutboundQueue);
    Mockito.when(mockDeviceContext.getPrimaryConnectionContext().getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
    NodeKey key = new NodeKey(testNodeId);
    InstanceIdentifier<Node> path = InstanceIdentifier.<Nodes>builder(Nodes.class).<Node, NodeKey>child(Node.class, key).build();
    nodeRef = new NodeRef(path);
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Before(org.junit.Before)

Example 5 with RoleRequestOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput 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());
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RoleRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder) SetRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) SetRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput) SalRoleService(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService) Test(org.junit.Test)

Aggregations

RoleRequestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput)7 Test (org.junit.Test)4 RoleRequestOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 BigInteger (java.math.BigInteger)3 SetRoleOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput)3 ByteBuf (io.netty.buffer.ByteBuf)2 RoleRequestInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder)2 SalRoleService (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService)2 SetRoleInput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput)2 SetRoleInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder)2 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1 Before (org.junit.Before)1 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)1 RoleChangeException (org.opendaylight.openflowplugin.impl.role.RoleChangeException)1 TransactionId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId)1 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)1 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)1 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)1