X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest-classifier.c;h=1308fa510546967a0563f1a6ec1dcbee5784318d;hb=3c4486a5f784731b1cb289d187ad9d9e100407c3;hp=6c296ecce641a78538495077c544742f91b515fa;hpb=b63f2ea79417e93390eaa86f68e546242e15a9ec;p=openvswitch diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 6c296ecc..1308fa51 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -33,6 +33,7 @@ #include "command-line.h" #include "flow.h" #include "packets.h" +#include "unaligned.h" #undef NDEBUG #include @@ -51,7 +52,8 @@ CLS_FIELD(OFPFW_TP_SRC, tp_src, TP_SRC) \ CLS_FIELD(OFPFW_TP_DST, tp_dst, TP_DST) \ CLS_FIELD(OFPFW_DL_SRC, dl_src, DL_SRC) \ - CLS_FIELD(OFPFW_DL_DST, dl_dst, DL_DST) \ + CLS_FIELD(OFPFW_DL_DST | FWW_ETH_MCAST, \ + dl_dst, DL_DST) \ CLS_FIELD(OFPFW_NW_PROTO, nw_proto, NW_PROTO) \ CLS_FIELD(OFPFW_DL_VLAN_PCP, dl_vlan_pcp, DL_VLAN_PCP) \ CLS_FIELD(OFPFW_NW_TOS, nw_tos, NW_TOS) @@ -194,14 +196,6 @@ tcls_remove(struct tcls *cls, const struct test_rule *rule) NOT_REACHED(); } -static uint32_t -read_uint32(const void *p) -{ - uint32_t x; - memcpy(&x, p, sizeof x); - return x; -} - static bool match(const struct cls_rule *wild, const struct flow *fixed) { @@ -219,8 +213,8 @@ match(const struct cls_rule *wild, const struct flow *fixed) } if (wild->wc.wildcards & f->wildcards) { - uint32_t test = read_uint32(wild_field); - uint32_t ip = read_uint32(fixed_field); + uint32_t test = get_unaligned_u32(wild_field); + uint32_t ip = get_unaligned_u32(fixed_field); int shift = (f_idx == CLS_F_IDX_NW_SRC ? OFPFW_NW_SRC_SHIFT : OFPFW_NW_DST_SHIFT); uint32_t mask = flow_nw_bits_to_mask(wild->wc.wildcards, shift); @@ -235,15 +229,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; } } @@ -251,17 +243,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 { @@ -270,20 +258,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 }, @@ -384,7 +371,6 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) 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)]; @@ -404,21 +390,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); } } } @@ -433,7 +417,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); } @@ -442,11 +426,17 @@ 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,20 +447,31 @@ 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 * @@ -874,12 +875,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);