Merge "Bug 8535: Fix IPv6 OXMHeader Mask issue"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / listener / OpenflowProtocolListenerInitialImpl.java
index a69696a6734d0d06753aa2c8ed2055af1fefa231..fb6cdcb0282033028ac05529287a3b2b4244edb7 100644 (file)
@@ -46,7 +46,9 @@ public class OpenflowProtocolListenerInitialImpl implements OpenflowProtocolList
 
     @Override
     public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
-        LOG.debug("echo request received: {}", echoRequestMessage.getXid());
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("echo request received: {}", echoRequestMessage.getXid());
+        }
         EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
         builder.setVersion(echoRequestMessage.getVersion());
         builder.setXid(echoRequestMessage.getXid());
@@ -57,52 +59,63 @@ public class OpenflowProtocolListenerInitialImpl implements OpenflowProtocolList
 
     @Override
     public void onErrorMessage(final ErrorMessage notification) {
-        // TODO: log
+        LOG.debug("NOOP: Error message received during handshake phase: {}", notification);
     }
 
     @Override
     public void onExperimenterMessage(final ExperimenterMessage notification) {
-        // NOOP
-
+        LOG.debug("NOOP: Experimenter message during handshake phase not supported: {}", notification);
     }
 
     @Override
     public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
-        // NOOP
+        LOG.debug("NOOP: Flow-removed message during handshake phase not supported: {}", notification);
     }
 
     @Override
     public void onHelloMessage(final HelloMessage hello) {
-        LOG.debug("processing HELLO.xid: {}", hello.getXid());
-        if (connectionContext.getConnectionState() == null) {
-            connectionContext.setConnectionState(ConnectionContext.CONNECTION_STATE.HANDSHAKING);
-        }
-
-        if (checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING)) {
-            final HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(
-                    hello, handshakeContext.getHandshakeManager(), connectionContext.getConnectionAdapter());
-            //handshakeContext.getHandshakePool().submit(handshakeStepWrapper);
-            // use up netty thread
-            handshakeStepWrapper.run();
+        LOG.debug("processing HELLO.xid: {} from device {}", hello.getXid(),
+                connectionContext.getConnectionAdapter().getRemoteAddress());
+        final ConnectionContext.CONNECTION_STATE connectionState = connectionContext.getConnectionState();
+        if (connectionState == null
+                || ConnectionContext.CONNECTION_STATE.HANDSHAKING.equals(connectionState)) {
+            synchronized (connectionContext) {
+                if (connectionContext.getConnectionState() == null) {
+                    // got here before connection ready notification
+                    connectionContext.changeStateToHandshaking();
+                }
+
+                if (checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING)) {
+                    final HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(
+                            hello, handshakeContext.getHandshakeManager(), connectionContext.getConnectionAdapter());
+                    // use up netty thread
+                    handshakeStepWrapper.run();
+                } else {
+                    LOG.debug("already out of handshake phase but still received hello message from device {}",
+                            connectionContext.getConnectionAdapter().getRemoteAddress());
+                }
+            }
         } else {
             //TODO: consider disconnecting of bad behaving device
+            LOG.warn("Hello message received outside handshake phase:{} ", hello);
+            LOG.debug("already touched by onConnectionReady event from device {} (or finished handshake)",
+                    connectionContext.getConnectionAdapter().getRemoteAddress());
         }
-
     }
 
     @Override
     public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
-        // NOOP
+        LOG.debug("NOOP: Multipart-reply message during handshake phase not supported: {}", notification);
     }
 
     @Override
     public void onPacketInMessage(final PacketInMessage notification) {
-        // NOOP
+        LOG.debug("NOOP: Packet-in message during handshake phase not supported: {}", notification);
     }
 
     @Override
     public void onPortStatusMessage(final PortStatusMessage notification) {
-        // NOOP
+        connectionContext.handlePortStatusMessage(notification);
     }
 
     /**