ethdev: add fuzzy match in flow API
authorQi Zhang <qi.z.zhang@intel.com>
Tue, 13 Jun 2017 03:07:05 +0000 (23:07 -0400)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 5 Jul 2017 17:51:56 +0000 (19:51 +0200)
Add new meta pattern item RTE_FLOW_TYPE_ITEM_FUZZY in flow API.

This is for device that support fuzzy match option.
Usually a fuzzy match is fast but the cost is accuracy.
i.e. Signature Match only match pattern's hash value, but it is
possible that two different patterns have the same hash value.

Matching accuracy level can be configured by subfield threshold.
Driver can divide the range of threshold and map to different
accuracy levels that device support.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
app/test-pmd/cmdline_flow.c
app/test-pmd/config.c
doc/guides/prog_guide/rte_flow.rst
doc/guides/testpmd_app_ug/testpmd_funcs.rst
lib/librte_ether/rte_flow.h

index a2a4a7e..25d5982 100644 (file)
@@ -169,6 +169,8 @@ enum index {
        ITEM_MPLS_LABEL,
        ITEM_GRE,
        ITEM_GRE_PROTO,
+       ITEM_FUZZY,
+       ITEM_FUZZY_THRESH,
 
        /* Validate/create actions. */
        ACTIONS,
@@ -449,6 +451,13 @@ static const enum index next_item[] = {
        ITEM_NVGRE,
        ITEM_MPLS,
        ITEM_GRE,
+       ITEM_FUZZY,
+       ZERO,
+};
+
+static const enum index item_fuzzy[] = {
+       ITEM_FUZZY_THRESH,
+       ITEM_NEXT,
        ZERO,
 };
 
@@ -1398,6 +1407,22 @@ static const struct token token_list[] = {
                .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
                                             protocol)),
        },
+       [ITEM_FUZZY] = {
+               .name = "fuzzy",
+               .help = "fuzzy pattern match, expect faster than default",
+               .priv = PRIV_ITEM(FUZZY,
+                               sizeof(struct rte_flow_item_fuzzy)),
+               .next = NEXT(item_fuzzy),
+               .call = parse_vc,
+       },
+       [ITEM_FUZZY_THRESH] = {
+               .name = "thresh",
+               .help = "match accuracy threshold",
+               .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
+                                       thresh)),
+       },
+
        /* Validate/create actions. */
        [ACTIONS] = {
                .name = "actions",
index b0b340e..aa35505 100644 (file)
@@ -946,6 +946,7 @@ static const struct {
        MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
        MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
        MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
+       MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
 };
 
 /** Compute storage space needed by item specification. */
index 6c26c37..1b44f50 100644 (file)
@@ -906,6 +906,52 @@ Matches a GRE header.
 - ``protocol``: protocol type.
 - Default ``mask`` matches protocol only.
 
+Item: ``FUZZY``
+^^^^^^^^^^^^^^^^^
+
+Fuzzy pattern match, expect faster than default.
+
+This is for device that support fuzzy match option. Usually a fuzzy match is
+fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
+value, but it is possible two different patterns have the same hash value.
+
+Matching accuracy level can be configured by threshold. Driver can divide the
+range of threshold and map to different accuracy levels that device support.
+
+.. _table_rte_flow_item_fuzzy:
+
+.. table:: FUZZY
+
+   +----------+---------------+--------------------------------------------------+
+   | Field    |   Subfield    | Value                                            |
+   +==========+===========+======================================================+
+   | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
+   +----------+---------------+--------------------------------------------------+
+   | ``last`` | ``threshold`` | upper range value                                |
+   +----------+-----------+------------------------------------------------------+
+   | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last"              |
+   +----------+-----------+------------------------------------------------------+
+
+Usage example, fuzzy match a TCPv4 packets:
+
+.. _table_rte_flow_item_fuzzy_example:
+
+.. table:: Fuzzy matching
+
+   +-------+----------+
+   | Index | Item     |
+   +=======+==========+
+   | 0     | FUZZY    |
+   +-------+----------+
+   | 1     | Ethernet |
+   +-------+----------+
+   | 2     | IPv4     |
+   +-------+----------+
+   | 3     | TCP      |
+   +-------+----------+
+   | 4     | END      |
+   +-------+----------+
+
 Actions
 ~~~~~~~
 
@@ -2093,8 +2139,8 @@ A few features are intentionally not supported:
 - "MAC VLAN" or "tunnel" perfect matching modes should be automatically set
   according to the created flow rules.
 
-- Signature mode of operation is not defined but could be handled through a
-  specific item type if needed.
+- Signature mode of operation is not defined but could be handled through
+  "FUZZY" item.
 
 .. _table_rte_flow_migration_fdir:
 
@@ -2121,8 +2167,8 @@ A few features are intentionally not supported:
    |   |                   +----------+-----+                       |
    |   |                   | ``mask`` | any |                       |
    +---+-------------------+----------+-----+                       |
-   | 3 | VF, PF (optional) | ``spec`` | any |                       |
-   |   |                   +----------+-----+                       |
+   | 3 | VF, PF, FUZZY     | ``spec`` | any |                       |
+   |   | (optional)        +----------+-----+                       |
    |   |                   | ``last`` | N/A |                       |
    |   |                   +----------+-----+                       |
    |   |                   | ``mask`` | any |                       |
index 2b9a1ea..ca7c16b 100644 (file)
@@ -2613,6 +2613,10 @@ This section lists supported pattern items and their attributes, if any.
 
   - ``protocol {unsigned}``: protocol type.
 
+- ``fuzzy``: fuzzy pattern match, expect faster than default.
+
+  - ``thresh {unsigned}``: accuracy threshold.
+
 Actions list
 ^^^^^^^^^^^^
 
index 057f7e7..cfbed30 100644 (file)
@@ -297,6 +297,18 @@ enum rte_flow_item_type {
         * See struct rte_flow_item_gre.
         */
        RTE_FLOW_ITEM_TYPE_GRE,
+
+       /**
+        * [META]
+        *
+        * Fuzzy pattern match, expect faster than default.
+        *
+        * This is for device that support fuzzy matching option.
+        * Usually a fuzzy matching is fast but the cost is accuracy.
+        *
+        * See struct rte_flow_item_fuzzy.
+        */
+       RTE_FLOW_ITEM_TYPE_FUZZY,
 };
 
 /**
@@ -694,6 +706,31 @@ static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
 };
 #endif
 
+/**
+ * RTE_FLOW_ITEM_TYPE_FUZZY
+ *
+ * Fuzzy pattern match, expect faster than default.
+ *
+ * This is for device that support fuzzy match option.
+ * Usually a fuzzy match is fast but the cost is accuracy.
+ * i.e. Signature Match only match pattern's hash value, but it is
+ * possible two different patterns have the same hash value.
+ *
+ * Matching accuracy level can be configure by threshold.
+ * Driver can divide the range of threshold and map to different
+ * accuracy levels that device support.
+ */
+struct rte_flow_item_fuzzy {
+       uint32_t thresh; /**< Accuracy threshold*/
+};
+
+/** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
+#ifndef __cplusplus
+static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
+       .thresh = 0xffffffff,
+};
+#endif
+
 /**
  * Matching pattern item definition.
  *