Skip to contentSkip to conversation

support the flow-based traffic sampling

PATCH In review Jiawei Wang 13 participants 186 messages Jun 25, 2020 – Oct 14, 2020 Page 1 of 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover support the flow-based traffic sampling

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with additional set of actions from the original packet.

MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.

Jiawei Wang (8):
ethdev: introduce sample action for rte flow common/mlx5: glue for default miss and sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action net/mlx5: update the metadata register c0 support app/testpmd: add testpmd command for sample action

 app/test-pmd/cmdline_flow.c           | 285 ++++++++++++++-
 drivers/common/mlx5/Makefile          |  10 +
 drivers/common/mlx5/linux/meson.build |   4 +
 drivers/common/mlx5/linux/mlx5_glue.c |  28 ++
 drivers/common/mlx5/linux/mlx5_glue.h |  13 +
 drivers/common/mlx5/mlx5_devx_cmds.c  |  27 ++
 drivers/common/mlx5/mlx5_devx_cmds.h  |   1 +
 drivers/common/mlx5/mlx5_prm.h        |  51 +++
 drivers/net/mlx5/linux/mlx5_os.c      |  14 +
 drivers/net/mlx5/mlx5.c               |  11 +
 drivers/net/mlx5/mlx5.h               |   4 +
 drivers/net/mlx5/mlx5_flow.c          | 270 +++++++++++++-
 drivers/net/mlx5/mlx5_flow.h          |  52 ++-
 drivers/net/mlx5/mlx5_flow_dv.c       | 668 +++++++++++++++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c          |   1 +
 lib/librte_ethdev/rte_flow.h          |  29 ++
 16 files changed, 1422 insertions(+), 46 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/8 ethdev: introduce sample action for rte flow

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

---
 lib/librte_ethdev/rte_flow.c |  1 +
 lib/librte_ethdev/rte_flow.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
lib/librte_ethdev/rte_flow.c +1 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +29 -0
index b0e4199..71dd82c 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * Redirects specific ratio of packets to vport or queue.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 12 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 6 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why it is called sample.

Quoted 18 lines

will be introduced.

---
 lib/librte_ethdev/rte_flow.c |  1 +
 lib/librte_ethdev/rte_flow.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2736

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+struct rte_flow_action_sample {
+       /* packets sampled equals to '1/ratio' */
+       const uint32_t ratio;
+       /* sub-action list specific for the sampling hit cases */

Why not use, RTE_FLOW_ACTION_TYPE_PASSTHRU action to append further action for this ACTION.

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +4 -1
+       const struct rte_flow_action *actions;
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
--

1.8.3.1

#3 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

25/06/2020 19:55, Jerin Jacob:

Quoted 17 lines · Jiawei Wang
Quoted 16 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

Quoted 5 lines
Quoted 2 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why it is called sample.

Sampling is a partial mirroring.
Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#4 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 19 lines · Thomas Monjalon

25/06/2020 19:55, Jerin Jacob:

Quoted 17 lines · Jiawei Wang
Quoted 16 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why it is called sample.

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

So IMO, explicit mirror keyword usage makes it is clear.

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?
2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.
3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Quoted 4 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#5 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

26/06/2020 12:35, Jerin Jacob:

Quoted 26 lines · Thomas Monjalon
Quoted 25 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 22 lines · Jiawei Wang
Quoted 12 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 6 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why it is called sample.

Quoted 8 lines
Quoted 1 line

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

I see. Good design question (I will let others reply).

Quoted 7 lines

So IMO, explicit mirror keyword usage makes it is clear.

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Quoted 10 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.
3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.
I want to help deprecating such API in 20.11 if possible.

Quoted 2 lines
Quoted 2 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#6 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 41 lines · Thomas Monjalon

26/06/2020 12:35, Jerin Jacob:

Quoted 26 lines · Thomas Monjalon
Quoted 25 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 22 lines · Jiawei Wang
Quoted 12 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 6 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why it is called sample.

Quoted 8 lines
Quoted 1 line

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

I see. Good design question (I will let others reply).

Quoted 2 lines

So IMO, explicit mirror keyword usage makes it is clear.

Quoted 8 lines
Quoted 5 lines

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Not clear to me. I will wait for another explanation if any. In what basics application set .1 vs .8?

Quoted 7 lines
Quoted 7 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.
3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Quoted 8 lines
Quoted 4 lines

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.

+1 from me.

it is taking too much effort and time to make support duplicate APIs.

Quoted 1 line

I want to help deprecating such API in 20.11 if possible.

Please start that discussion. In this case, it is clear API overlap with rte_eth_mirror_rule_set().
We should not have two separate paths for the same function in the same ethdev library.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#7 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 66 lines · Jerin Jacob
Quoted 41 lines · Thomas Monjalon

26/06/2020 12:35, Jerin Jacob:

Quoted 26 lines · Thomas Monjalon
Quoted 25 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 22 lines · Jiawei Wang
Quoted 12 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 6 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why it is called sample.

Quoted 8 lines
Quoted 1 line

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

I see. Good design question (I will let others reply).

Quoted 2 lines

So IMO, explicit mirror keyword usage makes it is clear.

Quoted 8 lines
Quoted 5 lines

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Not clear to me. I will wait for another explanation if any. In what basics application set .1 vs .8?

Quoted 12 lines
Quoted 11 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.
3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Quoted 5 lines
Quoted 3 lines

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.

+1 from me.

+1

Quoted 17 lines

it is taking too much effort and time to make support duplicate APIs.

Quoted 1 line

I want to help deprecating such API in 20.11 if possible.

Please start that discussion. In this case, it is clear API overlap with rte_eth_mirror_rule_set().
We should not have two separate paths for the same function in the same ethdev library.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#8 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

In reply to Jerin Jacob

On Friday, June 26, 2020 7:10 PM Jerin Jacob <[email protected]> Wrote:

Quoted 28 lines
Quoted 3 lines · Thomas Monjalon

26/06/2020 12:35, Jerin Jacob:

Quoted 1 line

On Fri, Jun 26, 2020 at 12:59 AM Thomas Monjalon

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 1 line

On Thu, Jun 25, 2020 at 10:20 PM Jiawei Wang

Quoted 7 lines · <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of

actions from the original packet.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 20 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why

it is called sample.

Quoted 13 lines
Quoted 9 lines
Quoted 2 lines

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

I see. Good design question (I will let others reply).

Quoted 1 line

So IMO, explicit mirror keyword usage makes it is clear.

Sampled packet is duplicated from incoming traffic at specific ratio and will go to different sample actions; ratio=1 is 100% duplication or mirroring.
All packets will continue to go to default flow actions.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

Quoted 5 lines
Quoted 2 lines

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Not clear to me. I will wait for another explanation if any. In what basics application set .1 vs .8?

The real case is like monitor the traffic with full-offload.
While packet hit the sample flow, the matching packets will be sampled and sent to specific Queue, align with OVS sflow probability, user application can set it different value.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.

The sample ratio isn’t the same as “meter’, the ratio of sampling will be calculated with incoming packets mask (every some packets sampled 1). Then the packets will be duplicated and go to do the other sample actions.

Quoted 32 lines
Quoted 4 lines
Quoted 4 lines

3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Quoted 8 lines
Quoted 4 lines

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.

+1 from me.

it is taking too much effort and time to make support duplicate APIs.

Quoted 1 line

I want to help deprecating such API in 20.11 if possible.

Please start that discussion. In this case, it is clear API overlap with rte_eth_mirror_rule_set().
We should not have two separate paths for the same function in the same ethdev library.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#9 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 48 lines · Jiawei(Jonny) Wang

On Friday, June 26, 2020 7:10 PM Jerin Jacob <[email protected]> Wrote:

Quoted 45 lines
Quoted 3 lines · Thomas Monjalon

26/06/2020 12:35, Jerin Jacob:

Quoted 1 line

On Fri, Jun 26, 2020 at 12:59 AM Thomas Monjalon

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 1 line

On Thu, Jun 25, 2020 at 10:20 PM Jiawei Wang

Quoted 7 lines · <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of

actions from the original packet.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand, Why

it is called sample.

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

I see. Good design question (I will let others reply).

Quoted 1 line

So IMO, explicit mirror keyword usage makes it is clear.

Sampled packet is duplicated from incoming traffic at specific ratio and will go to different sample actions; ratio=1 is 100% duplication or mirroring.
All packets will continue to go to default flow actions.

Functionality is clear from the git commit log(Not from action name). The only question is what would be the appropriate name
for this action. RTE_FLOW_ACTION_TYPE_SAMPLE vs RTE_FLOW_ACTION_TYPE_MIRROR

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Quoted 6 lines
Quoted 2 lines

Not clear to me. I will wait for another explanation if any. In what basics application set .1 vs .8?

The real case is like monitor the traffic with full-offload.
While packet hit the sample flow, the matching packets will be sampled and sent to specific Queue, align with OVS sflow probability, user application can set it different value.

I understand the use case for mirror and supported in a lot of HW. What I would like to understand is the use case for "ratio"? Is the "ratio" part of OpenFlow spec? Or Is it an MLX hardware feature?

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.

The sample ratio isn’t the same as “meter’, the ratio of sampling will be calculated with incoming packets mask (every some packets sampled 1). Then the packets will be duplicated and go to do the other sample actions.

What I meant here is , If the ratio is used for rate-limiting then having a cascade rule like RTE_FLOW_ACTION_TYPE_MIRROR, RTE_FLOW_ACTION_TYPE_MTR will do the job.

Quoted 34 lines
Quoted 34 lines
Quoted 6 lines
Quoted 6 lines

3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Quoted 8 lines
Quoted 4 lines

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.

+1 from me.

it is taking too much effort and time to make support duplicate APIs.

Quoted 1 line

I want to help deprecating such API in 20.11 if possible.

Please start that discussion. In this case, it is clear API overlap with rte_eth_mirror_rule_set().
We should not have two separate paths for the same function in the same ethdev library.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#10 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 97 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Sunday, June 28, 2020 9:38 PM
To: Jiawei(Jonny) Wang <[email protected]>
Cc: Thomas Monjalon <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; dpdk-dev <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 3 lines · Jiawei(Jonny) Wang

On Friday, June 26, 2020 7:10 PM Jerin Jacob <[email protected]>

Wrote:

Quoted 24 lines
Quoted 24 lines
Quoted 3 lines · Thomas Monjalon

26/06/2020 12:35, Jerin Jacob:

Quoted 1 line

On Fri, Jun 26, 2020 at 12:59 AM Thomas Monjalon

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 1 line

On Thu, Jun 25, 2020 at 10:20 PM Jiawei Wang

Quoted 12 lines · <[email protected]> wrote:
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic. So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of

actions from the original packet.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE

and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand,

Why

Quoted 11 lines
Quoted 11 lines

it is called sample.

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I see. Good design question (I will let others reply).

Quoted 1 line

So IMO, explicit mirror keyword usage makes it is clear.

Sampled packet is duplicated from incoming traffic at specific ratio and will go to different sample actions;
ratio=1 is 100% duplication or mirroring.
All packets will continue to go to default flow actions.

Functionality is clear from the git commit log(Not from action name). The only question is what would be the appropriate name for this action. RTE_FLOW_ACTION_TYPE_SAMPLE vs RTE_FLOW_ACTION_TYPE_MIRROR

Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 7 lines

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Not clear to me. I will wait for another explanation if any. In what basics application set .1 vs .8?

Quoted 9 lines
Quoted 3 lines

The real case is like monitor the traffic with full-offload. While packet hit the sample flow, the matching packets will be sampled and sent to specific Queue, align with OVS sflow probability, user

application can set it different value.

I understand the use case for mirror and supported in a lot of HW. What I would like to understand is the use case for "ratio"? Is the "ratio" part of OpenFlow spec? Or Is it an MLX hardware feature?

The same usage of the 'probability' variable of ovs sample action; MLX HW implemented it.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.

Quoted 8 lines
Quoted 1 line

The sample ratio isn’t the same as “meter’, the ratio of sampling will be

calculated with incoming packets mask (every some packets sampled 1). Then the packets will be duplicated and go to do the other sample actions.

What I meant here is , If the ratio is used for rate-limiting then having a cascade rule like RTE_FLOW_ACTION_TYPE_MIRROR, RTE_FLOW_ACTION_TYPE_MTR will do the job.

The ratio means the probability with packet replication, we don't need add METER action here.

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 6 lines
Quoted 6 lines

3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Quoted 8 lines
Quoted 4 lines

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.

+1 from me.

it is taking too much effort and time to make support duplicate APIs.

Quoted 1 line

I want to help deprecating such API in 20.11 if possible.

Please start that discussion. In this case, it is clear API overlap with rte_eth_mirror_rule_set().
We should not have two separate paths for the same function in the same ethdev library.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

#11 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 115 lines · On Sun, 28 Jun 2020 15:52:27 +0000 "Jiawei(Jonny) Wang" <[email protected]>…
Quoted 95 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Sunday, June 28, 2020 9:38 PM
To: Jiawei(Jonny) Wang <[email protected]>
Cc: Thomas Monjalon <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; dpdk-dev <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 3 lines · Jiawei(Jonny) Wang

On Friday, June 26, 2020 7:10 PM Jerin Jacob <[email protected]>

Wrote:

Quoted 24 lines
Quoted 24 lines
Quoted 3 lines · Thomas Monjalon

26/06/2020 12:35, Jerin Jacob:

Quoted 1 line

On Fri, Jun 26, 2020 at 12:59 AM Thomas Monjalon

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 1 line

On Thu, Jun 25, 2020 at 10:20 PM Jiawei Wang

Quoted 12 lines · <[email protected]> wrote:
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic. So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of

actions from the original packet.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE

and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand,

Why

Quoted 11 lines
Quoted 11 lines

it is called sample.

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I see. Good design question (I will let others reply).

Quoted 1 line

So IMO, explicit mirror keyword usage makes it is clear.

Sampled packet is duplicated from incoming traffic at specific ratio and will go to different sample actions;
ratio=1 is 100% duplication or mirroring.
All packets will continue to go to default flow actions.

Functionality is clear from the git commit log(Not from action name). The only question is what would be the appropriate name for this action. RTE_FLOW_ACTION_TYPE_SAMPLE vs RTE_FLOW_ACTION_TYPE_MIRROR

Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 7 lines

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Not clear to me. I will wait for another explanation if any. In what basics application set .1 vs .8?

Quoted 9 lines
Quoted 3 lines

The real case is like monitor the traffic with full-offload. While packet hit the sample flow, the matching packets will be sampled and sent to specific Queue, align with OVS sflow probability, user

application can set it different value.

I understand the use case for mirror and supported in a lot of HW. What I would like to understand is the use case for "ratio"? Is the "ratio" part of OpenFlow spec? Or Is it an MLX hardware feature?

The same usage of the 'probability' variable of ovs sample action; MLX HW implemented it.

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.

The sample ratio isn’t the same as “meter’, the ratio of sampling will be

Quoted 42 lines
Quoted 7 lines

calculated with incoming packets mask (every some packets sampled 1). Then the packets will be duplicated and go to do the other sample actions.

What I meant here is , If the ratio is used for rate-limiting then having a cascade rule like RTE_FLOW_ACTION_TYPE_MIRROR, RTE_FLOW_ACTION_TYPE_MTR will do the job.

The ratio means the probability with packet replication, we don't need add METER action here.

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 6 lines
Quoted 6 lines

3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Quoted 8 lines
Quoted 4 lines

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.

+1 from me.

it is taking too much effort and time to make support duplicate APIs.

Quoted 1 line

I want to help deprecating such API in 20.11 if possible.

Please start that discussion. In this case, it is clear API overlap with rte_eth_mirror_rule_set().
We should not have two separate paths for the same function in the same ethdev library.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

One use case would be simulating packet loss or duplication. (like netem does). In that use case, the sample action would have to not have an implicit copy.

Could sample be defined as "if random number hits the ratio" then execute this alternative rule, otherwise go to next rule.

The the alternative rule could mirror if it wanted, or drop, or count, or ...

It could even be used as a form of transmit load balancing.

#12 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi Stephen,

Quoted 178 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, July 2, 2020 3:18 AM
To: Jiawei(Jonny) Wang <[email protected]>
Cc: Jerin Jacob <[email protected]>; Thomas Monjalon <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; dpdk- dev <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 115 lines · On Sun, 28 Jun 2020 15:52:27 +0000 "Jiawei(Jonny) Wang" <[email protected]>…
Quoted 95 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Sunday, June 28, 2020 9:38 PM
To: Jiawei(Jonny) Wang <[email protected]>
Cc: Thomas Monjalon <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; dpdk-dev <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 3 lines · Jiawei(Jonny) Wang

On Friday, June 26, 2020 7:10 PM Jerin Jacob <[email protected]>

Wrote:

Quoted 24 lines
Quoted 24 lines
Quoted 3 lines · Thomas Monjalon

26/06/2020 12:35, Jerin Jacob:

Quoted 1 line

On Fri, Jun 26, 2020 at 12:59 AM Thomas Monjalon

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

25/06/2020 19:55, Jerin Jacob:

Quoted 1 line

On Thu, Jun 25, 2020 at 10:20 PM Jiawei Wang

Quoted 12 lines · <[email protected]> wrote:
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic. So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of

actions from the original packet.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE

and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

structure rte_flow_action_sample

Isn't mirroring the packet? How about, RTE_FLOW_ACTION_TYPE_MIRROR I am not able to understand,

Why

Quoted 11 lines
Quoted 11 lines

it is called sample.

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

Sampling is a partial mirroring.

I think, By definition, _sampling_ is the _selection_ of items from a specific group.
I think, _sampling_ is not dictating, what is the real action for the "selected" items.
One can get confused with the selected ones can be for forward, drop any other action.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I see. Good design question (I will let others reply).

Quoted 1 line

So IMO, explicit mirror keyword usage makes it is clear.

Sampled packet is duplicated from incoming traffic at specific ratio and will go to different sample actions;
ratio=1 is 100% duplication or mirroring.
All packets will continue to go to default flow actions.

Functionality is clear from the git commit log(Not from action name). The only question is what would be the appropriate name for this action. RTE_FLOW_ACTION_TYPE_SAMPLE vs RTE_FLOW_ACTION_TYPE_MIRROR

Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 7 lines

Some more related questions:
1) What is the real use case for ratio? I am not against adding a ratio attribute if the MLX hardware supports it. It will be good to know the use case from the application perspective? And what basics application set ratio != 1?

If I understand well, some applications want to check, by picking random packets, that the processing is not failing.

Not clear to me. I will wait for another explanation if any. In what basics application set .1 vs .8?

Quoted 9 lines
Quoted 3 lines

The real case is like monitor the traffic with full-offload. While packet hit the sample flow, the matching packets will be sampled and sent to specific Queue, align with OVS sflow probability, user

application can set it different value.

I understand the use case for mirror and supported in a lot of HW. What I would like to understand is the use case for "ratio"? Is the "ratio" part of OpenFlow spec? Or Is it an MLX hardware feature?

The same usage of the 'probability' variable of ovs sample action; MLX HW implemented it.

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

2) If it is for "rate-limiting" or "policing", why not use rte_mtr object (rte_mtr.h) via rte_flow action.

The sample ratio isn’t the same as “meter’, the ratio of sampling will be

Quoted 8 lines
Quoted 7 lines

calculated with incoming packets mask (every some packets sampled 1). Then the packets will be duplicated and go to do the other sample actions.

What I meant here is , If the ratio is used for rate-limiting then having a cascade rule like RTE_FLOW_ACTION_TYPE_MIRROR, RTE_FLOW_ACTION_TYPE_MTR will do the job.

The ratio means the probability with packet replication, we don't need add

METER action here.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 6 lines
Quoted 6 lines

3) One of the issue for driver developers and application writers are overlapping APIs. This would overlap with rte_eth_mirror_rule_set() API.

Quoted 8 lines
Quoted 4 lines

Can we deprecate rte_eth_mirror_rule_set() API? It will be a pain for all to have overlapping APIs. We have not fixed the VLAN filter API overlap with rte_flow in ethdev. Its being TODO for multiple releases now.

Ooooooooh yes!
I think flow-based API is more powerful, and should deprecate old port-based API.

+1 from me.

it is taking too much effort and time to make support duplicate APIs.

Quoted 1 line

I want to help deprecating such API in 20.11 if possible.

Please start that discussion. In this case, it is clear API overlap with rte_eth_mirror_rule_set().
We should not have two separate paths for the same function in the same ethdev library.

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Full mirroring is sampling 100% packets (ratio = 1). That's why only one action is enough.

One use case would be simulating packet loss or duplication. (like netem does). In that use case, the sample action would have to not have an implicit copy.

Quoted 6 lines

Could sample be defined as "if random number hits the ratio" then execute this alternative rule, otherwise go to next rule.

The the alternative rule could mirror if it wanted, or drop, or count, or ...

It could even be used as a form of transmit load balancing.

I think what you are suggesting is a different action, by definition (at least in kernel)
The sample is a duplication of a packet, it comes to solve the lack of visibility when doing full offload. What you are suggesting is to add 2 flows, like discussed in a different thread will have major impact on performance (duplicate the matching, waste two flows since number of HW have limited rules capabilities )
Also it seems a bug that application can't relay to where the packet will get to. It will break applications that are counting on traffic to get to a specific queue.

Best,
Ori

#13 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

In reply to Jiawei Wang
Quoted 20 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

[snip]

Quoted 13 lines
lib/librte_ethdev/rte_flow.h +9 -0
@@ -2709,6 +2716,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2737

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;

This design idea does not look good to me from the very beginning. IMHO it does not fit flow API overall design. I mean sub-action list.

As I understand Linux iptables solves it on match level (i.e. in pattern). E.g. "limit" extension which is basically sampling. Sampling using meta pattern item in combination with PASSTHRU action (to make sampling actions non-terminating if required) is a better solution from design point of view.

#14 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 57 lines · Andrew Rybchenko
Quoted 6 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 6 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

