[ovs-dev] [xc_v2 2/4] flow: Add new flow_wildcards_fold_minimask() function.

Justin Pettit jpettit at nicira.com
Fri Jun 7 09:03:38 UTC 2013


From: Ethan Jackson <ethan at nicira.com>

This function will be useful in a future commit.

Signed-off-by: Ethan Jackson <ethan at nicira.com>
Co-authored-by: Justin Pettit <jpettit at nicira.com>
Signed-off-by: Justin Pettit <jpettit at nicira.com>
---
 lib/flow.c |   43 +++++++++++++++++++++++++++++--------------
 lib/flow.h |    3 +++
 2 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index 3c12984..6476029 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -622,6 +622,33 @@ flow_wildcards_combine(struct flow_wildcards *dst,
     }
 }
 
+/* Perform a bitwise OR of miniflow 'src' flow data with the equivalent
+ * fields in 'dst', storing the result in 'dst'. */
+static void
+flow_union_with_miniflow(struct flow *dst, const struct miniflow *src)
+{
+    uint32_t *dst_u32 = (uint32_t *) dst;
+    int ofs;
+    int i;
+
+    ofs = 0;
+    for (i = 0; i < MINI_N_MAPS; i++) {
+        uint32_t map;
+
+        for (map = src->map[i]; map; map = zero_rightmost_1bit(map)) {
+            dst_u32[raw_ctz(map) + i * 32] |= src->values[ofs++];
+        }
+    }
+}
+
+/* Fold minimask 'mask''s wildcard mask into 'wc's wildcard mask. */
+void
+flow_wildcards_fold_minimask(struct flow_wildcards *wc,
+                             const struct minimask *mask)
+{
+    flow_union_with_miniflow(&wc->masks, &mask->masks);
+}
+
 /* Returns a hash of the wildcards in 'wc'. */
 uint32_t
 flow_wildcards_hash(const struct flow_wildcards *wc, uint32_t basis)
@@ -1024,20 +1051,8 @@ miniflow_destroy(struct miniflow *flow)
 void
 miniflow_expand(const struct miniflow *src, struct flow *dst)
 {
-    uint32_t *dst_u32 = (uint32_t *) dst;
-    int ofs;
-    int i;
-
-    memset(dst_u32, 0, sizeof *dst);
-
-    ofs = 0;
-    for (i = 0; i < MINI_N_MAPS; i++) {
-        uint32_t map;
-
-        for (map = src->map[i]; map; map = zero_rightmost_1bit(map)) {
-            dst_u32[raw_ctz(map) + i * 32] = src->values[ofs++];
-        }
-    }
+    memset(dst, 0, sizeof *dst);
+    flow_union_with_miniflow(dst, src);
 }
 
 static const uint32_t *
diff --git a/lib/flow.h b/lib/flow.h
index 0fdf4ef..e52b633 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -196,6 +196,9 @@ void flow_wildcards_combine(struct flow_wildcards *dst,
 bool flow_wildcards_has_extra(const struct flow_wildcards *,
                               const struct flow_wildcards *);
 
+void flow_wildcards_fold_minimask(struct flow_wildcards *,
+                                  const struct minimask *);
+
 uint32_t flow_wildcards_hash(const struct flow_wildcards *, uint32_t basis);
 bool flow_wildcards_equal(const struct flow_wildcards *,
                           const struct flow_wildcards *);
-- 
1.7.5.4




More information about the dev mailing list