Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/netmap/pkt-gen.c
Show First 20 Lines • Show All 1,810 Lines • ▼ Show 20 Lines | |||||
receiver_body(void *data) | receiver_body(void *data) | ||||
{ | { | ||||
struct targ *targ = (struct targ *) data; | struct targ *targ = (struct targ *) data; | ||||
struct pollfd pfd = { .fd = targ->fd, .events = POLLIN }; | struct pollfd pfd = { .fd = targ->fd, .events = POLLIN }; | ||||
struct netmap_if *nifp; | struct netmap_if *nifp; | ||||
struct netmap_ring *rxring; | struct netmap_ring *rxring; | ||||
int i; | int i; | ||||
struct my_ctrs cur; | struct my_ctrs cur; | ||||
uint64_t n = targ->g->npackets / targ->g->nthreads; | |||||
memset(&cur, 0, sizeof(cur)); | memset(&cur, 0, sizeof(cur)); | ||||
if (setaffinity(targ->thread, targ->affinity)) | if (setaffinity(targ->thread, targ->affinity)) | ||||
goto quit; | goto quit; | ||||
D("reading from %s fd %d main_fd %d", | D("reading from %s fd %d main_fd %d", | ||||
targ->g->ifname, targ->fd, targ->g->main_fd); | targ->g->ifname, targ->fd, targ->g->main_fd); | ||||
Show All 11 Lines | if (pfd.revents & POLLERR) { | ||||
goto quit; | goto quit; | ||||
} | } | ||||
RD(1, "waiting for initial packets, poll returns %d %d", | RD(1, "waiting for initial packets, poll returns %d %d", | ||||
i, pfd.revents); | i, pfd.revents); | ||||
} | } | ||||
/* main loop, exit after 1s silence */ | /* main loop, exit after 1s silence */ | ||||
clock_gettime(CLOCK_REALTIME_PRECISE, &targ->tic); | clock_gettime(CLOCK_REALTIME_PRECISE, &targ->tic); | ||||
if (targ->g->dev_type == DEV_TAP) { | if (targ->g->dev_type == DEV_TAP) { | ||||
while (!targ->cancel) { | while (!targ->cancel && (n == 0 || targ->ctr.pkts < n)) {) { | ||||
char buf[MAX_BODYSIZE]; | char buf[MAX_BODYSIZE]; | ||||
/* XXX should we poll ? */ | /* XXX should we poll ? */ | ||||
i = read(targ->g->main_fd, buf, sizeof(buf)); | i = read(targ->g->main_fd, buf, sizeof(buf)); | ||||
if (i > 0) { | if (i > 0) { | ||||
targ->ctr.pkts++; | targ->ctr.pkts++; | ||||
targ->ctr.bytes += i; | targ->ctr.bytes += i; | ||||
targ->ctr.events++; | targ->ctr.events++; | ||||
} | } | ||||
} | } | ||||
#ifndef NO_PCAP | #ifndef NO_PCAP | ||||
} else if (targ->g->dev_type == DEV_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 ? */ | /* XXX should we poll ? */ | ||||
pcap_dispatch(targ->g->p, targ->g->burst, receive_pcap, | pcap_dispatch(targ->g->p, targ->g->burst, receive_pcap, | ||||
(u_char *)&targ->ctr); | (u_char *)&targ->ctr); | ||||
targ->ctr.events++; | targ->ctr.events++; | ||||
} | } | ||||
#endif /* !NO_PCAP */ | #endif /* !NO_PCAP */ | ||||
} else { | } else { | ||||
int dump = targ->g->options & OPT_DUMP; | int dump = targ->g->options & OPT_DUMP; | ||||
nifp = targ->nmd->nifp; | 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 | /* Once we started to receive packets, wait at most 1 seconds | ||||
before quitting. */ | before quitting. */ | ||||
#ifdef BUSYWAIT | #ifdef BUSYWAIT | ||||
if (ioctl(pfd.fd, NIOCRXSYNC, NULL) < 0) { | if (ioctl(pfd.fd, NIOCRXSYNC, NULL) < 0) { | ||||
D("ioctl error on queue %d: %s", targ->me, | D("ioctl error on queue %d: %s", targ->me, | ||||
strerror(errno)); | strerror(errno)); | ||||
goto quit; | goto quit; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,404 Lines • Show Last 20 Lines |