From: Ben Pfaff Date: Wed, 4 Mar 2009 20:25:29 +0000 (-0800) Subject: classifier: Add tests for classifier_lookup_wild(), classifier_lookup_exact(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47a9658c5b071a46713b3c79b87b0023496c3c24;p=openvswitch classifier: Add tests for classifier_lookup_wild(), classifier_lookup_exact(). --- diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 53bf0002..20fd7c23 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -189,13 +189,15 @@ match(const struct cls_rule *wild, const flow_t *fixed) } static struct cls_rule * -tcls_lookup(const struct tcls *cls, const flow_t *flow) +tcls_lookup(const struct tcls *cls, const flow_t *flow, int include) { size_t i; for (i = 0; i < cls->n_rules; i++) { struct test_rule *pos = cls->rules[i]; - if (match(&pos->cls_rule, flow)) { + uint32_t wildcards = pos->cls_rule.wc.wildcards; + if (include & (wildcards ? CLS_INC_WILD : CLS_INC_EXACT) + && match(&pos->cls_rule, flow)) { return &pos->cls_rule; } } @@ -295,6 +297,22 @@ get_value(unsigned int *x, unsigned n_values) return rem; } +static struct cls_rule * +lookup_with_include_bits(const struct classifier *cls, + const flow_t *flow, int include) +{ + switch (include) { + case CLS_INC_WILD: + return classifier_lookup_wild(cls, flow); + case CLS_INC_EXACT: + return classifier_lookup_exact(cls, flow); + case CLS_INC_WILD | CLS_INC_EXACT: + return classifier_lookup(cls, flow); + default: + abort(); + } +} + static void compare_classifiers(struct classifier *cls, struct tcls *tcls) { @@ -304,6 +322,7 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) struct cls_rule *cr0, *cr1; flow_t flow; unsigned int x; + int include; x = i; flow.nw_src = nw_src_values[get_value(&x, N_NW_SRC_VALUES)]; @@ -320,19 +339,21 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) flow.nw_proto = nw_proto_values[get_value(&x, N_NW_PROTO_VALUES)]; flow.reserved = 0; - cr0 = classifier_lookup(cls, &flow); - cr1 = tcls_lookup(tcls, &flow); - assert((cr0 == NULL) == (cr1 == NULL)); - if (cr0 != NULL) { - 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(tr0->aux == tr1->aux); + for (include = 1; include <= 3; include++) { + cr0 = lookup_with_include_bits(cls, &flow, include); + cr1 = tcls_lookup(tcls, &flow, include); + assert((cr0 == NULL) == (cr1 == NULL)); + if (cr0 != NULL) { + 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(tr0->aux == tr1->aux); + } } } }