From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: netdev@vger.kernel.org
Cc: Willem de Bruijn <willemb@google.com>
Subject: [PATCH RFC net-next 4/6] selftests/net: so_txtime: support txonly/rxonly modes
Date: Tue, 9 Jun 2020 10:09:32 -0400 [thread overview]
Message-ID: <20200609140934.110785-5-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20200609140934.110785-1-willemdebruijn.kernel@gmail.com>
From: Willem de Bruijn <willemb@google.com>
Allow running the test across two machines, to test nic hw offload.
Add options
-A: receiver address
-r: receive only
-t: transmit only
-T: SO_RCVTIMEO value
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
tools/testing/selftests/net/so_txtime.c | 60 ++++++++++++++++++++-----
1 file changed, 48 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/net/so_txtime.c b/tools/testing/selftests/net/so_txtime.c
index 383bac05ac32..fa748e4209c0 100644
--- a/tools/testing/selftests/net/so_txtime.c
+++ b/tools/testing/selftests/net/so_txtime.c
@@ -28,9 +28,13 @@
#include <time.h>
#include <unistd.h>
+static const char *cfg_addr;
static int cfg_clockid = CLOCK_TAI;
static bool cfg_do_ipv4;
static bool cfg_do_ipv6;
+static bool cfg_rxonly;
+static int cfg_timeout_sec;
+static bool cfg_txonly;
static uint16_t cfg_port = 8000;
static int cfg_variance_us = 4000;
@@ -238,8 +242,12 @@ static int setup_rx(struct sockaddr *addr, socklen_t alen)
if (fd == -1)
error(1, errno, "socket r");
- if (bind(fd, addr, alen))
- error(1, errno, "bind");
+ if (!cfg_txonly)
+ if (bind(fd, addr, alen))
+ error(1, errno, "bind");
+
+ if (cfg_timeout_sec)
+ tv.tv_sec = cfg_timeout_sec;
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)))
error(1, errno, "setsockopt rcv timeout");
@@ -260,13 +268,18 @@ static void do_test(struct sockaddr *addr, socklen_t alen)
glob_tstart = gettime_ns();
- for (i = 0; i < cfg_num_pkt; i++)
- do_send_one(fdt, &cfg_in[i]);
- for (i = 0; i < cfg_num_pkt; i++)
- if (do_recv_one(fdr, &cfg_out[i]))
- do_recv_errqueue_timeout(fdt);
+ if (!cfg_rxonly) {
+ for (i = 0; i < cfg_num_pkt; i++)
+ do_send_one(fdt, &cfg_in[i]);
+ }
- do_recv_verify_empty(fdr);
+ if (!cfg_txonly) {
+ for (i = 0; i < cfg_num_pkt; i++)
+ if (do_recv_one(fdr, &cfg_out[i]))
+ do_recv_errqueue_timeout(fdt);
+
+ do_recv_verify_empty(fdr);
+ }
if (close(fdr))
error(1, errno, "close r");
@@ -308,7 +321,7 @@ static void parse_opts(int argc, char **argv)
{
int c, ilen, olen;
- while ((c = getopt(argc, argv, "46c:")) != -1) {
+ while ((c = getopt(argc, argv, "46A:c:rtT:")) != -1) {
switch (c) {
case '4':
cfg_do_ipv4 = true;
@@ -316,6 +329,9 @@ static void parse_opts(int argc, char **argv)
case '6':
cfg_do_ipv6 = true;
break;
+ case 'A':
+ cfg_addr = optarg;
+ break;
case 'c':
if (!strcmp(optarg, "tai"))
cfg_clockid = CLOCK_TAI;
@@ -325,13 +341,27 @@ static void parse_opts(int argc, char **argv)
else
error(1, 0, "unknown clock id %s", optarg);
break;
+ case 'r':
+ cfg_rxonly = true;
+ break;
+ case 't':
+ cfg_txonly = true;
+ break;
+ case 'T':
+ cfg_timeout_sec = strtol(optarg, NULL, 0);
+ break;
default:
error(1, 0, "parse error at %d", optind);
}
}
if (argc - optind != 2)
- error(1, 0, "Usage: %s [-46] -c <clock> <in> <out>", argv[0]);
+ error(1, 0, "Usage: %s [-46rt] [-A addr] [-c clock] [-T timeout] <in> <out>", argv[0]);
+
+ if (cfg_rxonly && cfg_txonly)
+ error(1, 0, "Select rx-only or tx-only, not both");
+ if (cfg_addr && cfg_do_ipv4 && cfg_do_ipv6)
+ error(1, 0, "Cannot run both IPv4 and IPv6 when passing address");
ilen = parse_io(argv[optind], cfg_in);
olen = parse_io(argv[optind + 1], cfg_out);
@@ -349,7 +379,10 @@ int main(int argc, char **argv)
addr6.sin6_family = AF_INET6;
addr6.sin6_port = htons(cfg_port);
- addr6.sin6_addr = in6addr_loopback;
+ if (!cfg_addr)
+ addr6.sin6_addr = in6addr_loopback;
+ else if (inet_pton(AF_INET6, cfg_addr, &addr6.sin6_addr) != 1)
+ error(1, 0, "ipv6 parse error: %s", cfg_addr);
cfg_errq_level = SOL_IPV6;
cfg_errq_type = IPV6_RECVERR;
@@ -362,7 +395,10 @@ int main(int argc, char **argv)
addr4.sin_family = AF_INET;
addr4.sin_port = htons(cfg_port);
- addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ if (!cfg_addr)
+ addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ else if (inet_pton(AF_INET, cfg_addr, &addr4.sin_addr) != 1)
+ error(1, 0, "ipv4 parse error: %s", cfg_addr);
cfg_errq_level = SOL_IP;
cfg_errq_type = IP_RECVERR;
--
2.27.0.278.ge193c7cf3a9-goog
next prev parent reply other threads:[~2020-06-09 14:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-09 14:09 [PATCH RFC net-next 0/6] multi release pacing for UDP GSO Willem de Bruijn
2020-06-09 14:09 ` [PATCH RFC net-next 1/6] net: multiple release time SO_TXTIME Willem de Bruijn
2020-06-09 14:09 ` [PATCH RFC net-next 2/6] net: build gso segs in multi " Willem de Bruijn
2020-06-09 14:09 ` [PATCH RFC net-next 3/6] net_sched: sch_fq: multiple release time support Willem de Bruijn
2020-06-09 15:00 ` Eric Dumazet
2020-06-09 15:10 ` Eric Dumazet
2020-06-09 14:09 ` Willem de Bruijn [this message]
2020-06-09 14:09 ` [PATCH RFC net-next 5/6] selftests/net: so_txtime: add gso and multi release pacing Willem de Bruijn
2020-06-09 14:09 ` [PATCH RFC net-next 6/6] selftests/net: upgso bench: add pacing with SO_TXTIME Willem de Bruijn
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=20200609140934.110785-5-willemdebruijn.kernel@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=willemb@google.com \
/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).