diff mbox

[dpdk-dev,v2] ethdev: add fuzzy match pattern

Message ID 1496874080-35086-1-git-send-email-qi.z.zhang@intel.com (mailing list archive)
State Superseded, archived
Headers show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Zhang, Qi Z June 7, 2017, 10:21 p.m. UTC
Add new meta pattern item RTE_FLOW_TYPE_ITEM_FUZZY.

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 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>
---

v2:
- replace "Roughly" with "Fuzzy"

 app/test-pmd/cmdline_flow.c                 | 24 ++++++++++++++
 app/test-pmd/config.c                       |  1 +
 doc/guides/prog_guide/rte_flow.rst          | 50 +++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  2 ++
 lib/librte_ether/rte_flow.h                 | 30 +++++++++++++++++
 5 files changed, 107 insertions(+)

Comments

Thomas Monjalon June 8, 2017, 7:19 a.m. UTC | #1
Hi,

08/06/2017 00:21, Qi Zhang:
> Add new meta pattern item RTE_FLOW_TYPE_ITEM_FUZZY.

I disagree about fuzzy wording, because fuzzy is something different
I think.

> 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.

You have described it yourself here: it matches a hash of the signature.
Why not using "hash" as wording?

> Matching accuracy level can be configure 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>
Adrien Mazarguil June 12, 2017, 3:38 p.m. UTC | #2
On Thu, Jun 08, 2017 at 09:19:24AM +0200, Thomas Monjalon wrote:
> Hi,
> 
> 08/06/2017 00:21, Qi Zhang:
> > Add new meta pattern item RTE_FLOW_TYPE_ITEM_FUZZY.
> 
> I disagree about fuzzy wording, because fuzzy is something different
> I think.

At least it's a generic term, unrelated PMDs could likewise implement
another kind of fuzzy matching for performance reasons (for applications
that really care more about performance than accuracy). The fact this
particular implementation is built on top of something that is internally
known as signature hash should not be relevant.

> > 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.
> 
> You have described it yourself here: it matches a hash of the signature.
> Why not using "hash" as wording?

While "hash" would be also correct, in my opinion it would restrict this
pattern item to Intel adapters (ixgbe) with the ability to actually perform
a hash on patterns and use the resulting value to imperfectly match
traffic. This excludes other implementations with similar unpredictable
results.

Also a threshold notion is necessary as far as I understand, the signature
mode has several levels. The higher, the fuzzier it gets. This behavior is
difficult to translate to something generic named "hash", as one would have
to describe how the hash is computed and packets matched according to that
value, which really is ixgbe-specific at the moment.

> > Matching accuracy level can be configure 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>

Qi, many of my other comments about v1 still stand, please check my previous
reply in any case.
Zhang, Qi Z June 13, 2017, 6:03 a.m. UTC | #3
> -----Original Message-----
> From: Adrien Mazarguil [mailto:adrien.mazarguil@6wind.com]
> Sent: Monday, June 12, 2017 11:39 PM
> To: Thomas Monjalon <thomas@monjalon.net>
> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2] ethdev: add fuzzy match pattern
> 
> On Thu, Jun 08, 2017 at 09:19:24AM +0200, Thomas Monjalon wrote:
> > Hi,
> >
> > 08/06/2017 00:21, Qi Zhang:
> > > Add new meta pattern item RTE_FLOW_TYPE_ITEM_FUZZY.
> >
> > I disagree about fuzzy wording, because fuzzy is something different I
> > think.
> 
> At least it's a generic term, unrelated PMDs could likewise implement
> another kind of fuzzy matching for performance reasons (for applications
> that really care more about performance than accuracy). The fact this
> particular implementation is built on top of something that is internally
> known as signature hash should not be relevant.
> 
> > > 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.
> >
> > You have described it yourself here: it matches a hash of the signature.
> > Why not using "hash" as wording?
> 
> While "hash" would be also correct, in my opinion it would restrict this
> pattern item to Intel adapters (ixgbe) with the ability to actually perform a
> hash on patterns and use the resulting value to imperfectly match traffic.
> This excludes other implementations with similar unpredictable results.
> 
> Also a threshold notion is necessary as far as I understand, the signature
> mode has several levels. The higher, the fuzzier it gets. This behavior is
> difficult to translate to something generic named "hash", as one would have
> to describe how the hash is computed and packets matched according to
> that value, which really is ixgbe-specific at the moment.
> 
> > > Matching accuracy level can be configure 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>
> 
> Qi, many of my other comments about v1 still stand, please check my
> previous reply in any case.

