Fix connection closing on switch IDLE state
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / DeviceManagerImpl.java
index 9ace923392f8e6bc4b3ae4888a7f70becc8abbdd..c55970b3187d8ffa75df6f972266759afd3c465e 100644 (file)
@@ -301,6 +301,14 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
             return;
         }
 
+        if (!connectionContext.equals(deviceCtx.getPrimaryConnectionContext())) {
+            LOG.debug("Node {} disconnected, but not primary connection.", connectionContext.getDeviceInfo().getLOGValue());
+            // Connection is not PrimaryConnection so try to remove from Auxiliary Connections
+            deviceCtx.removeAuxiliaryConnectionContext(connectionContext);
+            // If this is not primary connection, we should not continue disabling everything
+            return;
+        }
+
         if (deviceCtx.getState().equals(OFPContext.CONTEXT_STATE.TERMINATION)) {
             LOG.info("Device context for node {} is already is termination state, waiting for close all context", deviceInfo.getLOGValue());
             return;
@@ -308,12 +316,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
 
         deviceCtx.close();
 
-        if (!connectionContext.equals(deviceCtx.getPrimaryConnectionContext())) {
-            LOG.debug("Node {} disconnected, but not primary connection.", connectionContext.getDeviceInfo().getLOGValue());
-            // Connection is not PrimaryConnection so try to remove from Auxiliary Connections
-            deviceCtx.removeAuxiliaryConnectionContext(connectionContext);
-        }
-
         // TODO: Auxiliary connections supported ?
         // Device is disconnected and so we need to close TxManager
         final ListenableFuture<Void> future = deviceCtx.shuttingDownDataStoreTransactions();