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 2108D459B0; Tue, 17 Sep 2024 05:32:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A93E440665; Tue, 17 Sep 2024 05:31:38 +0200 (CEST) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mails.dpdk.org (Postfix) with ESMTP id E7EB0402CF for ; Tue, 17 Sep 2024 05:31:32 +0200 (CEST) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fc47abc040so40416885ad.0 for ; Mon, 16 Sep 2024 20:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726543892; x=1727148692; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cv4FtQT4PfeyG45jN+Vk7cAYBrmJM5jQx85bCQozG08=; b=EtaryCoN38lhFgJwbBbvSBYLMD3A2+WWUYzt3Uzaqzn0bUs4AMYgsn5SctTCYPHOeY tlmcK4BlcBDXLd6SSSUN/mV0Gs4Qd48K3198FLXLzO2P+BrAn9dVoinoKMcMk+w01Tq3 tHPXtvj8g+wVPyNuwA0abafH6inq/futXBCVHrPcYgAqgFTLnqZ046fY9/v1tkpMc6LW +PPvxs3MTRgYo9HqyiqS4WhWJX75kgYmP8/HEIVO57bFUipAdzX508CWr4GMwhyNQzcm ttSQRopqHFt+C08lCIqP4vJYcCvz2J1bvFptcMQFMTK3tjC9d9ZRwktxVOWvYoZCI7eL O6Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726543892; x=1727148692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cv4FtQT4PfeyG45jN+Vk7cAYBrmJM5jQx85bCQozG08=; b=ShuwHSB0maRthmyuc2tMpzcn3YqrZv+1yM+Crikm/or1s10798Iu1+Zc+b+2HZk7jX FpVSuDqRHMpnvYLNN4r9BC2rqFLsKJzevmrxHdTeqzwSJjVyV+lQjiSzXgPFAqPHW6qY ngcUBVk2IVx74jd8ES8OuMNKF5LzijGuUz6+df4AJV5fHaRf9fRHbjmihB6r/aFvqoTZ yG6Zr3Bk584ZixD51Dg8C6lEqXMHiHn/bv5wHBs1Q2QOInRDMHBR2071YlCj/AmFbfvV BsTNqhddlHUUZGf4emdRIHjgf+6JGwrkg8oWQ6LGcdFNxqBFR2eMUGwTaRRbG4lFugHF jY4w== X-Gm-Message-State: AOJu0YwKpDVnp3kGzu14veJORrc2TjT93kSOhAGYiGdRDGEziF+cFFvV iWMiHFR1BgakCkq2xKaqg/smiy9edV2sca2pTrWqa4mzf+47EJhMAMqwEjwhLdvES4/zcqVNM6w O X-Google-Smtp-Source: AGHT+IH9vQImeGAb+lsmhqJSQhZRdkwD/xiNTnE53HM8v6GbrQs1gKbNEH/foCPVqkYdxX6QHIyjRw== X-Received: by 2002:a17:902:d586:b0:205:5bc9:37fb with SMTP id d9443c01a7336-2076e478fe9mr223565235ad.61.1726543892115; Mon, 16 Sep 2024 20:31:32 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2079473d05dsm42647735ad.287.2024.09.16.20.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 20:31:31 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh Subject: [PATCH v8 5/7] test-pmd: add hex decode Date: Mon, 16 Sep 2024 20:28:02 -0700 Message-ID: <20240917033117.66346-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240917033117.66346-1-stephen@networkplumber.org> References: <20240312220129.70667-1-stephen@networkplumber.org> <20240917033117.66346-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 This adds new command: testpmd> set format hex which decodes packet in hex. Signed-off-by: Stephen Hemminger --- 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 | 48 ++++++++++++++++----- doc/guides/testpmd_app_ug/testpmd_funcs.rst | 13 ++++++ 6 files changed, 109 insertions(+), 11 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 7c6ab191de..37cce4868e 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -305,6 +305,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" @@ -3893,6 +3896,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 { @@ -13207,6 +13246,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_numbers, (cmdline_parse_inst_t *)&cmd_set_log, (cmdline_parse_inst_t *)&cmd_set_output, + (cmdline_parse_inst_t *)&cmd_set_format, (cmdline_parse_inst_t *)&cmd_set_rxoffs, (cmdline_parse_inst_t *)&cmd_set_rxpkts, (cmdline_parse_inst_t *)&cmd_set_rxhdrs, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index bfc5a1898b..f30bdfc7ff 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -6268,6 +6268,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 d92cb743dd..94e8f59ef0 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; @@ -1104,6 +1110,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..3f05c37e2b 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,39 @@ 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, struct rte_mbuf *pkts[], uint16_t nb_pkts) +{ + for (uint16_t i = 0; i < nb_pkts; i++) + rte_pktmbuf_dump(outf, pkts[i], MAX_DUMP_LEN); +} + + +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, pkts, nb_pkts); + 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 579432e5c7..9406af3225 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -672,6 +672,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