pyloxi: support of_bitmap_512_t
diff --git a/py_gen/oftype.py b/py_gen/oftype.py
index 51b8e13..3893865 100644
--- a/py_gen/oftype.py
+++ b/py_gen/oftype.py
@@ -116,6 +116,11 @@
init='0',
pack='util.pack_checksum_128(%s)',
unpack="util.unpack_checksum_128(%s)"),
+
+ 'of_bitmap_512_t': OFTypeData(
+ init='set()',
+ pack='util.pack_bitmap_512(%s)',
+ unpack="util.unpack_bitmap_512(%s)"),
}
## Fixed length strings
diff --git a/py_gen/templates/util.py b/py_gen/templates/util.py
index 85181dc..7558576 100644
--- a/py_gen/templates/util.py
+++ b/py_gen/templates/util.py
@@ -173,6 +173,28 @@
x >>= 1
return value
+def pack_bitmap_512(value):
+ words = [0] * 8
+ for v in value:
+ assert v < 512
+ words[7-v/64] |= 1 << (v % 64)
+ return struct.pack("!8Q", *words)
+
+def unpack_bitmap_512(reader):
+ words = reader.read("!8Q")
+ x = 0l
+ for word in words:
+ x <<= 64
+ x |= word
+ i = 0
+ value = set()
+ while x != 0:
+ if x & 1 == 1:
+ value.add(i)
+ i += 1
+ x >>= 1
+ return value
+
def pack_checksum_128(value):
return struct.pack("!QQ", (value >> 64) & MASK64, value & MASK64)
diff --git a/py_gen/tests/of13.py b/py_gen/tests/of13.py
index c5a16b2..c99ee34 100644
--- a/py_gen/tests/of13.py
+++ b/py_gen/tests/of13.py
@@ -126,5 +126,18 @@
else:
fn()
+class TestUtils(unittest.TestCase):
+ def check_bitmap_512(self, value, data):
+ self.assertEquals(data, ofp.util.pack_bitmap_512(set(value)))
+ self.assertEquals(ofp.util.unpack_bitmap_512(OFReader(data)), set(value))
+
+ def test_bitmap_512(self):
+ self.check_bitmap_512([0], "\x00" * 63 + "\x01")
+ self.check_bitmap_512([8], "\x00" * 62 + "\x01\x00")
+ self.check_bitmap_512([63], "\x00" * 56 + "\x80" + "\x00" * 7)
+ self.check_bitmap_512([64], "\x00" * 55 + "\x01" + "\x00" * 8)
+ self.check_bitmap_512([511], "\x80" + "\x00" * 63)
+ self.check_bitmap_512([5, 67, 90], "\x00" * 52 + "\x04\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x20")
+
if __name__ == '__main__':
unittest.main()