[v2,2/3] pipeline: add implementation for DSCP action

Message ID 20180211132905.7502-2-georgina.sheehan@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Cristian Dumitrescu
Headers
Series [v2,1/3] librte_pipeline: add support for DSCP action |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Sheehan,Georgina Feb. 11, 2018, 1:29 p.m. UTC
  From: Georgina Sheehan <georgina.sheehan@intel.com>

This allows the application to change the DSCP value of incoming packets

v2: Added in call of function parse_table_action_dscp in softnic cli file

Signed-off-by: Georgina Sheehan <georgina.sheehan@intel.com>
---
 examples/ip_pipeline/action.c   | 11 +++++++
 examples/ip_pipeline/action.h   |  1 +
 examples/ip_pipeline/cli.c      | 52 ++++++++++++++++++++++++++++++++-
 examples/ip_pipeline/pipeline.h |  1 +
 examples/ip_pipeline/thread.c   | 10 +++++++
 5 files changed, 74 insertions(+), 1 deletion(-)
  

Comments

Cristian Dumitrescu Feb. 28, 2019, 7:24 p.m. UTC | #1
> -----Original Message-----
> From: Sheehan, Georgina
> Sent: Sunday, February 11, 2018 1:29 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Sheehan,
> Georgina <georgina.sheehan@intel.com>
> Subject: [PATCH v2 2/3] pipeline: add implementation for DSCP action

According to DPDK conventions, the title should be: "examples/ip_pipeline: ..." instead of "pipeline: ..."

