[ovs-dev] [flow monitor v2 04/12] classifier: New function cls_rule_is_loose_match().

Ben Pfaff blp at nicira.com
Fri Jul 6 21:49:36 UTC 2012


This function will be useful in an upcoming commit.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/classifier.c |   76 ++++++++++++++++++++++++++++++++----------------------
 lib/classifier.h |    3 ++
 2 files changed, 48 insertions(+), 31 deletions(-)

diff --git a/lib/classifier.c b/lib/classifier.c
index 6e8f4d2..0c51df1 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -934,6 +934,46 @@ classifier_rule_overlaps(const struct classifier *cls,
 
     return false;
 }
+
+/* Returns true if 'rule' exactly matches 'criteria' or are more specific than
+ * 'criteria'.  That is, 'rule' matches 'criteria' and this function returns
+ * true if, for every field:
+ *
+ *   - 'criteria' and 'rule' specify the same (non-wildcarded) value for the
+ *     field, or
+ *
+ *   - 'criteria' wildcards the field,
+ *
+ * but not if:
+ *
+ *   - 'criteria' and 'rule' specify different values for the field, or
+ *
+ *   - 'criteria' specifies a value for the field but 'rule' wildcards it.
+ *
+ * Equivalently, the truth table for whether a field matches is:
+ *
+ *                                     rule
+ *
+ *                             wildcard    exact
+ *                            +---------+---------+
+ *                   t   wild |   yes   |   yes   |
+ *                   a   card |         |         |
+ *                   r        +---------+---------+
+ *                   g  exact |    no   |if values|
+ *                   e        |         |are equal|
+ *                   t        +---------+---------+
+ *
+ * This is the matching rule used by OpenFlow 1.0 non-strict OFPT_FLOW_MOD
+ * commands and by OpenFlow 1.0 aggregate and flow stats.
+ *
+ * Ignores rule->priority and criteria->priority. */
+bool
+cls_rule_is_loose_match(const struct cls_rule *rule,
+                        const struct cls_rule *criteria)
+{
+    return (!flow_wildcards_has_extra(&rule->wc, &criteria->wc)
+            && flow_equal_except(&rule->flow, &criteria->flow, &criteria->wc));
+}
 
 /* Iteration. */
 
@@ -959,40 +999,14 @@ search_table(const struct cls_table *table, const struct cls_rule *target)
     return NULL;
 }
 
-/* Initializes 'cursor' for iterating through 'cls' rules that exactly match
- * 'target' or are more specific than 'target'.  That is, a given 'rule'
- * matches 'target' if, for every field:
+/* Initializes 'cursor' for iterating through rules in 'cls':
  *
- *   - 'target' and 'rule' specify the same (non-wildcarded) value for the
- *     field, or
- *
- *   - 'target' wildcards the field,
- *
- * but not if:
- *
- *   - 'target' and 'rule' specify different values for the field, or
- *
- *   - 'target' specifies a value for the field but 'rule' wildcards it.
- *
- * Equivalently, the truth table for whether a field matches is:
- *
- *                                     rule
- *
- *                             wildcard    exact
- *                            +---------+---------+
- *                   t   wild |   yes   |   yes   |
- *                   a   card |         |         |
- *                   r        +---------+---------+
- *                   g  exact |    no   |if values|
- *                   e        |         |are equal|
- *                   t        +---------+---------+
- *
- * This is the matching rule used by OpenFlow 1.0 non-strict OFPT_FLOW_MOD
- * commands and by OpenFlow 1.0 aggregate and flow stats.
+ *     - If 'target' is null, the cursor will visit every rule in 'cls'.
  *
- * Ignores target->priority.
+ *     - If 'target' is nonnull, the cursor will visit each 'rule' in 'cls'
+ *       such that cls_rule_is_loose_match(rule, target) returns true.
  *
- * 'target' may be NULL to iterate over every rule in 'cls'. */
+ * Ignores target->priority. */
 void
 cls_cursor_init(struct cls_cursor *cursor, const struct classifier *cls,
                 const struct cls_rule *target)
diff --git a/lib/classifier.h b/lib/classifier.h
index ec7316c..b154899 100644
--- a/lib/classifier.h
+++ b/lib/classifier.h
@@ -87,6 +87,9 @@ void cls_rule_init_catchall(struct cls_rule *, unsigned int priority);
 
 void cls_rule_zero_wildcarded_fields(struct cls_rule *);
 
+bool cls_rule_is_loose_match(const struct cls_rule *rule,
+                             const struct cls_rule *criteria);
+
 void cls_rule_set_reg(struct cls_rule *, unsigned int reg_idx, uint32_t value);
 void cls_rule_set_reg_masked(struct cls_rule *, unsigned int reg_idx,
                              uint32_t value, uint32_t mask);
-- 
1.7.2.5




More information about the dev mailing list