datapath-windows: Define OVS_DPPORT_NUMBER_INVALID
[cascardo/ovs.git] / tests / test-classifier.c
index c63b7dc..0dfa910 100644 (file)
@@ -400,7 +400,6 @@ get_value(unsigned int *x, unsigned n_values)
 
 static void
 compare_classifiers(struct classifier *cls, struct tcls *tcls)
-    OVS_REQ_RDLOCK(cls->rwlock)
 {
     static const int confidence = 500;
     unsigned int i;
@@ -433,7 +432,7 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls)
         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);
@@ -453,19 +452,17 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls)
 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;
@@ -498,9 +495,8 @@ trie_verify(const rcu_trie_ptr *trie, unsigned int ofs, unsigned int n_bits)
 }
 
 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;
 
@@ -515,7 +511,7 @@ verify_tries(struct classifier *cls_)
 
 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;
@@ -524,8 +520,8 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
     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;
@@ -533,7 +529,7 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
         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'.",
@@ -548,10 +544,10 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
 
         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) {
@@ -566,7 +562,7 @@ check_tables(const struct classifier *cls, int n_tables, int n_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);
@@ -574,22 +570,22 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
                 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);
 
@@ -697,7 +693,6 @@ static enum mf_field_id trie_fields[2] = {
 
 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));
@@ -712,13 +707,11 @@ test_empty(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
     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);
 }
@@ -745,23 +738,19 @@ test_single_rule(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
                          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);
@@ -787,25 +776,21 @@ test_rule_replacement(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
         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);
@@ -904,16 +889,13 @@ test_many_rules_in_one_list (int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
             }
 
             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;
 
@@ -937,7 +919,6 @@ test_many_rules_in_one_list (int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
                     pri_rules[pris[j]] = -1;
                 }
                 compare_classifiers(&cls, &tcls);
-                fat_rwlock_unlock(&cls.rwlock);
 
                 n = 0;
                 for (m = 0; m < N_RULES; m++) {
@@ -946,14 +927,12 @@ test_many_rules_in_one_list (int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
                 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)));
@@ -1012,9 +991,7 @@ test_many_rules_in_one_table(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
         } 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++) {
@@ -1027,20 +1004,16 @@ test_many_rules_in_one_table(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
             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);
@@ -1080,9 +1053,7 @@ test_many_rules_in_n_tables(int n_tables)
         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++) {
@@ -1092,31 +1063,25 @@ test_many_rules_in_n_tables(int n_tables)
             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);
         }