[ovs-dev] [PATCH 1/2] odp-util: Reuse UUID marshalling for UFID.

Joe Stringer joestringer at nicira.com
Tue Jun 2 01:22:19 UTC 2015


Unique flow identifiers are really a UUID of sorts, so it makes sense to
reuse the UUID string representations for UFID.

Suggested-by: Ben Pfaff <blp at nicira.com>
Signed-off-by: Joe Stringer <joestringer at nicira.com>
---
 lib/odp-util.c          | 36 ++++++++++--------------------------
 tests/dpif-netdev.at    |  2 +-
 tests/ofproto-dpif.at   |  2 +-
 tests/ofproto-macros.at |  2 +-
 4 files changed, 13 insertions(+), 29 deletions(-)

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 3204d16..4f74f07 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -37,6 +37,7 @@
 #include "timeval.h"
 #include "unaligned.h"
 #include "util.h"
+#include "uuid.h"
 #include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(odp_util);
@@ -51,8 +52,6 @@ VLOG_DEFINE_THIS_MODULE(odp_util);
  * from another. */
 static const char *delimiters = ", \t\r\n";
 
-static const char *hex_chars = "0123456789abcdefABCDEF";
-
 struct attr_len_tbl {
     int len;
     const struct attr_len_tbl *next;
@@ -2354,24 +2353,12 @@ odp_ufid_from_string(const char *s_, ovs_u128 *ufid)
     const char *s = s_;
 
     if (ovs_scan(s, "ufid:")) {
-        size_t n;
-
         s += 5;
-        if (ovs_scan(s, "0x")) {
-            s += 2;
-        }
-
-        n = strspn(s, hex_chars);
-        if (n != 32) {
-            return -EINVAL;
-        }
 
-        if (!ovs_scan(s, "%16"SCNx64"%16"SCNx64, &ufid->u64.hi,
-                      &ufid->u64.lo)) {
+        if (!uuid_from_string_prefix((struct uuid *)ufid, s)) {
             return -EINVAL;
         }
-        s += n;
-        s += strspn(s, delimiters);
+        s += UUID_LEN;
 
         return s - s_;
     }
@@ -2382,8 +2369,7 @@ odp_ufid_from_string(const char *s_, ovs_u128 *ufid)
 void
 odp_format_ufid(const ovs_u128 *ufid, struct ds *ds)
 {
-    ds_put_format(ds, "ufid:%016"PRIx64"%016"PRIx64, ufid->u64.hi,
-                  ufid->u64.lo);
+    ds_put_format(ds, "ufid:"UUID_FMT, UUID_ARGS((struct uuid *)ufid));
 }
 
 /* Appends to 'ds' a string representation of the 'key_len' bytes of
@@ -3218,15 +3204,13 @@ static int
 parse_odp_key_mask_attr(const char *s, const struct simap *port_names,
                         struct ofpbuf *key, struct ofpbuf *mask)
 {
-    if (!strncmp(s, "ufid:", 5)) {
-        const char *start = s;
-
-        /* Skip UFID. */
-        s += 5;
-        s += strspn(s, hex_chars);
-        s += strspn(s, delimiters);
+    ovs_u128 ufid;
+    int len;
 
-        return s - start;
+    /* Skip UFID. */
+    len = odp_ufid_from_string(s, &ufid);
+    if (len) {
+        return len;
     }
 
     SCAN_SINGLE("skb_priority(", uint32_t, u32, OVS_KEY_ATTR_PRIORITY);
diff --git a/tests/dpif-netdev.at b/tests/dpif-netdev.at
index 067f900..e9af63f 100644
--- a/tests/dpif-netdev.at
+++ b/tests/dpif-netdev.at
@@ -3,7 +3,7 @@ AT_BANNER([dpif-netdev])
 # Strips out uninteresting parts of flow output, as well as parts
 # that vary from one run to another (e.g., timing and bond actions).
 m4_define([STRIP_XOUT], [[sed '
-    s/ufid:[0-9a-f]* //
+    s/ufid:[-0-9a-f]* //
     s/used:[0-9]*\.[0-9]*/used:0.0/
     s/actions:.*/actions: <del>/
     s/packets:[0-9]*/packets:0/
diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at
index b5a9ad9..98783fa 100644
--- a/tests/ofproto-dpif.at
+++ b/tests/ofproto-dpif.at
@@ -5460,7 +5460,7 @@ AT_CHECK([ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:
 ovs-appctl revalidator/wait
 AT_CHECK([ovs-appctl dpif/dump-flows -m br0], [0], [stdout])
 
-UFID=`sed -n 's/\(ufid:[[0-9a-fA-F]]*\).*/\1/p' stdout`
+UFID=`sed -n 's/\(ufid:[[-0-9a-fA-F]]*\).*/\1/p' stdout`
 AT_CHECK([ovs-appctl dpctl/get-flow $UFID], [0], [dnl
 recirc_id(0),in_port(1),eth_type(0x0800),ipv4(frag=no), packets:0, bytes:0, used:never, actions:drop
 ])
diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
index fd915ef..a69719b 100644
--- a/tests/ofproto-macros.at
+++ b/tests/ofproto-macros.at
@@ -36,7 +36,7 @@ m4_divert_pop([PREPARE_TESTS])
 m4_define([STRIP_XIDS], [[sed 's/ (xid=0x[0-9a-fA-F]*)//']])
 m4_define([STRIP_DURATION], [[sed 's/\bduration=[0-9.]*s/duration=?s/']])
 m4_define([STRIP_USED], [[sed 's/used:[0-9]\.[0-9]*/used:0.0/']])
-m4_define([STRIP_UFID], [[sed 's/ufid:[0-9a-f]* //']])
+m4_define([STRIP_UFID], [[sed 's/ufid:[-0-9a-f]* //']])
 m4_define([TESTABLE_LOG], [-vPATTERN:ANY:'%c|%p|%m'])
 
 # _OVS_VSWITCHD_START([vswitchd-aux-args])
-- 
2.1.4




More information about the dev mailing list