ofp-prop: Add support for putting and parsing nested properties.
[cascardo/ovs.git] / lib / classifier-private.h
index cb65422..0f8ad1e 100644 (file)
@@ -21,7 +21,6 @@
 #include "flow.h"
 #include "hash.h"
 #include "rculist.h"
-#include "tag.h"
 
 /* Classifier internal definitions, subject to change at any time. */
 
@@ -40,9 +39,8 @@ struct cls_subtable {
      * following data structures. */
 
     /* These fields are accessed by readers who care about wildcarding. */
-    const tag_type tag;       /* Tag generated from mask for partitioning. */
     const uint8_t n_indices;                   /* How many indices to use. */
-    const struct miniflow index_maps[CLS_MAX_INDICES + 1]; /* Stage maps. */
+    const struct flowmap index_maps[CLS_MAX_INDICES + 1]; /* Stage maps. */
     unsigned int trie_plen[CLS_MAX_TRIES];  /* Trie prefix length in 'mask'
                                              * (runtime configurable). */
     const int ports_mask_len;
@@ -55,16 +53,6 @@ struct cls_subtable {
     /* 'mask' must be the last field. */
 };
 
-/* Associates a metadata value (that is, a value of the OpenFlow 1.1+ metadata
- * field) with tags for the "cls_subtable"s that contain rules that match that
- * metadata value.  */
-struct cls_partition {
-    struct cmap_node cmap_node; /* In struct classifier's 'partitions' map. */
-    ovs_be64 metadata;          /* metadata value for this partition. */
-    tag_type tags;              /* OR of each flow's cls_subtable tag. */
-    struct tag_tracker tracker; /* Tracks the bits in 'tags'. */
-};
-
 /* Internal representation of a rule in a "struct cls_subtable".
  *
  * The 'next' member is an element in a singly linked, null-terminated list.
@@ -77,9 +65,6 @@ struct cls_match {
     OVSRCU_TYPE(struct cls_match *) next; /* Equal, lower-priority matches. */
     OVSRCU_TYPE(struct cls_conjunction_set *) conj_set;
 
-    /* Accessed only by writers. */
-    struct cls_partition *partition;
-
     /* Accessed by readers interested in wildcarding. */
     const int priority;         /* Larger numbers are higher priorities. */
     struct cmap_node index_nodes[CLS_MAX_INDICES]; /* Within subtable's
@@ -90,7 +75,7 @@ struct cls_match {
     /* Rule versioning.
      *
      * CLS_NOT_REMOVED_VERSION has a special meaning for 'remove_version',
-     * meaningthat the rule has been added but not yet removed.
+     * meaning that the rule has been added but not yet removed.
      */
     const cls_version_t add_version;        /* Version rule was added in. */
     ATOMIC(cls_version_t) remove_version;   /* Version rule is removed in. */
@@ -238,16 +223,16 @@ flow_hash_in_minimask(const struct flow *flow, const struct minimask *mask,
     const uint64_t *mask_values = miniflow_get_values(&mask->masks);
     const uint64_t *flow_u64 = (const uint64_t *)flow;
     const uint64_t *p = mask_values;
-    uint32_t hash;
-    size_t idx;
+    uint32_t hash = basis;
+    map_t map;
 
-    hash = basis;
-    MAP_FOR_EACH_INDEX(idx, mask->masks.tnl_map) {
-        hash = hash_add64(hash, flow_u64[idx] & *p++);
-    }
-    flow_u64 += FLOW_TNL_U64S;
-    MAP_FOR_EACH_INDEX(idx, mask->masks.pkt_map) {
-        hash = hash_add64(hash, flow_u64[idx] & *p++);
+    FLOWMAP_FOR_EACH_MAP (map, mask->masks.map) {
+        size_t idx;
+
+        MAP_FOR_EACH_INDEX (idx, map) {
+            hash = hash_add64(hash, flow_u64[idx] & *p++);
+        }
+        flow_u64 += MAP_T_BITS;
     }
 
     return hash_finish(hash, (p - mask_values) * 8);
@@ -265,13 +250,10 @@ miniflow_hash_in_minimask(const struct miniflow *flow,
     const uint64_t *mask_values = miniflow_get_values(&mask->masks);
     const uint64_t *p = mask_values;
     uint32_t hash = basis;
-    uint64_t flow_u64;
+    uint64_t value;
 
-    MINIFLOW_FOR_EACH_IN_TNL_MAP(flow_u64, flow, mask->masks) {
-        hash = hash_add64(hash, flow_u64 & *p++);
-    }
-    MINIFLOW_FOR_EACH_IN_PKT_MAP(flow_u64, flow, mask->masks) {
-        hash = hash_add64(hash, flow_u64 & *p++);
+    MINIFLOW_FOR_EACH_IN_FLOWMAP(value, flow, mask->masks.map) {
+        hash = hash_add64(hash, value & *p++);
     }
 
     return hash_finish(hash, (p - mask_values) * 8);
@@ -293,22 +275,23 @@ miniflow_hash_in_minimask(const struct miniflow *flow,
 static inline uint32_t
 flow_hash_in_minimask_range(const struct flow *flow,
                             const struct minimask *mask,
-                            const struct miniflow *range,
+                            const struct flowmap range,
                             unsigned int *offset,
                             uint32_t *basis)
 {
     const uint64_t *mask_values = miniflow_get_values(&mask->masks);
-    const uint64_t *p = mask_values + *offset;
     const uint64_t *flow_u64 = (const uint64_t *)flow;
+    const uint64_t *p = mask_values + *offset;
     uint32_t hash = *basis;
-    size_t idx;
+    map_t map;
 
-    MAP_FOR_EACH_INDEX(idx, range->tnl_map) {
-        hash = hash_add64(hash, flow_u64[idx] & *p++);
-    }
-    flow_u64 += FLOW_TNL_U64S;
-    MAP_FOR_EACH_INDEX(idx, range->pkt_map) {
-        hash = hash_add64(hash, flow_u64[idx] & *p++);
+    FLOWMAP_FOR_EACH_MAP (map, range) {
+        size_t idx;
+
+        MAP_FOR_EACH_INDEX (idx, map) {
+            hash = hash_add64(hash, flow_u64[idx] & *p++);
+        }
+        flow_u64 += MAP_T_BITS;
     }
 
     *basis = hash; /* Allow continuation from the unfinished value. */
@@ -325,26 +308,13 @@ flow_wildcards_fold_minimask(struct flow_wildcards *wc,
 }
 
 /* Fold minimask 'mask''s wildcard mask into 'wc's wildcard mask for bits in
- * 'map'.  The 1-bits in 'map' correspond to the first 1-bits in 'mask''s
- * map. */
+ * 'fmap'.  1-bits in 'fmap' are a subset of 1-bits in 'mask''s map. */
 static inline void
 flow_wildcards_fold_minimask_in_map(struct flow_wildcards *wc,
                                     const struct minimask *mask,
-                                    const struct miniflow *map)
+                                    const struct flowmap fmap)
 {
-    const uint64_t *p = miniflow_get_values(&mask->masks);
-    uint64_t *dst_u64 = (uint64_t *)&wc->masks;
-    size_t idx;
-
-    if (map->tnl_map) {
-        MAP_FOR_EACH_INDEX(idx, map->tnl_map) {
-            dst_u64[idx] |= *p++;
-        }
-    }
-    dst_u64 += FLOW_TNL_U64S;
-    MAP_FOR_EACH_INDEX(idx, map->pkt_map) {
-        dst_u64[idx] |= *p++;
-    }
+    flow_union_with_miniflow_subset(&wc->masks, &mask->masks, fmap);
 }
 
 /* Returns a hash value for 'mask', given 'basis'. */
@@ -358,8 +328,11 @@ minimask_hash(const struct minimask *mask, uint32_t basis)
     for (size_t i = 0; i < n_values; i++) {
         hash = hash_add64(hash, *p++);
     }
-    hash = hash_add64(hash, mask->masks.tnl_map);
-    hash = hash_add64(hash, mask->masks.pkt_map);
+
+    map_t map;
+    FLOWMAP_FOR_EACH_MAP (map, mask->masks.map) {
+        hash = hash_add64(hash, map);
+    }
 
     return hash_finish(hash, n_values);
 }
@@ -379,20 +352,15 @@ minimask_hash(const struct minimask *mask, uint32_t basis)
  * flow_hash_in_minimask_range(), only the form of the arguments differ. */
 static inline uint32_t
 minimatch_hash_range(const struct minimatch *match,
-                     const struct miniflow *range, unsigned int *offset,
+                     const struct flowmap range, unsigned int *offset,
                      uint32_t *basis)
 {
-    const uint64_t *p = miniflow_get_values(match->flow);
-    const uint64_t *q = miniflow_get_values(&match->mask->masks);
+    const uint64_t *p = miniflow_get_values(match->flow) + *offset;
+    const uint64_t *q = miniflow_get_values(&match->mask->masks) + *offset;
+    unsigned int n = flowmap_n_1bits(range);
     uint32_t hash = *basis;
-    int n, i;
-
-    n = miniflow_n_values(range);
-
-    q += *offset;
-    p += *offset;
 
-    for (i = 0; i < n; i++) {
+    for (unsigned int i = 0; i < n; i++) {
         hash = hash_add64(hash, p[i] & q[i]);
     }
     *basis = hash; /* Allow continuation from the unfinished value. */