DPDK patches and discussions
 help / color / mirror / Atom feed
From: Amit Prakash Shukla <amitprakashs@marvell.com>
To: Jerin Jacob <jerinj@marvell.com>,
	Kiran Kumar K <kirankumark@marvell.com>,
	 Nithin Dabilpuram <ndabilpuram@marvell.com>
Cc: <dev@dpdk.org>, Amit Prakash Shukla <amitprakashs@marvell.com>
Subject: [PATCH v4 3/3] l3fwd-graph: changes to configure pcap capture
Date: Tue, 24 Jan 2023 16:51:38 +0530	[thread overview]
Message-ID: <20230124112139.1426279-3-amitprakashs@marvell.com> (raw)
In-Reply-To: <20230124112139.1426279-1-amitprakashs@marvell.com>

Added support to configure pcap capture.

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
---
v2:
 - Fixed code style issue
 - Fixed CI compilation issue on github-robot

v3:
 - Code review suggestion from Stephen
 - Fixed potential memory leak
 
v4:
 - Code review suggestion from Jerin

 doc/guides/sample_app_ug/l3_forward_graph.rst | 23 +++++++
 examples/l3fwd-graph/main.c                   | 62 ++++++++++++++++++-
 2 files changed, 83 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..3043dba8e2 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]
