java_gen: small improvements to gen_table/tlv extensions

 - move bsntlv classes to dedicated package/factory
 - change type of of_bsn_tlv_vlan_vid to VlanVid
 - change type of tableId to new typesafe constant GenTableId
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index c4e4ea5..6f86706 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -209,7 +209,7 @@
 
         factories = OrderedDict()
 
-        sub_factory_classes = ("OFAction", "OFInstruction", "OFMeterBand", "OFOxm", "OFQueueProp", "OFErrorMsg", "OFActionId", "OFInstructionId")
+        sub_factory_classes = ("OFAction", "OFInstruction", "OFMeterBand", "OFOxm", "OFQueueProp", "OFErrorMsg", "OFActionId", "OFInstructionId", "OFBsnTlv")
         for base_class in sub_factory_classes:
             package = base_class[2:].lower()
             remove_prefix = base_class[2].lower() + base_class[3:]
@@ -521,7 +521,7 @@
         elif loxi_utils.class_is_table_feature_prop(self.c_name):
             return ("", "OFTableFeatureProp", None)
         elif loxi_utils.class_is_bsn_tlv(self.c_name):
-            return ("", "OFBsnTlv", None)
+            return ("bsntlv", "OFBsnTlv", None)
         else:
             return ("", None, None)
 
diff --git a/java_gen/java_type.py b/java_gen/java_type.py
index ac1e672..87cd6e8 100644
--- a/java_gen/java_type.py
+++ b/java_gen/java_type.py
@@ -484,6 +484,10 @@
         .op(read='OFChecksum128.read16Bytes(bb)',
             write='$name.write16Bytes(bb)',
             default='OFChecksum128.ZERO')
+gen_table_id = JType("GenTableId") \
+        .op(read='GenTableId.read2Bytes(bb)',
+            write='$name.write2Bytes(bb)',
+           )
 
 generic_t = JType("T")
 
@@ -624,6 +628,9 @@
         'of_group_delete' : { 'command' : group_mod_cmd },
 
         'of_bucket' : { 'watch_group': of_group },
+
+        'of_bsn_tlv_vlan_vid' : { 'value' : vlan_vid },
+        'of_bsn_gentable_entry_add' : { 'table_id' : gen_table_id },
 }
 
 
@@ -682,6 +689,8 @@
         return datapath_id
     elif field_name == 'actions' and obj_name == 'of_features_reply':
         return action_type_set
+    elif field_name == "table_id" and re.match(r'of_bsn_gentable.*', obj_name):
+        return gen_table_id
     elif c_type in default_mtype_to_jtype_convert_map:
         return default_mtype_to_jtype_convert_map[c_type]
     elif re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type):
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/GenTableId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/GenTableId.java
new file mode 100644
index 0000000..cfa7cdf
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/GenTableId.java
@@ -0,0 +1,93 @@
+package org.projectfloodlight.openflow.types;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.projectfloodlight.openflow.exceptions.OFParseError;
+
+import com.google.common.hash.PrimitiveSink;
+import com.google.common.primitives.UnsignedInts;
+
+public class GenTableId implements OFValueType<GenTableId>, Comparable<GenTableId> {
+    final static int LENGTH = 2;
+
+    private static final int VALIDATION_MASK = 0xFFFF;
+
+    private static final int ALL_VAL = 0xFFFF;
+    private static final int NONE_VAL = 0x0000;
+    public static final GenTableId NONE = new GenTableId(NONE_VAL);
+
+    public static final GenTableId ALL = new GenTableId(ALL_VAL);
+    public static final GenTableId ZERO = NONE;
+
+    private final int id;
+
+    private GenTableId(int id) {
+        this.id = id;
+    }
+
+    public static GenTableId of(int id) {
+        switch(id) {
+            case NONE_VAL:
+                return NONE;
+            case ALL_VAL:
+                return ALL;
+            default:
+                if ((id & VALIDATION_MASK) != id)
+                    throw new IllegalArgumentException("Illegal Table id value: " + id);
+                return new GenTableId(id);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "0x" + Integer.toHexString(id);
+    }
+
+    public int getValue() {
+        return id;
+    }
+
+    @Override
+    public int getLength() {
+        return LENGTH;
+    }
+
+    public void write2Bytes(ChannelBuffer c) {
+        c.writeShort(this.id);
+    }
+
+    public static GenTableId read2Bytes(ChannelBuffer c) throws OFParseError {
+        return GenTableId.of(c.readUnsignedShort());
+    }
+
+    @Override
+    public GenTableId applyMask(GenTableId mask) {
+        return GenTableId.of(this.id & mask.id);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof GenTableId))
+            return false;
+        GenTableId other = (GenTableId)obj;
+        if (other.id != this.id)
+            return false;
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int prime = 13873;
+        return this.id * prime;
+    }
+
+    @Override
+    public int compareTo(GenTableId other) {
+        return UnsignedInts.compare(this.id, other.id);
+    }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort((byte) id);
+    }
+
+}
diff --git a/java_gen/templates/_imports.java b/java_gen/templates/_imports.java
index 498d2f9..0c95916 100644
--- a/java_gen/templates/_imports.java
+++ b/java_gen/templates/_imports.java
@@ -8,6 +8,7 @@
 import org.projectfloodlight.openflow.protocol.*;
 import org.projectfloodlight.openflow.protocol.action.*;
 import org.projectfloodlight.openflow.protocol.actionid.*;
+import org.projectfloodlight.openflow.protocol.bsntlv.*;
 import org.projectfloodlight.openflow.protocol.errormsg.*;
 import org.projectfloodlight.openflow.protocol.meterband.*;
 import org.projectfloodlight.openflow.protocol.instruction.*;