Sorry, seems I skipped that important mail by mistake, just find it, thanks for all the comments. 
> 
> --
> Adrien Mazarguil
> 6WIND
diff mbox

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 0fd69f9..048d455 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -107,6 +107,8 @@  enum index {
 	ITEM_END,
 	ITEM_VOID,
 	ITEM_INVERT,
+	ITEM_FUZZY,
+	ITEM_FUZZY_THRESHOLD,
 	ITEM_ANY,
 	ITEM_ANY_NUM,
 	ITEM_PF,
@@ -426,6 +428,7 @@  static const enum index next_item[] = {
 	ITEM_END,
 	ITEM_VOID,
 	ITEM_INVERT,
+	ITEM_FUZZY,
 	ITEM_ANY,
 	ITEM_PF,
 	ITEM_VF,
@@ -447,6 +450,12 @@  static const enum index next_item[] = {
 	ZERO,
 };
 
+static const enum index item_fuzzy[] = {
+	ITEM_FUZZY_THRESHOLD,
+	ITEM_NEXT,
+	ZERO,
+};
+
 static const enum index item_any[] = {
 	ITEM_ANY_NUM,
 	ITEM_NEXT,
@@ -954,6 +963,21 @@  static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
 		.call = parse_vc,
 	},
+	[ITEM_FUZZY] = {
+		.name = "fuzzy",
+		.help = "match the pattern fuzzy",
+		.priv = PRIV_ITEM(FUZZY,
+				sizeof(struct rte_flow_item_fuzzy)),
+		.next = NEXT(item_fuzzy),
+		.call = parse_vc,
+	},
+	[ITEM_FUZZY_THRESHOLD] = {
+		.name = "threshold",
+		.help = "match accuracy threshold",
+		.next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
+					threshold)),
+	},
 	[ITEM_ANY] = {
 		.name = "any",
 		.help = "match any protocol for the current layer",
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 4d873cd..db7b740 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -954,6 +954,7 @@  static const struct {
 	MK_FLOW_ITEM(END, 0),
 	MK_FLOW_ITEM(VOID, 0),
 	MK_FLOW_ITEM(INVERT, 0),
+	MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
 	MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
 	MK_FLOW_ITEM(PF, 0),
 	MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index b587ba9..516a0ac 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -491,6 +491,7 @@  Usage example, matching non-TCPv4 packets only:
 
    +-------+----------+
    | Index | Item     |
+
    +=======+==========+
    | 0     | INVERT   |
    +-------+----------+
@@ -503,6 +504,55 @@  Usage example, matching non-TCPv4 packets only:
    | 4     | END      |
    +-------+----------+
 
+Item: ``FUZZY``
+^^^^^^^^^^^^^^^^^
+
+Fuzzy matching, not perfect match.
+
+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.
+
+.. _table_rte_flow_item_fuzzy:
+
+.. table:: FUZZY
+
+   +----------+---------------+--------------------------------------------------+
+   | Field    |   Subfield    | Value                                            |
+   +==========+===========+======================================================+
+   | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzzies match |
+   +----------+---------------+--------------------------------------------------+
+   | ``last`` | ``threshold`` | ignored                                          |
+   +----------+-----------+------------------------------------------------------+
+   | ``mask`` | ``threshold`` | ignored                                          |
+   +----------+-----------+------------------------------------------------------+
+
+
+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      |
+   +-------+----------+
+
 Item: ``PF``
 ^^^^^^^^^^^^
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 0e50c10..0b1d927 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -2513,6 +2513,8 @@  This section lists supported pattern items and their attributes, if any.
 
 - ``invert``: perform actions when pattern does not match.
 
+- ``fuzzy``: this is a fuzzy match..
+
 - ``any``: match any protocol for the current layer.
 
   - ``num {unsigned}``: number of layers covered.
diff --git a/lib/librte_ether/rte_flow.h b/lib/librte_ether/rte_flow.h
index c47edbc..b27e858 100644
--- a/lib/librte_ether/rte_flow.h
+++ b/lib/librte_ether/rte_flow.h
@@ -148,6 +148,18 @@  enum rte_flow_item_type {
 	RTE_FLOW_ITEM_TYPE_INVERT,
 
 	/**
+	 * [META]
+	 *
+	 * Fuzzy matching, not perfect matching
+	 *
+	 * 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,
+
+	/**
 	 * Matches any protocol in place of the current layer, a single ANY
 	 * may also stand for several protocol layers.
 	 *
@@ -300,6 +312,24 @@  enum rte_flow_item_type {
 };
 
 /**
+ * RTE_FLOW_ITEM_TYPE_FUZZY
+ *
+ * Fuzzy matching, not perfect match.
+ *
+ * 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 threshold; /**< accuracy threshold*/
+};
+
+/**
  * RTE_FLOW_ITEM_TYPE_ANY
  *
  * Matches any protocol in place of the current layer, a single ANY may also