static void
compare_classifiers(struct classifier *cls, struct tcls *tcls)
- OVS_REQ_RDLOCK(cls->rwlock)
{
static const int confidence = 500;
unsigned int i;
flow.nw_tos = nw_dscp_values[get_value(&x, N_NW_DSCP_VALUES)];
/* This assertion is here to suppress a GCC 4.9 array-bounds warning */
- ovs_assert(cls->cls->n_tries <= CLS_MAX_TRIES);
+ ovs_assert(cls->n_tries <= CLS_MAX_TRIES);
cr0 = classifier_lookup(cls, &flow, &wc);
cr1 = tcls_lookup(tcls, &flow);
static void
destroy_classifier(struct classifier *cls)
{
- struct test_rule *rule, *next_rule;
+ struct test_rule *rule;
- CLS_FOR_EACH_SAFE (rule, next_rule, cls_rule, cls) {
- fat_rwlock_wrlock(&cls->rwlock);
+ CLS_FOR_EACH_SAFE (rule, cls_rule, cls) {
classifier_remove(cls, &rule->cls_rule);
- fat_rwlock_unlock(&cls->rwlock);
free_rule(rule);
}
classifier_destroy(cls);
}
static void
-pvector_verify(struct pvector *pvec)
+pvector_verify(const struct pvector *pvec)
{
void *ptr OVS_UNUSED;
unsigned int priority, prev_priority = UINT_MAX;
}
static void
-verify_tries(struct classifier *cls_)
+verify_tries(struct classifier *cls)
{
- struct cls_classifier *cls = cls_->cls;
unsigned int n_rules = 0;
int i;
static void
check_tables(const struct classifier *cls, int n_tables, int n_rules,
- int n_dups) OVS_EXCLUDED(cls->rwlock)
+ int n_dups)
{
const struct cls_subtable *table;
struct test_rule *test_rule;
int found_dups = 0;
int found_rules2 = 0;
- pvector_verify(&cls->cls->subtables);
- CMAP_FOR_EACH (table, cmap_node, &cls->cls->subtables_map) {
+ pvector_verify(&cls->subtables);
+ CMAP_FOR_EACH (table, cmap_node, &cls->subtables_map) {
const struct cls_match *head;
unsigned int max_priority = 0;
unsigned int max_count = 0;
const struct cls_subtable *iter;
/* Locate the subtable from 'subtables'. */
- PVECTOR_FOR_EACH (iter, &cls->cls->subtables) {
+ PVECTOR_FOR_EACH (iter, &cls->subtables) {
if (iter == table) {
if (found) {
VLOG_ABORT("Subtable %p duplicated in 'subtables'.",
assert(!cmap_is_empty(&table->rules));
- ovs_mutex_lock(&cls->cls->mutex);
+ ovs_mutex_lock(&cls->mutex);
assert(trie_verify(&table->ports_trie, 0, table->ports_mask_len)
== (table->ports_mask_len ? table->n_rules : 0));
- ovs_mutex_unlock(&cls->cls->mutex);
+ ovs_mutex_unlock(&cls->mutex);
found_tables++;
CMAP_FOR_EACH (head, cmap_node, &table->rules) {
}
found_rules++;
- ovs_mutex_lock(&cls->cls->mutex);
+ ovs_mutex_lock(&cls->mutex);
LIST_FOR_EACH (rule, list, &head->list) {
assert(rule->priority < prev_priority);
assert(rule->priority <= table->max_priority);
prev_priority = rule->priority;
found_rules++;
found_dups++;
- ovs_mutex_unlock(&cls->cls->mutex);
+ ovs_mutex_unlock(&cls->mutex);
assert(classifier_find_rule_exactly(cls, rule->cls_rule)
== rule->cls_rule);
- ovs_mutex_lock(&cls->cls->mutex);
+ ovs_mutex_lock(&cls->mutex);
}
- ovs_mutex_unlock(&cls->cls->mutex);
+ ovs_mutex_unlock(&cls->mutex);
}
- ovs_mutex_lock(&cls->cls->mutex);
+ ovs_mutex_lock(&cls->mutex);
assert(table->max_priority == max_priority);
assert(table->max_count == max_count);
- ovs_mutex_unlock(&cls->cls->mutex);
+ ovs_mutex_unlock(&cls->mutex);
}
- assert(found_tables == cmap_count(&cls->cls->subtables_map));
- assert(found_tables == pvector_count(&cls->cls->subtables));
- assert(n_tables == -1 || n_tables == cmap_count(&cls->cls->subtables_map));
+ assert(found_tables == cmap_count(&cls->subtables_map));
+ assert(found_tables == pvector_count(&cls->subtables));
+ assert(n_tables == -1 || n_tables == cmap_count(&cls->subtables_map));
assert(n_rules == -1 || found_rules == n_rules);
assert(n_dups == -1 || found_dups == n_dups);
static void
set_prefix_fields(struct classifier *cls)
- OVS_REQ_WRLOCK(cls->rwlock)
{
verify_tries(cls);
classifier_set_prefix_fields(cls, trie_fields, ARRAY_SIZE(trie_fields));
struct tcls tcls;
classifier_init(&cls, flow_segment_u32s);
- fat_rwlock_wrlock(&cls.rwlock);
set_prefix_fields(&cls);
tcls_init(&tcls);
assert(classifier_is_empty(&cls));
assert(tcls_is_empty(&tcls));
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
classifier_destroy(&cls);
tcls_destroy(&tcls);
}
hash_bytes(&wc_fields, sizeof wc_fields, 0), 0);
classifier_init(&cls, flow_segment_u32s);
- fat_rwlock_wrlock(&cls.rwlock);
set_prefix_fields(&cls);
tcls_init(&tcls);
tcls_rule = tcls_insert(&tcls, rule);
classifier_insert(&cls, &rule->cls_rule);
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
check_tables(&cls, 1, 1, 0);
- fat_rwlock_wrlock(&cls.rwlock);
classifier_remove(&cls, &rule->cls_rule);
tcls_remove(&tcls, tcls_rule);
assert(classifier_is_empty(&cls));
assert(tcls_is_empty(&tcls));
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
free_rule(rule);
classifier_destroy(&cls);
rule2->aux += 5;
classifier_init(&cls, flow_segment_u32s);
- fat_rwlock_wrlock(&cls.rwlock);
set_prefix_fields(&cls);
tcls_init(&tcls);
tcls_insert(&tcls, rule1);
classifier_insert(&cls, &rule1->cls_rule);
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
check_tables(&cls, 1, 1, 0);
tcls_destroy(&tcls);
tcls_init(&tcls);
tcls_insert(&tcls, rule2);
- fat_rwlock_wrlock(&cls.rwlock);
assert(test_rule_from_cls_rule(
classifier_replace(&cls, &rule2->cls_rule)) == rule1);
free_rule(rule1);
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
check_tables(&cls, 1, 1, 0);
tcls_destroy(&tcls);
}
classifier_init(&cls, flow_segment_u32s);
- fat_rwlock_wrlock(&cls.rwlock);
set_prefix_fields(&cls);
- fat_rwlock_unlock(&cls.rwlock);
tcls_init(&tcls);
for (i = 0; i < ARRAY_SIZE(ops); i++) {
int j = ops[i];
int m, n;
- fat_rwlock_wrlock(&cls.rwlock);
if (!tcls_rules[j]) {
struct test_rule *displaced_rule;
pri_rules[pris[j]] = -1;
}
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
n = 0;
for (m = 0; m < N_RULES; m++) {
check_tables(&cls, n > 0, n, n - 1);
}
- fat_rwlock_wrlock(&cls.rwlock);
for (i = 0; i < N_RULES; i++) {
if (rules[i]->cls_rule.cls_match) {
classifier_remove(&cls, &rules[i]->cls_rule);
}
free_rule(rules[i]);
}
- fat_rwlock_unlock(&cls.rwlock);
classifier_destroy(&cls);
tcls_destroy(&tcls);
} while (next_permutation(ops, ARRAY_SIZE(ops)));
} while ((1 << count_ones(value_mask)) < N_RULES);
classifier_init(&cls, flow_segment_u32s);
- fat_rwlock_wrlock(&cls.rwlock);
set_prefix_fields(&cls);
- fat_rwlock_unlock(&cls.rwlock);
tcls_init(&tcls);
for (i = 0; i < N_RULES; i++) {
rules[i] = make_rule(wcf, priority, value_pats[i]);
tcls_rules[i] = tcls_insert(&tcls, rules[i]);
- fat_rwlock_wrlock(&cls.rwlock);
classifier_insert(&cls, &rules[i]->cls_rule);
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
check_tables(&cls, 1, i + 1, 0);
}
for (i = 0; i < N_RULES; i++) {
tcls_remove(&tcls, tcls_rules[i]);
- fat_rwlock_wrlock(&cls.rwlock);
classifier_remove(&cls, &rules[i]->cls_rule);
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
free_rule(rules[i]);
check_tables(&cls, i < N_RULES - 1, N_RULES - (i + 1), 0);
shuffle(priorities, ARRAY_SIZE(priorities));
classifier_init(&cls, flow_segment_u32s);
- fat_rwlock_wrlock(&cls.rwlock);
set_prefix_fields(&cls);
- fat_rwlock_unlock(&cls.rwlock);
tcls_init(&tcls);
for (i = 0; i < MAX_RULES; i++) {
int value_pat = random_uint32() & ((1u << CLS_N_FIELDS) - 1);
rule = make_rule(wcf, priority, value_pat);
tcls_insert(&tcls, rule);
- fat_rwlock_wrlock(&cls.rwlock);
classifier_insert(&cls, &rule->cls_rule);
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
check_tables(&cls, -1, i + 1, -1);
}
while (!classifier_is_empty(&cls)) {
- struct test_rule *rule, *next_rule;
struct test_rule *target;
+ struct test_rule *rule;
target = clone_rule(tcls.rules[random_range(tcls.n_rules)]);
- CLS_FOR_EACH_TARGET_SAFE (rule, next_rule, cls_rule, &cls,
+ CLS_FOR_EACH_TARGET_SAFE (rule, cls_rule, &cls,
&target->cls_rule) {
- fat_rwlock_wrlock(&cls.rwlock);
classifier_remove(&cls, &rule->cls_rule);
- fat_rwlock_unlock(&cls.rwlock);
free_rule(rule);
}
tcls_delete_matches(&tcls, &target->cls_rule);
- fat_rwlock_rdlock(&cls.rwlock);
compare_classifiers(&cls, &tcls);
- fat_rwlock_unlock(&cls.rwlock);
check_tables(&cls, -1, -1, -1);
free_rule(target);
}