X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Ftest-classifier.c;h=6cecef75f3932ffd1b5d555fd07289b63420346e;hb=96fc46e8fdafd6467906e11e0fb493e2b78f2fb5;hp=783c59e243d2d7bd736b33cdda793f40303828a7;hpb=c0a56d9fe1fdb57220b9c1e2f709ea2db5d6489d;p=openvswitch diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 783c59e2..6cecef75 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -125,19 +125,6 @@ tcls_destroy(struct tcls *tcls) } } -static int -tcls_count_exact(const struct tcls *tcls) -{ - int n_exact; - size_t i; - - n_exact = 0; - for (i = 0; i < tcls->n_rules; i++) { - n_exact += tcls->rules[i]->cls_rule.wc.wildcards == 0; - } - return n_exact; -} - static bool tcls_is_empty(const struct tcls *tcls) { @@ -229,15 +216,13 @@ match(const struct cls_rule *wild, const struct flow *fixed) } static struct cls_rule * -tcls_lookup(const struct tcls *cls, const struct flow *flow, int include) +tcls_lookup(const struct tcls *cls, const struct flow *flow) { size_t i; for (i = 0; i < cls->n_rules; i++) { struct test_rule *pos = cls->rules[i]; - uint32_t wildcards = pos->cls_rule.wc.wildcards; - if (include & (wildcards ? CLS_INC_WILD : CLS_INC_EXACT) - && match(&pos->cls_rule, flow)) { + if (match(&pos->cls_rule, flow)) { return &pos->cls_rule; } } @@ -245,17 +230,13 @@ tcls_lookup(const struct tcls *cls, const struct flow *flow, int include) } static void -tcls_delete_matches(struct tcls *cls, - const struct cls_rule *target, - int include) +tcls_delete_matches(struct tcls *cls, const struct cls_rule *target) { size_t i; for (i = 0; i < cls->n_rules; ) { struct test_rule *pos = cls->rules[i]; - uint32_t wildcards = pos->cls_rule.wc.wildcards; - if (include & (wildcards ? CLS_INC_WILD : CLS_INC_EXACT) - && !flow_wildcards_has_extra(&pos->cls_rule.wc, &target->wc) + if (!flow_wildcards_has_extra(&pos->cls_rule.wc, &target->wc) && match(target, &pos->cls_rule.flow)) { tcls_remove(cls, pos); } else { @@ -264,20 +245,19 @@ tcls_delete_matches(struct tcls *cls, } } -static uint32_t nw_src_values[] = { CONSTANT_HTONL(0xc0a80001), +static ovs_be32 nw_src_values[] = { CONSTANT_HTONL(0xc0a80001), CONSTANT_HTONL(0xc0a04455) }; -static uint32_t nw_dst_values[] = { CONSTANT_HTONL(0xc0a80002), +static ovs_be32 nw_dst_values[] = { CONSTANT_HTONL(0xc0a80002), CONSTANT_HTONL(0xc0a04455) }; -static uint32_t tun_id_values[] = { 0, 0xffff0000 }; -static uint16_t in_port_values[] = { CONSTANT_HTONS(1), - CONSTANT_HTONS(OFPP_LOCAL) }; -static uint16_t dl_vlan_values[] = { CONSTANT_HTONS(101), CONSTANT_HTONS(0) }; +static ovs_be32 tun_id_values[] = { 0, 0xffff0000 }; +static uint16_t in_port_values[] = { 1, ODPP_LOCAL }; +static ovs_be16 dl_vlan_values[] = { CONSTANT_HTONS(101), CONSTANT_HTONS(0) }; static uint8_t dl_vlan_pcp_values[] = { 7, 0 }; -static uint16_t dl_type_values[] +static ovs_be16 dl_type_values[] = { CONSTANT_HTONS(ETH_TYPE_IP), CONSTANT_HTONS(ETH_TYPE_ARP) }; -static uint16_t tp_src_values[] = { CONSTANT_HTONS(49362), +static ovs_be16 tp_src_values[] = { CONSTANT_HTONS(49362), CONSTANT_HTONS(80) }; -static uint16_t tp_dst_values[] = { CONSTANT_HTONS(6667), CONSTANT_HTONS(22) }; +static ovs_be16 tp_dst_values[] = { CONSTANT_HTONS(6667), CONSTANT_HTONS(22) }; static uint8_t dl_src_values[][6] = { { 0x00, 0x02, 0xe3, 0x0f, 0x80, 0xa4 }, { 0x5e, 0x33, 0x7f, 0x5f, 0x1e, 0x99 } }; static uint8_t dl_dst_values[][6] = { { 0x4a, 0x27, 0x71, 0xae, 0x64, 0xc1 }, @@ -373,12 +353,10 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) unsigned int i; assert(classifier_count(cls) == tcls->n_rules); - assert(classifier_count_exact(cls) == tcls_count_exact(tcls)); for (i = 0; i < confidence; i++) { struct cls_rule *cr0, *cr1; struct flow flow; unsigned int x; - int include; x = rand () % N_FLOW_VALUES; flow.nw_src = nw_src_values[get_value(&x, N_NW_SRC_VALUES)]; @@ -398,21 +376,19 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) flow.nw_proto = nw_proto_values[get_value(&x, N_NW_PROTO_VALUES)]; flow.nw_tos = nw_tos_values[get_value(&x, N_NW_TOS_VALUES)]; - for (include = 1; include <= 3; include++) { - cr0 = classifier_lookup(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); - } + 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); } } } @@ -427,7 +403,7 @@ free_rule(struct cls_rule *cls_rule, void *cls) static void destroy_classifier(struct classifier *cls) { - classifier_for_each(cls, CLS_INC_ALL, free_rule, cls); + classifier_for_each(cls, free_rule, cls); classifier_destroy(cls); } @@ -436,17 +412,13 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules, int n_dups) { const struct cls_table *table; - const struct test_rule *test_rule; struct flow_wildcards exact_wc; int found_tables = 0; int found_rules = 0; int found_dups = 0; - int n_exact1 = 0; - int n_exact2 = 0; flow_wildcards_init_exact(&exact_wc); HMAP_FOR_EACH (table, hmap_node, &cls->tables) { - bool is_exact = flow_wildcards_equal(&table->wc, &exact_wc); const struct cls_rule *head; assert(!hmap_is_empty(&table->rules)); @@ -457,31 +429,20 @@ check_tables(const struct classifier *cls, const struct cls_rule *rule; found_rules++; - if (is_exact) { - n_exact1++; - } LIST_FOR_EACH (rule, list, &head->list) { assert(rule->priority < prev_priority); prev_priority = rule->priority; found_rules++; found_dups++; - if (is_exact) { - n_exact1++; - } assert(classifier_find_rule_exactly(cls, rule) == rule); } } } - CLASSIFIER_FOR_EACH_EXACT_RULE (test_rule, cls_rule, cls) { - n_exact2++; - } - assert(found_tables == hmap_count(&cls->tables)); assert(n_tables == -1 || n_tables == hmap_count(&cls->tables)); assert(n_rules == -1 || found_rules == n_rules); assert(n_dups == -1 || found_dups == n_dups); - assert(n_exact1 == n_exact2); } static struct test_rule * @@ -885,12 +846,8 @@ test_many_rules_in_n_tables(int n_tables) while (!classifier_is_empty(&cls)) { struct test_rule *rule = xmemdup(tcls.rules[rand() % tcls.n_rules], sizeof(struct test_rule)); - int include = rand() % 2 ? CLS_INC_WILD : CLS_INC_EXACT; - include |= (rule->cls_rule.wc.wildcards - ? CLS_INC_WILD : CLS_INC_EXACT); - classifier_for_each_match(&cls, &rule->cls_rule, include, - free_rule, &cls); - tcls_delete_matches(&tcls, &rule->cls_rule, include); + classifier_for_each_match(&cls, &rule->cls_rule, free_rule, &cls); + tcls_delete_matches(&tcls, &rule->cls_rule); compare_classifiers(&cls, &tcls); check_tables(&cls, -1, -1, -1); free(rule);