DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/3] dumpcap: small enhancements
@ 2023-01-26 18:23 Stephen Hemminger
  2023-01-26 18:23 ` [PATCH 1/3] dumpcap: add --interface to help Stephen Hemminger
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stephen Hemminger @ 2023-01-26 18:23 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

Cover a few more options and statistics mode to be add more
compatiablity with wireshark dumpcap.

Stephen Hemminger (3):
  dumpcap: add --interface to help
  dumpcap: support temp-dir option
  dumpcap: add support statistics mode

 app/dumpcap/main.c | 67 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 59 insertions(+), 8 deletions(-)

-- 
2.39.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] dumpcap: add --interface to help
  2023-01-26 18:23 [PATCH 0/3] dumpcap: small enhancements Stephen Hemminger
@ 2023-01-26 18:23 ` Stephen Hemminger
  2023-01-26 18:23 ` [PATCH 2/3] dumpcap: support temp-dir option Stephen Hemminger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2023-01-26 18:23 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

Make the help more complete, add all supported options.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 2eb8414efaa5..297b6378aaf2 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -102,7 +102,8 @@ static void usage(void)
 {
 	printf("Usage: %s [options] ...\n\n", progname);
 	printf("Capture Interface:\n"
-	       "  -i <interface>           name or port index of interface\n"
+	       "  -i <interface>, --interface <interface>\n"
+	       "                           name or port index of interface\n"
 	       "  -f <capture filter>      packet filter in libpcap filter syntax\n");
 	printf("  -s <snaplen>, --snapshot-length <snaplen>\n"
 	       "                           packet snapshot length (def: %u)\n",
-- 
2.39.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] dumpcap: support temp-dir option
  2023-01-26 18:23 [PATCH 0/3] dumpcap: small enhancements Stephen Hemminger
  2023-01-26 18:23 ` [PATCH 1/3] dumpcap: add --interface to help Stephen Hemminger