[snip]

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +4 -0
@@ -2709,6 +2716,28 @@ struct rte_flow_action {  struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2731

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+vport
+ * in the predefined probabiilty, All the packets continues
+processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Review struct rte_flow_action { struct rte_flow; · line 2732

Quoted 1 line
(quoted diff) +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2737

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;

This design idea does not look good to me from the very beginning. IMHO it does not fit flow API overall design.
I mean sub-action list.

Quoted 4 lines

As I understand Linux iptables solves it on match level (i.e. in pattern). E.g. "limit" extension which is basically sampling. Sampling using meta pattern item in combination with PASSTHRU action (to make sampling actions non- terminating if required) is a better solution from design point of view.

On our design, there're sample flow path and normal flow path, each path can have different actions. The defined sub-actions list only applied for sampled packets in the sample flow path; For normal path, all packets will continue to go with the original actions.

#15 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 59 lines · Jiawei(Jonny) Wang
Quoted 57 lines · Andrew Rybchenko
Quoted 6 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 6 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

[snip]

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +4 -0
@@ -2709,6 +2716,28 @@ struct rte_flow_action {  struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2731

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+vport
+ * in the predefined probabiilty, All the packets continues
+processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Review struct rte_flow_action { struct rte_flow; · line 2732

Quoted 1 line
(quoted diff) +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2737

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;

This design idea does not look good to me from the very beginning. IMHO it does not fit flow API overall design.
I mean sub-action list.

Quoted 9 lines
Quoted 4 lines

As I understand Linux iptables solves it on match level (i.e. in pattern). E.g. "limit" extension which is basically sampling. Sampling using meta pattern item in combination with PASSTHRU action (to make sampling actions non- terminating if required) is a better solution from design point of view.

On our design, there're sample flow path and normal flow path, each path can have different actions. The defined sub-actions list only applied for sampled packets in the sample flow path; For normal path, all packets will continue to go with the original actions.

In my too.

#16 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi all,

Quoted 77 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Sunday, June 28, 2020 7:19 PM
To: Jiawei(Jonny) Wang <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 2 lines · Jiawei(Jonny) Wang

On Sunday, June 28, 2020 4:27 PM, Andrew Rybchenko

Quoted 62 lines · <[email protected]> wrote:
Quoted 61 lines · Jiawei Wang
Quoted 6 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 6 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

[snip]

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +4 -0
@@ -2709,6 +2716,28 @@ struct rte_flow_action {  struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2731

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+vport
+ * in the predefined probabiilty, All the packets continues
+processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Review struct rte_flow_action { struct rte_flow; · line 2732

Quoted 1 line
(quoted diff) +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2737

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;

This design idea does not look good to me from the very beginning. IMHO it does not fit flow API overall design.
I mean sub-action list.

As I understand Linux iptables solves it on match level (i.e. in pattern). E.g. "limit" extension which is basically sampling. Sampling using meta pattern item in combination with PASSTHRU action (to make sampling actions non- terminating if required) is a better solution from design point of view.

Quoted 8 lines
Quoted 1 line

On our design, there're sample flow path and normal flow path, each path

can have different actions.

Quoted 1 line

The defined sub-actions list only applied for sampled packets in the sample

flow path;

Quoted 2 lines

For normal path, all packets will continue to go with the original actions.

In my too.

First as far as I know TC works close to the suggest approach (that by itself doesn’t mean anything) The concept of a PASSTHRU is a good one but it has some issue to consider:
1. When using PASSTHRU it will mean that the matching part will be needed to be checked
more times this will have performance penalty , also number of HW have limited number of flow that can be offload this will approach will waste resources.
2. Using PASSTHRU will force the order of flows (sure it can be done using priorities but it is more complex to the application to implement)
3. PASSTHRU will mean that there will be 2 terminal action for each flow (for example queue index 2 / passthru) this also is not native to RTE flow.
4. since we want to select only part of the packets, and we want to have some of the actions done on both
packets (the sampled and the standard one) and then we want on the sampled packet do some specific actions
while on the standard packet do different actions.
Lest check the following use case:
Application is using full offload traffic from the wire to a VM, which should decaped
So the basic flow is:
Flow create 0 transfer ingress pattern eth / outer.ip =x / end actions decap / port id 3
Since after the offload the application loses visibility of the traffic. it still wants to sample some of the traffic in order to verify that the traffic is valid. So the application request to receive some of the original traffic and mark it with id.

If we use the original approach (the one in the patch) we will need something like this:
Flow 1: flow create 0 transfer ingress pattern eth / outer.ip=x / end actions sample(ratio 2, actions mark id 3 / port pf)) / decap / port 3

In the PASSTHRU concept (I'm not sure I can even create such flows)
Flow 1: flow create 0 transfer ingress pattern eth / outer.ip =x / end actions decap / port 2 /passtthru // original request
Flow 2: flow create 0 transfer ingress pattern eth/ outer.ip=x / should sample (new item that selects if the packet is selected based on the ratio)end act / mark / port pf

The main issue with this case the decap is before the sample so the sample will get decap packet.

So when looking at everything I think the original API is the best approach.
For the record I think that passthru action is very important and should be supported but not the best one for this feature.

Thanks,
Ori

#17 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi all,

CC Adrien

(I apologize for pulling you to the rte_flow API discussions once again, but may be you can find spare time and share your thoughts. Your opinion as an author and architect of the rte_flow API would be very useful and highly appreciated.)

Quoted 86 lines · Ori Kam

Hi all,

Quoted 84 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Sunday, June 28, 2020 7:19 PM
To: Jiawei(Jonny) Wang <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 2 lines · Jiawei(Jonny) Wang

On Sunday, June 28, 2020 4:27 PM, Andrew Rybchenko

Quoted 57 lines · <[email protected]> wrote:
Quoted 57 lines · Jiawei Wang
Quoted 6 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 6 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

[snip]

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +4 -0
@@ -2709,6 +2716,28 @@ struct rte_flow_action {  struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2731

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+vport
+ * in the predefined probabiilty, All the packets continues
+processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Review struct rte_flow_action { struct rte_flow; · line 2732

Quoted 1 line
(quoted diff) +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2737

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;

This design idea does not look good to me from the very beginning. IMHO it does not fit flow API overall design.
I mean sub-action list.

Quoted 6 lines
Quoted 4 lines

As I understand Linux iptables solves it on match level (i.e. in pattern). E.g. "limit" extension which is basically sampling. Sampling using meta pattern item in combination with PASSTHRU action (to make sampling actions non- terminating if required) is a better solution from design point of view.

On our design, there're sample flow path and normal flow path, each path

can have different actions.

Quoted 1 line

The defined sub-actions list only applied for sampled packets in the sample

flow path;

Quoted 2 lines

For normal path, all packets will continue to go with the original actions.

Quoted 7 lines
Quoted 1 line

In my too.

First as far as I know TC works close to the suggest approach (that by itself doesn’t mean anything) The concept of a PASSTHRU is a good one but it has some issue to consider:
1. When using PASSTHRU it will mean that the matching part will be needed to be checked
more times this will have performance penalty , also number of HW have limited number of flow that can be offload this will approach will waste resources.

Marking or tagging could be used to address it. E.g. target traffic could be tagged first, then matching by tag should be used to sample and to do HW offloads.

Moreover, mapping of rte_flow API rules into HW rule is not required to be 1-to-1. Yes, 1-to-1 is simple, but it could be more complicated 1-to-N (when one rte_flow API rule is represented by many HW rules) or N-to-1 (when few flow API rules are represented as one HW rule) or even N-to-M. For example, tagging which is not visible outside, could be purely SW and used to build such constructions in SW. It is an implementation detail is out of scope of the generic API definition.

Yes, it sounds like over-complicating, but I really dislike above sub-action list from design point of view and that's why I"m trying to think in different directions.

Quoted 2 lines

2. Using PASSTHRU will force the order of flows (sure it can be done using priorities but it is more complex to the application to implement)

See above.

Quoted 2 lines

3. PASSTHRU will mean that there will be 2 terminal action for each flow (for example queue index 2 / passthru) this also is not native to RTE flow.

Sorry, but there are two branches for terminating actions in the sampling action design anyway (yes, internal/hidden). You need two copies of the packet, so whatever you do it will be two terminating actions.

Quoted 3 lines

4. since we want to select only part of the packets, and we want to have some of the actions done on both
packets (the sampled and the standard one) and then we want on the sampled packet do some specific actions
while on the standard packet do different actions.

Yes, it is not a problem with PASSTHRU.

Quoted 8 lines

Lest check the following use case:
Application is using full offload traffic from the wire to a VM, which should decaped
So the basic flow is:
Flow create 0 transfer ingress pattern eth / outer.ip =x / end actions decap / port id 3
Since after the offload the application loses visibility of the traffic. it still wants to sample some of the traffic in order to verify that the traffic is valid. So the application request to receive some of the original traffic and mark it with id.

Quoted 8 lines

If we use the original approach (the one in the patch) we will need something like this:
Flow 1: flow create 0 transfer ingress pattern eth / outer.ip=x / end actions sample(ratio 2, actions mark id 3 / port pf)) / decap / port 3

In the PASSTHRU concept (I'm not sure I can even create such flows)
Flow 1: flow create 0 transfer ingress pattern eth / outer.ip =x / end actions decap / port 2 /passtthru // original request
Flow 2: flow create 0 transfer ingress pattern eth/ outer.ip=x / should sample (new item that selects if the packet is selected based on the ratio)end act / mark / port pf

The main issue with this case the decap is before the sample so the sample will get decap packet.

Order should be simply different: first sampling with pass- through, second decap and deliver to VM.

Yes, I realize that two actions with basically the same match (modulo sampling match) is not ideal for mapping to HW (even if it collapsed into trivial tag match which pre-rule to make tagging). I'm not 100% happy with it, but I'm even less happy with sub-action list design and just trying to find better alternative solution.

Quoted 6 lines

So when looking at everything I think the original API is the best approach.
For the record I think that passthru action is very important and should be supported but not the best one for this feature.

Thanks,
Ori

#18 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi All,

Quoted 118 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Monday, June 29, 2020 4:12 PM
To: Ori Kam <[email protected]>; Jiawei(Jonny) Wang <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Adrien Mazarguil <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi all,

CC Adrien

(I apologize for pulling you to the rte_flow API discussions once again, but may be you can find spare time and share your thoughts. Your opinion as an author and architect of the rte_flow API would be very useful and highly appreciated.)

Quoted 7 lines · Ori Kam

Hi all,

Quoted 5 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Sunday, June 28, 2020 7:19 PM
To: Jiawei(Jonny) Wang <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>;

Matan

Quoted 3 lines
Quoted 3 lines

Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected];

[email protected]

Quoted 53 lines
Quoted 53 lines

Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Quoted 2 lines · Jiawei(Jonny) Wang

On Sunday, June 28, 2020 4:27 PM, Andrew Rybchenko

Quoted 46 lines · <[email protected]> wrote:
Quoted 46 lines · Jiawei Wang
Quoted 6 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 6 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

[snip]

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +4 -0
@@ -2709,6 +2716,28 @@ struct rte_flow_action {  struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2731

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+vport
+ * in the predefined probabiilty, All the packets continues
+processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Review struct rte_flow_action { struct rte_flow; · line 2732

Quoted 1 line
(quoted diff) +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2737

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;

This design idea does not look good to me from the very beginning. IMHO

it

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

does not fit flow API overall design.
I mean sub-action list.

As I understand Linux iptables solves it on match level (i.e. in pattern). E.g. "limit" extension which is basically sampling. Sampling using meta pattern item in combination with PASSTHRU action (to make sampling actions

non-

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

terminating if required) is a better solution from design point of view.

On our design, there're sample flow path and normal flow path, each path

can have different actions.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

The defined sub-actions list only applied for sampled packets in the sample

flow path;

Quoted 2 lines

For normal path, all packets will continue to go with the original actions.

In my too.

First as far as I know TC works close to the suggest approach (that by itself

doesn’t mean anything)

Quoted 2 lines

The concept of a PASSTHRU is a good one but it has some issue to consider:
1. When using PASSTHRU it will mean that the matching part will be needed

Quoted 9 lines

to be checked

Quoted 1 line

more times this will have performance penalty , also number of HW have

limited number of flow that can be offload

Quoted 1 line

this will approach will waste resources.

Marking or tagging could be used to address it. E.g. target traffic could be tagged first, then matching by tag should be used to sample and to do HW offloads.

In this case you are forcing at least two steps, this will hurt performance. Matching on mark is the same as matching on other items. While it may have extra penalty to add the extra mark action. (this is general HW issue I assume number of manufactures have the same limitation)

Quoted 10 lines

Moreover, mapping of rte_flow API rules into HW rule is not required to be 1-to-1. Yes, 1-to-1 is simple, but it could be more complicated 1-to-N (when one rte_flow API rule is represented by many HW rules) or N-to-1 (when few flow API rules are represented as one HW rule) or even N-to-M. For example, tagging which is not visible outside, could be purely SW and used to build such constructions in SW. It is an implementation detail is out of scope of the generic API definition.

I don’t understand this part. I never said that 1 to 1 is needed but if you try to combine flows in SW it means that you must keep all flows in the PMD in order to combine them. I now some HW must do that, but not all of them and if they don’t it is just a huge memory waste.

Quoted 4 lines

Yes, it sounds like over-complicating, but I really dislike above sub-action list from design point of view and that's why I"m trying to think in different directions.

Thinking in different direction is always good.
I just think that between the two approaches I like the original better. May be you can explain your reason for your opinion and we can find the best solution together?

Quoted 6 lines
Quoted 1 line

2. Using PASSTHRU will force the order of flows (sure it can be done using

priorities but it is more complex to

Quoted 1 line

the application to implement)

See above.

See above 😊

Quoted 9 lines
Quoted 1 line

3. PASSTHRU will mean that there will be 2 terminal action for each flow (for

example queue index 2 / passthru)

Quoted 1 line

this also is not native to RTE flow.

Sorry, but there are two branches for terminating actions in the sampling action design anyway (yes, internal/hidden). You need two copies of the packet, so whatever you do it will be two terminating actions.

Yes but you can look at it as 1 flow with 2 sets of actions and not two flows.

Quoted 29 lines
Quoted 1 line

4. since we want to select only part of the packets, and we want to have some

of the actions done on both

Quoted 1 line

packets (the sampled and the standard one) and then we want on the

sampled packet do some specific actions

Quoted 1 line

while on the standard packet do different actions.

Yes, it is not a problem with PASSTHRU.

Quoted 2 lines

Lest check the following use case:
Application is using full offload traffic from the wire to a VM, which should

decaped

Quoted 2 lines

So the basic flow is:
Flow create 0 transfer ingress pattern eth / outer.ip =x / end actions decap /

port id 3

Quoted 1 line

Since after the offload the application loses visibility of the traffic. it still

wants to sample some of the traffic

Quoted 1 line

in order to verify that the traffic is valid. So the application request to receive

some of the original traffic and

Quoted 3 lines

mark it with id.

If we use the original approach (the one in the patch) we will need something

like this:

Quoted 1 line

Flow 1: flow create 0 transfer ingress pattern eth / outer.ip=x / end actions

sample(ratio 2, actions mark id 3 / port pf)) / decap / port 3

Quoted 3 lines

In the PASSTHRU concept (I'm not sure I can even create such flows) Flow 1: flow create 0 transfer ingress pattern eth / outer.ip =x / end actions

decap / port 2 /passtthru // original request

Quoted 1 line

Flow 2: flow create 0 transfer ingress pattern eth/ outer.ip=x / should sample

Quoted 9 lines

(new item that selects if the packet is selected based on the ratio)end act / mark / port pf

Quoted 2 lines

The main issue with this case the decap is before the sample so the sample

will get decap packet.

Order should be simply different: first sampling with pass- through, second decap and deliver to VM.

Then in your case the packet will be marked. Which is not what the application requested.

Quoted 7 lines

Yes, I realize that two actions with basically the same match (modulo sampling match) is not ideal for mapping to HW (even if it collapsed into trivial tag match which pre-rule to make tagging). I'm not 100% happy with it, but I'm even less happy with sub-action list design and just trying to find better alternative solution.

Please see above, maybe we can find the best solution together.

Quoted 7 lines
Quoted 2 lines

So when looking at everything I think the original API is the best approach. For the record I think that passthru action is very important and should be

supported but not the best one for this feature.

Quoted 4 lines

Thanks,
Ori

Best,
Ori

Acked-by
#19 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi All,

After considering both approaches, I think the original is the better approach.

Thanks,
Ori

Quoted 266 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Ori Kam
Sent: Monday, June 29, 2020 5:30 PM
To: Andrew Rybchenko <[email protected]>; Jiawei(Jonny) Wang <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Adrien Mazarguil <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi All,

Quoted 8 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Monday, June 29, 2020 4:12 PM
To: Ori Kam <[email protected]>; Jiawei(Jonny) Wang <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected];

[email protected];

Quoted 21 lines

Adrien Mazarguil <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

Hi all,

CC Adrien

(I apologize for pulling you to the rte_flow API discussions once again, but may be you can find spare time and share your thoughts. Your opinion as an author and architect of the rte_flow API would be very useful and highly appreciated.)

Quoted 7 lines · Ori Kam

Hi all,

Quoted 5 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Sunday, June 28, 2020 7:19 PM
To: Jiawei(Jonny) Wang <[email protected]>; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>;

Quoted 6 lines

Matan

Quoted 3 lines
Quoted 3 lines

Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected];

[email protected]

Quoted 1 line
Quoted 1 line

Subject: Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for

rte

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines

flow

Quoted 2 lines · Jiawei(Jonny) Wang

On Sunday, June 28, 2020 4:27 PM, Andrew Rybchenko

Quoted 46 lines · <[email protected]> wrote:
Quoted 46 lines · Jiawei Wang
Quoted 6 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 6 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

[snip]

Quoted 7 lines
(quoted diff) +4 -0
@@ -2709,6 +2716,28 @@ struct rte_flow_action {  struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE

Review struct rte_flow_action { struct rte_flow; · line 2731

Quoted 10 lines
(quoted diff) +10 -0
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+vport
+ * in the predefined probabiilty, All the packets continues
+processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Review struct rte_flow_action { struct rte_flow; · line 2732

Quoted 1 line
(quoted diff) +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review struct rte_flow_action { struct rte_flow; · line 2738

Quoted 6 lines
(quoted diff) +6 -0
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;

This design idea does not look good to me from the very beginning.

IMHO

Quoted 5 lines

it

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

does not fit flow API overall design.
I mean sub-action list.

As I understand Linux iptables solves it on match level (i.e. in pattern).

E.g.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"limit" extension which is basically sampling. Sampling using meta

pattern

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

item in combination with PASSTHRU action (to make sampling actions

non-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

terminating if required) is a better solution from design point of view.

On our design, there're sample flow path and normal flow path, each

path

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

can have different actions.

Quoted 1 line

The defined sub-actions list only applied for sampled packets in the

sample

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

flow path;

Quoted 2 lines

For normal path, all packets will continue to go with the original actions.

In my too.

First as far as I know TC works close to the suggest approach (that by itself

doesn’t mean anything)

Quoted 2 lines

The concept of a PASSTHRU is a good one but it has some issue to consider:
1. When using PASSTHRU it will mean that the matching part will be needed

Quoted 9 lines

to be checked

Quoted 1 line

more times this will have performance penalty , also number of HW have

limited number of flow that can be offload

Quoted 1 line

this will approach will waste resources.

Marking or tagging could be used to address it. E.g. target traffic could be tagged first, then matching by tag should be used to sample and to do HW offloads.

In this case you are forcing at least two steps, this will hurt performance. Matching on mark is the same as matching on other items. While it may have extra
penalty to add the extra mark action. (this is general HW issue I assume number of
manufactures have the same limitation)

Quoted 10 lines

Moreover, mapping of rte_flow API rules into HW rule is not required to be 1-to-1. Yes, 1-to-1 is simple, but it could be more complicated 1-to-N (when one rte_flow API rule is represented by many HW rules) or N-to-1 (when few flow API rules are represented as one HW rule) or even N-to-M. For example, tagging which is not visible outside, could be purely SW and used to build such constructions in SW. It is an implementation detail is out of scope of the generic API definition.

I don’t understand this part. I never said that 1 to 1 is needed but if you try to combine flows in SW it means that you must keep all flows in the PMD in order to combine them. I now some HW must do that, but not all of them and if they don’t it is just a huge memory waste.

Quoted 4 lines

Yes, it sounds like over-complicating, but I really dislike above sub-action list from design point of view and that's why I"m trying to think in different directions.

Thinking in different direction is always good.
I just think that between the two approaches I like the original better. May be you can explain your reason for your opinion and we can find the best solution together?

Quoted 6 lines
Quoted 1 line

2. Using PASSTHRU will force the order of flows (sure it can be done using

priorities but it is more complex to

Quoted 1 line

the application to implement)

See above.

See above 😊

Quoted 1 line
Quoted 1 line

3. PASSTHRU will mean that there will be 2 terminal action for each flow

(for

Quoted 8 lines

example queue index 2 / passthru)

Quoted 1 line

this also is not native to RTE flow.

Sorry, but there are two branches for terminating actions in the sampling action design anyway (yes, internal/hidden). You need two copies of the packet, so whatever you do it will be two terminating actions.

Yes but you can look at it as 1 flow with 2 sets of actions and not two flows.

Quoted 1 line
Quoted 1 line

4. since we want to select only part of the packets, and we want to have

some

Quoted 12 lines

of the actions done on both

Quoted 1 line

packets (the sampled and the standard one) and then we want on the

sampled packet do some specific actions

Quoted 1 line

while on the standard packet do different actions.

Yes, it is not a problem with PASSTHRU.

Quoted 2 lines

Lest check the following use case:
Application is using full offload traffic from the wire to a VM, which should

decaped

Quoted 2 lines

So the basic flow is:
Flow create 0 transfer ingress pattern eth / outer.ip =x / end actions decap

/

Quoted 4 lines

port id 3

Quoted 1 line

Since after the offload the application loses visibility of the traffic. it still

wants to sample some of the traffic

Quoted 1 line

in order to verify that the traffic is valid. So the application request to

receive

Quoted 4 lines

some of the original traffic and

Quoted 3 lines

mark it with id.

If we use the original approach (the one in the patch) we will need

something

Quoted 8 lines

like this:

Quoted 1 line

Flow 1: flow create 0 transfer ingress pattern eth / outer.ip=x / end actions

sample(ratio 2, actions mark id 3 / port pf)) / decap / port 3

Quoted 3 lines

In the PASSTHRU concept (I'm not sure I can even create such flows) Flow 1: flow create 0 transfer ingress pattern eth / outer.ip =x / end actions

decap / port 2 /passtthru // original request

Quoted 1 line

Flow 2: flow create 0 transfer ingress pattern eth/ outer.ip=x / should

sample

Quoted 9 lines

(new item that selects if the packet is selected based on the ratio)end act / mark / port pf

Quoted 2 lines

The main issue with this case the decap is before the sample so the sample

will get decap packet.

Order should be simply different: first sampling with pass- through, second decap and deliver to VM.

Then in your case the packet will be marked. Which is not what the application requested.

Quoted 7 lines

Yes, I realize that two actions with basically the same match (modulo sampling match) is not ideal for mapping to HW (even if it collapsed into trivial tag match which pre-rule to make tagging). I'm not 100% happy with it, but I'm even less happy with sub-action list design and just trying to find better alternative solution.

Please see above, maybe we can find the best solution together.

Quoted 7 lines
Quoted 2 lines

So when looking at everything I think the original API is the best approach. For the record I think that passthru action is very important and should be

supported but not the best one for this feature.

Quoted 4 lines

Thanks,
Ori

Best,
Ori

#20 lore raw

Re: [dpdk-dev] [PATCH 1/8] ethdev: introduce sample action for rte flow

In reply to Jiawei Wang

Hi Jiawei,

Please note that you are missing the doc changes.

Please update them.

Best,
Ori

Quoted 99 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
To: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Jiawei(Jonny) Wang <[email protected]>
Subject: [PATCH 1/8] ethdev: introduce sample action for rte flow

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample
will be introduced.

---
 lib/librte_ethdev/rte_flow.c |  1 +
 lib/librte_ethdev/rte_flow.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
lib/librte_ethdev/rte_flow.c +1 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct
 rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct
 rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };

int

lib/librte_ethdev/rte_flow.h +29 -1
index b0e4199..71dd82c 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * Redirects specific ratio of packets to vport or queue.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	/* packets sampled equals to '1/ratio' */
+	const uint32_t ratio;
+	/* sub-action list specific for the sampling hit cases */
+	const struct rte_flow_action *actions;
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
--

1.8.3.1

#21 lore raw

PATCH 2/8 common/mlx5: glue for default miss and sample action

In reply to Jiawei Wang

rdma-core introduce two new DR action: default miss and sample action.

Add the rdma-core commands in glue to create these two actions.

Default miss action is used for the sampled packet on FDB domain, it steering packet to eswitch manager vport.

Sample action is used for creating the sample object to implement the sampling/mirroring function.

---
 drivers/common/mlx5/Makefile          | 10 ++++++++++
 drivers/common/mlx5/linux/meson.build |  4 ++++
 drivers/common/mlx5/linux/mlx5_glue.c | 28 ++++++++++++++++++++++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++
 4 files changed, 55 insertions(+)
drivers/common/mlx5/Makefile +10 -0
index 622bde4..8db0604 100644
@@ -187,6 +187,16 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh
 		func mlx5dv_dump_dr_domain \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_default_miss \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_flow_sampler \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_MLX5DV_MMAP_GET_NC_PAGES_CMD \
 		infiniband/mlx5dv.h \
 		enum MLX5_MMAP_GET_NC_PAGES_CMD \
drivers/common/mlx5/linux/meson.build +4 -0
index 638bb2b..95f3204 100644
@@ -160,6 +160,10 @@ has_sym_args = [
 	'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
 	[ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
 	'mlx5dv_dump_dr_domain'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS', 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_default_miss'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_flow_sampler'],
 	[ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h',
 	'mlx5dv_dr_domain_set_reclaim_device_memory'],
 	[ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +28 -0
index c91ee33..ea366e2 100644
@@ -1047,6 +1047,30 @@
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_default_miss(void)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS
+	return mlx5dv_dr_action_create_default_miss();
+#else
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
+static void *
+mlx5_glue_dr_create_flow_action_sampler(
+			struct mlx5dv_dr_flow_sampler_attr *attr)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+	return mlx5dv_dr_action_create_flow_sampler(attr);
+#else
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static int
 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
 			 uint32_t *eqn)
@@ -1294,6 +1318,10 @@
 	.devx_port_query = mlx5_glue_devx_port_query,
 	.dr_dump_domain = mlx5_glue_dr_dump_domain,
 	.dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
+	.dr_create_flow_action_default_miss =
+		mlx5_glue_dr_create_flow_action_default_miss,
+	.dr_create_flow_action_sampler =
+		mlx5_glue_dr_create_flow_action_sampler,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
 	.devx_create_event_channel = mlx5_glue_devx_create_event_channel,
 	.devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +13 -0
index 5d238a4..9b1487d 100644
@@ -77,6 +77,7 @@
 #ifndef HAVE_MLX5DV_DR
 enum  mlx5dv_dr_domain_type { unused, };
 struct mlx5dv_dr_domain;
+struct mlx5dv_dr_action;
 #endif
 
 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,15 @@
 struct mlx5dv_dr_flow_meter_attr;
 #endif
 
+#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+struct mlx5dv_dr_flow_sampler_attr {
+	uint32_t sample_ratio;
+	void *default_next_table;
+	size_t num_sample_actions;
+	struct mlx5dv_dr_action **sample_actions;
+};
+#endif
+
 #ifndef HAVE_IBV_DEVX_EVENT
 struct mlx5dv_devx_event_channel { int fd; };
 struct mlx5dv_devx_async_event_hdr;
@@ -303,6 +313,9 @@ struct mlx5_glue {
 			 struct mlx5dv_devx_async_event_hdr *event_data,
 			 size_t event_resp_len);
 	void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
+	void *(*dr_create_flow_action_default_miss)(void);
+	void *(*dr_create_flow_action_sampler)
+			(struct mlx5dv_dr_flow_sampler_attr *attr);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
Acked-by on v1 2/8
#22 lore raw

Re: [dpdk-dev] [PATCH 2/8] common/mlx5: glue for default miss and sample action

Quoted 161 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
To: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Jiawei(Jonny) Wang <[email protected]>
Subject: [PATCH 2/8] common/mlx5: glue for default miss and sample action

rdma-core introduce two new DR action: default miss and sample action.

Add the rdma-core commands in glue to create these two actions.

Default miss action is used for the sampled packet on FDB domain, it steering packet to eswitch manager vport.

Sample action is used for creating the sample object to implement the sampling/mirroring function.

---
 drivers/common/mlx5/Makefile          | 10 ++++++++++
 drivers/common/mlx5/linux/meson.build |  4 ++++
 drivers/common/mlx5/linux/mlx5_glue.c | 28
++++++++++++++++++++++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++
 4 files changed, 55 insertions(+)
drivers/common/mlx5/Makefile +0 -0
index 622bde4..8db0604 100644
@@ -187,6 +187,16 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-

config-h.sh

drivers/common/mlx5/Makefile +10 -0
 		func mlx5dv_dump_dr_domain \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_default_miss \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_flow_sampler \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_MLX5DV_MMAP_GET_NC_PAGES_CMD \
 		infiniband/mlx5dv.h \
 		enum MLX5_MMAP_GET_NC_PAGES_CMD \
drivers/common/mlx5/linux/meson.build +4 -0
index 638bb2b..95f3204 100644
@@ -160,6 +160,10 @@ has_sym_args = [
 	'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
 	[ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
 	'mlx5dv_dump_dr_domain'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS',
 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_default_miss'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE',
 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_flow_sampler'],
 	[ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h',
drivers/common/mlx5/linux/meson.build +0 -0
 	'mlx5dv_dr_domain_set_reclaim_device_memory'],
 	[ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +28 -0
index c91ee33..ea366e2 100644
@@ -1047,6 +1047,30 @@
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_default_miss(void)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS
+	return mlx5dv_dr_action_create_default_miss();
+#else
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
+static void *
+mlx5_glue_dr_create_flow_action_sampler(
+			struct mlx5dv_dr_flow_sampler_attr *attr)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+	return mlx5dv_dr_action_create_flow_sampler(attr);
+#else
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static int
 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
 			 uint32_t *eqn)
@@ -1294,6 +1318,10 @@
 	.devx_port_query = mlx5_glue_devx_port_query,
 	.dr_dump_domain = mlx5_glue_dr_dump_domain,
 	.dr_reclaim_domain_memory =
 mlx5_glue_dr_reclaim_domain_memory,
+	.dr_create_flow_action_default_miss =
+		mlx5_glue_dr_create_flow_action_default_miss,
+	.dr_create_flow_action_sampler =
+		mlx5_glue_dr_create_flow_action_sampler,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
 	.devx_create_event_channel = mlx5_glue_devx_create_event_channel,

.devx_destroy_event_channel =
mlx5_glue_devx_destroy_event_channel,

drivers/common/mlx5/linux/mlx5_glue.h +13 -1
index 5d238a4..9b1487d 100644
@@ -77,6 +77,7 @@
 #ifndef HAVE_MLX5DV_DR
 enum  mlx5dv_dr_domain_type { unused, };
 struct mlx5dv_dr_domain;
+struct mlx5dv_dr_action;
 #endif
 
 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,15 @@
 struct mlx5dv_dr_flow_meter_attr;
 #endif
 
+#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+struct mlx5dv_dr_flow_sampler_attr {
+	uint32_t sample_ratio;
+	void *default_next_table;
+	size_t num_sample_actions;
+	struct mlx5dv_dr_action **sample_actions;
+};
+#endif
+
 #ifndef HAVE_IBV_DEVX_EVENT
 struct mlx5dv_devx_event_channel { int fd; };
 struct mlx5dv_devx_async_event_hdr;
@@ -303,6 +313,9 @@ struct mlx5_glue {
 			 struct mlx5dv_devx_async_event_hdr *event_data,
 			 size_t event_resp_len);
 	void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
+	void *(*dr_create_flow_action_default_miss)(void);
+	void *(*dr_create_flow_action_sampler)
+			(struct mlx5dv_dr_flow_sampler_attr *attr);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
--
Quoted 1 line

1.8.3.1

Thanks,
Ori

#23 lore raw

PATCH 3/8 common/mlx5: query sampler object capability via DevX

In reply to Jiawei Wang

Update function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.

Add the related structs definition in mlx5_prm.h.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++
 drivers/common/mlx5/mlx5_devx_cmds.h |  1 +
 drivers/common/mlx5/mlx5_prm.h       | 51 ++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
index ec92eb6..6b551f1 100644
@@ -496,6 +496,33 @@ struct mlx5_devx_obj *
 	if (!attr->eth_net_offloads)
 		return 0;
 
+	/* Query Flow Sampler Capabilitiy From FLow Table Properties Layout. */
+	memset(in, 0, sizeof(in));
+	memset(out, 0, sizeof(out));
+	MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
+	MLX5_SET(query_hca_cap_in, in, op_mod,
+		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
+		 MLX5_HCA_CAP_OPMOD_GET_CUR);
+
+	rc = mlx5_glue->devx_general_cmd(ctx,
+					 in, sizeof(in),
+					 out, sizeof(out));
+	if (rc)
+		goto error;
+	status = MLX5_GET(query_hca_cap_out, out, status);
+	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
+	if (status) {
+		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
+			"status %x, syndrome = %x",
+			status, syndrome);
+		attr->log_max_ft_sampler_num = 0;
+		return -1;
+	}
+	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
+	attr->log_max_ft_sampler_num =
+			MLX5_GET(flow_table_nic_cap,
+			hcattr, flow_table_properties.log_max_ft_sampler_num);
+
 	/* Query HCA offloads for Ethernet protocol. */
 	memset(in, 0, sizeof(in));
 	memset(out, 0, sizeof(out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
index 25704ef..a9cfe6d 100644
@@ -90,6 +90,7 @@ struct mlx5_hca_attr {
 	uint32_t vhca_id:16;
 	uint32_t relaxed_ordering_write:1;
 	uint32_t relaxed_ordering_read:1;
+	uint32_t log_max_ft_sampler_num:8;
 	struct mlx5_hca_qos_attr qos;
 	struct mlx5_hca_vdpa_attr vdpa;
 };
drivers/common/mlx5/mlx5_prm.h +51 -0

69 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Acked-by on v1 3/8
#24 lore raw

Re: [dpdk-dev] [PATCH 3/8] common/mlx5: query sampler object capability via DevX

Quoted 8 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
Jiawei(Jonny) Wang <[email protected]>
Subject: [PATCH 3/8] common/mlx5: query sampler object capability via DevX

Quoted 8 lines

Update function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.

Add the related structs definition in mlx5_prm.h.

---

Thanks,
Ori

#25 lore raw

PATCH 4/8 net/mlx5: add the validate sample action

In reply to Jiawei Wang

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX or DEFAULT_MISS in FDB.

Only NIC_RX support with addition optinal actions.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 130 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
index f0147e6..5c057d3 100644
@@ -878,6 +878,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config.hca_attr.log_max_ft_sampler_num > 0  &&
+		    config.dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config.hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register for"
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not supported!\n");
+		}
+#endif
 	}
 	if (config.mprq.enabled && mprq) {
 		if (config.mprq.stride_num_n &&
drivers/net/mlx5/mlx5.h +1 -0
index 8a09ebc..c2a875c 100644
@@ -607,6 +607,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management. */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
index 2c96677..902380b 100644
@@ -200,6 +200,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SET_IPV4_DSCP (1ull << 32)
 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 35)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +130 -0

142 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#26 lore raw

Re: [dpdk-dev] [PATCH 4/8] net/mlx5: add the validate sample action

Hi Jiawei,

PSB.

Best,
Ori

Quoted 9 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
Subject: [PATCH 4/8] net/mlx5: add the validate sample action

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX or DEFAULT_MISS in FDB.

What is the DEFAULT_MISS action?
I think from reading the code that you mean that no action is allowed and it is always goes to e-switch manager / go to PF, am I correct?

Quoted 233 lines

Only NIC_RX support with addition optinal actions.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 130
+++++++++++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +9 -0
index f0147e6..5c057d3 100644
@@ -878,6 +878,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) &&
 defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config.hca_attr.log_max_ft_sampler_num > 0  &&
+		    config.dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config.hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register

for"

drivers/net/mlx5/linux/mlx5_os.c +3 -0
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not

supported!\n");

drivers/net/mlx5/linux/mlx5_os.c +2 -0
+		}
+#endif
 	}
 	if (config.mprq.enabled && mprq) {
 		if (config.mprq.stride_num_n &&
drivers/net/mlx5/mlx5.h +1 -0
index 8a09ebc..c2a875c 100644
@@ -607,6 +607,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management.
 */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share.
 */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
drivers/net/mlx5/mlx5.h +0 -0
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
index 2c96677..902380b 100644
@@ -200,6 +200,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SET_IPV4_DSCP (1ull << 32)
 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 35)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +47 -0
index f174009..710c0f3 100644
@@ -3925,6 +3925,127 @@ struct field_modify_info modify_tcp[] = {
 }
 
 /**
+ * Validate the sample action.
+ *
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
+ * @param[in] action
+ *   Pointer to the sample action.
+ * @param[in] dev
+ *   Pointer to the Ethernet device structure.
+ * @param[in] attr
+ *   Attributes of flow that includes this action.
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+flow_dv_validate_action_sample(uint64_t action_flags,
+			      const struct rte_flow_action *action,
+			      struct rte_eth_dev *dev,
+			      const struct rte_flow_attr *attr,
+			      struct rte_flow_error *error)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_dev_config *dev_conf = &priv->config;
+	const struct rte_flow_action_sample *sample = action->conf;
+	const struct rte_flow_action *act = sample->actions;
+	uint64_t sub_action_flags = 0;
+	int actions_n = 0;
+	int ret;
+
+	if (!attr->group)
+		return rte_flow_error_set(error, ENOTSUP,
+
 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
+					  NULL, "root table is not supported");
+	if (!priv->config.devx || !priv->sampler_en)
+		return rte_flow_error_set(error, ENOTSUP,
+
 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL,
+					  "sample action not supported");
+	if (!(action->conf))
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,
 action,
+					  "configuration cannot be null");
+	if (sample->ratio == 0)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,

action,

drivers/net/mlx5/mlx5_flow_dv.c +4 -0
+					  "ratio value start from 1");
+	if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,

NULL,

drivers/net/mlx5/mlx5_flow_dv.c +4 -0
+					  "Duplicate sample actions set");
+	if (action_flags & MLX5_FLOW_ACTION_METER)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,

action,

drivers/net/mlx5/mlx5_flow_dv.c +6 -0
+					  "wrong action order, meter should "
+					  "be after sample action");
+	for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
+		if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
+			return rte_flow_error_set(error, ENOTSUP,
+

RTE_FLOW_ERROR_TYPE_ACTION,

drivers/net/mlx5/mlx5_flow_dv.c +18 -0
+						  act, "too many actions");
+		switch (act->type) {
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			ret = mlx5_flow_validate_action_queue(act,
+							      sub_action_flags,
+							      dev,
+							      attr, error);
+			if (ret < 0)
+				return ret;
+			sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
+			break;
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			ret = flow_dv_validate_action_mark(dev, act,
+							   sub_action_flags,
+							   attr, error);
+			if (ret < 0)
+				return ret;
+			if (dev_conf->dv_xmeta_en !=

MLX5_XMETA_MODE_LEGACY)

drivers/net/mlx5/mlx5_flow_dv.c +1 -0
+				sub_action_flags |=

MLX5_FLOW_ACTION_MARK |
+

	MLX5_FLOW_ACTION_MARK_EXT;
drivers/net/mlx5/mlx5_flow_dv.c +2 -0
+			else
+				sub_action_flags |=

MLX5_FLOW_ACTION_MARK;

drivers/net/mlx5/mlx5_flow_dv.c +10 -0
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			ret = flow_dv_validate_action_count(dev, error);
+			if (ret < 0)
+				return ret;
+			sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
+			break;
+		default:
+			return rte_flow_error_set(error, ENOTSUP,
+

RTE_FLOW_ERROR_TYPE_ACTION,

drivers/net/mlx5/mlx5_flow_dv.c +9 -0
+						  NULL,
+						  "Doesn't support optional "
+						  "action");
+		}
+	}
+	if (attr->ingress && !attr->transfer) {
+		if (!(sub_action_flags & MLX5_FLOW_ACTION_QUEUE))
+			return rte_flow_error_set(error, EINVAL,
+

RTE_FLOW_ERROR_TYPE_ACTION,

drivers/net/mlx5/mlx5_flow_dv.c +12 -0
+						  NULL,
+						  "Ingress must has a dest "
+						  "QUEUE for Sample");
+	} else if (attr->egress && !attr->transfer) {
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ACTION,
+					  NULL,
+					  "Sample Only support Ingress "
+					  "or E-Switch");
+	} else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ACTION,

NULL,

drivers/net/mlx5/mlx5_flow_dv.c +16 -0
+					  "E-Switch doesn't support any "
+					  "optinal action for sampling");
+	}
+	return 0;
+}
+
+/**
  * Find existing modify-header resource or create and register a new one.
  *
  * @param dev[in, out]
@@ -5539,6 +5660,15 @@ struct field_modify_info modify_tcp[] = {
 			action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
 			rw_act_num += MLX5_ACT_NUM_SET_DSCP;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SAMPLE:
+			ret = flow_dv_validate_action_sample(action_flags,
+							     actions, dev,
+							     attr, error);
+			if (ret < 0)
+				return ret;
+			action_flags |= MLX5_FLOW_ACTION_SAMPLE;
+			++actions_n;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 

RTE_FLOW_ERROR_TYPE_ACTION,
--
1.8.3.1

#27 lore raw

Re: [dpdk-dev] [PATCH 4/8] net/mlx5: add the validate sample action

Quoted 24 lines

-----Original Message-----
From: Ori Kam <[email protected]>
Sent: Wednesday, July 1, 2020 2:00 AM
To: Jiawei(Jonny) Wang <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Jiawei(Jonny) Wang <[email protected]>
Subject: RE: [PATCH 4/8] net/mlx5: add the validate sample action

Hi Jiawei,

PSB.

Best,
Ori

Quoted 5 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
Subject: [PATCH 4/8] net/mlx5: add the validate sample action

Quoted 9 lines
Quoted 4 lines

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX or DEFAULT_MISS in FDB.

What is the DEFAULT_MISS action?
I think from reading the code that you mean that no action is allowed and it is always goes to e-switch manager / go to PF, am I correct?

Yes, you're right, For FDB, not addition action be allowed for sampling, the default action is go to e-switch manager port.
The DEFAULT_MISS is rdma-core action that steering packet to default miss of the steering domain, for FDB domain, it's e-switch manager port.

I'll update the commit log description.

Thanks.

Quoted 233 lines
Quoted 46 lines

Only NIC_RX support with addition optinal actions.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 130
+++++++++++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +9 -0
index f0147e6..5c057d3 100644
@@ -878,6 +878,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) &&
 defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config.hca_attr.log_max_ft_sampler_num > 0  &&
+		    config.dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config.hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register

for"

drivers/net/mlx5/linux/mlx5_os.c +3 -0
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not

supported!\n");

drivers/net/mlx5/linux/mlx5_os.c +2 -0
+		}
+#endif
 	}
 	if (config.mprq.enabled && mprq) {
 		if (config.mprq.stride_num_n &&
drivers/net/mlx5/mlx5.h index renamed from drivers/net/mlx5/mlx5.h +0 -0

8a09ebc..c2a875c 100644

drivers/net/mlx5/mlx5.h struct mlx5_priv { · line 610

Quoted 4 lines
drivers/net/mlx5/mlx5.h +0 -0
@@ -607,6 +607,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management.
 */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C

share.

Quoted 13 lines
drivers/net/mlx5/mlx5.h +1 -0
 */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
drivers/net/mlx5/mlx5.h +0 -0
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG.

*/ diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 2c96677..902380b 100644

drivers/net/mlx5/mlx5_flow.h +0 -0
@@ -200,6 +200,7 @@ enum mlx5_feature_name {  #define

MLX5_FLOW_ACTION_SET_IPV4_DSCP (1ull << 32) #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33) #define MLX5_FLOW_ACTION_AGE (1ull << 34)

drivers/net/mlx5/mlx5_flow.h enum mlx5_feature_name {

Quoted 4 lines
drivers/net/mlx5/mlx5_flow.h +1 -0
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 35)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \ diff

--git

Quoted 145 lines

a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index f174009..710c0f3 100644

drivers/net/mlx5/mlx5_flow_dv.c +50 -0
@@ -3925,6 +3925,127 @@ struct field_modify_info modify_tcp[] = {  }
 
 /**
+ * Validate the sample action.
+ *
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
+ * @param[in] action
+ *   Pointer to the sample action.
+ * @param[in] dev
+ *   Pointer to the Ethernet device structure.
+ * @param[in] attr
+ *   Attributes of flow that includes this action.
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+flow_dv_validate_action_sample(uint64_t action_flags,
+			      const struct rte_flow_action *action,
+			      struct rte_eth_dev *dev,
+			      const struct rte_flow_attr *attr,
+			      struct rte_flow_error *error) {
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_dev_config *dev_conf = &priv->config;
+	const struct rte_flow_action_sample *sample = action->conf;
+	const struct rte_flow_action *act = sample->actions;
+	uint64_t sub_action_flags = 0;
+	int actions_n = 0;
+	int ret;
+
+	if (!attr->group)
+		return rte_flow_error_set(error, ENOTSUP,
+
 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
+					  NULL, "root table is not supported");
+	if (!priv->config.devx || !priv->sampler_en)
+		return rte_flow_error_set(error, ENOTSUP,
+
 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL,
+					  "sample action not supported");
+	if (!(action->conf))
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,
 action,
+					  "configuration cannot be null");
+	if (sample->ratio == 0)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,
 action,
+					  "ratio value start from 1");
+	if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,

NULL,

drivers/net/mlx5/mlx5_flow_dv.c +4 -0
+					  "Duplicate sample actions set");
+	if (action_flags & MLX5_FLOW_ACTION_METER)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ACTION,

action,

drivers/net/mlx5/mlx5_flow_dv.c +6 -0
+					  "wrong action order, meter should "
+					  "be after sample action");
+	for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
+		if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
+			return rte_flow_error_set(error, ENOTSUP,
+

RTE_FLOW_ERROR_TYPE_ACTION,

drivers/net/mlx5/mlx5_flow_dv.c +18 -0
+						  act, "too many actions");
+		switch (act->type) {
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			ret = mlx5_flow_validate_action_queue(act,
+							      sub_action_flags,
+							      dev,
+							      attr, error);
+			if (ret < 0)
+				return ret;
+			sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
+			break;
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			ret = flow_dv_validate_action_mark(dev, act,
+							   sub_action_flags,
+							   attr, error);
+			if (ret < 0)
+				return ret;
+			if (dev_conf->dv_xmeta_en !=

MLX5_XMETA_MODE_LEGACY)

drivers/net/mlx5/mlx5_flow_dv.c +1 -0
+				sub_action_flags |=

MLX5_FLOW_ACTION_MARK |
+

	MLX5_FLOW_ACTION_MARK_EXT;
drivers/net/mlx5/mlx5_flow_dv.c +2 -0
+			else
+				sub_action_flags |=

MLX5_FLOW_ACTION_MARK;

drivers/net/mlx5/mlx5_flow_dv.c +10 -0
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			ret = flow_dv_validate_action_count(dev, error);
+			if (ret < 0)
+				return ret;
+			sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
+			break;
+		default:
+			return rte_flow_error_set(error, ENOTSUP,
+

RTE_FLOW_ERROR_TYPE_ACTION,

drivers/net/mlx5/mlx5_flow_dv.c +9 -0
+						  NULL,
+						  "Doesn't support optional "
+						  "action");
+		}
+	}
+	if (attr->ingress && !attr->transfer) {
+		if (!(sub_action_flags & MLX5_FLOW_ACTION_QUEUE))
+			return rte_flow_error_set(error, EINVAL,
+

RTE_FLOW_ERROR_TYPE_ACTION,

drivers/net/mlx5/mlx5_flow_dv.c +12 -0
+						  NULL,
+						  "Ingress must has a dest "
+						  "QUEUE for Sample");
+	} else if (attr->egress && !attr->transfer) {
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ACTION,
+					  NULL,
+					  "Sample Only support Ingress "
+					  "or E-Switch");
+	} else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ACTION,

NULL,

drivers/net/mlx5/mlx5_flow_dv.c +7 -0
+					  "E-Switch doesn't support any "
+					  "optinal action for sampling");
+	}
+	return 0;
+}
+
+/**
  * Find existing modify-header resource or create and register a new one.
  *
  * @param dev[in, out]

drivers/net/mlx5/mlx5_flow_dv.c struct field_modify_info modify_tcp[] = { · line 5660

Quoted 1 line
drivers/net/mlx5/mlx5_flow_dv.c +0 -0
@@ -5539,6 +5660,15 @@ struct field_modify_info modify_tcp[] = {
 			action_flags |=

MLX5_FLOW_ACTION_SET_IPV6_DSCP;

Quoted 17 lines
drivers/net/mlx5/mlx5_flow_dv.c +9 -0
 			rw_act_num += MLX5_ACT_NUM_SET_DSCP;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SAMPLE:
+			ret = flow_dv_validate_action_sample(action_flags,
+							     actions, dev,
+							     attr, error);
+			if (ret < 0)
+				return ret;
+			action_flags |= MLX5_FLOW_ACTION_SAMPLE;
+			++actions_n;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 

RTE_FLOW_ERROR_TYPE_ACTION,
--
1.8.3.1

#28 lore raw

PATCH 5/8 net/mlx5: split sample flow into two sub flows

In reply to Jiawei Wang

Add the sampler action resource structs definition.

The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.

For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.

---
 drivers/net/mlx5/mlx5.c      |  11 ++
 drivers/net/mlx5/mlx5.h      |   3 +
 drivers/net/mlx5/mlx5_flow.c | 254 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h |  37 +++++++
 4 files changed, 301 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
index ddbe29d..4a52462 100644
@@ -238,6 +238,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		.free = rte_free,
 		.type = "mlx5_jump_ipool",
 	},
+	{
+		.size = sizeof(struct mlx5_flow_dv_sample_resource),
+		.trunk_size = 64,
+		.grow_trunk = 3,
+		.grow_shift = 2,
+		.need_lock = 0,
+		.release_mem_en = 1,
+		.malloc = rte_malloc_socket,
+		.free = rte_free,
+		.type = "mlx5_sample_ipool",
+	},
 #endif
 	{
 		.size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
index c2a875c..7394753 100644
@@ -51,6 +51,7 @@ enum mlx5_ipool_index {
 	MLX5_IPOOL_TAG, /* Pool for tag resource. */
 	MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
 	MLX5_IPOOL_JUMP, /* Pool for jump resource. */
+	MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */
 #endif
 	MLX5_IPOOL_MTR, /* Pool for meter resource. */
 	MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -510,6 +511,7 @@ struct mlx5_flow_tbl_resource {
 /* Tables for metering splits should be added here. */
 #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)
 #define MLX5_MAX_TABLES_FDB UINT16_MAX
+#define MLX5_FLOW_TABLE_FACTOR 10
 
 /* ID generation structure. */
 struct mlx5_flow_id_pool {
@@ -558,6 +560,7 @@ struct mlx5_dev_ctx_shared {
 	struct mlx5_hlist *tag_table;
 	uint32_t port_id_action_list; /* List of port ID actions. */
 	uint32_t push_vlan_action_list; /* List of push VLAN actions. */
+	uint32_t sample_action_list; /* List of sample actions. */
 	struct mlx5_flow_counter_mng cmng; /* Counters management structure. */
 	struct mlx5_indexed_pool *ipool[MLX5_IPOOL_MAX];
 	/* Memory Pool for mlx5 flow resources. */
drivers/net/mlx5/mlx5_flow.c +250 -4

296 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +37 -0
index 902380b..941de5f 100644
@@ -79,6 +79,7 @@ enum mlx5_feature_name {
 	MLX5_COPY_MARK,
 	MLX5_MTR_COLOR,
 	MLX5_MTR_SFX,
+	MLX5_SAMPLE_FDB,
 };
 
 /* Pattern outer Layer bits. */
@@ -498,6 +499,38 @@ struct mlx5_flow_tbl_data_entry {
 	uint32_t idx; /**< index for the indexed mempool. */
 };
 
+/* Sub rdma-core actions list. */
+struct mlx5_flow_sub_actions_list {
+	uint32_t actions_num; /**< Number of sample actions. */
+	uint64_t action_flags;
+	void *dr_queue_action;
+	void *dr_tag_action;
+	void *dr_cnt_action;
+};
+
+/* Sample sub-actions resource list. */
+struct mlx5_flow_sub_actions_idx {
+	uint32_t rix_hrxq; /**< Hash Rx queue object index. */
+	uint32_t rix_tag; /**< Index to the tag action. */
+	uint32_t cnt;
+};
+
+/* Sample action resource structure. */
+struct mlx5_flow_dv_sample_resource {
+	ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
+	rte_atomic32_t refcnt; /**< Reference counter. */
+	void *verbs_action; /**< Verbs sample action object. */
+	uint8_t ft_type; /** Flow Table Type */
+	uint32_t ft_id; /** Flow Table Level */
+	void *normal_path_tbl; /** Flow Table pointer */
+	void *default_miss; /** default_miss dr_action. */
+	uint32_t ratio;   /** Sample Ratio */
+	struct mlx5_flow_sub_actions_idx sample_idx;
+	/**< Action index resources. */
+	struct mlx5_flow_sub_actions_list sample_act;
+	/**< Action resources. */
+};
+
 /* Verbs specification header. */
 struct ibv_spec_header {
 	enum ibv_flow_spec_type type;
@@ -526,6 +559,8 @@ struct mlx5_flow_handle_dv {
 	/**< Index to push VLAN action resource in cache. */
 	uint32_t rix_tag;
 	/**< Index to the tag action. */
+	uint32_t rix_sample;
+	/**< Index to sample action resource in cache. */
 } __rte_packed;
 
 /** Device flow handle structure: used both for creating & destroying. */
@@ -589,6 +624,8 @@ struct mlx5_flow_dv_workspace {
 	/**< Pointer to the jump action resource. */
 	struct mlx5_flow_dv_match_params value;
 	/**< Holds the value that the packet is compared to. */
+	struct mlx5_flow_dv_sample_resource *sample_res;
+	/**< Pointer to the sample action resource. */
 };
 
 /*
Signature · 1 line
1.8.3.1
Acked-by on v1 5/8
#29 lore raw

Re: [dpdk-dev] [PATCH 5/8] net/mlx5: split sample flow into two sub flows

Hi Jiawei,

Please fix the small comment below and send with my ack

Best,
Ori

Quoted 142 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
To: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Jiawei(Jonny) Wang <[email protected]>
Subject: [PATCH 5/8] net/mlx5: split sample flow into two sub flows

Add the sampler action resource structs definition.

The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.

For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.

---
 drivers/net/mlx5/mlx5.c      |  11 ++
 drivers/net/mlx5/mlx5.h      |   3 +
 drivers/net/mlx5/mlx5_flow.c | 254
++++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h |  37 +++++++
 4 files changed, 301 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.c +0 -0
index ddbe29d..4a52462 100644
@@ -238,6 +238,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared)

mlx5_dev_ctx_list =

drivers/net/mlx5/mlx5.c +11 -0
 		.free = rte_free,
 		.type = "mlx5_jump_ipool",
 	},
+	{
+		.size = sizeof(struct mlx5_flow_dv_sample_resource),
+		.trunk_size = 64,
+		.grow_trunk = 3,
+		.grow_shift = 2,
+		.need_lock = 0,
+		.release_mem_en = 1,
+		.malloc = rte_malloc_socket,
+		.free = rte_free,
+		.type = "mlx5_sample_ipool",
+	},
 #endif
 	{
 		.size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
index c2a875c..7394753 100644
@@ -51,6 +51,7 @@ enum mlx5_ipool_index {
 	MLX5_IPOOL_TAG, /* Pool for tag resource. */
 	MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
 	MLX5_IPOOL_JUMP, /* Pool for jump resource. */
+	MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */
 #endif
 	MLX5_IPOOL_MTR, /* Pool for meter resource. */
 	MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -510,6 +511,7 @@ struct mlx5_flow_tbl_resource {
 /* Tables for metering splits should be added here. */
 #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)
 #define MLX5_MAX_TABLES_FDB UINT16_MAX
+#define MLX5_FLOW_TABLE_FACTOR 10
 
 /* ID generation structure. */
 struct mlx5_flow_id_pool {
@@ -558,6 +560,7 @@ struct mlx5_dev_ctx_shared {
 	struct mlx5_hlist *tag_table;
 	uint32_t port_id_action_list; /* List of port ID actions. */
 	uint32_t push_vlan_action_list; /* List of push VLAN actions. */
+	uint32_t sample_action_list; /* List of sample actions. */
 	struct mlx5_flow_counter_mng cmng; /* Counters management

structure. */

drivers/net/mlx5/mlx5.h +0 -0
 	struct mlx5_indexed_pool *ipool[MLX5_IPOOL_MAX];
 	/* Memory Pool for mlx5 flow resources. */
drivers/net/mlx5/mlx5_flow.c +45 -0
index 3a48b89..7c65a9a 100644
@@ -360,6 +360,8 @@ struct mlx5_flow_tunnel_info {
 		return REG_B;
 	case MLX5_HAIRPIN_TX:
 		return REG_A;
+	case MLX5_SAMPLE_FDB:
+		return REG_C_0;
 	case MLX5_METADATA_RX:
 		switch (config->dv_xmeta_en) {
 		case MLX5_XMETA_MODE_LEGACY:
@@ -3878,6 +3880,137 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 	return 0;
 }
 
+
+/**
+ * Check the match action from the action list.
+ *
+ * @param[in] actions
+ *   Pointer to the list of actions.
+ * @param[in] action
+ *   The action to be check if exist.
+ *
+ * @return
+ *   > 0 the total number of actions.
+ *   0 if not found match action in action list.
+ */
+static int
+flow_check_match_action(const struct rte_flow_action actions[],
+					enum rte_flow_action_type action)
+{
+	int actions_n = 0;
+	int flag = 0;
+
+	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
+		if (actions->type == action)
+			flag = 1;
+		actions_n++;
+	}
+	/* Count RTE_FLOW_ACTION_TYPE_END. */
+	return flag ? actions_n + 1 : 0;
+}
+
+/**
+ * Split the sample flow.
+ *
+ * As sample flow will split to two sub flow, sample flow with
+ * sample action, the other actions will move to new suffix flow.
+ *
+ * Also add unique tag id with tag action in the sample flow,
+ * the same tag id will be as match in the suffix flow.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[in] attr
+ *   Flow rule attributes.
+ * @param[out] sfx_items

drivers/net/mlx5/mlx5_flow.c uint32_t mlx5_flow_adjust_priority(struct · line 3936

Quoted 10 lines
drivers/net/mlx5/mlx5_flow.c +10 -0
+ *   Suffix flow match items (list terminated by the END pattern item).
+ * @param[in] actions
+ *   Associated actions (list terminated by the END action).
+ * @param[out] actions_sfx
+ *   Suffix flow actions.
+ * @param[out] actions_pre
+ *   Prefix flow actions.
+ *
+ * @return
+ *   0 on success.

It looks like the function also returns the tag id.

Quoted 318 lines
drivers/net/mlx5/mlx5_flow.c +78 -0
+ */
+static int
+flow_sample_split_prep(struct rte_eth_dev *dev,
+		 const struct rte_flow_attr *attr,
+		 struct rte_flow_item sfx_items[],
+		 const struct rte_flow_action actions[],
+		 struct rte_flow_action actions_sfx[],
+		 struct rte_flow_action actions_pre[])
+{
+	struct mlx5_rte_flow_action_set_tag *set_tag;
+	struct mlx5_rte_flow_item_tag *tag_spec;
+	struct mlx5_rte_flow_item_tag *tag_mask;
+	struct rte_flow_item *tag_item;
+	struct rte_flow_action *tag_action = NULL;
+	bool pre_sample = true;
+	struct rte_flow_error error;
+	uint32_t tag_id;
+
+	/* Prepare the actions for prefix and suffix flow. */
+	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
+		struct rte_flow_action **action_cur = NULL;
+
+		switch (actions->type) {
+		case RTE_FLOW_ACTION_TYPE_SAMPLE:
+			/* Add the extra tag action first. */
+			tag_action = actions_pre;
+			tag_action->type = (enum rte_flow_action_type)
+
 	MLX5_RTE_FLOW_ACTION_TYPE_TAG;
+			actions_pre++;
+			break;
+		case RTE_FLOW_ACTION_TYPE_JUMP:
+		case RTE_FLOW_ACTION_TYPE_METER:
+			action_cur = &actions_sfx;
+			break;
+		default:
+			break;
+		}
+		if (pre_sample && !action_cur)
+			action_cur = &actions_pre;
+		else
+			action_cur = &actions_sfx;
+		memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
+		(*action_cur)++;
+		if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE)
+			pre_sample = false;
+	}
+	/* Add end action to the actions. */
+	actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
+	actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
+	actions_pre++;
+	/* Set the tag. */
+	set_tag = (void *)actions_pre;
+	set_tag->id = mlx5_flow_get_reg_id(dev, attr->transfer ?
+			MLX5_SAMPLE_FDB : MLX5_APP_TAG, 0, &error);
+	tag_id = flow_qrss_get_id(dev);
+	set_tag->data = tag_id;
+	assert(tag_action);
+	tag_action->conf = set_tag;
+	/* Prepare the suffix subflow items. */
+	if (sfx_items) {
+		tag_item = sfx_items++;
+		sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
+		sfx_items++;
+		tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
+		tag_spec->data = tag_id;
+		tag_spec->id = set_tag->id;
+		tag_mask = tag_spec + 1;
+		tag_mask->data = UINT32_MAX;
+		tag_mask->id = UINT16_MAX;
+		tag_item->type = (enum rte_flow_item_type)
+				MLX5_RTE_FLOW_ITEM_TYPE_TAG;
+		tag_item->spec = tag_spec;
+		tag_item->last = NULL;
+		tag_item->mask = tag_mask;
+	}
+	return tag_id;
+}
+
 /**

* The splitting for metadata feature.
*

drivers/net/mlx5/mlx5_flow.c +1 -0
@@ -4137,6 +4270,7 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 static int
 flow_create_split_meter(struct rte_eth_dev *dev,
 			   struct rte_flow *flow,
+			   uint64_t prefix_layers,
 			   const struct rte_flow_attr *attr,
 			   const struct rte_flow_item items[],
drivers/net/mlx5/mlx5_flow.c +3 -2
 			   const struct rte_flow_action actions[],
@@ -4183,8 +4317,9 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 			goto exit;
 		}
 		/* Add the prefix subflow. */
-		ret = flow_create_split_inner(dev, flow, &dev_flow, 0, attr,
-					      items, pre_actions, external,
+		ret = flow_create_split_inner(dev, flow, &dev_flow,
+					      prefix_layers, attr, items,
+					      pre_actions, external,
 					      flow_idx, error);
 		if (ret) {
drivers/net/mlx5/mlx5_flow.c +0 -0
 			ret = -rte_errno;
@@ -4199,7 +4334,7 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 	/* Add the prefix subflow. */
 	ret = flow_create_split_metadata(dev, flow, dev_flow ?
 

flow_get_prefix_layer_flags(dev_flow) :

drivers/net/mlx5/mlx5_flow.c +60 -1
-					 0, &sfx_attr,
+					 prefix_layers, &sfx_attr,
 					 sfx_items ? sfx_items : items,
 					 sfx_actions ? sfx_actions : actions,
 					 external, flow_idx, error);
@@ -4210,6 +4345,117 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 }
 
 /**
+ * The splitting for sample feature.
+ *
+ * The sample flow will be split to two flows as prefix and
+ * suffix flow.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[in] flow
+ *   Parent flow structure pointer.
+ * @param[in] attr
+ *   Flow rule attributes.
+ * @param[in] items
+ *   Pattern specification (list terminated by the END pattern item).
+ * @param[in] actions
+ *   Associated actions (list terminated by the END action).
+ * @param[in] external
+ *   This flow rule is created by request external to PMD.
+ * @param[in] flow_idx
+ *   This memory pool index to the flow.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ * @return
+ *   0 on success, negative value otherwise
+ */
+static int
+flow_create_split_sample(struct rte_eth_dev *dev,
+			   struct rte_flow *flow,
+			   const struct rte_flow_attr *attr,
+			   const struct rte_flow_item items[],
+			   const struct rte_flow_action actions[],
+			   bool external, uint32_t flow_idx,
+			   struct rte_flow_error *error)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct rte_flow_action *sfx_actions = NULL;
+	struct rte_flow_action *pre_actions = NULL;
+	struct rte_flow_item *sfx_items = NULL;
+	struct mlx5_flow *dev_flow = NULL;
+	struct rte_flow_attr sfx_attr = *attr;
+	struct mlx5_flow_dv_sample_resource *sample_res;
+	struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
+	struct mlx5_flow_tbl_resource *sfx_tbl;
+	union mlx5_flow_tbl_key sfx_table_key;
+	size_t act_size;
+	size_t item_size;
+	uint32_t tag_id = 0;
+	int actions_n = 0;
+	int ret = 0;
+
+	if (priv->sampler_en)
+		actions_n = flow_check_match_action(actions,
+					RTE_FLOW_ACTION_TYPE_SAMPLE);
+	if (actions_n) {
+		/* The prefix actions must includes sample, tag, end. */
+		act_size = sizeof(struct rte_flow_action) * (actions_n * 2) +
+			   sizeof(struct mlx5_rte_flow_action_set_tag);
+		/* tag, end. */
+#define SAMPLE_SUFFIX_ITEM 2
+		item_size = sizeof(struct rte_flow_item) *

SAMPLE_SUFFIX_ITEM +

drivers/net/mlx5/mlx5_flow.c +5 -0
+			    sizeof(struct mlx5_rte_flow_item_tag) * 2;
+		sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
+		if (!sfx_actions)
+			return rte_flow_error_set(error, ENOMEM,
+

RTE_FLOW_ERROR_TYPE_ACTION,

drivers/net/mlx5/mlx5_flow.c +4 -0
+						  NULL, "no memory to split "
+						  "sample flow");
+		if (!attr->transfer)
+			sfx_items = (struct rte_flow_item *)((char

*)sfx_actions

drivers/net/mlx5/mlx5_flow.c +44 -1
+					+ act_size);
+		pre_actions = sfx_actions + actions_n;
+		tag_id = flow_sample_split_prep(dev, attr, sfx_items,
+						   actions, sfx_actions,
+						   pre_actions);
+		if (!tag_id) {
+			ret = -rte_errno;
+			goto exit;
+		}
+		/* Add the prefix subflow. */
+		ret = flow_create_split_inner(dev, flow, &dev_flow, 0, attr,
+					      items, pre_actions, external,
+					      flow_idx, error);
+		if (ret) {
+			ret = -rte_errno;
+			goto exit;
+		}
+		dev_flow->handle->split_flow_id = tag_id;
+		/* Set the sfx group attr. */
+		sample_res = (struct mlx5_flow_dv_sample_resource *)
+					dev_flow->dv.sample_res;
+		sfx_tbl = (struct mlx5_flow_tbl_resource *)
+					sample_res->normal_path_tbl;
+		sfx_tbl_data = container_of(sfx_tbl,
+					struct mlx5_flow_tbl_data_entry, tbl);
+		sfx_table_key.v64 = sfx_tbl_data->entry.key;
+		sfx_attr.group = sfx_attr.transfer ?
+					(sfx_table_key.table_id - 1) :
+					sfx_table_key.table_id;
+	}
+	/* Add the suffix subflow. */
+	ret = flow_create_split_meter(dev, flow, dev_flow ?
+				 flow_get_prefix_layer_flags(dev_flow) : 0,
+				 &sfx_attr, sfx_items ? sfx_items : items,
+				 sfx_actions ? sfx_actions : actions,
+				 external, flow_idx, error);
+exit:
+	if (sfx_actions)
+		rte_free(sfx_actions);
+	return ret;
+}
+
+/**
  * Split the flow to subflow set. The splitters might be linked
  * in the chain, like this:
  * flow_create_split_outer() calls:
@@ -4257,7 +4503,7 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 {
 	int ret;
 
-	ret = flow_create_split_meter(dev, flow, attr, items,
+	ret = flow_create_split_sample(dev, flow, attr, items,
 					 actions, external, flow_idx, error);
 	MLX5_ASSERT(ret <= 0);
drivers/net/mlx5/mlx5_flow.c +0 -0
 	return ret;
drivers/net/mlx5/mlx5_flow.h +37 -1
index 902380b..941de5f 100644
@@ -79,6 +79,7 @@ enum mlx5_feature_name {
 	MLX5_COPY_MARK,
 	MLX5_MTR_COLOR,
 	MLX5_MTR_SFX,
+	MLX5_SAMPLE_FDB,
 };
 
 /* Pattern outer Layer bits. */
@@ -498,6 +499,38 @@ struct mlx5_flow_tbl_data_entry {
 	uint32_t idx; /**< index for the indexed mempool. */
 };
 
+/* Sub rdma-core actions list. */
+struct mlx5_flow_sub_actions_list {
+	uint32_t actions_num; /**< Number of sample actions. */
+	uint64_t action_flags;
+	void *dr_queue_action;
+	void *dr_tag_action;
+	void *dr_cnt_action;
+};
+
+/* Sample sub-actions resource list. */
+struct mlx5_flow_sub_actions_idx {
+	uint32_t rix_hrxq; /**< Hash Rx queue object index. */
+	uint32_t rix_tag; /**< Index to the tag action. */
+	uint32_t cnt;
+};
+
+/* Sample action resource structure. */
+struct mlx5_flow_dv_sample_resource {
+	ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
+	rte_atomic32_t refcnt; /**< Reference counter. */
+	void *verbs_action; /**< Verbs sample action object. */
+	uint8_t ft_type; /** Flow Table Type */
+	uint32_t ft_id; /** Flow Table Level */
+	void *normal_path_tbl; /** Flow Table pointer */
+	void *default_miss; /** default_miss dr_action. */
+	uint32_t ratio;   /** Sample Ratio */
+	struct mlx5_flow_sub_actions_idx sample_idx;
+	/**< Action index resources. */
+	struct mlx5_flow_sub_actions_list sample_act;
+	/**< Action resources. */
+};
+
 /* Verbs specification header. */
 struct ibv_spec_header {
 	enum ibv_flow_spec_type type;
@@ -526,6 +559,8 @@ struct mlx5_flow_handle_dv {
 	/**< Index to push VLAN action resource in cache. */
 	uint32_t rix_tag;
 	/**< Index to the tag action. */
+	uint32_t rix_sample;
+	/**< Index to sample action resource in cache. */
 } __rte_packed;
 
 /** Device flow handle structure: used both for creating & destroying. */
@@ -589,6 +624,8 @@ struct mlx5_flow_dv_workspace {
 	/**< Pointer to the jump action resource. */
 	struct mlx5_flow_dv_match_params value;
 	/**< Holds the value that the packet is compared to. */
+	struct mlx5_flow_dv_sample_resource *sample_res;
+	/**< Pointer to the sample action resource. */
 };
 
 /*
--

1.8.3.1

#30 lore raw

PATCH 6/8 net/mlx5: update translate function for sample action

In reply to Jiawei Wang

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---
 drivers/net/mlx5/mlx5_flow.c    |  16 +-
 drivers/net/mlx5/mlx5_flow.h    |  14 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 502 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 511 insertions(+), 21 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
index 7c65a9a..73ef290 100644
@@ -4569,10 +4569,14 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	int hairpin_flow;
 	uint32_t hairpin_id = 0;
 	struct rte_flow_attr attr_tx = { .priority = 0 };
+	struct rte_flow_attr attr_factor = {0};
 	int ret;
 
-	hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
-	ret = flow_drv_validate(dev, attr, items, p_actions_rx,
+	memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
+	if (external)
+		attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
+	hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
+	ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
 				external, hairpin_flow, error);
 	if (ret < 0)
 		return 0;
@@ -4591,7 +4595,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		rte_errno = ENOMEM;
 		goto error_before_flow;
 	}
-	flow->drv_type = flow_get_drv_type(dev, attr);
+	flow->drv_type = flow_get_drv_type(dev, &attr_factor);
 	if (hairpin_id != 0)
 		flow->hairpin_flow_id = hairpin_id;
 	MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4637,7 +4641,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		 * depending on configuration. In the simplest
 		 * case it just creates unmodified original flow.
 		 */
-		ret = flow_create_split_outer(dev, flow, attr,
+		ret = flow_create_split_outer(dev, flow, &attr_factor,
 					      buf->entry[i].pattern,
 					      p_actions_rx, external, idx,
 					      error);
@@ -4674,8 +4678,8 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	 * the egress Flows belong to the different device and
 	 * copy table should be updated in peer NIC Rx domain.
 	 */
-	if (attr->ingress &&
-	    (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
+	if (attr_factor.ingress &&
+	    (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
 		ret = flow_mreg_update_copy_table(dev, flow, actions, error);
 		if (ret)
 			goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
index 941de5f..4163183 100644
@@ -369,6 +369,13 @@ enum mlx5_flow_fate_type {
 	MLX5_FLOW_FATE_MAX,
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /* Matcher PRM representation */
 struct mlx5_flow_dv_match_params {
 	size_t size;
@@ -599,13 +606,6 @@ struct mlx5_flow_handle {
 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
 #endif
 
-/*
- * Max number of actions per DV flow.
- * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
- * in rdma-core file providers/mlx5/verbs.c.
- */
-#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
-
 /** Device flow structure only for DV flow creation. */
 struct mlx5_flow_dv_workspace {
 	uint32_t group; /**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +494 -8

581 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#31 lore raw

Re: [dpdk-dev] [PATCH 6/8] net/mlx5: update translate function for sample action

Hi Jiawei,
PSB,

Thanks,
Ori

Quoted 123 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
Subject: [PATCH 6/8] net/mlx5: update translate function for sample action

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---
 drivers/net/mlx5/mlx5_flow.c    |  16 +-
 drivers/net/mlx5/mlx5_flow.h    |  14 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 502
+++++++++++++++++++++++++++++++++++++++-
 3 files changed, 511 insertions(+), 21 deletions(-)
drivers/net/mlx5/mlx5_flow.c +6 -2
index 7c65a9a..73ef290 100644
@@ -4569,10 +4569,14 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 	int hairpin_flow;
 	uint32_t hairpin_id = 0;
 	struct rte_flow_attr attr_tx = { .priority = 0 };
+	struct rte_flow_attr attr_factor = {0};
 	int ret;
 
-	hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
-	ret = flow_drv_validate(dev, attr, items, p_actions_rx,
+	memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
+	if (external)
+		attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
+	hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
+	ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
 				external, hairpin_flow, error);
 	if (ret < 0)
drivers/net/mlx5/mlx5_flow.c +1 -1
 		return 0;
@@ -4591,7 +4595,7 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 		rte_errno = ENOMEM;
 		goto error_before_flow;
 	}
-	flow->drv_type = flow_get_drv_type(dev, attr);
+	flow->drv_type = flow_get_drv_type(dev, &attr_factor);
 	if (hairpin_id != 0)
 		flow->hairpin_flow_id = hairpin_id;
drivers/net/mlx5/mlx5_flow.c +1 -1
 	MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4637,7 +4641,7 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 		 * depending on configuration. In the simplest
 		 * case it just creates unmodified original flow.
 		 */
-		ret = flow_create_split_outer(dev, flow, attr,
+		ret = flow_create_split_outer(dev, flow, &attr_factor,
 					      buf->entry[i].pattern,
 					      p_actions_rx, external, idx,
drivers/net/mlx5/mlx5_flow.c +2 -2
 					      error);
@@ -4674,8 +4678,8 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 	 * the egress Flows belong to the different device and
 	 * copy table should be updated in peer NIC Rx domain.
 	 */
-	if (attr->ingress &&
-	    (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP))
 {
+	if (attr_factor.ingress &&
+	    (external || attr_factor.group !=
 MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
drivers/net/mlx5/mlx5_flow.c +0 -0
 		ret = flow_mreg_update_copy_table(dev, flow, actions, error);
 		if (ret)
 			goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
index 941de5f..4163183 100644
@@ -369,6 +369,13 @@ enum mlx5_flow_fate_type {
 	MLX5_FLOW_FATE_MAX,
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /* Matcher PRM representation */
 struct mlx5_flow_dv_match_params {
 	size_t size;
@@ -599,13 +606,6 @@ struct mlx5_flow_handle {
 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
 #endif
 
-/*
- * Max number of actions per DV flow.
- * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
- * in rdma-core file providers/mlx5/verbs.c.
- */
-#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
-
 /** Device flow structure only for DV flow creation. */
 struct mlx5_flow_dv_workspace {
 	uint32_t group; /**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +4 -0
index 710c0f3..62a4a3b 100644
@@ -79,6 +79,10 @@
 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
 			     struct mlx5_flow_tbl_resource *tbl);
 
+static int
+flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
+				     uint32_t encap_decap_idx);
+
 /**
  * Initialize flow attributes structure according to flow items' types.
  *
@@ -7897,6 +7901,385 @@ struct field_modify_info modify_tcp[] = {
 }
 

drivers/net/mlx5/mlx5_flow_dv.c struct field_modify_info modify_tcp[] = { · line 7912

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +9 -0
 /**
+ * Create an Rx Hash queue.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[in] dev_flow
+ *   Pointer to the mlx5_flow.
+ * @param[in] rss_desc
+ *   Pointer to the mlx5_flow_rss_desc.
+ * @param[in, out] hrxq_idx

I think this is only used as out.

Quoted 26 lines
drivers/net/mlx5/mlx5_flow_dv.c +26 -0
+ *   Hash Rx queue index.
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
+ */
+static struct mlx5_hrxq *
+flow_dv_handle_rx_queue(struct rte_eth_dev *dev,
+			  struct mlx5_flow *dev_flow,
+			  struct mlx5_flow_rss_desc *rss_desc,
+			  uint32_t *hrxq_idx,
+			  struct rte_flow_error *error)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_flow_handle *dh = dev_flow->handle;
+	struct mlx5_hrxq *hrxq;
+
+	MLX5_ASSERT(rss_desc->queue_num);
+	*hrxq_idx = mlx5_hrxq_get(dev, rss_desc->key,
+				 MLX5_RSS_HASH_KEY_LEN,
+				 dev_flow->hash_fields,
+				 rss_desc->queue,
+				 rss_desc->queue_num);
+	if (!*hrxq_idx) {
+		*hrxq_idx = mlx5_hrxq_new

drivers/net/mlx5/mlx5_flow_dv.c struct field_modify_info modify_tcp[] = { · line 7948

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +10 -0
+				(dev, rss_desc->key,
+				MLX5_RSS_HASH_KEY_LEN,
+				dev_flow->hash_fields,
+				rss_desc->queue,
+				rss_desc->queue_num,
+				!!(dh->layers &
+				MLX5_FLOW_LAYER_TUNNEL));
+	}
+	hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
+			      *hrxq_idx);

Why do you need this line? You can compare the hrxq_idx to check for error.

Quoted 8 lines
drivers/net/mlx5/mlx5_flow_dv.c +8 -0
+	if (!hrxq) {
+		rte_flow_error_set
+			(error, rte_errno,
+			 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+			 "cannot get hash queue");
+		goto error;
+	}
+	dh->rix_hrxq = *hrxq_idx;

drivers/net/mlx5/mlx5_flow_dv.c struct field_modify_info modify_tcp[] = { · line 7966

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +10 -0
+	return hrxq;
+error:
+	/* hrxq is union, don't clear it if the flag is not set. */
+	if (dh->rix_hrxq) {
+		mlx5_hrxq_release(dev, dh->rix_hrxq);
+		dh->rix_hrxq = 0;
+	}
+	return NULL;
+}
+

[snap...]

#32 lore raw

Re: [dpdk-dev] [PATCH 6/8] net/mlx5: update translate function for sample action

Quoted 143 lines

-----Original Message-----
From: Ori Kam <[email protected]>
Sent: Wednesday, July 1, 2020 3:55 AM
To: Jiawei(Jonny) Wang <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Jiawei(Jonny) Wang <[email protected]>
Subject: RE: [PATCH 6/8] net/mlx5: update translate function for sample action

Hi Jiawei,
PSB,

Thanks,
Ori

Quoted 48 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
Subject: [PATCH 6/8] net/mlx5: update translate function for sample action

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---
 drivers/net/mlx5/mlx5_flow.c    |  16 +-
 drivers/net/mlx5/mlx5_flow.h    |  14 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 502
+++++++++++++++++++++++++++++++++++++++-
 3 files changed, 511 insertions(+), 21 deletions(-)
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_flow.c index 7c65a9a..73ef290 100644

drivers/net/mlx5/mlx5_flow.c +6 -2
@@ -4569,10 +4569,14 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 	int hairpin_flow;
 	uint32_t hairpin_id = 0;
 	struct rte_flow_attr attr_tx = { .priority = 0 };
+	struct rte_flow_attr attr_factor = {0};
 	int ret;
 
-	hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
-	ret = flow_drv_validate(dev, attr, items, p_actions_rx,
+	memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
+	if (external)
+		attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
+	hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
+	ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
 				external, hairpin_flow, error);
 	if (ret < 0)
drivers/net/mlx5/mlx5_flow.c +1 -1
 		return 0;
@@ -4591,7 +4595,7 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 		rte_errno = ENOMEM;
 		goto error_before_flow;
 	}
-	flow->drv_type = flow_get_drv_type(dev, attr);
+	flow->drv_type = flow_get_drv_type(dev, &attr_factor);
 	if (hairpin_id != 0)
 		flow->hairpin_flow_id = hairpin_id;
Quoted 1 line

MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN && @@ -

4637,7

Quoted 21 lines

+4641,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,

drivers/net/mlx5/mlx5_flow.c +3 -3
 		 * depending on configuration. In the simplest
 		 * case it just creates unmodified original flow.
 		 */
-		ret = flow_create_split_outer(dev, flow, attr,
+		ret = flow_create_split_outer(dev, flow, &attr_factor,
 					      buf->entry[i].pattern,
 					      p_actions_rx, external, idx,
 					      error);
@@ -4674,8 +4678,8 @@ uint32_t mlx5_flow_adjust_priority(struct
 rte_eth_dev *dev, int32_t priority,
 	 * the egress Flows belong to the different device and
 	 * copy table should be updated in peer NIC Rx domain.
 	 */
-	if (attr->ingress &&
-	    (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP))
 {
+	if (attr_factor.ingress &&
+	    (external || attr_factor.group !=
 MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
Quoted 1 line

ret = flow_mreg_update_copy_table(dev, flow, actions,

error);

Quoted 21 lines
drivers/net/mlx5/mlx5_flow.c +0 -0
 		if (ret)
 			goto error;
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_flow.h index 941de5f..4163183 100644

drivers/net/mlx5/mlx5_flow.h +7 -0
@@ -369,6 +369,13 @@ enum mlx5_flow_fate_type {
 	MLX5_FLOW_FATE_MAX,
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /* Matcher PRM representation */
 struct mlx5_flow_dv_match_params {
 	size_t size;

drivers/net/mlx5/mlx5_flow.h struct mlx5_flow_handle { #define · line 606

Quoted 1 line
drivers/net/mlx5/mlx5_flow.h +0 -0
@@ -599,13 +606,6 @@ struct mlx5_flow_handle {  #define
 MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))

#endif

Quoted 28 lines
drivers/net/mlx5/mlx5_flow.h +0 -7
-/*
- * Max number of actions per DV flow.
- * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
- * in rdma-core file providers/mlx5/verbs.c.
- */
-#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
-
 /** Device flow structure only for DV flow creation. */  struct
 mlx5_flow_dv_workspace {
 	uint32_t group; /**< The group index. */ diff --git

a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 710c0f3..62a4a3b 100644

drivers/net/mlx5/mlx5_flow_dv.c +4 -0
@@ -79,6 +79,10 @@
 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
 			     struct mlx5_flow_tbl_resource *tbl);
 
+static int
+flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
+				     uint32_t encap_decap_idx);
+
 /**
  * Initialize flow attributes structure according to flow items' types.
  *
@@ -7897,6 +7901,385 @@ struct field_modify_info modify_tcp[] = {  }
 
Quoted 13 lines

drivers/net/mlx5/mlx5_flow_dv.c struct field_modify_info modify_tcp[] = { · line 7912

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +9 -0
 /**
+ * Create an Rx Hash queue.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[in] dev_flow
+ *   Pointer to the mlx5_flow.
+ * @param[in] rss_desc
+ *   Pointer to the mlx5_flow_rss_desc.
+ * @param[in, out] hrxq_idx

I think this is only used as out.

right, will change it.

Quoted 30 lines
Quoted 30 lines
drivers/net/mlx5/mlx5_flow_dv.c +30 -0
+ *   Hash Rx queue index.
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
+ */
+static struct mlx5_hrxq *
+flow_dv_handle_rx_queue(struct rte_eth_dev *dev,
+			  struct mlx5_flow *dev_flow,
+			  struct mlx5_flow_rss_desc *rss_desc,
+			  uint32_t *hrxq_idx,
+			  struct rte_flow_error *error)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_flow_handle *dh = dev_flow->handle;
+	struct mlx5_hrxq *hrxq;
+
+	MLX5_ASSERT(rss_desc->queue_num);
+	*hrxq_idx = mlx5_hrxq_get(dev, rss_desc->key,
+				 MLX5_RSS_HASH_KEY_LEN,
+				 dev_flow->hash_fields,
+				 rss_desc->queue,
+				 rss_desc->queue_num);
+	if (!*hrxq_idx) {
+		*hrxq_idx = mlx5_hrxq_new
+				(dev, rss_desc->key,
+				MLX5_RSS_HASH_KEY_LEN,
+				dev_flow->hash_fields,
+				rss_desc->queue,
Quoted 9 lines

drivers/net/mlx5/mlx5_flow_dv.c struct field_modify_info modify_tcp[] = { · line 7948

Quoted 6 lines
drivers/net/mlx5/mlx5_flow_dv.c +6 -0
+				rss_desc->queue_num,
+				!!(dh->layers &
+				MLX5_FLOW_LAYER_TUNNEL));
+	}
+	hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
+			      *hrxq_idx);

Why do you need this line? You can compare the hrxq_idx to check for error.

Yes, we can check by *hrxq_idx==0 for error, or return corresponding hash rx queue object if no error. Thanks.

Quoted 21 lines
Quoted 8 lines
drivers/net/mlx5/mlx5_flow_dv.c +8 -0
+	if (!hrxq) {
+		rte_flow_error_set
+			(error, rte_errno,
+			 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+			 "cannot get hash queue");
+		goto error;
+	}
+	dh->rix_hrxq = *hrxq_idx;

drivers/net/mlx5/mlx5_flow_dv.c struct field_modify_info modify_tcp[] = { · line 7966

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +10 -0
+	return hrxq;
+error:
+	/* hrxq is union, don't clear it if the flag is not set. */
+	if (dh->rix_hrxq) {
+		mlx5_hrxq_release(dev, dh->rix_hrxq);
+		dh->rix_hrxq = 0;
+	}
+	return NULL;
+}
+

[snap...]

#33 lore raw

PATCH 7/8 net/mlx5: update the metadata register c0 support

In reply to Jiawei Wang

For Sample flow, it splits into two sub flows and using metadata register as matcher between two flows.

Meatadata register C0 filed might be also used for source vport index if kernel uses this field, this changes add the checking while do tag action with reg_c0 to decide using upper or lower 16-bits of metadata register c0 filed.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)
drivers/net/mlx5/mlx5_flow_dv.c +24 -12
index 62a4a3b..ed9d2d2e 100644
@@ -980,13 +980,24 @@ struct field_modify_info modify_tcp[] = {
  */
 static int
 flow_dv_convert_action_set_reg
-			(struct mlx5_flow_dv_modify_hdr_resource *resource,
+			(struct rte_eth_dev *dev,
+			 struct mlx5_flow_dv_modify_hdr_resource *resource,
 			 const struct rte_flow_action *action,
 			 struct rte_flow_error *error)
 {
 	const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
-	struct mlx5_modification_cmd *actions = resource->actions;
 	uint32_t i = resource->actions_num;
+	struct mlx5_priv *priv = dev->data->dev_private;
+	rte_be32_t mask = UINT32_MAX;
+	rte_be32_t data = rte_cpu_to_be_32(conf->data) & mask;
+	struct rte_flow_item item = {
+		.spec = &data,
+		.mask = &mask,
+	};
+	struct field_modify_info reg_c_x[] = {
+		[1] = {0, 0, 0},
+	};
+	int reg = conf->id;
 
 	if (i >= MLX5_MAX_MODIFY_NUM)
 		return rte_flow_error_set(error, EINVAL,
@@ -994,15 +1005,16 @@ struct field_modify_info modify_tcp[] = {
 					  "too many items to modify");
 	MLX5_ASSERT(conf->id != REG_NONE);
 	MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
-	actions[i] = (struct mlx5_modification_cmd) {
-		.action_type = MLX5_MODIFICATION_TYPE_SET,
-		.field = reg_to_field[conf->id],
-	};
-	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
-	actions[i].data1 = rte_cpu_to_be_32(conf->data);
-	++i;
-	resource->actions_num = i;
-	return 0;
+	if (reg == REG_C_0) {
+		uint32_t msk_c0 = priv->sh->dv_regc0_mask;
+		uint32_t shl_c0 = rte_bsf32(msk_c0);
+		data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
+		mask = rte_cpu_to_be_32(mask) & msk_c0;
+		mask = rte_cpu_to_be_32(mask << shl_c0);
+	}
+	reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
+	return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
+			MLX5_MODIFICATION_TYPE_SET, error);
 }
 
 /**
@@ -8722,7 +8734,7 @@ struct field_modify_info modify_tcp[] = {
 			break;
 		case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
 			if (flow_dv_convert_action_set_reg
-					(mhdr_res, actions, error))
+					(dev, mhdr_res, actions, error))
 				return -rte_errno;
 			action_flags |= MLX5_FLOW_ACTION_SET_TAG;
 			break;
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH 8/8 app/testpmd: add testpmd command for sample action

In reply to Jiawei Wang

Add a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>

The examples for the sample flow use case and result as below:

1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...

This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.

2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...

The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.

---
 app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
index 4e2006c..6b1e515 100644
@@ -56,6 +56,8 @@ enum index {
 	SET_RAW_ENCAP,
 	SET_RAW_DECAP,
 	SET_RAW_INDEX,
+	SET_SAMPLE_ACTIONS,
+	SET_SAMPLE_INDEX,
 
 	/* Top-level command. */
 	FLOW,
@@ -349,6 +351,10 @@ enum index {
 	ACTION_SET_IPV6_DSCP_VALUE,
 	ACTION_AGE,
 	ACTION_AGE_TIMEOUT,
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_SAMPLE_INDEX_VALUE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -484,6 +490,22 @@ struct action_nvgre_encap_data {
 
 struct mplsoudp_decap_conf mplsoudp_decap_conf;
 
+#define ACTION_SAMPLE_ACTIONS_NUM 10
+#define RAW_SAMPLE_CONFS_MAX_NUM 8
+/** Storage for struct rte_flow_action_sample including external data. */
+struct action_sample_data {
+	struct rte_flow_action_sample conf;
+	uint32_t idx;
+};
+/** Storage for struct rte_flow_action_sample. */
+struct raw_sample_conf {
+	struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
+};
+struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -1161,6 +1183,7 @@ struct parse_action_priv {
 	ACTION_SET_IPV4_DSCP,
 	ACTION_SET_IPV6_DSCP,
 	ACTION_AGE,
+	ACTION_SAMPLE,
 	ZERO,
 };
 
@@ -1393,9 +1416,28 @@ struct parse_action_priv {
 	ZERO,
 };
 
+static const enum index action_sample[] = {
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index next_action_sample[] = {
+	ACTION_QUEUE,
+	ACTION_MARK,
+	ACTION_COUNT,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
+static int parse_set_sample_action(struct context *, const struct token *,
+				   const char *, unsigned int,
+				   void *, unsigned int);
 static int parse_set_init(struct context *, const struct token *,
 			  const char *, unsigned int,
 			  void *, unsigned int);
@@ -1460,7 +1502,15 @@ static int parse_vc_action_raw_decap_index(struct context *,
 static int parse_vc_action_set_meta(struct context *ctx,
 				    const struct token *token, const char *str,
 				    unsigned int len, void *buf,
+					unsigned int size);
+static int parse_vc_action_sample(struct context *ctx,
+				    const struct token *token, const char *str,
+				    unsigned int len, void *buf,
 				    unsigned int size);
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
@@ -1531,6 +1581,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_set_raw_index(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_set_sample_index(struct context *, const struct token *,
+			      unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -3612,11 +3664,13 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
-		.help = "set raw encap/decap data",
-		.type = "set raw_encap|raw_decap <index> <pattern>",
+		.help = "set raw encap/decap/sample data",
+		.type = "set raw_encap|raw_decap <index> <pattern>"
+				" or set sample_actions <index> <action>",
 		.next = NEXT(NEXT_ENTRY
 			     (SET_RAW_ENCAP,
-			      SET_RAW_DECAP)),
+			      SET_RAW_DECAP,
+			      SET_SAMPLE_ACTIONS)),
 		.call = parse_set_init,
 	},
 	/* Sub-level commands. */
@@ -3647,6 +3701,23 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(next_item),
 		.call = parse_port,
 	},
+	[SET_SAMPLE_INDEX] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "index of sample actions",
+		.next = NEXT(next_action_sample),
+		.call = parse_port,
+	},
+	[SET_SAMPLE_ACTIONS] = {
+		.name = "sample_actions",
+		.help = "set sample actions list",
+		.next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
+		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
+				(offsetof(struct buffer, port),
+				 sizeof(((struct buffer *)0)->port),
+				 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
+		.call = parse_set_sample_action,
+	},
 	[ACTION_SET_TAG] = {
 		.name = "set_tag",
 		.help = "set tag",
@@ -3750,6 +3821,37 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SAMPLE] = {
+		.name = "sample",
+		.help = "set a sample action",
+		.next = NEXT(action_sample),
+		.priv = PRIV_ACTION(SAMPLE,
+			sizeof(struct action_sample_data)),
+		.call = parse_vc_action_sample,
+	},
+	[ACTION_SAMPLE_RATIO] = {
+		.name = "ratio",
+		.help = "flow sample ratio value",
+		.next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_sample_data, conf) +
+			      offsetof(struct rte_flow_action_sample, ratio),
+			      sizeof(((struct rte_flow_action_sample *)0)->
+				     ratio))),
+	},
+	[ACTION_SAMPLE_INDEX] = {
+		.name = "index",
+		.help = "the index of sample actions list",
+		.next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
+	},
+	[ACTION_SAMPLE_INDEX_VALUE] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "unsigned integer value",
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc_action_sample_index,
+		.comp = comp_set_sample_index,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
@@ -5207,6 +5309,76 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return len;
 }
 
+static int
+parse_vc_action_sample(struct context *ctx, const struct token *token,
+			 const char *str, unsigned int len, void *buf,
+			 unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_sample_data *action_sample_data = NULL;
+	static struct rte_flow_action end_action = {
+		RTE_FLOW_ACTION_TYPE_END, 0
+	};
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Copy the headers to the buffer. */
+	action_sample_data = ctx->object;
+	action_sample_data->conf.actions = &end_action;
+	action->conf = &action_sample_data->conf;
+	return ret;
+}
+
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size)
+{
+	struct action_sample_data *action_sample_data;
+	struct rte_flow_action *action;
+	const struct arg *arg;
+	struct buffer *out = buf;
+	int ret;
+	uint16_t idx;
+
+	RTE_SET_USED(token);
+	RTE_SET_USED(buf);
+	RTE_SET_USED(size);
+	if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
+		return -1;
+	arg = ARGS_ENTRY_ARB_BOUNDED
+		(offsetof(struct action_sample_data, idx),
+		 sizeof(((struct action_sample_data *)0)->idx),
+		 0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
+	if (push_args(ctx, arg))
+		return -1;
+	ret = parse_int(ctx, token, str, len, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		return -1;
+	}
+	if (!ctx->object)
+		return len;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	action_sample_data = ctx->object;
+	idx = action_sample_data->idx;
+	action_sample_data->conf.actions = raw_sample_confs[idx].data;
+	action->conf = &action_sample_data->conf;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
@@ -5971,6 +6143,38 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	if (!out->command)
 		return -1;
 	out->command = ctx->curr;
+	/* For encap/decap we need is pattern */
+	out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
+	return len;
+}
+
+/** Parse set command, initialize output buffer for subsequent tokens. */
+static int
+parse_set_sample_action(struct context *ctx, const struct token *token,
+			  const char *str, unsigned int len,
+			  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	/* Make sure buffer is large enough. */
+	if (size < sizeof(*out))
+		return -1;
+	ctx->objdata = 0;
+	ctx->objmask = NULL;
+	ctx->object = out;
+	if (!out->command)
+		return -1;
+	out->command = ctx->curr;
+	/* For sampler we need is actions */
+	out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	return len;
 }
 
@@ -6007,11 +6211,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 			return -1;
 		out->command = ctx->curr;
 		out->args.vc.data = (uint8_t *)out + size;
-		/* All we need is pattern */
-		out->args.vc.pattern =
-			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
-					       sizeof(double));
-		ctx->object = out->args.vc.pattern;
+		ctx->object  = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	}
 	return len;
 }
@@ -6162,6 +6363,24 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return nb;
 }
 
+/** Complete index number for set raw_encap/raw_decap commands. */
+static int
+comp_set_sample_index(struct context *ctx, const struct token *token,
+		   unsigned int ent, char *buf, unsigned int size)
+{
+	uint16_t idx = 0;
+	uint16_t nb = 0;
+
+	RTE_SET_USED(ctx);
+	RTE_SET_USED(token);
+	for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
+		if (buf && idx == ent)
+			return snprintf(buf, size, "%u", idx);
+		++nb;
+	}
+	return nb;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -6607,7 +6826,53 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return mask;
 }
 
-
+/** Dispatch parsed buffer to function calls. */
+static void
+cmd_set_raw_parsed_sample(const struct buffer *in)
+{
+	uint32_t n = in->args.vc.actions_n;
+	uint32_t i = 0;
+	struct rte_flow_action *action = NULL;
+	struct rte_flow_action *data = NULL;
+	size_t size = 0;
+	uint16_t idx = in->port; /* We borrow port field as index */
+	uint32_t max_size = sizeof(struct rte_flow_action) *
+						ACTION_SAMPLE_ACTIONS_NUM;
+
+	RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
+	data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
+	memset(data, 0x00, max_size);
+	for (; i <= n - 1; i++) {
+		action = in->args.vc.actions + i;
+		if (action->type == RTE_FLOW_ACTION_TYPE_END)
+			break;
+		switch (action->type) {
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			size = sizeof(struct rte_flow_action_mark);
+			rte_memcpy(&sample_mark[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_mark[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			size = sizeof(struct rte_flow_action_count);
+			rte_memcpy(&sample_count[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_count[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			size = sizeof(struct rte_flow_action_queue);
+			rte_memcpy(&sample_queue[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_queue[idx];
+			break;
+		default:
+			printf("Error - Not supported action\n");
+			return;
+		}
+		rte_memcpy(data, action, sizeof(struct rte_flow_action));
+		data++;
+	}
+}
 
 /** Dispatch parsed buffer to function calls. */
 static void
@@ -6624,6 +6889,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	uint16_t proto = 0;
 	uint16_t idx = in->port; /* We borrow port field as index */
 
+	if (in->command == SET_SAMPLE_ACTIONS)
+		return cmd_set_raw_parsed_sample(in);
 	RTE_ASSERT(in->command == SET_RAW_ENCAP ||
 		   in->command == SET_RAW_DECAP);
 	if (in->command == SET_RAW_ENCAP) {
Signature · 1 line
1.8.3.1
Acked-by on v1 8/8
#35 lore raw

Re: [dpdk-dev] [PATCH 8/8] app/testpmd: add testpmd command for sample action

Quoted 459 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Thursday, June 25, 2020 7:26 PM
To: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Jiawei(Jonny) Wang <[email protected]>
Subject: [PATCH 8/8] app/testpmd: add testpmd command for sample action

Add a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>

The examples for the sample flow use case and result as below:

1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...

This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.

2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...

The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.

---
 app/test-pmd/cmdline_flow.c | 285
++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +21 -0
index 4e2006c..6b1e515 100644
@@ -56,6 +56,8 @@ enum index {
 	SET_RAW_ENCAP,
 	SET_RAW_DECAP,
 	SET_RAW_INDEX,
+	SET_SAMPLE_ACTIONS,
+	SET_SAMPLE_INDEX,
 
 	/* Top-level command. */
 	FLOW,
@@ -349,6 +351,10 @@ enum index {
 	ACTION_SET_IPV6_DSCP_VALUE,
 	ACTION_AGE,
 	ACTION_AGE_TIMEOUT,
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_SAMPLE_INDEX_VALUE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -484,6 +490,22 @@ struct action_nvgre_encap_data {
 
 struct mplsoudp_decap_conf mplsoudp_decap_conf;
 
+#define ACTION_SAMPLE_ACTIONS_NUM 10
+#define RAW_SAMPLE_CONFS_MAX_NUM 8
+/** Storage for struct rte_flow_action_sample including external data. */
+struct action_sample_data {
+	struct rte_flow_action_sample conf;
+	uint32_t idx;
+};
+/** Storage for struct rte_flow_action_sample. */
+struct raw_sample_conf {
+	struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
+};
+struct raw_sample_conf
 raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_mark
 sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_queue
 sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_count

sample_count[RAW_SAMPLE_CONFS_MAX_NUM];

app/test-pmd/cmdline_flow.c +29 -0
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
@@ -1161,6 +1183,7 @@ struct parse_action_priv {
 	ACTION_SET_IPV4_DSCP,
 	ACTION_SET_IPV6_DSCP,
 	ACTION_AGE,
+	ACTION_SAMPLE,
 	ZERO,
 };
 
@@ -1393,9 +1416,28 @@ struct parse_action_priv {
 	ZERO,
 };
 
+static const enum index action_sample[] = {
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index next_action_sample[] = {
+	ACTION_QUEUE,
+	ACTION_MARK,
+	ACTION_COUNT,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
+static int parse_set_sample_action(struct context *, const struct token *,
+				   const char *, unsigned int,
+				   void *, unsigned int);
 static int parse_set_init(struct context *, const struct token *,
 			  const char *, unsigned int,
 			  void *, unsigned int);
@@ -1460,7 +1502,15 @@ static int parse_vc_action_raw_decap_index(struct
 context *,
 static int parse_vc_action_set_meta(struct context *ctx,
 				    const struct token *token, const char *str,
 				    unsigned int len, void *buf,
+					unsigned int size);
+static int parse_vc_action_sample(struct context *ctx,
+				    const struct token *token, const char *str,
+				    unsigned int len, void *buf,
 				    unsigned int size);
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
app/test-pmd/cmdline_flow.c +2 -0
 			 void *, unsigned int);
@@ -1531,6 +1581,8 @@ static int comp_vc_action_rss_queue(struct context
 *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_set_raw_index(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_set_sample_index(struct context *, const struct token *,
+			      unsigned int, char *, unsigned int);
 
 /** Token definitions. */

static const struct token token_list[] = {

app/test-pmd/cmdline_flow.c +5 -3
@@ -3612,11 +3664,13 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
-		.help = "set raw encap/decap data",
-		.type = "set raw_encap|raw_decap <index> <pattern>",
+		.help = "set raw encap/decap/sample data",
+		.type = "set raw_encap|raw_decap <index> <pattern>"
+				" or set sample_actions <index> <action>",
 		.next = NEXT(NEXT_ENTRY
 			     (SET_RAW_ENCAP,
-			      SET_RAW_DECAP)),
+			      SET_RAW_DECAP,
+			      SET_SAMPLE_ACTIONS)),
 		.call = parse_set_init,
 	},
app/test-pmd/cmdline_flow.c +17 -0
 	/* Sub-level commands. */
@@ -3647,6 +3701,23 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 		.next = NEXT(next_item),
 		.call = parse_port,
 	},
+	[SET_SAMPLE_INDEX] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "index of sample actions",
+		.next = NEXT(next_action_sample),
+		.call = parse_port,
+	},
+	[SET_SAMPLE_ACTIONS] = {
+		.name = "sample_actions",
+		.help = "set sample actions list",
+		.next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
+		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
+				(offsetof(struct buffer, port),
+				 sizeof(((struct buffer *)0)->port),
+				 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
+		.call = parse_set_sample_action,
+	},
 	[ACTION_SET_TAG] = {
 		.name = "set_tag",
app/test-pmd/cmdline_flow.c +31 -0
 		.help = "set tag",
@@ -3750,6 +3821,37 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 		.next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SAMPLE] = {
+		.name = "sample",
+		.help = "set a sample action",
+		.next = NEXT(action_sample),
+		.priv = PRIV_ACTION(SAMPLE,
+			sizeof(struct action_sample_data)),
+		.call = parse_vc_action_sample,
+	},
+	[ACTION_SAMPLE_RATIO] = {
+		.name = "ratio",
+		.help = "flow sample ratio value",
+		.next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_sample_data, conf) +
+			      offsetof(struct rte_flow_action_sample, ratio),
+			      sizeof(((struct rte_flow_action_sample *)0)->
+				     ratio))),
+	},
+	[ACTION_SAMPLE_INDEX] = {
+		.name = "index",
+		.help = "the index of sample actions list",
+		.next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
+	},
+	[ACTION_SAMPLE_INDEX_VALUE] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "unsigned integer value",
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc_action_sample_index,
+		.comp = comp_set_sample_index,
+	},
 };
 

/** Remove and return last entry from argument stack. */

app/test-pmd/cmdline_flow.c +70 -0
@@ -5207,6 +5309,76 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 	return len;
 }
 
+static int
+parse_vc_action_sample(struct context *ctx, const struct token *token,
+			 const char *str, unsigned int len, void *buf,
+			 unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_sample_data *action_sample_data = NULL;
+	static struct rte_flow_action end_action = {
+		RTE_FLOW_ACTION_TYPE_END, 0
+	};
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Copy the headers to the buffer. */
+	action_sample_data = ctx->object;
+	action_sample_data->conf.actions = &end_action;
+	action->conf = &action_sample_data->conf;
+	return ret;
+}
+
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size)
+{
+	struct action_sample_data *action_sample_data;
+	struct rte_flow_action *action;
+	const struct arg *arg;
+	struct buffer *out = buf;
+	int ret;
+	uint16_t idx;
+
+	RTE_SET_USED(token);
+	RTE_SET_USED(buf);
+	RTE_SET_USED(size);
+	if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
+		return -1;
+	arg = ARGS_ENTRY_ARB_BOUNDED
+		(offsetof(struct action_sample_data, idx),
+		 sizeof(((struct action_sample_data *)0)->idx),
+		 0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
+	if (push_args(ctx, arg))
+		return -1;
+	ret = parse_int(ctx, token, str, len, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		return -1;
+	}
+	if (!ctx->object)
+		return len;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	action_sample_data = ctx->object;
+	idx = action_sample_data->idx;
+	action_sample_data->conf.actions = raw_sample_confs[idx].data;
+	action->conf = &action_sample_data->conf;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int

parse_destroy(struct context *ctx, const struct token *token,

app/test-pmd/cmdline_flow.c +34 -5
@@ -5971,6 +6143,38 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 	if (!out->command)
 		return -1;
 	out->command = ctx->curr;
+	/* For encap/decap we need is pattern */
+	out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
+	return len;
+}
+
+/** Parse set command, initialize output buffer for subsequent tokens. */
+static int
+parse_set_sample_action(struct context *ctx, const struct token *token,
+			  const char *str, unsigned int len,
+			  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	/* Make sure buffer is large enough. */
+	if (size < sizeof(*out))
+		return -1;
+	ctx->objdata = 0;
+	ctx->objmask = NULL;
+	ctx->object = out;
+	if (!out->command)
+		return -1;
+	out->command = ctx->curr;
+	/* For sampler we need is actions */
+	out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	return len;
 }
@@ -6007,11 +6211,8 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 			return -1;
 		out->command = ctx->curr;
 		out->args.vc.data = (uint8_t *)out + size;
-		/* All we need is pattern */
-		out->args.vc.pattern =
-			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
-					       sizeof(double));
-		ctx->object = out->args.vc.pattern;
+		ctx->object  = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	}
 	return len;

}

app/test-pmd/cmdline_flow.c +65 -1
@@ -6162,6 +6363,24 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 	return nb;
 }
 
+/** Complete index number for set raw_encap/raw_decap commands. */
+static int
+comp_set_sample_index(struct context *ctx, const struct token *token,
+		   unsigned int ent, char *buf, unsigned int size)
+{
+	uint16_t idx = 0;
+	uint16_t nb = 0;
+
+	RTE_SET_USED(ctx);
+	RTE_SET_USED(token);
+	for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
+		if (buf && idx == ent)
+			return snprintf(buf, size, "%u", idx);
+		++nb;
+	}
+	return nb;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
@@ -6607,7 +6826,53 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 	return mask;
 }
 
-
+/** Dispatch parsed buffer to function calls. */
+static void
+cmd_set_raw_parsed_sample(const struct buffer *in)
+{
+	uint32_t n = in->args.vc.actions_n;
+	uint32_t i = 0;
+	struct rte_flow_action *action = NULL;
+	struct rte_flow_action *data = NULL;
+	size_t size = 0;
+	uint16_t idx = in->port; /* We borrow port field as index */
+	uint32_t max_size = sizeof(struct rte_flow_action) *
+
 	ACTION_SAMPLE_ACTIONS_NUM;
+
+	RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
+	data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
+	memset(data, 0x00, max_size);
+	for (; i <= n - 1; i++) {
+		action = in->args.vc.actions + i;
+		if (action->type == RTE_FLOW_ACTION_TYPE_END)
+			break;
+		switch (action->type) {
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			size = sizeof(struct rte_flow_action_mark);
+			rte_memcpy(&sample_mark[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_mark[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			size = sizeof(struct rte_flow_action_count);
+			rte_memcpy(&sample_count[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_count[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			size = sizeof(struct rte_flow_action_queue);
+			rte_memcpy(&sample_queue[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_queue[idx];
+			break;
+		default:
+			printf("Error - Not supported action\n");
+			return;
+		}
+		rte_memcpy(data, action, sizeof(struct rte_flow_action));
+		data++;
+	}
+}
 

/** Dispatch parsed buffer to function calls. */
static void

app/test-pmd/cmdline_flow.c +2 -0
@@ -6624,6 +6889,8 @@ static int comp_set_raw_index(struct context *,
 const struct token *,
 	uint16_t proto = 0;
 	uint16_t idx = in->port; /* We borrow port field as index */
 
+	if (in->command == SET_SAMPLE_ACTIONS)
+		return cmd_set_raw_parsed_sample(in);
 	RTE_ASSERT(in->command == SET_RAW_ENCAP ||
 		   in->command == SET_RAW_DECAP);
Quoted 3 lines

if (in->command == SET_RAW_ENCAP) {
--
1.8.3.1

Thanks,
Ori

#36 lore raw

cover support the flow-based traffic sampling

In reply to Jiawei Wang

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with additional set of actions from the original packet.

MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.

v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.

Jiawei Wang (7):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action

 app/test-pmd/cmdline_flow.c            | 285 ++++++++++++++-
 doc/guides/prog_guide/rte_flow.rst     |  25 ++
 doc/guides/rel_notes/release_20_08.rst |   6 +
 drivers/common/mlx5/Makefile           |   5 +
 drivers/common/mlx5/linux/meson.build  |   2 +
 drivers/common/mlx5/linux/mlx5_glue.c  |  15 +
 drivers/common/mlx5/linux/mlx5_glue.h  |  12 +
 drivers/common/mlx5/mlx5_devx_cmds.c   |  27 ++
 drivers/common/mlx5/mlx5_devx_cmds.h   |   1 +
 drivers/common/mlx5/mlx5_prm.h         |  51 +++
 drivers/net/mlx5/linux/mlx5_os.c       |  14 +
 drivers/net/mlx5/mlx5.c                |  11 +
 drivers/net/mlx5/mlx5.h                |   4 +
 drivers/net/mlx5/mlx5_flow.c           | 274 +++++++++++++-
 drivers/net/mlx5/mlx5_flow.h           |  51 ++-
 drivers/net/mlx5/mlx5_flow_dv.c        | 627 ++++++++++++++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c           |   1 +
 lib/librte_ethdev/rte_flow.h           |  28 ++
 18 files changed, 1404 insertions(+), 35 deletions(-)
Signature · 1 line
1.8.3.1
#37 lore raw

PATCH 1/7 ethdev: introduce sample action for rte flow

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28 ++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
index d5dd18c..50dfe1f 100644
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_08.rst +6 -0
index 5cbc4ce..313e8d3 100644
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching
+  packets with given ratio and redirects to vport or queue. The sampled packets
+  also can be assigned with an additional optional actions.
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
lib/librte_ethdev/rte_flow.c +1 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +28 -0
index b0e4199..c9cd80d 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * Redirects specific ratio of packets to vport or queue.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
#38 lore raw

PATCH 2/7 common/mlx5: glue for sample action

In reply to Jiawei Wang

rdma-core introduce a new DR sample action.

Add the rdma-core commands in glue to create this action.

Sample action is used for creating the sample object to implement the sampling/mirroring function.

---
 drivers/common/mlx5/Makefile          |  5 +++++
 drivers/common/mlx5/linux/meson.build |  2 ++
 drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 12 ++++++++++++
 4 files changed, 34 insertions(+)
drivers/common/mlx5/Makefile +5 -0
index f6c762b..4c1484c 100644
@@ -192,6 +192,11 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh
 		func mlx5dv_dump_dr_domain \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_flow_sampler \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_MLX5DV_MMAP_GET_NC_PAGES_CMD \
 		infiniband/mlx5dv.h \
 		enum MLX5_MMAP_GET_NC_PAGES_CMD \
drivers/common/mlx5/linux/meson.build +2 -0
index 2294213..0f08318 100644
@@ -162,6 +162,8 @@ has_sym_args = [
 	'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
 	[ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
 	'mlx5dv_dump_dr_domain'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_flow_sampler'],
 	[ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h',
 	'mlx5dv_dr_domain_set_reclaim_device_memory'],
 	[ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
index 048207e..98b3e71 100644
@@ -1059,6 +1059,19 @@
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_sampler(
+			struct mlx5dv_dr_flow_sampler_attr *attr)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+	return mlx5dv_dr_action_create_flow_sampler(attr);
+#else
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static int
 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
 			 uint32_t *eqn)
@@ -1308,6 +1321,8 @@
 	.devx_port_query = mlx5_glue_devx_port_query,
 	.dr_dump_domain = mlx5_glue_dr_dump_domain,
 	.dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
+	.dr_create_flow_action_sampler =
+		mlx5_glue_dr_create_flow_action_sampler,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
 	.devx_create_event_channel = mlx5_glue_devx_create_event_channel,
 	.devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +12 -0
index 069d854..11b95c5 100644
@@ -77,6 +77,7 @@
 #ifndef HAVE_MLX5DV_DR
 enum  mlx5dv_dr_domain_type { unused, };
 struct mlx5dv_dr_domain;
+struct mlx5dv_dr_action;
 #endif
 
 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,15 @@
 struct mlx5dv_dr_flow_meter_attr;
 #endif
 
+#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+struct mlx5dv_dr_flow_sampler_attr {
+	uint32_t sample_ratio;
+	void *default_next_table;
+	size_t num_sample_actions;
+	struct mlx5dv_dr_action **sample_actions;
+};
+#endif
+
 #ifndef HAVE_IBV_DEVX_EVENT
 struct mlx5dv_devx_event_channel { int fd; };
 struct mlx5dv_devx_async_event_hdr;
@@ -304,6 +314,8 @@ struct mlx5_glue {
 			 struct mlx5dv_devx_async_event_hdr *event_data,
 			 size_t event_resp_len);
 	void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
+	void *(*dr_create_flow_action_sampler)
+			(struct mlx5dv_dr_flow_sampler_attr *attr);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
#39 lore raw

PATCH 3/7 common/mlx5: query sampler object capability via DevX

In reply to Jiawei Wang

Update function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.

Add the related structs definition in mlx5_prm.h.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++
 drivers/common/mlx5/mlx5_devx_cmds.h |  1 +
 drivers/common/mlx5/mlx5_prm.h       | 51 ++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
index ec92eb6..6b551f1 100644
@@ -496,6 +496,33 @@ struct mlx5_devx_obj *
 	if (!attr->eth_net_offloads)
 		return 0;
 
+	/* Query Flow Sampler Capabilitiy From FLow Table Properties Layout. */
+	memset(in, 0, sizeof(in));
+	memset(out, 0, sizeof(out));
+	MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
+	MLX5_SET(query_hca_cap_in, in, op_mod,
+		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
+		 MLX5_HCA_CAP_OPMOD_GET_CUR);
+
+	rc = mlx5_glue->devx_general_cmd(ctx,
+					 in, sizeof(in),
+					 out, sizeof(out));
+	if (rc)
+		goto error;
+	status = MLX5_GET(query_hca_cap_out, out, status);
+	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
+	if (status) {
+		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
+			"status %x, syndrome = %x",
+			status, syndrome);
+		attr->log_max_ft_sampler_num = 0;
+		return -1;
+	}
+	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
+	attr->log_max_ft_sampler_num =
+			MLX5_GET(flow_table_nic_cap,
+			hcattr, flow_table_properties.log_max_ft_sampler_num);
+
 	/* Query HCA offloads for Ethernet protocol. */
 	memset(in, 0, sizeof(in));
 	memset(out, 0, sizeof(out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
index 25704ef..a9cfe6d 100644
@@ -90,6 +90,7 @@ struct mlx5_hca_attr {
 	uint32_t vhca_id:16;
 	uint32_t relaxed_ordering_write:1;
 	uint32_t relaxed_ordering_read:1;
+	uint32_t log_max_ft_sampler_num:8;
 	struct mlx5_hca_qos_attr qos;
 	struct mlx5_hca_vdpa_attr vdpa;
 };
drivers/common/mlx5/mlx5_prm.h +51 -0

69 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#40 lore raw

PATCH 4/7 net/mlx5: add the validate sample action

In reply to Jiawei Wang

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX.

Only NIC_RX support with addition optional actions. FDB doesn't support any optional action, the sampled packets is always goes to e-switch manager port.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 133 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
index 2dc57b2..6dfacf2 100644
@@ -878,6 +878,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config.hca_attr.log_max_ft_sampler_num > 0  &&
+		    config.dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config.hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register for"
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not supported!\n");
+		}
+#endif
 	}
 	if (config.mprq.enabled && mprq) {
 		if (config.mprq.stride_num_n &&
drivers/net/mlx5/mlx5.h +1 -0
index 46e66eb..6790738 100644
@@ -617,6 +617,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management. */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
index 43cbda8..45a073c 100644
@@ -202,6 +202,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35)
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +133 -0

145 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#41 lore raw

PATCH 5/7 net/mlx5: split sample flow into two sub flows

In reply to Jiawei Wang

Add the sampler action resource structs definition.

The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.

For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.

---
 drivers/net/mlx5/mlx5.c      |  11 ++
 drivers/net/mlx5/mlx5.h      |   3 +
 drivers/net/mlx5/mlx5_flow.c | 258 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h |  36 ++++++
 4 files changed, 304 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
index 07c6add..db55545 100644
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		.free = rte_free,
 		.type = "mlx5_jump_ipool",
 	},
+	{
+		.size = sizeof(struct mlx5_flow_dv_sample_resource),
+		.trunk_size = 64,
+		.grow_trunk = 3,
+		.grow_shift = 2,
+		.need_lock = 0,
+		.release_mem_en = 1,
+		.malloc = rte_malloc_socket,
+		.free = rte_free,
+		.type = "mlx5_sample_ipool",
+	},
 #endif
 	{
 		.size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
index 6790738..756bd68 100644
@@ -51,6 +51,7 @@ enum mlx5_ipool_index {
 	MLX5_IPOOL_TAG, /* Pool for tag resource. */
 	MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
 	MLX5_IPOOL_JUMP, /* Pool for jump resource. */
+	MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */
 #endif
 	MLX5_IPOOL_MTR, /* Pool for meter resource. */
 	MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -518,6 +519,7 @@ struct mlx5_flow_tbl_resource {
 /* Tables for metering splits should be added here. */
 #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)
 #define MLX5_MAX_TABLES_FDB UINT16_MAX
+#define MLX5_FLOW_TABLE_FACTOR 10
 
 /* ID generation structure. */
 struct mlx5_flow_id_pool {
@@ -566,6 +568,7 @@ struct mlx5_dev_ctx_shared {
 	struct mlx5_hlist *tag_table;
 	uint32_t port_id_action_list; /* List of port ID actions. */
 	uint32_t push_vlan_action_list; /* List of push VLAN actions. */
+	uint32_t sample_action_list; /* List of sample actions. */
 	struct mlx5_flow_counter_mng cmng; /* Counters management structure. */
 	struct mlx5_flow_default_miss_resource default_miss;
 	/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +254 -4

294 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +36 -0
index 45a073c..51826f8 100644
@@ -502,6 +502,38 @@ struct mlx5_flow_tbl_data_entry {
 	uint32_t idx; /**< index for the indexed mempool. */
 };
 
+/* Sub rdma-core actions list. */
+struct mlx5_flow_sub_actions_list {
+	uint32_t actions_num; /**< Number of sample actions. */
+	uint64_t action_flags;
+	void *dr_queue_action;
+	void *dr_tag_action;
+	void *dr_cnt_action;
+};
+
+/* Sample sub-actions resource list. */
+struct mlx5_flow_sub_actions_idx {
+	uint32_t rix_hrxq; /**< Hash Rx queue object index. */
+	uint32_t rix_tag; /**< Index to the tag action. */
+	uint32_t cnt;
+};
+
+/* Sample action resource structure. */
+struct mlx5_flow_dv_sample_resource {
+	ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
+	rte_atomic32_t refcnt; /**< Reference counter. */
+	void *verbs_action; /**< Verbs sample action object. */
+	uint8_t ft_type; /** Flow Table Type */
+	uint32_t ft_id; /** Flow Table Level */
+	void *normal_path_tbl; /** Flow Table pointer */
+	void *default_miss; /** default_miss dr_action. */
+	uint32_t ratio;   /** Sample Ratio */
+	struct mlx5_flow_sub_actions_idx sample_idx;
+	/**< Action index resources. */
+	struct mlx5_flow_sub_actions_list sample_act;
+	/**< Action resources. */
+};
+
 /* Verbs specification header. */
 struct ibv_spec_header {
 	enum ibv_flow_spec_type type;
@@ -530,6 +562,8 @@ struct mlx5_flow_handle_dv {
 	/**< Index to push VLAN action resource in cache. */
 	uint32_t rix_tag;
 	/**< Index to the tag action. */
+	uint32_t rix_sample;
+	/**< Index to sample action resource in cache. */
 } __rte_packed;
 
 /** Device flow handle structure: used both for creating & destroying. */
@@ -595,6 +629,8 @@ struct mlx5_flow_dv_workspace {
 	/**< Pointer to the jump action resource. */
 	struct mlx5_flow_dv_match_params value;
 	/**< Holds the value that the packet is compared to. */
+	struct mlx5_flow_dv_sample_resource *sample_res;
+	/**< Pointer to the sample action resource. */
 };
 
 /*
Signature · 1 line
1.8.3.1
#42 lore raw

PATCH 6/7 net/mlx5: update translate function for sample action

In reply to Jiawei Wang

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---
 drivers/net/mlx5/mlx5_flow.c    |  16 +-
 drivers/net/mlx5/mlx5_flow.h    |  14 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 494 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 502 insertions(+), 22 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
index 7ed9ba3..c91ae7d 100644
@@ -4612,10 +4612,14 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	int hairpin_flow;
 	uint32_t hairpin_id = 0;
 	struct rte_flow_attr attr_tx = { .priority = 0 };
+	struct rte_flow_attr attr_factor = {0};
 	int ret;
 
-	hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
-	ret = flow_drv_validate(dev, attr, items, p_actions_rx,
+	memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
+	if (external)
+		attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
+	hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
+	ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
 				external, hairpin_flow, error);
 	if (ret < 0)
 		return 0;
@@ -4634,7 +4638,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		rte_errno = ENOMEM;
 		goto error_before_flow;
 	}
-	flow->drv_type = flow_get_drv_type(dev, attr);
+	flow->drv_type = flow_get_drv_type(dev, &attr_factor);
 	if (hairpin_id != 0)
 		flow->hairpin_flow_id = hairpin_id;
 	MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4680,7 +4684,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		 * depending on configuration. In the simplest
 		 * case it just creates unmodified original flow.
 		 */
-		ret = flow_create_split_outer(dev, flow, attr,
+		ret = flow_create_split_outer(dev, flow, &attr_factor,
 					      buf->entry[i].pattern,
 					      p_actions_rx, external, idx,
 					      error);
@@ -4717,8 +4721,8 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	 * the egress Flows belong to the different device and
 	 * copy table should be updated in peer NIC Rx domain.
 	 */
-	if (attr->ingress &&
-	    (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
+	if (attr_factor.ingress &&
+	    (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
 		ret = flow_mreg_update_copy_table(dev, flow, actions, error);
 		if (ret)
 			goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
index 51826f8..99e900b 100644
@@ -372,6 +372,13 @@ enum mlx5_flow_fate_type {
 	MLX5_FLOW_FATE_MAX,
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /* Matcher PRM representation */
 struct mlx5_flow_dv_match_params {
 	size_t size;
@@ -604,13 +611,6 @@ struct mlx5_flow_handle {
 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
 #endif
 
-/*
- * Max number of actions per DV flow.
- * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
- * in rdma-core file providers/mlx5/verbs.c.
- */
-#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
-
 /** Device flow structure only for DV flow creation. */
 struct mlx5_flow_dv_workspace {
 	uint32_t group; /**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +485 -9

579 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#43 lore raw

PATCH 7/7 app/testpmd: add testpmd command for sample action

In reply to Jiawei Wang

Add a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>

The examples for the sample flow use case and result as below:

1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...

This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.

2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...

The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.

---
 app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
index 4e2006c..6b1e515 100644
@@ -56,6 +56,8 @@ enum index {
 	SET_RAW_ENCAP,
 	SET_RAW_DECAP,
 	SET_RAW_INDEX,
+	SET_SAMPLE_ACTIONS,
+	SET_SAMPLE_INDEX,
 
 	/* Top-level command. */
 	FLOW,
@@ -349,6 +351,10 @@ enum index {
 	ACTION_SET_IPV6_DSCP_VALUE,
 	ACTION_AGE,
 	ACTION_AGE_TIMEOUT,
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_SAMPLE_INDEX_VALUE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -484,6 +490,22 @@ struct action_nvgre_encap_data {
 
 struct mplsoudp_decap_conf mplsoudp_decap_conf;
 
+#define ACTION_SAMPLE_ACTIONS_NUM 10
+#define RAW_SAMPLE_CONFS_MAX_NUM 8
+/** Storage for struct rte_flow_action_sample including external data. */
+struct action_sample_data {
+	struct rte_flow_action_sample conf;
+	uint32_t idx;
+};
+/** Storage for struct rte_flow_action_sample. */
+struct raw_sample_conf {
+	struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
+};
+struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -1161,6 +1183,7 @@ struct parse_action_priv {
 	ACTION_SET_IPV4_DSCP,
 	ACTION_SET_IPV6_DSCP,
 	ACTION_AGE,
+	ACTION_SAMPLE,
 	ZERO,
 };
 
@@ -1393,9 +1416,28 @@ struct parse_action_priv {
 	ZERO,
 };
 
+static const enum index action_sample[] = {
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index next_action_sample[] = {
+	ACTION_QUEUE,
+	ACTION_MARK,
+	ACTION_COUNT,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
+static int parse_set_sample_action(struct context *, const struct token *,
+				   const char *, unsigned int,
+				   void *, unsigned int);
 static int parse_set_init(struct context *, const struct token *,
 			  const char *, unsigned int,
 			  void *, unsigned int);
@@ -1460,7 +1502,15 @@ static int parse_vc_action_raw_decap_index(struct context *,
 static int parse_vc_action_set_meta(struct context *ctx,
 				    const struct token *token, const char *str,
 				    unsigned int len, void *buf,
+					unsigned int size);
+static int parse_vc_action_sample(struct context *ctx,
+				    const struct token *token, const char *str,
+				    unsigned int len, void *buf,
 				    unsigned int size);
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
@@ -1531,6 +1581,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_set_raw_index(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_set_sample_index(struct context *, const struct token *,
+			      unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -3612,11 +3664,13 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
-		.help = "set raw encap/decap data",
-		.type = "set raw_encap|raw_decap <index> <pattern>",
+		.help = "set raw encap/decap/sample data",
+		.type = "set raw_encap|raw_decap <index> <pattern>"
+				" or set sample_actions <index> <action>",
 		.next = NEXT(NEXT_ENTRY
 			     (SET_RAW_ENCAP,
-			      SET_RAW_DECAP)),
+			      SET_RAW_DECAP,
+			      SET_SAMPLE_ACTIONS)),
 		.call = parse_set_init,
 	},
 	/* Sub-level commands. */
@@ -3647,6 +3701,23 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(next_item),
 		.call = parse_port,
 	},
+	[SET_SAMPLE_INDEX] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "index of sample actions",
+		.next = NEXT(next_action_sample),
+		.call = parse_port,
+	},
+	[SET_SAMPLE_ACTIONS] = {
+		.name = "sample_actions",
+		.help = "set sample actions list",
+		.next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
+		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
+				(offsetof(struct buffer, port),
+				 sizeof(((struct buffer *)0)->port),
+				 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
+		.call = parse_set_sample_action,
+	},
 	[ACTION_SET_TAG] = {
 		.name = "set_tag",
 		.help = "set tag",
@@ -3750,6 +3821,37 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SAMPLE] = {
+		.name = "sample",
+		.help = "set a sample action",
+		.next = NEXT(action_sample),
+		.priv = PRIV_ACTION(SAMPLE,
+			sizeof(struct action_sample_data)),
+		.call = parse_vc_action_sample,
+	},
+	[ACTION_SAMPLE_RATIO] = {
+		.name = "ratio",
+		.help = "flow sample ratio value",
+		.next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_sample_data, conf) +
+			      offsetof(struct rte_flow_action_sample, ratio),
+			      sizeof(((struct rte_flow_action_sample *)0)->
+				     ratio))),
+	},
+	[ACTION_SAMPLE_INDEX] = {
+		.name = "index",
+		.help = "the index of sample actions list",
+		.next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
+	},
+	[ACTION_SAMPLE_INDEX_VALUE] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "unsigned integer value",
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc_action_sample_index,
+		.comp = comp_set_sample_index,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
@@ -5207,6 +5309,76 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return len;
 }
 
+static int
+parse_vc_action_sample(struct context *ctx, const struct token *token,
+			 const char *str, unsigned int len, void *buf,
+			 unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_sample_data *action_sample_data = NULL;
+	static struct rte_flow_action end_action = {
+		RTE_FLOW_ACTION_TYPE_END, 0
+	};
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Copy the headers to the buffer. */
+	action_sample_data = ctx->object;
+	action_sample_data->conf.actions = &end_action;
+	action->conf = &action_sample_data->conf;
+	return ret;
+}
+
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size)
+{
+	struct action_sample_data *action_sample_data;
+	struct rte_flow_action *action;
+	const struct arg *arg;
+	struct buffer *out = buf;
+	int ret;
+	uint16_t idx;
+
+	RTE_SET_USED(token);
+	RTE_SET_USED(buf);
+	RTE_SET_USED(size);
+	if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
+		return -1;
+	arg = ARGS_ENTRY_ARB_BOUNDED
+		(offsetof(struct action_sample_data, idx),
+		 sizeof(((struct action_sample_data *)0)->idx),
+		 0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
+	if (push_args(ctx, arg))
+		return -1;
+	ret = parse_int(ctx, token, str, len, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		return -1;
+	}
+	if (!ctx->object)
+		return len;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	action_sample_data = ctx->object;
+	idx = action_sample_data->idx;
+	action_sample_data->conf.actions = raw_sample_confs[idx].data;
+	action->conf = &action_sample_data->conf;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
@@ -5971,6 +6143,38 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	if (!out->command)
 		return -1;
 	out->command = ctx->curr;
+	/* For encap/decap we need is pattern */
+	out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
+	return len;
+}
+
+/** Parse set command, initialize output buffer for subsequent tokens. */
+static int
+parse_set_sample_action(struct context *ctx, const struct token *token,
+			  const char *str, unsigned int len,
+			  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	/* Make sure buffer is large enough. */
+	if (size < sizeof(*out))
+		return -1;
+	ctx->objdata = 0;
+	ctx->objmask = NULL;
+	ctx->object = out;
+	if (!out->command)
+		return -1;
+	out->command = ctx->curr;
+	/* For sampler we need is actions */
+	out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	return len;
 }
 
@@ -6007,11 +6211,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 			return -1;
 		out->command = ctx->curr;
 		out->args.vc.data = (uint8_t *)out + size;
-		/* All we need is pattern */
-		out->args.vc.pattern =
-			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
-					       sizeof(double));
-		ctx->object = out->args.vc.pattern;
+		ctx->object  = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	}
 	return len;
 }
@@ -6162,6 +6363,24 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return nb;
 }
 
+/** Complete index number for set raw_encap/raw_decap commands. */
+static int
+comp_set_sample_index(struct context *ctx, const struct token *token,
+		   unsigned int ent, char *buf, unsigned int size)
+{
+	uint16_t idx = 0;
+	uint16_t nb = 0;
+
+	RTE_SET_USED(ctx);
+	RTE_SET_USED(token);
+	for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
+		if (buf && idx == ent)
+			return snprintf(buf, size, "%u", idx);
+		++nb;
+	}
+	return nb;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -6607,7 +6826,53 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return mask;
 }
 
-
+/** Dispatch parsed buffer to function calls. */
+static void
+cmd_set_raw_parsed_sample(const struct buffer *in)
+{
+	uint32_t n = in->args.vc.actions_n;
+	uint32_t i = 0;
+	struct rte_flow_action *action = NULL;
+	struct rte_flow_action *data = NULL;
+	size_t size = 0;
+	uint16_t idx = in->port; /* We borrow port field as index */
+	uint32_t max_size = sizeof(struct rte_flow_action) *
+						ACTION_SAMPLE_ACTIONS_NUM;
+
+	RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
+	data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
+	memset(data, 0x00, max_size);
+	for (; i <= n - 1; i++) {
+		action = in->args.vc.actions + i;
+		if (action->type == RTE_FLOW_ACTION_TYPE_END)
+			break;
+		switch (action->type) {
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			size = sizeof(struct rte_flow_action_mark);
+			rte_memcpy(&sample_mark[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_mark[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			size = sizeof(struct rte_flow_action_count);
+			rte_memcpy(&sample_count[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_count[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			size = sizeof(struct rte_flow_action_queue);
+			rte_memcpy(&sample_queue[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_queue[idx];
+			break;
+		default:
+			printf("Error - Not supported action\n");
+			return;
+		}
+		rte_memcpy(data, action, sizeof(struct rte_flow_action));
+		data++;
+	}
+}
 
 /** Dispatch parsed buffer to function calls. */
 static void
@@ -6624,6 +6889,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	uint16_t proto = 0;
 	uint16_t idx = in->port; /* We borrow port field as index */
 
+	if (in->command == SET_SAMPLE_ACTIONS)
+		return cmd_set_raw_parsed_sample(in);
 	RTE_ASSERT(in->command == SET_RAW_ENCAP ||
 		   in->command == SET_RAW_DECAP);
 	if (in->command == SET_RAW_ENCAP) {
Signature · 1 line
1.8.3.1
#44 lore raw

v2 cover support the flow-based traffic sampling

In reply to Jiawei Wang

Sorry for that I forget to change the subject prefix to PATCH v2 of title last time.

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with additional set of actions from the original packet.

MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.

v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.

Jiawei Wang (7):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action

 app/test-pmd/cmdline_flow.c            | 285 ++++++++++++++-
 doc/guides/prog_guide/rte_flow.rst     |  25 ++
 doc/guides/rel_notes/release_20_08.rst |   6 +
 drivers/common/mlx5/Makefile           |   5 +
 drivers/common/mlx5/linux/meson.build  |   2 +
 drivers/common/mlx5/linux/mlx5_glue.c  |  15 +
 drivers/common/mlx5/linux/mlx5_glue.h  |  12 +
 drivers/common/mlx5/mlx5_devx_cmds.c   |  27 ++
 drivers/common/mlx5/mlx5_devx_cmds.h   |   1 +
 drivers/common/mlx5/mlx5_prm.h         |  51 +++
 drivers/net/mlx5/linux/mlx5_os.c       |  14 +
 drivers/net/mlx5/mlx5.c                |  11 +
 drivers/net/mlx5/mlx5.h                |   4 +
 drivers/net/mlx5/mlx5_flow.c           | 274 +++++++++++++-
 drivers/net/mlx5/mlx5_flow.h           |  51 ++-
 drivers/net/mlx5/mlx5_flow_dv.c        | 627 ++++++++++++++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c           |   1 +
 lib/librte_ethdev/rte_flow.h           |  28 ++
 18 files changed, 1404 insertions(+), 35 deletions(-)
Signature · 1 line
1.8.3.1
#45 lore raw

PATCH v2 1/7 ethdev: introduce sample action for rte flow

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28 ++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
index d5dd18c..50dfe1f 100644
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_08.rst +6 -0
index 5cbc4ce..313e8d3 100644
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching
+  packets with given ratio and redirects to vport or queue. The sampled packets
+  also can be assigned with an additional optional actions.
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
lib/librte_ethdev/rte_flow.c +1 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +28 -0
index b0e4199..c9cd80d 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * Redirects specific ratio of packets to vport or queue.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
Acked-by on v2 1/7
#46 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 16 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

Quoted 6 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

With the above deprecation notice,

Quoted 121 lines
---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28 ++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
index d5dd18c..50dfe1f 100644
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_08.rst +6 -0
index 5cbc4ce..313e8d3 100644
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching
+  packets with given ratio and redirects to vport or queue. The sampled packets
+  also can be assigned with an additional optional actions.
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
lib/librte_ethdev/rte_flow.c +1 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
        MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
        MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
        MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+       MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +28 -1
index b0e4199..c9cd80d 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
         * see enum RTE_ETH_EVENT_FLOW_AGED
         */
        RTE_FLOW_ACTION_TYPE_AGE,
+
+       /**
+        * Redirects specific ratio of packets to vport or queue.
+        *
+        * See struct rte_flow_action_sample.
+        */
+       RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+       const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+       const struct rte_flow_action *actions;
+               /**< sub-action list specific for the sampling hit cases. */
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
--

1.8.3.1

#47 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Hi Jerin

From: Jerin Jacob:

Quoted 22 lines · Jiawei Wang
Quoted 7 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 5 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

Quoted 8 lines
Quoted 2 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in ethdev:
promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

Quoted 137 lines

With the above deprecation notice,

Quoted 2 lines
---
 doc/guides/prog_guide/rte_flow.rst     | 25

+++++++++++++++++++++++++

Quoted 3 lines
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28

++++++++++++++++++++++++++++

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the

Quoted 8 lines
 4 files changed, 60 insertions(+)
doc/guides/prog_guide/rte_flow.rst +0 -0
index d5dd18c..50dfe1f 100644
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the

flow.

Quoted 37 lines
doc/guides/prog_guide/rte_flow.rst +25 -0
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or
+mirrored packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_08.rst +0 -0
index 5cbc4ce..313e8d3 100644

doc/guides/rel_notes/release_20_08.rst New Features · line 86

Quoted 6 lines
doc/guides/rel_notes/release_20_08.rst +3 -0
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate

the

doc/guides/rel_notes/release_20_08.rst New Features · line 88

Quoted 2 lines
doc/guides/rel_notes/release_20_08.rst +2 -0
+ matching  packets with given ratio and redirects to vport or queue.
+ The sampled packets  also can be assigned with an additional optional

actions.

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 173

Quoted 10 lines
doc/guides/rel_notes/release_20_08.rst +1 -0
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.c index 1685be5..733871d 100644

lib/librte_ethdev/rte_flow.c +0 -0
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
        MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 174

Quoted 1 line
lib/librte_ethdev/rte_flow.c +0 -0
        MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

Quoted 30 lines
lib/librte_ethdev/rte_flow.c +1 -0
        MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+       MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.h index b0e4199..c9cd80d 100644

lib/librte_ethdev/rte_flow.h +11 -0
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
         * see enum RTE_ETH_EVENT_FLOW_AGED
         */
        RTE_FLOW_ACTION_TYPE_AGE,
+
+       /**
+        * Redirects specific ratio of packets to vport or queue.
+        *
+        * See struct rte_flow_action_sample.
+        */
+       RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {  struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2731

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+vport
+ * in the predefined probabiilty, All the packets continues
+processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2732

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

Quoted 14 lines
lib/librte_ethdev/rte_flow.h +8 -1
+ */
+struct rte_flow_action_sample {
+       const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+       const struct rte_flow_action *actions;
+               /**< sub-action list specific for the sampling hit
+cases. */ };
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
--

1.8.3.1

#48 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 3 lines · Matan Azrad

Hi Jerin

Hi Matan,

Quoted 51 lines

From: Jerin Jacob:

Quoted 22 lines · Jiawei Wang
Quoted 7 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 8 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 5 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

Quoted 8 lines
Quoted 2 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in ethdev:
promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

But The VLAN and UDP related should be rte_flow candidates.(IMO)

Quoted 3 lines
Quoted 3 lines

With the above deprecation notice,

#49 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

From: Jerin Jacob

Quoted 74 lines · Matan Azrad
Quoted 3 lines

Hi Jerin

Hi Matan,

Quoted 3 lines

From: Jerin Jacob:

Quoted 1 line

On Fri, Jul 3, 2020 at 12:13 AM Jiawei Wang <[email protected]>

Quoted 50 lines · wrote:
Quoted 23 lines
Quoted 12 lines

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 5 lines

The packets sampled equals is '1/ratio', if the ratio value be set to
1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original

packet.

Quoted 5 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

Quoted 8 lines
Quoted 2 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in ethdev:
promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

Quoted 1 line

But The VLAN and UDP related should be rte_flow candidates.(IMO)

Can you explain why?
Each one of them can be configured by rte_flow, so why do we need duplicate ways to configure the same thing.

What is the expected behavior if there are conflicts? Is it documented?

It is probably different discussion, but I think that rte_flow becomes more popular and it will be makes sense to concentrate all the traffic filtering/actions to the rte_flow.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

With the above deprecation notice,

#50 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

In reply to Jerin Jacob

03/07/2020 17:08, Jerin Jacob:

Quoted 29 lines · Matan Azrad
Quoted 25 lines

From: Jerin Jacob:

Quoted 5 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in ethdev:
promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

Quoted 9 lines

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

"Basic" is not a precise definition :)
I would say port-level configuration should remain out of rte_flow API.

Quoted 1 line

But The VLAN and UDP related should be rte_flow candidates.(IMO)

Yes definitely, tunneling is better managed with rte_flow.

This is an important discussion, I Cc other ethdev maintainers.
Note: this is an ethdev patch, all ethdev maintainers should be Cc'ed. Aren't you using --cc-cmd devtools/get-maintainer.sh ?

#51 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 41 lines · Thomas Monjalon

03/07/2020 17:08, Jerin Jacob:

Quoted 29 lines · Matan Azrad
Quoted 25 lines

From: Jerin Jacob:

Quoted 5 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in ethdev:
promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

Quoted 9 lines

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

Quoted 1 line

"Basic" is not a precise definition :)

Yep.

Quoted 2 lines

I would say port-level configuration should remain out of rte_flow API.

+1.
In addition that, I would say anything needs to configured at "per-flow" granularity use rte_flow.

Quoted 10 lines
Quoted 2 lines

But The VLAN and UDP related should be rte_flow candidates.(IMO)

Yes definitely, tunneling is better managed with rte_flow.

This is an important discussion, I Cc other ethdev maintainers.
Note: this is an ethdev patch, all ethdev maintainers should be Cc'ed. Aren't you using --cc-cmd devtools/get-maintainer.sh ?

#52 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Hi all

From: Jerin Jacob:

Quoted 45 lines
Quoted 3 lines · Thomas Monjalon

03/07/2020 17:08, Jerin Jacob:

Quoted 1 line

On Fri, Jul 3, 2020 at 8:25 PM Matan Azrad <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines
Quoted 8 lines

From: Jerin Jacob:

Quoted 5 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in

ethdev:

Quoted 30 lines
Quoted 29 lines
Quoted 17 lines

promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

Quoted 6 lines
Quoted 1 line

"Basic" is not a precise definition :)

Yep.

Quoted 2 lines

I would say port-level configuration should remain out of rte_flow API.

Thomas, Can you explain what is port-level?
Everything in rte_flow is per port...

Also, can you give reasons for your claim?

Quoted 3 lines

+1.
In addition that, I would say anything needs to configured at "per-flow" granularity use rte_flow.

Jerin, What do you mean "per-flow" ?
Everything in traffic filtering\actions is per flow, for example:

Promiscuous: flow create 0 ingress pattern eth / end actions queue index 0 / end Multicast\mac related: flow create 0 ingress pattern eth dst is X /end actions queue 0/ end (in case of legacy RSS queue action will be replaced by rss).
....

Everything here are flows.

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

But The VLAN and UDP related should be rte_flow candidates.(IMO)

Yes definitely, tunneling is better managed with rte_flow.

Can you give reasons for your claim?
Why should Vlan\Tunnel be in rte_flow and promiscuous\Multicast\mac not?

Quoted 1 line
Quoted 1 line

This is an important discussion, I Cc other ethdev maintainers.

Agree, this is a good trigger to open this important discussion.

Quoted 2 lines
Quoted 2 lines

Note: this is an ethdev patch, all ethdev maintainers should be Cc'ed. Aren't you using --cc-cmd devtools/get-maintainer.sh ?

#53 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 59 lines · Matan Azrad

Hi all

From: Jerin Jacob:

Quoted 45 lines
Quoted 3 lines · Thomas Monjalon

03/07/2020 17:08, Jerin Jacob:

Quoted 1 line

On Fri, Jul 3, 2020 at 8:25 PM Matan Azrad <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines
Quoted 8 lines

From: Jerin Jacob:

Quoted 5 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in

ethdev:

Quoted 30 lines
Quoted 29 lines
Quoted 17 lines

promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

Quoted 6 lines
Quoted 1 line

"Basic" is not a precise definition :)

Yep.

Quoted 2 lines

I would say port-level configuration should remain out of rte_flow API.

Thomas, Can you explain what is port-level?
Everything in rte_flow is per port...

Quoted 7 lines

Also, can you give reasons for your claim?

Quoted 3 lines

+1.
In addition that, I would say anything needs to configured at "per-flow" granularity use rte_flow.

Jerin, What do you mean "per-flow" ?

In Terms of NIC HW features, Typical HW will have
a) Basic "port" level configuration like
- enable/disable promiscuous
b) Advance HW's will have CAM based flow filtering. IMO, CAM related stuff should go to rte_flow.

This is to enable, The very basic PMD(without advanced features) should work with port level basic APIs(i.e without rte_flow)

I have seen promiscuous, mac address handling is part of basic NIC HW(i.e NICs without advanced CAM filters).
That's my reasoning for the split.

Quoted 2 lines

Everything in traffic filtering\actions is per flow, for example:
Promiscuous: flow create 0 ingress pattern eth / end actions queue index 0 / end

IMO, it is not an accurate representation of promiscuous enable. It needs to send the traffic
to all queues and patterns is not just eth.

Quoted 21 lines

Multicast\mac related: flow create 0 ingress pattern eth dst is X /end actions queue 0/ end (in case of legacy RSS queue action will be replaced by rss).
....

Everything here are flows.

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

But The VLAN and UDP related should be rte_flow candidates.(IMO)

Yes definitely, tunneling is better managed with rte_flow.

Can you give reasons for your claim?
Why should Vlan\Tunnel be in rte_flow and promiscuous\Multicast\mac not?

Quoted 1 line
Quoted 1 line

This is an important discussion, I Cc other ethdev maintainers.

Agree, this is a good trigger to open this important discussion.

Quoted 2 lines
Quoted 2 lines

Note: this is an ethdev patch, all ethdev maintainers should be Cc'ed. Aren't you using --cc-cmd devtools/get-maintainer.sh ?

#54 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

From: Jerin Jacob:

Quoted 67 lines · Matan Azrad
Quoted 66 lines

Hi all

From: Jerin Jacob:

Quoted 46 lines
Quoted 3 lines · Thomas Monjalon

03/07/2020 17:08, Jerin Jacob:

Quoted 1 line

On Fri, Jul 3, 2020 at 8:25 PM Matan Azrad <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 9 lines

From: Jerin Jacob:

Quoted 5 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in

ethdev:

Quoted 30 lines
Quoted 29 lines
Quoted 17 lines

promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

Quoted 6 lines
Quoted 1 line

"Basic" is not a precise definition :)

Yep.

Quoted 2 lines

I would say port-level configuration should remain out of rte_flow API.

Thomas, Can you explain what is port-level?
Everything in rte_flow is per port...

Also, can you give reasons for your claim?

Quoted 3 lines

+1.
In addition that, I would say anything needs to configured at "per-flow" granularity use rte_flow.

Quoted 5 lines
Quoted 1 line

Jerin, What do you mean "per-flow" ?

In Terms of NIC HW features, Typical HW will have
a) Basic "port" level configuration like
- enable/disable promiscuous

What is "port level", everything in rte_flow is also per port...

Quoted 2 lines

b) Advance HW's will have CAM based flow filtering. IMO, CAM related stuff should go to rte_flow.

It is HW internal, I don't think all HWs use the same logic here.
Since rte_flow is generic for all filtering methods, It is good candidate API for all HWs.

Quoted 2 lines

This is to enable, The very basic PMD(without advanced features) should work with port level basic APIs(i.e without rte_flow)

What is "basic"? Do you mean simple match and simple action?
As I said, Also rte_flow is port level API - so "port level" is not good term here.

As you said " When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev). Please depreciate the old API."

Different APIs to do the same thing is not good, especially in packet filtering:
What should we do if we have conflicts?
For example: legacy filtering APIs say to receive packet A and rte_flow says to drop it.

Don't you think it complicates more the user API understanding, also the PMD implementations?

Quoted 3 lines

I have seen promiscuous, mac address handling is part of basic NIC HW(i.e NICs without advanced CAM filters).
That's my reasoning for the split.

As I said, the nic HW specific implementation should not affect the API. I don't think we need to split API and to complicate the user because of it.

IMO, It is better to have one generic API for packet filtering:
It is clearer, simpler, generic and classic.
The user and PMD need to understand only one filtering API and that’s it (no need to combine between multiple filtering APIs).

I know this is big change but we can do it in modular way.
It reminds me the big change that was done in Rx\Tx offload configurations:
So, when offload became more popular we modularly forced users to replace the offload API.
Also here, flow filtering becomes popular so maybe this is the time(20.08-20.11) to force changes in the old APIs.

Quoted 6 lines
Quoted 3 lines

Everything in traffic filtering\actions is per flow, for example:
Promiscuous: flow create 0 ingress pattern eth / end actions queue index 0 / end

IMO, it is not an accurate representation of promiscuous enable. It needs to send the traffic to all queues and patterns is not just eth.

Yes, if legacy RSS is configured we need to replace the above queue action by rss action as I wrote before.(did you read it just below?)

So, we can add legacy RSS APIs to the list above...

Quoted 23 lines
Quoted 2 lines

Multicast\mac related: flow create 0 ingress pattern eth dst is X /end actions queue 0/ end (in case of legacy RSS queue action will be replaced by

rss).

Quoted 11 lines

....

Everything here are flows.

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

But The VLAN and UDP related should be rte_flow candidates.(IMO)

Yes definitely, tunneling is better managed with rte_flow.

Can you give reasons for your claim?
Why should Vlan\Tunnel be in rte_flow and promiscuous\Multicast\mac

not?

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

This is an important discussion, I Cc other ethdev maintainers.

Agree, this is a good trigger to open this important discussion.

Quoted 2 lines
Quoted 2 lines

Note: this is an ethdev patch, all ethdev maintainers should be Cc'ed. Aren't you using --cc-cmd devtools/get-maintainer.sh ?

#55 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 120 lines · Matan Azrad

From: Jerin Jacob:

Quoted 67 lines · Matan Azrad
Quoted 66 lines

Hi all

From: Jerin Jacob:

Quoted 46 lines
Quoted 3 lines · Thomas Monjalon

03/07/2020 17:08, Jerin Jacob:

Quoted 1 line

On Fri, Jul 3, 2020 at 8:25 PM Matan Azrad <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 9 lines

From: Jerin Jacob:

Quoted 5 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in

ethdev:

Quoted 30 lines
Quoted 29 lines
Quoted 17 lines

promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

Quoted 6 lines
Quoted 1 line

"Basic" is not a precise definition :)

Yep.

Quoted 2 lines

I would say port-level configuration should remain out of rte_flow API.

Thomas, Can you explain what is port-level?
Everything in rte_flow is per port...

Also, can you give reasons for your claim?

Quoted 3 lines

+1.
In addition that, I would say anything needs to configured at "per-flow" granularity use rte_flow.

Quoted 5 lines
Quoted 1 line

Jerin, What do you mean "per-flow" ?

In Terms of NIC HW features, Typical HW will have
a) Basic "port" level configuration like
- enable/disable promiscuous

What is "port level", everything in rte_flow is also per port...

Quoted 2 lines

b) Advance HW's will have CAM based flow filtering. IMO, CAM related stuff should go to rte_flow.

It is HW internal, I don't think all HWs use the same logic here.
Since rte_flow is generic for all filtering methods, It is good candidate API for all HWs.

Quoted 2 lines

This is to enable, The very basic PMD(without advanced features) should work with port level basic APIs(i.e without rte_flow)

What is "basic"? Do you mean simple match and simple action?
As I said, Also rte_flow is port level API - so "port level" is not good term here.

As you said " When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev). Please depreciate the old API."

Different APIs to do the same thing is not good, especially in packet filtering:
What should we do if we have conflicts?
For example: legacy filtering APIs say to receive packet A and rte_flow says to drop it.

Don't you think it complicates more the user API understanding, also the PMD implementations?

Quoted 3 lines

I have seen promiscuous, mac address handling is part of basic NIC HW(i.e NICs without advanced CAM filters).
That's my reasoning for the split.

As I said, the nic HW specific implementation should not affect the API. I don't think we need to split API and to complicate the user because of it.

IMO, It is better to have one generic API for packet filtering:
It is clearer, simpler, generic and classic.
The user and PMD need to understand only one filtering API and that’s it (no need to combine between multiple filtering APIs).

I know this is big change but we can do it in modular way.
It reminds me the big change that was done in Rx\Tx offload configurations:
So, when offload became more popular we modularly forced users to replace the offload API.
Also here, flow filtering becomes popular so maybe this is the time(20.08-20.11) to force changes in the old APIs.

Quoted 4 lines
Quoted 3 lines

Everything in traffic filtering\actions is per flow, for example:
Promiscuous: flow create 0 ingress pattern eth / end actions queue index 0 / end

Quoted 6 lines
Quoted 2 lines

IMO, it is not an accurate representation of promiscuous enable. It needs to send the traffic to all queues and patterns is not just eth.

Yes, if legacy RSS is configured we need to replace the above queue action by rss action as I wrote before.(did you read it just below?)

So, we can add legacy RSS APIs to the list above...

I meant, If promiscuous enable, then what would be the pattern, Should be limit just to "eth".
I leave up to ethdev maintainer to decide. Is promiscuous part of rte_flow API or not? I dnt have a very strong objection. For me, VLAN(rte_vlan_*) and MIRROR(rte_eth_mirror_rule_set()) are most worrisome as each PMD need to duplicate that work
as both are CAM based API.

#56 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

In reply to Thomas Monjalon
Quoted 42 lines · Thomas Monjalon

03/07/2020 17:08, Jerin Jacob:

Quoted 6 lines · Matan Azrad
Quoted 5 lines

From: Jerin Jacob:

Quoted 4 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the

same

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

ethdev library. It is pain for app and driver developers.

What are about all the other rte_flow parallel configuration APIs in

ethdev:

Quoted 20 lines
Quoted 17 lines

promiscuous_enable;
promiscuous_disable;
allmulticast_enable;
allmulticast_disable;
mac_addr_remove;
mac_addr_add;
mac_addr_set;
set_mc_addr_list;
vlan_filter_set;
vlan_tpid_set;
vlan_strip_queue_set;
vlan_offload_set;
vlan_pvid_set;
udp_tunnel_port_add;
udp_tunnel_port_del;
...

Quoted 2 lines

These APIs can be replaced easily by rte_flow API. Do you think we need to deprecate all?

Quoted 9 lines

I think, basic stuff like below can have separate API.
1) promiscuous_enable;
2) promiscuous_disable;
3) allmulticast_enable;
4) allmulticast_disable;
5) mac_addr_remove;
6) mac_addr_add;
7) mac_addr_set;
8) set_mc_addr_list;

Quoted 4 lines

"Basic" is not a precise definition :)
I would say port-level configuration should remain out of rte_flow API.

+1

Quoted 3 lines
Quoted 2 lines

But The VLAN and UDP related should be rte_flow candidates.(IMO)

I do not have a strong opinion on VLAN in port-level or rte_flow list. But isn't the UDP port number for tunnels a port-level setting for HW?

Quoted 9 lines

Yes definitely, tunneling is better managed with rte_flow.

This is an important discussion, I Cc other ethdev maintainers.
Note: this is an ethdev patch, all ethdev maintainers should be Cc'ed. Aren't you using --cc-cmd devtools/get-maintainer.sh ?

#57 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

In reply to Jerin Jacob
Quoted 25 lines · Jerin Jacob
Quoted 12 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

Quoted 6 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure

rte_flow_action_sample

Quoted 4 lines

will be introduced.

Quoted 9 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

With the above deprecation notice,

I am fine with the proposed RTE_FLOW_ACTION_TYPE_SAMPLE. But..

When rte_eth_mirror_rule_set() is deprecated, are we going to add RTE_FLOW_ACTION_TYPE_MIRROR for full fledged mirror action? Or we are proposing to use RTE_FLOW_ACTION_TYPE_SAMPLE with ratio of 1 to mirror all packets, thereby doing away with the need for a separate RTE_FLOW_ACTION_TYPE_MIRROR?

Quoted 135 lines

Review

Quoted 10 lines

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28 ++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
(quoted diff) +0 -0

b/doc/guides/prog_guide/rte_flow.rst

Quoted 8 lines

index d5dd18c..50dfe1f 100644

doc/guides/prog_guide/rte_flow.rst +1 -0
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2658

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or

mirrored

Review

Quoted 18 lines
doc/guides/prog_guide/rte_flow.rst +14 -0
+packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_20_08.rst

doc/guides/rel_notes/release_20_08.rst New Features · line 86

Quoted 10 lines

index 5cbc4ce..313e8d3 100644

doc/guides/rel_notes/release_20_08.rst +3 -0
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the

matching

doc/guides/rel_notes/release_20_08.rst New Features · line 87

Quoted 1 line
doc/guides/rel_notes/release_20_08.rst +1 -0
+  packets with given ratio and redirects to vport or queue. The sampled

packets

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 173

Quoted 11 lines
doc/guides/rel_notes/release_20_08.rst +2 -0
+  also can be assigned with an additional optional actions.
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
lib/librte_ethdev/rte_flow.c +0 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
        MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 174

Quoted 1 line
lib/librte_ethdev/rte_flow.c +0 -0
        MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

Quoted 29 lines
lib/librte_ethdev/rte_flow.c +1 -0
        MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+       MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +9 -0
index b0e4199..c9cd80d 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
         * see enum RTE_ETH_EVENT_FLOW_AGED
         */
        RTE_FLOW_ACTION_TYPE_AGE,
+
+       /**
+        * Redirects specific ratio of packets to vport or queue.
+        *
+        * See struct rte_flow_action_sample.
+        */
+       RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2730

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport
+ * in the predefined probabiilty, All the packets continues processing
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2731

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

lib/librte_ethdev/rte_flow.h struct rte_flow_action {

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +3 -0
+ */
+struct rte_flow_action_sample {
+       const uint32_t ratio; /**< packets sampled equals to '1/ratio'.

*/

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2736

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+       const struct rte_flow_action *actions;
+               /**< sub-action list specific for the sampling hit

cases. */

Quoted 9 lines
lib/librte_ethdev/rte_flow.h +3 -1
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
--

1.8.3.1

#58 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

04/07/2020 16:44, Ajit Khaparde:

Quoted 10 lines · Jerin Jacob
Quoted 9 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

With the above deprecation notice,

Quoted 7 lines

I am fine with the proposed RTE_FLOW_ACTION_TYPE_SAMPLE. But..

When rte_eth_mirror_rule_set() is deprecated, are we going to add RTE_FLOW_ACTION_TYPE_MIRROR for full fledged mirror action? Or we are proposing to use RTE_FLOW_ACTION_TYPE_SAMPLE with ratio of 1 to mirror all packets, thereby doing away with the need for a separate RTE_FLOW_ACTION_TYPE_MIRROR?

The idea is to use RTE_FLOW_ACTION_TYPE_SAMPLE with ratio=1 for mirroring.

#59 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 14 lines · Thomas Monjalon

04/07/2020 16:44, Ajit Khaparde:

Quoted 1 line

On Thu, Jul 2, 2020 at 11:40 PM Jerin Jacob <[email protected]>

Quoted 11 lines · wrote:
Quoted 9 lines

When adding overlapping API(rte_eth_mirror_rule_set()) in the same library(ethdev).
Please depreciate the old API.
We should not have two separate paths for the same function in the same ethdev library. It is pain for app and driver developers.

With the above deprecation notice,

I am fine with the proposed RTE_FLOW_ACTION_TYPE_SAMPLE. But..

Quoted 8 lines
Quoted 5 lines

When rte_eth_mirror_rule_set() is deprecated, are we going to add RTE_FLOW_ACTION_TYPE_MIRROR for full fledged mirror action? Or we are proposing to use RTE_FLOW_ACTION_TYPE_SAMPLE with ratio of 1 to mirror all packets, thereby doing away with the need for a separate RTE_FLOW_ACTION_TYPE_MIRROR?

The idea is to use RTE_FLOW_ACTION_TYPE_SAMPLE with ratio=1 for mirroring.

Thanks for clarifying.

#60 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

In reply to Jiawei Wang
Quoted 2 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses

vf->VF

Quoted 9 lines

visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

May be 1 packet per second is a better sampling approach? Or just different.

Quoted 2 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet

Comma on the next line looks bad.

Quoted 20 lines

can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28 ++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
doc/guides/prog_guide/rte_flow.rst +0 -0
index d5dd18c..50dfe1f 100644

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2653

Quoted 9 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport

what is vport above?

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2655

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.

continues -> continue (if I'm not mistaken)

Quoted 25 lines
doc/guides/prog_guide/rte_flow.rst +17 -0
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_08.rst +0 -0
index 5cbc4ce..313e8d3 100644

doc/guides/rel_notes/release_20_08.rst New Features · line 87

Quoted 7 lines
doc/guides/rel_notes/release_20_08.rst +4 -0
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching
+  packets with given ratio and redirects to vport or queue. The sampled packets

What is vport above?

doc/guides/rel_notes/release_20_08.rst New Features · line 88

Quoted 1 line
doc/guides/rel_notes/release_20_08.rst +1 -0
+  also can be assigned with an additional optional actions.

May actions list be empty or NULL? If no, it does not look optional.

Quoted 36 lines
doc/guides/rel_notes/release_20_08.rst +1 -0
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
lib/librte_ethdev/rte_flow.c +1 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +7 -0
index b0e4199..c9cd80d 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * Redirects specific ratio of packets to vport or queue.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {
 struct rte_flow;

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2726

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +8 -0
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport

again 'vport' here
It sounds misleading and too restrictive to say "be duplicated to a special queue or vport". There is no specification of the queue or vport in the control structure.
You should either describe it in a generic way like "be duplicated and own set of actions with a fate action applied" or put a restriction about QUEUE, RSS or "vport"-related action to be present in the sub-actions list.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2727

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+ * in the predefined probabiilty, All the packets continues processing

probabiilty -> probability
I think 'predefined' is misleading here, 'specified' is better. Also strictly speaking it is not a predefined probability (as Stephen suggested), it is defined ratio.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2734

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +7 -0
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */

const is still above and it is meaningless (other actions do not have 'const' for plain fields).

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2736

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */

Is it required to have fate action?
May I use it to MARK some packets and do not duplicate? I guess no. Or COUNT and DROP? Just COUNT?

What I'm trying to say that you're adding a generic packet selection mechanism with very restricted usage by design.

Anyway, if you go with it, please, process other notes above.

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +3 -0
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
#61 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Hi Andrew,

I replied to some of your comments.
Best,
Ori

Quoted 16 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Andrew Rybchenko
Sent: Saturday, July 4, 2020 4:05 PM
Subject: Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 2 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses

vf->VF

Quoted 4 lines

visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 9 lines
Quoted 5 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

May be 1 packet per second is a better sampling approach? Or just different.

Those are two different things, lets take a packet that arrives once every two seconds and we ask to sample once every second, this means that we will always get that packet. Also as far as I understand the use case is to have some visibility about the traffic. so you can assume that if a packet is sent once per second the application will get the packet with very high delay and very low visibility. Lets take a use case that the hyprivor wants to check if one of the VM is abusing the system (sends DDOS packets, or just trying to understand the network) in this case we can assume that the VM will send large amount of traffic. and if we only check once per second the application will not be able to understand the traffic meaning, but if we sample 1% of the traffic then the application will see very fast the type of the traffic the VM is sending and if it is trying to abuse the system. So I vote in favor of keeping as is.

Quoted 30 lines
Quoted 2 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet

Comma on the next line looks bad.

Quoted 4 lines

can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure

rte_flow_action_sample

Quoted 4 lines

will be introduced.

Review

Quoted 8 lines
---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28 ++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
(quoted diff) +0 -0

b/doc/guides/prog_guide/rte_flow.rst

Quoted 7 lines

index d5dd18c..50dfe1f 100644

doc/guides/prog_guide/rte_flow.rst +0 -0
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2653

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport

what is vport above?

I think it should be port (when using E-Switch)

Quoted 34 lines

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2655

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.

continues -> continue (if I'm not mistaken)

Review

Quoted 21 lines
doc/guides/prog_guide/rte_flow.rst +17 -0
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_20_08.rst

Quoted 7 lines

index 5cbc4ce..313e8d3 100644

doc/guides/rel_notes/release_20_08.rst +0 -0
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
Quoted 9 lines

doc/guides/rel_notes/release_20_08.rst New Features

Quoted 3 lines
doc/guides/rel_notes/release_20_08.rst +3 -0
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the

matching

doc/guides/rel_notes/release_20_08.rst New Features · line 87

Quoted 1 line
doc/guides/rel_notes/release_20_08.rst +1 -0
+  packets with given ratio and redirects to vport or queue. The sampled

packets

What is vport above?

See comment above.

Quoted 5 lines

doc/guides/rel_notes/release_20_08.rst New Features · line 88

Quoted 1 line
doc/guides/rel_notes/release_20_08.rst +1 -0
+  also can be assigned with an additional optional actions.

May actions list be empty or NULL? If no, it does not look optional.

I think that the action list can't be NULL or empty. There is no meaning to empty list. I agree it should be stated.

Quoted 69 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 173

Quoted 10 lines
doc/guides/rel_notes/release_20_08.rst +1 -0
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
lib/librte_ethdev/rte_flow.c +0 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 174

Quoted 1 line
lib/librte_ethdev/rte_flow.c +0 -0
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

Quoted 25 lines
lib/librte_ethdev/rte_flow.c +1 -0
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +7 -0
index b0e4199..c9cd80d 100644
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * Redirects specific ratio of packets to vport or queue.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {
 struct rte_flow;

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2726

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +8 -0
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport

again 'vport' here
It sounds misleading and too restrictive to say "be duplicated to a special queue or vport". There is no specification of the queue or vport in the control structure.
You should either describe it in a generic way like "be duplicated and own set of actions with a fate action applied" or put a restriction about QUEUE, RSS or "vport"-related action to be present in the sub-actions list.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2727

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+ * in the predefined probabiilty, All the packets continues processing

probabiilty -> probability
I think 'predefined' is misleading here, 'specified' is better. Also strictly speaking it is not a predefined probability (as Stephen suggested), it is defined ratio.

lib/librte_ethdev/rte_flow.h struct rte_flow_action {

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored
Quoted 8 lines

packets.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2734

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +3 -0
+ */
+struct rte_flow_action_sample {
+	const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */

const is still above and it is meaningless (other actions do not have 'const' for plain fields).

+1

Quoted 7 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2736

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */

Is it required to have fate action?
May I use it to MARK some packets and do not duplicate? I guess no. Or COUNT and DROP? Just COUNT?

I from my understanding you may use mark and count but it also must have a fate action.

Quoted 13 lines

What I'm trying to say that you're adding a generic packet selection mechanism with very restricted usage by design.

Anyway, if you go with it, please, process other notes above.

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +3 -0
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
#62 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 45 lines · Ori Kam

Hi Andrew,

I replied to some of your comments.
Best,
Ori

Quoted 4 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Andrew Rybchenko
Sent: Saturday, July 4, 2020 4:05 PM
Subject: Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action

for rte

Quoted 10 lines

flow

Quoted 2 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses

vf->VF

Quoted 2 lines

visibility on the traffic.
So there's a need for an action that will enable the control

application

Quoted 11 lines
Quoted 7 lines

some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

May be 1 packet per second is a better sampling approach? Or just different.

Those are two different things, lets take a packet that arrives once every two seconds
and we ask to sample once every second, this means that we will always get that packet.
Also as far as I understand the use case is to have some visibility about the traffic.
so you can assume that if a packet is sent once per second the application will get the packet
with very high delay and very low visibility. Lets take a use case that the hyprivor
wants to check if one of the VM is abusing the system (sends DDOS packets, or just
trying to understand the network) in this case we can assume that the VM

Quoted 9 lines

will send large
amount of traffic. and if we only check once per second the application will not be able to
understand the traffic meaning, but if we sample 1% of the traffic then the application will
see very fast the type of the traffic the VM is sending and if it is trying to abuse the system.
So I vote in favor of keeping as is.

Thanks for bringing this up.
So an application may want to sample either "finite" packets per second or "a percentage" of packets per second or "all" packets.
So a "uint32_t ratio" may not just be enough by itself.
Maybe we need to also couple it with a unit.

uint32_t sampling_unit; /* Specifies one of the units to use while
sampling. */
RTE_FLOW_NUM_PACKETS_PER_SEC /* Samples specific number of packets per second. */
RTE_FLOW_PERCENT_PACKETS_PER_SEC /* Samples a percentage of packets per second. */
RTE_FLOW_ALL_PACKETS /* SAMPLES all packets - equivalent to mirror */
This may be redundant if percentage is specified and ratio is 100. In that case instead of "uint32_t ratio", just use "uint32_t sample"?

Quoted 209 lines
Quoted 3 lines
Quoted 3 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample

packet

Quoted 17 lines

Comma on the next line looks bad.

Quoted 4 lines

can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure

rte_flow_action_sample

Quoted 9 lines

will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28

++++++++++++++++++++++++++++

Quoted 11 lines

Review

Quoted 3 lines
 4 files changed, 60 insertions(+)
(quoted diff) +0 -0

b/doc/guides/prog_guide/rte_flow.rst

Quoted 7 lines

index d5dd18c..50dfe1f 100644

doc/guides/prog_guide/rte_flow.rst +0 -0
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2653

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport

what is vport above?

I think it should be port (when using E-Switch)

Quoted 1 line

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2654

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+with the predefined ``ratio``, the packets sampled equals is

'1/ratio'.

Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2655

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+All the packets continues to the target destination.

continues -> continue (if I'm not mistaken)

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow.

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +3 -0
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or

mirrored

Quoted 26 lines

Review

Quoted 18 lines
doc/guides/prog_guide/rte_flow.rst +14 -0
+packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_20_08.rst

Quoted 7 lines

index 5cbc4ce..313e8d3 100644

doc/guides/rel_notes/release_20_08.rst +0 -0
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
Quoted 5 lines

doc/guides/rel_notes/release_20_08.rst New Features

Quoted 3 lines
doc/guides/rel_notes/release_20_08.rst +3 -0
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the

matching

Quoted 1 line
doc/guides/rel_notes/release_20_08.rst +1 -0
+  packets with given ratio and redirects to vport or queue. The

sampled

Quoted 4 lines

packets

What is vport above?

See comment above.

Quoted 5 lines

doc/guides/rel_notes/release_20_08.rst New Features · line 88

Quoted 1 line
doc/guides/rel_notes/release_20_08.rst +1 -0
+  also can be assigned with an additional optional actions.

May actions list be empty or NULL? If no, it does not look optional.

I think that the action list can't be NULL or empty. There is no meaning to empty list.
I agree it should be stated.

Quoted 5 lines

Review

Quoted 5 lines
doc/guides/rel_notes/release_20_08.rst +1 -0
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.c

Quoted 6 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 173

Quoted 5 lines

index 1685be5..733871d 100644

lib/librte_ethdev/rte_flow.c +0 -0
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
    MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

Quoted 8 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 174

Quoted 1 line
lib/librte_ethdev/rte_flow.c +0 -0
    MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

Review

Quoted 6 lines
lib/librte_ethdev/rte_flow.c +1 -0
    MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+   MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.h

Quoted 39 lines
Quoted 19 lines

index b0e4199..c9cd80d 100644

lib/librte_ethdev/rte_flow.h +7 -0
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
     * see enum RTE_ETH_EVENT_FLOW_AGED
     */
    RTE_FLOW_ACTION_TYPE_AGE,
+
+   /**
+    * Redirects specific ratio of packets to vport or queue.
+    *
+    * See struct rte_flow_action_sample.
+    */
+   RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {
 struct rte_flow;

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2726

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +8 -0
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or vport

again 'vport' here
It sounds misleading and too restrictive to say "be duplicated to a special queue or vport". There is no specification of the queue or vport in the control structure.
You should either describe it in a generic way like "be duplicated and own set of actions with a fate action applied" or put a restriction about QUEUE, RSS or "vport"-related action to be present in the sub-actions list.

Quoted 10 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2727

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+ * in the predefined probabiilty, All the packets continues processing

probabiilty -> probability
I think 'predefined' is misleading here, 'specified' is better. Also strictly speaking it is not a predefined probability (as Stephen suggested), it is defined ratio.

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +3 -0
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Quoted 9 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2731

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+ * Additional action list be supported to add for sampled or mirrored

packets.

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2734

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +3 -0
+ */
+struct rte_flow_action_sample {
+   const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */

const is still above and it is meaningless (other actions do not have 'const' for plain fields).

+1

Quoted 2 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2736

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+   const struct rte_flow_action *actions;
+           /**< sub-action list specific for the sampling hit cases.

*/

Quoted 5 lines

Is it required to have fate action?
May I use it to MARK some packets and do not duplicate? I guess no. Or COUNT and DROP? Just COUNT?

I from my understanding you may use mark and count but it also must have a fate action.

Quoted 13 lines

What I'm trying to say that you're adding a generic packet selection mechanism with very restricted usage by design.

Anyway, if you go with it, please, process other notes above.

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +3 -0
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
#63 lore raw

Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

In reply to Ori Kam

Thanks Andrew and Ori,

Quoted 12 lines

-----Original Message-----
From: Ori Kam <[email protected]>
Sent: Sunday, July 5, 2020 6:19 PM
To: Andrew Rybchenko <[email protected]>; Jiawei(Jonny) Wang <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]
Subject: RE: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 16 lines

Hi Andrew,

I replied to some of your comments.
Best,
Ori

Quoted 11 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Andrew Rybchenko
Sent: Saturday, July 4, 2020 4:05 PM
Subject: Re: [dpdk-dev] [PATCH v2 1/7] ethdev: introduce sample action for rte flow

Quoted 2 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested vf or wire, the control application loses

vf->VF

will change in v3 patch.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines

visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

Quoted 9 lines
Quoted 5 lines

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic in some predefined ratio to the application, while the original packet will continue to the target destination.

May be 1 packet per second is a better sampling approach? Or just different.

Quoted 22 lines

Those are two different things, lets take a packet that arrives once every two seconds and we ask to sample once every second, this means that we will always get that packet.
Also as far as I understand the use case is to have some visibility about the traffic.
so you can assume that if a packet is sent once per second the application will get the packet with very high delay and very low visibility. Lets take a use case that the hyprivor wants to check if one of the VM is abusing the system (sends DDOS packets, or just trying to understand the network) in this case we can assume that the VM will send large amount of traffic. and if we only check once per second the application will not be able to understand the traffic meaning, but if we sample 1% of the traffic then the application will see very fast the type of the traffic the VM is sending and if it is trying to abuse the system.
So I vote in favor of keeping as is.

Quoted 5 lines
Quoted 3 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1 , means that the packets would be completely mirrored. The sample packet

Comma on the next line looks bad.

ok, will move the Comma to the same line.

Quoted 37 lines
Quoted 12 lines
Quoted 5 lines

can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure

rte_flow_action_sample

Quoted 6 lines

will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst     | 25

+++++++++++++++++++++++++

Quoted 11 lines

Review

Quoted 6 lines
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 28 ++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)
(quoted diff) +0 -0

b/doc/guides/prog_guide/rte_flow.rst

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the

Quoted 4 lines

index d5dd18c..50dfe1f 100644

doc/guides/prog_guide/rte_flow.rst +0 -0
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the

flow.

Quoted 12 lines

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2653

Quoted 9 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated to a special queue or vport

what is vport above?

Quoted 1 line

I think it should be port (when using E-Switch)

Yes, the destination port is working on e-switch mode, change vport->port.

Quoted 5 lines
Quoted 5 lines

doc/guides/prog_guide/rte_flow.rst timeout passed without any matching on the flow. · line 2655

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+with the predefined ``ratio``, the packets sampled equals is '1/ratio'.
+All the packets continues to the target destination.

continues -> continue (if I'm not mistaken)

ok, will change.

Quoted 43 lines
Quoted 35 lines

Review

Quoted 22 lines
doc/guides/prog_guide/rte_flow.rst +17 -0
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled
+or mirrored packets.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_20_08.rst

doc/guides/rel_notes/release_20_08.rst New Features · line 87

Quoted 11 lines

index 5cbc4ce..313e8d3 100644

doc/guides/rel_notes/release_20_08.rst +4 -0
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate
+ the

matching

Quoted 6 lines

doc/guides/rel_notes/release_20_08.rst New Features · line 89

Quoted 2 lines
doc/guides/rel_notes/release_20_08.rst +2 -0
+  packets with given ratio and redirects to vport or queue. The
+ sampled

packets

What is vport above?

See comment above.

Quoted 8 lines
Quoted 4 lines

doc/guides/rel_notes/release_20_08.rst New Features · line 88

Quoted 1 line
doc/guides/rel_notes/release_20_08.rst +1 -0
+  also can be assigned with an additional optional actions.

May actions list be empty or NULL? If no, it does not look optional.

I think that the action list can't be NULL or empty. There is no meaning to empty list.
I agree it should be stated.

'optional' means that besides an fate action, also can combine with addition action if needed, like mark and queue for sampled packet.

Quoted 50 lines
Quoted 50 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 173

Quoted 10 lines
doc/guides/rel_notes/release_20_08.rst +1 -0
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.c index 1685be5..733871d 100644

lib/librte_ethdev/rte_flow.c +0 -0
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 174

Quoted 1 line
lib/librte_ethdev/rte_flow.c +0 -0
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct

rte_flow_action_set_dscp)),

Quoted 25 lines
lib/librte_ethdev/rte_flow.c +1 -0
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.h index b0e4199..c9cd80d 100644

lib/librte_ethdev/rte_flow.h +7 -0
@@ -2099,6 +2099,13 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * Redirects specific ratio of packets to vport or queue.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2716,27 @@ struct rte_flow_action {  struct rte_flow;
 

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2726

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +9 -0
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated to a special queue or
+ vport

again 'vport' here

Quoted 8 lines
Quoted 8 lines

It sounds misleading and too restrictive to say "be duplicated to a special queue or vport". There is no specification of the queue or vport in the control structure.
You should either describe it in a generic way like "be duplicated and own set of actions with a fate action applied"
or put a restriction about QUEUE, RSS or "vport"-related action to be present in the sub-actions list.

I'll change the description to "The matching packets will be duplicated and applied with own set of actions with a fate action"

Quoted 8 lines
Quoted 8 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2728

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+ * in the predefined probabiilty, All the packets continues
+ processing

probabiilty -> probability
I think 'predefined' is misleading here, 'specified' is better. Also strictly speaking it is not a predefined probability (as Stephen suggested), it is defined ratio.

Thanks for pointing out typo, I will use 'specified ratio' instead of.

Quoted 7 lines
Quoted 3 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action {

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +3 -0
+ * on the default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100%

mirrored.

Quoted 3 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { struct rte_flow; · line 2733

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+ * Additional action list be supported to add for sampled or
+ mirrored

packets.

Quoted 8 lines
Quoted 7 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2734

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +3 -0
+ */
+struct rte_flow_action_sample {
+	const uint32_t ratio; /**< packets sampled equals to '1/ratio'. */

const is still above and it is meaningless (other actions do not have 'const' for plain fields).

+1

agree, remove 'const'.

Quoted 11 lines
Quoted 8 lines

lib/librte_ethdev/rte_flow.h struct rte_flow_action { · line 2736

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +2 -0
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */

Is it required to have fate action?
May I use it to MARK some packets and do not duplicate? I guess no. Or COUNT and DROP? Just COUNT?

I from my understanding you may use mark and count but it also must have a fate action.

Yes, need fate action for sampling, mark or count is optional action.

Quoted 13 lines
Quoted 13 lines

What I'm trying to say that you're adding a generic packet selection mechanism with very restricted usage by design.

Anyway, if you go with it, please, process other notes above.

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +3 -0
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
#64 lore raw

PATCH v2 2/7 common/mlx5: glue for sample action

In reply to Jiawei Wang

rdma-core introduce a new DR sample action.

Add the rdma-core commands in glue to create this action.

Sample action is used for creating the sample object to implement the sampling/mirroring function.

---
 drivers/common/mlx5/Makefile          |  5 +++++
 drivers/common/mlx5/linux/meson.build |  2 ++
 drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 12 ++++++++++++
 4 files changed, 34 insertions(+)
drivers/common/mlx5/Makefile +5 -0
index f6c762b..4c1484c 100644
@@ -192,6 +192,11 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh
 		func mlx5dv_dump_dr_domain \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_flow_sampler \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_MLX5DV_MMAP_GET_NC_PAGES_CMD \
 		infiniband/mlx5dv.h \
 		enum MLX5_MMAP_GET_NC_PAGES_CMD \
drivers/common/mlx5/linux/meson.build +2 -0
index 2294213..0f08318 100644
@@ -162,6 +162,8 @@ has_sym_args = [
 	'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
 	[ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
 	'mlx5dv_dump_dr_domain'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_flow_sampler'],
 	[ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h',
 	'mlx5dv_dr_domain_set_reclaim_device_memory'],
 	[ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
index 048207e..98b3e71 100644
@@ -1059,6 +1059,19 @@
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_sampler(
+			struct mlx5dv_dr_flow_sampler_attr *attr)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+	return mlx5dv_dr_action_create_flow_sampler(attr);
+#else
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static int
 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
 			 uint32_t *eqn)
@@ -1308,6 +1321,8 @@
 	.devx_port_query = mlx5_glue_devx_port_query,
 	.dr_dump_domain = mlx5_glue_dr_dump_domain,
 	.dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
+	.dr_create_flow_action_sampler =
+		mlx5_glue_dr_create_flow_action_sampler,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
 	.devx_create_event_channel = mlx5_glue_devx_create_event_channel,
 	.devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +12 -0
index 069d854..11b95c5 100644
@@ -77,6 +77,7 @@
 #ifndef HAVE_MLX5DV_DR
 enum  mlx5dv_dr_domain_type { unused, };
 struct mlx5dv_dr_domain;
+struct mlx5dv_dr_action;
 #endif
 
 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,15 @@
 struct mlx5dv_dr_flow_meter_attr;
 #endif
 
+#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+struct mlx5dv_dr_flow_sampler_attr {
+	uint32_t sample_ratio;
+	void *default_next_table;
+	size_t num_sample_actions;
+	struct mlx5dv_dr_action **sample_actions;
+};
+#endif
+
 #ifndef HAVE_IBV_DEVX_EVENT
 struct mlx5dv_devx_event_channel { int fd; };
 struct mlx5dv_devx_async_event_hdr;
@@ -304,6 +314,8 @@ struct mlx5_glue {
 			 struct mlx5dv_devx_async_event_hdr *event_data,
 			 size_t event_resp_len);
 	void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
+	void *(*dr_create_flow_action_sampler)
+			(struct mlx5dv_dr_flow_sampler_attr *attr);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
#65 lore raw

PATCH v2 3/7 common/mlx5: query sampler object capability via DevX

In reply to Jiawei Wang

Update function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.

Add the related structs definition in mlx5_prm.h.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++
 drivers/common/mlx5/mlx5_devx_cmds.h |  1 +
 drivers/common/mlx5/mlx5_prm.h       | 51 ++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
index ec92eb6..6b551f1 100644
@@ -496,6 +496,33 @@ struct mlx5_devx_obj *
 	if (!attr->eth_net_offloads)
 		return 0;
 
+	/* Query Flow Sampler Capabilitiy From FLow Table Properties Layout. */
+	memset(in, 0, sizeof(in));
+	memset(out, 0, sizeof(out));
+	MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
+	MLX5_SET(query_hca_cap_in, in, op_mod,
+		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
+		 MLX5_HCA_CAP_OPMOD_GET_CUR);
+
+	rc = mlx5_glue->devx_general_cmd(ctx,
+					 in, sizeof(in),
+					 out, sizeof(out));
+	if (rc)
+		goto error;
+	status = MLX5_GET(query_hca_cap_out, out, status);
+	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
+	if (status) {
+		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
+			"status %x, syndrome = %x",
+			status, syndrome);
+		attr->log_max_ft_sampler_num = 0;
+		return -1;
+	}
+	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
+	attr->log_max_ft_sampler_num =
+			MLX5_GET(flow_table_nic_cap,
+			hcattr, flow_table_properties.log_max_ft_sampler_num);
+
 	/* Query HCA offloads for Ethernet protocol. */
 	memset(in, 0, sizeof(in));
 	memset(out, 0, sizeof(out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
index 25704ef..a9cfe6d 100644
@@ -90,6 +90,7 @@ struct mlx5_hca_attr {
 	uint32_t vhca_id:16;
 	uint32_t relaxed_ordering_write:1;
 	uint32_t relaxed_ordering_read:1;
+	uint32_t log_max_ft_sampler_num:8;
 	struct mlx5_hca_qos_attr qos;
 	struct mlx5_hca_vdpa_attr vdpa;
 };
drivers/common/mlx5/mlx5_prm.h +51 -0

69 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#66 lore raw

PATCH v2 4/7 net/mlx5: add the validate sample action

In reply to Jiawei Wang

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX.

Only NIC_RX support with addition optional actions. FDB doesn't support any optional action, the sampled packets is always goes to e-switch manager port.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 133 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
index 2dc57b2..6dfacf2 100644
@@ -878,6 +878,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config.hca_attr.log_max_ft_sampler_num > 0  &&
+		    config.dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config.hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register for"
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not supported!\n");
+		}
+#endif
 	}
 	if (config.mprq.enabled && mprq) {
 		if (config.mprq.stride_num_n &&
drivers/net/mlx5/mlx5.h +1 -0
index 46e66eb..6790738 100644
@@ -617,6 +617,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management. */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
index 43cbda8..45a073c 100644
@@ -202,6 +202,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35)
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +133 -0

145 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Acked-by on v2 4/7
#67 lore raw

Re: [dpdk-dev] [PATCH v2 4/7] net/mlx5: add the validate sample action

Hi Jiawei

Quoted 9 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Subject: [PATCH v2 4/7] net/mlx5: add the validate sample action

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX.

Quoted 6 lines

Only NIC_RX support with addition optional actions. FDB doesn't support any optional action, the sampled packets is always goes to e-switch manager port.

---

Thanks,
Ori

#68 lore raw

PATCH v2 5/7 net/mlx5: split sample flow into two sub flows

In reply to Jiawei Wang

Add the sampler action resource structs definition.

The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.

For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.

---
 drivers/net/mlx5/mlx5.c      |  11 ++
 drivers/net/mlx5/mlx5.h      |   3 +
 drivers/net/mlx5/mlx5_flow.c | 258 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h |  36 ++++++
 4 files changed, 304 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
index 07c6add..db55545 100644
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		.free = rte_free,
 		.type = "mlx5_jump_ipool",
 	},
+	{
+		.size = sizeof(struct mlx5_flow_dv_sample_resource),
+		.trunk_size = 64,
+		.grow_trunk = 3,
+		.grow_shift = 2,
+		.need_lock = 0,
+		.release_mem_en = 1,
+		.malloc = rte_malloc_socket,
+		.free = rte_free,
+		.type = "mlx5_sample_ipool",
+	},
 #endif
 	{
 		.size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
index 6790738..756bd68 100644
@@ -51,6 +51,7 @@ enum mlx5_ipool_index {
 	MLX5_IPOOL_TAG, /* Pool for tag resource. */
 	MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
 	MLX5_IPOOL_JUMP, /* Pool for jump resource. */
+	MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */
 #endif
 	MLX5_IPOOL_MTR, /* Pool for meter resource. */
 	MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -518,6 +519,7 @@ struct mlx5_flow_tbl_resource {
 /* Tables for metering splits should be added here. */
 #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)
 #define MLX5_MAX_TABLES_FDB UINT16_MAX
+#define MLX5_FLOW_TABLE_FACTOR 10
 
 /* ID generation structure. */
 struct mlx5_flow_id_pool {
@@ -566,6 +568,7 @@ struct mlx5_dev_ctx_shared {
 	struct mlx5_hlist *tag_table;
 	uint32_t port_id_action_list; /* List of port ID actions. */
 	uint32_t push_vlan_action_list; /* List of push VLAN actions. */
+	uint32_t sample_action_list; /* List of sample actions. */
 	struct mlx5_flow_counter_mng cmng; /* Counters management structure. */
 	struct mlx5_flow_default_miss_resource default_miss;
 	/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +254 -4

294 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +36 -0
index 45a073c..51826f8 100644
@@ -502,6 +502,38 @@ struct mlx5_flow_tbl_data_entry {
 	uint32_t idx; /**< index for the indexed mempool. */
 };
 
+/* Sub rdma-core actions list. */
+struct mlx5_flow_sub_actions_list {
+	uint32_t actions_num; /**< Number of sample actions. */
+	uint64_t action_flags;
+	void *dr_queue_action;
+	void *dr_tag_action;
+	void *dr_cnt_action;
+};
+
+/* Sample sub-actions resource list. */
+struct mlx5_flow_sub_actions_idx {
+	uint32_t rix_hrxq; /**< Hash Rx queue object index. */
+	uint32_t rix_tag; /**< Index to the tag action. */
+	uint32_t cnt;
+};
+
+/* Sample action resource structure. */
+struct mlx5_flow_dv_sample_resource {
+	ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
+	rte_atomic32_t refcnt; /**< Reference counter. */
+	void *verbs_action; /**< Verbs sample action object. */
+	uint8_t ft_type; /** Flow Table Type */
+	uint32_t ft_id; /** Flow Table Level */
+	void *normal_path_tbl; /** Flow Table pointer */
+	void *default_miss; /** default_miss dr_action. */
+	uint32_t ratio;   /** Sample Ratio */
+	struct mlx5_flow_sub_actions_idx sample_idx;
+	/**< Action index resources. */
+	struct mlx5_flow_sub_actions_list sample_act;
+	/**< Action resources. */
+};
+
 /* Verbs specification header. */
 struct ibv_spec_header {
 	enum ibv_flow_spec_type type;
@@ -530,6 +562,8 @@ struct mlx5_flow_handle_dv {
 	/**< Index to push VLAN action resource in cache. */
 	uint32_t rix_tag;
 	/**< Index to the tag action. */
+	uint32_t rix_sample;
+	/**< Index to sample action resource in cache. */
 } __rte_packed;
 
 /** Device flow handle structure: used both for creating & destroying. */
@@ -595,6 +629,8 @@ struct mlx5_flow_dv_workspace {
 	/**< Pointer to the jump action resource. */
 	struct mlx5_flow_dv_match_params value;
 	/**< Holds the value that the packet is compared to. */
+	struct mlx5_flow_dv_sample_resource *sample_res;
+	/**< Pointer to the sample action resource. */
 };
 
 /*
Signature · 1 line
1.8.3.1
#69 lore raw

PATCH v2 6/7 net/mlx5: update translate function for sample action

In reply to Jiawei Wang

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---
 drivers/net/mlx5/mlx5_flow.c    |  16 +-
 drivers/net/mlx5/mlx5_flow.h    |  14 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 494 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 502 insertions(+), 22 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
index 7ed9ba3..c91ae7d 100644
@@ -4612,10 +4612,14 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	int hairpin_flow;
 	uint32_t hairpin_id = 0;
 	struct rte_flow_attr attr_tx = { .priority = 0 };
+	struct rte_flow_attr attr_factor = {0};
 	int ret;
 
-	hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
-	ret = flow_drv_validate(dev, attr, items, p_actions_rx,
+	memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
+	if (external)
+		attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
+	hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
+	ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
 				external, hairpin_flow, error);
 	if (ret < 0)
 		return 0;
@@ -4634,7 +4638,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		rte_errno = ENOMEM;
 		goto error_before_flow;
 	}
-	flow->drv_type = flow_get_drv_type(dev, attr);
+	flow->drv_type = flow_get_drv_type(dev, &attr_factor);
 	if (hairpin_id != 0)
 		flow->hairpin_flow_id = hairpin_id;
 	MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4680,7 +4684,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		 * depending on configuration. In the simplest
 		 * case it just creates unmodified original flow.
 		 */
-		ret = flow_create_split_outer(dev, flow, attr,
+		ret = flow_create_split_outer(dev, flow, &attr_factor,
 					      buf->entry[i].pattern,
 					      p_actions_rx, external, idx,
 					      error);
@@ -4717,8 +4721,8 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	 * the egress Flows belong to the different device and
 	 * copy table should be updated in peer NIC Rx domain.
 	 */
-	if (attr->ingress &&
-	    (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
+	if (attr_factor.ingress &&
+	    (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
 		ret = flow_mreg_update_copy_table(dev, flow, actions, error);
 		if (ret)
 			goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
index 51826f8..99e900b 100644
@@ -372,6 +372,13 @@ enum mlx5_flow_fate_type {
 	MLX5_FLOW_FATE_MAX,
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /* Matcher PRM representation */
 struct mlx5_flow_dv_match_params {
 	size_t size;
@@ -604,13 +611,6 @@ struct mlx5_flow_handle {
 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
 #endif
 
-/*
- * Max number of actions per DV flow.
- * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
- * in rdma-core file providers/mlx5/verbs.c.
- */
-#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
-
 /** Device flow structure only for DV flow creation. */
 struct mlx5_flow_dv_workspace {
 	uint32_t group; /**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +485 -9

579 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Acked-by on v2 6/7
#70 lore raw

Re: [dpdk-dev] [PATCH v2 6/7] net/mlx5: update translate function for sample action

Hi Jiawei,

Quoted 9 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Subject: [PATCH v2 6/7] net/mlx5: update translate function for sample action

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---

Thanks,
Ori

#71 lore raw

PATCH v2 7/7 app/testpmd: add testpmd command for sample action

In reply to Jiawei Wang

Add a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>

The examples for the sample flow use case and result as below:

1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...

This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.

2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...

The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.

---
 app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
index 4e2006c..6b1e515 100644
@@ -56,6 +56,8 @@ enum index {
 	SET_RAW_ENCAP,
 	SET_RAW_DECAP,
 	SET_RAW_INDEX,
+	SET_SAMPLE_ACTIONS,
+	SET_SAMPLE_INDEX,
 
 	/* Top-level command. */
 	FLOW,
@@ -349,6 +351,10 @@ enum index {
 	ACTION_SET_IPV6_DSCP_VALUE,
 	ACTION_AGE,
 	ACTION_AGE_TIMEOUT,
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_SAMPLE_INDEX_VALUE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -484,6 +490,22 @@ struct action_nvgre_encap_data {
 
 struct mplsoudp_decap_conf mplsoudp_decap_conf;
 
+#define ACTION_SAMPLE_ACTIONS_NUM 10
+#define RAW_SAMPLE_CONFS_MAX_NUM 8
+/** Storage for struct rte_flow_action_sample including external data. */
+struct action_sample_data {
+	struct rte_flow_action_sample conf;
+	uint32_t idx;
+};
+/** Storage for struct rte_flow_action_sample. */
+struct raw_sample_conf {
+	struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
+};
+struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -1161,6 +1183,7 @@ struct parse_action_priv {
 	ACTION_SET_IPV4_DSCP,
 	ACTION_SET_IPV6_DSCP,
 	ACTION_AGE,
+	ACTION_SAMPLE,
 	ZERO,
 };
 
@@ -1393,9 +1416,28 @@ struct parse_action_priv {
 	ZERO,
 };
 
+static const enum index action_sample[] = {
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index next_action_sample[] = {
+	ACTION_QUEUE,
+	ACTION_MARK,
+	ACTION_COUNT,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
+static int parse_set_sample_action(struct context *, const struct token *,
+				   const char *, unsigned int,
+				   void *, unsigned int);
 static int parse_set_init(struct context *, const struct token *,
 			  const char *, unsigned int,
 			  void *, unsigned int);
@@ -1460,7 +1502,15 @@ static int parse_vc_action_raw_decap_index(struct context *,
 static int parse_vc_action_set_meta(struct context *ctx,
 				    const struct token *token, const char *str,
 				    unsigned int len, void *buf,
+					unsigned int size);
+static int parse_vc_action_sample(struct context *ctx,
+				    const struct token *token, const char *str,
+				    unsigned int len, void *buf,
 				    unsigned int size);
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
@@ -1531,6 +1581,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_set_raw_index(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_set_sample_index(struct context *, const struct token *,
+			      unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -3612,11 +3664,13 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
-		.help = "set raw encap/decap data",
-		.type = "set raw_encap|raw_decap <index> <pattern>",
+		.help = "set raw encap/decap/sample data",
+		.type = "set raw_encap|raw_decap <index> <pattern>"
+				" or set sample_actions <index> <action>",
 		.next = NEXT(NEXT_ENTRY
 			     (SET_RAW_ENCAP,
-			      SET_RAW_DECAP)),
+			      SET_RAW_DECAP,
+			      SET_SAMPLE_ACTIONS)),
 		.call = parse_set_init,
 	},
 	/* Sub-level commands. */
@@ -3647,6 +3701,23 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(next_item),
 		.call = parse_port,
 	},
+	[SET_SAMPLE_INDEX] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "index of sample actions",
+		.next = NEXT(next_action_sample),
+		.call = parse_port,
+	},
+	[SET_SAMPLE_ACTIONS] = {
+		.name = "sample_actions",
+		.help = "set sample actions list",
+		.next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
+		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
+				(offsetof(struct buffer, port),
+				 sizeof(((struct buffer *)0)->port),
+				 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
+		.call = parse_set_sample_action,
+	},
 	[ACTION_SET_TAG] = {
 		.name = "set_tag",
 		.help = "set tag",
@@ -3750,6 +3821,37 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SAMPLE] = {
+		.name = "sample",
+		.help = "set a sample action",
+		.next = NEXT(action_sample),
+		.priv = PRIV_ACTION(SAMPLE,
+			sizeof(struct action_sample_data)),
+		.call = parse_vc_action_sample,
+	},
+	[ACTION_SAMPLE_RATIO] = {
+		.name = "ratio",
+		.help = "flow sample ratio value",
+		.next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_sample_data, conf) +
+			      offsetof(struct rte_flow_action_sample, ratio),
+			      sizeof(((struct rte_flow_action_sample *)0)->
+				     ratio))),
+	},
+	[ACTION_SAMPLE_INDEX] = {
+		.name = "index",
+		.help = "the index of sample actions list",
+		.next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
+	},
+	[ACTION_SAMPLE_INDEX_VALUE] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "unsigned integer value",
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc_action_sample_index,
+		.comp = comp_set_sample_index,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
@@ -5207,6 +5309,76 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return len;
 }
 
+static int
+parse_vc_action_sample(struct context *ctx, const struct token *token,
+			 const char *str, unsigned int len, void *buf,
+			 unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_sample_data *action_sample_data = NULL;
+	static struct rte_flow_action end_action = {
+		RTE_FLOW_ACTION_TYPE_END, 0
+	};
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Copy the headers to the buffer. */
+	action_sample_data = ctx->object;
+	action_sample_data->conf.actions = &end_action;
+	action->conf = &action_sample_data->conf;
+	return ret;
+}
+
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size)
+{
+	struct action_sample_data *action_sample_data;
+	struct rte_flow_action *action;
+	const struct arg *arg;
+	struct buffer *out = buf;
+	int ret;
+	uint16_t idx;
+
+	RTE_SET_USED(token);
+	RTE_SET_USED(buf);
+	RTE_SET_USED(size);
+	if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
+		return -1;
+	arg = ARGS_ENTRY_ARB_BOUNDED
+		(offsetof(struct action_sample_data, idx),
+		 sizeof(((struct action_sample_data *)0)->idx),
+		 0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
+	if (push_args(ctx, arg))
+		return -1;
+	ret = parse_int(ctx, token, str, len, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		return -1;
+	}
+	if (!ctx->object)
+		return len;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	action_sample_data = ctx->object;
+	idx = action_sample_data->idx;
+	action_sample_data->conf.actions = raw_sample_confs[idx].data;
+	action->conf = &action_sample_data->conf;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
@@ -5971,6 +6143,38 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	if (!out->command)
 		return -1;
 	out->command = ctx->curr;
+	/* For encap/decap we need is pattern */
+	out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
+	return len;
+}
+
+/** Parse set command, initialize output buffer for subsequent tokens. */
+static int
+parse_set_sample_action(struct context *ctx, const struct token *token,
+			  const char *str, unsigned int len,
+			  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	/* Make sure buffer is large enough. */
+	if (size < sizeof(*out))
+		return -1;
+	ctx->objdata = 0;
+	ctx->objmask = NULL;
+	ctx->object = out;
+	if (!out->command)
+		return -1;
+	out->command = ctx->curr;
+	/* For sampler we need is actions */
+	out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	return len;
 }
 
@@ -6007,11 +6211,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 			return -1;
 		out->command = ctx->curr;
 		out->args.vc.data = (uint8_t *)out + size;
-		/* All we need is pattern */
-		out->args.vc.pattern =
-			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
-					       sizeof(double));
-		ctx->object = out->args.vc.pattern;
+		ctx->object  = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	}
 	return len;
 }
@@ -6162,6 +6363,24 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return nb;
 }
 
+/** Complete index number for set raw_encap/raw_decap commands. */
+static int
+comp_set_sample_index(struct context *ctx, const struct token *token,
+		   unsigned int ent, char *buf, unsigned int size)
+{
+	uint16_t idx = 0;
+	uint16_t nb = 0;
+
+	RTE_SET_USED(ctx);
+	RTE_SET_USED(token);
+	for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
+		if (buf && idx == ent)
+			return snprintf(buf, size, "%u", idx);
+		++nb;
+	}
+	return nb;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -6607,7 +6826,53 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return mask;
 }
 
-
+/** Dispatch parsed buffer to function calls. */
+static void
+cmd_set_raw_parsed_sample(const struct buffer *in)
+{
+	uint32_t n = in->args.vc.actions_n;
+	uint32_t i = 0;
+	struct rte_flow_action *action = NULL;
+	struct rte_flow_action *data = NULL;
+	size_t size = 0;
+	uint16_t idx = in->port; /* We borrow port field as index */
+	uint32_t max_size = sizeof(struct rte_flow_action) *
+						ACTION_SAMPLE_ACTIONS_NUM;
+
+	RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
+	data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
+	memset(data, 0x00, max_size);
+	for (; i <= n - 1; i++) {
+		action = in->args.vc.actions + i;
+		if (action->type == RTE_FLOW_ACTION_TYPE_END)
+			break;
+		switch (action->type) {
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			size = sizeof(struct rte_flow_action_mark);
+			rte_memcpy(&sample_mark[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_mark[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			size = sizeof(struct rte_flow_action_count);
+			rte_memcpy(&sample_count[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_count[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			size = sizeof(struct rte_flow_action_queue);
+			rte_memcpy(&sample_queue[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_queue[idx];
+			break;
+		default:
+			printf("Error - Not supported action\n");
+			return;
+		}
+		rte_memcpy(data, action, sizeof(struct rte_flow_action));
+		data++;
+	}
+}
 
 /** Dispatch parsed buffer to function calls. */
 static void
@@ -6624,6 +6889,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	uint16_t proto = 0;
 	uint16_t idx = in->port; /* We borrow port field as index */
 
+	if (in->command == SET_SAMPLE_ACTIONS)
+		return cmd_set_raw_parsed_sample(in);
 	RTE_ASSERT(in->command == SET_RAW_ENCAP ||
 		   in->command == SET_RAW_DECAP);
 	if (in->command == SET_RAW_ENCAP) {
Signature · 1 line
1.8.3.1
#72 lore raw

v3 cover support the flow-based traffic sampling

In reply to Jiawei Wang

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.

v3:
* Remove 'const' of ratio field.
* Update description and commit messages.

v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.

Jiawei Wang (7):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action

 app/test-pmd/cmdline_flow.c            | 285 ++++++++++++++-
 doc/guides/prog_guide/rte_flow.rst     |  25 ++
 doc/guides/rel_notes/release_20_08.rst |   6 +
 drivers/common/mlx5/Makefile           |   5 +
 drivers/common/mlx5/linux/meson.build  |   2 +
 drivers/common/mlx5/linux/mlx5_glue.c  |  15 +
 drivers/common/mlx5/linux/mlx5_glue.h  |  12 +
 drivers/common/mlx5/mlx5_devx_cmds.c   |  27 ++
 drivers/common/mlx5/mlx5_devx_cmds.h   |   1 +
 drivers/common/mlx5/mlx5_prm.h         |  51 +++
 drivers/net/mlx5/linux/mlx5_os.c       |  14 +
 drivers/net/mlx5/mlx5.c                |  11 +
 drivers/net/mlx5/mlx5.h                |   4 +
 drivers/net/mlx5/mlx5_flow.c           | 274 +++++++++++++-
 drivers/net/mlx5/mlx5_flow.h           |  51 ++-
 drivers/net/mlx5/mlx5_flow_dv.c        | 627 ++++++++++++++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c           |   1 +
 lib/librte_ethdev/rte_flow.h           |  30 ++
 18 files changed, 1406 insertions(+), 35 deletions(-)
Signature · 1 line
1.8.3.1
#73 lore raw

PATCH v3 1/7 ethdev: introduce sample action for rte flow

When using full offload, all traffic will be handled by the HW, and directed to the requested VF or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_08.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
index d5dd18c..e384d40 100644
@@ -2645,6 +2645,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated with the specified ``ratio`` and
+applied with own set of actions with a fate action, the packets sampled
+equals is '1/ratio'. All the packets continue to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets, and must have a fate action.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_08.rst +6 -0
index 5cbc4ce..87c719d 100644
@@ -81,6 +81,12 @@ New Features
   * Added support for virtio queue statistics.
   * Added support for MTU update.
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching
+  packets with specified ratio, and apply with own set of actions with a fate
+  action. When the ratio is set to 1 then the packets will be 100% mirrored.
+
 * **Updated Marvell octeontx2 ethdev PMD.**
 
   Updated Marvell octeontx2 driver with cn98xx support.
lib/librte_ethdev/rte_flow.c +1 -0
index 1685be5..733871d 100644
@@ -173,6 +173,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +30 -0
index b0e4199..e0d6264 100644
@@ -2099,6 +2099,14 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * The matching packets will be duplicated with specified ratio and
+	 * applied with own set of actions with a fate action.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2709,6 +2717,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated with specified ratio and applied
+ * with own set of actions with a fate action, the sampled packet could be
+ * redirected to queue or port. All the packets continue processing on the
+ * default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
Acked-by on v3 1/7
#74 lore raw

Re: [dpdk-dev] [PATCH v3 1/7] ethdev: introduce sample action for rte flow

Quoted 15 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested VF or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

Quoted 7 lines

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

#75 lore raw

PATCH v3 2/7 common/mlx5: glue for sample action

In reply to Jiawei Wang

rdma-core introduce a new DR sample action.

Add the rdma-core commands in glue to create this action.

Sample action is used for creating the sample object to implement the sampling/mirroring function.

---
 drivers/common/mlx5/Makefile          |  5 +++++
 drivers/common/mlx5/linux/meson.build |  2 ++
 drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 12 ++++++++++++
 4 files changed, 34 insertions(+)
drivers/common/mlx5/Makefile +5 -0
index f6c762b..4c1484c 100644
@@ -192,6 +192,11 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh
 		func mlx5dv_dump_dr_domain \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_flow_sampler \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_MLX5DV_MMAP_GET_NC_PAGES_CMD \
 		infiniband/mlx5dv.h \
 		enum MLX5_MMAP_GET_NC_PAGES_CMD \
drivers/common/mlx5/linux/meson.build +2 -0
index 2294213..0f08318 100644
@@ -162,6 +162,8 @@ has_sym_args = [
 	'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
 	[ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
 	'mlx5dv_dump_dr_domain'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_flow_sampler'],
 	[ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h',
 	'mlx5dv_dr_domain_set_reclaim_device_memory'],
 	[ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
index 048207e..98b3e71 100644
@@ -1059,6 +1059,19 @@
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_sampler(
+			struct mlx5dv_dr_flow_sampler_attr *attr)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+	return mlx5dv_dr_action_create_flow_sampler(attr);
+#else
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static int
 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
 			 uint32_t *eqn)
@@ -1308,6 +1321,8 @@
 	.devx_port_query = mlx5_glue_devx_port_query,
 	.dr_dump_domain = mlx5_glue_dr_dump_domain,
 	.dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
+	.dr_create_flow_action_sampler =
+		mlx5_glue_dr_create_flow_action_sampler,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
 	.devx_create_event_channel = mlx5_glue_devx_create_event_channel,
 	.devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +12 -0
index 069d854..11b95c5 100644
@@ -77,6 +77,7 @@
 #ifndef HAVE_MLX5DV_DR
 enum  mlx5dv_dr_domain_type { unused, };
 struct mlx5dv_dr_domain;
+struct mlx5dv_dr_action;
 #endif
 
 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,15 @@
 struct mlx5dv_dr_flow_meter_attr;
 #endif
 
+#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+struct mlx5dv_dr_flow_sampler_attr {
+	uint32_t sample_ratio;
+	void *default_next_table;
+	size_t num_sample_actions;
+	struct mlx5dv_dr_action **sample_actions;
+};
+#endif
+
 #ifndef HAVE_IBV_DEVX_EVENT
 struct mlx5dv_devx_event_channel { int fd; };
 struct mlx5dv_devx_async_event_hdr;
@@ -304,6 +314,8 @@ struct mlx5_glue {
 			 struct mlx5dv_devx_async_event_hdr *event_data,
 			 size_t event_resp_len);
 	void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
+	void *(*dr_create_flow_action_sampler)
+			(struct mlx5dv_dr_flow_sampler_attr *attr);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
#76 lore raw

PATCH v3 3/7 common/mlx5: query sampler object capability via DevX

In reply to Jiawei Wang

Update function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.

Add the related structs definition in mlx5_prm.h.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++
 drivers/common/mlx5/mlx5_devx_cmds.h |  1 +
 drivers/common/mlx5/mlx5_prm.h       | 51 ++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
index ec92eb6..6b551f1 100644
@@ -496,6 +496,33 @@ struct mlx5_devx_obj *
 	if (!attr->eth_net_offloads)
 		return 0;
 
+	/* Query Flow Sampler Capabilitiy From FLow Table Properties Layout. */
+	memset(in, 0, sizeof(in));
+	memset(out, 0, sizeof(out));
+	MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
+	MLX5_SET(query_hca_cap_in, in, op_mod,
+		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
+		 MLX5_HCA_CAP_OPMOD_GET_CUR);
+
+	rc = mlx5_glue->devx_general_cmd(ctx,
+					 in, sizeof(in),
+					 out, sizeof(out));
+	if (rc)
+		goto error;
+	status = MLX5_GET(query_hca_cap_out, out, status);
+	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
+	if (status) {
+		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
+			"status %x, syndrome = %x",
+			status, syndrome);
+		attr->log_max_ft_sampler_num = 0;
+		return -1;
+	}
+	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
+	attr->log_max_ft_sampler_num =
+			MLX5_GET(flow_table_nic_cap,
+			hcattr, flow_table_properties.log_max_ft_sampler_num);
+
 	/* Query HCA offloads for Ethernet protocol. */
 	memset(in, 0, sizeof(in));
 	memset(out, 0, sizeof(out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
index 25704ef..a9cfe6d 100644
@@ -90,6 +90,7 @@ struct mlx5_hca_attr {
 	uint32_t vhca_id:16;
 	uint32_t relaxed_ordering_write:1;
 	uint32_t relaxed_ordering_read:1;
+	uint32_t log_max_ft_sampler_num:8;
 	struct mlx5_hca_qos_attr qos;
 	struct mlx5_hca_vdpa_attr vdpa;
 };
drivers/common/mlx5/mlx5_prm.h +51 -0

69 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#77 lore raw

PATCH v3 4/7 net/mlx5: add the validate sample action

In reply to Jiawei Wang

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX.

Only NIC_RX support with addition optional actions. FDB doesn't support any optional action, the sampled packets is always goes to e-switch manager port.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 133 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
index 2dc57b2..6dfacf2 100644
@@ -878,6 +878,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config.hca_attr.log_max_ft_sampler_num > 0  &&
+		    config.dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config.hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register for"
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not supported!\n");
+		}
+#endif
 	}
 	if (config.mprq.enabled && mprq) {
 		if (config.mprq.stride_num_n &&
drivers/net/mlx5/mlx5.h +1 -0
index 46e66eb..6790738 100644
@@ -617,6 +617,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management. */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
index 43cbda8..45a073c 100644
@@ -202,6 +202,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35)
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +133 -0

145 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#78 lore raw

PATCH v3 5/7 net/mlx5: split sample flow into two sub flows

In reply to Jiawei Wang

Add the sampler action resource structs definition.

The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.

For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.

---
 drivers/net/mlx5/mlx5.c      |  11 ++
 drivers/net/mlx5/mlx5.h      |   3 +
 drivers/net/mlx5/mlx5_flow.c | 258 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h |  36 ++++++
 4 files changed, 304 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
index 07c6add..db55545 100644
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		.free = rte_free,
 		.type = "mlx5_jump_ipool",
 	},
+	{
+		.size = sizeof(struct mlx5_flow_dv_sample_resource),
+		.trunk_size = 64,
+		.grow_trunk = 3,
+		.grow_shift = 2,
+		.need_lock = 0,
+		.release_mem_en = 1,
+		.malloc = rte_malloc_socket,
+		.free = rte_free,
+		.type = "mlx5_sample_ipool",
+	},
 #endif
 	{
 		.size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
index 6790738..756bd68 100644
@@ -51,6 +51,7 @@ enum mlx5_ipool_index {
 	MLX5_IPOOL_TAG, /* Pool for tag resource. */
 	MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
 	MLX5_IPOOL_JUMP, /* Pool for jump resource. */
+	MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */
 #endif
 	MLX5_IPOOL_MTR, /* Pool for meter resource. */
 	MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -518,6 +519,7 @@ struct mlx5_flow_tbl_resource {
 /* Tables for metering splits should be added here. */
 #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)
 #define MLX5_MAX_TABLES_FDB UINT16_MAX
+#define MLX5_FLOW_TABLE_FACTOR 10
 
 /* ID generation structure. */
 struct mlx5_flow_id_pool {
@@ -566,6 +568,7 @@ struct mlx5_dev_ctx_shared {
 	struct mlx5_hlist *tag_table;
 	uint32_t port_id_action_list; /* List of port ID actions. */
 	uint32_t push_vlan_action_list; /* List of push VLAN actions. */
+	uint32_t sample_action_list; /* List of sample actions. */
 	struct mlx5_flow_counter_mng cmng; /* Counters management structure. */
 	struct mlx5_flow_default_miss_resource default_miss;
 	/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +254 -4

294 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +36 -0
index 45a073c..51826f8 100644
@@ -502,6 +502,38 @@ struct mlx5_flow_tbl_data_entry {
 	uint32_t idx; /**< index for the indexed mempool. */
 };
 
+/* Sub rdma-core actions list. */
+struct mlx5_flow_sub_actions_list {
+	uint32_t actions_num; /**< Number of sample actions. */
+	uint64_t action_flags;
+	void *dr_queue_action;
+	void *dr_tag_action;
+	void *dr_cnt_action;
+};
+
+/* Sample sub-actions resource list. */
+struct mlx5_flow_sub_actions_idx {
+	uint32_t rix_hrxq; /**< Hash Rx queue object index. */
+	uint32_t rix_tag; /**< Index to the tag action. */
+	uint32_t cnt;
+};
+
+/* Sample action resource structure. */
+struct mlx5_flow_dv_sample_resource {
+	ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
+	rte_atomic32_t refcnt; /**< Reference counter. */
+	void *verbs_action; /**< Verbs sample action object. */
+	uint8_t ft_type; /** Flow Table Type */
+	uint32_t ft_id; /** Flow Table Level */
+	void *normal_path_tbl; /** Flow Table pointer */
+	void *default_miss; /** default_miss dr_action. */
+	uint32_t ratio;   /** Sample Ratio */
+	struct mlx5_flow_sub_actions_idx sample_idx;
+	/**< Action index resources. */
+	struct mlx5_flow_sub_actions_list sample_act;
+	/**< Action resources. */
+};
+
 /* Verbs specification header. */
 struct ibv_spec_header {
 	enum ibv_flow_spec_type type;
@@ -530,6 +562,8 @@ struct mlx5_flow_handle_dv {
 	/**< Index to push VLAN action resource in cache. */
 	uint32_t rix_tag;
 	/**< Index to the tag action. */
+	uint32_t rix_sample;
+	/**< Index to sample action resource in cache. */
 } __rte_packed;
 
 /** Device flow handle structure: used both for creating & destroying. */
@@ -595,6 +629,8 @@ struct mlx5_flow_dv_workspace {
 	/**< Pointer to the jump action resource. */
 	struct mlx5_flow_dv_match_params value;
 	/**< Holds the value that the packet is compared to. */
+	struct mlx5_flow_dv_sample_resource *sample_res;
+	/**< Pointer to the sample action resource. */
 };
 
 /*
Signature · 1 line
1.8.3.1
#79 lore raw

PATCH v3 6/7 net/mlx5: update translate function for sample action

In reply to Jiawei Wang

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---
 drivers/net/mlx5/mlx5_flow.c    |  16 +-
 drivers/net/mlx5/mlx5_flow.h    |  14 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 494 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 502 insertions(+), 22 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
index 7ed9ba3..c91ae7d 100644
@@ -4612,10 +4612,14 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	int hairpin_flow;
 	uint32_t hairpin_id = 0;
 	struct rte_flow_attr attr_tx = { .priority = 0 };
+	struct rte_flow_attr attr_factor = {0};
 	int ret;
 
-	hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
-	ret = flow_drv_validate(dev, attr, items, p_actions_rx,
+	memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
+	if (external)
+		attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
+	hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
+	ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
 				external, hairpin_flow, error);
 	if (ret < 0)
 		return 0;
@@ -4634,7 +4638,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		rte_errno = ENOMEM;
 		goto error_before_flow;
 	}
-	flow->drv_type = flow_get_drv_type(dev, attr);
+	flow->drv_type = flow_get_drv_type(dev, &attr_factor);
 	if (hairpin_id != 0)
 		flow->hairpin_flow_id = hairpin_id;
 	MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4680,7 +4684,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 		 * depending on configuration. In the simplest
 		 * case it just creates unmodified original flow.
 		 */
-		ret = flow_create_split_outer(dev, flow, attr,
+		ret = flow_create_split_outer(dev, flow, &attr_factor,
 					      buf->entry[i].pattern,
 					      p_actions_rx, external, idx,
 					      error);
@@ -4717,8 +4721,8 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
 	 * the egress Flows belong to the different device and
 	 * copy table should be updated in peer NIC Rx domain.
 	 */
-	if (attr->ingress &&
-	    (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
+	if (attr_factor.ingress &&
+	    (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
 		ret = flow_mreg_update_copy_table(dev, flow, actions, error);
 		if (ret)
 			goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
index 51826f8..99e900b 100644
@@ -372,6 +372,13 @@ enum mlx5_flow_fate_type {
 	MLX5_FLOW_FATE_MAX,
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /* Matcher PRM representation */
 struct mlx5_flow_dv_match_params {
 	size_t size;
@@ -604,13 +611,6 @@ struct mlx5_flow_handle {
 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
 #endif
 
-/*
- * Max number of actions per DV flow.
- * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
- * in rdma-core file providers/mlx5/verbs.c.
- */
-#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
-
 /** Device flow structure only for DV flow creation. */
 struct mlx5_flow_dv_workspace {
 	uint32_t group; /**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +485 -9

579 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#80 lore raw

PATCH v3 7/7 app/testpmd: add testpmd command for sample action

In reply to Jiawei Wang

Add a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>

The examples for the sample flow use case and result as below:

1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...

This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.

2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...

The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.

---
 app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
index 4e2006c..6b1e515 100644
@@ -56,6 +56,8 @@ enum index {
 	SET_RAW_ENCAP,
 	SET_RAW_DECAP,
 	SET_RAW_INDEX,
+	SET_SAMPLE_ACTIONS,
+	SET_SAMPLE_INDEX,
 
 	/* Top-level command. */
 	FLOW,
@@ -349,6 +351,10 @@ enum index {
 	ACTION_SET_IPV6_DSCP_VALUE,
 	ACTION_AGE,
 	ACTION_AGE_TIMEOUT,
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_SAMPLE_INDEX_VALUE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -484,6 +490,22 @@ struct action_nvgre_encap_data {
 
 struct mplsoudp_decap_conf mplsoudp_decap_conf;
 
+#define ACTION_SAMPLE_ACTIONS_NUM 10
+#define RAW_SAMPLE_CONFS_MAX_NUM 8
+/** Storage for struct rte_flow_action_sample including external data. */
+struct action_sample_data {
+	struct rte_flow_action_sample conf;
+	uint32_t idx;
+};
+/** Storage for struct rte_flow_action_sample. */
+struct raw_sample_conf {
+	struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
+};
+struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -1161,6 +1183,7 @@ struct parse_action_priv {
 	ACTION_SET_IPV4_DSCP,
 	ACTION_SET_IPV6_DSCP,
 	ACTION_AGE,
+	ACTION_SAMPLE,
 	ZERO,
 };
 
@@ -1393,9 +1416,28 @@ struct parse_action_priv {
 	ZERO,
 };
 
+static const enum index action_sample[] = {
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index next_action_sample[] = {
+	ACTION_QUEUE,
+	ACTION_MARK,
+	ACTION_COUNT,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
+static int parse_set_sample_action(struct context *, const struct token *,
+				   const char *, unsigned int,
+				   void *, unsigned int);
 static int parse_set_init(struct context *, const struct token *,
 			  const char *, unsigned int,
 			  void *, unsigned int);
@@ -1460,7 +1502,15 @@ static int parse_vc_action_raw_decap_index(struct context *,
 static int parse_vc_action_set_meta(struct context *ctx,
 				    const struct token *token, const char *str,
 				    unsigned int len, void *buf,
+					unsigned int size);
+static int parse_vc_action_sample(struct context *ctx,
+				    const struct token *token, const char *str,
+				    unsigned int len, void *buf,
 				    unsigned int size);
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
@@ -1531,6 +1581,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_set_raw_index(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_set_sample_index(struct context *, const struct token *,
+			      unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -3612,11 +3664,13 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
-		.help = "set raw encap/decap data",
-		.type = "set raw_encap|raw_decap <index> <pattern>",
+		.help = "set raw encap/decap/sample data",
+		.type = "set raw_encap|raw_decap <index> <pattern>"
+				" or set sample_actions <index> <action>",
 		.next = NEXT(NEXT_ENTRY
 			     (SET_RAW_ENCAP,
-			      SET_RAW_DECAP)),
+			      SET_RAW_DECAP,
+			      SET_SAMPLE_ACTIONS)),
 		.call = parse_set_init,
 	},
 	/* Sub-level commands. */
@@ -3647,6 +3701,23 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(next_item),
 		.call = parse_port,
 	},
+	[SET_SAMPLE_INDEX] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "index of sample actions",
+		.next = NEXT(next_action_sample),
+		.call = parse_port,
+	},
+	[SET_SAMPLE_ACTIONS] = {
+		.name = "sample_actions",
+		.help = "set sample actions list",
+		.next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
+		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
+				(offsetof(struct buffer, port),
+				 sizeof(((struct buffer *)0)->port),
+				 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
+		.call = parse_set_sample_action,
+	},
 	[ACTION_SET_TAG] = {
 		.name = "set_tag",
 		.help = "set tag",
@@ -3750,6 +3821,37 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SAMPLE] = {
+		.name = "sample",
+		.help = "set a sample action",
+		.next = NEXT(action_sample),
+		.priv = PRIV_ACTION(SAMPLE,
+			sizeof(struct action_sample_data)),
+		.call = parse_vc_action_sample,
+	},
+	[ACTION_SAMPLE_RATIO] = {
+		.name = "ratio",
+		.help = "flow sample ratio value",
+		.next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_sample_data, conf) +
+			      offsetof(struct rte_flow_action_sample, ratio),
+			      sizeof(((struct rte_flow_action_sample *)0)->
+				     ratio))),
+	},
+	[ACTION_SAMPLE_INDEX] = {
+		.name = "index",
+		.help = "the index of sample actions list",
+		.next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
+	},
+	[ACTION_SAMPLE_INDEX_VALUE] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "unsigned integer value",
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc_action_sample_index,
+		.comp = comp_set_sample_index,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
@@ -5207,6 +5309,76 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return len;
 }
 
+static int
+parse_vc_action_sample(struct context *ctx, const struct token *token,
+			 const char *str, unsigned int len, void *buf,
+			 unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_sample_data *action_sample_data = NULL;
+	static struct rte_flow_action end_action = {
+		RTE_FLOW_ACTION_TYPE_END, 0
+	};
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Copy the headers to the buffer. */
+	action_sample_data = ctx->object;
+	action_sample_data->conf.actions = &end_action;
+	action->conf = &action_sample_data->conf;
+	return ret;
+}
+
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size)
+{
+	struct action_sample_data *action_sample_data;
+	struct rte_flow_action *action;
+	const struct arg *arg;
+	struct buffer *out = buf;
+	int ret;
+	uint16_t idx;
+
+	RTE_SET_USED(token);
+	RTE_SET_USED(buf);
+	RTE_SET_USED(size);
+	if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
+		return -1;
+	arg = ARGS_ENTRY_ARB_BOUNDED
+		(offsetof(struct action_sample_data, idx),
+		 sizeof(((struct action_sample_data *)0)->idx),
+		 0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
+	if (push_args(ctx, arg))
+		return -1;
+	ret = parse_int(ctx, token, str, len, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		return -1;
+	}
+	if (!ctx->object)
+		return len;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	action_sample_data = ctx->object;
+	idx = action_sample_data->idx;
+	action_sample_data->conf.actions = raw_sample_confs[idx].data;
+	action->conf = &action_sample_data->conf;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
@@ -5971,6 +6143,38 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	if (!out->command)
 		return -1;
 	out->command = ctx->curr;
+	/* For encap/decap we need is pattern */
+	out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
+	return len;
+}
+
+/** Parse set command, initialize output buffer for subsequent tokens. */
+static int
+parse_set_sample_action(struct context *ctx, const struct token *token,
+			  const char *str, unsigned int len,
+			  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	/* Make sure buffer is large enough. */
+	if (size < sizeof(*out))
+		return -1;
+	ctx->objdata = 0;
+	ctx->objmask = NULL;
+	ctx->object = out;
+	if (!out->command)
+		return -1;
+	out->command = ctx->curr;
+	/* For sampler we need is actions */
+	out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	return len;
 }
 
@@ -6007,11 +6211,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 			return -1;
 		out->command = ctx->curr;
 		out->args.vc.data = (uint8_t *)out + size;
-		/* All we need is pattern */
-		out->args.vc.pattern =
-			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
-					       sizeof(double));
-		ctx->object = out->args.vc.pattern;
+		ctx->object  = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	}
 	return len;
 }
@@ -6162,6 +6363,24 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return nb;
 }
 
+/** Complete index number for set raw_encap/raw_decap commands. */
+static int
+comp_set_sample_index(struct context *ctx, const struct token *token,
+		   unsigned int ent, char *buf, unsigned int size)
+{
+	uint16_t idx = 0;
+	uint16_t nb = 0;
+
+	RTE_SET_USED(ctx);
+	RTE_SET_USED(token);
+	for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
+		if (buf && idx == ent)
+			return snprintf(buf, size, "%u", idx);
+		++nb;
+	}
+	return nb;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -6607,7 +6826,53 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return mask;
 }
 
-
+/** Dispatch parsed buffer to function calls. */
+static void
+cmd_set_raw_parsed_sample(const struct buffer *in)
+{
+	uint32_t n = in->args.vc.actions_n;
+	uint32_t i = 0;
+	struct rte_flow_action *action = NULL;
+	struct rte_flow_action *data = NULL;
+	size_t size = 0;
+	uint16_t idx = in->port; /* We borrow port field as index */
+	uint32_t max_size = sizeof(struct rte_flow_action) *
+						ACTION_SAMPLE_ACTIONS_NUM;
+
+	RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
+	data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
+	memset(data, 0x00, max_size);
+	for (; i <= n - 1; i++) {
+		action = in->args.vc.actions + i;
+		if (action->type == RTE_FLOW_ACTION_TYPE_END)
+			break;
+		switch (action->type) {
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			size = sizeof(struct rte_flow_action_mark);
+			rte_memcpy(&sample_mark[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_mark[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			size = sizeof(struct rte_flow_action_count);
+			rte_memcpy(&sample_count[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_count[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			size = sizeof(struct rte_flow_action_queue);
+			rte_memcpy(&sample_queue[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_queue[idx];
+			break;
+		default:
+			printf("Error - Not supported action\n");
+			return;
+		}
+		rte_memcpy(data, action, sizeof(struct rte_flow_action));
+		data++;
+	}
+}
 
 /** Dispatch parsed buffer to function calls. */
 static void
@@ -6624,6 +6889,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	uint16_t proto = 0;
 	uint16_t idx = in->port; /* We borrow port field as index */
 
+	if (in->command == SET_SAMPLE_ACTIONS)
+		return cmd_set_raw_parsed_sample(in);
 	RTE_ASSERT(in->command == SET_RAW_ENCAP ||
 		   in->command == SET_RAW_DECAP);
 	if (in->command == SET_RAW_ENCAP) {
Signature · 1 line
1.8.3.1
#81 lore raw
In reply to Jiawei Wang
Quoted 8 lines · On Mon, 6 Jul 2020 20:51:01 +0300 Jiawei Wang <[email protected]> wrote:

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.

You seem to have ignored my feedback that this could be more useful if it didn't just support duplication. It should allow sampling and then make the other rule chain (the one that gets hit after sampling) run.

By allowing a more general form of sampling it could be used for doing network emulation (or packet manipulation) as well as simple netflow/ipfix style sampling.

#82 lore raw

Hi Stephen,

Quoted 21 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v3 0/7] support the flow-based traffic sampling

Quoted 3 lines · On Mon, 6 Jul 2020 20:51:01 +0300 Jiawei Wang <[email protected]> wrote:

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the

incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

Quoted 2 lines

If the sample ratio value be set to 1, means that the packets would be

completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

Quoted 2 lines

MLX5 PMD driver will be responsible for validate and translate the sample

action while creating a flow.

Quoted 1 line
Quoted 8 lines

You seem to have ignored my feedback that this could be more useful if it didn't just support duplication. It should allow sampling and then make the other rule chain (the one that gets hit after sampling) run.

By allowing a more general form of sampling it could be used for doing network emulation (or packet manipulation) as well as simple netflow/ipfix style sampling.

What is network emulation?
I think that what you are suggesting is a different feature. There is high penalty for rules duplication, like I stated in my previous reply.
As I can see there is no plan at least in Mellanox to support this kind of feature you are suggesting, Since this API in any case is experimental. I suggest that when the need comes or some other vendor will wish to implement such a feature we
can ether update the API or create a new one.
What do you think?

Best,
Ori

#83 lore raw

v4 cover support the flow-based traffic sampling

In reply to Jiawei Wang

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.

v4:
* Rebase.
* Fix the coding style issue.

v3:
* Remove 'const' of ratio field.
* Update description and commit messages.

v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.

Jiawei Wang (7):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action

 app/test-pmd/cmdline_flow.c           | 285 +++++++++++++++-
 doc/guides/prog_guide/rte_flow.rst    |  25 ++
 drivers/common/mlx5/Makefile          |   5 +
 drivers/common/mlx5/linux/meson.build |   2 +
 drivers/common/mlx5/linux/mlx5_glue.c |  15 +
 drivers/common/mlx5/linux/mlx5_glue.h |  12 +
 drivers/common/mlx5/mlx5_devx_cmds.c  |  27 ++
 drivers/common/mlx5/mlx5_devx_cmds.h  |   1 +
 drivers/common/mlx5/mlx5_prm.h        |  51 +++
 drivers/net/mlx5/linux/mlx5_os.c      |  14 +
 drivers/net/mlx5/mlx5.c               |  11 +
 drivers/net/mlx5/mlx5.h               |   4 +
 drivers/net/mlx5/mlx5_flow.c          | 274 ++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h          |  51 ++-
 drivers/net/mlx5/mlx5_flow_dv.c       | 627 +++++++++++++++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c          |   1 +
 lib/librte_ethdev/rte_flow.h          |  30 ++
 17 files changed, 1400 insertions(+), 35 deletions(-)
Signature · 1 line
1.8.3.1
#84 lore raw

PATCH v4 1/7 ethdev: introduce sample action for rte flow

When using full offload, all traffic will be handled by the HW, and directed to the requested VF or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst | 25 +++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  1 +
 lib/librte_ethdev/rte_flow.h       | 30 ++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
index 3e5cd1e..f8f3f51 100644
@@ -2653,6 +2653,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated with the specified ``ratio`` and
+applied with own set of actions with a fate action, the packets sampled
+equals is '1/ratio'. All the packets continue to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets, and must have a fate action.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
lib/librte_ethdev/rte_flow.c +1 -0
index f8fdd68..035671d 100644
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +30 -0
index da8bfa5..fa70d40 100644
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * The matching packets will be duplicated with specified ratio and
+	 * applied with own set of actions with a fate action.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated with specified ratio and applied
+ * with own set of actions with a fate action, the sampled packet could be
+ * redirected to queue or port. All the packets continue processing on the
+ * default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
#85 lore raw

PATCH v4 2/7 common/mlx5: glue for sample action

In reply to Jiawei Wang

rdma-core introduce a new DR sample action.

Add the rdma-core commands in glue to create this action.

Sample action is used for creating the sample object to implement the sampling/mirroring function.

---
 drivers/common/mlx5/Makefile          |  5 +++++
 drivers/common/mlx5/linux/meson.build |  2 ++
 drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 12 ++++++++++++
 4 files changed, 34 insertions(+)
drivers/common/mlx5/Makefile +5 -0
index 4edd541..24b932c 100644
@@ -205,6 +205,11 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh
 		func mlx5dv_dump_dr_domain \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE \
+		infiniband/mlx5dv.h \
+		func mlx5dv_dr_action_create_flow_sampler \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_MLX5DV_MMAP_GET_NC_PAGES_CMD \
 		infiniband/mlx5dv.h \
 		enum MLX5_MMAP_GET_NC_PAGES_CMD \
drivers/common/mlx5/linux/meson.build +2 -0
index 48e8ad6..1aa137d 100644
@@ -172,6 +172,8 @@ has_sym_args = [
 	'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
 	[ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
 	'mlx5dv_dump_dr_domain'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_flow_sampler'],
 	[ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h',
 	'mlx5dv_dr_domain_set_reclaim_device_memory'],
 	[ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
index fcf03e8..771a47c 100644
@@ -1063,6 +1063,19 @@
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_sampler(
+			struct mlx5dv_dr_flow_sampler_attr *attr)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+	return mlx5dv_dr_action_create_flow_sampler(attr);
+#else
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static int
 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
 			 uint32_t *eqn)
@@ -1339,6 +1352,8 @@
 	.devx_port_query = mlx5_glue_devx_port_query,
 	.dr_dump_domain = mlx5_glue_dr_dump_domain,
 	.dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
+	.dr_create_flow_action_sampler =
+		mlx5_glue_dr_create_flow_action_sampler,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
 	.devx_create_event_channel = mlx5_glue_devx_create_event_channel,
 	.devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +12 -0
index 734ace2..85b43b9 100644
@@ -77,6 +77,7 @@
 #ifndef HAVE_MLX5DV_DR
 enum  mlx5dv_dr_domain_type { unused, };
 struct mlx5dv_dr_domain;
+struct mlx5dv_dr_action;
 #endif
 
 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,15 @@
 struct mlx5dv_dr_flow_meter_attr;
 #endif
 
+#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+struct mlx5dv_dr_flow_sampler_attr {
+	uint32_t sample_ratio;
+	void *default_next_table;
+	size_t num_sample_actions;
+	struct mlx5dv_dr_action **sample_actions;
+};
+#endif
+
 #ifndef HAVE_IBV_DEVX_EVENT
 struct mlx5dv_devx_event_channel { int fd; };
 struct mlx5dv_devx_async_event_hdr;
@@ -309,6 +319,8 @@ struct mlx5_glue {
 					 const void *pp_context,
 					 uint32_t flags);
 	void (*dv_free_pp)(struct mlx5dv_pp *pp);
+	void *(*dr_create_flow_action_sampler)
+			(struct mlx5dv_dr_flow_sampler_attr *attr);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
#86 lore raw

PATCH v4 3/7 common/mlx5: query sampler object capability via DevX

In reply to Jiawei Wang

Update function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.

Add the related structs definition in mlx5_prm.h.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++
 drivers/common/mlx5/mlx5_devx_cmds.h |  1 +
 drivers/common/mlx5/mlx5_prm.h       | 51 ++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
index 7c81ae1..fd4e3f2 100644
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *
 	if (!attr->eth_net_offloads)
 		return 0;
 
+	/* Query Flow Sampler Capability From FLow Table Properties Layout. */
+	memset(in, 0, sizeof(in));
+	memset(out, 0, sizeof(out));
+	MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
+	MLX5_SET(query_hca_cap_in, in, op_mod,
+		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
+		 MLX5_HCA_CAP_OPMOD_GET_CUR);
+
+	rc = mlx5_glue->devx_general_cmd(ctx,
+					 in, sizeof(in),
+					 out, sizeof(out));
+	if (rc)
+		goto error;
+	status = MLX5_GET(query_hca_cap_out, out, status);
+	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
+	if (status) {
+		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
+			"status %x, syndrome = %x",
+			status, syndrome);
+		attr->log_max_ft_sampler_num = 0;
+		return -1;
+	}
+	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
+	attr->log_max_ft_sampler_num =
+			MLX5_GET(flow_table_nic_cap,
+			hcattr, flow_table_properties.log_max_ft_sampler_num);
+
 	/* Query HCA offloads for Ethernet protocol. */
 	memset(in, 0, sizeof(in));
 	memset(out, 0, sizeof(out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
index 1c84cea..cfa7a7b 100644
@@ -102,6 +102,7 @@ struct mlx5_hca_attr {
 	uint32_t scatter_fcs_w_decap_disable:1;
 	uint32_t regex:1;
 	uint32_t regexp_num_of_engines;
+	uint32_t log_max_ft_sampler_num:8;
 	struct mlx5_hca_qos_attr qos;
 	struct mlx5_hca_vdpa_attr vdpa;
 };
drivers/common/mlx5/mlx5_prm.h +51 -0

69 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#87 lore raw

PATCH v4 4/7 net/mlx5: add the validate sample action

In reply to Jiawei Wang

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX.

Only NIC_RX support with addition optional actions. FDB doesn't support any optional action, the sampled packets is always goes to e-switch manager port.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 133 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
index db955ae..5b663a1 100644
@@ -1015,6 +1015,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config->hca_attr.log_max_ft_sampler_num > 0  &&
+		    config->dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config->hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register for"
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not supported!\n");
+		}
+#endif
 	}
 	if (config->tx_pp) {
 		DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
index 1880a82..ae0c7cc 100644
@@ -698,6 +698,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management. */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
index 92301e4..41404de 100644
@@ -196,6 +196,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35)
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +133 -0

145 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#88 lore raw

PATCH v4 5/7 net/mlx5: split sample flow into two sub flows

In reply to Jiawei Wang

Add the sampler action resource structs definition.

The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.

For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.

---
 drivers/net/mlx5/mlx5.c      |  11 ++
 drivers/net/mlx5/mlx5.h      |   3 +
 drivers/net/mlx5/mlx5_flow.c | 258 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h |  36 ++++++
 4 files changed, 304 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
index 1e4c695..7b33a3e 100644
@@ -244,6 +244,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
 		.free = mlx5_free,
 		.type = "mlx5_jump_ipool",
 	},
+	{
+		.size = sizeof(struct mlx5_flow_dv_sample_resource),
+		.trunk_size = 64,
+		.grow_trunk = 3,
+		.grow_shift = 2,
+		.need_lock = 0,
+		.release_mem_en = 1,
+		.malloc = mlx5_malloc,
+		.free = mlx5_free,
+		.type = "mlx5_sample_ipool",
+	},
 #endif
 	{
 		.size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
index ae0c7cc..a76c161 100644
@@ -41,6 +41,7 @@ enum mlx5_ipool_index {
 	MLX5_IPOOL_TAG, /* Pool for tag resource. */
 	MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
 	MLX5_IPOOL_JUMP, /* Pool for jump resource. */
+	MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */
 #endif
 	MLX5_IPOOL_MTR, /* Pool for meter resource. */
 	MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -514,6 +515,7 @@ struct mlx5_flow_tbl_resource {
 /* Tables for metering splits should be added here. */
 #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)
 #define MLX5_MAX_TABLES_FDB UINT16_MAX
+#define MLX5_FLOW_TABLE_FACTOR 10
 
 /* ID generation structure. */
 struct mlx5_flow_id_pool {
@@ -642,6 +644,7 @@ struct mlx5_dev_ctx_shared {
 	struct mlx5_hlist *tag_table;
 	uint32_t port_id_action_list; /* List of port ID actions. */
 	uint32_t push_vlan_action_list; /* List of push VLAN actions. */
+	uint32_t sample_action_list; /* List of sample actions. */
 	struct mlx5_flow_counter_mng cmng; /* Counters management structure. */
 	struct mlx5_flow_default_miss_resource default_miss;
 	/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +254 -4

294 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +36 -0
index 41404de..9d2493a 100644
@@ -507,6 +507,38 @@ struct mlx5_flow_tbl_data_entry {
 	uint32_t idx; /**< index for the indexed mempool. */
 };
 
+/* Sub rdma-core actions list. */
+struct mlx5_flow_sub_actions_list {
+	uint32_t actions_num; /**< Number of sample actions. */
+	uint64_t action_flags;
+	void *dr_queue_action;
+	void *dr_tag_action;
+	void *dr_cnt_action;
+};
+
+/* Sample sub-actions resource list. */
+struct mlx5_flow_sub_actions_idx {
+	uint32_t rix_hrxq; /**< Hash Rx queue object index. */
+	uint32_t rix_tag; /**< Index to the tag action. */
+	uint32_t cnt;
+};
+
+/* Sample action resource structure. */
+struct mlx5_flow_dv_sample_resource {
+	ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
+	rte_atomic32_t refcnt; /**< Reference counter. */
+	void *verbs_action; /**< Verbs sample action object. */
+	uint8_t ft_type; /** Flow Table Type */
+	uint32_t ft_id; /** Flow Table Level */
+	void *normal_path_tbl; /** Flow Table pointer */
+	void *default_miss; /** default_miss dr_action. */
+	uint32_t ratio;   /** Sample Ratio */
+	struct mlx5_flow_sub_actions_idx sample_idx;
+	/**< Action index resources. */
+	struct mlx5_flow_sub_actions_list sample_act;
+	/**< Action resources. */
+};
+
 /* Verbs specification header. */
 struct ibv_spec_header {
 	enum ibv_flow_spec_type type;
@@ -539,6 +571,8 @@ struct mlx5_flow_handle_dv {
 	/**< Index to push VLAN action resource in cache. */
 	uint32_t rix_tag;
 	/**< Index to the tag action. */
+	uint32_t rix_sample;
+	/**< Index to sample action resource in cache. */
 } __rte_packed;
 
 /** Device flow handle structure: used both for creating & destroying. */
@@ -604,6 +638,8 @@ struct mlx5_flow_dv_workspace {
 	/**< Pointer to the jump action resource. */
 	struct mlx5_flow_dv_match_params value;
 	/**< Holds the value that the packet is compared to. */
+	struct mlx5_flow_dv_sample_resource *sample_res;
+	/**< Pointer to the sample action resource. */
 };
 
 /*
Signature · 1 line
1.8.3.1
#89 lore raw

PATCH v4 6/7 net/mlx5: update translate function for sample action

In reply to Jiawei Wang

Translate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.

---
 drivers/net/mlx5/mlx5_flow.c    |  16 +-
 drivers/net/mlx5/mlx5_flow.h    |  14 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 494 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 502 insertions(+), 22 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
index 49f49e7..d2b79f0 100644
@@ -4606,10 +4606,14 @@ struct mlx5_flow_tunnel_info {
 	int hairpin_flow;
 	uint32_t hairpin_id = 0;
 	struct rte_flow_attr attr_tx = { .priority = 0 };
+	struct rte_flow_attr attr_factor = {0};
 	int ret;
 
-	hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
-	ret = flow_drv_validate(dev, attr, items, p_actions_rx,
+	memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
+	if (external)
+		attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
+	hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
+	ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
 				external, hairpin_flow, error);
 	if (ret < 0)
 		return 0;
@@ -4628,7 +4632,7 @@ struct mlx5_flow_tunnel_info {
 		rte_errno = ENOMEM;
 		goto error_before_flow;
 	}
-	flow->drv_type = flow_get_drv_type(dev, attr);
+	flow->drv_type = flow_get_drv_type(dev, &attr_factor);
 	if (hairpin_id != 0)
 		flow->hairpin_flow_id = hairpin_id;
 	MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4674,7 +4678,7 @@ struct mlx5_flow_tunnel_info {
 		 * depending on configuration. In the simplest
 		 * case it just creates unmodified original flow.
 		 */
-		ret = flow_create_split_outer(dev, flow, attr,
+		ret = flow_create_split_outer(dev, flow, &attr_factor,
 					      buf->entry[i].pattern,
 					      p_actions_rx, external, idx,
 					      error);
@@ -4711,8 +4715,8 @@ struct mlx5_flow_tunnel_info {
 	 * the egress Flows belong to the different device and
 	 * copy table should be updated in peer NIC Rx domain.
 	 */
-	if (attr->ingress &&
-	    (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
+	if (attr_factor.ingress &&
+	    (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
 		ret = flow_mreg_update_copy_table(dev, flow, actions, error);
 		if (ret)
 			goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
index 9d2493a..f3c0406 100644
@@ -366,6 +366,13 @@ enum mlx5_flow_fate_type {
 	MLX5_FLOW_FATE_MAX,
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /* Matcher PRM representation */
 struct mlx5_flow_dv_match_params {
 	size_t size;
@@ -613,13 +620,6 @@ struct mlx5_flow_handle {
 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
 #endif
 
-/*
- * Max number of actions per DV flow.
- * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
- * in rdma-core file providers/mlx5/verbs.c.
- */
-#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
-
 /** Device flow structure only for DV flow creation. */
 struct mlx5_flow_dv_workspace {
 	uint32_t group; /**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +485 -9

579 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#90 lore raw

PATCH v4 7/7 app/testpmd: add testpmd command for sample action

In reply to Jiawei Wang

Add a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>

The examples for the sample flow use case and result as below:

1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...

This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.

2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...

The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.

---
 app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
index 6263d30..27fa294 100644
@@ -56,6 +56,8 @@ enum index {
 	SET_RAW_ENCAP,
 	SET_RAW_DECAP,
 	SET_RAW_INDEX,
+	SET_SAMPLE_ACTIONS,
+	SET_SAMPLE_INDEX,
 
 	/* Top-level command. */
 	FLOW,
@@ -358,6 +360,10 @@ enum index {
 	ACTION_SET_IPV6_DSCP_VALUE,
 	ACTION_AGE,
 	ACTION_AGE_TIMEOUT,
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_SAMPLE_INDEX_VALUE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -493,6 +499,22 @@ struct action_nvgre_encap_data {
 
 struct mplsoudp_decap_conf mplsoudp_decap_conf;
 
+#define ACTION_SAMPLE_ACTIONS_NUM 10
+#define RAW_SAMPLE_CONFS_MAX_NUM 8
+/** Storage for struct rte_flow_action_sample including external data. */
+struct action_sample_data {
+	struct rte_flow_action_sample conf;
+	uint32_t idx;
+};
+/** Storage for struct rte_flow_action_sample. */
+struct raw_sample_conf {
+	struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
+};
+struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
+struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -1189,6 +1211,7 @@ struct parse_action_priv {
 	ACTION_SET_IPV4_DSCP,
 	ACTION_SET_IPV6_DSCP,
 	ACTION_AGE,
+	ACTION_SAMPLE,
 	ZERO,
 };
 
@@ -1421,9 +1444,28 @@ struct parse_action_priv {
 	ZERO,
 };
 
+static const enum index action_sample[] = {
+	ACTION_SAMPLE,
+	ACTION_SAMPLE_RATIO,
+	ACTION_SAMPLE_INDEX,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index next_action_sample[] = {
+	ACTION_QUEUE,
+	ACTION_MARK,
+	ACTION_COUNT,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
+static int parse_set_sample_action(struct context *, const struct token *,
+				   const char *, unsigned int,
+				   void *, unsigned int);
 static int parse_set_init(struct context *, const struct token *,
 			  const char *, unsigned int,
 			  void *, unsigned int);
@@ -1491,7 +1533,15 @@ static int parse_vc_action_raw_decap_index(struct context *,
 static int parse_vc_action_set_meta(struct context *ctx,
 				    const struct token *token, const char *str,
 				    unsigned int len, void *buf,
+					unsigned int size);
+static int parse_vc_action_sample(struct context *ctx,
+				    const struct token *token, const char *str,
+				    unsigned int len, void *buf,
 				    unsigned int size);
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
@@ -1562,6 +1612,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_set_raw_index(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_set_sample_index(struct context *, const struct token *,
+			      unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -3703,11 +3755,13 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
-		.help = "set raw encap/decap data",
-		.type = "set raw_encap|raw_decap <index> <pattern>",
+		.help = "set raw encap/decap/sample data",
+		.type = "set raw_encap|raw_decap <index> <pattern>"
+				" or set sample_actions <index> <action>",
 		.next = NEXT(NEXT_ENTRY
 			     (SET_RAW_ENCAP,
-			      SET_RAW_DECAP)),
+			      SET_RAW_DECAP,
+			      SET_SAMPLE_ACTIONS)),
 		.call = parse_set_init,
 	},
 	/* Sub-level commands. */
@@ -3738,6 +3792,23 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(next_item),
 		.call = parse_port,
 	},
+	[SET_SAMPLE_INDEX] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "index of sample actions",
+		.next = NEXT(next_action_sample),
+		.call = parse_port,
+	},
+	[SET_SAMPLE_ACTIONS] = {
+		.name = "sample_actions",
+		.help = "set sample actions list",
+		.next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
+		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
+				(offsetof(struct buffer, port),
+				 sizeof(((struct buffer *)0)->port),
+				 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
+		.call = parse_set_sample_action,
+	},
 	[ACTION_SET_TAG] = {
 		.name = "set_tag",
 		.help = "set tag",
@@ -3841,6 +3912,37 @@ static int comp_set_raw_index(struct context *, const struct token *,
 		.next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SAMPLE] = {
+		.name = "sample",
+		.help = "set a sample action",
+		.next = NEXT(action_sample),
+		.priv = PRIV_ACTION(SAMPLE,
+			sizeof(struct action_sample_data)),
+		.call = parse_vc_action_sample,
+	},
+	[ACTION_SAMPLE_RATIO] = {
+		.name = "ratio",
+		.help = "flow sample ratio value",
+		.next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_sample_data, conf) +
+			      offsetof(struct rte_flow_action_sample, ratio),
+			      sizeof(((struct rte_flow_action_sample *)0)->
+				     ratio))),
+	},
+	[ACTION_SAMPLE_INDEX] = {
+		.name = "index",
+		.help = "the index of sample actions list",
+		.next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
+	},
+	[ACTION_SAMPLE_INDEX_VALUE] = {
+		.name = "{index}",
+		.type = "UNSIGNED",
+		.help = "unsigned integer value",
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc_action_sample_index,
+		.comp = comp_set_sample_index,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
@@ -5351,6 +5453,76 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return len;
 }
 
+static int
+parse_vc_action_sample(struct context *ctx, const struct token *token,
+			 const char *str, unsigned int len, void *buf,
+			 unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_sample_data *action_sample_data = NULL;
+	static struct rte_flow_action end_action = {
+		RTE_FLOW_ACTION_TYPE_END, 0
+	};
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Copy the headers to the buffer. */
+	action_sample_data = ctx->object;
+	action_sample_data->conf.actions = &end_action;
+	action->conf = &action_sample_data->conf;
+	return ret;
+}
+
+static int
+parse_vc_action_sample_index(struct context *ctx, const struct token *token,
+				const char *str, unsigned int len, void *buf,
+				unsigned int size)
+{
+	struct action_sample_data *action_sample_data;
+	struct rte_flow_action *action;
+	const struct arg *arg;
+	struct buffer *out = buf;
+	int ret;
+	uint16_t idx;
+
+	RTE_SET_USED(token);
+	RTE_SET_USED(buf);
+	RTE_SET_USED(size);
+	if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
+		return -1;
+	arg = ARGS_ENTRY_ARB_BOUNDED
+		(offsetof(struct action_sample_data, idx),
+		 sizeof(((struct action_sample_data *)0)->idx),
+		 0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
+	if (push_args(ctx, arg))
+		return -1;
+	ret = parse_int(ctx, token, str, len, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		return -1;
+	}
+	if (!ctx->object)
+		return len;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	action_sample_data = ctx->object;
+	idx = action_sample_data->idx;
+	action_sample_data->conf.actions = raw_sample_confs[idx].data;
+	action->conf = &action_sample_data->conf;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
@@ -6115,6 +6287,38 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	if (!out->command)
 		return -1;
 	out->command = ctx->curr;
+	/* For encap/decap we need is pattern */
+	out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
+	return len;
+}
+
+/** Parse set command, initialize output buffer for subsequent tokens. */
+static int
+parse_set_sample_action(struct context *ctx, const struct token *token,
+			  const char *str, unsigned int len,
+			  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	/* Make sure buffer is large enough. */
+	if (size < sizeof(*out))
+		return -1;
+	ctx->objdata = 0;
+	ctx->objmask = NULL;
+	ctx->object = out;
+	if (!out->command)
+		return -1;
+	out->command = ctx->curr;
+	/* For sampler we need is actions */
+	out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	return len;
 }
 
@@ -6151,11 +6355,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 			return -1;
 		out->command = ctx->curr;
 		out->args.vc.data = (uint8_t *)out + size;
-		/* All we need is pattern */
-		out->args.vc.pattern =
-			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
-					       sizeof(double));
-		ctx->object = out->args.vc.pattern;
+		ctx->object  = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+						       sizeof(double));
 	}
 	return len;
 }
@@ -6306,6 +6507,24 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return nb;
 }
 
+/** Complete index number for set raw_encap/raw_decap commands. */
+static int
+comp_set_sample_index(struct context *ctx, const struct token *token,
+		   unsigned int ent, char *buf, unsigned int size)
+{
+	uint16_t idx = 0;
+	uint16_t nb = 0;
+
+	RTE_SET_USED(ctx);
+	RTE_SET_USED(token);
+	for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
+		if (buf && idx == ent)
+			return snprintf(buf, size, "%u", idx);
+		++nb;
+	}
+	return nb;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -6751,7 +6970,53 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	return mask;
 }
 
-
+/** Dispatch parsed buffer to function calls. */
+static void
+cmd_set_raw_parsed_sample(const struct buffer *in)
+{
+	uint32_t n = in->args.vc.actions_n;
+	uint32_t i = 0;
+	struct rte_flow_action *action = NULL;
+	struct rte_flow_action *data = NULL;
+	size_t size = 0;
+	uint16_t idx = in->port; /* We borrow port field as index */
+	uint32_t max_size = sizeof(struct rte_flow_action) *
+						ACTION_SAMPLE_ACTIONS_NUM;
+
+	RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
+	data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
+	memset(data, 0x00, max_size);
+	for (; i <= n - 1; i++) {
+		action = in->args.vc.actions + i;
+		if (action->type == RTE_FLOW_ACTION_TYPE_END)
+			break;
+		switch (action->type) {
+		case RTE_FLOW_ACTION_TYPE_MARK:
+			size = sizeof(struct rte_flow_action_mark);
+			rte_memcpy(&sample_mark[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_mark[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			size = sizeof(struct rte_flow_action_count);
+			rte_memcpy(&sample_count[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_count[idx];
+			break;
+		case RTE_FLOW_ACTION_TYPE_QUEUE:
+			size = sizeof(struct rte_flow_action_queue);
+			rte_memcpy(&sample_queue[idx],
+				(const void *)action->conf, size);
+			action->conf = &sample_queue[idx];
+			break;
+		default:
+			printf("Error - Not supported action\n");
+			return;
+		}
+		rte_memcpy(data, action, sizeof(struct rte_flow_action));
+		data++;
+	}
+}
 
 /** Dispatch parsed buffer to function calls. */
 static void
@@ -6768,6 +7033,8 @@ static int comp_set_raw_index(struct context *, const struct token *,
 	uint16_t proto = 0;
 	uint16_t idx = in->port; /* We borrow port field as index */
 
+	if (in->command == SET_SAMPLE_ACTIONS)
+		return cmd_set_raw_parsed_sample(in);
 	RTE_ASSERT(in->command == SET_RAW_ENCAP ||
 		   in->command == SET_RAW_DECAP);
 	if (in->command == SET_RAW_ENCAP) {
Signature · 1 line
1.8.3.1
#91 lore raw

v5 cover support the flow-based traffic sampling

In reply to Jiawei Wang

This patch set implement the flow sampling for mlx5 driver.

The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.

v5:
* Add the release note.
* Remove Make changes since it's deprecated.

v4:
* Rebase.
* Fix the coding style issue.

v3:
* Remove 'const' of ratio field.
* Update description and commit messages.

v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.

Jiawei Wang (7):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action

 app/test-pmd/cmdline_flow.c            | 285 ++++++++++++++-
 doc/guides/prog_guide/rte_flow.rst     |  25 ++
 doc/guides/rel_notes/release_20_11.rst |   6 +
 drivers/common/mlx5/linux/meson.build  |   2 +
 drivers/common/mlx5/linux/mlx5_glue.c  |  15 +
 drivers/common/mlx5/linux/mlx5_glue.h  |  12 +
 drivers/common/mlx5/mlx5_devx_cmds.c   |  27 ++
 drivers/common/mlx5/mlx5_devx_cmds.h   |   1 +
 drivers/common/mlx5/mlx5_prm.h         |  51 +++
 drivers/net/mlx5/linux/mlx5_os.c       |  14 +
 drivers/net/mlx5/mlx5.c                |  11 +
 drivers/net/mlx5/mlx5.h                |   4 +
 drivers/net/mlx5/mlx5_flow.c           | 274 +++++++++++++-
 drivers/net/mlx5/mlx5_flow.h           |  51 ++-
 drivers/net/mlx5/mlx5_flow_dv.c        | 627 ++++++++++++++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c           |   1 +
 lib/librte_ethdev/rte_flow.h           |  30 ++
 17 files changed, 1401 insertions(+), 35 deletions(-)
Signature · 1 line
1.8.3.1
#92 lore raw

PATCH v5 1/7 ethdev: introduce sample action for rte flow

When using full offload, all traffic will be handled by the HW, and directed to the requested VF or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_11.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
index 3e5cd1e..f8f3f51 100644
@@ -2653,6 +2653,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated with the specified ``ratio`` and
+applied with own set of actions with a fate action, the packets sampled
+equals is '1/ratio'. All the packets continue to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets, and must have a fate action.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_11.rst +6 -0
index df227a1..7f99563 100644
@@ -55,6 +55,12 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching
+  packets with specified ratio, and apply with own set of actions with a fate
+  action. When the ratio is set to 1 then the packets will be 100% mirrored.
+
 
 Removed Items
 -------------
lib/librte_ethdev/rte_flow.c +1 -0
index f8fdd68..035671d 100644
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +30 -0
index da8bfa5..fa70d40 100644
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {
 	 * see enum RTE_ETH_EVENT_FLOW_AGED
 	 */
 	RTE_FLOW_ACTION_TYPE_AGE,
+
+	/**
+	 * The matching packets will be duplicated with specified ratio and
+	 * applied with own set of actions with a fate action.
+	 *
+	 * See struct rte_flow_action_sample.
+	 */
+	RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated with specified ratio and applied
+ * with own set of actions with a fate action, the sampled packet could be
+ * redirected to queue or port. All the packets continue processing on the
+ * default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+	uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+	const struct rte_flow_action *actions;
+		/**< sub-action list specific for the sampling hit cases. */
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
#93 lore raw

Re: [dpdk-dev] [PATCH v5 1/7] ethdev: introduce sample action for rte flow

Quoted 11 lines · Jiawei Wang

When using full offload, all traffic will be handled by the HW, and directed to the requested VF or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

Quoted 8 lines

The packets sampled equals is '1/ratio', if the ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

In use cases where sampling/mirroring is enabled for monitoring security/policy breaches
and network connectivity/performance, mirroring copies traffic from mirrored sources
and sends it to a collector destination where monitoring applications run.

At any given time, the number of flows to be mirrored could be high, however,
the number of collector destinations is limited because DC operators would monitor
the copied traffic using a handful number of monitoring applications.

Therefore it would increase the scalability if we can configure the sampling/mirroring in 2 steps
(something similar to meter configuration). In other words, sampling action is configured via
one API and the sampling is enabled on a flow via rte_flow_create API.

We could send the proposal in the next couple of days for review.

Thanks
Ajit

Quoted 140 lines
---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_11.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +11 -0
index 3e5cd1e..f8f3f51 100644
@@ -2653,6 +2653,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated with the specified ``ratio`` and
+applied with own set of actions with a fate action, the packets sampled
+equals is '1/ratio'. All the packets continue to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or

mirrored

doc/guides/prog_guide/rte_flow.rst +14 -0
+packets, and must have a fate action.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
doc/guides/rel_notes/release_20_11.rst +3 -0
index df227a1..7f99563 100644
@@ -55,6 +55,12 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the

matching
+ packets with specified ratio, and apply with own set of actions with a fate
+ action. When the ratio is set to 1 then the packets will be 100% mirrored.

doc/guides/rel_notes/release_20_11.rst +1 -0
+
 
 Removed Items
 -------------
lib/librte_ethdev/rte_flow.c +1 -0
index f8fdd68..035671d 100644
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {
        MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct
 rte_flow_action_set_dscp)),
        MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct
 rte_flow_action_set_dscp)),
        MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+       MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };

int

lib/librte_ethdev/rte_flow.h +16 -0
index da8bfa5..fa70d40 100644
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {
         * see enum RTE_ETH_EVENT_FLOW_AGED
         */
        RTE_FLOW_ACTION_TYPE_AGE,
+
+       /**
+        * The matching packets will be duplicated with specified ratio and
+        * applied with own set of actions with a fate action.
+        *
+        * See struct rte_flow_action_sample.
+        */
+       RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated with specified ratio and

applied
+ * with own set of actions with a fate action, the sampled packet could be
+ * redirected to queue or port. All the packets continue processing on the
+ * default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */

lib/librte_ethdev/rte_flow.h +4 -0
+struct rte_flow_action_sample {
+       uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+       const struct rte_flow_action *actions;
+               /**< sub-action list specific for the sampling hit cases.

*/

lib/librte_ethdev/rte_flow.h +3 -1
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct
--

1.8.3.1

Acked-by Acked-by Jerin Jacob Acked-by Andrew Rybchenko
#94 lore raw

Re: [dpdk-dev] [PATCH v5 1/7] ethdev: introduce sample action for rte flow

Hi Ajit,

Sorry for not inline, but for some reason this tread is in html format. I think that the issue you are rising is a good one, but can be solved using the new context API that we are going to push into 20.11
https://patches.dpdk.org/cover/73555/

this will enable creating the sample action once and reuse it later.

Best,
Ori

From: Ajit Khaparde <[email protected]>
Sent: Friday, September 4, 2020 7:17 AM

On Thu, Aug 27, 2020 at 8:23 AM Jiawei Wang <[email protected]<mailto:[email protected]>> wrote:
When using full offload, all traffic will be handled by the HW, and
directed to the requested VF or wire, the control application loses
visibility on the traffic.
So there's a need for an action that will enable the control application
some visibility.

The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.

The packets sampled equals is '1/ratio', if the ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.

In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.

In use cases where sampling/mirroring is enabled for monitoring security/policy breaches and network connectivity/performance, mirroring copies traffic from mirrored sources and sends it to a collector destination where monitoring applications run.

At any given time, the number of flows to be mirrored could be high, however, the number of collector destinations is limited because DC operators would monitor the copied traffic using a handful number of monitoring applications.

Therefore it would increase the scalability if we can configure the sampling/mirroring in 2 steps (something similar to meter configuration). In other words, sampling action is configured via one API and the sampling is enabled on a flow via rte_flow_create API.

We could send the proposal in the next couple of days for review.

Thanks
Ajit

---
 doc/guides/prog_guide/rte_flow.rst     | 25 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_20_11.rst |  6 ++++++
 lib/librte_ethdev/rte_flow.c           |  1 +
 lib/librte_ethdev/rte_flow.h           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
index 3e5cd1e..f8f3f51 100644
@@ -2653,6 +2653,31 @@ timeout passed without any matching on the flow.
    | ``context``  | user input flow context         |
    +--------------+---------------------------------+
 
+Action: ``SAMPLE``
+^^^^^^^^^^^^^^^^^^
+
+Adds a sample action to a matched flow.
+
+The matching packets will be duplicated with the specified ``ratio`` and
+applied with own set of actions with a fate action, the packets sampled
+equals is '1/ratio'. All the packets continue to the target destination.
+
+When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
+``actions`` represent the different set of actions for the sampled or mirrored
+packets, and must have a fate action.
+
+.. _table_rte_flow_action_sample:
+
+.. table:: SAMPLE
+
+   +--------------+---------------------------------+
+   | Field        | Value                           |
+   +==============+=================================+
+   | ``ratio``    | 32 bits sample ratio value      |
+   +--------------+---------------------------------+
+   | ``actions``  | sub-action list for sampling    |
+   +--------------+---------------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_11.rst +6 -0
index df227a1..7f99563 100644
@@ -55,6 +55,12 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added flow-based traffic sampling support.**
+
+  Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching
+  packets with specified ratio, and apply with own set of actions with a fate
+  action. When the ratio is set to 1 then the packets will be 100% mirrored.
+
 
 Removed Items
 -------------
lib/librte_ethdev/rte_flow.c +1 -0
index f8fdd68..035671d 100644
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {
        MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
        MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
        MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
+       MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
 };
 
 int
lib/librte_ethdev/rte_flow.h +30 -0
index da8bfa5..fa70d40 100644
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {
         * see enum RTE_ETH_EVENT_FLOW_AGED
         */
        RTE_FLOW_ACTION_TYPE_AGE,
+
+       /**
+        * The matching packets will be duplicated with specified ratio and
+        * applied with own set of actions with a fate action.
+        *
+        * See struct rte_flow_action_sample.
+        */
+       RTE_FLOW_ACTION_TYPE_SAMPLE,
 };
 
 /**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {
 struct rte_flow;
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SAMPLE
+ *
+ * Adds a sample action to a matched flow.
+ *
+ * The matching packets will be duplicated with specified ratio and applied
+ * with own set of actions with a fate action, the sampled packet could be
+ * redirected to queue or port. All the packets continue processing on the
+ * default flow path.
+ *
+ * When the sample ratio is set to 1 then the packets will be 100% mirrored.
+ * Additional action list be supported to add for sampled or mirrored packets.
+ */
+struct rte_flow_action_sample {
+       uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
+       const struct rte_flow_action *actions;
+               /**< sub-action list specific for the sampling hit cases. */
+};
+
+/**
  * Verbose error types.
  *
  * Most of them provide the type of the object referenced by struct

--
1.8.3.1

#95 lore raw

PATCH v5 2/7 common/mlx5: glue for sample action

In reply to Jiawei Wang

rdma-core introduce a new DR sample action.

Add the rdma-core commands in glue to create this action.

Sample action is used for creating the sample object to implement the sampling/mirroring function.

---
 drivers/common/mlx5/linux/meson.build |  2 ++
 drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 12 ++++++++++++
 3 files changed, 29 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
index 48e8ad6..1aa137d 100644
@@ -172,6 +172,8 @@ has_sym_args = [
 	'RDMA_NLDEV_ATTR_NDEV_INDEX' ],
 	[ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h',
 	'mlx5dv_dump_dr_domain'],
+	[ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h',
+	'mlx5dv_dr_action_create_flow_sampler'],
 	[ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h',
 	'mlx5dv_dr_domain_set_reclaim_device_memory'],
 	[ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
index fcf03e8..771a47c 100644
@@ -1063,6 +1063,19 @@
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_sampler(
+			struct mlx5dv_dr_flow_sampler_attr *attr)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+	return mlx5dv_dr_action_create_flow_sampler(attr);
+#else
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static int
 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
 			 uint32_t *eqn)
@@ -1339,6 +1352,8 @@
 	.devx_port_query = mlx5_glue_devx_port_query,
 	.dr_dump_domain = mlx5_glue_dr_dump_domain,
 	.dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
+	.dr_create_flow_action_sampler =
+		mlx5_glue_dr_create_flow_action_sampler,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
 	.devx_create_event_channel = mlx5_glue_devx_create_event_channel,
 	.devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +12 -0
index 734ace2..85b43b9 100644
@@ -77,6 +77,7 @@
 #ifndef HAVE_MLX5DV_DR
 enum  mlx5dv_dr_domain_type { unused, };
 struct mlx5dv_dr_domain;
+struct mlx5dv_dr_action;
 #endif
 
 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,15 @@
 struct mlx5dv_dr_flow_meter_attr;
 #endif
 
+#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
+struct mlx5dv_dr_flow_sampler_attr {
+	uint32_t sample_ratio;
+	void *default_next_table;
+	size_t num_sample_actions;
+	struct mlx5dv_dr_action **sample_actions;
+};
+#endif
+
 #ifndef HAVE_IBV_DEVX_EVENT
 struct mlx5dv_devx_event_channel { int fd; };
 struct mlx5dv_devx_async_event_hdr;
@@ -309,6 +319,8 @@ struct mlx5_glue {
 					 const void *pp_context,
 					 uint32_t flags);
 	void (*dv_free_pp)(struct mlx5dv_pp *pp);
+	void *(*dr_create_flow_action_sampler)
+			(struct mlx5dv_dr_flow_sampler_attr *attr);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
#96 lore raw

PATCH v5 3/7 common/mlx5: query sampler object capability via DevX

In reply to Jiawei Wang

Update function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.

Add the related structs definition in mlx5_prm.h.

---
 drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++
 drivers/common/mlx5/mlx5_devx_cmds.h |  1 +
 drivers/common/mlx5/mlx5_prm.h       | 51 ++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
index 7c81ae1..fd4e3f2 100644
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *
 	if (!attr->eth_net_offloads)
 		return 0;
 
+	/* Query Flow Sampler Capability From FLow Table Properties Layout. */
+	memset(in, 0, sizeof(in));
+	memset(out, 0, sizeof(out));
+	MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
+	MLX5_SET(query_hca_cap_in, in, op_mod,
+		 MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
+		 MLX5_HCA_CAP_OPMOD_GET_CUR);
+
+	rc = mlx5_glue->devx_general_cmd(ctx,
+					 in, sizeof(in),
+					 out, sizeof(out));
+	if (rc)
+		goto error;
+	status = MLX5_GET(query_hca_cap_out, out, status);
+	syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
+	if (status) {
+		DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
+			"status %x, syndrome = %x",
+			status, syndrome);
+		attr->log_max_ft_sampler_num = 0;
+		return -1;
+	}
+	hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
+	attr->log_max_ft_sampler_num =
+			MLX5_GET(flow_table_nic_cap,
+			hcattr, flow_table_properties.log_max_ft_sampler_num);
+
 	/* Query HCA offloads for Ethernet protocol. */
 	memset(in, 0, sizeof(in));
 	memset(out, 0, sizeof(out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
index 1c84cea..cfa7a7b 100644
@@ -102,6 +102,7 @@ struct mlx5_hca_attr {
 	uint32_t scatter_fcs_w_decap_disable:1;
 	uint32_t regex:1;
 	uint32_t regexp_num_of_engines;
+	uint32_t log_max_ft_sampler_num:8;
 	struct mlx5_hca_qos_attr qos;
 	struct mlx5_hca_vdpa_attr vdpa;
 };
drivers/common/mlx5/mlx5_prm.h +51 -0

69 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#97 lore raw

PATCH v5 4/7 net/mlx5: add the validate sample action

In reply to Jiawei Wang

Add sample action validate function.

For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX.

Only NIC_RX support with addition optional actions. FDB doesn't support any optional action, the sampled packets is always goes to e-switch manager port.

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +++++
 drivers/net/mlx5/mlx5.h          |   1 +
 drivers/net/mlx5/mlx5_flow.h     |   1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 133 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
index db955ae..5b663a1 100644
@@ -1015,6 +1015,20 @@
 			}
 		}
 #endif
+#if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
+		if (config->hca_attr.log_max_ft_sampler_num > 0  &&
+		    config->dv_flow_en) {
+			priv->sampler_en = 1;
+			DRV_LOG(DEBUG, "The Sampler enabled!\n");
+		} else {
+			priv->sampler_en = 0;
+			if (!config->hca_attr.log_max_ft_sampler_num)
+				DRV_LOG(WARNING, "No available register for"
+						" Sampler.");
+			else
+				DRV_LOG(DEBUG, "DV flow is not supported!\n");
+		}
+#endif
 	}
 	if (config->tx_pp) {
 		DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
index 1880a82..ae0c7cc 100644
@@ -698,6 +698,7 @@ struct mlx5_priv {
 	unsigned int counter_fallback:1; /* Use counter fallback management. */
 	unsigned int mtr_en:1; /* Whether support meter. */
 	unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
+	unsigned int sampler_en:1; /* Whether support sampler. */
 	uint16_t domain_id; /* Switch domain identifier. */
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
index 92301e4..41404de 100644
@@ -196,6 +196,7 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35)
+#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +133 -0

145 lines not on this page · raw message

Signature · 1 line
1.8.3.1