BUG-3579: device disconnection cleanup
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / listener / HandshakeListenerImpl.java
index fdb1c27f267663a20b4c9071a8bccb6fcb0c70ef..2f1261e79952e7c3596f53bc48b2ef2264b4cf81 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
+ * <p/>
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -38,7 +38,9 @@ public class HandshakeListenerImpl implements HandshakeListener {
 
     @Override
     public void onHandshakeSuccessfull(GetFeaturesOutput featureOutput, Short version) {
-        connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.WORKING);
+        LOG.debug("handshake succeeded: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
+        closeHandshakeContext();
+        connectionContext.changeStateToWorking();
         connectionContext.setFeatures(featureOutput);
         connectionContext.setNodeId(InventoryDataServiceUtil.nodeIdFromDatapathId(featureOutput.getDatapathId()));
         deviceConnectedHandler.deviceConnected(connectionContext);
@@ -46,8 +48,12 @@ public class HandshakeListenerImpl implements HandshakeListener {
 
     @Override
     public void onHandshakeFailure() {
-        LOG.info("handshake failed: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
-        connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
+        LOG.debug("handshake failed: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
+        closeHandshakeContext();
+        connectionContext.closeConnection(false);
+    }
+
+    private void closeHandshakeContext() {
         try {
             handshakeContext.close();
         } catch (Exception e) {