[ovs-dev] [PATCH 3/3] extract-ofp-fields: Detect duplicate fields.

Joe Stringer joestringer at nicira.com
Wed May 20 20:41:15 UTC 2015


Figure out if a developer accidentally defines new NXM fields using an
existing number, and warn them. Useful particularly if new fields are
introduced upstream while rebasing an in-progress patchset.

Signed-off-by: Joe Stringer <joestringer at nicira.com>
---
 build-aux/extract-ofp-fields | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/build-aux/extract-ofp-fields b/build-aux/extract-ofp-fields
index f05487e..6f6f8ec 100755
--- a/build-aux/extract-ofp-fields
+++ b/build-aux/extract-ofp-fields
@@ -76,7 +76,7 @@ def oxm_name_to_class(name):
         if name.startswith(p) and len(p) > len(prefix):
             prefix = p
             class_ = c
-    return class_
+    return (prefix, class_)
 
 
 def decode_version_range(range):
@@ -141,18 +141,31 @@ def parse_oxms(s, prefix, n_bytes):
     return tuple(parse_oxm(s2.strip(), prefix, n_bytes) for s2 in s.split(','))
 
 
+match_types = dict()
+
+
 def parse_oxm(s, prefix, n_bytes):
+    global match_types
+
     m = re.match('([A-Z0-9_]+)\(([0-9]+)\) since(?: OF(1\.[0-9]+) and)? v([12]\.[0-9]+)$', s)
     if not m:
         fatal("%s: syntax error parsing %s" % (s, prefix))
 
     name, oxm_type, of_version, ovs_version = m.groups()
 
-    class_ = oxm_name_to_class(name)
+    prefix, class_ = oxm_name_to_class(name)
     if class_ is None:
         fatal("unknown OXM class for %s" % name)
     oxm_vendor, oxm_class = class_
 
+    if prefix in match_types:
+        if oxm_type in match_types[prefix]:
+            fatal("duplicate match type for %s (conflicts with %s)" %
+                  (name, match_types[prefix][oxm_type]))
+    else:
+        match_types[prefix] = dict()
+    match_types[prefix][oxm_type] = name
+
     # Normally the oxm_length is the size of the field, but for experimenter
     # OXMs oxm_length also includes the 4-byte experimenter ID.
     oxm_length = n_bytes
-- 
2.1.4




More information about the dev mailing list