DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Aman Singh <aman.deep.singh@intel.com>
Subject: [PATCH v10 6/8] test-pmd: add hex decode
Date: Sun, 27 Oct 2024 19:19:32 -0700	[thread overview]
Message-ID: <20241028022131.142609-7-stephen@networkplumber.org> (raw)
In-Reply-To: <20241028022131.142609-1-stephen@networkplumber.org>

This adds new command:
   testpmd> set format hex
which decodes packet in hex.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test-pmd/cmdline.c                      | 40 +++++++++++++++
 app/test-pmd/config.c                       | 11 +++++
 app/test-pmd/testpmd.c                      |  1 +
 app/test-pmd/testpmd.h                      |  7 +++
 app/test-pmd/util.c                         | 54 ++++++++++++++++-----
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 13 +++++
 6 files changed, 115 insertions(+), 11 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index a6dfa116c7..fb73087880 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -318,6 +318,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"set output (filename)\n"
 			"    Set the packet debug log file\n\n"
 
+			"set format (verbose|hex)\n"
+			"    Set the format of packet log\\n"
+
 			"set log global|(type) (level)\n"
 			"    Set the log level.\n\n"
 
@@ -4150,6 +4153,42 @@ static cmdline_parse_inst_t cmd_set_output = {
 	},
 };
 
+/* *** SET FORMAT OF PACKET LOG */
+struct cmd_set_format_result {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t format;
+	cmdline_fixed_string_t value;
+};
+
+static void
+cmd_set_format_parsed(void *parsed_result,
+		      __rte_unused struct cmdline *cl,
+		      __rte_unused void *data)
+{
+	struct cmd_set_format_result *res = parsed_result;
+
+	set_output_format(res->value);
+}
+
+static cmdline_parse_token_string_t cmd_set_format_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_format_result, set, "set");
+static cmdline_parse_token_string_t cmd_set_format_output =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_format_result, format, "format");
+static cmdline_parse_token_string_t cmd_set_format_value =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_format_result, value, "verbose#hex");
+
+static cmdline_parse_inst_t cmd_set_format = {
+	.f = cmd_set_format_parsed,
+	.data = NULL,
+	.help_str = "set format verbose|hex",
+	.tokens = {
+		(void *)&cmd_set_format_set,
+		(void *)&cmd_set_format_output,
+		(void *)&cmd_set_format_value,
+		NULL,
+	},
+};
+
 /* *** SET LOG LEVEL CONFIGURATION *** */
 
 struct cmd_set_log_result {
@@ -13685,6 +13724,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_read_rxd_txd,
 	&cmd_stop,
 	&cmd_mac_addr,
+	&cmd_set_format,
 	&cmd_set_fwd_eth_peer,
 	&cmd_set_qmap,
 	&cmd_set_xstats_hide_zero,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index d806cea3d3..86c18a7dc1 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -6340,6 +6340,17 @@ set_verbose_level(uint16_t vb_level)
 	configure_rxtx_dump_callbacks(verbose_level);
 }
 
+void
+set_output_format(const char *mode)
+{
+	if (!strcmp(mode, "verbose"))
+		output_format = OUTPUT_MODE_VERBOSE;
+	else if (!strcmp(mode, "hex"))
+		output_format = OUTPUT_MODE_HEX;
+	else
+		fprintf(stderr, "Unknown output format '%s'\n", mode);
+}
+
 void
 set_output_file(const char *filename)
 {
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 7790ba6ce0..f4fd51e46f 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -100,6 +100,7 @@
 
 uint16_t verbose_level = 0; /**< Silent by default. */
 RTE_ATOMIC(FILE *) output_file; /**< log to console by default. */
+enum output_mode output_format; /**< default to original mode. */
 int testpmd_logtype; /**< Log type for testpmd logs */
 
 /* use main core for command line ? */
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index e5affd44a2..6c21fb16f8 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -488,6 +488,11 @@ enum dcb_mode_enable
 	DCB_ENABLED
 };
 
+enum output_mode {
+	OUTPUT_MODE_VERBOSE = 0,
+	OUTPUT_MODE_HEX,
+};
+
 extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */
 
 /* globals used for configuration */
@@ -495,6 +500,7 @@ extern uint8_t record_core_cycles; /**< Enables measurement of CPU cycles */
 extern uint8_t record_burst_stats; /**< Enables display of RX and TX bursts */
 extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */
 extern RTE_ATOMIC(FILE *) output_file; /**< Where packet data is written */
+extern enum output_mode output_format; /**< Format of packet decode */
 extern int testpmd_logtype; /**< Log type for testpmd logs */
 extern uint8_t  interactive;
 extern uint8_t  auto_start;
@@ -1107,6 +1113,7 @@ void set_xstats_hide_zero(uint8_t on_off);
 void set_record_core_cycles(uint8_t on_off);
 void set_record_burst_stats(uint8_t on_off);
 void set_verbose_level(uint16_t vb_level);
