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=5c3b76167d70d5030ddfdf221a7c1f3340e90f79;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=300e3373bd0bd7873925eeabf065903014e6d349;hpb=5b05fc8e7dd2b61a076dfd1864a205b0995c7722;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 300e3373..5c3b7616 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 @@ -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; @@ -8,6 +15,8 @@ import io.netty.handler.codec.ByteToMessageDecoder; import java.util.List; +import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade; +import org.opendaylight.openflowjava.util.ByteBufUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,34 +30,61 @@ public class OFFrameDecoder extends ByteToMessageDecoder { 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 ConnectionFacade connectionFacade; + private boolean firstTlsPass = false; /** * Constructor of class. + * @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() { - LOGGER.debug("Creating OFFrameDecoder"); + public OFFrameDecoder(ConnectionFacade connectionFacade, boolean tlsPresent) { + LOGGER.trace("Creating OFFrameDecoder"); + if (tlsPresent) { + firstTlsPass = true; + } + this.connectionFacade = connectionFacade; } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - LOGGER.warn("Unexpected exception from downstream.", cause); + if (cause instanceof io.netty.handler.ssl.NotSslRecordException) { + LOGGER.warn("Not an TLS record exception - please verify TLS configuration."); + } else { + LOGGER.warn("Unexpected exception from downstream.", cause); + } + LOGGER.warn("Closing connection."); ctx.close(); } @Override protected void decode(ChannelHandlerContext chc, ByteBuf bb, List list) throws Exception { - if (bb.readableBytes() < LENGTH_OF_HEADER) { - LOGGER.debug("skipping bb - too few data for header: " + bb.readableBytes()); + if (firstTlsPass) { + connectionFacade.fireConnectionReadyNotification(); + firstTlsPass = false; + } + int readableBytes = bb.readableBytes(); + if (readableBytes < LENGTH_OF_HEADER) { + 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(LENGTH_INDEX_IN_HEADER); - if (bb.readableBytes() < length) { - LOGGER.debug("skipping bb - too few data for msg: " + - bb.readableBytes() + " < " + length); + 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.info("OF Protocol message received, type:{}", bb.getByte(1)); + LOGGER.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1)); ByteBuf messageBuffer = bb.slice(bb.readerIndex(), length); list.add(messageBuffer);