summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMinoru TAKAHASHI <takahashi.minoru7@gmail.com>2014-11-18 13:25:43 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-11-18 15:57:56 +0900
commit828b6f48c446cdfdc49e114d99a88c5c47d8ee68 (patch)
tree31e413ccdf85ced03486634a8e3fbd890f5e4310
parentb8d7db4076c13aa551db56d857e5e6d62f331198 (diff)
test_ofctl_v1_2/3: Add a test case of masked metadata
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/unit/lib/test_ofctl.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/ryu/tests/unit/lib/test_ofctl.py b/ryu/tests/unit/lib/test_ofctl.py
index e005efca..52d1b9a9 100644
--- a/ryu/tests/unit/lib/test_ofctl.py
+++ b/ryu/tests/unit/lib/test_ofctl.py
@@ -94,6 +94,26 @@ def _to_match_ipv6(value):
netmask = network.netmask.words
return ipv6, netmask
+
+def _to_match_metadata(value):
+ if '/' in value:
+ metadata = value.split('/')
+ return _str_to_int(metadata[0]), _str_to_int(metadata[1])
+ else:
+ return _str_to_int(value), ofproto_v1_2_parser.UINT64_MAX
+
+
+def _str_to_int(src):
+ if isinstance(src, str):
+ if src.startswith("0x") or src.startswith("0X"):
+ dst = int(src, 16)
+ else:
+ dst = int(src)
+ else:
+ dst = src
+ return dst
+
+
conv_dict = {
'eth_src': 'dl_src',
'eth_dst': 'dl_dst',
@@ -251,7 +271,12 @@ class Test_ofctl(unittest.TestCase):
eq_(mac.haddr_to_bin(value), field.value)
return
elif key == 'metadata':
- eq_(int(value, 16), field.value)
+ metadata, mask = _to_match_metadata(value)
+ metadata = metadata & mask
+ if mask == (1 << 64) - 1:
+ mask = None
+ eq_(metadata, field.value)
+ eq_(mask, field.mask)
return
else:
eq_(value, field.value)
@@ -310,7 +335,11 @@ class Test_ofctl(unittest.TestCase):
continue
return
elif key == 'metadata':
- eq_(str(int(value, 16)), match_str[key])
+ metadata_1, mask_1 = _to_match_metadata(value)
+ metadata_1 = metadata_1 & mask_1
+ metadata_2, mask_2 = _to_match_metadata(match_str[key])
+ eq_(metadata_1, metadata_2)
+ eq_(mask_1, mask_2)
return
eq_(value, match_str[key])
@@ -349,6 +378,7 @@ class test_data_v1_2():
{'in_port': 7},
{'in_phy_port': 5, 'in_port': 3},
{'metadata': '0x1212121212121212'},
+ {'metadata': '0x19af28be37fa91b/0x1010101010101010'},
{'dl_src': "aa:bb:cc:11:22:33"},
{'dl_src': "aa:bb:cc:11:22:33/00:00:00:00:ff:ff"},
{'dl_dst': "aa:bb:cc:11:22:33"},