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.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
15 * Detects version of used OpenFlow Protocol and discards unsupported version messages
16 * @author michal.polkorab
18 public class OFVersionDetector extends ByteToMessageDecoder {
20 /** Version number of OpenFlow 1.0 protocol */
21 private static final byte OF10_VERSION_ID = EncodeConstants.OF10_VERSION_ID;
22 /** Version number of OpenFlow 1.3 protocol */
23 private static final byte OF13_VERSION_ID = EncodeConstants.OF13_VERSION_ID;
24 private static final Logger LOGGER = LoggerFactory.getLogger(OFVersionDetector.class);
27 * Constructor of class.
29 public OFVersionDetector() {
30 LOGGER.debug("Creating OFVersionDetector");
34 protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {
35 if (bb.readableBytes() == 0) {
36 LOGGER.debug("not enough data");
40 LOGGER.debug("RI: " + bb.readerIndex());
41 byte version = bb.readByte();
43 if ((version == OF13_VERSION_ID) || (version == OF10_VERSION_ID)) {
44 LOGGER.debug("detected version: " + version);
46 LOGGER.warn("detected version: " + version + " - currently not supported");
47 bb.skipBytes(bb.readableBytes());
51 ByteBuf messageBuffer = bb.slice();
52 list.add(new VersionMessageWrapper(version, messageBuffer));
53 messageBuffer.retain();
54 bb.skipBytes(bb.readableBytes());