pkt-gen: Allow limiting received packets

Makes pkg-gen quit after having received N packets, the same way it
already supports doing for sent packets.

Reviewed by:	vmaffione
Sponsored by:	Klara Inc.
MFC after:	4 weeks
Differential Revision:	https://reviews.freebsd.org/D30266
This commit is contained in:
Allan Jude 2021-05-17 23:04:08 +00:00
parent 73e77cf90b
commit 20d684ecc9

View File

@ -1816,6 +1816,7 @@ receiver_body(void *data)
struct netmap_ring *rxring;
int i;
struct my_ctrs cur;
uint64_t n = targ->g->npackets / targ->g->nthreads;
memset(&cur, 0, sizeof(cur));
@ -1843,7 +1844,7 @@ receiver_body(void *data)
/* main loop, exit after 1s silence */
clock_gettime(CLOCK_REALTIME_PRECISE, &targ->tic);
if (targ->g->dev_type == DEV_TAP) {
while (!targ->cancel) {
while (!targ->cancel && (n == 0 || targ->ctr.pkts < n)) {) {
char buf[MAX_BODYSIZE];
/* XXX should we poll ? */
i = read(targ->g->main_fd, buf, sizeof(buf));
@ -1855,7 +1856,7 @@ receiver_body(void *data)
}
#ifndef NO_PCAP
} else if (targ->g->dev_type == DEV_PCAP) {
while (!targ->cancel) {
while (!targ->cancel && (n == 0 || targ->ctr.pkts < n)) {
/* XXX should we poll ? */
pcap_dispatch(targ->g->p, targ->g->burst, receive_pcap,
(u_char *)&targ->ctr);
@ -1866,7 +1867,7 @@ receiver_body(void *data)
int dump = targ->g->options & OPT_DUMP;
nifp = targ->nmd->nifp;
while (!targ->cancel) {
while (!targ->cancel && (n == 0 || targ->ctr.pkts < n)) {
/* Once we started to receive packets, wait at most 1 seconds
before quitting. */
#ifdef BUSYWAIT