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());
}
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();
}
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);
}
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);
}
}
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());
}
Aggregations