+void set_output_format(const char *mode);
 void set_output_file(const char *filename);
 void set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs);
 void set_rx_pkt_hdrs(unsigned int *seg_protos, unsigned int nb_segs);
diff --git a/app/test-pmd/util.c b/app/test-pmd/util.c
index 2446687090..130821fddb 100644
--- a/app/test-pmd/util.c
+++ b/app/test-pmd/util.c
@@ -16,6 +16,7 @@
 #include "testpmd.h"
 
 #define MAX_STRING_LEN 8192
+#define MAX_DUMP_LEN   1024
 
 #define MKDUMPSTR(buf, buf_size, cur_len, ...) \
 do { \
@@ -67,9 +68,9 @@ get_timestamp(const struct rte_mbuf *mbuf)
 			timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
 }
 
-static inline void
-dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
-	      uint16_t nb_pkts, int is_rx)
+static void
+dump_pkt_verbose(FILE *outf, uint16_t port_id, uint16_t queue,
+		 struct rte_mbuf *pkts[], uint16_t nb_pkts, int is_rx)
 {
 	struct rte_mbuf  *mb;
 	const struct rte_ether_hdr *eth_hdr;
@@ -89,14 +90,6 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	size_t buf_size = MAX_STRING_LEN;
 	size_t cur_len = 0;
 	uint64_t restore_info_dynflag;
-	FILE *outf;
-
-	if (!nb_pkts)
-		return;
-
-	outf = rte_atomic_load_explicit(&output_file, rte_memory_order_relaxed);
-	if (!outf)
-		return;
 
 	restore_info_dynflag = rte_flow_restore_info_dynflag();
 	MKDUMPSTR(print_buf, buf_size, cur_len,
@@ -303,6 +296,45 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 			fprintf(outf, "%s", print_buf);
 		cur_len = 0;
 	}
+}
+
+static void
+dump_pkt_hex(FILE *outf, uint16_t port_id, uint16_t queue,
+	     struct rte_mbuf *pkts[], uint16_t nb_pkts, int is_rx)
+{
+	fprintf(outf, "port %u/queue %u: %s %u packets\n", port_id, queue,
+		  is_rx ? "received" : "sent", (unsigned int) nb_pkts);
+
+	for (uint16_t i = 0; i < nb_pkts; i++) {
+		rte_pktmbuf_dump(outf, pkts[i], MAX_DUMP_LEN);
+		fprintf(outf, "\n");
+	}
+}
+
+
+static void
+dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
+	      uint16_t nb_pkts, int is_rx)
+{
+	FILE *outf;
+
+	if (!nb_pkts)
+		return;
+
+	outf = rte_atomic_load_explicit(&output_file, rte_memory_order_relaxed);
+	if (unlikely(!outf))
+		return;
+
+	switch (output_format) {
+	case OUTPUT_MODE_VERBOSE:
+		dump_pkt_verbose(outf, port_id, queue, pkts, nb_pkts, is_rx);
+		return;
+	case OUTPUT_MODE_HEX:
+		dump_pkt_hex(outf, port_id, queue, pkts, nb_pkts, is_rx);
+		break;
+	default:
+		return;
+	}
 	fflush(outf);
 }
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 6aef74ff45..088dffd9fd 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -691,6 +691,19 @@ Redirect the debug log::
 
   testpmd> set output /tmp/packet.log
 
+set format
+~~~~~~~~~~
+
+Chose the output format for packet debug log::
+
+   testpmd> set format verbose|hex
+
+Available formats are:
+
+* ``verbose`` print the packet meta data information
+* ``hex`` print the mbuf flags and data in hex
+
+
 set verbose
 ~~~~~~~~~~~
 
