Search in sources :

Example 6 with EchoOutput

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

the class EchoReplyMessageFactoryTest method testWithDataFieldSet.

/**
 * Testing {@link EchoReplyMessageFactory} for correct translation into POJO.
 */
@Test
public void testWithDataFieldSet() {
    byte[] data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
    ByteBuf bb = BufferHelper.buildBuffer(data);
    EchoOutput builtByFactory = BufferHelper.deserialize(factory, bb);
    Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData());
}
Also used : EchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput) ByteBuf(io.netty.buffer.ByteBuf) DefaultDeserializerFactoryTest(org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest) Test(org.junit.Test)

Example 7 with EchoOutput

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

the class SalEchoServiceImpl method transform.

private Future<RpcResult<SendEchoOutput>> transform(final ListenableFuture<RpcResult<EchoOutput>> rpcResultListenableFuture) {
    return Futures.transform(rpcResultListenableFuture, input -> {
        Preconditions.checkNotNull(input, "echoOutput value is never expected to be NULL");
        final RpcResult<SendEchoOutput> rpcOutput;
        if (input.isSuccessful()) {
            final SendEchoOutput sendEchoOutput = new SendEchoOutputBuilder().setData(input.getResult().getData()).build();
            rpcOutput = RpcResultBuilder.success(sendEchoOutput).build();
        } else {
            rpcOutput = RpcResultBuilder.<SendEchoOutput>failed().withRpcErrors(input.getErrors()).build();
        }
        return rpcOutput;
    }, MoreExecutors.directExecutor());
}
Also used : SendEchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput) SendEchoOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutputBuilder)

Example 8 with EchoOutput

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

the class SystemNotificationsListenerImplTest method testOnSwitchIdleEvent2.

/**
 * First encounter of idle event, echo not receive.
 */
@Test
public void testOnSwitchIdleEvent2() throws Exception {
    final SettableFuture<RpcResult<EchoOutput>> echoReply = SettableFuture.create();
    Mockito.when(connectionAdapter.echo(Matchers.any(EchoInput.class))).thenReturn(echoReply);
    Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
    Mockito.when(connectionAdapter.disconnect()).thenReturn(Futures.<Boolean>immediateFailedFuture(new Exception("unit exception")));
    SwitchIdleEvent notification = new SwitchIdleEventBuilder().setInfo("wake up, device sleeps").build();
    systemNotificationsListener.onSwitchIdleEvent(notification);
    Thread.sleep(SystemNotificationsListenerImpl.MAX_ECHO_REPLY_TIMEOUT + SAFE_TIMEOUT);
    verifyCommonInvocations();
    Mockito.verify(connectionAdapter, Mockito.timeout(SAFE_TIMEOUT)).echo(Matchers.any(EchoInput.class));
    Mockito.verify(connectionAdapter).disconnect();
    Mockito.verify(connectionContext).changeStateToTimeouting();
    Mockito.verify(connectionContext).closeConnection(true);
    Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
}
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) Test(org.junit.Test)

Example 9 with EchoOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput 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

Test (org.junit.Test)6 EchoOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput)5 EchoOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 ByteBuf (io.netty.buffer.ByteBuf)3 DefaultDeserializerFactoryTest (org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest)2 SendEchoOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput)2 EchoInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput)2 SwitchIdleEvent (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent)2 SwitchIdleEventBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder)2 InetSocketAddress (java.net.InetSocketAddress)1 Date (java.util.Date)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 SendEchoOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutputBuilder)1 EchoInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder)1 FeaturesReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply)1 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)1