pyloxi: move list unpack functions into util
The goal is to make all module templates identical.
diff --git a/py_gen/templates/action.py b/py_gen/templates/action.py
index 9f80243..dfd832d 100644
--- a/py_gen/templates/action.py
+++ b/py_gen/templates/action.py
@@ -41,11 +41,6 @@
import oxm # for unpack
:: #endif
-def unpack_list(reader):
- def deserializer(reader, typ):
- return action.unpack(reader)
- return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
-
:: for ofclass in ofclasses:
:: if ofclass.virtual:
:: include('_virtual_ofclass.py', ofclass=ofclass)
diff --git a/py_gen/templates/common.py b/py_gen/templates/common.py
index 6569c77..f222e9b 100644
--- a/py_gen/templates/common.py
+++ b/py_gen/templates/common.py
@@ -49,43 +49,6 @@
# HACK make this module visible as 'common' to simplify code generation
common = sys.modules[__name__]
-def unpack_list_flow_stats_entry(reader):
- return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
-
-def unpack_list_queue_prop(reader):
- def deserializer(reader, typ):
- return queue_prop.unpack(reader)
- return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
-
-def unpack_list_packet_queue(reader):
- def wrapper(reader):
- length, = reader.peek('!4xH')
- return packet_queue.unpack(reader.slice(length))
- return loxi.generic_util.unpack_list(reader, wrapper)
-
-def unpack_list_hello_elem(reader):
- def deserializer(reader, typ):
- try:
- return hello_elem.unpack(reader)
- except loxi.ProtocolError:
- return None
- return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
-
-def unpack_list_bucket(reader):
- return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
-
-def unpack_list_group_desc_stats_entry(reader):
- return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
-
-def unpack_list_group_stats_entry(reader):
- return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
-
-def unpack_list_meter_stats(reader):
- def wrapper(reader):
- length, = reader.peek('!4xH')
- return meter_stats.unpack(reader.slice(length))
- return loxi.generic_util.unpack_list(reader, wrapper)
-
:: for ofclass in ofclasses:
:: if ofclass.virtual:
:: include('_virtual_ofclass.py', ofclass=ofclass)
diff --git a/py_gen/templates/instruction.py b/py_gen/templates/instruction.py
index 9842f95..da91b76 100644
--- a/py_gen/templates/instruction.py
+++ b/py_gen/templates/instruction.py
@@ -38,11 +38,6 @@
import loxi.generic_util
import loxi
-def unpack_list(reader):
- def deserializer(reader, typ):
- return instruction.unpack(reader)
- return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
-
:: for ofclass in ofclasses:
:: if ofclass.virtual:
:: include('_virtual_ofclass.py', ofclass=ofclass)
diff --git a/py_gen/templates/meter_band.py b/py_gen/templates/meter_band.py
index 38607e7..24c1f2c 100644
--- a/py_gen/templates/meter_band.py
+++ b/py_gen/templates/meter_band.py
@@ -37,11 +37,6 @@
import loxi.generic_util
import loxi
-def unpack_list(reader):
- def deserializer(reader, typ):
- return meter_band.unpack(reader)
- return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
-
:: for ofclass in ofclasses:
:: if ofclass.virtual:
:: include('_virtual_ofclass.py', ofclass=ofclass)
diff --git a/py_gen/templates/oxm.py b/py_gen/templates/oxm.py
index 71bf7df..5de771c 100644
--- a/py_gen/templates/oxm.py
+++ b/py_gen/templates/oxm.py
@@ -37,12 +37,6 @@
import loxi.generic_util
import loxi
-def unpack(reader):
- return oxm.unpack(reader)
-
-def unpack_list(reader):
- return loxi.generic_util.unpack_list(reader, unpack)
-
:: for ofclass in ofclasses:
:: if ofclass.virtual:
:: include('_virtual_ofclass.py', ofclass=ofclass)
diff --git a/py_gen/templates/util.py b/py_gen/templates/util.py
index 50a64db..73da0ea 100644
--- a/py_gen/templates/util.py
+++ b/py_gen/templates/util.py
@@ -29,9 +29,20 @@
:: from loxi_globals import OFVersions
:: include('_autogen.py')
+import struct
import loxi
import const
-import struct
+import common
+import action
+:: if version >= OFVersions.VERSION_1_1:
+import instruction
+:: #endif
+:: if version >= OFVersions.VERSION_1_2:
+import oxm
+:: #endif
+:: if version >= OFVersions.VERSION_1_3:
+import meter_band
+:: #endif
def pretty_mac(mac):
return ':'.join(["%02x" % x for x in mac])
@@ -162,3 +173,58 @@
i += 1
x >>= 1
return value
+
+def unpack_list_flow_stats_entry(reader):
+ return loxi.generic_util.unpack_list_lv16(reader, common.flow_stats_entry.unpack)
+
+def unpack_list_queue_prop(reader):
+ def deserializer(reader, typ):
+ return common.queue_prop.unpack(reader)
+ return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+
+def unpack_list_packet_queue(reader):
+ def wrapper(reader):
+ length, = reader.peek('!4xH')
+ return common.packet_queue.unpack(reader.slice(length))
+ return loxi.generic_util.unpack_list(reader, wrapper)
+
+def unpack_list_hello_elem(reader):
+ def deserializer(reader, typ):
+ try:
+ return common.hello_elem.unpack(reader)
+ except loxi.ProtocolError:
+ return None
+ return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
+
+def unpack_list_bucket(reader):
+ return loxi.generic_util.unpack_list_lv16(reader, common.bucket.unpack)
+
+def unpack_list_group_desc_stats_entry(reader):
+ return loxi.generic_util.unpack_list_lv16(reader, common.group_desc_stats_entry.unpack)
+
+def unpack_list_group_stats_entry(reader):
+ return loxi.generic_util.unpack_list_lv16(reader, common.group_stats_entry.unpack)
+
+def unpack_list_meter_stats(reader):
+ def wrapper(reader):
+ length, = reader.peek('!4xH')
+ return common.meter_stats.unpack(reader.slice(length))
+ return loxi.generic_util.unpack_list(reader, wrapper)
+
+def unpack_list_action(reader):
+ def deserializer(reader, typ):
+ return action.action.unpack(reader)
+ return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+
+def unpack_list_instruction(reader):
+ def deserializer(reader, typ):
+ return instruction.instruction.unpack(reader)
+ return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+
+def unpack_list_meter_band(reader):
+ def deserializer(reader, typ):
+ return meter_band.meter_band.unpack(reader)
+ return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+
+def unpack_list_oxm(reader):
+ return loxi.generic_util.unpack_list(reader, oxm.oxm.unpack)