DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kirill Rybalchenko <kirill.rybalchenko@intel.com>
To: dev@dpdk.org
Cc: kirill.rybalchenko@intel.com, andrey.chilikin@intel.com,
	beilei.xing@intel.com, jingjing.wu@intel.com
Subject: [dpdk-dev] [PATCH 1/2] app/testpmd: add raw flowtype mode for flow director filter
Date: Thu, 23 Nov 2017 16:15:00 +0000	[thread overview]
Message-ID: <1511453701-117320-2-git-send-email-kirill.rybalchenko@intel.com> (raw)
In-Reply-To: <1511453701-117320-1-git-send-email-kirill.rybalchenko@intel.com>

Add possibility to load file with raw packet and set it
as a template for flow director filter setup.

Signed-off-by: Kirill Rybalchenko <kirill.rybalchenko@intel.com>
---
 app/test-pmd/cmdline.c | 116 ++++++++++++++++++++++++++++++++++++++++++++-----
 app/test-pmd/config.c  |   8 ++--
 app/test-pmd/testpmd.h |   6 +--
 3 files changed, 112 insertions(+), 18 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index f71d963..86178ae 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -979,6 +979,11 @@ static void cmd_help_long_parsed(void *parsed_result,
 			" queue (queue_id) fd_id (fd_id_value)\n"
 			"    Add/Del a Tunnel flow director filter.\n\n"
 
+			"flow_director_filter (port_id) mode raw (add|del|update)"
+			" flow (flow_id) (drop|fwd) queue (queue_id)"
+			" fd_id (fd_id_value) packet (packet file name)\n"
+			"    Add/Del a raw type flow director filter.\n\n"
+
 			"flush_flow_director (port_id)\n"
 			"    Flush all flow director entries of a device.\n\n"
 
@@ -9769,6 +9774,8 @@ struct cmd_flow_director_result {
 	cmdline_fixed_string_t tunnel_type;
 	cmdline_fixed_string_t tunnel_id;
 	uint32_t tunnel_id_value;
+	cmdline_fixed_string_t packet;
+	char filepath[];
 };
 
 static inline int
@@ -9918,8 +9925,62 @@ cmd_flow_director_filter_parsed(void *parsed_result,
 			return;
 		}
 	} else {
-		if (strcmp(res->mode_value, "IP")) {
-			printf("Please set mode to IP.\n");
+		if (!strcmp(res->mode_value, "raw")) {
+#ifdef RTE_LIBRTE_I40E_PMD
+			struct rte_pmd_i40e_flow_type_mapping
+					mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
+			struct rte_pmd_i40e_pkt_template_conf conf;
+			uint16_t flow_type = str2flowtype(res->flow_type);
+			uint16_t i, port = res->port_id;
+			uint8_t add;
+
+			memset(&conf, 0, sizeof(conf));
+
+			if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
+				printf("Invalid flow type specified.\n");
+				return;
+			}
+			ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
+								 mapping);
+			if (ret)
+				return;
+			if (mapping[flow_type].pctype == 0ULL) {
+				printf("Invalid flow type specified.\n");
+				return;
+			}
+			for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
+				if (mapping[flow_type].pctype & (1ULL << i)) {
+					conf.input.pctype = i;
+					break;
+				}
+			}
+
+			conf.input.packet = open_file(res->filepath,
+						&conf.input.length);
+			if (!conf.input.packet)
+				return;
+			if (!strcmp(res->drop, "drop"))
+				conf.action.behavior =
+					RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
+			else
+				conf.action.behavior =
+					RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
+			conf.action.report_status =
+					RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
+			conf.action.rx_queue = res->queue_id;
+			conf.soft_id = res->fd_id_value;
+			add  = strcmp(res->ops, "del") ? 1 : 0;
+			ret = rte_pmd_i40e_flow_add_del_packet_template(port,
+									&conf,
+									add);
+			if (ret < 0)
+				printf("flow director config error: (%s)\n",
+				       strerror(-ret));
+			close_file(conf.input.packet);
+#endif
+			return;
+		} else if (strcmp(res->mode_value, "IP")) {
+			printf("Please set mode to IP or raw.\n");
 			return;
 		}
 		entry.input.flow_type = str2flowtype(res->flow_type);
@@ -10091,8 +10152,7 @@ cmdline_parse_token_string_t cmd_flow_director_flow =
 				 flow, "flow");
 cmdline_parse_token_string_t cmd_flow_director_flow_type =
 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
-		flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
-		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
+		flow_type, NULL);
 cmdline_parse_token_string_t cmd_flow_director_ether =
 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
 				 ether, "ether");
@@ -10184,6 +10244,9 @@ cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
 				 mode_value, "Tunnel");
+cmdline_parse_token_string_t cmd_flow_director_mode_raw =
+	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
+				 mode_value, "raw");
 cmdline_parse_token_string_t cmd_flow_director_mac =
 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
 				 mac, "mac");
@@ -10202,6 +10265,12 @@ cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
 			      tunnel_id_value, UINT32);
+cmdline_parse_token_string_t cmd_flow_director_packet =
+	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
+				 packet, "packet");
+cmdline_parse_token_string_t cmd_flow_director_filepath =
+	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
+				 filepath, NULL);
 
 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
 	.f = cmd_flow_director_filter_parsed,
@@ -10405,6 +10474,30 @@ cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
 	},
 };
 
+cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
+	.f = cmd_flow_director_filter_parsed,
+	.data = NULL,
+	.help_str = "flow_director_filter ... : Add or delete a raw flow "
+		"director entry on NIC",
+	.tokens = {
+		(void *)&cmd_flow_director_filter,
+		(void *)&cmd_flow_director_port_id,
+		(void *)&cmd_flow_director_mode,
+		(void *)&cmd_flow_director_mode_raw,
+		(void *)&cmd_flow_director_ops,
+		(void *)&cmd_flow_director_flow,
+		(void *)&cmd_flow_director_flow_type,
+		(void *)&cmd_flow_director_drop,
+		(void *)&cmd_flow_director_queue,
+		(void *)&cmd_flow_director_queue_id,
+		(void *)&cmd_flow_director_fd_id,
+		(void *)&cmd_flow_director_fd_id_value,
+		(void *)&cmd_flow_director_packet,
+		(void *)&cmd_flow_director_filepath,
+		NULL,
+	},
+};
+
 struct cmd_flush_flow_director_result {
 	cmdline_fixed_string_t flush_flow_director;
 	portid_t port_id;
@@ -14220,7 +14313,7 @@ cmd_ddp_add_parsed(
 	}
 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
 
-	buff = open_ddp_package_file(file_fld[0], &size);
+	buff = open_file(file_fld[0], &size);
 	if (!buff) {
 		free((void *)filepath);
 		return;
@@ -14238,9 +14331,9 @@ cmd_ddp_add_parsed(
 	else if (ret < 0)
 		printf("Failed to load profile.\n");
 	else if (file_num == 2)
-		save_ddp_package_file(file_fld[1], buff, size);
+		save_file(file_fld[1], buff, size);
 
-	close_ddp_package_file(buff);
+	close_file(buff);
 	free((void *)filepath);
 }
 
@@ -14295,7 +14388,7 @@ cmd_ddp_del_parsed(
 		return;
 	}
 
-	buff = open_ddp_package_file(res->filepath, &size);
+	buff = open_file(res->filepath, &size);
 	if (!buff)
 		return;
 
@@ -14311,7 +14404,7 @@ cmd_ddp_del_parsed(
 	else if (ret < 0)
 		printf("Failed to delete profile.\n");
 
-	close_ddp_package_file(buff);
+	close_file(buff);
 }
 
 cmdline_parse_inst_t cmd_ddp_del = {
@@ -14371,7 +14464,7 @@ cmd_ddp_info_parsed(
 
 #endif
 
-	pkg = open_ddp_package_file(res->filepath, &pkg_size);
+	pkg = open_file(res->filepath, &pkg_size);
 	if (!pkg)
 		return;
 
@@ -14548,7 +14641,7 @@ cmd_ddp_info_parsed(
 #endif
 	if (ret == -ENOTSUP)
 		printf("Function not supported in PMD driver\n");
-	close_ddp_package_file(pkg);
+	close_file(pkg);
 }
 
 cmdline_parse_inst_t cmd_ddp_get_info = {
@@ -15672,6 +15765,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
+	(cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index cd2ac11..f217ad2 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -3401,7 +3401,7 @@ port_dcb_info_display(portid_t port_id)
 }
 
 uint8_t *
-open_ddp_package_file(const char *file_path, uint32_t *size)
+open_file(const char *file_path, uint32_t *size)
 {
 	int fd = open(file_path, O_RDONLY);
 	off_t pkg_size;
@@ -3441,7 +3441,7 @@ open_ddp_package_file(const char *file_path, uint32_t *size)
 	if (ret < 0) {
 		close(fd);
 		printf("%s: File read operation failed\n", __func__);
-		close_ddp_package_file(buf);
+		close_file(buf);
 		return NULL;
 	}
 
@@ -3454,7 +3454,7 @@ open_ddp_package_file(const char *file_path, uint32_t *size)
 }
 
 int
-save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size)
+save_file(const char *file_path, uint8_t *buf, uint32_t size)
 {
 	FILE *fh = fopen(file_path, "wb");
 
@@ -3475,7 +3475,7 @@ save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size)
 }
 
 int
-close_ddp_package_file(uint8_t *buf)
+close_file(uint8_t *buf)
 {
 	if (buf) {
 		free((void *)buf);
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 1639d27..640ea92 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -715,9 +715,9 @@ void mcast_addr_add(portid_t port_id, struct ether_addr *mc_addr);
 void mcast_addr_remove(portid_t port_id, struct ether_addr *mc_addr);
 void port_dcb_info_display(portid_t port_id);
 
-uint8_t *open_ddp_package_file(const char *file_path, uint32_t *size);
-int save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size);
-int close_ddp_package_file(uint8_t *buf);
+uint8_t *open_file(const char *file_path, uint32_t *size);
+int save_file(const char *file_path, uint8_t *buf, uint32_t size);
+int close_file(uint8_t *buf);
 
 void port_queue_region_info_display(portid_t port_id, void *buf);
 
-- 
2.5.5

  reply	other threads:[~2017-11-23 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-23 16:14 [dpdk-dev] [PATCH 0/2] " Kirill Rybalchenko
2017-11-23 16:15 ` Kirill Rybalchenko [this message]
2018-01-10  0:58   ` [dpdk-dev] [PATCH 1/2] app/testpmd: " Lu, Wenzhuo
2018-01-10  2:55   ` Lu, Wenzhuo
2017-11-23 16:15 ` [dpdk-dev] [PATCH 2/2] doc: add description of raw mode in flow director in testpmd Kirill Rybalchenko
2017-12-11 15:01   ` Mcnamara, John
2018-01-10 14:09 ` [dpdk-dev] [PATCH 0/2] add raw flowtype mode for flow director filter Zhang, Helin

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=1511453701-117320-2-git-send-email-kirill.rybalchenko@intel.com \
    --to=kirill.rybalchenko@intel.com \
    --cc=andrey.chilikin@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    /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).