2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-03 15:55:19 +00:00

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 <ethan@nicira.com>
Signed-off-by: Justin Pettit <jpettit@nicira.com>
This commit is contained in:
Ethan Jackson
2013-06-10 22:48:58 -07:00
committed by Justin Pettit
parent 74f74083e6
commit 368eefac37
3 changed files with 53 additions and 10 deletions

View File

@@ -604,11 +604,11 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc)
return true; return true;
} }
/* Initializes 'dst' as the combination of wildcards in 'src1' and 'src2'. /* 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 * That is, a bit or a field is wildcarded in 'dst' if it is wildcarded
* 'src1' or 'src2' or both. */ * in 'src1' or 'src2' or both. */
void void
flow_wildcards_combine(struct flow_wildcards *dst, flow_wildcards_and(struct flow_wildcards *dst,
const struct flow_wildcards *src1, const struct flow_wildcards *src1,
const struct flow_wildcards *src2) const struct flow_wildcards *src2)
{ {
@@ -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 /* Perform a bitwise OR of miniflow 'src' flow data with the equivalent
* fields in 'dst', storing the result in 'dst'. */ * fields in 'dst', storing the result in 'dst'. */
static void static void
@@ -795,6 +813,24 @@ flow_hash_fields_valid(enum nx_hash_fields fields)
|| fields == NX_HASH_FIELDS_SYMMETRIC_L4; || 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 /* Sets the VLAN VID that 'flow' matches to 'vid', which is interpreted as an
* OpenFlow 1.0 "dl_vlan" value: * OpenFlow 1.0 "dl_vlan" value:
* *

View File

@@ -190,7 +190,10 @@ bool flow_wildcards_is_catchall(const struct flow_wildcards *);
void flow_wildcards_set_reg_mask(struct flow_wildcards *, void flow_wildcards_set_reg_mask(struct flow_wildcards *,
int idx, uint32_t mask); int idx, uint32_t mask);
void flow_wildcards_combine(struct flow_wildcards *dst, 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 *src1,
const struct flow_wildcards *src2); const struct flow_wildcards *src2);
bool flow_wildcards_has_extra(const struct flow_wildcards *, bool flow_wildcards_has_extra(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); const char *flow_hash_fields_to_str(enum nx_hash_fields);
bool flow_hash_fields_valid(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, bool flow_equal_except(const struct flow *a, const struct flow *b,
const struct flow_wildcards *); const struct flow_wildcards *);

View File

@@ -1279,7 +1279,7 @@ test_minimask_combine(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
minimask_init(&minimask2, &mask2); minimask_init(&minimask2, &mask2);
minimask_combine(&minicombined, &minimask, &minimask2, storage); minimask_combine(&minicombined, &minimask, &minimask2, storage);
flow_wildcards_combine(&combined, &mask, &mask2); flow_wildcards_and(&combined, &mask, &mask2);
minimask_expand(&minicombined, &combined2); minimask_expand(&minicombined, &combined2);
assert(flow_wildcards_equal(&combined, &combined2)); assert(flow_wildcards_equal(&combined, &combined2));