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 * Detects version of used OpenFlow Protocol and discards unsupported version messages
15 * @author michal.polkorab
17 public class OFVersionDetector extends ByteToMessageDecoder {
19 /** Version number of OpenFlow 1.0 protocol */
20 public static final byte OF10_VERSION_ID = 0x01;
21 /** Version number of OpenFlow 1.3 protocol */
22 public static final byte OF13_VERSION_ID = 0x04;
23 private static final Logger LOGGER = LoggerFactory.getLogger(OFVersionDetector.class);
26 * Constructor of class.
28 public OFVersionDetector() {
29 LOGGER.debug("Creating OFVersionDetector");
33 protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {
34 if (bb.readableBytes() == 0) {
35 LOGGER.debug("not enough data");
39 LOGGER.debug("RI: " + bb.readerIndex());
40 byte version = bb.readByte();
42 if ((version == OF13_VERSION_ID) || (version == OF10_VERSION_ID)) {
43 LOGGER.debug("detected version: " + version);
45 LOGGER.warn("detected version: " + version + " - currently not supported");
46 bb.skipBytes(bb.readableBytes());
50 ByteBuf messageBuffer = bb.slice();
51 list.add(new VersionMessageWrapper(version, messageBuffer));
52 messageBuffer.retain();
53 bb.skipBytes(bb.readableBytes());