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 933D445BE5; Mon, 28 Oct 2024 03:22:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E80740B9B; Mon, 28 Oct 2024 03:21:58 +0100 (CET) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 6A8194066F for ; Mon, 28 Oct 2024 03:21:47 +0100 (CET) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20c8c50fdd9so29490635ad.0 for ; Sun, 27 Oct 2024 19:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1730082106; x=1730686906; 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=54qwxhKy913FrmKd+E7qWObgNfK78bB+MQcEmg3oeE8=; b=JIqdTHlt7AUy2dB7Glv2/QumK5V73CxzwIvHQmNbWATPKSW/VP3OR4zApstIg9/wS3 /RPkiBqqr1Ao1NasiZ+XMnZZF6NUM2SBz9darewq/akmGphOmgiVHmiG5vGGGE4dyiAn wzxYkEzHVcjmDDMbiAHfKkcEs/wvmqjFBY0qx3ebSW7Jp1JwzqPoWVOMq1Fpe2VLui7i Bam8pf2gdoBwmiu6qZhdPHJcxDoopBNnVPc80OQE0+P24aTLeLAUEdpEMB6TFI7V1fim 0zbKI5tMZBtJz6OWMDzNlNtfpYCaPq+4uyKKqiYRyLAhzY1/li/XdseD+gVPlGjPYFa2 5LGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730082106; x=1730686906; 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=54qwxhKy913FrmKd+E7qWObgNfK78bB+MQcEmg3oeE8=; b=qIwcMhqRUXGxXe2eSetkoIdMCpDkVCXBplkIbawMluuUDxykQqLirwyJnDJSrvtuOX CUKADz6fuctVZuy1D1p2Fkiv+MLbgbKsYvq9k2H62pi4lPDL7hnDv0oU4x8hHS6nOBwh 8uh4fMHLJe3kt5yL06RIdyGDcY6OEWIkT8N/deBUJE40OsrKXFF+RH6s80jyNibjxmbN ofBLTRtyh49EIAea3C3HaajtXntaxp0GB8iChEdloyjcFSZZ0IdKszisvM50NWNjIcR+ GKuCVDYsDVvFuhHnyj37lHU6Pn0wMF4lRSVy/1/GgHFpRlzDtaoVgGOlOs5oN/f/58IF 2tbg== X-Gm-Message-State: AOJu0YxWqh9duhr1GCsMwizoGs3qfXrwjkxpAmDuFxBnoIh2mrHHfYAi YyBMrSifs+OUuHVlUtCyiMekURUNjg8dW1lhysOVZ7MMcqWyXlveeo6uwPRyVg/iMiFtwHxzdVI nedA= X-Google-Smtp-Source: AGHT+IGXBQsKpbJhDrZpv/X1JG1hE7OWN27hEr6xhtPsk+Zh3jaSMi9UEnkvmDcfHIPn3cQJELFOTQ== X-Received: by 2002:a17:902:ef43:b0:20e:567c:9d87 with SMTP id d9443c01a7336-20fb89daae4mr183355435ad.20.1730082106498; Sun, 27 Oct 2024 19:21:46 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04b8bbsm41095615ad.244.2024.10.27.19.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 19:21:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh Subject: [PATCH v10 7/8] test-pmd: add packet dissect format Date: Sun, 27 Oct 2024 19:19:33 -0700 Message-ID: <20241028022131.142609-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241028022131.142609-1-stephen@networkplumber.org> References: <20240312220129.70667-1-stephen@networkplumber.org> <20241028022131.142609-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 Add ability to get decode packet in summary tshark style format. Signed-off-by: Stephen Hemminger --- app/test-pmd/cmdline.c | 6 ++-- app/test-pmd/config.c | 23 +++++++++---- app/test-pmd/testpmd.h | 1 + app/test-pmd/util.c | 36 +++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 3 +- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index fb73087880..0595da6749 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -318,7 +318,7 @@ 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 format (dissect|hex|verbose)\n" " Set the format of packet log\\n" "set log global|(type) (level)\n" @@ -4175,12 +4175,12 @@ static cmdline_parse_token_string_t cmd_set_format_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"); + TOKEN_STRING_INITIALIZER(struct cmd_set_format_result, value, "dissect#hex#verbose"); static cmdline_parse_inst_t cmd_set_format = { .f = cmd_set_format_parsed, .data = NULL, - .help_str = "set format verbose|hex", + .help_str = "set format dissect|hex|verbose", .tokens = { (void *)&cmd_set_format_set, (void *)&cmd_set_format_output, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 86c18a7dc1..410d5a60f2 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -6343,12 +6343,23 @@ set_verbose_level(uint16_t vb_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); + static const char * const output_formats[] = { + [OUTPUT_MODE_VERBOSE] = "verbose", + [OUTPUT_MODE_HEX] = "hex", + [OUTPUT_MODE_DISSECT] = "dissect", + }; + + printf("Change output format from %s to %s\n", + output_formats[output_format], mode); + + for (unsigned int i = 0; i < RTE_DIM(output_formats); i++) { + if (strcasecmp(mode, output_formats[i]) == 0) { + output_format = i; + return; + } + } + + fprintf(stderr, "Unknown output format '%s'\n", mode); } void diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 6c21fb16f8..167bfeb00f 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -491,6 +491,7 @@ enum dcb_mode_enable enum output_mode { OUTPUT_MODE_VERBOSE = 0, OUTPUT_MODE_HEX, + OUTPUT_MODE_DISSECT, }; extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */ diff --git a/app/test-pmd/util.c b/app/test-pmd/util.c index 130821fddb..551e684e4c 100644 --- a/app/test-pmd/util.c +++ b/app/test-pmd/util.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -311,6 +312,38 @@ dump_pkt_hex(FILE *outf, uint16_t port_id, uint16_t queue, } } +/* Brief tshark style one line output which is + * number time_delta Source Destination Protocol len info + */ +static void +dump_pkt_brief(FILE *outf, uint16_t port, uint16_t queue, + struct rte_mbuf *pkts[], uint16_t nb_pkts, int is_rx) +{ + static uint64_t start_cycles; + static RTE_ATOMIC(uint64_t) packet_count = 1; + uint64_t now, count; + double interval; + + /* Compute time interval from the first packet received */ + now = rte_rdtsc(); + if (start_cycles == 0) { + start_cycles = now; + printf("Seq# Time Port:Que R Description\n"); + } + interval = (double)(now - start_cycles) / (double)rte_get_tsc_hz(); + + /* Packet counter needs to be thread safe */ + count = rte_atomic_fetch_add_explicit(&packet_count, nb_pkts, rte_memory_order_relaxed); + + for (uint16_t i = 0; i < nb_pkts; i++) { + const struct rte_mbuf *mb = pkts[i]; + char str[256]; + + rte_dissect_mbuf(str, sizeof(str), mb, 0); + fprintf(outf, "%6"PRIu64" %11.9f %4u:%-3u %c %s\n", + count + i, interval, port, queue, is_rx ? 'R' : 'T', str); + } +} static void dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[], @@ -332,6 +365,9 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[], case OUTPUT_MODE_HEX: dump_pkt_hex(outf, port_id, queue, pkts, nb_pkts, is_rx); break; + case OUTPUT_MODE_DISSECT: + dump_pkt_brief(outf, port_id, queue, pkts, nb_pkts, is_rx); + break; default: return; } diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 088dffd9fd..4a852297fb 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -696,12 +696,13 @@ set format Chose the output format for packet debug log:: - testpmd> set format verbose|hex + testpmd> set format dissect|hex|verbose Available formats are: * ``verbose`` print the packet meta data information * ``hex`` print the mbuf flags and data in hex +* ``dissect`` print the packet in tshark summary format set verbose -- 2.45.2