classifier: Test classifier_for_each_match().
authorBen Pfaff <blp@nicira.com>
Wed, 4 Mar 2009 21:20:47 +0000 (13:20 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 4 Mar 2009 21:29:06 +0000 (13:29 -0800)
tests/test-classifier.c

index 5c5fe90c0b48ec0b23c91d507db26b6a5598e114..c4d7f57c06d13ee3b7b3f501d578d91462c783d8 100644 (file)
@@ -217,6 +217,25 @@ tcls_lookup(const struct tcls *cls, const flow_t *flow, int include)
     }
     return NULL;
 }
+
+static void
+tcls_delete_matches(struct tcls *cls,
+                    const struct cls_rule *target,
+                    int include)
+{
+    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)
+            && match(target, &pos->cls_rule.flow)) {
+            tcls_remove(cls, pos);
+        } else {
+            i++;
+        }
+    }
+}
 \f
 #ifdef WORDS_BIGENDIAN
 #define HTONL(VALUE) ((uint32_t) (VALUE))
@@ -923,6 +942,21 @@ test_many_rules_in_different_tables(void)
             compare_classifiers(&cls, &tcls);
         }
 
+        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);
+            compare_classifiers(&cls, &tcls);
+            free(rule);
+        }
+        putchar('.');
+        fflush(stdout);
+
         destroy_classifier(&cls);
         tcls_destroy(&tcls);
     }