DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jasvinder Singh <jasvinder.singh@intel.com>
To: dev@dpdk.org
Cc: cristian.dumitrescu@intel.com
Subject: [dpdk-dev] [PATCH v2 10/10] net/softnic: enable flow rule with meter action
Date: Wed, 12 Sep 2018 17:41:38 +0100	[thread overview]
Message-ID: <20180912164138.55800-11-jasvinder.singh@intel.com> (raw)
In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com>

Implement flow rules with meter action.

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
 drivers/net/softnic/rte_eth_softnic_flow.c | 153 +++++++++++++++++++++++++++++
 1 file changed, 153 insertions(+)

diff --git a/drivers/net/softnic/rte_eth_softnic_flow.c b/drivers/net/softnic/rte_eth_softnic_flow.c
index fc7a0b0..f0eeff2 100644
--- a/drivers/net/softnic/rte_eth_softnic_flow.c
+++ b/drivers/net/softnic/rte_eth_softnic_flow.c
@@ -1474,6 +1474,101 @@ flow_rule_action_get(struct pmd_internals *softnic,
 			break;
 		} /* RTE_FLOW_ACTION_TYPE_COUNT */
 
+		case RTE_FLOW_ACTION_TYPE_METER:
+		{
+			struct rte_table_action_mtr_tc_params mtr_tc_params;
+			const struct rte_flow_action_meter *conf = action->conf;
+			struct rte_table_action_meter_profile profile;
+			struct softnic_mtr_meter_profile *mp;
+			struct softnic_mtr *m;
+			uint32_t i, meter_profile_id, table_id = UINT32_MAX;
+			int status;
+
+			if (conf == NULL)
+				return rte_flow_error_set(error,
+					EINVAL,
+					RTE_FLOW_ERROR_TYPE_ACTION,
+					action,
+					"METER: Null configuration");
+
+			if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0)
+				return rte_flow_error_set(error,
+					EINVAL,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					NULL,
+					"METER: table action not supported");
+
+			m = softnic_mtr_find(softnic, conf->mtr_id);
+			if (m == NULL)
+				return -rte_flow_error_set(error,
+					EINVAL,
+					RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+					NULL,
+					"METER: invalid meter id");
+
+			if (m->flow)
+				return -rte_flow_error_set(error,
+					EINVAL,
+					RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+					NULL,
+					"METER: meter already attached to flow");
+
+			if (params->mtr.n_tc != 1)
+				return -rte_flow_error_set(error,
+					EINVAL,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					NULL,
+					"METER: multiple TCs not supported");
+
+			meter_profile_id = m->params.meter_profile_id;
+			mp = softnic_mtr_meter_profile_find(softnic, meter_profile_id);
+
+			memset(&profile, 0, sizeof(profile));
+			profile.alg = RTE_TABLE_ACTION_METER_TRTCM;
+			profile.trtcm.cir = mp->params.trtcm_rfc2698.cir;
+			profile.trtcm.pir = mp->params.trtcm_rfc2698.pir;
+			profile.trtcm.cbs = mp->params.trtcm_rfc2698.cbs;
+			profile.trtcm.pbs = mp->params.trtcm_rfc2698.pbs;
+
+			/* Identify the pipeline table to add this flow to. */
+			for (i = 0; i < pipeline->n_tables; i++) {
+				if (table == &pipeline->table[i]) {
+					table_id = i;
+					break;
+				}
+			}
+
+			/* Add meter profile to pipeline table */
+			status = softnic_pipeline_table_mtr_profile_add(softnic,
+					pipeline->name,
+					table_id,
+					meter_profile_id,
+					&profile);
+			if (status) {
+				rte_flow_error_set(error,
+					EINVAL,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					NULL,
+					"Table meter profile add failed");
+				return -1;
+			}
+
+			/* RTE_TABLE_ACTION_METER */
+			mtr_tc_params.meter_profile_id = meter_profile_id;
+			mtr_tc_params.policer[e_RTE_METER_GREEN] =
+				(enum rte_table_action_policer)m->params.action[RTE_MTR_GREEN];
+			mtr_tc_params.policer[e_RTE_METER_YELLOW] =
+				(enum rte_table_action_policer)m->params.action[RTE_MTR_YELLOW];
+			mtr_tc_params.policer[e_RTE_METER_RED] =
+				(enum rte_table_action_policer)m->params.action[RTE_MTR_RED];
+
+			memcpy(&rule_action->mtr.mtr[0], &mtr_tc_params,
+				sizeof(rule_action->mtr.mtr[0]));
+			rule_action->mtr.tc_mask = 1 << 0;
+			rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
+			break;
+		} /* RTE_FLOW_ACTION_TYPE_METER */
+
 		default:
 			return -ENOTSUP;
 		}
