Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions clib/fakeoftable.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def table_state(self, dp_id):

def hash_table(self, dp_id):
"""Return a hash of a single FakeOFTable"""
return self.tables[dp_id].__hash__()
return hash(self.tables[dp_id])


class FakeOFTable:
Expand All @@ -252,12 +252,26 @@ def __init__(self, dp_id, num_tables=1, requires_tfm=True):

def table_state(self):
"""Return tuple of table hash & table str"""
table_str = str(self.tables)
return (hash(frozenset(table_str)), table_str)
return (hash(self), str(self))

def __hash__(self):
"""Return a host of the tables"""
return hash(frozenset(str(self.tables)))
return hash(
tuple(
tuple(
sorted(
table,
key=lambda x: (
x.priority,
tuple(
(k, str(v)) for k, v in sorted(x.match_values.items())
),
),
)
)
for table in self.tables
)
)

def _apply_groupmod(self, ofmsg):
"""Maintain group table."""
Expand Down Expand Up @@ -863,7 +877,20 @@ def __str__(self):
string = ""
for table_id, table in enumerate(self.tables):
string += "\n----- Table %u -----\n" % (table_id)
string += "\n".join(sorted([str(flowmod) for flowmod in table]))
string += "\n".join(
[
str(flowmod)
for flowmod in sorted(
table,
key=lambda x: (
x.priority,
tuple(
(k, str(v)) for k, v in sorted(x.match_values.items())
),
),
)
]
)
return string

def sort_tables(self):
Expand Down Expand Up @@ -1051,10 +1078,10 @@ def __hash__(self):
return hash(
(
self.priority,
self.match_values,
self.match_masks,
tuple(sorted(self.match_values.items())),
tuple(sorted(self.match_masks.items())),
self.out_port,
self.instructions,
str(self.instructions),
)
)

Expand Down
6 changes: 1 addition & 5 deletions clib/valve_test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,7 @@ def _check_table_difference(self, before_hash, before_str, dp_id):
diff = difflib.unified_diff(
before_str.splitlines(), after_str.splitlines()
)
self.assertEqual(
before_hash,
after_hash,
msg="%s != %s\n".join(diff) % (before_hash, after_hash),
)
self.assertEqual(before_hash, after_hash, msg="\n" + "\n".join(diff))

def _verify_redundant_safe_offset_ofmsgs(self, ofmsgs, dp_id, offset=1):
"""
Expand Down