import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
import org.opendaylight.openflowjava.statistics.CounterEventTypes;
import org.slf4j.LoggerFactory;
/**
- * Detects version of used OpenFlow Protocol and discards unsupported version messages
+ * Detects version of used OpenFlow Protocol and discards unsupported version messages.
* @author michal.polkorab
*/
public class OFVersionDetector extends ByteToMessageDecoder {
- /** Version number of OpenFlow 1.0 protocol */
- private static final byte OF10_VERSION_ID = EncodeConstants.OF10_VERSION_ID;
- /** Version number of OpenFlow 1.3 protocol */
- private static final byte OF13_VERSION_ID = EncodeConstants.OF13_VERSION_ID;
- private static final short OF_PACKETIN = 10;
private static final Logger LOG = LoggerFactory.getLogger(OFVersionDetector.class);
+ /** IDs of accepted OpenFlow protocol versions */
+ private static final List<Byte> OF_VERSIONS = new ArrayList<>(Arrays.asList(
+ EncodeConstants.OF10_VERSION_ID,
+ EncodeConstants.OF13_VERSION_ID
+ ));
private final StatisticsCounters statisticsCounters;
private volatile boolean filterPacketIns;
- /**
- * Constructor of class.
- */
public OFVersionDetector() {
LOG.trace("Creating OFVersionDetector");
statisticsCounters = StatisticsCounters.getInstance();
}
final byte version = in.readByte();
- if (version == OF13_VERSION_ID || version == OF10_VERSION_ID) {
+ final short messageType = in.getUnsignedByte(in.readerIndex());
+ if (messageType == EncodeConstants.OF_HELLO_MESSAGE_TYPE_VALUE || OF_VERSIONS.contains(version)) {
LOG.debug("detected version: {}", version);
- if (!filterPacketIns || OF_PACKETIN != in.getUnsignedByte(in.readerIndex())) {
+ if (!filterPacketIns || EncodeConstants.OF_PACKETIN_MESSAGE_TYPE_VALUE != messageType) {
ByteBuf messageBuffer = in.slice();
out.add(new VersionMessageWrapper(version, messageBuffer));
messageBuffer.retain();
}
in.skipBytes(in.readableBytes());
}
+
}