Search in sources :

Example 1 with SwitchIdleEvent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent in project openflowplugin by opendaylight.

the class ConnectionAdapterImplTest method testConsume.

/**
 * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with notifications.
 */
@Test
public void testConsume() {
    DataObject message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
    message = new ErrorMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onErrorMessage((ErrorMessage) message);
    message = new ExperimenterMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onExperimenterMessage((ExperimenterMessage) message);
    message = new FlowRemovedMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onFlowRemovedMessage((FlowRemovedMessage) message);
    message = new HelloMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onHelloMessage((HelloMessage) message);
    message = new MultipartReplyMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onMultipartReplyMessage((MultipartReplyMessage) message);
    message = new PacketInMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onPacketInMessage((PacketInMessage) message);
    message = new PortStatusMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onPortStatusMessage((PortStatusMessage) message);
    message = new SwitchIdleEventBuilder().build();
    adapter.consume(message);
    verify(systemListener, times(1)).onSwitchIdleEvent((SwitchIdleEvent) message);
    message = new DisconnectEventBuilder().build();
    adapter.consume(message);
    verify(systemListener, times(1)).onDisconnectEvent((DisconnectEvent) message);
    message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) DisconnectEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder) ExperimenterMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SwitchIdleEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder) PortStatusMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder) HelloMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) FlowRemovedMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder) EchoRequestMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder) Test(org.junit.Test)

Example 2 with SwitchIdleEvent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent 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 3 with SwitchIdleEvent

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent 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)3 SwitchIdleEventBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder)3 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 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 EchoOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder)1 EchoRequestMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder)1 ErrorMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder)1 ExperimenterMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder)1 FlowRemovedMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder)1 HelloMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder)1 MultipartReplyMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder)1 PacketInMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder)1 PortStatusMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder)1 DisconnectEventBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder)1 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)1