summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAdrian Moreno <amorenoz@redhat.com>2022-12-19 17:13:47 +0100
committerIlya Maximets <i.maximets@ovn.org>2022-12-21 18:36:02 +0100
commit1850e5e6891282d84bdeb7b7100166cfd8deed28 (patch)
treeb92e03826f72b0ecb0dd09303837b6ad4392024b /python
parent75a6e8db9c5f9dc2887cae1555d977f0fdf08471 (diff)
downloadopenvswitch-1850e5e6891282d84bdeb7b7100166cfd8deed28.tar.gz
python: Support case-insensitive OpenFlow actions.
OpenFlow actions names can be capitalized so in order to support this, support case-insensitive KVDecoders and use it in Openflow actions. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'python')
-rw-r--r--python/ovs/flow/kv.py17
-rw-r--r--python/ovs/flow/ofp.py7
-rw-r--r--python/ovs/tests/test_ofp.py15
3 files changed, 33 insertions, 6 deletions
diff --git a/python/ovs/flow/kv.py b/python/ovs/flow/kv.py
index 3138db008..f7d7be0cf 100644
--- a/python/ovs/flow/kv.py
+++ b/python/ovs/flow/kv.py
@@ -105,10 +105,17 @@ class KVDecoders(object):
strict = True
- def __init__(self, decoders=None, default=None, default_free=None):
- self._decoders = decoders or dict()
+ def __init__(self, decoders=None, default=None, default_free=None,
+ ignore_case=False):
+ if not decoders:
+ self._decoders = dict()
+ elif ignore_case:
+ self._decoders = {k.lower(): v for k, v in decoders.items()}
+ else:
+ self._decoders = decoders
self._default = default
self._default_free = default_free or self._default_free_decoder
+ self._ignore_case = ignore_case
def decode(self, keyword, value_str):
"""Decode a keyword and value.
@@ -121,7 +128,11 @@ class KVDecoders(object):
The key (str) and value(any) to be stored.
"""
- decoder = self._decoders.get(keyword)
+ decoder = None
+ if self._ignore_case:
+ decoder = self._decoders.get(keyword.lower())
+ else:
+ decoder = self._decoders.get(keyword)
if decoder:
result = decoder(value_str)
if isinstance(result, KeyValue):
diff --git a/python/ovs/flow/ofp.py b/python/ovs/flow/ofp.py
index 8f2727361..bf832f71b 100644
--- a/python/ovs/flow/ofp.py
+++ b/python/ovs/flow/ofp.py
@@ -246,7 +246,8 @@ class OFPFlow(Flow):
}
clone_actions = OFPFlow._clone_actions_decoders_args(actions)
actions.update(clone_actions)
- return KVDecoders(actions, default_free=decode_free_output)
+ return KVDecoders(actions, default_free=decode_free_output,
+ ignore_case=True)
@staticmethod
def _output_actions_decoders_args():
@@ -401,10 +402,10 @@ class OFPFlow(Flow):
return {
"learn": decode_learn(action_decoders),
"clone": nested_kv_decoder(
- KVDecoders(action_decoders), is_list=True
+ KVDecoders(action_decoders, ignore_case=True), is_list=True
),
"write_actions": nested_kv_decoder(
- KVDecoders(action_decoders), is_list=True
+ KVDecoders(action_decoders, ignore_case=True), is_list=True
),
}
diff --git a/python/ovs/tests/test_ofp.py b/python/ovs/tests/test_ofp.py
index 328ab7285..5aa8d591b 100644
--- a/python/ovs/tests/test_ofp.py
+++ b/python/ovs/tests/test_ofp.py
@@ -510,6 +510,21 @@ from ovs.flow.decoders import EthMask, IPMask, decode_mask
],
),
(
+ "actions=POP_VLAN,push_vlan:0x8100,NORMAL,clone(MOD_NW_SRC:192.168.1.1,resubmit(,10))", # noqa: E501
+ [
+ KeyValue("POP_VLAN", True),
+ KeyValue("push_vlan", 0x8100),
+ KeyValue("output", {"port": "NORMAL"}),
+ KeyValue(
+ "clone",
+ [
+ {"MOD_NW_SRC": netaddr.IPAddress("192.168.1.1")},
+ {"resubmit": {"port": "", "table": 10}},
+ ]
+ ),
+ ],
+ ),
+ (
"actions=doesnotexist(1234)",
ParseError,
),