+                                   [--pcap-num-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.
+
+* ``--pcap-num-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.
 
@@ -99,6 +108,20 @@ In this command:
 |          |           |           |                                     |
 +----------+-----------+-----------+-------------------------------------+
 
+To enable pcap trace on each graph, use following command:
+
+.. code-block:: console
+
+    ./<build_dir>/examples/dpdk-l3fwd-graph -l 1,2 -n 4 -- -p 0x3 --config="(0,0,1),(1,0,2)" --pcap-enable --pcap-num-cap=<number of packets> --pcap-file-name "</filepath/filename>"
+
+In this command:
+
+*   The --pcap-enable option enables pcap trace on graph nodes.
+
+*   The --pcap-num-cap option enables user to configure number packets to be captured per graph. Default 1024 packets per graph are captured.
+
+*   The --pcap-file-name option enables user to give filename in which packets are to be captured.
+
 Refer to the *DPDK Getting Started Guide* for general information on running applications and
 the Environment Abstraction Layer (EAL) options.
 
diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c
index 6dcb6ee92b..5feeab4f0f 100644
--- a/examples/l3fwd-graph/main.c
+++ b/examples/l3fwd-graph/main.c
@@ -76,6 +76,12 @@ xmm_t val_eth[RTE_MAX_ETHPORTS];
 /* Mask of enabled ports */
 static uint32_t enabled_port_mask;
 
+/* Pcap trace */
+static char pcap_filename[RTE_GRAPH_PCAP_FILE_SZ];
+static uint64_t packet_to_capture;
+static int pcap_trace_enable;
+
+
 struct lcore_rx_queue {
 	uint16_t port_id;
 	uint8_t queue_id;
@@ -261,7 +267,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 +277,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"
+		"  --pcap-num-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 +431,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   "pcap-num-cap"
+#define CMD_LINE_OPT_PCAP_FILENAME "pcap-file-name"
 enum {
 	/* Long options mapped to a short option */
 
@@ -416,6 +446,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 +457,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},
 };
 
@@ -498,6 +534,23 @@ parse_args(int argc, char **argv)
 			per_port_pool = 1;
 			break;
 
+		case CMD_LINE_OPT_PARSE_PCAP_ENABLE:
+			printf("Packet capture enabled\n");
+			pcap_trace_enable = 1;
+			break;
+
+		case CMD_LINE_OPT_PARSE_NUM_PKT_CAP:
+			packet_to_capture = parse_num_pkt_cap(optarg);
+			printf("Number of packets to capture: %"PRIu64"\n",
+			       packet_to_capture);
+			break;
+
+		case CMD_LINE_OPT_PCAP_FILENAME_CAP:
+			rte_strlcpy(pcap_filename, optarg,
+				    sizeof(pcap_filename));
+			printf("Pcap file name: %s\n", pcap_filename);
+			break;
+
 		default:
 			print_usage(prgname);
 			return -1;
@@ -1027,6 +1080,11 @@ main(int argc, char **argv)
 	memset(&graph_conf, 0, sizeof(graph_conf));
 	graph_conf.node_patterns = node_patterns;
 
+	/* Pcap config */
+	graph_conf.pcap_enable = pcap_trace_enable;
+	graph_conf.num_pkt_to_capture = packet_to_capture;
+	graph_conf.pcap_filename = pcap_filename;
+
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
 		rte_graph_t graph_id;
 		rte_edge_t i;
-- 
2.25.1


  parent reply	other threads:[~2023-01-24 11:23 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-23 12:02 [RFC PATCH] graph: add support for pcap trace for graph Amit Prakash Shukla
2022-12-23 16:47 ` Stephen Hemminger
2023-01-06 10:40   ` [EXT] " Amit Prakash Shukla
2023-01-06 16:41     ` Stephen Hemminger
2023-01-06 18:56     ` Stephen Hemminger
2023-01-10 11:26       ` Amit Prakash Shukla
2023-01-10 11:58 ` [PATCH v1 1/3] pcapng: comment option support for epb Amit Prakash Shukla
2023-01-10 11:58   ` [PATCH v1 2/3] graph: pcap capture for graph nodes Amit Prakash Shukla
2023-01-10 11:58   ` [PATCH v1 3/3] l3fwd-graph: changes to configure pcap capture Amit Prakash Shukla
2023-01-10 17:05   ` [PATCH v1 1/3] pcapng: comment option support for epb Stephen Hemminger
2023-01-11  8:53   ` [PATCH v2 " Amit Prakash Shukla
2023-01-11  8:53     ` [PATCH v2 2/3] graph: pcap capture for graph nodes Amit Prakash Shukla
2023-01-11 16:07       ` Stephen Hemminger
2023-01-12  9:57         ` [EXT] " Amit Prakash Shukla
2023-01-12 16:30           ` Stephen Hemminger
2023-01-19 14:37             ` Amit Prakash Shukla
2023-01-19 16:48               ` Stephen Hemminger
2023-01-11  8:53     ` [PATCH v2 3/3] l3fwd-graph: changes to configure pcap capture Amit Prakash Shukla
2023-01-12 10:01     ` [PATCH v3 1/3] pcapng: comment option support for epb Amit Prakash Shukla
2023-01-12 10:01       ` [PATCH v3 2/3] graph: pcap capture for graph nodes Amit Prakash Shukla
2023-01-12 12:18         ` Jerin Jacob
2023-01-19 14:21           ` [EXT] " Amit Prakash Shukla
2023-01-12 10:01       ` [PATCH v3 3/3] l3fwd-graph: changes to configure pcap capture Amit Prakash Shukla
2023-01-24 11:21       ` [PATCH v4 1/3] pcapng: comment option support for epb Amit Prakash Shukla
2023-01-24 11:21         ` [PATCH v4 2/3] graph: pcap capture for graph nodes Amit Prakash Shukla
2023-01-31  8:06           ` Jerin Jacob
2023-02-03  8:15             ` [EXT] " Amit Prakash Shukla
2023-01-24 11:21         ` Amit Prakash Shukla [this message]
2023-01-31  8:14           ` [PATCH v4 3/3] l3fwd-graph: changes to configure pcap capture Jerin Jacob
2023-02-03  8:16             ` [EXT] " Amit Prakash Shukla
2023-02-03  8:19         ` [PATCH v5 1/3] pcapng: comment option support for epb Amit Prakash Shukla
2023-02-03  8:19           ` [PATCH v5 2/3] graph: pcap capture for graph nodes Amit Prakash Shukla
2023-02-09  9:12             ` David Marchand
2023-02-09  9:29               ` [EXT] " Amit Prakash Shukla
2023-02-03  8:19           ` [PATCH v5 3/3] examples/l3fwd-graph: changes to configure pcap capture Amit Prakash Shukla
2023-02-09  9:13           ` [PATCH v5 1/3] pcapng: comment option support for epb David Marchand
2023-02-09 16:48             ` Stephen Hemminger
2023-02-09  9:56           ` [PATCH v6 1/4] " Amit Prakash Shukla
2023-02-09  9:56             ` [PATCH v6 2/4] graph: pcap capture for graph nodes Amit Prakash Shukla
2023-02-09  9:56             ` [PATCH v6 3/4] examples/l3fwd-graph: changes to configure pcap capture Amit Prakash Shukla
2023-02-09  9:56             ` [PATCH v6 4/4] test/graph: initialize graph param variable Amit Prakash Shukla
2023-02-09 10:03             ` [PATCH v6 1/4] pcapng: comment option support for epb Amit Prakash Shukla
2023-02-09 10:24             ` [PATCH v7 1/3] " Amit Prakash Shukla
2023-02-09 10:24               ` [PATCH v7 2/3] graph: pcap capture for graph nodes Amit Prakash Shukla
2023-02-09 10:24               ` [PATCH v7 3/3] examples/l3fwd-graph: changes to configure pcap capture Amit Prakash Shukla
2023-02-09 17:28                 ` Jerin Jacob
2023-02-10 12:18                   ` David Marchand

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=20230124112139.1426279-3-amitprakashs@marvell.com \
    --to=amitprakashs@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=kirankumark@marvell.com \
    --cc=ndabilpuram@marvell.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).