From 368eefac37c490ad4f63e5d40deb94c724cf25c5 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Mon, 10 Jun 2013 22:48:58 -0700 Subject: [PATCH] flow: Add new wildcard functions. Rename the function flow_wildcards_combine() to flow_wildcards_and(). Add new flow_wildcards_or() and flow_hash_in_wildcards() functions. These will be useful in a future patch. Signed-off-by: Ethan Jackson Signed-off-by: Justin Pettit --- lib/flow.c | 48 +++++++++++++++++++++++++++++++++++------ lib/flow.h | 13 ++++++++--- tests/test-classifier.c | 2 +- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/lib/flow.c b/lib/flow.c index 647602944..bf89fbc00 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -604,13 +604,13 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) return true; } -/* Initializes 'dst' as the combination of wildcards in 'src1' and 'src2'. - * That is, a bit or a field is wildcarded in 'dst' if it is wildcarded in - * 'src1' or 'src2' or both. */ +/* Sets 'dst' as the bitwise AND of wildcards in 'src1' and 'src2'. + * That is, a bit or a field is wildcarded in 'dst' if it is wildcarded + * in 'src1' or 'src2' or both. */ void -flow_wildcards_combine(struct flow_wildcards *dst, - const struct flow_wildcards *src1, - const struct flow_wildcards *src2) +flow_wildcards_and(struct flow_wildcards *dst, + const struct flow_wildcards *src1, + const struct flow_wildcards *src2) { uint32_t *dst_u32 = (uint32_t *) &dst->masks; const uint32_t *src1_u32 = (const uint32_t *) &src1->masks; @@ -622,6 +622,24 @@ flow_wildcards_combine(struct flow_wildcards *dst, } } +/* Sets 'dst' as the bitwise OR of wildcards in 'src1' and 'src2'. That + * is, a bit or a field is wildcarded in 'dst' if it is neither + * wildcarded in 'src1' nor 'src2'. */ +void +flow_wildcards_or(struct flow_wildcards *dst, + const struct flow_wildcards *src1, + const struct flow_wildcards *src2) +{ + uint32_t *dst_u32 = (uint32_t *) &dst->masks; + const uint32_t *src1_u32 = (const uint32_t *) &src1->masks; + const uint32_t *src2_u32 = (const uint32_t *) &src2->masks; + size_t i; + + for (i = 0; i < FLOW_U32S; i++) { + dst_u32[i] = src1_u32[i] | src2_u32[i]; + } +} + /* Perform a bitwise OR of miniflow 'src' flow data with the equivalent * fields in 'dst', storing the result in 'dst'. */ static void @@ -795,6 +813,24 @@ flow_hash_fields_valid(enum nx_hash_fields fields) || fields == NX_HASH_FIELDS_SYMMETRIC_L4; } +/* Returns a hash value for the bits of 'flow' that are active based on + * 'wc', given 'basis'. */ +uint32_t +flow_hash_in_wildcards(const struct flow *flow, + const struct flow_wildcards *wc, uint32_t basis) +{ + const uint32_t *wc_u32 = (const uint32_t *) &wc->masks; + const uint32_t *flow_u32 = (const uint32_t *) flow; + uint32_t hash; + size_t i; + + hash = basis; + for (i = 0; i < FLOW_U32S; i++) { + hash = mhash_add(hash, flow_u32[i] & wc_u32[i]); + } + return mhash_finish(hash, 4 * FLOW_U32S); +} + /* Sets the VLAN VID that 'flow' matches to 'vid', which is interpreted as an * OpenFlow 1.0 "dl_vlan" value: * diff --git a/lib/flow.h b/lib/flow.h index e52b633c9..ff18dc640 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -190,9 +190,12 @@ bool flow_wildcards_is_catchall(const struct flow_wildcards *); void flow_wildcards_set_reg_mask(struct flow_wildcards *, int idx, uint32_t mask); -void flow_wildcards_combine(struct flow_wildcards *dst, - const struct flow_wildcards *src1, - const struct flow_wildcards *src2); +void flow_wildcards_and(struct flow_wildcards *dst, + const struct flow_wildcards *src1, + const struct flow_wildcards *src2); +void flow_wildcards_or(struct flow_wildcards *dst, + const struct flow_wildcards *src1, + const struct flow_wildcards *src2); bool flow_wildcards_has_extra(const struct flow_wildcards *, const struct flow_wildcards *); @@ -209,6 +212,10 @@ uint32_t flow_hash_fields(const struct flow *, enum nx_hash_fields, const char *flow_hash_fields_to_str(enum nx_hash_fields); bool flow_hash_fields_valid(enum nx_hash_fields); +uint32_t flow_hash_in_wildcards(const struct flow *, + const struct flow_wildcards *, + uint32_t basis); + bool flow_equal_except(const struct flow *a, const struct flow *b, const struct flow_wildcards *); diff --git a/tests/test-classifier.c b/tests/test-classifier.c index da7bdcba8..f6164947b 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -1279,7 +1279,7 @@ test_minimask_combine(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) minimask_init(&minimask2, &mask2); minimask_combine(&minicombined, &minimask, &minimask2, storage); - flow_wildcards_combine(&combined, &mask, &mask2); + flow_wildcards_and(&combined, &mask, &mask2); minimask_expand(&minicombined, &combined2); assert(flow_wildcards_equal(&combined, &combined2)); -- 2.39.5