From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9BF68423B5; Thu, 12 Jan 2023 11:01:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 90AD542D27; Thu, 12 Jan 2023 11:01:48 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id BEEA242D23 for ; Thu, 12 Jan 2023 11:01:47 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30C9dqmB004927 for ; Thu, 12 Jan 2023 02:01:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=XB+j2vjKOHjpdIcofHat2kykAYJvLKH32lkT/hGOwog=; b=lDWp8F5ebfF5vL92RbIBl0zJPP62oziCbAj+uRwmBWTx/wSDerBSE4FUs841oyaQ1Sho I1RF0ZNufxuqJ2w6qFxyysZD4Tk/j0jXcpFQS5e8J2qZib05d/GzMlqJn4tvBvqrQNWW 6Dpb6NMVxdhtgV/g/+AL/ZY05jdHsdMMWc/KX4gz+xHc31rq5kik5ASc4dIgFsuSvdQr Ql/V7TsXrM9/Gpb3e5lEdIv7IjnJsAEbAZYfinv4igDXC3IzvHqW+mD1DPtGIjgm2c8E Tq/CWPkpWusEYTG5TMPgJ2OMYT5/wxGNod3e/QOgx9D3k0wqVhf2gM++evsDcRcaTc+A gA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3n23b2hmbt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 12 Jan 2023 02:01:46 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 12 Jan 2023 02:01:44 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 12 Jan 2023 02:01:44 -0800 Received: from localhost.localdomain (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id 0FA023F707E; Thu, 12 Jan 2023 02:01:42 -0800 (PST) From: Amit Prakash Shukla To: Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram CC: , Amit Prakash Shukla Subject: [PATCH v3 3/3] l3fwd-graph: changes to configure pcap capture Date: Thu, 12 Jan 2023 15:31:06 +0530 Message-ID: <20230112100106.2180665-3-amitprakashs@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230112100106.2180665-1-amitprakashs@marvell.com> References: <20230111085343.2058993-1-amitprakashs@marvell.com> <20230112100106.2180665-1-amitprakashs@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: 6Vpu-7RIAIaZ3ASYFc2Siu5z3gpp_8Jf X-Proofpoint-ORIG-GUID: 6Vpu-7RIAIaZ3ASYFc2Siu5z3gpp_8Jf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-12_06,2023-01-12_01,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Added support to configure pcap capture. Signed-off-by: Amit Prakash Shukla --- v2: - Fixed code style issue - Fixed CI compilation issue on github-robot v3: - Code review suggestion from Stephen - Fixed potential memory leak doc/guides/sample_app_ug/l3_forward_graph.rst | 9 +++ examples/l3fwd-graph/main.c | 58 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/doc/guides/sample_app_ug/l3_forward_graph.rst b/doc/guides/sample_app_ug/l3_forward_graph.rst index 0a3e0d44ec..e0935eaae3 100644 --- a/doc/guides/sample_app_ug/l3_forward_graph.rst +++ b/doc/guides/sample_app_ug/l3_forward_graph.rst @@ -51,6 +51,9 @@ The application has a number of command line options similar to l3fwd:: [--max-pkt-len PKTLEN] [--no-numa] [--per-port-pool] + [--pcap-enable] + [--num-pkt-cap] + [--pcap-file-name] Where, @@ -69,6 +72,12 @@ Where, * ``--per-port-pool:`` Optional, set to use independent buffer pools per port. Without this option, single buffer pool is used for all ports. +* ``--pcap-enable:`` Optional, Enables packet capture in pcap format on each node with mbuf and node metadata. + +* ``--num-pkt-cap:`` Optional, Number of packets to be captured per core. + +* ``--pcap-file-name:`` Optional, Pcap filename to capture packets in. + For example, consider a dual processor socket platform with 8 physical cores, where cores 0-7 and 16-23 appear on socket 0, while cores 8-15 and 24-31 appear on socket 1. diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c index 6dcb6ee92b..0b30ebbd83 100644 --- a/examples/l3fwd-graph/main.c +++ b/examples/l3fwd-graph/main.c @@ -261,7 +261,8 @@ print_usage(const char *prgname) " [--eth-dest=X,MM:MM:MM:MM:MM:MM]" " [--max-pkt-len PKTLEN]" " [--no-numa]" - " [--per-port-pool]\n\n" + " [--per-port-pool]" + " [--num-pkt-cap]\n\n" " -p PORTMASK: Hexadecimal bitmask of ports to configure\n" " -P : Enable promiscuous mode\n" @@ -270,10 +271,30 @@ print_usage(const char *prgname) "port X\n" " --max-pkt-len PKTLEN: maximum packet length in decimal (64-9600)\n" " --no-numa: Disable numa awareness\n" - " --per-port-pool: Use separate buffer pool per port\n\n", + " --per-port-pool: Use separate buffer pool per port\n" + " --pcap-enable: Enables pcap capture\n" + " --num-pkt-cap NUMPKT: Number of packets to capture\n" + " --pcap-file-name NAME: Pcap file name\n\n", prgname); } +static uint64_t +parse_num_pkt_cap(const char *num_pkt_cap) +{ + uint64_t num_pkt; + char *end = NULL; + + /* Parse decimal string */ + num_pkt = strtoull(num_pkt_cap, &end, 10); + if ((num_pkt_cap[0] == '\0') || (end == NULL) || (*end != '\0')) + return 0; + + if (num_pkt == 0) + return 0; + + return num_pkt; +} + static int parse_max_pkt_len(const char *pktlen) { @@ -404,6 +425,9 @@ static const char short_options[] = "p:" /* portmask */ #define CMD_LINE_OPT_NO_NUMA "no-numa" #define CMD_LINE_OPT_MAX_PKT_LEN "max-pkt-len" #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool" +#define CMD_LINE_OPT_PCAP_ENABLE "pcap-enable" +#define CMD_LINE_OPT_NUM_PKT_CAP "num-pkt-cap" +#define CMD_LINE_OPT_PCAP_FILENAME "pcap-file-name" enum { /* Long options mapped to a short option */ @@ -416,6 +440,9 @@ enum { CMD_LINE_OPT_NO_NUMA_NUM, CMD_LINE_OPT_MAX_PKT_LEN_NUM, CMD_LINE_OPT_PARSE_PER_PORT_POOL, + CMD_LINE_OPT_PARSE_PCAP_ENABLE, + CMD_LINE_OPT_PARSE_NUM_PKT_CAP, + CMD_LINE_OPT_PCAP_FILENAME_CAP, }; static const struct option lgopts[] = { @@ -424,6 +451,9 @@ static const struct option lgopts[] = { {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM}, {CMD_LINE_OPT_MAX_PKT_LEN, 1, 0, CMD_LINE_OPT_MAX_PKT_LEN_NUM}, {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL}, + {CMD_LINE_OPT_PCAP_ENABLE, 0, 0, CMD_LINE_OPT_PARSE_PCAP_ENABLE}, + {CMD_LINE_OPT_NUM_PKT_CAP, 1, 0, CMD_LINE_OPT_PARSE_NUM_PKT_CAP}, + {CMD_LINE_OPT_PCAP_FILENAME, 1, 0, CMD_LINE_OPT_PCAP_FILENAME_CAP}, {NULL, 0, 0, 0}, }; @@ -448,6 +478,7 @@ parse_args(int argc, char **argv) int option_index; char **argvopt; int opt, ret; + uint64_t num_pkt; argvopt = argv; @@ -498,6 +529,23 @@ parse_args(int argc, char **argv) per_port_pool = 1; break; + case CMD_LINE_OPT_PARSE_PCAP_ENABLE: + printf("Packet capture enabled\n"); + rte_pcap_trace_enable(1); + break; + + case CMD_LINE_OPT_PARSE_NUM_PKT_CAP: + num_pkt = parse_num_pkt_cap(optarg); + rte_num_pkt_to_capture(num_pkt); + printf("Number of packets to capture: %"PRIu64"\n", + num_pkt); + break; + + case CMD_LINE_OPT_PCAP_FILENAME_CAP: + rte_filename_to_capture_pkt(optarg); + printf("Pcap file name: %s\n", optarg); + break; + default: print_usage(prgname); return -1; @@ -635,6 +683,7 @@ signal_handler(int signum) if (signum == SIGINT || signum == SIGTERM) { printf("\n\nSignal %d received, preparing to exit...\n", signum); + rte_graph_pcap_trace_exit(); force_quit = true; } } @@ -1015,6 +1064,11 @@ main(int argc, char **argv) check_all_ports_link_status(enabled_port_mask); + if (rte_pcap_trace_is_enable()) { + if (rte_graph_pcap_trace_init() < 0) + rte_pcap_trace_enable(0); + } + /* Graph Initialization */ nb_patterns = RTE_DIM(default_patterns); node_patterns = malloc((MAX_RX_QUEUE_PER_LCORE + nb_patterns) * -- 2.25.1