bsn_gentable: add checksum/num_entries assertions to table stats test
diff --git a/tests-1.3/bsn_gentable.py b/tests-1.3/bsn_gentable.py
index 3b22e27..8e4d932 100644
--- a/tests-1.3/bsn_gentable.py
+++ b/tests-1.3/bsn_gentable.py
@@ -21,6 +21,14 @@
d[tlv.__class__] = tlv.value
return d
+def make_checksum(hi, lo):
+ """
+ Place 'hi' in the upper 8 bits and 'lo' in the lower bits.
+ """
+ return ((hi & 0xff) << 120) | lo
+
+assert make_checksum(0xab, 0xcd) == 0xab0000000000000000000000000000cd
+
class BaseGenTableTest(base_tests.SimpleProtocol):
def setUp(self):
base_tests.SimpleProtocol.setUp(self)
@@ -82,6 +90,13 @@
request = ofp.message.bsn_gentable_stats_request()
return get_stats(self, request)
+ def do_test_table_stats(self):
+ entries = self.do_table_stats()
+ for entry in entries:
+ if entry.table_id == TABLE_ID:
+ return entry
+ raise AssertionError("did not find test table")
+
class ClearAll(BaseGenTableTest):
"""
Test clearing entire table
@@ -212,6 +227,7 @@
Test retrieving table stats
"""
def runTest(self):
+ # Verify we have the test table and no duplicates
entries = self.do_table_stats()
seen = set()
for entry in entries:
@@ -221,7 +237,45 @@
if entry.table_id == TABLE_ID:
self.assertEqual(entry.entry_count, 0)
self.assertEqual(entry.checksum, 0)
-
- # TODO add/modify/remove flows and verify entry_count/checksum
-
self.assertIn(TABLE_ID, seen)
+
+ table_checksum = 0
+
+ # Add a bunch of entries, spread among the checksum buckets
+ for i in range(0, 256):
+ table_checksum ^= make_checksum(i, i*31)
+ self.do_add(vlan_vid=i, ipv4=0x12345678, mac=(0, 1, 2, 3, 4, i),
+ checksum=make_checksum(i, i*31))
+
+ do_barrier(self.controller)
+ verify_no_errors(self.controller)
+
+ table_stats = self.do_test_table_stats()
+ self.assertEqual(table_stats.entry_count, 256)
+ self.assertEqual(table_stats.checksum, table_checksum)
+
+ # Modify an entry, changing its checksum
+ i = 30
+ table_checksum ^= make_checksum(i, i*31) # subtract old checksum
+ table_checksum ^= make_checksum(i, i*37) # add new checksum
+ self.do_add(vlan_vid=i, ipv4=0x12345678, mac=(0, 4, 3, 2, 1, i),
+ checksum=make_checksum(i, i*37))
+
+ do_barrier(self.controller)
+ verify_no_errors(self.controller)
+
+ table_stats = self.do_test_table_stats()
+ self.assertEqual(table_stats.entry_count, 256)
+ self.assertEqual(table_stats.checksum, table_checksum)
+
+ # Delete an entry
+ i = 87
+ table_checksum ^= make_checksum(i, i*31)
+ self.do_delete(vlan_vid=i, ipv4=0x12345678)
+
+ do_barrier(self.controller)
+ verify_no_errors(self.controller)
+
+ table_stats = self.do_test_table_stats()
+ self.assertEqual(table_stats.entry_count, 255)
+ self.assertEqual(table_stats.checksum, table_checksum)