> 
> From: Georgina Sheehan <georgina.sheehan@intel.com>
> 
> This allows the application to change the DSCP value of incoming packets
> 
> v2: Added in call of function parse_table_action_dscp in softnic cli file
> 
> Signed-off-by: Georgina Sheehan <georgina.sheehan@intel.com>
> ---
>  examples/ip_pipeline/action.c   | 11 +++++++
>  examples/ip_pipeline/action.h   |  1 +
>  examples/ip_pipeline/cli.c      | 52 ++++++++++++++++++++++++++++++++-
>  examples/ip_pipeline/pipeline.h |  1 +
>  examples/ip_pipeline/thread.c   | 10 +++++++
>  5 files changed, 74 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/ip_pipeline/action.c b/examples/ip_pipeline/action.c
> index d2104aad6..625c870a2 100644
> --- a/examples/ip_pipeline/action.c
> +++ b/examples/ip_pipeline/action.c
> @@ -366,6 +366,17 @@ table_action_profile_create(const char *name,
>  		}
>  	}
> 
> +	if (params->action_mask & (1LLU << RTE_TABLE_ACTION_DSCP)) {
> +		status = rte_table_action_profile_action_register(ap,
> +				RTE_TABLE_ACTION_DSCP,
> +				&params->dscp);
> +
> +		if (status) {
> +			rte_table_action_profile_free(ap);
> +			return NULL;
> +		}
> +	}
> +
>  	status = rte_table_action_profile_freeze(ap);
>  	if (status) {
>  		rte_table_action_profile_free(ap);
> diff --git a/examples/ip_pipeline/action.h b/examples/ip_pipeline/action.h
> index cde17e69a..ea8f81c56 100644
> --- a/examples/ip_pipeline/action.h
> +++ b/examples/ip_pipeline/action.h
> @@ -54,6 +54,7 @@ struct table_action_profile_params {
>  	struct rte_table_action_ttl_config ttl;
>  	struct rte_table_action_stats_config stats;
>  	struct rte_table_action_sym_crypto_config sym_crypto;
> +	struct rte_table_action_dscp_config dscp;
>  };
> 
>  struct table_action_profile {
> diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c
> index a92467e63..ca3083a48 100644
> --- a/examples/ip_pipeline/cli.c
> +++ b/examples/ip_pipeline/cli.c
> @@ -1045,7 +1045,8 @@ static const char cmd_table_action_profile_help[] =
>  "   [time]\n"
>  "   [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
>  "   [tag]\n"
> -"   [decap]\n";
> +"   [decap]\n"
> +"   [dscp]\n";
> 
>  static void
>  cmd_table_action_profile(char **tokens,
> @@ -1458,6 +1459,17 @@ cmd_table_action_profile(char **tokens,
>  		t0 += 1;
>  	} /* decap */
> 
> +	if ((t0 < n_tokens) && (strcmp(tokens[t0], "dscp") == 0)) {
> +		if (n_tokens < t0 + 1) {
> +			snprintf(out, out_size, MSG_ARG_MISMATCH,
> +				"table action profile dscp");
> +			return;
> +		}
> +
> +		p.action_mask |= 1LLU << RTE_TABLE_ACTION_DSCP;
> +		t0 += 1;
> +	} /** DSCP **/
> +
>  	if (t0 < n_tokens) {
>  		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
>  		return;
> @@ -3116,6 +3128,7 @@ parse_match(char **tokens,
>   *       data_offset <data_offset>]
>   *    [tag <tag>]
>   *    [decap <n>]
> + *    [dscp <n>]
>   *
>   * where:
>   *    <pa> ::= g | y | r | drop
> @@ -4108,6 +4121,26 @@ parse_table_action_decap(char **tokens,
>  	return 2;
>  }
> 
> +static uint32_t
> +parse_table_action_dscp(char **tokens,
> +		uint32_t n_tokens,
> +		struct table_rule_action *a)
> +{
> +	if ((n_tokens < 2) ||
> +		strcmp(tokens[0], "dscp"))
> +		return 0;
> +
> +	uint8_t dscp_val;
> +
> +	if (parser_read_uint8(&dscp_val, tokens[1]))
> +		return 0;
> +
> +	a->dscp.dscp_val = dscp_val;
> +
> +	a->action_mask |= 1 << RTE_TABLE_ACTION_DSCP;
> +	return 2;
> +}
> +
>  static uint32_t
>  parse_table_action(char **tokens,
>  	uint32_t n_tokens,
> @@ -4293,6 +4326,20 @@ parse_table_action(char **tokens,
>  		n_tokens -= n;
>  	}
> 
> +	if (n_tokens && (strcmp(tokens[0], "dscp") == 0)) {
> +		uint32_t n;
> +
> +		n = parse_table_action_dscp(tokens, n_tokens, a);
> +		if (n == 0) {
> +			snprintf(out, out_size, MSG_ARG_INVALID,
> +				"action dscp");
> +			return 0;
> +		}
> +
> +		tokens += n;
> +		n_tokens -= n;
> +	}
> +
>  	if (n_tokens0 - n_tokens == 1) {
>  		snprintf(out, out_size, MSG_ARG_INVALID, "action");
>  		return 0;
> @@ -5056,6 +5103,9 @@ table_rule_show(const char *pipeline_name,
>  		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
>  			fprintf(f, "decap %u ", a->decap.n);
> 
> +		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DSCP))
> +			fprintf(f, "dscp ");
> +
>  		/* end */
>  		fprintf(f, "\n");
>  	}
> diff --git a/examples/ip_pipeline/pipeline.h
> b/examples/ip_pipeline/pipeline.h
> index 278775c2d..670174ed4 100644
> --- a/examples/ip_pipeline/pipeline.h
> +++ b/examples/ip_pipeline/pipeline.h
> @@ -290,6 +290,7 @@ struct table_rule_action {
>  	struct rte_table_action_sym_crypto_params sym_crypto;
>  	struct rte_table_action_tag_params tag;
>  	struct rte_table_action_decap_params decap;
> +	struct rte_table_action_dscp_params dscp;
>  };
> 
>  struct table_rule {
> diff --git a/examples/ip_pipeline/thread.c b/examples/ip_pipeline/thread.c
> index 272fbbeed..c9facb53e 100644
> --- a/examples/ip_pipeline/thread.c
> +++ b/examples/ip_pipeline/thread.c
> @@ -2751,6 +2751,16 @@ action_convert(struct rte_table_action *a,
>  			return status;
>  	}
> 
> +	if (action->action_mask & (1LLU << RTE_TABLE_ACTION_DSCP)) {
> +		status = rte_table_action_apply(a,
> +			data,
> +			RTE_TABLE_ACTION_DSCP,
> +			&action->dscp);
> +
> +		if (status)
> +			return status;
> +	}
> +
>  	return 0;
>  }
> 
> --
> 2.17.1
  

Patch

diff --git a/examples/ip_pipeline/action.c b/examples/ip_pipeline/action.c
index d2104aad6..625c870a2 100644
--- a/examples/ip_pipeline/action.c
+++ b/examples/ip_pipeline/action.c
@@ -366,6 +366,17 @@  table_action_profile_create(const char *name,
 		}
 	}
 
+	if (params->action_mask & (1LLU << RTE_TABLE_ACTION_DSCP)) {
+		status = rte_table_action_profile_action_register(ap,
+				RTE_TABLE_ACTION_DSCP,
+				&params->dscp);
+
+		if (status) {
+			rte_table_action_profile_free(ap);
+			return NULL;
+		}
+	}
+
 	status = rte_table_action_profile_freeze(ap);
 	if (status) {
 		rte_table_action_profile_free(ap);
diff --git a/examples/ip_pipeline/action.h b/examples/ip_pipeline/action.h
index cde17e69a..ea8f81c56 100644
--- a/examples/ip_pipeline/action.h
+++ b/examples/ip_pipeline/action.h
@@ -54,6 +54,7 @@  struct table_action_profile_params {
 	struct rte_table_action_ttl_config ttl;
 	struct rte_table_action_stats_config stats;
 	struct rte_table_action_sym_crypto_config sym_crypto;
+	struct rte_table_action_dscp_config dscp;
 };
 
 struct table_action_profile {
diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c
index a92467e63..ca3083a48 100644
--- a/examples/ip_pipeline/cli.c
+++ b/examples/ip_pipeline/cli.c
@@ -1045,7 +1045,8 @@  static const char cmd_table_action_profile_help[] =
 "   [time]\n"
 "   [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
 "   [tag]\n"
-"   [decap]\n";
+"   [decap]\n"
+"   [dscp]\n";
 
 static void
 cmd_table_action_profile(char **tokens,
@@ -1458,6 +1459,17 @@  cmd_table_action_profile(char **tokens,
 		t0 += 1;
 	} /* decap */
 
+	if ((t0 < n_tokens) && (strcmp(tokens[t0], "dscp") == 0)) {
+		if (n_tokens < t0 + 1) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH,
+				"table action profile dscp");
+			return;
+		}
+
+		p.action_mask |= 1LLU << RTE_TABLE_ACTION_DSCP;
+		t0 += 1;
+	} /** DSCP **/
+
 	if (t0 < n_tokens) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
@@ -3116,6 +3128,7 @@  parse_match(char **tokens,
  *       data_offset <data_offset>]
  *    [tag <tag>]
  *    [decap <n>]
+ *    [dscp <n>]
  *
  * where:
  *    <pa> ::= g | y | r | drop
@@ -4108,6 +4121,26 @@  parse_table_action_decap(char **tokens,
 	return 2;
 }
 
+static uint32_t
+parse_table_action_dscp(char **tokens,
+		uint32_t n_tokens,
+		struct table_rule_action *a)
+{
+	if ((n_tokens < 2) ||
+		strcmp(tokens[0], "dscp"))
+		return 0;
+
+	uint8_t dscp_val;
+
+	if (parser_read_uint8(&dscp_val, tokens[1]))
+		return 0;
+
+	a->dscp.dscp_val = dscp_val;
+
+	a->action_mask |= 1 << RTE_TABLE_ACTION_DSCP;
+	return 2;
+}
+
 static uint32_t
 parse_table_action(char **tokens,
 	uint32_t n_tokens,
@@ -4293,6 +4326,20 @@  parse_table_action(char **tokens,
 		n_tokens -= n;
 	}
 
+	if (n_tokens && (strcmp(tokens[0], "dscp") == 0)) {
+		uint32_t n;
+
+		n = parse_table_action_dscp(tokens, n_tokens, a);
+		if (n == 0) {
+			snprintf(out, out_size, MSG_ARG_INVALID,
+				"action dscp");
+			return 0;
+		}
+
+		tokens += n;
+		n_tokens -= n;
+	}
+
 	if (n_tokens0 - n_tokens == 1) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "action");
 		return 0;
@@ -5056,6 +5103,9 @@  table_rule_show(const char *pipeline_name,
 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
 			fprintf(f, "decap %u ", a->decap.n);
 
+		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DSCP))
+			fprintf(f, "dscp ");
+
 		/* end */
 		fprintf(f, "\n");
 	}
diff --git a/examples/ip_pipeline/pipeline.h b/examples/ip_pipeline/pipeline.h
index 278775c2d..670174ed4 100644
--- a/examples/ip_pipeline/pipeline.h
+++ b/examples/ip_pipeline/pipeline.h
@@ -290,6 +290,7 @@  struct table_rule_action {
 	struct rte_table_action_sym_crypto_params sym_crypto;
 	struct rte_table_action_tag_params tag;
 	struct rte_table_action_decap_params decap;
+	struct rte_table_action_dscp_params dscp;
 };
 
 struct table_rule {
diff --git a/examples/ip_pipeline/thread.c b/examples/ip_pipeline/thread.c
index 272fbbeed..c9facb53e 100644
--- a/examples/ip_pipeline/thread.c
+++ b/examples/ip_pipeline/thread.c
@@ -2751,6 +2751,16 @@  action_convert(struct rte_table_action *a,
 			return status;
 	}
 
+	if (action->action_mask & (1LLU << RTE_TABLE_ACTION_DSCP)) {
+		status = rte_table_action_apply(a,
+			data,
+			RTE_TABLE_ACTION_DSCP,
+			&action->dscp);
+
+		if (status)
+			return status;
+	}
+
 	return 0;
 }