X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fcore%2FOFFrameDecoder.java;h=735070fa0c0017684b6d37c95207446d5b3a2d06;hb=0b153ce18153b71fc7e5bb6de5338d5dbaf9b1a1;hp=7e62347524b0a6f714d436b756d9564ae7311dc9;hpb=10b9c3569a636b73a7dcfb88a55864df46455560;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java index 7e623475..735070fa 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java @@ -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; @@ -29,54 +29,62 @@ public class OFFrameDecoder extends ByteToMessageDecoder { /** Length of OpenFlow 1.3 header */ public static final byte LENGTH_OF_HEADER = 8; private static final byte LENGTH_INDEX_IN_HEADER = 2; - private static final Logger LOGGER = LoggerFactory.getLogger(OFFrameDecoder.class); + private static final Logger LOG = 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) { - LOGGER.trace("Creating OFFrameDecoder"); + public OFFrameDecoder(ConnectionFacade connectionFacade, boolean tlsPresent) { + LOG.trace("Creating OFFrameDecoder"); + if (tlsPresent) { + firstTlsPass = true; + } this.connectionFacade = connectionFacade; } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof io.netty.handler.ssl.NotSslRecordException) { - LOGGER.warn("Not an TLS record exception - please verify TLS configuration."); + LOG.warn("Not an TLS record exception - please verify TLS configuration."); } else { - LOGGER.warn("Unexpected exception from downstream.", cause); + LOG.warn("Unexpected exception from downstream.", cause); } - LOGGER.warn("Closing connection."); + LOG.warn("Closing connection."); ctx.close(); } @Override protected void decode(ChannelHandlerContext chc, ByteBuf bb, List 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 (LOG.isDebugEnabled()) { + LOG.debug("skipping bytebuf - too few bytes for header: {} < {}", readableBytes, LENGTH_OF_HEADER); + LOG.debug("bb: {}", ByteBufUtils.byteBufToHexString(bb)); + } return; } - + int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER); - LOGGER.debug("length of actual message: {}", length); - + LOG.debug("length of actual message: {}", length); + if (readableBytes < length) { - LOGGER.debug("skipping bytebuf - too few bytes for msg: " + - readableBytes + " < " + length); - LOGGER.debug("bytebuffer: " + ByteBufUtils.byteBufToHexString(bb)); + if (LOG.isDebugEnabled()) { + LOG.debug("skipping bytebuf - too few bytes for msg: {} < {}", readableBytes, length); + LOG.debug("bytebuffer: {}", ByteBufUtils.byteBufToHexString(bb)); + } return; } - LOGGER.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1)); - + LOG.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1)); + ByteBuf messageBuffer = bb.slice(bb.readerIndex(), length); list.add(messageBuffer); messageBuffer.retain();