Search in sources :

Example 1 with EchoOutputBuilder

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

the class SalEchoServiceImplTest method testSendEcho.

@Test
public void testSendEcho() throws Exception {
    final EchoOutput echoOut = new EchoOutputBuilder().setData(DUMMY_DATA).build();
    final RpcResult<EchoOutput> replyRpcResult = RpcResultBuilder.success(echoOut).build();
    final ListenableFuture<RpcResult<EchoOutput>> replyFt = Futures.immediateFuture(replyRpcResult);
    Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFt);
    SendEchoInput sendEchoInput = new SendEchoInputBuilder().setData(DUMMY_DATA).build();
    final Future<RpcResult<SendEchoOutput>> echoOutput = salEchoService.sendEcho(sendEchoInput);
    Assert.assertNotNull(echoOutput);
    Assert.assertTrue(echoOutput.isDone());
    Assert.assertTrue(echoOutput.get().isSuccessful());
    verify(mockedRequestContextStack).createRequestContext();
    verify(mockedOutboundQueue).commitEntry(Matchers.eq(2121L), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
}
Also used : SendEchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput) EchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) SendEchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) EchoOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder) SendEchoInput(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput) Test(org.junit.Test)

Example 2 with EchoOutputBuilder

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

the class EchoReplyMessageFactory method deserialize.

@Override
public EchoOutput deserialize(ByteBuf rawMessage) {
    EchoOutputBuilder builder = new EchoOutputBuilder();
    builder.setVersion(getVersion());
    builder.setXid(rawMessage.readUnsignedInt());
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        byte[] data = new byte[remainingBytes];
        rawMessage.readBytes(data);
        builder.setData(data);
    }
    return builder.build();
}
Also used : EchoOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder)

Example 3 with EchoOutputBuilder

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

the class EchoOutputMessageFactoryTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    EchoOutputBuilder builder = new EchoOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14");
    builder.setData(data);
    EchoOutput message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24);
    byte[] readData = new byte[serializedBuffer.readableBytes()];
    serializedBuffer.readBytes(readData);
    Assert.assertArrayEquals("Wrong data", message.getData(), readData);
}
Also used : EchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput) EchoOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 4 with EchoOutputBuilder

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

the class SystemNotificationsListenerImplTest method testOnSwitchIdleEvent1.

/**
 * First encounter of idle event, echo received successfully.
 */
@Test
public void testOnSwitchIdleEvent1() throws Exception {
    final Future<RpcResult<EchoOutput>> echoReply = Futures.immediateFuture(RpcResultBuilder.success(new EchoOutputBuilder().setXid(0L).build()).build());
    Mockito.when(connectionAdapter.echo(Matchers.any(EchoInput.class))).thenReturn(echoReply);
    SwitchIdleEvent notification = new SwitchIdleEventBuilder().setInfo("wake up, device sleeps").build();
    systemNotificationsListener.onSwitchIdleEvent(notification);
    // make sure that the idle notification processing thread started
    Thread.sleep(SAFE_TIMEOUT);
    verifyCommonInvocations();
    Mockito.verify(connectionAdapter, Mockito.timeout(SAFE_TIMEOUT)).echo(Matchers.any(EchoInput.class));
    Mockito.verify(connectionAdapter, Mockito.never()).disconnect();
    Mockito.verify(connectionContext).changeStateToTimeouting();
    Mockito.verify(connectionContext).changeStateToWorking();
}
Also used : SwitchIdleEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder) EchoInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput) SwitchIdleEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) EchoOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder) Test(org.junit.Test)

Aggregations

EchoOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder)4 Test (org.junit.Test)3 EchoOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 ByteBuf (io.netty.buffer.ByteBuf)1 SendEchoInput (org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput)1 SendEchoInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInputBuilder)1 SendEchoOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput)1 EchoInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput)1 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)1 SwitchIdleEvent (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent)1 SwitchIdleEventBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder)1