@ 2023-01-26 18:23 ` Stephen Hemminger
  2023-01-26 18:23 ` [PATCH 3/3] dumpcap: add support statistics mode Stephen Hemminger
  2023-02-06  9:46 ` [PATCH 0/3] dumpcap: small enhancements Thomas Monjalon
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2023-01-26 18:23 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

Option for putting output files in different directory.
Same syntax as wireshark.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 297b6378aaf2..02bb8b2b2b4f 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -58,6 +58,7 @@ static bool quiet;
 static bool promiscuous_mode = true;
 static bool use_pcapng = true;
 static char *output_name;
+static const char *tmp_dir = "/tmp";
 static const char *filter_str;
 static unsigned int ring_size = 2048;
 static const char *capture_comment;
@@ -126,6 +127,8 @@ static void usage(void)
 	       "  -P                       use libpcap format instead of pcapng\n"
 	       "  --capture-comment <comment>\n"
 	       "                           add a capture comment to the output file\n"
+	       "  --temp-dir <directory>   write temporary files to this directory\n"
+	       "                           (default: /tmp)\n"
 	       "\n"
 	       "Miscellaneous:\n"
 	       "  --file-prefix=<prefix>   prefix to use for multi-process\n"
@@ -327,6 +330,7 @@ static void parse_opts(int argc, char **argv)
 		{ "output-file",     required_argument, NULL, 'w' },
 		{ "ring-buffer",     required_argument, NULL, 'b' },
 		{ "snapshot-length", required_argument, NULL, 's' },
+		{ "temp-dir",        required_argument, NULL, 0 },
 		{ "version",         no_argument,       NULL, 'v' },
 		{ NULL },
 	};
@@ -346,6 +350,9 @@ static void parse_opts(int argc, char **argv)
 			} else if (!strcmp(long_options[option_index].name,
 					   "file-prefix")) {
 				file_prefix = optarg;
+			} else if (!strcmp(long_options[option_index].name,
+					   "temp-dir")) {
+				tmp_dir = optarg;
 			} else {
 				usage();
 				exit(1);
@@ -642,7 +649,7 @@ static dumpcap_out_t create_output(void)
 		strftime(ts, sizeof(ts), "%Y%m%d%H%M%S", tm);
 
 		snprintf(tmp_path, sizeof(tmp_path),
-			 "/tmp/%s_%u_%s_%s.%s",
+			 "%s/%s_%u_%s_%s.%s", tmp_dir,
 			 progname, intf->port, intf->name, ts,
 			 use_pcapng ? "pcapng" : "pcap");
 		output_name = tmp_path;
-- 
2.39.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] dumpcap: add support statistics mode
  2023-01-26 18:23 [PATCH 0/3] dumpcap: small enhancements Stephen Hemminger
  2023-01-26 18:23 ` [PATCH 1/3] dumpcap: add --interface to help Stephen Hemminger
  2023-01-26 18:23 ` [PATCH 2/3] dumpcap: support temp-dir option Stephen Hemminger
@ 2023-01-26 18:23 ` Stephen Hemminger
  2023-02-06  9:46 ` [PATCH 0/3] dumpcap: small enhancements Thomas Monjalon
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2023-01-26 18:23 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

This add new -S option which does the same thing as wireshark's
dumpcap -S option.

It loops over all interfaces and prints the number of received
and dropped packets. In this mode, actual packet capture is
not done.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c | 55 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 02bb8b2b2b4f..d1c70f769be5 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -66,6 +66,7 @@ static const char *file_prefix;
 static uint32_t snaplen = RTE_MBUF_DEFAULT_BUF_SIZE;
 static bool dump_bpf;
 static bool show_interfaces;
+static bool print_stats;
 static bool select_interfaces;
 const char *interface_arg;
 
@@ -113,6 +114,7 @@ static void usage(void)
 	       "                           don't capture in promiscuous mode\n"
 	       "  -D, --list-interfaces    print list of interfaces and exit\n"
 	       "  -d                       print generated BPF code for capture filter\n"
+	       "  -S                       print statistics for each interface once per second\n"
 	       "\n"
 	       "Stop conditions:\n"
 	       "  -c <packet count>        stop after n packets (def: infinite)\n"
@@ -337,7 +339,7 @@ static void parse_opts(int argc, char **argv)
 	int option_index, c;
 
 	for (;;) {
-		c = getopt_long(argc, argv, "a:b:c:dDf:ghi:nN:pPqs:vw:",
+		c = getopt_long(argc, argv, "a:b:c:dDf:ghi:nN:pPqSs:vw:",
 				long_options, &option_index);
 		if (c == -1)
 			break;
@@ -406,6 +408,9 @@ static void parse_opts(int argc, char **argv)
 		case 's':
 			snaplen = get_uint(optarg, "snap_len", 0);
 			break;
+		case 'S':
+			print_stats = true;
+			break;
 		case 'w':
 			output_name = optarg;
 			break;
@@ -427,6 +432,39 @@ signal_handler(int sig_num __rte_unused)
 	__atomic_store_n(&quit_signal, true, __ATOMIC_RELAXED);
 }
 
+
+/* Instead of capturing, it tracks interface statistics */
+static void statistics_loop(void)
+{
+	struct rte_eth_stats stats;
+	char name[RTE_ETH_NAME_MAX_LEN];
+	uint16_t p;
+	int r;
+
+	printf("%-15s  %10s  %10s\n",
+	       "Interface", "Received", "Dropped");
+
+	while (!__atomic_load_n(&quit_signal, __ATOMIC_RELAXED)) {
+		RTE_ETH_FOREACH_DEV(p) {
+			if (rte_eth_dev_get_name_by_port(p, name) < 0)
+				continue;
+
+			r = rte_eth_stats_get(p, &stats);
+			if (r < 0) {
+				fprintf(stderr,
+					"stats_get for port %u failed: %d (%s)\n",
+					p, r, strerror(r));
+				return;
+			}
+
+			printf("%-15s  %10"PRIu64"  %10"PRIu64"\n",
+			       name, stats.ipackets,
+			       stats.imissed + stats.ierrors + stats.rx_nombuf);
+		}
+		sleep(1);
+	}
+}
+
 /* Return the time since 1/1/1970 in nanoseconds */
 static uint64_t create_timestamp(void)
 {
@@ -834,6 +872,16 @@ int main(int argc, char **argv)
 	if (TAILQ_EMPTY(&interfaces))
 		set_default_interface();
 
+	signal(SIGINT, signal_handler);
+	signal(SIGPIPE, SIG_IGN);
+
+	enable_primary_monitor();
+
+	if (print_stats) {
+		statistics_loop();
+		exit(0);
+	}
+
 	r = create_ring();
 	mp = create_mempool();
 	out = create_output();
@@ -841,11 +889,6 @@ int main(int argc, char **argv)
 	start_time = create_timestamp();
 	enable_pdump(r, mp);
 
-	signal(SIGINT, signal_handler);
-	signal(SIGPIPE, SIG_IGN);
-
-	enable_primary_monitor();
-
 	if (!quiet) {
 		fprintf(stderr, "Packets captured: ");
 		show_count(0);
-- 
2.39.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] dumpcap: small enhancements
  2023-01-26 18:23 [PATCH 0/3] dumpcap: small enhancements Stephen Hemminger
                   ` (2 preceding siblings ...)
  2023-01-26 18:23 ` [PATCH 3/3] dumpcap: add support statistics mode Stephen Hemminger
@ 2023-02-06  9:46 ` Thomas Monjalon
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Monjalon @ 2023-02-06  9:46 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

> Stephen Hemminger (3):
>   dumpcap: add --interface to help
>   dumpcap: support temp-dir option
>   dumpcap: add support statistics mode

Applied, thanks.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-02-06  9:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 18:23 [PATCH 0/3] dumpcap: small enhancements Stephen Hemminger
2023-01-26 18:23 ` [PATCH 1/3] dumpcap: add --interface to help Stephen Hemminger
2023-01-26 18:23 ` [PATCH 2/3] dumpcap: support temp-dir option Stephen Hemminger
2023-01-26 18:23 ` [PATCH 3/3] dumpcap: add support statistics mode Stephen Hemminger
2023-02-06  9:46 ` [PATCH 0/3] dumpcap: small enhancements Thomas Monjalon

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).