Copyright update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / TlsDetector.java
index 3edf5068f91621dc0767863096f172aedcadf1a7..93b296d0f2461f514d7ac3851a21d77fe3f2e14d 100644 (file)
@@ -1,4 +1,11 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * 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
+ */
+
 package org.opendaylight.openflowjava.protocol.impl.core;
 
 import io.netty.buffer.ByteBuf;
@@ -13,6 +20,7 @@ import javax.net.ssl.SSLEngine;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionFacade;
 import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;
 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
 
@@ -28,12 +36,14 @@ public class TlsDetector extends ByteToMessageDecoder {
     private boolean detectSsl;
     private static final Logger LOGGER = LoggerFactory
             .getLogger(TlsDetector.class);
+    
+    private ConnectionFacade connectionFacade;
 
     /**
      * Constructor of class
      */
     public TlsDetector() {
-        LOGGER.info("Creating TLS Detector");
+        LOGGER.debug("Creating TLS Detector");
         detectSsl = true;
     }
 
@@ -59,21 +69,11 @@ public class TlsDetector extends ByteToMessageDecoder {
             SSLEngine engine = SslContextFactory.getServerContext()
                     .createSSLEngine();
             engine.setUseClientMode(false);
-            p.addBefore(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), COMPONENT_NAMES.SSL_HANDLER.name(),
+            p.addAfter(COMPONENT_NAMES.TLS_DETECTOR.name(), COMPONENT_NAMES.SSL_HANDLER.name(),
                     new SslHandler(engine));
         }
     }
 
-    private static void enableOFFrameDecoder(ChannelHandlerContext ctx) {
-        ChannelPipeline p = ctx.channel().pipeline();
-        if (p.get(COMPONENT_NAMES.OF_FRAME_DECODER.name()) == null) {
-            LOGGER.debug("Engaging OFFrameDecoder");
-            p.addBefore(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), COMPONENT_NAMES.OF_FRAME_DECODER.name(), new OFFrameDecoder());
-        } else {
-            LOGGER.debug("OFFD already in pipeline");
-        }
-    }
-
     @Override
     protected void decode(ChannelHandlerContext ctx, ByteBuf bb,
             List<Object> list) throws Exception {
@@ -89,7 +89,19 @@ public class TlsDetector extends ByteToMessageDecoder {
         } else {
             LOGGER.info("Connection is not encrypted");
         }
-        enableOFFrameDecoder(ctx);
+        
+        if (connectionFacade != null) {
+            LOGGER.debug("Firing onConnectionReady notification");
+            connectionFacade.fireConnectionReadyNotification();
+        }
+        
         ctx.pipeline().remove(COMPONENT_NAMES.TLS_DETECTOR.name());
     }
+    
+    /**
+     * @param connectionFacade the connectionFacade to set
+     */
+    public void setConnectionFacade(ConnectionFacade connectionFacade) {
+        this.connectionFacade = connectionFacade;
+    }
 }