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 E498E459B0; Tue, 17 Sep 2024 05:32:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 18E4D40677; Tue, 17 Sep 2024 05:31:40 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id D979E402DA for ; Tue, 17 Sep 2024 05:31:33 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2055136b612so63569575ad.0 for ; Mon, 16 Sep 2024 20:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726543893; x=1727148693; 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=k19cwDZo2w1A78IBoHGEx8/IBh+SuIgbrDHqDwvbDMk=; b=KIN+pd7euA3FGyihqAkOiHVoGyyLmvVyEoV+kjyBRuL5zWzcyDOhkwAp7luWC6dGrT 5lI6Wp4Ly5vYNsIfqD4QcBuRsqnY0DeAneppb6daGGVHj++ZqOPBLq1SuYIBXc/xeTSt Setkh5uWjFWOy0r3xCEQ582qOPKaqYOOF9o+E7ZXPBaASki/ajsRaKEJMv4d9Gf6y9h5 tG4fwewxS0ENYW9h0u1Bw5rMY4f+NxqZY7kGbJm7JRsrYTMYB1SVIhrvTdR5ll3kZyPt wnldOQFkJcYXuDVotV554M+AWTxYG8Lt9GmxvRlxNSFwNZC4II+JCOP5DEDyRn1rkXdd YLXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726543893; x=1727148693; 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=k19cwDZo2w1A78IBoHGEx8/IBh+SuIgbrDHqDwvbDMk=; b=ZBSjW/o05t4LQ+GxFKdrUCZesxOd8VJM+ZevcfpZZYU1KCJMH+ReDMZWtA2ePXHvpg g7lrMdEKxYc2iR3wBQJoPAeeLoLgVTp8tCR/0FMXxt5dVA9KDGS5ge9Uzz9ePI+iUfhs Bxj3CM33cE2PMdoI3aZjwtYhFgL1FGyOAJ8DxxYNOk3ebtecOTPzObaRHLleEawVN790 a8C6yISDtKu9Esn3qw0UZT+/oay/WU4e0wy9SGibOyLQkfGNTEOa/4J2FCjElzUDktHb uGbP9pxJaoSmX6+65Rj8IDdHzF7Azq19frtpQIswaJtbRspx/GjpIZ/o81y7N/wimuRe TYWg== X-Gm-Message-State: AOJu0Yypt+3iDovxPVzqXe90i+4Iid2ACX1voFcK9k4OvpxujtgYtVPf G2VWNcTpJ7hOg+8ZTl90uHNE3NmNBvRjbyvrO4+JVmAbjPGJkplCgkiFOEAOOXLcB8W/2YJEGZa t X-Google-Smtp-Source: AGHT+IH6ORHK7uf/6dbQ8WBlbNG0z4AgObnncaMF63NtsBPt9q+kIxYtSt077dnDVXpGZXfQFRMQLQ== X-Received: by 2002:a17:902:db05:b0:206:c12d:abad with SMTP id d9443c01a7336-2076e393e31mr287356555ad.34.1726543892965; 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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 20:31:32 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh Subject: [PATCH v8 6/7] test-pmd: add packet dissect format Date: Mon, 16 Sep 2024 20:28:03 -0700 Message-ID: <20240917033117.66346-7-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 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 | 22 +++++++++---- app/test-pmd/testpmd.h | 1 + app/test-pmd/util.c | 36 +++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 3 +- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 37cce4868e..72be5a0c06 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -305,7 +305,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" @@ -3918,12 +3918,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 f30bdfc7ff..c9b3eb7c2b 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -6271,12 +6271,22 @@ 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 *formats[] = { + [OUTPUT_MODE_VERBOSE] = "verbose", + [OUTPUT_MODE_HEX] = "hex", + [OUTPUT_MODE_DISSECT] = "dissect", + }; + + printf("Change output format from %s to %s\n", formats[output_format], mode); + + for (unsigned int i = 0; i < RTE_DIM(formats); i++) { + if (strcasecmp(mode, 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 94e8f59ef0..66b0317b61 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 3f05c37e2b..392c444021 100644 --- a/app/test-pmd/util.c +++ b/app/test-pmd/util.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -305,6 +306,38 @@ dump_pkt_hex(FILE *outf, struct rte_mbuf *pkts[], uint16_t nb_pkts) rte_pktmbuf_dump(outf, pkts[i], MAX_DUMP_LEN); } +/* 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[], @@ -326,6 +359,9 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[], case OUTPUT_MODE_HEX: dump_pkt_hex(outf, pkts, nb_pkts); 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 9406af3225..705b3dc3d5 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -677,12 +677,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