[ovs-dev] [generic tci mask 1/8] classifier: New function cls_rule_equal().

Justin Pettit jpettit at nicira.com
Fri Nov 19 22:23:57 UTC 2010


Looks good.

--Justin


On Nov 10, 2010, at 3:37 PM, Ben Pfaff wrote:

> ---
> lib/classifier.c        |   10 ++++++++++
> lib/classifier.h        |    2 ++
> tests/test-classifier.c |   13 +++----------
> 3 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/classifier.c b/lib/classifier.c
> index 591322e..4bf354e 100644
> --- a/lib/classifier.c
> +++ b/lib/classifier.c
> @@ -306,6 +306,16 @@ cls_rule_set_icmp_code(struct cls_rule *rule, uint8_t icmp_code)
>     rule->flow.icmp_code = htons(icmp_code);
> }
> 
> +/* Returns true if 'a' and 'b' have the same priority, wildcard the same
> + * fields, and have the same values for fixed fields, otherwise false. */
> +bool
> +cls_rule_equal(const struct cls_rule *a, const struct cls_rule *b)
> +{
> +    return (a->priority == b->priority
> +            && flow_wildcards_equal(&a->wc, &b->wc)
> +            && flow_equal(&a->flow, &b->flow));
> +}
> +
> /* Converts 'rule' to a string and returns the string.  The caller must free
>  * the string (with free()). */
> char *
> diff --git a/lib/classifier.h b/lib/classifier.h
> index c22a161..ea4d6fc 100644
> --- a/lib/classifier.h
> +++ b/lib/classifier.h
> @@ -96,6 +96,8 @@ void cls_rule_set_nw_tos(struct cls_rule *, uint8_t);
> void cls_rule_set_icmp_type(struct cls_rule *, uint8_t);
> void cls_rule_set_icmp_code(struct cls_rule *, uint8_t);
> 
> +bool cls_rule_equal(const struct cls_rule *, const struct cls_rule *);
> +
> char *cls_rule_to_string(const struct cls_rule *);
> void cls_rule_print(const struct cls_rule *);
> 
> diff --git a/tests/test-classifier.c b/tests/test-classifier.c
> index b77835f..581b6ef 100644
> --- a/tests/test-classifier.c
> +++ b/tests/test-classifier.c
> @@ -139,11 +139,8 @@ tcls_insert(struct tcls *tcls, const struct test_rule *rule)
>     assert(rule->cls_rule.wc.wildcards || rule->cls_rule.priority == UINT_MAX);
>     for (i = 0; i < tcls->n_rules; i++) {
>         const struct cls_rule *pos = &tcls->rules[i]->cls_rule;
> -        if (pos->priority == rule->cls_rule.priority
> -            && pos->wc.wildcards == rule->cls_rule.wc.wildcards
> -            && flow_equal(&pos->flow, &rule->cls_rule.flow)) {
> -            /* Exact match.
> -             * XXX flow_equal should ignore wildcarded fields */
> +        if (cls_rule_equal(pos, &rule->cls_rule)) {
> +            /* Exact match. */
>             free(tcls->rules[i]);
>             tcls->rules[i] = xmemdup(rule, sizeof *rule);
>             return tcls->rules[i];
> @@ -383,11 +380,7 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls)
>             const struct test_rule *tr0 = test_rule_from_cls_rule(cr0);
>             const struct test_rule *tr1 = test_rule_from_cls_rule(cr1);
> 
> -            assert(flow_equal(&cr0->flow, &cr1->flow));
> -            assert(cr0->wc.wildcards == cr1->wc.wildcards);
> -            assert(cr0->priority == cr1->priority);
> -            /* Skip nw_src_mask and nw_dst_mask, because they are derived
> -             * members whose values are used only for optimization. */
> +            assert(cls_rule_equal(cr0, cr1));
>             assert(tr0->aux == tr1->aux);
>         }
>     }
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org





More information about the dev mailing list