Ditch use of SystemNotificationsListener 66/110166/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Feb 2024 02:26:24 +0000 (03:26 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 8 Feb 2024 10:28:57 +0000 (10:28 +0000)
Introduce SystemListener, which does essentially the same thing.

Change-Id: I97ae5237e3313d757e1a01ad9d022cfbfda498e1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
openflowjava/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImpl.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplTest.java
openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/MockPlugin.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/OpenflowProtocolListenerInitialImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/listener/OpenflowProtocolListenerFullImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/OpenflowProtocolListenerInitialImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/OpenflowProtocolListenerFullImplTest.java

index c60311af64e45cd030b09770b92e2ac31e057065..9a9e9a3067428f307e6da76ebd8de76d5bad69b9 100644 (file)
@@ -14,11 +14,14 @@ import java.security.cert.X509Certificate;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.openflowjava.protocol.api.extensibility.AlienMessageListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SslConnectionError;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
 
 /**
  * Manages a switch connection.
@@ -27,6 +30,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.S
  * @author michal.polkorab
  */
 public interface ConnectionAdapter extends OpenflowProtocolService {
+    @NonNullByDefault
+    interface SystemListener {
+        void onDisconnect(DisconnectEvent disconnect);
+
+        void onSwitchIdle(SwitchIdleEvent switchIdle);
+
+        void onSslConnectionError(SslConnectionError sslConnectionError);
+    }
 
     /**
      * Disconnect corresponding switch.
@@ -61,7 +72,7 @@ public interface ConnectionAdapter extends OpenflowProtocolService {
      *
      * @param systemListener here will be pushed all system messages from library
      */
-    void setSystemListener(SystemNotificationsListener systemListener);
+    void setSystemListener(SystemListener systemListener);
 
     /**
      * Set handler for alien messages received from device.
index 94ce4e18abfa6d2f3dcdfa2114be2ad7b5a06275..3efd60fcdda3835fe25120370ef202dac35ea865 100644 (file)
@@ -48,7 +48,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.D
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SslConnectionError;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SslConnectionErrorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927._switch.certificate.IssuerBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927._switch.certificate.SubjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.ssl.connection.error.SwitchCertificate;
@@ -68,7 +67,7 @@ public class ConnectionAdapterImpl extends AbstractConnectionAdapterStatistics i
 
     private ConnectionReadyListener connectionReadyListener;
     private OpenflowProtocolListener messageListener;
-    private SystemNotificationsListener systemListener;
+    private SystemListener systemListener;
     private AlienMessageListener alienMessageListener;
     private AbstractOutboundQueueManager<?, ?> outputManager;
     private OFVersionDetector versionDetector;
@@ -102,7 +101,7 @@ public class ConnectionAdapterImpl extends AbstractConnectionAdapterStatistics i
     }
 
     @Override
-    public void setSystemListener(final SystemNotificationsListener systemListener) {
+    public void setSystemListener(final SystemListener systemListener) {
         this.systemListener = systemListener;
     }
 
@@ -120,65 +119,63 @@ public class ConnectionAdapterImpl extends AbstractConnectionAdapterStatistics i
             return;
         }
         if (message instanceof Notification) {
-
             // System events
-            if (message instanceof DisconnectEvent) {
-                systemListener.onDisconnectEvent((DisconnectEvent) message);
+            if (message instanceof DisconnectEvent disconnect) {
+                systemListener.onDisconnect(disconnect);
                 responseCache.invalidateAll();
                 disconnectOccured = true;
-            } else if (message instanceof SwitchIdleEvent) {
-                systemListener.onSwitchIdleEvent((SwitchIdleEvent) message);
-            } else if (message instanceof SslConnectionError) {
+            } else if (message instanceof SwitchIdleEvent switchIdle) {
+                systemListener.onSwitchIdle(switchIdle);
+            } else if (message instanceof SslConnectionError sslError) {
                 systemListener.onSslConnectionError(new SslConnectionErrorBuilder()
-                        .setInfo(((SslConnectionError) message).getInfo())
-                        .setSwitchCertificate(buildSwitchCertificate())
-                        .build());
+                    .setInfo(sslError.getInfo())
+                    .setSwitchCertificate(buildSwitchCertificate())
+                    .build());
             // OpenFlow messages
-            } else if (message instanceof EchoRequestMessage) {
+            } else if (message instanceof EchoRequestMessage echoRequest) {
                 if (outputManager != null) {
-                    outputManager.onEchoRequest((EchoRequestMessage) message, datapathId);
+                    outputManager.onEchoRequest(echoRequest, datapathId);
                 } else {
-                    messageListener.onEchoRequestMessage((EchoRequestMessage) message);
+                    messageListener.onEchoRequestMessage(echoRequest);
                 }
-            } else if (message instanceof ErrorMessage) {
+            } else if (message instanceof ErrorMessage error) {
                 // Send only unmatched errors
-                if (outputManager == null || !outputManager.onMessage((OfHeader) message)) {
-                    messageListener.onErrorMessage((ErrorMessage) message);
+                if (outputManager == null || !outputManager.onMessage(error)) {
+                    messageListener.onErrorMessage(error);
                 }
-            } else if (message instanceof ExperimenterMessage) {
+            } else if (message instanceof ExperimenterMessage experimenter) {
                 if (outputManager != null) {
-                    outputManager.onMessage((OfHeader) message);
+                    outputManager.onMessage(experimenter);
                 }
-                messageListener.onExperimenterMessage((ExperimenterMessage) message);
-            } else if (message instanceof FlowRemovedMessage) {
-                messageListener.onFlowRemovedMessage((FlowRemovedMessage) message);
-            } else if (message instanceof HelloMessage) {
+                messageListener.onExperimenterMessage(experimenter);
+            } else if (message instanceof FlowRemovedMessage flowRemoved) {
+                messageListener.onFlowRemovedMessage(flowRemoved);
+            } else if (message instanceof HelloMessage hello) {
                 LOG.info("Hello received");
-                messageListener.onHelloMessage((HelloMessage) message);
-            } else if (message instanceof MultipartReplyMessage) {
+                messageListener.onHelloMessage(hello);
+            } else if (message instanceof MultipartReplyMessage multipartReply) {
                 if (outputManager != null) {
-                    outputManager.onMessage((OfHeader) message);
+                    outputManager.onMessage(multipartReply);
                 }
-                messageListener.onMultipartReplyMessage((MultipartReplyMessage) message);
-            } else if (message instanceof PacketInMessage) {
-                messageListener.onPacketInMessage((PacketInMessage) message);
-            } else if (message instanceof PortStatusMessage) {
-                messageListener.onPortStatusMessage((PortStatusMessage) message);
+                messageListener.onMultipartReplyMessage(multipartReply);
+            } else if (message instanceof PacketInMessage packetIn) {
+                messageListener.onPacketInMessage(packetIn);
+            } else if (message instanceof PortStatusMessage portStatus) {
+                messageListener.onPortStatusMessage(portStatus);
             } else {
                 LOG.warn("message listening not supported for type: {}", message.getClass());
             }
-        } else if (message instanceof OfHeader) {
+        } else if (message instanceof OfHeader header) {
             LOG.debug("OF header msg received");
 
-            if (alienMessageListener != null && alienMessageListener.onAlienMessage((OfHeader) message)) {
-                LOG.debug("Alien message {} received", message.implementedInterface());
-            } else if (outputManager == null || !outputManager.onMessage((OfHeader) message)
-                    || message instanceof EchoOutput) {
-                final RpcResponseKey key = createRpcResponseKey((OfHeader) message);
+            if (alienMessageListener != null && alienMessageListener.onAlienMessage(header)) {
+                LOG.debug("Alien message {} received", header.implementedInterface());
+            } else if (outputManager == null || !outputManager.onMessage(header) || header instanceof EchoOutput) {
+                final RpcResponseKey key = createRpcResponseKey(header);
                 final ResponseExpectedRpcListener<?> listener = findRpcResponse(key);
                 if (listener != null) {
                     LOG.debug("Corresponding rpcFuture found");
-                    listener.completed((OfHeader) message);
+                    listener.completed(header);
                     LOG.debug("After setting rpcFuture");
                     responseCache.invalidate(key);
                 }
index 69bebc495d57c543af82d7287c55e948c79838b8..6b44deb04a653e03976483dbcd88a83b56b4f89b 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter.SystemListener;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.openflowjava.statistics.CounterEventTypes;
 import org.opendaylight.openflowjava.statistics.StatisticsCounters;
@@ -59,7 +60,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.common.Uint32;
 
@@ -77,31 +77,56 @@ public class ConnectionAdapterImplStatisticsTest {
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
         notification -> notification.getValue().discard();
 
-    @Mock SystemNotificationsListener systemListener;
-    @Mock ConnectionReadyListener readyListener;
-    @Mock ChannelFuture channelFuture;
-    @Mock OpenflowProtocolListener messageListener;
-    @Mock SocketChannel channel;
-    @Mock ChannelPipeline pipeline;
-    @Mock EchoInput echoInput;
-    @Mock BarrierInput barrierInput;
-    @Mock EchoReplyInput echoReplyInput;
-    @Mock ExperimenterInput experimenterInput;
-    @Mock FlowModInput flowModInput;
-    @Mock GetConfigInput getConfigInput;
-    @Mock GetFeaturesInput getFeaturesInput;
-    @Mock GetQueueConfigInput getQueueConfigInput;
-    @Mock GroupModInput groupModInput;
-    @Mock HelloInput helloInput;
-    @Mock MeterModInput meterModInput;
-    @Mock PacketOutInput packetOutInput;
-    @Mock MultipartRequestInput multipartRequestInput;
-    @Mock PortModInput portModInput;
-    @Mock RoleRequestInput roleRequestInput;
-    @Mock SetConfigInput setConfigInput;
-    @Mock TableModInput tableModInput;
-    @Mock GetAsyncInput getAsyncInput;
-    @Mock SetAsyncInput setAsyncInput;
+    @Mock
+    private SystemListener systemListener;
+    @Mock
+    private ConnectionReadyListener readyListener;
+    @Mock
+    private ChannelFuture channelFuture;
+    @Mock
+    private OpenflowProtocolListener messageListener;
+    @Mock
+    private SocketChannel channel;
+    @Mock
+    private ChannelPipeline pipeline;
+    @Mock
+    private EchoInput echoInput;
+    @Mock
+    private BarrierInput barrierInput;
+    @Mock
+    private EchoReplyInput echoReplyInput;
+    @Mock
+    private ExperimenterInput experimenterInput;
+    @Mock
+    private FlowModInput flowModInput;
+    @Mock
+    private GetConfigInput getConfigInput;
+    @Mock
+    private GetFeaturesInput getFeaturesInput;
+    @Mock
+    private GetQueueConfigInput getQueueConfigInput;
+    @Mock
+    private GroupModInput groupModInput;
+    @Mock
+    private HelloInput helloInput;
+    @Mock
+    private MeterModInput meterModInput;
+    @Mock
+    private PacketOutInput packetOutInput;
+    @Mock
+    private MultipartRequestInput multipartRequestInput;
+    @Mock
+    private PortModInput portModInput;
+    @Mock
+    private RoleRequestInput roleRequestInput;
+    @Mock
+    private SetConfigInput setConfigInput;
+    @Mock
+    private TableModInput tableModInput;
+    @Mock
+    private GetAsyncInput getAsyncInput;
+    @Mock
+    private SetAsyncInput setAsyncInput;
 
     private ConnectionAdapterImpl adapter;
     private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> cache;
index 6f5ce578938f3d4cfe8b595789ea122200b1bb95..af201c0c5e59d53546e0e4cb42006d6790005f05 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter.SystemListener;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
@@ -55,7 +56,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.D
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.common.Uint32;
 
@@ -73,13 +73,20 @@ public class ConnectionAdapterImplTest {
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
         notification -> notification.getValue().discard();
 
-    @Mock SocketChannel channel;
-    @Mock ChannelPipeline pipeline;
-    @Mock OpenflowProtocolListener messageListener;
-    @Mock SystemNotificationsListener systemListener;
-    @Mock ConnectionReadyListener readyListener;
-    @Mock Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> mockCache;
-    @Mock ChannelFuture channelFuture;
+    @Mock
+    private SocketChannel channel;
+    @Mock
+    ChannelPipeline pipeline;
+    @Mock
+    private OpenflowProtocolListener messageListener;
+    @Mock
+    private SystemListener systemListener;
+    @Mock
+    private ConnectionReadyListener readyListener;
+    @Mock
+    private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> mockCache;
+    @Mock
+    private ChannelFuture channelFuture;
 
     private ConnectionAdapterImpl adapter;
     private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> cache;
@@ -132,10 +139,10 @@ public class ConnectionAdapterImplTest {
         verify(messageListener, times(1)).onPortStatusMessage((PortStatusMessage) message);
         message = new SwitchIdleEventBuilder().build();
         adapter.consume(message);
-        verify(systemListener, times(1)).onSwitchIdleEvent((SwitchIdleEvent) message);
+        verify(systemListener, times(1)).onSwitchIdle((SwitchIdleEvent) message);
         message = new DisconnectEventBuilder().build();
         adapter.consume(message);
-        verify(systemListener, times(1)).onDisconnectEvent((DisconnectEvent) message);
+        verify(systemListener, times(1)).onDisconnect((DisconnectEvent) message);
         message = new EchoRequestMessageBuilder().build();
         adapter.consume(message);
         verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
index 133561d399b2fe202c47c14250e7dc3488a2ec7e..b366515a2df9696d58aa93f24ca5626cb05038a7 100644 (file)
@@ -15,6 +15,7 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter.SystemListener;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
 import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
@@ -37,7 +38,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SslConnectionError;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.Uint32;
@@ -50,16 +50,18 @@ import org.slf4j.LoggerFactory;
  *
  * @author michal.polkorab
  */
-public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHandler,
-        SystemNotificationsListener, ConnectionReadyListener {
-
+public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHandler, SystemListener,
+        ConnectionReadyListener {
     protected static final Logger LOGGER = LoggerFactory.getLogger(MockPlugin.class);
-    protected volatile ConnectionAdapter adapter;
+
     private final SettableFuture<Void> finishedFuture;
-    private int idleCounter = 0;
     private final ExecutorService executorService;
 
-    public MockPlugin(ExecutorService executorService) {
+    private int idleCounter = 0;
+
+    protected volatile ConnectionAdapter adapter;
+
+    public MockPlugin(final ExecutorService executorService) {
         LOGGER.trace("Creating MockPlugin");
         finishedFuture = SettableFuture.create();
         this.executorService = executorService;
@@ -67,9 +69,9 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
     }
 
     @Override
-    public void onSwitchConnected(ConnectionAdapter connection) {
+    public void onSwitchConnected(final ConnectionAdapter connection) {
         LOGGER.debug("onSwitchConnected: {}", connection);
-        this.adapter = connection;
+        adapter = connection;
         connection.setMessageListener(this);
         connection.setSystemListener(this);
         connection.setConnectionReadyListener(this);
@@ -77,12 +79,27 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
     }
 
     @Override
-    public boolean accept(InetAddress switchAddress) {
+    public boolean accept(final InetAddress switchAddress) {
         LOGGER.debug("MockPlugin.accept(): {}", switchAddress.toString());
-
         return true;
     }
 
+    @Override
+    public void onDisconnect(final DisconnectEvent disconnect) {
+        LOGGER.debug("disconnection occured: {}", disconnect.getInfo());
+    }
+
+    @Override
+    public void onSslConnectionError(final SslConnectionError sslConnectionError) {
+        LOGGER.debug("Ssl error occured: {}", sslConnectionError.getInfo());
+    }
+
+    @Override
+    public void onSwitchIdle(final SwitchIdleEvent switchIdle) {
+        LOGGER.debug("MockPlugin.onSwitchIdleEvent() switch status: {}", switchIdle.getInfo());
+        idleCounter++;
+    }
+
     @Override
     public void onEchoRequestMessage(final EchoRequestMessage notification) {
         LOGGER.debug("MockPlugin.onEchoRequestMessage() adapter: {}", adapter);
@@ -99,25 +116,22 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
     }
 
     @Override
-    public void onErrorMessage(ErrorMessage notification) {
+    public void onErrorMessage(final ErrorMessage notification) {
         LOGGER.debug("Error message received");
-
     }
 
     @Override
-    public void onExperimenterMessage(ExperimenterMessage notification) {
+    public void onExperimenterMessage(final ExperimenterMessage notification) {
         LOGGER.debug("Experimenter message received");
-
     }
 
     @Override
-    public void onFlowRemovedMessage(FlowRemovedMessage notification) {
+    public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
         LOGGER.debug("FlowRemoved message received");
-
     }
 
     @Override
-    public void onHelloMessage(HelloMessage notification) {
+    public void onHelloMessage(final HelloMessage notification) {
         new Thread(() -> {
             LOGGER.debug("MockPlugin.onHelloMessage().run() Hello message received");
             HelloInputBuilder hib = new HelloInputBuilder();
@@ -128,7 +142,6 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
             LOGGER.debug("hello msg sent");
             new Thread(this::getSwitchFeatures).start();
         }).start();
-
     }
 
     protected void getSwitchFeatures() {
@@ -164,13 +177,12 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
     }
 
     @Override
-    public void onMultipartReplyMessage(MultipartReplyMessage notification) {
+    public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
         LOGGER.debug("MultipartReply message received");
-
     }
 
     @Override
-    public void onPacketInMessage(PacketInMessage notification) {
+    public void onPacketInMessage(final PacketInMessage notification) {
         LOGGER.debug("PacketIn message received");
         LOGGER.debug("BufferId: {}", notification.getBufferId());
         LOGGER.debug("TotalLength: {}", notification.getTotalLen());
@@ -183,26 +195,14 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
     }
 
     @Override
-    public void onPortStatusMessage(PortStatusMessage notification) {
+    public void onPortStatusMessage(final PortStatusMessage notification) {
         LOGGER.debug("MockPlugin.onPortStatusMessage() message received");
-
-    }
-
-    @Override
-    public void onDisconnectEvent(DisconnectEvent notification) {
-        LOGGER.debug("disconnection occured: {}", notification.getInfo());
     }
 
     public SettableFuture<Void> getFinishedFuture() {
         return finishedFuture;
     }
 
-    @Override
-    public void onSwitchIdleEvent(SwitchIdleEvent notification) {
-        LOGGER.debug("MockPlugin.onSwitchIdleEvent() switch status: {}", notification.getInfo());
-        idleCounter++;
-    }
-
     /**
      * Returns number of occurred idleEvents.
      */
@@ -222,14 +222,9 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
      * @param host                     - host IP
      * @param port                     - port number
      */
-    public void initiateConnection(SwitchConnectionProviderImpl switchConnectionProvider, String host, int port) {
+    public void initiateConnection(final SwitchConnectionProviderImpl switchConnectionProvider, final String host,
+            final int port) {
         LOGGER.trace("MockPlugin().initiateConnection()");
         switchConnectionProvider.initiateConnection(host, port);
     }
-
-    @Override
-    public void onSslConnectionError(SslConnectionError notification) {
-        LOGGER.debug("Ssl error occured: {}", notification.getInfo());
-
-    }
 }
index f68b00fe7ac77ce7ee611883351937d8df329b6b..3810f3e08fec5a5a781636cf8348a677d88d68b7 100644 (file)
@@ -46,8 +46,6 @@ import org.opendaylight.openflowplugin.impl.connection.listener.OpenflowProtocol
 import org.opendaylight.openflowplugin.impl.connection.listener.SystemNotificationsListenerImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -111,13 +109,11 @@ public class ConnectionManagerImpl implements ConnectionManager {
                 connectionContext, handshakeContext);
         connectionAdapter.setConnectionReadyListener(connectionReadyListener);
 
-        final OpenflowProtocolListener ofMessageListener =
-                new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
-        connectionAdapter.setMessageListener(ofMessageListener);
+        connectionAdapter.setMessageListener(
+            new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext));
 
-        final SystemNotificationsListener systemListener = new SystemNotificationsListenerImpl(connectionContext,
-                config.getEchoReplyTimeout().getValue().toJava(), executorService, notificationPublishService);
-        connectionAdapter.setSystemListener(systemListener);
+        connectionAdapter.setSystemListener(new SystemNotificationsListenerImpl(connectionContext,
+                config.getEchoReplyTimeout().getValue().toJava(), executorService, notificationPublishService));
 
         LOG.trace("connection ballet finished");
     }
index eb9c190661d8eda11143eb2f6cc118d1a035bd0d..d31cef0087f2d84de87cad39ab6d56852e4634e9 100644 (file)
@@ -7,11 +7,15 @@
  */
 package org.opendaylight.openflowplugin.impl.connection.listener;
 
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Objects;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
 import org.opendaylight.openflowplugin.impl.connection.HandshakeStepWrapper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
@@ -21,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,15 +49,21 @@ public class OpenflowProtocolListenerInitialImpl implements OpenflowProtocolList
 
     @Override
     public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("echo request received: {}", echoRequestMessage.getXid());
-        }
-        EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
-        builder.setVersion(echoRequestMessage.getVersion());
-        builder.setXid(echoRequestMessage.getXid());
-        builder.setData(echoRequestMessage.getData());
+        final var xid = echoRequestMessage.getXid();
+        LOG.debug("echo request received: {}", xid);
+        Futures.addCallback(connectionContext.getConnectionAdapter().echoReply(
+            new EchoReplyInputBuilder().setXid(xid).setData(echoRequestMessage.getData()).build()),
+            new FutureCallback<>() {
+                @Override
+                public void onSuccess(final RpcResult<EchoReplyOutput> result) {
+                    LOG.debug("echo reply sent: {}", xid);
+                }
 
-        connectionContext.getConnectionAdapter().echoReply(builder.build());
+                @Override
+                public void onFailure(final Throwable cause) {
+                    LOG.debug("echo reply failed: {}", xid, cause);
+                }
+            }, MoreExecutors.directExecutor());
     }
 
     @Override
index 9211867f391e31a614b5c250534790c9290318cc..e98cca75de4e76269dbd57acc03ca60d02b8c51d 100644 (file)
@@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter.SystemListener;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
@@ -32,7 +33,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SslConnectionError;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.Uint16;
@@ -40,8 +40,7 @@ import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SystemNotificationsListenerImpl implements SystemNotificationsListener {
-
+public class SystemNotificationsListenerImpl implements SystemListener {
     private static final Logger LOG = LoggerFactory.getLogger(SystemNotificationsListenerImpl.class);
     private static final Logger OF_EVENT_LOG = LoggerFactory.getLogger("OfEventLog");
     private static final Xid ECHO_XID = new Xid(Uint32.ZERO);
@@ -54,28 +53,39 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
     private final NotificationPublishService notificationPublishService;
 
     public SystemNotificationsListenerImpl(@NonNull final ConnectionContext connectionContext,
-                                           final long echoReplyTimeout,
-                                           @NonNull final Executor executor,
-                                           @NonNull final NotificationPublishService notificationPublishService) {
-        this.executor = requireNonNull(executor);
+            final long echoReplyTimeout, final @NonNull Executor executor,
+            @NonNull final NotificationPublishService notificationPublishService) {
         this.connectionContext = requireNonNull(connectionContext);
         this.echoReplyTimeout = echoReplyTimeout;
-        this.notificationPublishService = notificationPublishService;
+        this.executor = requireNonNull(executor);
+        this.notificationPublishService = requireNonNull(notificationPublishService);
     }
 
     @Override
-    public void onDisconnectEvent(final DisconnectEvent notification) {
-        OF_EVENT_LOG.debug("Disconnect, Node: {}", connectionContext.getSafeNodeIdForLOG());
-        LOG.info("ConnectionEvent: Connection closed by device, Device:{}, NodeId:{}",
-                connectionContext.getConnectionAdapter().getRemoteAddress(), connectionContext.getSafeNodeIdForLOG());
-        connectionContext.onConnectionClosed();
+    public void onSslConnectionError(final SslConnectionError sslConnectionError) {
+        final var switchCert = sslConnectionError.getSwitchCertificate();
+        notificationPublishService.offerNotification(new SslErrorBuilder()
+            .setType(SslErrorType.SslConFailed)
+            .setCode(Uint16.valueOf(SslErrorType.SslConFailed.getIntValue()))
+            .setNodeIpAddress(remoteAddress())
+            .setData(sslConnectionError.getInfo())
+            .setSwitchCertificate(switchCert == null ? null : new SwitchCertificateBuilder(switchCert).build())
+            .build());
     }
 
     @Override
-    public void onSwitchIdleEvent(final SwitchIdleEvent notification) {
+    public void onSwitchIdle(final SwitchIdleEvent switchIdle) {
         executor.execute(this::executeOnSwitchIdleEvent);
     }
 
+    @Override
+    public void onDisconnect(final DisconnectEvent notification) {
+        OF_EVENT_LOG.debug("Disconnect, Node: {}", connectionContext.getSafeNodeIdForLOG());
+        LOG.info("ConnectionEvent: Connection closed by device, Device:{}, NodeId:{}",
+                connectionContext.getConnectionAdapter().getRemoteAddress(), connectionContext.getSafeNodeIdForLOG());
+        connectionContext.onConnectionClosed();
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     private void executeOnSwitchIdleEvent() {
         boolean shouldBeDisconnected = true;
@@ -141,19 +151,6 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
         }
     }
 
-    @Override
-    public void onSslConnectionError(final SslConnectionError notification) {
-        final var switchCert = notification.getSwitchCertificate();
-
-        notificationPublishService.offerNotification(new SslErrorBuilder()
-            .setType(SslErrorType.SslConFailed)
-            .setCode(Uint16.valueOf(SslErrorType.SslConFailed.getIntValue()))
-            .setNodeIpAddress(remoteAddress())
-            .setData(notification.getInfo())
-            .setSwitchCertificate(switchCert == null ? null : new SwitchCertificateBuilder(switchCert).build())
-            .build());
-    }
-
     private @Nullable IpAddress remoteAddress() {
         final var connectionAdapter = connectionContext.getConnectionAdapter();
         if (connectionAdapter != null) {
index 574fa1c4db1cf1de409877cfcdbe75c067026a76..546b3f30c19550c342aa5d4c1f68e7490d38e145 100644 (file)
@@ -7,11 +7,15 @@
  */
 package org.opendaylight.openflowplugin.impl.device.listener;
 
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.extensibility.AlienMessageListener;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
 import org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
@@ -21,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,15 +50,25 @@ public class OpenflowProtocolListenerFullImpl implements AlienMessageListener, O
 
     @Override
     public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("echo request received: {}", echoRequestMessage.getXid());
-        }
-        final EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
-        builder.setVersion(echoRequestMessage.getVersion());
-        builder.setXid(echoRequestMessage.getXid());
-        builder.setData(echoRequestMessage.getData());
-
-        connectionAdapter.echoReply(builder.build());
+        final var xid = echoRequestMessage.getXid();
+        LOG.debug("echo request received: {}", xid);
+        Futures.addCallback(connectionAdapter.echoReply(
+            new EchoReplyInputBuilder()
+                .setVersion(echoRequestMessage.getVersion())
+                .setXid(xid)
+                .setData(echoRequestMessage.getData())
+                .build()),
+            new FutureCallback<>() {
+                @Override
+                public void onSuccess(final RpcResult<EchoReplyOutput> result) {
+                    LOG.debug("echo reply sent: {}", xid);
+                }
+
+                @Override
+                public void onFailure(final Throwable cause) {
+                    LOG.debug("echo reply failed: {}", xid, cause);
+                }
+            }, MoreExecutors.directExecutor());
     }
 
     @Override
index d5114bb476e8000335ff14dcfb58b1789b02833f..7efa4e79561a1b9c3a9ad61b07627af1ac2f90d2 100644 (file)
@@ -7,13 +7,17 @@
  */
 package org.opendaylight.openflowplugin.impl.connection.listener;
 
-import org.junit.Assert;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.util.concurrent.Futures;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
-import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
@@ -29,7 +33,6 @@ import org.opendaylight.yangtools.yang.common.Uint32;
  */
 @RunWith(MockitoJUnitRunner.class)
 public class OpenflowProtocolListenerInitialImplTest {
-
     @Mock
     private ConnectionContext connectionContext;
     @Mock
@@ -43,23 +46,26 @@ public class OpenflowProtocolListenerInitialImplTest {
 
     @Before
     public void setUp() {
-        Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
-        Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
-        Mockito.when(connectionContext.getConnectionState())
+        when(connectionAdapter.isAlive()).thenReturn(true);
+        when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
+        when(connectionContext.getConnectionState())
                 .thenReturn(null, ConnectionContext.CONNECTION_STATE.HANDSHAKING);
-        Mockito.when(handshakeContext.getHandshakeManager()).thenReturn(handshakeManager);
+        when(handshakeContext.getHandshakeManager()).thenReturn(handshakeManager);
 
         openflowProtocolListenerInitial = new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
     }
 
     @Test
     public void testOnEchoRequestMessage() {
-        EchoRequestMessageBuilder echoRequestMessageBld = new EchoRequestMessageBuilder()
+        when(connectionAdapter.echoReply(any())).thenReturn(Futures.immediateFuture(null));
+
+        openflowProtocolListenerInitial.onEchoRequestMessage(
+            new EchoRequestMessageBuilder()
                 .setXid(Uint32.valueOf(42))
-                .setVersion(EncodeConstants.OF_VERSION_1_3);
-        openflowProtocolListenerInitial.onEchoRequestMessage(echoRequestMessageBld.build());
+                .setVersion(EncodeConstants.OF_VERSION_1_3)
+                .build());
 
-        Mockito.verify(connectionAdapter).echoReply(ArgumentMatchers.any());
+        verify(connectionAdapter).echoReply(any());
     }
 
     @Test
@@ -69,12 +75,12 @@ public class OpenflowProtocolListenerInitialImplTest {
                 .setVersion(EncodeConstants.OF_VERSION_1_3);
         openflowProtocolListenerInitial.onHelloMessage(helloMessageBld.build());
 
-        Mockito.verify(handshakeManager).shake(ArgumentMatchers.any());
+        verify(handshakeManager).shake(any());
     }
 
     @Test
     public void testCheckState() {
-        Assert.assertFalse(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
-        Assert.assertTrue(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
+        assertFalse(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
+        assertTrue(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
     }
 }
\ No newline at end of file
index effbf13bf8fa860c6b4237c4cbda84b1af711e59..dffd35320435d23479ac63b85fb3fb5cefd7d603 100644 (file)
@@ -25,6 +25,7 @@ import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter.SystemListener;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.DeviceConnectionStatusProvider;
 import org.opendaylight.openflowplugin.impl.connection.ConnectionContextImpl;
@@ -36,7 +37,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -63,7 +63,7 @@ public class SystemNotificationsListenerImplTest {
 
     private ConnectionContext connectionContext;
     private ConnectionContextImpl connectionContextGolem;
-    private SystemNotificationsListenerImpl systemNotificationsListener;
+    private SystemListener systemNotificationsListener;
 
     private static final NodeId NODE_ID =
             new NodeId("OFP:TEST");
@@ -100,7 +100,7 @@ public class SystemNotificationsListenerImplTest {
     public void testOnDisconnectEvent1() {
 
         DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
-        systemNotificationsListener.onDisconnectEvent(disconnectNotification);
+        systemNotificationsListener.onDisconnect(disconnectNotification);
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
@@ -114,8 +114,7 @@ public class SystemNotificationsListenerImplTest {
     @Test
     public void testOnDisconnectEvent2() {
 
-        DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
-        systemNotificationsListener.onDisconnectEvent(disconnectNotification);
+        systemNotificationsListener.onDisconnect(new DisconnectEventBuilder().setInfo("testing disconnect").build());
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
@@ -130,8 +129,7 @@ public class SystemNotificationsListenerImplTest {
     public void testOnDisconnectEvent3() {
         connectionContextGolem.changeStateToTimeouting();
 
-        DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
-        systemNotificationsListener.onDisconnectEvent(disconnectNotification);
+        systemNotificationsListener.onDisconnect(new DisconnectEventBuilder().setInfo("testing disconnect").build());
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
@@ -146,8 +144,7 @@ public class SystemNotificationsListenerImplTest {
     public void testOnDisconnectEvent4() {
         Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.RIP);
 
-        DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
-        systemNotificationsListener.onDisconnectEvent(disconnectNotification);
+        systemNotificationsListener.onDisconnect(new DisconnectEventBuilder().setInfo("testing disconnect").build());
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
@@ -165,8 +162,8 @@ public class SystemNotificationsListenerImplTest {
 
         Mockito.when(connectionAdapter.echo(any(EchoInput.class))).thenReturn(echoReply);
 
-        SwitchIdleEvent notification = new SwitchIdleEventBuilder().setInfo("wake up, device sleeps").build();
-        systemNotificationsListener.onSwitchIdleEvent(notification);
+        systemNotificationsListener.onSwitchIdle(
+            new SwitchIdleEventBuilder().setInfo("wake up, device sleeps").build());
 
         // make sure that the idle notification processing thread started
         Thread.sleep(SAFE_TIMEOUT);
@@ -189,8 +186,8 @@ public class SystemNotificationsListenerImplTest {
         Mockito.when(connectionAdapter.disconnect())
                 .thenReturn(Futures.immediateFailedFuture(new Exception("unit exception")));
 
-        SwitchIdleEvent notification = new SwitchIdleEventBuilder().setInfo("wake up, device sleeps").build();
-        systemNotificationsListener.onSwitchIdleEvent(notification);
+        systemNotificationsListener.onSwitchIdle(
+            new SwitchIdleEventBuilder().setInfo("wake up, device sleeps").build());
 
         Thread.sleep(SystemNotificationsListenerImpl.MAX_ECHO_REPLY_TIMEOUT + SAFE_TIMEOUT);
 
index ffe7362f6d9c027cb186715560ed1a00948d5e5a..2de02d448ef9364a17c4faca4a33493e5fa4df17 100644 (file)
@@ -8,21 +8,22 @@
 package org.opendaylight.openflowplugin.impl.device.listener;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
 
+import com.google.common.util.concurrent.Futures;
 import java.net.InetSocketAddress;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
-import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
@@ -48,9 +49,6 @@ import org.opendaylight.yangtools.yang.common.Uint32;
  */
 @RunWith(MockitoJUnitRunner.class)
 public class OpenflowProtocolListenerFullImplTest {
-
-    private OpenflowProtocolListenerFullImpl ofProtocolListener;
-
     @Mock
     private DeviceReplyProcessor deviceReplyProcessor;
     @Mock
@@ -58,19 +56,21 @@ public class OpenflowProtocolListenerFullImplTest {
 
     private final Uint32 xid = Uint32.valueOf(42);
 
+    private OpenflowProtocolListenerFullImpl ofProtocolListener;
+
     @Before
     public void setUp() {
         // place for mocking method's general behavior for HandshakeContext and ConnectionContext
         ofProtocolListener = new OpenflowProtocolListenerFullImpl(connectionAdapter, deviceReplyProcessor);
         connectionAdapter.setMessageListener(ofProtocolListener);
-        Mockito.when(connectionAdapter.getRemoteAddress())
+        when(connectionAdapter.getRemoteAddress())
                 .thenReturn(InetSocketAddress.createUnresolved("ofp-junit.example.org", 6663));
-        Mockito.verify(connectionAdapter).setMessageListener(any(OpenflowProtocolListener.class));
+        verify(connectionAdapter).setMessageListener(any(OpenflowProtocolListener.class));
     }
 
     @After
     public void tearDown() {
-        Mockito.verifyNoMoreInteractions(connectionAdapter, deviceReplyProcessor);
+        verifyNoMoreInteractions(connectionAdapter, deviceReplyProcessor);
     }
 
     /**
@@ -80,11 +80,11 @@ public class OpenflowProtocolListenerFullImplTest {
      */
     @Test
     public void testOnEchoRequestMessage() {
-        EchoRequestMessage echoRequestMessage = new EchoRequestMessageBuilder()
-                .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
-        ofProtocolListener.onEchoRequestMessage(echoRequestMessage);
+        when(connectionAdapter.echoReply(any())).thenReturn(Futures.immediateFuture(null));
+        ofProtocolListener.onEchoRequestMessage(
+            new EchoRequestMessageBuilder().setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build());
 
-        Mockito.verify(connectionAdapter).echoReply(any(EchoReplyInput.class));
+        verify(connectionAdapter).echoReply(any(EchoReplyInput.class));
     }
 
     /**
@@ -98,7 +98,7 @@ public class OpenflowProtocolListenerFullImplTest {
                 .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onErrorMessage(errorMessage);
 
-        Mockito.verify(deviceReplyProcessor).processReply(any(ErrorMessage.class));
+        verify(deviceReplyProcessor).processReply(any(ErrorMessage.class));
     }
 
     /**
@@ -112,7 +112,7 @@ public class OpenflowProtocolListenerFullImplTest {
                 .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onExperimenterMessage(experimenterMessage);
 
-        Mockito.verify(deviceReplyProcessor).processExperimenterMessage(ArgumentMatchers.any());
+        verify(deviceReplyProcessor).processExperimenterMessage(any());
     }
 
     /**
@@ -126,7 +126,7 @@ public class OpenflowProtocolListenerFullImplTest {
                 .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onFlowRemovedMessage(flowRemovedMessage);
 
-        Mockito.verify(deviceReplyProcessor).processFlowRemovedMessage(any(FlowRemovedMessage.class));
+        verify(deviceReplyProcessor).processFlowRemovedMessage(any(FlowRemovedMessage.class));
     }
 
     /**
@@ -140,8 +140,8 @@ public class OpenflowProtocolListenerFullImplTest {
                 .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onHelloMessage(helloMessage);
 
-        Mockito.verify(connectionAdapter).getRemoteAddress();
-        Mockito.verify(connectionAdapter).disconnect();
+        verify(connectionAdapter).getRemoteAddress();
+        verify(connectionAdapter).disconnect();
     }
 
     /**
@@ -155,7 +155,7 @@ public class OpenflowProtocolListenerFullImplTest {
                 .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onPacketInMessage(packetInMessage);
 
-        Mockito.verify(deviceReplyProcessor).processPacketInMessage(any(PacketInMessage.class));
+        verify(deviceReplyProcessor).processPacketInMessage(any(PacketInMessage.class));
     }
 
     /**
@@ -169,7 +169,6 @@ public class OpenflowProtocolListenerFullImplTest {
                 .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onPortStatusMessage(portStatusMessage);
 
-        Mockito.verify(deviceReplyProcessor).processPortStatusMessage(any(PortStatusMessage.class));
+        verify(deviceReplyProcessor).processPortStatusMessage(any(PortStatusMessage.class));
     }
-
 }