From: Ben Pfaff Date: Tue, 17 Mar 2009 21:42:24 +0000 (-0700) Subject: classifier: Expand the classifier priority range to 32 bits. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c76d0a94ff3622639a5a2383cd8f6fabea8fde17;p=openvswitch classifier: Expand the classifier priority range to 32 bits. secchan will reserve priorities above UINT16_MAX for its own purposes (e.g. in-band control). --- diff --git a/lib/classifier.c b/lib/classifier.c index 52cad760..d40d1de1 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -67,17 +67,15 @@ static bool rules_match_1wild(const struct cls_rule *fixed, const struct cls_rule *wild, int field_idx); /* Converts the flow in 'flow' into a cls_rule in 'rule', with the given - * 'wildcards' and 'priority'. - * - * Rules without wildcards always have the maximum priority 65535. */ + * 'wildcards' and 'priority'.*/ void cls_rule_from_flow(struct cls_rule *rule, const flow_t *flow, - uint32_t wildcards, uint16_t priority) + uint32_t wildcards, unsigned int priority) { assert(flow->reserved == 0); rule->flow = *flow; flow_wildcards_init(&rule->wc, wildcards); - rule->priority = rule->wc.wildcards ? priority : UINT16_MAX; + rule->priority = priority; rule->table_idx = table_idx_from_wildcards(rule->wc.wildcards); } @@ -85,7 +83,7 @@ cls_rule_from_flow(struct cls_rule *rule, const flow_t *flow, * 'priority'. */ void cls_rule_from_match(struct cls_rule *rule, const struct ofp_match *match, - uint16_t priority) + unsigned int priority) { uint32_t wildcards; flow_from_match(&rule->flow, &wildcards, match); @@ -101,7 +99,7 @@ cls_rule_from_match(struct cls_rule *rule, const struct ofp_match *match, void cls_rule_print(const struct cls_rule *rule) { - printf("wildcards=%x priority=%d ", rule->wc.wildcards, rule->priority); + printf("wildcards=%x priority=%u ", rule->wc.wildcards, rule->priority); flow_print(stdout, &rule->flow); putc('\n', stdout); } @@ -310,14 +308,14 @@ classifier_lookup_wild(const struct classifier *cls, const flow_t *flow) struct cls_rule * classifier_find_rule_exactly(const struct classifier *cls, const flow_t *target, uint32_t wildcards, - uint16_t priority) + unsigned int priority) { struct cls_bucket *bucket; int table_idx; uint32_t hash; if (!wildcards) { - /* Ignores 'priority', should we check that it is UINT16_MAX? */ + /* Ignores 'priority'. */ return search_exact_table(cls, flow_hash(target, 0), target); } diff --git a/lib/classifier.h b/lib/classifier.h index 1afebede..dd2fb525 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -118,14 +118,14 @@ struct cls_rule { } node; flow_t flow; /* All field values. */ struct flow_wildcards wc; /* Wildcards for fields. */ - uint16_t priority; /* Larger numbers are higher priorities. */ - unsigned short table_idx; /* Index into struct classifier 'tables'. */ + unsigned int priority; /* Larger numbers are higher priorities. */ + unsigned int table_idx; /* Index into struct classifier 'tables'. */ }; void cls_rule_from_flow(struct cls_rule *, const flow_t *, uint32_t wildcards, - uint16_t priority); + unsigned int priority); void cls_rule_from_match(struct cls_rule *, const struct ofp_match *, - uint16_t priority); + unsigned int priority); void cls_rule_print(const struct cls_rule *); void cls_rule_moved(struct classifier *, struct cls_rule *old, struct cls_rule *new); @@ -160,6 +160,6 @@ void classifier_for_each_match(const struct classifier *, struct cls_rule *classifier_find_rule_exactly(const struct classifier *, const flow_t *target, uint32_t wildcards, - uint16_t priority); + unsigned int priority); #endif /* classifier.h */ diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 2e768bdf..efbb2390 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -117,8 +117,7 @@ tcls_insert(struct tcls *tcls, const struct test_rule *rule) { size_t i; - assert(rule->cls_rule.wc.wildcards - || rule->cls_rule.priority == UINT16_MAX); + 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 @@ -444,7 +443,7 @@ check_tables(const struct classifier *cls, } static struct test_rule * -make_rule(int wc_fields, int priority, int value_pat) +make_rule(int wc_fields, unsigned int priority, int value_pat) { const struct cls_field *f; struct test_rule *rule; @@ -469,11 +468,11 @@ make_rule(int wc_fields, int priority, int value_pat) } static void -shuffle(int *p, size_t n) +shuffle(unsigned int *p, size_t n) { for (; n > 1; n--, p++) { - int *q = &p[rand() % n]; - int tmp = *p; + unsigned int *q = &p[rand() % n]; + unsigned int tmp = *p; *p = *q; *q = tmp; } @@ -603,7 +602,7 @@ test_two_rules_in_one_bucket(void) struct test_rule *displaced_rule; struct classifier cls; struct tcls tcls; - int pri1, pri2; + unsigned int pri1, pri2; int wcf1, wcf2; if (table != CLS_F_IDX_EXACT) { @@ -627,7 +626,7 @@ test_two_rules_in_one_bucket(void) } else { /* This classifier always puts exact-match rules at * maximum priority. */ - pri1 = pri2 = UINT16_MAX; + pri1 = pri2 = UINT_MAX; /* No wildcard fields. */ wcf1 = wcf2 = 0; @@ -690,7 +689,7 @@ test_two_rules_in_one_table(void) struct test_rule *rule2, *tcls_rule2; struct classifier cls; struct tcls tcls; - int pri1, pri2; + unsigned int pri1, pri2; int wcf1, wcf2; int value_mask, value_pat1, value_pat2; int i; @@ -767,7 +766,7 @@ test_two_rules_in_different_tables(void) struct test_rule *rule2, *tcls_rule2; struct classifier cls; struct tcls tcls; - int pri1, pri2; + unsigned int pri1, pri2; int wcf1, wcf2; /* We must use unique priorities in this test because the @@ -831,7 +830,7 @@ test_many_rules_in_one_bucket(void) for (iteration = 0; iteration < 3; iteration++) { for (table = 0; table <= CLS_N_FIELDS; table++) { - int priorities[MAX_RULES]; + unsigned int priorities[MAX_RULES]; struct classifier cls; struct tcls tcls; int i; @@ -847,7 +846,7 @@ test_many_rules_in_one_bucket(void) for (i = 0; i < MAX_RULES; i++) { struct test_rule *rule; - int priority = priorities[i]; + unsigned int priority = priorities[i]; int wcf; wcf = random_wcf_in_table(table, priority); @@ -875,7 +874,7 @@ test_many_rules_in_one_table(void) for (iteration = 0; iteration < 3; iteration++) { for (table = 0; table < CLS_N_FIELDS; table++) { - int priorities[MAX_RULES]; + unsigned int priorities[MAX_RULES]; struct classifier cls; struct tcls tcls; int i; @@ -891,7 +890,7 @@ test_many_rules_in_one_table(void) for (i = 0; i < MAX_RULES; i++) { struct test_rule *rule; - int priority = priorities[i]; + unsigned int priority = priorities[i]; int wcf; wcf = random_wcf_in_table(table, priority); @@ -918,7 +917,7 @@ test_many_rules_in_different_tables(void) int iteration; for (iteration = 0; iteration < 30; iteration++) { - int priorities[MAX_RULES]; + unsigned int priorities[MAX_RULES]; struct classifier cls; struct tcls tcls; int i; @@ -934,7 +933,7 @@ test_many_rules_in_different_tables(void) for (i = 0; i < MAX_RULES; i++) { struct test_rule *rule; - int priority = priorities[i]; + unsigned int priority = priorities[i]; int table = rand() % (CLS_N_FIELDS + 1); int wcf = random_wcf_in_table(table, rand()); int value_pat = rand() & ((1u << CLS_N_FIELDS) - 1);