Merge "Bug-5551:Audit of Connection Events"
authormichal rehak <mirehak@cisco.com>
Thu, 24 Mar 2016 09:38:37 +0000 (09:38 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 24 Mar 2016 09:38:37 +0000 (09:38 +0000)
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java

index ebb03b889fbad2b1879a7d527d5117adbfcedfcc..2cd648acf5810ed4a172747dfb2f34297f56c491 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.impl.connection.listener;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import java.net.InetSocketAddress;
+import java.util.Date;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
@@ -44,6 +45,8 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
 
     @Override
     public void onDisconnectEvent(final DisconnectEvent notification) {
+        LOG.info("ConnectionEvent: Connection closed by device, Device:{}, NodeId:{}",
+                connectionContext.getConnectionAdapter().getRemoteAddress(), connectionContext.getNodeId());
         connectionContext.onConnectionClosed();
     }
 
@@ -97,6 +100,11 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
                     }
                 }
                 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.getNodeId());
+                    }
+
                     connectionContext.closeConnection(true);
                 }
             }
index 3aed9d60b670a4e2e8c558784846cf5e5875abf4..7a6889f763f5fa0ca2e735708029e3df4fa2409e 100644 (file)
@@ -601,6 +601,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
 
     @Override
     public void onDeviceDisconnected(final ConnectionContext connectionContext) {
+        LOG.info("ConnectionEvent: Device disconnected from controller, Device:{}, NodeId:{}",
+                connectionContext.getConnectionAdapter().getRemoteAddress(), connectionContext.getNodeId());
         if (getPrimaryConnectionContext().equals(connectionContext)) {
             try {
                 tearDown();
index 5742453758ac93079dda72473db0d0f62dc10323..8942ef3e7301080c649d518c05b3dab5e868749c 100644 (file)
@@ -124,7 +124,8 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 "Rejecting connection from node which is already connected and there exist deviceContext for it: {}",
                 connectionContext.getNodeId()
         );
-        LOG.info("Initializing New Connection DeviceContext for node:{}", connectionContext.getNodeId());
+        LOG.info("ConnectionEvent: Device connected to controller, Device:{}, NodeId:{}",
+                connectionContext.getConnectionAdapter().getRemoteAddress(), connectionContext.getNodeId());
 
         // Cache this for clarity
         final ConnectionAdapter connectionAdapter = connectionContext.getConnectionAdapter();
index 84fbd22b60b9848ffccafa64f7b985805311a36d..a361d61ac9ca60eeda8a1d0ea438a5ec88f60382 100644 (file)
@@ -56,10 +56,11 @@ public class SystemNotificationsListenerImplTest {
         connectionContextGolem = new ConnectionContextImpl(connectionAdapter);
         connectionContextGolem.changeStateToWorking();
         connectionContextGolem.setNodeId(nodeId);
+        connectionContext = Mockito.spy(connectionContextGolem);
 
         Mockito.when(connectionAdapter.getRemoteAddress()).thenReturn(
                 InetSocketAddress.createUnresolved("unit-odl.example.org", 4242));
-        connectionContext = Mockito.spy(connectionContextGolem);
+
         Mockito.when(features.getAuxiliaryId()).thenReturn((short) 0);
 
         Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
@@ -88,6 +89,8 @@ public class SystemNotificationsListenerImplTest {
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
+        Mockito.verify(connectionContext).getConnectionAdapter();
+        Mockito.verify(connectionContext).getNodeId();
     }
 
     /**
@@ -105,6 +108,8 @@ public class SystemNotificationsListenerImplTest {
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
+        Mockito.verify(connectionContext).getConnectionAdapter();
+        Mockito.verify(connectionContext).getNodeId();
     }
 
     /**
@@ -124,6 +129,8 @@ public class SystemNotificationsListenerImplTest {
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
+        Mockito.verify(connectionContext).getConnectionAdapter();
+        Mockito.verify(connectionContext).getNodeId();
     }
 
     /**
@@ -141,6 +148,8 @@ public class SystemNotificationsListenerImplTest {
 
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
+        Mockito.verify(connectionContext).getConnectionAdapter();
+        Mockito.verify(connectionContext).getNodeId();
     }
 
     /**
@@ -190,6 +199,8 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionAdapter).disconnect();
         Mockito.verify(connectionContext).changeStateToTimeouting();
         Mockito.verify(connectionContext).closeConnection(true);
+        Mockito.verify(connectionContext).getNodeId();
+
     }
 
     private void verifyCommonInvocations() {