From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 19F762C54 for ; Thu, 23 Nov 2017 17:15:08 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Nov 2017 08:15:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,441,1505804400"; d="scan'208";a="5225923" Received: from silpixa00389036.ir.intel.com (HELO silpixa00389036.ger.corp.intel.com) ([10.237.223.231]) by fmsmga004.fm.intel.com with ESMTP; 23 Nov 2017 08:15:06 -0800 From: Kirill Rybalchenko To: dev@dpdk.org Cc: kirill.rybalchenko@intel.com, andrey.chilikin@intel.com, beilei.xing@intel.com, jingjing.wu@intel.com Date: Thu, 23 Nov 2017 16:15:00 +0000 Message-Id: <1511453701-117320-2-git-send-email-kirill.rybalchenko@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1511453701-117320-1-git-send-email-kirill.rybalchenko@intel.com> References: <1511453701-117320-1-git-send-email-kirill.rybalchenko@intel.com> Subject: [dpdk-dev] [PATCH 1/2] app/testpmd: add raw flowtype mode for flow director filter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Nov 2017 16:15:09 -0000 Add possibility to load file with raw packet and set it as a template for flow director filter setup. Signed-off-by: Kirill Rybalchenko --- 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