Search in sources :

Example 1 with EchoInputBuilder

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

the class EchoInputMessageFactoryTest method testData.

/**
 * Testing of {@link EchoInputMessageFactory} for correct data serialization.
 */
@Test
public void testData() throws Exception {
    byte[] dataToTest = new byte[] { 91, 92, 93, 94, 95, 96, 97, 98 };
    EchoInputBuilder eib = new EchoInputBuilder();
    BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID);
    eib.setData(dataToTest);
    EchoInput ei = eib.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    echoFactory.serialize(ei, out);
    BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8 + dataToTest.length);
    byte[] outData = new byte[dataToTest.length];
    out.readBytes(outData);
    Assert.assertArrayEquals("Wrong - different output data.", dataToTest, outData);
    out.release();
}
Also used : EchoInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput) EchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 2 with EchoInputBuilder

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

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

the class EchoInputMessageFactoryTest method testV13.

/**
 * Testing of {@link EchoInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testV13() throws Exception {
    EchoInputBuilder eib = new EchoInputBuilder();
    BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID);
    EchoInput ei = eib.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    echoFactory.serialize(ei, out);
    BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);
}
Also used : EchoInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput) EchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 4 with EchoInputBuilder

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

the class EchoInputMessageFactoryTest method testV10.

/**
 * Testing of {@link EchoInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testV10() throws Exception {
    EchoInputBuilder eib = new EchoInputBuilder();
    BufferHelper.setupHeader(eib, EncodeConstants.OF10_VERSION_ID);
    EchoInput ei = eib.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    echoFactory.serialize(ei, out);
    BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);
}
Also used : EchoInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput) EchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 5 with EchoInputBuilder

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

the class EchoServiceTest method testSendEcho.

@Test
public void testSendEcho() throws Exception {
    EchoInputBuilder sendEchoInput = new EchoInputBuilder();
    echoService.handleServiceCall(sendEchoInput);
    verify(mockedRequestContextStack).createRequestContext();
}
Also used : EchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder) Test(org.junit.Test)

Aggregations

EchoInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder)6 Test (org.junit.Test)5 EchoInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput)4 ByteBuf (io.netty.buffer.ByteBuf)3 InetSocketAddress (java.net.InetSocketAddress)1 Date (java.util.Date)1 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)1 EchoOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput)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 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1