From: Reshma Pattan <reshma.pattan@intel.com>
To: dev@dpdk.org
Cc: Cristian Dumitrescu <cristian.dumitrescu@intel.com>,
Reshma Pattan <reshma.pattan@intel.com>
Subject: [dpdk-dev] [PATCH 12/15] net/softnic: add flow create API
Date: Thu, 6 Sep 2018 17:26:59 +0100 [thread overview]
Message-ID: <1536251222-17275-13-git-send-email-reshma.pattan@intel.com> (raw)
In-Reply-To: <1536251222-17275-1-git-send-email-reshma.pattan@intel.com>
pmd_flow_create API is added to support
rte flow create.
Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
drivers/net/softnic/rte_eth_softnic_flow.c | 174 +++++++++++++++++++++++++++++
1 file changed, 174 insertions(+)
diff --git a/drivers/net/softnic/rte_eth_softnic_flow.c b/drivers/net/softnic/rte_eth_softnic_flow.c
index 351d34524..034bca047 100644
--- a/drivers/net/softnic/rte_eth_softnic_flow.c
+++ b/drivers/net/softnic/rte_eth_softnic_flow.c
@@ -1,13 +1,39 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Intel Corporation
*/
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rte_common.h>
+#include <rte_byteorder.h>
+#include <rte_malloc.h>
+#include <rte_string_fns.h>
+#include <rte_flow.h>
+#include <rte_flow_driver.h>
#include "rte_eth_softnic_internals.h"
#include "rte_eth_softnic.h"
+#define rte_htons rte_cpu_to_be_16
+#define rte_htonl rte_cpu_to_be_32
+
#define rte_ntohs rte_be_to_cpu_16
#define rte_ntohl rte_be_to_cpu_32
+static struct rte_flow *
+softnic_flow_find(struct softnic_table *table,
+ struct softnic_table_rule_match *rule_match)
+{
+ struct rte_flow *flow;
+
+ TAILQ_FOREACH(flow, &table->flows, node)
+ if (memcmp(&flow->match, rule_match, sizeof(*rule_match)) == 0)
+ return flow;
+
+ return NULL;
+}
+
int
flow_attr_map_set(struct pmd_internals *softnic,
uint32_t group_id,
@@ -1428,6 +1454,154 @@ pmd_flow_validate(struct rte_eth_dev *dev,
return 0;
}
+static struct rte_flow *
+pmd_flow_create(struct rte_eth_dev *dev,
+ const struct rte_flow_attr *attr,
+ const struct rte_flow_item item[],
+ const struct rte_flow_action action[],
+ struct rte_flow_error *error)
+{
+ struct softnic_table_rule_match rule_match;
+ struct softnic_table_rule_action rule_action;
+ void *rule_data;
+
+ struct pmd_internals *softnic = dev->data->dev_private;
+ struct pipeline *pipeline;
+ struct softnic_table *table;
+ struct rte_flow *flow;
+ const char *pipeline_name = NULL;
+ uint32_t table_id = 0;
+ int new_flow, status;
+
+ /* Check input parameters. */
+ if (attr == NULL) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_ATTR,
+ NULL,
+ "Null attr");
+ return NULL;
+ }
+
+ if (item == NULL) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_ITEM,
+ NULL,
+ "Null item");
+ return NULL;
+ }
+
+ if (action == NULL) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ NULL,
+ "Null action");
+ return NULL;
+ }
+
+ /* Identify the pipeline table to add this flow to. */
+ status = flow_pipeline_table_get(softnic, attr, &pipeline_name,
+ &table_id, error);
+ if (status)
+ return NULL;
+
+ pipeline = softnic_pipeline_find(softnic, pipeline_name);
+ if (pipeline == NULL) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL,
+ "Invalid pipeline name");
+ return NULL;
+ }
+
+ if (table_id >= pipeline->n_tables) {
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL,
+ "Invalid pipeline table ID");
+ return NULL;
+ }
+
+ table = &pipeline->table[table_id];
+
+ /* Rule match. */
+ memset(&rule_match, 0, sizeof(rule_match));
+ status = flow_rule_match_get(softnic,
+ pipeline,
+ table,
+ attr,
+ item,
+ &rule_match,
+ error);
+ if (status)
+ return NULL;
+
+ /* Rule action. */
+ memset(&rule_action, 0, sizeof(rule_action));
+ status = flow_rule_action_get(softnic,
+ pipeline,
+ table,
+ attr,
+ action,
+ &rule_action,
+ error);
+ if (status)
+ return NULL;
+
+ /* Flow find/allocate. */
+ new_flow = 0;
+ flow = softnic_flow_find(table, &rule_match);
+ if (flow == NULL) {
+ new_flow = 1;
+ flow = calloc(1, sizeof(struct rte_flow));
+ if (flow == NULL) {
+ rte_flow_error_set(error,
+ ENOMEM,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL,
+ "Not enough memory for new flow");
+ return NULL;
+ }
+ }
+
+ /* Rule add. */
+ status = softnic_pipeline_table_rule_add(softnic,
+ pipeline_name,
+ table_id,
+ &rule_match,
+ &rule_action,
+ &rule_data);
+ if (status) {
+ if (new_flow)
+ free(flow);
+
+ rte_flow_error_set(error,
+ EINVAL,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL,
+ "Pipeline table rule add failed");
+ return NULL;
+ }
+
+ /* Flow fill in. */
+ memcpy(&flow->match, &rule_match, sizeof(rule_match));
+ memcpy(&flow->action, &rule_action, sizeof(rule_action));
+ flow->data = rule_data;
+ flow->pipeline = pipeline;
+ flow->table_id = table_id;
+
+ /* Flow add to list. */
+ if (new_flow)
+ TAILQ_INSERT_TAIL(&table->flows, flow, node);
+
+ return flow;
+}
+
const struct rte_flow_ops pmd_flow_ops = {
.validate = pmd_flow_validate,
+ .create = pmd_flow_create,
};
--
2.14.4
next prev parent reply other threads:[~2018-09-06 16:27 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-06 16:26 [dpdk-dev] [PATCH 00/15] add flow API support to softnic Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 01/15] net/softnic: add infrastructure for flow API Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 02/15] net/softnic: rte flow attr mapping to pipeline Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 03/15] net/softnic: add new cli for flow attribute map Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 04/15] net/softnic: various data type changes Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 05/15] net/softnic: add free table and find out port functions Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 06/15] net/softnic: add function to get eth device from softnic Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 07/15] net/softnic: flow API validate support Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 08/15] net/softnic: validate and map flow rule with acl table match Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 09/15] net/softnic: parse flow protocol for " Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 10/15] net/softnic: validate and map flow with hash " Reshma Pattan
2018-09-06 16:26 ` [dpdk-dev] [PATCH 11/15] net/softnic: validate and map flow action with table action Reshma Pattan
2018-09-06 16:26 ` Reshma Pattan [this message]
2018-09-06 16:27 ` [dpdk-dev] [PATCH 13/15] net/softnic: add flow destroy API Reshma Pattan
2018-09-06 16:27 ` [dpdk-dev] [PATCH 14/15] net/softnic: add flow query API Reshma Pattan
2018-09-06 16:27 ` [dpdk-dev] [PATCH 15/15] net/softnic: add parsing for raw flow item Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 00/15] add flow API support to softnic Reshma Pattan
2018-09-28 10:36 ` Dumitrescu, Cristian
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 01/15] net/softnic: add infrastructure for flow API Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 02/15] net/softnic: map flow attributes to pipeline table Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 03/15] net/softnic: add new cli for flow attribute map Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 04/15] net/softnic: replace some pointers with arrays Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 05/15] net/softnic: add free table and find out port functions Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 06/15] net/softnic: add function to get eth device from softnic Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 07/15] net/softnic: implement flow validate API Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 08/15] net/softnic: validate and map flow rule with acl table match Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 09/15] net/softnic: parse flow protocol for " Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 10/15] net/softnic: validate and map flow with hash " Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 11/15] net/softnic: validate and map flow action with table action Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 12/15] net/softnic: add flow create API Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 13/15] net/softnic: add flow destroy API Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 14/15] net/softnic: add flow query API Reshma Pattan
2018-09-11 14:20 ` [dpdk-dev] [PATCH v2 15/15] net/softnic: add parsing for raw flow item Reshma Pattan
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=1536251222-17275-13-git-send-email-reshma.pattan@intel.com \
--to=reshma.pattan@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).