From: Ben Pfaff Date: Tue, 9 Nov 2010 00:35:34 +0000 (-0800) Subject: classifier: New function cls_rule_equal(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=193eb87453463d45eb10a3d3adbffedc0a762d1f;p=openvswitch classifier: New function cls_rule_equal(). --- diff --git a/lib/classifier.c b/lib/classifier.c index 38424229..f3b5d5d2 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -307,6 +307,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 c22a161e..ea4d6fc8 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 f4ccfdfe..45700ed9 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); } }