-- 
2.45.2


  parent reply	other threads:[~2024-10-28  2:22 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12 22:01 [PATCH] test-pmd: add more packet decode options (verbose) Stephen Hemminger
2024-03-13 21:49 ` Stephen Hemminger
2024-07-05  7:13 ` David Marchand
2024-07-23  2:44 ` [PATCH v2 0/3] Add packet dissector Stephen Hemminger
2024-07-23  2:44   ` [PATCH v2 1/3] net: add new " Stephen Hemminger
2024-07-23  2:44   ` [PATCH v2 2/3] test: add test for " Stephen Hemminger
2024-07-23  2:44   ` [PATCH v2 3/3] test-pmd: add more packet verbose decode options Stephen Hemminger
2024-07-23 20:33 ` [PATCH v3 0/3] add packet dissector function Stephen Hemminger
2024-07-23 20:33   ` [PATCH v3 1/3] net: add new packet dissector Stephen Hemminger
2024-07-23 20:33   ` [PATCH v3 2/3] test: add test for " Stephen Hemminger
2024-07-23 20:33   ` [PATCH v3 3/3] test-pmd: add more packet verbose decode options Stephen Hemminger
2024-07-24 18:46 ` [PATCH v4 0/3] Add packet dissector Stephen Hemminger
2024-07-24 18:46   ` [PATCH v4 1/3] net: add new " Stephen Hemminger
2024-07-24 18:46   ` [PATCH v4 2/3] test: add test for " Stephen Hemminger
2024-07-24 18:46   ` [PATCH v4 3/3] test-pmd: add more packet verbose decode options Stephen Hemminger
2024-08-01 19:04 ` [PATCH v5 0/4] Add network packet dissector Stephen Hemminger
2024-08-01 19:04   ` [PATCH v5 1/4] net: add more icmp types Stephen Hemminger
2024-08-01 19:04   ` [PATCH v5 2/4] net: add new packet dissector Stephen Hemminger
2024-08-01 19:04   ` [PATCH v5 3/4] test: add test for " Stephen Hemminger
2024-08-02  8:38     ` Bruce Richardson
2024-08-02 15:31       ` Stephen Hemminger
2024-08-02 18:06       ` Stephen Hemminger
2024-08-01 19:04   ` [PATCH v5 4/4] test-pmd: add more packet verbose decode options Stephen Hemminger
2024-08-02 18:07 ` [PATCH v6 0/4] Add network packet dissector Stephen Hemminger
2024-08-02 18:07   ` [PATCH v6 1/4] net: add more icmp types Stephen Hemminger
2024-08-02 18:07   ` [PATCH v6 2/4] net: add new packet dissector Stephen Hemminger
2024-08-02 18:07   ` [PATCH v6 3/4] test: add test for " Stephen Hemminger
2024-08-02 18:07   ` [PATCH v6 4/4] test-pmd: add more packet verbose decode options Stephen Hemminger
2024-08-02 19:56 ` [PATCH v7 0/4] Add network packet dissector Stephen Hemminger
2024-08-02 19:56   ` [PATCH v7 1/4] net: add more icmp types Stephen Hemminger
2024-08-02 19:56   ` [PATCH v7 2/4] net: add new packet dissector Stephen Hemminger
2024-08-02 19:56   ` [PATCH v7 3/4] test: add test for " Stephen Hemminger
2024-08-02 19:56   ` [PATCH v7 4/4] test-pmd: add more packet verbose decode options Stephen Hemminger
2024-08-20 13:42     ` Alex Chapman
2024-08-20 15:54       ` Stephen Hemminger
2024-08-22  9:04         ` Paul Szczepanek
2024-09-28 18:36           ` Stephen Hemminger
2024-09-17  3:27 ` [PATCH v8 0/7] Test-pmd packet decode enhancements Stephen Hemminger
2024-09-17  3:27   ` [PATCH v8 1/7] net: add more icmp types Stephen Hemminger
2024-09-17  3:27   ` [PATCH v8 2/7] net: add new packet dissector Stephen Hemminger
2024-09-17  3:28   ` [PATCH v8 3/7] test: add test for " Stephen Hemminger
2024-09-17  3:28   ` [PATCH v8 4/7] test-pmd: add option to redirect packet log Stephen Hemminger
2024-09-17  3:28   ` [PATCH v8 5/7] test-pmd: add hex decode Stephen Hemminger
2024-09-17  3:28   ` [PATCH v8 6/7] test-pmd: add packet dissect format Stephen Hemminger
2024-09-17  3:28   ` [PATCH v8 7/7] test-pmd: add a JSON packet output Stephen Hemminger
2024-09-28 16:18 ` [PATCH v9 0/8] test-pmd packet decoding enhancements Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 1/8] net: add more icmp types Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 2/8] net: add new packet dissector Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 3/8] mbuf: decode the hash and fdir info in rte_pktmbuf_dump Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 4/8] test: add test for packet dissector Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 5/8] test-pmd: add option to redirect packet log Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 6/8] test-pmd: add hex decode Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 7/8] test-pmd: add packet dissect format Stephen Hemminger
2024-09-28 16:18   ` [PATCH v9 8/8] test-pmd: add a JSON packet output Stephen Hemminger
2024-10-28  2:19 ` [PATCH v10 0/8] test-pmd packet decoding enhancements Stephen Hemminger
2024-10-28  2:19   ` [PATCH v10 1/8] net: add more icmp types Stephen Hemminger
2024-10-28  2:19   ` [PATCH v10 2/8] net: add new packet dissector Stephen Hemminger
2024-10-28  2:19   ` [PATCH v10 3/8] mbuf: decode the hash and fdir info in rte_pktmbuf_dump Stephen Hemminger
2024-10-28  2:19   ` [PATCH v10 4/8] test: add test for packet dissector Stephen Hemminger
2024-10-28  2:19   ` [PATCH v10 5/8] test-pmd: add option to redirect packet log Stephen Hemminger
2024-10-28  2:19   ` Stephen Hemminger [this message]
2024-10-28  2:19   ` [PATCH v10 7/8] test-pmd: add packet dissect format Stephen Hemminger
2024-10-28  2:19   ` [PATCH v10 8/8] test-pmd: add a JSON packet output Stephen Hemminger

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=20241028022131.142609-7-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=aman.deep.singh@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).