Allow any hello mesage and extend hello support for v1.4, v1.5
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / OFVersionDetector.java
index b635ef2567610076a3b982db2dfb688ed387f209..8e23566af1fef8bf5fda007668787aff26c58f97 100644 (file)
@@ -11,6 +11,8 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 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;
@@ -19,23 +21,20 @@ import org.slf4j.Logger;
 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();
@@ -54,9 +53,10 @@ public class OFVersionDetector extends ByteToMessageDecoder {
         }
 
         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();
@@ -69,4 +69,5 @@ public class OFVersionDetector extends ByteToMessageDecoder {
         }
         in.skipBytes(in.readableBytes());
     }
+
 }