openflow_input: add bsn_gentable extension and tests

See the documentation in openflow_input/bsn_gentable.
diff --git a/openflow_input/bsn_gentable b/openflow_input/bsn_gentable
new file mode 100644
index 0000000..3643418
--- /dev/null
+++ b/openflow_input/bsn_gentable
@@ -0,0 +1,350 @@
+// Copyright 2013, Big Switch Networks, Inc.
+//
+// LoxiGen is licensed under the Eclipse Public License,
+// version 1.0 (EPL), with the following special exception:
+//
+// LOXI Exception
+//
+// As a special exception to the terms of the EPL, you may
+// distribute libraries generated by LoxiGen (LoxiGen Libraries)
+// under the terms of your choice, provided that copyright and
+// licensing notices generated by LoxiGen are not altered or removed
+// from the LoxiGen Libraries and the notice provided below is (i)
+// included in the LoxiGen Libraries, if distributed in source code
+// form and (ii) included in any documentation for the LoxiGen
+// Libraries, if distributed in binary form.
+//
+// Notice: "Copyright 2013, Big Switch Networks, Inc.
+// This library was generated by the LoxiGen Compiler."
+//
+// You may not use this file except in compliance with the EPL or
+// LOXI Exception. You may obtain a copy of the EPL at:
+//
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an "AS
+// IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. See the EPL for the specific language
+// governing permissions and limitations under the EPL.
+
+#version 4
+
+// We have a number of switch agents that need to be configured by the
+// controller and report stats. Some of them will have large tables (1000+
+// entries) and so need an efficient synchronization mechanism (as can be
+// accomplished using the cookie field in flowtable entries). It's a
+// significant amount of work to do this from scratch for each new table.
+// This extension (and the corresponding Indigo code) provides a framework
+// to ease implementing new tables.
+
+// We don't plan on replacing our use of the OpenFlow flow table and group
+// table with this scheme. This is intended for controlling switch
+// functionality like the ARP and LACP agents which don't map at all to
+// flow-mods.
+
+// Each switch will have a number of tables indexed by a 16-bit table ID. Each
+// table has a name, id, a set of entries, and an array of checksum buckets.
+// There is no order to the entries; stats requests will return them in an
+// arbitrary order. The controller is expected to use the table name to
+// determine the semantics of a table.
+
+// Each entry has a key, value, stats, and checksum. The key and value are TLV
+// lists given by the controller in a gentable_entry_add message. The switch must
+// return these lists in stats replies exactly as it received them. The stats
+// are a list of TLVs controlled by the switch. The stats are expected to
+// include more than simple counters (for example, last hit time or seen TCP
+// flags). The checksum is an opaque value used for table synchronization.
+
+// LOXI includes a built-in type of_checksum_128_t, which is 128 bits but
+// only requires 32-bit alignment.
+
+
+// These TLV classes are used for keys, values, and stats. Like OXM, lists of
+// TLVs are tightly packed without padding. TLV lists may include duplicates
+// and the semantics of this is left to the particular table.
+//
+// If this is eventually standardized it would be good to add a "class" type
+// member as in OXM.
+struct of_bsn_tlv {
+    uint16_t type == ?;
+    uint16_t length;
+};
+
+
+// This message sets key=value in the given table. If key already exists in the
+// table then it modifies the value, preserving stats.
+//
+// If the switch cannot process the message then it should reply with an error
+// message. The contents of the table must not be changed in case of an error.
+struct of_bsn_gentable_entry_add : of_bsn_header {
+    uint8_t version;
+    uint8_t type == 4;
+    uint16_t length;
+    uint32_t xid;
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 46;
+    uint16_t table_id;
+    uint16_t key_length;
+    of_checksum_128_t checksum;
+    list(of_bsn_tlv_t) key;
+    list(of_bsn_tlv_t) value;
+};
+
+
+// This message deletes the entry with the given key in the given table.
+//
+// If the switch cannot process the message then it should reply with an error
+// message. The contents of the table must not be changed in case of an error.
+struct of_bsn_gentable_entry_delete : of_bsn_header {
+    uint8_t version;
+    uint8_t type == 4;
+    uint16_t length;
+    uint32_t xid;
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 47;
+    uint16_t table_id;
+    list(of_bsn_tlv_t) key;
+};
+
+
+// This message deletes a range of table entries. The checksum_mask must be a
+// prefix mask. The checksum must be zero in the bits where the checksum_mask
+// is zero.
+//
+// The switch may fail to delete some table entries. No error messages will be
+// sent, but the error_count in the reply message will be incremented.
+struct of_bsn_gentable_clear_request : of_bsn_header {
+    uint8_t version;
+    uint8_t type == 4;
+    uint16_t length;
+    uint32_t xid;
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 48;
+    uint16_t table_id;
+    pad(2);
+    of_checksum_128_t checksum;
+    of_checksum_128_t checksum_mask;
+};
+
+struct of_bsn_gentable_clear_reply : of_bsn_header {
+    uint8_t version;
+    uint8_t type == 4;
+    uint16_t length;
+    uint32_t xid;
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 49;
+    uint16_t table_id;
+    pad(2);
+    uint32_t deleted_count;
+    uint32_t error_count;
+};
+
+
+// This message sets the size of the buckets array. The switch may reject this
+// message if the table has entries.
+struct of_bsn_gentable_set_buckets_size : of_bsn_header {
+    uint8_t version;
+    uint8_t type == 4;
+    uint16_t length;
+    uint32_t xid;
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 50;
+    uint16_t table_id;
+    pad(2);
+    uint32_t buckets_size;
+};
+
+
+// Retrieve the configuration state (key, value, and checksum) for each table
+// entry in a range of buckets.
+//
+// The checksum_mask must be a prefix mask. The checksum must be zero in the
+// bits where the checksum_mask is zero.
+struct of_bsn_gentable_entry_desc_stats_request : of_bsn_stats_request {
+    uint8_t version;
+    uint8_t type == 18;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_request_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 2;
+    uint16_t table_id;
+    pad(2);
+    of_checksum_128_t checksum;
+    of_checksum_128_t checksum_mask;
+};
+
+struct of_bsn_gentable_entry_desc_stats_entry {
+    uint16_t length;
+    uint16_t key_length;
+    of_checksum_128_t checksum;
+    list(of_bsn_tlv_t) key;
+    list(of_bsn_tlv_t) value;
+};
+
+struct of_bsn_gentable_entry_desc_stats_reply : of_bsn_stats_reply {
+    uint8_t version;
+    uint8_t type == 19;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_reply_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 2;
+    list(of_bsn_gentable_entry_desc_stats_entry_t) entries;
+};
+
+
+// Retrieve the runtime state (key and stats) for each table entry in a range
+// of buckets.
+//
+// The checksum_mask must be a prefix mask. The checksum must be zero in the
+// bits where the checksum_mask is zero.
+struct of_bsn_gentable_entry_stats_request : of_bsn_stats_request {
+    uint8_t version;
+    uint8_t type == 18;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_request_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 3;
+    uint16_t table_id;
+    pad(2);
+    of_checksum_128_t checksum;
+    of_checksum_128_t checksum_mask;
+};
+
+struct of_bsn_gentable_entry_stats_entry {
+    uint16_t length;
+    uint16_t key_length;
+    list(of_bsn_tlv_t) key;
+    list(of_bsn_tlv_t) stats;
+};
+
+struct of_bsn_gentable_entry_stats_reply : of_bsn_stats_reply {
+    uint8_t version;
+    uint8_t type == 19;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_reply_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 3;
+    list(of_bsn_gentable_entry_stats_entry_t) entries;
+};
+
+
+// Retrieve the description for all tables.
+struct of_bsn_gentable_desc_stats_request : of_bsn_stats_request {
+    uint8_t version;
+    uint8_t type == 18;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_request_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 4;
+};
+
+struct of_bsn_gentable_desc_stats_entry {
+    uint16_t length;
+    uint16_t table_id;
+    of_table_name_t name;
+    uint32_t buckets_size;
+    /* TODO properties */
+};
+
+struct of_bsn_gentable_desc_stats_reply : of_bsn_stats_reply {
+    uint8_t version;
+    uint8_t type == 19;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_reply_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 4;
+    list(of_bsn_gentable_desc_stats_entry_t) entries;
+};
+
+
+// Retrieves stats for every table. This includes the total checksum, so the
+// controller can quickly check whether the whole table is in sync.
+//
+// The checksum of a table is the XOR of the checksums of all entries in the
+// table.
+struct of_bsn_gentable_stats_request : of_bsn_stats_request {
+    uint8_t version;
+    uint8_t type == 18;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_request_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 7;
+};
+
+struct of_bsn_gentable_stats_entry {
+    uint16_t table_id;
+    pad(2);
+    uint32_t entry_count;
+    of_checksum_128_t checksum;
+};
+
+struct of_bsn_gentable_stats_reply : of_bsn_stats_reply {
+    uint8_t version;
+    uint8_t type == 19;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_reply_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 7;
+    list(of_bsn_gentable_stats_entry_t) entries;
+};
+
+
+// Retrieves the checksum for every bucket in a table. The entries are ordered
+// by bucket index.
+//
+// The checksum of a bucket is the XOR of the checksums of all entries in the
+// bucket.
+struct of_bsn_gentable_bucket_stats_request : of_bsn_stats_request {
+    uint8_t version;
+    uint8_t type == 18;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_request_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 5;
+    uint16_t table_id;
+};
+
+struct of_bsn_gentable_bucket_stats_entry {
+    of_checksum_128_t checksum;
+};
+
+struct of_bsn_gentable_bucket_stats_reply : of_bsn_stats_reply {
+    uint8_t version;
+    uint8_t type == 19;
+    uint16_t length;
+    uint32_t xid;
+    uint16_t stats_type == 0xffff;
+    enum ofp_stats_reply_flags flags;
+    pad(4);
+    uint32_t experimenter == 0x5c16c7;
+    uint32_t subtype == 5;
+    list(of_bsn_gentable_bucket_stats_entry_t) entries;
+};
diff --git a/openflow_input/bsn_tlv b/openflow_input/bsn_tlv
new file mode 100644
index 0000000..3f39ed3
--- /dev/null
+++ b/openflow_input/bsn_tlv
@@ -0,0 +1,55 @@
+// Copyright 2013, Big Switch Networks, Inc.
+//
+// LoxiGen is licensed under the Eclipse Public License,
+// version 1.0 (EPL), with the following special exception:
+//
+// LOXI Exception
+//
+// As a special exception to the terms of the EPL, you may
+// distribute libraries generated by LoxiGen (LoxiGen Libraries)
+// under the terms of your choice, provided that copyright and
+// licensing notices generated by LoxiGen are not altered or removed
+// from the LoxiGen Libraries and the notice provided below is (i)
+// included in the LoxiGen Libraries, if distributed in source code
+// form and (ii) included in any documentation for the LoxiGen
+// Libraries, if distributed in binary form.
+//
+// Notice: "Copyright 2013, Big Switch Networks, Inc.
+// This library was generated by the LoxiGen Compiler."
+//
+// You may not use this file except in compliance with the EPL or
+// LOXI Exception. You may obtain a copy of the EPL at:
+//
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an "AS
+// IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. See the EPL for the specific language
+// governing permissions and limitations under the EPL.
+
+#version 4
+
+struct of_bsn_tlv_port : of_bsn_tlv {
+    uint16_t type == 0;
+    uint16_t length;
+    of_port_no_t value;
+};
+
+struct of_bsn_tlv_mac : of_bsn_tlv {
+    uint16_t type == 1;
+    uint16_t length;
+    of_mac_addr_t value;
+};
+
+struct of_bsn_tlv_rx_packets : of_bsn_tlv {
+    uint16_t type == 2;
+    uint16_t length;
+    uint64_t value;
+};
+
+struct of_bsn_tlv_tx_packets : of_bsn_tlv {
+    uint16_t type == 3;
+    uint16_t length;
+    uint64_t value;
+};
diff --git a/test_data/of13/bsn_gentable_bucket_stats_reply.data b/test_data/of13/bsn_gentable_bucket_stats_reply.data
new file mode 100644
index 0000000..8e0772f
--- /dev/null
+++ b/test_data/of13/bsn_gentable_bucket_stats_reply.data
@@ -0,0 +1,54 @@
+-- binary
+04 13 # version, type
+00 38 # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 05 # subtype
+88 77 66 55 44 33 22 11 FF EE DD CC BB AA 99 88 # entries[0].checksum
+12 34 23 45 34 56 45 67 56 78 67 89 78 9A 89 AB # entries[1].checksum
+-- python
+ofp.message.bsn_gentable_bucket_stats_reply(
+    xid=0x12345678,
+    entries=[
+        ofp.bsn_gentable_bucket_stats_entry(
+            checksum=0x8877665544332211FFEEDDCCBBAA9988),
+        ofp.bsn_gentable_bucket_stats_entry(
+            checksum=0x123423453456456756786789789A89AB),
+    ])
+-- java
+builder.setXid(0x12345678)
+    .setEntries(
+        ImmutableList.<OFBsnGentableBucketStatsEntry>of(
+            factory.bsnGentableBucketStatsEntry(OFChecksum128.of(0x8877665544332211L, 0xFFEEDDCCBBAA9988L)),
+            factory.bsnGentableBucketStatsEntry(OFChecksum128.of(0x1234234534564567L, 0x56786789789A89ABL))
+        )
+    )
+-- c
+obj = of_bsn_gentable_bucket_stats_reply_new(OF_VERSION_1_3);
+of_bsn_gentable_bucket_stats_reply_xid_set(obj, 0x12345678);
+{
+    of_object_t *list = of_list_bsn_gentable_bucket_stats_entry_new(OF_VERSION_1_3);
+    {
+        of_object_t *entry = of_bsn_gentable_bucket_stats_entry_new(OF_VERSION_1_3);
+        {
+            of_checksum_128_t checksum = { 0x8877665544332211L, 0xFFEEDDCCBBAA9988L };
+            of_bsn_gentable_bucket_stats_entry_checksum_set(entry, checksum);
+        }
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    {
+        of_object_t *entry = of_bsn_gentable_bucket_stats_entry_new(OF_VERSION_1_3);
+        {
+            of_checksum_128_t checksum = { 0x1234234534564567L, 0x56786789789A89ABL };
+            of_bsn_gentable_bucket_stats_entry_checksum_set(entry, checksum);
+        }
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    of_bsn_gentable_bucket_stats_reply_entries_set(obj, list);
+    of_object_delete(list);
+}
diff --git a/test_data/of13/bsn_gentable_bucket_stats_request.data b/test_data/of13/bsn_gentable_bucket_stats_request.data
new file mode 100644
index 0000000..b756b54
--- /dev/null
+++ b/test_data/of13/bsn_gentable_bucket_stats_request.data
@@ -0,0 +1,14 @@
+-- binary
+04 12 # version, type
+00 1a # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 05 # subtype
+12 34 # table_id
+-- python
+ofp.message.bsn_gentable_bucket_stats_request(
+    xid=0x12345678,
+    table_id=0x1234)
diff --git a/test_data/of13/bsn_gentable_clear_request.data b/test_data/of13/bsn_gentable_clear_request.data
new file mode 100644
index 0000000..911ee27
--- /dev/null
+++ b/test_data/of13/bsn_gentable_clear_request.data
@@ -0,0 +1,33 @@
+-- binary
+04 04 # version, type
+00 34 # length
+12 34 56 78 # xid
+00 5c 16 c7 # experimenter
+00 00 00 30 # subtype
+00 14 # table_id
+00 00 # pad
+fe dc ba 98 76 54 32 10 ff ee cc bb aa 99 00 00 # checksum
+ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00 # checksum_mask
+-- python
+ofp.message.bsn_gentable_clear_request(
+    xid=0x12345678,
+    table_id=20,
+    checksum=     0xFEDCBA9876543210FFEECCBBAA990000,
+    checksum_mask=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000)
+-- java
+builder.setXid(0x12345678)
+    .setChecksum(OFChecksum128.of(0xFEDCBA9876543210L, 0xFFEECCBBAA990000L))
+    .setChecksumMask(OFChecksum128.of(0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFF0000L))
+    .setTableId(20)
+-- c
+obj = of_bsn_gentable_clear_request_new(OF_VERSION_1_3);
+of_bsn_gentable_clear_request_xid_set(obj, 0x12345678);
+of_bsn_gentable_clear_request_table_id_set(obj, 20);
+{
+    of_checksum_128_t checksum = { 0xFEDCBA9876543210L, 0xFFEECCBBAA990000L };
+    of_bsn_gentable_clear_request_checksum_set(obj, checksum);
+}
+{
+    of_checksum_128_t checksum_mask = { 0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFF0000L };
+    of_bsn_gentable_clear_request_checksum_mask_set(obj, checksum_mask);
+}
diff --git a/test_data/of13/bsn_gentable_desc_stats_reply.data b/test_data/of13/bsn_gentable_desc_stats_reply.data
new file mode 100644
index 0000000..52e627a
--- /dev/null
+++ b/test_data/of13/bsn_gentable_desc_stats_reply.data
@@ -0,0 +1,76 @@
+-- binary
+04 13 # version, type
+00 68 # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 04 # subtype
+
+# entries[0]
+00 28 # length
+00 00 # table id
+74 61 62 6c 65 20 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # name
+00 00 00 20 # buckets_size
+
+# entries[1]
+00 28 # length
+00 01 # table id
+74 61 62 6c 65 20 31 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e # name
+00 00 00 40 # buckets_size
+-- python
+ofp.message.bsn_gentable_desc_stats_reply(
+    xid=0x12345678,
+    entries=[
+        ofp.bsn_gentable_desc_stats_entry(
+            table_id=0,
+            name="table 0",
+            buckets_size=32),
+        ofp.bsn_gentable_desc_stats_entry(
+            table_id=1,
+            name="table 1".ljust(32, '.'),
+            buckets_size=64),
+    ])
+-- java
+builder.setXid(0x12345678)
+    .setEntries(
+        ImmutableList.<OFBsnGentableDescStatsEntry>of(
+            factory.buildBsnGentableDescStatsEntry()
+                .setTableId(0)
+                .setName("table 0")
+                .setBucketsSize(32)
+                .build(),
+            factory.buildBsnGentableDescStatsEntry()
+                .setTableId(1)
+                .setName("table 1.........................")
+                .setBucketsSize(64)
+                .build()
+        )
+    )
+-- c
+obj = of_bsn_gentable_desc_stats_reply_new(OF_VERSION_1_3);
+of_bsn_gentable_desc_stats_reply_xid_set(obj, 0x12345678);
+{
+    of_object_t *list = of_list_bsn_gentable_desc_stats_entry_new(OF_VERSION_1_3);
+    {
+        of_table_name_t name = "table 0";
+        of_object_t *entry = of_bsn_gentable_desc_stats_entry_new(OF_VERSION_1_3);
+        of_bsn_gentable_desc_stats_entry_table_id_set(entry, 0);
+        of_bsn_gentable_desc_stats_entry_name_set(entry, name);
+        of_bsn_gentable_desc_stats_entry_buckets_size_set(entry, 32);
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    {
+        of_table_name_t name = "table 1.........................";
+        of_object_t *entry = of_bsn_gentable_desc_stats_entry_new(OF_VERSION_1_3);
+        of_bsn_gentable_desc_stats_entry_table_id_set(entry, 1);
+        of_bsn_gentable_desc_stats_entry_name_set(entry, name);
+        of_bsn_gentable_desc_stats_entry_buckets_size_set(entry, 64);
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    of_bsn_gentable_desc_stats_reply_entries_set(obj, list);
+    of_object_delete(list);
+}
diff --git a/test_data/of13/bsn_gentable_desc_stats_request.data b/test_data/of13/bsn_gentable_desc_stats_request.data
new file mode 100644
index 0000000..977fe29
--- /dev/null
+++ b/test_data/of13/bsn_gentable_desc_stats_request.data
@@ -0,0 +1,12 @@
+-- binary
+04 12 # version, type
+00 18 # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 04 # subtype
+-- python
+ofp.message.bsn_gentable_desc_stats_request(
+    xid=0x12345678)
diff --git a/test_data/of13/bsn_gentable_entry_add.data b/test_data/of13/bsn_gentable_entry_add.data
new file mode 100644
index 0000000..d8db0f8
--- /dev/null
+++ b/test_data/of13/bsn_gentable_entry_add.data
@@ -0,0 +1,98 @@
+-- binary
+04 04 # version, type
+00 48 # length
+12 34 56 78 # xid
+00 5c 16 c7 # experimenter
+00 00 00 2e # subtype
+00 14 # table_id
+00 12 # key_length
+fe dc ba 98 76 54 32 10 ff ee cc bb aa 99 88 77 # checksum
+
+00 00 # key[0].type
+00 08 # key[0].length
+00 00 00 05 # key[0].value
+
+00 01 # key[1].type
+00 0a # key[1].length
+01 23 45 67 89 ab # key[1].value
+
+00 00 # value[0].type
+00 08 # value[0].length
+00 00 00 06 # value[0].value
+
+00 01 # value[1].type
+00 0a # value[1].length
+ff ee dd cc bb aa # value[1].value
+-- python
+ofp.message.bsn_gentable_entry_add(
+    xid=0x12345678,
+    checksum=0xFEDCBA9876543210FFEECCBBAA998877,
+    table_id=20,
+    key=[
+        ofp.bsn_tlv.port(5),
+        ofp.bsn_tlv.mac([0x01, 0x23, 0x45, 0x67, 0x89, 0xab]),
+    ],
+    value=[
+        ofp.bsn_tlv.port(6),
+        ofp.bsn_tlv.mac([0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa]),
+    ])
+-- java
+builder.setXid(0x12345678)
+    .setChecksum(OFChecksum128.of(0xFEDCBA9876543210L, 0xFFEECCBBAA998877L))
+    .setTableId(20)
+    .setKey(
+        ImmutableList.<OFBsnTlv>of(
+            factory.bsnTlvPort(OFPort.of(5)),
+            factory.bsnTlvMac(MacAddress.of("01:23:45:67:89:ab"))
+        )
+    )
+    .setValue(
+        ImmutableList.<OFBsnTlv>of(
+            factory.bsnTlvPort(OFPort.of(6)),
+            factory.bsnTlvMac(MacAddress.of("ff:ee:dd:cc:bb:aa"))
+        )
+    )
+-- c
+obj = of_bsn_gentable_entry_add_new(OF_VERSION_1_3);
+of_bsn_gentable_entry_add_xid_set(obj, 0x12345678);
+of_bsn_gentable_entry_add_table_id_set(obj, 20);
+{
+    of_checksum_128_t checksum = { 0xFEDCBA9876543210L, 0xFFEECCBBAA998877L };
+    of_bsn_gentable_entry_add_checksum_set(obj, checksum);
+}
+{
+    of_object_t *list = of_list_bsn_tlv_new(OF_VERSION_1_3);
+    {
+        of_object_t *tlv = of_bsn_tlv_port_new(OF_VERSION_1_3);
+        of_bsn_tlv_port_value_set(tlv, 5);
+        of_list_append(list, tlv);
+        of_object_delete(tlv);
+    }
+    {
+        of_mac_addr_t mac = { { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab } };
+        of_object_t *tlv = of_bsn_tlv_mac_new(OF_VERSION_1_3);
+        of_bsn_tlv_mac_value_set(tlv, mac);
+        of_list_append(list, tlv);
+        of_object_delete(tlv);
+    }
+    of_bsn_gentable_entry_add_key_set(obj, list);
+    of_object_delete(list);
+}
+{
+    of_object_t *list = of_list_bsn_tlv_new(OF_VERSION_1_3);
+    {
+        of_object_t *tlv = of_bsn_tlv_port_new(OF_VERSION_1_3);
+        of_bsn_tlv_port_value_set(tlv, 6);
+        of_list_append(list, tlv);
+        of_object_delete(tlv);
+    }
+    {
+        of_mac_addr_t mac = { { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa } };
+        of_object_t *tlv = of_bsn_tlv_mac_new(OF_VERSION_1_3);
+        of_bsn_tlv_mac_value_set(tlv, mac);
+        of_list_append(list, tlv);
+        of_object_delete(tlv);
+    }
+    of_bsn_gentable_entry_add_value_set(obj, list);
+    of_object_delete(list);
+}
diff --git a/test_data/of13/bsn_gentable_entry_delete.data b/test_data/of13/bsn_gentable_entry_delete.data
new file mode 100644
index 0000000..0f17bfd
--- /dev/null
+++ b/test_data/of13/bsn_gentable_entry_delete.data
@@ -0,0 +1,54 @@
+-- binary
+04 04 # version, type
+00 24 # length
+12 34 56 78 # xid
+00 5c 16 c7 # experimenter
+00 00 00 2f # subtype
+00 14 # table_id
+
+00 00 # key[0].type
+00 08 # key[0].length
+00 00 00 05 # key[0].value
+
+00 01 # key[1].type
+00 0a # key[1].length
+01 23 45 67 89 ab # key[1].value
+-- python
+ofp.message.bsn_gentable_entry_delete(
+    xid=0x12345678,
+    table_id=20,
+    key=[
+        ofp.bsn_tlv.port(5),
+        ofp.bsn_tlv.mac([0x01, 0x23, 0x45, 0x67, 0x89, 0xab]),
+    ])
+-- java
+builder.setXid(0x12345678)
+    .setTableId(20)
+    .setKey(
+        ImmutableList.<OFBsnTlv>of(
+            factory.bsnTlvPort(OFPort.of(5)),
+            factory.bsnTlvMac(MacAddress.of("01:23:45:67:89:ab"))
+        )
+    )
+-- c
+obj = of_bsn_gentable_entry_delete_new(OF_VERSION_1_3);
+of_bsn_gentable_entry_delete_xid_set(obj, 0x12345678);
+of_bsn_gentable_entry_delete_table_id_set(obj, 20);
+{
+    of_object_t *list = of_list_bsn_tlv_new(OF_VERSION_1_3);
+    {
+        of_object_t *tlv = of_bsn_tlv_port_new(OF_VERSION_1_3);
+        of_bsn_tlv_port_value_set(tlv, 5);
+        of_list_append(list, tlv);
+        of_object_delete(tlv);
+    }
+    {
+        of_mac_addr_t mac = { { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab } };
+        of_object_t *tlv = of_bsn_tlv_mac_new(OF_VERSION_1_3);
+        of_bsn_tlv_mac_value_set(tlv, mac);
+        of_list_append(list, tlv);
+        of_object_delete(tlv);
+    }
+    of_bsn_gentable_entry_delete_key_set(obj, list);
+    of_object_delete(list);
+}
diff --git a/test_data/of13/bsn_gentable_entry_desc_stats_reply.data b/test_data/of13/bsn_gentable_entry_desc_stats_reply.data
new file mode 100644
index 0000000..40de7dd
--- /dev/null
+++ b/test_data/of13/bsn_gentable_entry_desc_stats_reply.data
@@ -0,0 +1,148 @@
+-- binary
+04 13 # version, type
+00 64 # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 2 # subtype
+
+# entries[0]
+00 26 # length
+00 08 # key_length
+fe dc ba 98 76 54 32 10 ff ee cc bb aa 99 88 00 # checksum
+00 00 # key[0].type
+00 08 # key[0].length
+00 00 00 05 # key[0].value
+00 01 # value[0].type
+00 0a # value[0].length
+ff ee dd cc bb 00 # value[0].value
+
+# entries[1]
+00 26 # length
+00 08 # key_length
+fe dc ba 98 76 54 32 10 ff ee cc bb aa 99 88 01 # checksum
+00 00 # key[0].type
+00 08 # key[0].length
+00 00 00 06 # key[0].value
+00 01 # value[0].type
+00 0a # value[0].length
+ff ee dd cc bb 01 # value[0].value
+-- python
+ofp.message.bsn_gentable_entry_desc_stats_reply(
+    xid=0x12345678,
+    entries=[
+        ofp.bsn_gentable_entry_desc_stats_entry(
+            checksum=0xFEDCBA9876543210FFEECCBBAA998800,
+            key=[
+                ofp.bsn_tlv.port(5),
+            ],
+            value=[
+                ofp.bsn_tlv.mac([0xff, 0xee, 0xdd, 0xcc, 0xbb, 0x00]),
+            ]),
+        ofp.bsn_gentable_entry_desc_stats_entry(
+            checksum=0xFEDCBA9876543210FFEECCBBAA998801,
+            key=[
+                ofp.bsn_tlv.port(6),
+            ],
+            value=[
+                ofp.bsn_tlv.mac([0xff, 0xee, 0xdd, 0xcc, 0xbb, 0x01]),
+            ]),
+    ])
+-- java
+builder.setXid(0x12345678)
+    .setEntries(
+        ImmutableList.<OFBsnGentableEntryDescStatsEntry>of(
+            factory.buildBsnGentableEntryDescStatsEntry()
+                .setChecksum(OFChecksum128.of(0xFEDCBA9876543210L, 0xFFEECCBBAA998800L))
+                .setKey(ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvPort(OFPort.of(5))
+                ))
+                .setValue(ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvMac(MacAddress.of("ff:ee:dd:cc:bb:00"))
+                ))
+                .build(),
+            factory.buildBsnGentableEntryDescStatsEntry()
+                .setChecksum(OFChecksum128.of(0xFEDCBA9876543210L, 0xFFEECCBBAA998801L))
+                .setKey(ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvPort(OFPort.of(6))
+                ))
+                .setValue(ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvMac(MacAddress.of("ff:ee:dd:cc:bb:01"))
+                ))
+                .build()
+        )
+    )
+-- c
+obj = of_bsn_gentable_entry_desc_stats_reply_new(OF_VERSION_1_3);
+of_bsn_gentable_entry_desc_stats_reply_xid_set(obj, 0x12345678);
+{
+    of_object_t *list = of_list_bsn_gentable_entry_desc_stats_entry_new(OF_VERSION_1_3);
+    {
+        of_object_t *entry = of_bsn_gentable_entry_desc_stats_entry_new(OF_VERSION_1_3);
+        {
+            of_checksum_128_t checksum = { 0xFEDCBA9876543210L, 0xFFEECCBBAA998800L };
+            of_bsn_gentable_entry_desc_stats_entry_checksum_set(entry, checksum);
+        }
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_port_new(OF_VERSION_1_3);
+                of_bsn_tlv_port_value_set(tlv, 5);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_desc_stats_entry_key_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_mac_new(OF_VERSION_1_3);
+                of_mac_addr_t mac = { { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0x00 } };
+                of_bsn_tlv_mac_value_set(tlv, mac);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_desc_stats_entry_value_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    {
+        of_object_t *entry = of_bsn_gentable_entry_desc_stats_entry_new(OF_VERSION_1_3);
+        {
+            of_checksum_128_t checksum = { 0xFEDCBA9876543210L, 0xFFEECCBBAA998801L };
+            of_bsn_gentable_entry_desc_stats_entry_checksum_set(entry, checksum);
+        }
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_port_new(OF_VERSION_1_3);
+                of_bsn_tlv_port_value_set(tlv, 6);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_desc_stats_entry_key_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_mac_new(OF_VERSION_1_3);
+                of_mac_addr_t mac = { { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0x01 } };
+                of_bsn_tlv_mac_value_set(tlv, mac);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_desc_stats_entry_value_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    of_bsn_gentable_entry_desc_stats_reply_entries_set(obj, list);
+    of_object_delete(list);
+}
diff --git a/test_data/of13/bsn_gentable_entry_desc_stats_request.data b/test_data/of13/bsn_gentable_entry_desc_stats_request.data
new file mode 100644
index 0000000..4971f06
--- /dev/null
+++ b/test_data/of13/bsn_gentable_entry_desc_stats_request.data
@@ -0,0 +1,19 @@
+-- binary
+04 12 # version, type
+00 3c # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 2 # subtype
+00 14 # table_id
+00 00 # pad
+fe dc ba 98 76 54 32 10 ff ee cc bb aa 99 00 00 # checksum
+ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00 # checksum_mask
+-- python
+ofp.message.bsn_gentable_entry_desc_stats_request(
+    xid=0x12345678,
+    table_id=20,
+    checksum=     0xFEDCBA9876543210FFEECCBBAA990000,
+    checksum_mask=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000)
diff --git a/test_data/of13/bsn_gentable_entry_stats_reply.data b/test_data/of13/bsn_gentable_entry_stats_reply.data
new file mode 100644
index 0000000..cd4ab62
--- /dev/null
+++ b/test_data/of13/bsn_gentable_entry_stats_reply.data
@@ -0,0 +1,154 @@
+-- binary
+04 13 # version, type
+00 60 # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 03 # subtype
+
+# entries[0]
+00 24 # length
+00 08 # key_length
+00 00 # key[0].type
+00 08 # key[0].length
+00 00 00 05 # key[0].value
+00 02 # stats[0].type
+00 0c # stats[0].length
+00 00 00 00 00 00 00 64 # stats[0].value
+00 03 # stats[0].type
+00 0c # stats[0].length
+00 00 00 00 00 00 00 65 # stats[0].value
+
+# entries[1]
+00 24 # length
+00 08 # key_length
+00 00 # key[0].type
+00 08 # key[0].length
+00 00 00 06 # key[0].value
+00 02 # stats[0].type
+00 0c # stats[0].length
+00 00 00 00 00 00 00 64 # stats[0].value
+00 03 # stats[0].type
+00 0c # stats[0].length
+00 00 00 00 00 00 00 65 # stats[0].value
+-- python
+ofp.message.bsn_gentable_entry_stats_reply(
+    xid=0x12345678,
+    entries=[
+        ofp.bsn_gentable_entry_stats_entry(
+            key=[
+                ofp.bsn_tlv.port(5),
+            ],
+            stats=[
+                ofp.bsn_tlv.rx_packets(100),
+                ofp.bsn_tlv.tx_packets(101),
+            ]),
+        ofp.bsn_gentable_entry_stats_entry(
+            key=[
+                ofp.bsn_tlv.port(6),
+            ],
+            stats=[
+                ofp.bsn_tlv.rx_packets(100),
+                ofp.bsn_tlv.tx_packets(101),
+            ]),
+    ])
+-- java
+builder.setXid(0x12345678)
+    .setEntries(
+        ImmutableList.<OFBsnGentableEntryStatsEntry>of(
+            factory.bsnGentableEntryStatsEntry(
+                ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvPort(OFPort.of(5))
+                ),
+                ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvRxPackets(U64.of(100)),
+                    factory.bsnTlvTxPackets(U64.of(101))
+                )
+            ),
+            factory.bsnGentableEntryStatsEntry(
+                ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvPort(OFPort.of(6))
+                ),
+                ImmutableList.<OFBsnTlv>of(
+                    factory.bsnTlvRxPackets(U64.of(100)),
+                    factory.bsnTlvTxPackets(U64.of(101))
+                )
+            )
+        )
+    )
+-- c
+obj = of_bsn_gentable_entry_stats_reply_new(OF_VERSION_1_3);
+of_bsn_gentable_entry_stats_reply_xid_set(obj, 0x12345678);
+{
+    of_object_t *list = of_list_bsn_gentable_entry_stats_entry_new(OF_VERSION_1_3);
+    {
+        of_object_t *entry = of_bsn_gentable_entry_stats_entry_new(OF_VERSION_1_3);
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_port_new(OF_VERSION_1_3);
+                of_bsn_tlv_port_value_set(tlv, 5);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_stats_entry_key_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_rx_packets_new(OF_VERSION_1_3);
+                of_bsn_tlv_rx_packets_value_set(tlv, 100);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            {
+                of_object_t *tlv = of_bsn_tlv_tx_packets_new(OF_VERSION_1_3);
+                of_bsn_tlv_tx_packets_value_set(tlv, 101);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_stats_entry_stats_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    {
+        of_object_t *entry = of_bsn_gentable_entry_stats_entry_new(OF_VERSION_1_3);
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_port_new(OF_VERSION_1_3);
+                of_bsn_tlv_port_value_set(tlv, 6);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_stats_entry_key_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        {
+            of_object_t *tlvs = of_list_bsn_tlv_new(OF_VERSION_1_3);
+            {
+                of_object_t *tlv = of_bsn_tlv_rx_packets_new(OF_VERSION_1_3);
+                of_bsn_tlv_rx_packets_value_set(tlv, 100);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            {
+                of_object_t *tlv = of_bsn_tlv_tx_packets_new(OF_VERSION_1_3);
+                of_bsn_tlv_tx_packets_value_set(tlv, 101);
+                of_list_append(tlvs, tlv);
+                of_object_delete(tlv);
+            }
+            of_bsn_gentable_entry_stats_entry_stats_set(entry, tlvs);
+            of_object_delete(tlvs);
+        }
+        of_list_append(list, entry);
+        of_object_delete(entry);
+    }
+    of_bsn_gentable_entry_stats_reply_entries_set(obj, list);
+    of_object_delete(list);
+}
diff --git a/test_data/of13/bsn_gentable_entry_stats_request.data b/test_data/of13/bsn_gentable_entry_stats_request.data
new file mode 100644
index 0000000..a288a55
--- /dev/null
+++ b/test_data/of13/bsn_gentable_entry_stats_request.data
@@ -0,0 +1,19 @@
+-- binary
+04 12 # version, type
+00 3c # length
+12 34 56 78 # xid
+ff ff # stats_type
+00 00 # flags
+00 00 00 00 # pad
+00 5c 16 c7 # experimenter
+00 00 00 3 # subtype
+00 14 # table_id
+00 00 # pad
+fe dc ba 98 76 54 32 10 ff ee cc bb aa 99 00 00 # checksum
+ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00 # checksum_mask
+-- python
+ofp.message.bsn_gentable_entry_stats_request(
+    xid=0x12345678,
+    table_id=20,
+    checksum=     0xFEDCBA9876543210FFEECCBBAA990000,
+    checksum_mask=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000)
diff --git a/test_data/of13/bsn_gentable_set_buckets_size.data b/test_data/of13/bsn_gentable_set_buckets_size.data
new file mode 100644
index 0000000..7833736
--- /dev/null
+++ b/test_data/of13/bsn_gentable_set_buckets_size.data
@@ -0,0 +1,14 @@
+-- binary
+04 04 # version, type
+00 18 # length
+12 34 56 78 # xid
+00 5c 16 c7 # experimenter
+00 00 00 32 # subtype
+00 14 # table_id
+00 00 # pad
+00 11 22 33 # buckets_size
+-- python
+ofp.message.bsn_gentable_set_buckets_size(
+    xid=0x12345678,
+    table_id=20,
+    buckets_size=0x00112233)
diff --git a/test_data/of13/bsn_tlv_port.data b/test_data/of13/bsn_tlv_port.data
new file mode 100644
index 0000000..303b0ec
--- /dev/null
+++ b/test_data/of13/bsn_tlv_port.data
@@ -0,0 +1,6 @@
+-- binary
+00 00 # type
+00 08 # length
+00 00 00 05 # value
+-- python
+ofp.bsn_tlv.port(5)