diff mbox series

[ovs-dev,v1,06/11] python: support case-insensitive OpenFlow actions

Message ID 20221123100303.323460-6-amorenoz@redhat.com
State Superseded
Headers show
Series [ovs-dev,v1,01/11] python: fix datapath flow decoders | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Adrian Moreno Nov. 23, 2022, 10:02 a.m. UTC
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 python/ovs/flow/kv.py        | 17 ++++++++++++++---
 python/ovs/flow/ofp.py       |  7 ++++---
 python/ovs/tests/test_ofp.py | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 6 deletions(-)

Comments

Mike Pattrick Nov. 23, 2022, 2:02 p.m. UTC | #1
On Wed, Nov 23, 2022 at 5:03 AM Adrian Moreno <amorenoz@redhat.com> wrote:
>

I believe the commit message was cut out.

> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
> ---
>  python/ovs/flow/kv.py        | 17 ++++++++++++++---
>  python/ovs/flow/ofp.py       |  7 ++++---
>  python/ovs/tests/test_ofp.py | 15 +++++++++++++++
>  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
> @@ -509,6 +509,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,
> --
> 2.38.1
>
Adrian Moreno Dec. 19, 2022, 4:05 p.m. UTC | #2
On 11/23/22 15:02, Mike Pattrick wrote:
> On Wed, Nov 23, 2022 at 5:03 AM Adrian Moreno <amorenoz@redhat.com> wrote:
>>
> 
> I believe the commit message was cut out.
> 

Hey Mike, sorry I missed this message.
I have no idea what happened between format-patch and git-send. Sending the same 
series again.


>> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
>> ---
>>   python/ovs/flow/kv.py        | 17 ++++++++++++++---
>>   python/ovs/flow/ofp.py       |  7 ++++---
>>   python/ovs/tests/test_ofp.py | 15 +++++++++++++++
>>   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
>> @@ -509,6 +509,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,
>> --
>> 2.38.1
>>
>
diff mbox series

Patch

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
@@ -509,6 +509,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,