BUG-2429: Need to close the ODL Denial of Service interface 79/23279/1
authorMichal Rehak <mirehak@cisco.com>
Wed, 24 Jun 2015 14:47:21 +0000 (16:47 +0200)
committerMichal Rehak <mirehak@cisco.com>
Thu, 25 Jun 2015 15:01:18 +0000 (17:01 +0200)
 - added hsContext close action to connectionContext

Change-Id: I93d92951450f6a7af366d75ce985f1076b977d3f
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/connection/ConnectionContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java

index 695a206caed662ce27d09b95f50b146a56916fa4..32c7d636866ebd2160b5677f586c646d2199783c 100644 (file)
@@ -24,6 +24,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */
 public interface ConnectionContext {
 
+    /**
+     * @param handshakeContext corresponding handshake context used upon this connection
+     */
+    void setHandshakeContext(HandshakeContext handshakeContext);
+
     /**
      * distinguished connection states
      */
index cbd5d0440ef293330f05aca3f114c7f5a4a65af7..bbc58a8c273b6f9aa89d855d09b2cbd21f94ddbd 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
@@ -34,6 +35,7 @@ public class ConnectionContextImpl implements ConnectionContext {
     private static final Logger LOG = LoggerFactory.getLogger(ConnectionContextImpl.class);
     private OutboundQueueProvider outboundQueueProvider;
     private OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration;
+    private HandshakeContext handshakeContext;
 
     /**
      * @param connectionAdapter
@@ -100,6 +102,8 @@ public class ConnectionContextImpl implements ConnectionContext {
         connectionState = ConnectionContext.CONNECTION_STATE.RIP;
 
         unregisterOutboundQueue();
+        closeHandshakeContext();
+
         if (getConnectionAdapter().isAlive()) {
             getConnectionAdapter().disconnect();
         }
@@ -109,6 +113,18 @@ public class ConnectionContextImpl implements ConnectionContext {
         }
     }
 
+    private void closeHandshakeContext() {
+        if (handshakeContext != null) {
+            try {
+                handshakeContext.close();
+            } catch (Exception e) {
+                LOG.info("handshake context closing failed: ", e);
+            } finally {
+                handshakeContext = null;
+            }
+        }
+    }
+
     @Override
     public void onConnectionClosed() {
         if (null == nodeId){
@@ -132,7 +148,7 @@ public class ConnectionContextImpl implements ConnectionContext {
                 getConnectionState());
 
         unregisterOutboundQueue();
-
+        closeHandshakeContext();
         propagateDeviceDisconnectedEvent();
     }
 
@@ -171,4 +187,9 @@ public class ConnectionContextImpl implements ConnectionContext {
     public void changeStateToWorking() {
         connectionState = CONNECTION_STATE.WORKING;
     }
+
+    @Override
+    public void setHandshakeContext(HandshakeContext handshakeContext) {
+        this.handshakeContext = handshakeContext;
+    }
 }
index 70f23afdb4947a1ac8c95a4341be62149f45b55e..907afb6c0d88cd0b0b85204963e785b358c93631 100644 (file)
@@ -60,6 +60,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
         LOG.trace("prepare handshake context");
         HandshakeContext handshakeContext = new HandshakeContextImpl(handshakePool, handshakeManager);
         handshakeListener.setHandshakeContext(handshakeContext);
+        connectionContext.setHandshakeContext(handshakeContext);
 
         LOG.trace("prepare connection listeners");
         final ConnectionReadyListener connectionReadyListener = new ConnectionReadyListenerImpl(