File: Accept_empty_OXM_fields.patch

package info (click to toggle)
python-os-ken 3.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,320 kB
  • sloc: python: 100,703; erlang: 14,517; ansic: 594; sh: 338; makefile: 136
file content (68 lines) | stat: -rw-r--r-- 2,504 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Description: Accept empty "OXM" fields (tuple, list)
 When decoding an "OXM" field, now it is possible to accept
 and empty tuple or list. The value and the mask are considered as
 "None".
Author: lajoskatona <lajos.katona@est.tech>
Date: Wed, 10 Dec 2025 10:23:17 +0100
Bug: https://launchpad.net/bugs/2133487
Signed-off-by: lajoskatona <lajos.katona@est.tech>
Co-Authored-By: Rodolfo Alonso Hernandez <ralonsoh@redhat.com>
Change-Id: I9069337270cc261974c524a5ab284b055177ab3e
Origin: upstream, https://review.opendev.org/c/openstack/os-ken/+/972085
Last-Update: 2026-01-06

diff --git a/os_ken/ofproto/oxx_fields.py b/os_ken/ofproto/oxx_fields.py
index c37557f..84facd5 100644
--- a/os_ken/ofproto/oxx_fields.py
+++ b/os_ken/ofproto/oxx_fields.py
@@ -59,7 +59,10 @@
     # the 'list' case below is a bit hack; json.dumps silently maps
     # python tuples into json lists.
     if oxx == 'oxm' and isinstance(user_value, (tuple, list)):
-        (value, mask) = user_value
+        if not user_value:
+            value, mask = None, None
+        else:
+            (value, mask) = user_value
     else:
         value = user_value
         mask = None
diff --git a/os_ken/tests/unit/ofproto/test_oxm.py b/os_ken/tests/unit/ofproto/test_oxm.py
index 3a58ac9..1b00142 100644
--- a/os_ken/tests/unit/ofproto/test_oxm.py
+++ b/os_ken/tests/unit/ofproto/test_oxm.py
@@ -24,6 +24,8 @@
         (f, uv) = user
         (n, v, m) = ofp.oxm_from_user(f, uv)
         buf = bytearray()
+        m = b'' if m is None else m
+        v = b'' if v is None else v
         ofp.oxm_serialize(n, v, m, buf, 0)
         self.assertEqual(on_wire, buf)
 
@@ -46,9 +48,10 @@
         f = ofp.oxm_to_user_header(n)
         self.assertEqual(user, f)
 
-    def _test(self, user, on_wire, header_bytes):
+    def _test(self, user, on_wire, header_bytes, test_decode=True):
         self._test_encode(user, on_wire)
-        self._test_decode(user, on_wire)
+        if test_decode:
+            self._test_decode(user, on_wire)
         if isinstance(user[1], tuple):  # has mask?
             return
         user_header = user[0]
@@ -186,3 +189,12 @@
             b'fugafuga'
         )
         self._test(user, on_wire, 4)
+
+    def test_empty_values(self):
+        # This test is a corner case that rarely happens. The decoded
+        # information is empty.
+        user = ('ipv4_src', ())
+        on_wire = (
+            b'\x80\x00\x16\x00'
+        )
+        self._test(user, on_wire, 4, test_decode=False)