[ovs-dev] [overload 6/7] classifier: Introduce macros for iterating exact-match flows.

Justin Pettit jpettit at nicira.com
Thu Oct 7 07:12:18 UTC 2010


Looks good.  You'll need to update your HMAP_FOR_EACH(_SAFE) functions to not take a struct argument, since the HMAP changes you pushed last week remove it. 

--Justin


On Sep 30, 2010, at 5:17 PM, Ben Pfaff wrote:

> This special case of iterating through flows is easier and presumably
> faster to implement using a macro.
> ---
> lib/classifier.c  |    5 ++++-
> lib/classifier.h  |    7 +++++++
> ofproto/ofproto.c |   18 ++++++------------
> 3 files changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/lib/classifier.c b/lib/classifier.c
> index 378faf8..8e5c1a6 100644
> --- a/lib/classifier.c
> +++ b/lib/classifier.c
> @@ -465,7 +465,10 @@ classifier_for_each_match(const struct classifier *cls,
>  * it must not delete (or move) any other rules in 'cls' that are in the same
>  * table as the argument rule.  Two rules are in the same table if their
>  * cls_rule structs have the same table_idx; as a special case, a rule with
> - * wildcards and an exact-match rule will never be in the same table. */
> + * wildcards and an exact-match rule will never be in the same table.
> + *
> + * If 'include' is CLS_INC_EXACT then CLASSIFIER_FOR_EACH_EXACT_RULE(_SAFE) is
> + * probably easier to use. */
> void
> classifier_for_each(const struct classifier *cls, int include,
>                     void (*callback)(struct cls_rule *, void *aux),
> diff --git a/lib/classifier.h b/lib/classifier.h
> index f522f0e..24a3563 100644
> --- a/lib/classifier.h
> +++ b/lib/classifier.h
> @@ -168,4 +168,11 @@ struct cls_rule *classifier_find_rule_exactly(const struct classifier *,
>                                               uint32_t wildcards,
>                                               unsigned int priority);
> 
> +#define CLASSIFIER_FOR_EACH_EXACT_RULE(RULE, STRUCT, MEMBER, CLS)   \
> +        HMAP_FOR_EACH (RULE, STRUCT, MEMBER.node.hmap, &(CLS)->exact_table)
> +
> +#define CLASSIFIER_FOR_EACH_EXACT_RULE_SAFE(RULE, NEXT, CLS) \
> +        HMAP_FOR_EACH_SAFE (RULE, NEXT, STRUCT, MEMBER.node.hmap, \
> +                            &(CLS)->exact_table)
> +
> #endif /* classifier.h */
> diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
> index 0f07b23..87034ad 100644
> --- a/ofproto/ofproto.c
> +++ b/ofproto/ofproto.c
> @@ -3007,17 +3007,6 @@ handle_desc_stats_request(struct ofproto *p, struct ofconn *ofconn,
>     return 0;
> }
> 
> -static void
> -count_subrules(struct cls_rule *cls_rule, void *n_subrules_)
> -{
> -    struct rule *rule = rule_from_cls_rule(cls_rule);
> -    int *n_subrules = n_subrules_;
> -
> -    if (rule->super) {
> -        (*n_subrules)++;
> -    }
> -}
> -
> static int
> handle_table_stats_request(struct ofproto *p, struct ofconn *ofconn,
>                            struct ofp_stats_request *request)
> @@ -3026,12 +3015,17 @@ handle_table_stats_request(struct ofproto *p, struct ofconn *ofconn,
>     struct ofpbuf *msg;
>     struct odp_stats dpstats;
>     int n_exact, n_subrules, n_wild;
> +    struct rule *rule;
> 
>     msg = start_stats_reply(request, sizeof *ots * 2);
> 
>     /* Count rules of various kinds. */
>     n_subrules = 0;
> -    classifier_for_each(&p->cls, CLS_INC_EXACT, count_subrules, &n_subrules);
> +    CLASSIFIER_FOR_EACH_EXACT_RULE (rule, struct rule, cr, &p->cls) {
> +        if (rule->super) {
> +            n_subrules++;
> +        }
> +    }
>     n_exact = classifier_count_exact(&p->cls) - n_subrules;
>     n_wild = classifier_count(&p->cls) - classifier_count_exact(&p->cls);
> 
> -- 
> 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