Search in sources :

Example 1 with EchoOutput

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

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

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

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

the class SystemNotificationsListenerImpl method executeOnSwitchIdleEvent.

@SuppressWarnings("checkstyle:IllegalCatch")
private void executeOnSwitchIdleEvent() {
    boolean shouldBeDisconnected = true;
    final InetSocketAddress remoteAddress = connectionContext.getConnectionAdapter().getRemoteAddress();
    if (ConnectionContext.CONNECTION_STATE.WORKING.equals(connectionContext.getConnectionState())) {
        FeaturesReply features = connectionContext.getFeatures();
        LOG.info("Switch Idle state occurred, node={}|auxId={}", remoteAddress, features.getAuxiliaryId());
        connectionContext.changeStateToTimeouting();
        EchoInputBuilder builder = new EchoInputBuilder();
        builder.setVersion(features.getVersion());
        builder.setXid(ECHO_XID.getValue());
        Future<RpcResult<EchoOutput>> echoReplyFuture = connectionContext.getConnectionAdapter().echo(builder.build());
        try {
            RpcResult<EchoOutput> echoReplyValue = echoReplyFuture.get(echoReplyTimeout, TimeUnit.MILLISECONDS);
            if (echoReplyValue.isSuccessful() && Objects.equals(echoReplyValue.getResult().getXid(), ECHO_XID.getValue())) {
                connectionContext.changeStateToWorking();
                shouldBeDisconnected = false;
            } else {
                logErrors(remoteAddress, echoReplyValue);
            }
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Exception while  waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e.getMessage());
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("Exception while  waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e);
            }
        }
    }
    if (shouldBeDisconnected) {
        if (LOG.isInfoEnabled()) {
            LOG.info("ConnectionEvent:Closing connection as device is idle. Echo sent at {}. Device:{}, NodeId:{}", new Date(System.currentTimeMillis() - echoReplyTimeout), remoteAddress, connectionContext.getSafeNodeIdForLOG());
        }
        connectionContext.closeConnection(true);
    }
}
Also used : EchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput) InetSocketAddress(java.net.InetSocketAddress) FeaturesReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply) EchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Date(java.util.Date)

Example 5 with EchoOutput

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

the class EchoReplyMessageFactoryTest method testWithEmptyDataField.

/**
 * Testing {@link EchoReplyMessageFactory} for correct translation into POJO.
 */
@Test
public void testWithEmptyDataField() {
    ByteBuf bb = BufferHelper.buildBuffer();
    EchoOutput builtByFactory = BufferHelper.deserialize(factory, bb);
    Assert.assertArrayEquals("Wrong data", null, 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)

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