1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
2 package org.opendaylight.openflowjava.protocol.impl.core;
4 import io.netty.buffer.ByteBuf;
5 import io.netty.channel.ChannelHandlerContext;
6 import io.netty.handler.codec.ByteToMessageDecoder;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
14 * Class that detects version of used OpenFlow Protocol and engages right OFCodec into
17 * @author michal.polkorab
19 public class OFVersionDetector extends ByteToMessageDecoder {
21 /** Version number of OpenFlow 1.0 protocol */
22 public static final byte OF10_VERSION_ID = 0x01;
23 /** Version number of OpenFlow 1.3 protocol */
24 public static final byte OF13_VERSION_ID = 0x04;
25 private static final Logger LOGGER = LoggerFactory.getLogger(OFVersionDetector.class);
28 * Constructor of class.
30 public OFVersionDetector() {
31 LOGGER.debug("Creating OFVersionDetector");
35 protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {
36 if (bb.readableBytes() == 0) {
37 LOGGER.debug("not enough data");
41 LOGGER.debug("RI: " + bb.readerIndex());
42 byte version = bb.readByte();
44 if ((version == OF13_VERSION_ID) || (version == OF10_VERSION_ID)) {
45 LOGGER.debug("detected version: " + version);
47 LOGGER.warn("detected version: " + version + " - currently not supported");
48 bb.skipBytes(bb.readableBytes());
52 ByteBuf messageBuffer = bb.slice();
53 list.add(new VersionMessageWrapper(version, messageBuffer));
54 messageBuffer.retain();
55 bb.skipBytes(bb.readableBytes());