@@ -1577,6 +1672,34 @@ pmd_flow_validate(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static void set_meter_owner_to_flow(struct pmd_internals *softnic,
+	struct rte_flow *flow,
+	const struct rte_flow_action *action)
+{
+	for ( ; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
+		if (action->type == RTE_FLOW_ACTION_TYPE_VOID)
+			continue;
+
+		if (action->type == RTE_FLOW_ACTION_TYPE_METER) {
+			const struct rte_flow_action_meter *conf = action->conf;
+			struct softnic_mtr_list *ml = &softnic->mtr.mtrs;
+			struct softnic_mtr *m;
+
+			TAILQ_FOREACH(m, ml, node) {
+				if (m->flow == flow) {
+					m->flow = NULL;
+					break;
+				}
+			}
+
+			m = softnic_mtr_find(softnic, conf->mtr_id);
+			m->flow = flow;
+
+			break;
+		}
+	}
+}
+
 static struct rte_flow *
 pmd_flow_create(struct rte_eth_dev *dev,
 	const struct rte_flow_attr *attr,
@@ -1717,6 +1840,8 @@ pmd_flow_create(struct rte_eth_dev *dev,
 	flow->pipeline = pipeline;
 	flow->table_id = table_id;
 
+	set_meter_owner_to_flow(softnic, flow, action);
+
 	/* Flow add to list. */
 	if (new_flow)
 		TAILQ_INSERT_TAIL(&table->flows, flow, node);
@@ -1724,6 +1849,31 @@ pmd_flow_create(struct rte_eth_dev *dev,
 	return flow;
 }
 
+static void reset_meter_owner(struct pmd_internals *softnic,
+	struct softnic_table *table,
+	struct rte_flow *flow)
+{
+	struct softnic_table_action_profile *profile;
+	struct softnic_table_action_profile_params *params;
+
+	profile = softnic_table_action_profile_find(softnic,
+		table->params.action_profile_name);
+
+	params = &profile->params;
+
+	if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) {
+		struct softnic_mtr_list *ml = &softnic->mtr.mtrs;
+		struct softnic_mtr *m;
+
+		TAILQ_FOREACH(m, ml, node) {
+			if (m->flow == flow) {
+				m->flow = NULL;
+				break;
+			}
+		}
+	}
+}
+
 static int
 pmd_flow_destroy(struct rte_eth_dev *dev,
 	struct rte_flow *flow,
@@ -1759,6 +1909,9 @@ pmd_flow_destroy(struct rte_eth_dev *dev,
 	TAILQ_REMOVE(&table->flows, flow, node);
 	free(flow);
 
+	/* Update dependencies */
+	reset_meter_owner(softnic, table, flow);
+
 	return 0;
 }
 
-- 
2.9.3

  parent reply	other threads:[~2018-09-12 16:41 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-07 18:13 [dpdk-dev] [PATCH 00/10] net/softnic: implement metering and policing API Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 01/10] net/softnic: add metering and policing support Jasvinder Singh
2018-09-12 16:41   ` [dpdk-dev] [PATCH v2 00/10] net/softnic: implement metering and policing API Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 01/10] net/softnic: add metering and policing support Jasvinder Singh
2018-09-14 17:45       ` [dpdk-dev] [PATCH v3 00/10] net/softnic: implement metering and policing API Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 01/10] net/softnic: add metering and policing support Jasvinder Singh
2018-09-18 16:58           ` [dpdk-dev] [PATCH v4 00/10] net/softnic: implement metering and policing API Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 01/10] net/softnic: add metering and policing support Jasvinder Singh
2018-09-26 13:08               ` [dpdk-dev] [PATCH v5 00/10] net/softnic: implement metering and policing API Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 01/10] net/softnic: add metering and policing support Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 02/10] net/softnic: add meter profile Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 03/10] net/softnic: delete " Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 04/10] net/softnic: create meter object Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 05/10] net/softnic: destroy " Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 06/10] net/softnic: update meter profile Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 07/10] net/softnic: update dscp table Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 08/10] net/softnic: update policer actions Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 09/10] net/softnic: meter stats read Jasvinder Singh
2018-09-26 13:08                 ` [dpdk-dev] [PATCH v5 10/10] net/softnic: enable flow rule with meter action Jasvinder Singh
2018-09-28 10:36                 ` [dpdk-dev] [PATCH v5 00/10] net/softnic: implement metering and policing API Dumitrescu, Cristian
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 02/10] net/softnic: add meter profile Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 03/10] net/softnic: delete " Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 04/10] net/softnic: create meter object Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 05/10] net/softnic: destroy " Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 06/10] net/softnic: update meter profile Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 07/10] net/softnic: update dscp table Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 08/10] net/softnic: update policer actions Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 09/10] net/softnic: meter stats read Jasvinder Singh
2018-09-18 16:58             ` [dpdk-dev] [PATCH v4 10/10] net/softnic: enable flow rule with meter action Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 02/10] net/softnic: add meter profile Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 03/10] net/softnic: delete " Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 04/10] net/softnic: create meter object Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 05/10] net/softnic: destroy " Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 06/10] net/softnic: update meter profile Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 07/10] net/softnic: update dscp table Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 08/10] net/softnic: update policer actions Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 09/10] net/softnic: meter stats read Jasvinder Singh
2018-09-14 17:45         ` [dpdk-dev] [PATCH v3 10/10] net/softnic: enable flow rule with meter action Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 02/10] net/softnic: add meter profile Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 03/10] net/softnic: delete " Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 04/10] net/softnic: create meter object Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 05/10] net/softnic: destroy " Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 06/10] net/softnic: update meter profile Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 07/10] net/softnic: update dscp table Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 08/10] net/softnic: update policer actions Jasvinder Singh
2018-09-12 16:41     ` [dpdk-dev] [PATCH v2 09/10] net/softnic: meter stats read Jasvinder Singh
2018-09-12 16:41     ` Jasvinder Singh [this message]
2018-09-07 18:13 ` [dpdk-dev] [PATCH 02/10] net/softnic: add meter profile Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 03/10] net/softnic: delete " Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 04/10] net/softnic: create meter object Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 05/10] net/softnic: destroy " Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 06/10] net/softnic: update meter profile Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 07/10] net/softnic: update dscp table Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 08/10] net/softnic: update policer actions Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 09/10] net/softnic: meter stats read Jasvinder Singh
2018-09-07 18:13 ` [dpdk-dev] [PATCH 10/10] net/softnic: enable meter action using flow rule Jasvinder Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180912164138.55800-11-jasvinder.singh@intel.com \
    --to=jasvinder.singh@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).