diff options
author | Yuichi Ito <ito.yuichi0@gmail.com> | 2014-04-18 16:38:39 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-04-18 18:42:49 +0900 |
commit | 51ec3d2d7bb386aa1a836bcca59bab8f475f886f (patch) | |
tree | ec9e0cfda72269c5aef6ead0b9df0e066890909c | |
parent | 660c8e68b476757a83ff3c413e76621592fb8c4f (diff) |
sw test tool: Fix to compare OFPMatch using masks without byte boundary
Mask lengths without byte boundary are fixed as follows:
- VLAN_VID, from 16 bits (2 bytes) to 12 + 1 bits
- IPV6_EXTHDR, from 16 bits (2 bytes) to 9 bits
Reported-by: Arne Goetje <arne_goetje@accton.com>
Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/switch/tester.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ryu/tests/switch/tester.py b/ryu/tests/switch/tester.py index 8954b211..c5571914 100644 --- a/ryu/tests/switch/tester.py +++ b/ryu/tests/switch/tester.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import binascii import inspect import json import logging @@ -782,6 +783,8 @@ class OfTester(app_manager.RyuApp): def __reasm_match(match): """ reassemble match_fields. """ + mask_lengths = {'vlan_vid': 12 + 1, + 'ipv6_exthdr': 9} match_fields = list() for key, united_value in match.iteritems(): if isinstance(united_value, tuple): @@ -789,12 +792,18 @@ class OfTester(app_manager.RyuApp): # look up oxm_fields.TypeDescr to get mask length. for ofb in ofproto_v1_3.oxm_types: if ofb.name == key: - mbytes = ofb.type.from_user(mask) + # create all one bits mask + mask_len = mask_lengths.get( + key, ofb.type.size * 8) + all_one_bits = 2 ** mask_len - 1 + # convert mask to integer + mask_bytes = ofb.type.from_user(mask) + oxm_mask = int(binascii.hexlify(mask_bytes), 16) # when mask is all one bits, remove mask - if mbytes == '\xff' * ofb.type.size: + if oxm_mask & all_one_bits == all_one_bits: united_value = value # when mask is all zero bits, remove field. - elif mbytes == '\x00' * ofb.type.size: + elif oxm_mask & all_one_bits == 0: united_value = None break if united_value is not None: |