Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / OFFrameDecoder.java
index 7e62347524b0a6f714d436b756d9564ae7311dc9..5c3b76167d70d5030ddfdf221a7c1f3340e90f79 100644 (file)
@@ -15,8 +15,8 @@ import io.netty.handler.codec.ByteToMessageDecoder;
 
 import java.util.List;
 
-import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionFacade;
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,14 +31,19 @@ public class OFFrameDecoder extends ByteToMessageDecoder {
     private static final byte LENGTH_INDEX_IN_HEADER = 2;
     private static final Logger LOGGER = LoggerFactory.getLogger(OFFrameDecoder.class);
     private ConnectionFacade connectionFacade;
-    private boolean started = false;
+    private boolean firstTlsPass = false;
 
     /**
      * Constructor of class.
-     * @param connectionFacade 
+     * @param connectionFacade  ConnectionFacade that will be notified
+     * with ConnectionReadyNotification after TLS has been successfully set up.
+     * @param tlsPresent true is TLS is required, false otherwise
      */
-    public OFFrameDecoder(ConnectionFacade connectionFacade) {
+    public OFFrameDecoder(ConnectionFacade connectionFacade, boolean tlsPresent) {
         LOGGER.trace("Creating OFFrameDecoder");
+        if (tlsPresent) {
+            firstTlsPass = true;
+        }
         this.connectionFacade = connectionFacade;
     }
 
@@ -55,28 +60,32 @@ public class OFFrameDecoder extends ByteToMessageDecoder {
 
     @Override
     protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {
-        if (!started) {
+        if (firstTlsPass) {
             connectionFacade.fireConnectionReadyNotification();
-            started = true;
+            firstTlsPass = false;
         }
         int readableBytes = bb.readableBytes();
         if (readableBytes < LENGTH_OF_HEADER) {
-            LOGGER.debug("skipping bytebuf - too few bytes for header: " + readableBytes + " < " + LENGTH_OF_HEADER );
-            LOGGER.debug("bb: " + ByteBufUtils.byteBufToHexString(bb));
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("skipping bytebuf - too few bytes for header: " + readableBytes + " < " + LENGTH_OF_HEADER );
+                LOGGER.debug("bb: " + ByteBufUtils.byteBufToHexString(bb));
+            }
             return;
         }
-        
+
         int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER);
         LOGGER.debug("length of actual message: {}", length);
-        
+
         if (readableBytes < length) {
+            if (LOGGER.isDebugEnabled()) {
                 LOGGER.debug("skipping bytebuf - too few bytes for msg: " +
                         readableBytes + " < " + length);
                 LOGGER.debug("bytebuffer: " + ByteBufUtils.byteBufToHexString(bb));
+            }
             return;
         }
         LOGGER.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1));
-        
+
         ByteBuf messageBuffer = bb.slice(bb.readerIndex(), length);
         list.add(messageBuffer);
         messageBuffer.retain();