Deleted Added
full compact
pkt-gen.c (238170) pkt-gen.c (238175)
1/*
2 * Copyright (C) 2011 Matteo Landi, Luigi Rizzo. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26/*
1/*
2 * Copyright (C) 2011 Matteo Landi, Luigi Rizzo. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26/*
27 * $FreeBSD: head/tools/tools/netmap/pkt-gen.c 238170 2012-07-06 15:36:39Z emaste $
27 * $FreeBSD: head/tools/tools/netmap/pkt-gen.c 238175 2012-07-06 17:03:43Z emaste $
28 * $Id: pkt-gen.c 10967 2012-05-03 11:29:23Z luigi $
29 *
30 * Example program to show how to build a multithreaded packet
31 * source/sink using the netmap device.
32 *
33 * In this example we create a programmable number of threads
34 * to take care of all the queues of the interface used to
35 * send or receive traffic.

--- 431 unchanged lines hidden (view full) ---

467static void *
468sender_body(void *data)
469{
470 struct targ *targ = (struct targ *) data;
471
472 struct pollfd fds[1];
473 struct netmap_if *nifp = targ->nifp;
474 struct netmap_ring *txring;
28 * $Id: pkt-gen.c 10967 2012-05-03 11:29:23Z luigi $
29 *
30 * Example program to show how to build a multithreaded packet
31 * source/sink using the netmap device.
32 *
33 * In this example we create a programmable number of threads
34 * to take care of all the queues of the interface used to
35 * send or receive traffic.

--- 431 unchanged lines hidden (view full) ---

467static void *
468sender_body(void *data)
469{
470 struct targ *targ = (struct targ *) data;
471
472 struct pollfd fds[1];
473 struct netmap_if *nifp = targ->nifp;
474 struct netmap_ring *txring;
475 int i, n = targ->g->npackets / targ->g->nthreads, sent = 0;
475 int i, pkts_per_td = targ->g->npackets / targ->g->nthreads, sent = 0;
476 int continuous = 0;
476 int options = targ->g->options | OPT_COPY;
477D("start");
477 int options = targ->g->options | OPT_COPY;
478D("start");
479 if (pkts_per_td == 0) {
480 continuous = 1;
481 pkts_per_td = 100000;
482 }
478 if (setaffinity(targ->thread, targ->affinity))
479 goto quit;
480 /* setup poll(2) mechanism. */
481 memset(fds, 0, sizeof(fds));
482 fds[0].fd = targ->fd;
483 fds[0].events = (POLLOUT);
484
485 /* main loop.*/
486 gettimeofday(&targ->tic, NULL);
487 if (targ->g->use_pcap) {
488 int size = targ->g->pkt_size;
489 void *pkt = &targ->pkt;
490 pcap_t *p = targ->g->p;
491
483 if (setaffinity(targ->thread, targ->affinity))
484 goto quit;
485 /* setup poll(2) mechanism. */
486 memset(fds, 0, sizeof(fds));
487 fds[0].fd = targ->fd;
488 fds[0].events = (POLLOUT);
489
490 /* main loop.*/
491 gettimeofday(&targ->tic, NULL);
492 if (targ->g->use_pcap) {
493 int size = targ->g->pkt_size;
494 void *pkt = &targ->pkt;
495 pcap_t *p = targ->g->p;
496
492 for (i = 0; sent < n && !targ->cancel; i++) {
497 for (i = 0; (sent < pkts_per_td && !targ->cancel) || continuous; i++) {
493 if (pcap_inject(p, pkt, size) != -1)
494 sent++;
495 if (i > 10000) {
496 targ->count = sent;
497 i = 0;
498 }
499 }
500 } else {
498 if (pcap_inject(p, pkt, size) != -1)
499 sent++;
500 if (i > 10000) {
501 targ->count = sent;
502 i = 0;
503 }
504 }
505 } else {
501 while (sent < n) {
506 while (sent < pkts_per_td || continuous) {
502
503 /*
504 * wait for available room in the send queue(s)
505 */
506 if (poll(fds, 1, 2000) <= 0) {
507 if (targ->cancel)
508 break;
509 D("poll error/timeout on queue %d\n", targ->me);
510 goto quit;
511 }
512 /*
513 * scan our queues and send on those with room
514 */
515 if (sent > 100000 && !(targ->g->options & OPT_COPY) )
516 options &= ~OPT_COPY;
517 for (i = targ->qfirst; i < targ->qlast && !targ->cancel; i++) {
507
508 /*
509 * wait for available room in the send queue(s)
510 */
511 if (poll(fds, 1, 2000) <= 0) {
512 if (targ->cancel)
513 break;
514 D("poll error/timeout on queue %d\n", targ->me);
515 goto quit;
516 }
517 /*
518 * scan our queues and send on those with room
519 */
520 if (sent > 100000 && !(targ->g->options & OPT_COPY) )
521 options &= ~OPT_COPY;
522 for (i = targ->qfirst; i < targ->qlast && !targ->cancel; i++) {
518 int m, limit = MIN(n - sent, targ->g->burst);
523 int m, limit = targ->g->burst;
524 if (!continuous && pkts_per_td - sent < limit)
525 limit = pkts_per_td - sent;
519
520 txring = NETMAP_TXRING(nifp, i);
521 if (txring->avail == 0)
522 continue;
523 m = send_packets(txring, &targ->pkt, targ->g->pkt_size,
524 limit, options);
525 sent += m;
526 targ->count = sent;

--- 70 unchanged lines hidden (view full) ---

597 goto quit;
598
599 /* setup poll(2) mechanism. */
600 memset(fds, 0, sizeof(fds));
601 fds[0].fd = targ->fd;
602 fds[0].events = (POLLIN);
603
604 /* unbounded wait for the first packet. */
526
527 txring = NETMAP_TXRING(nifp, i);
528 if (txring->avail == 0)
529 continue;
530 m = send_packets(txring, &targ->pkt, targ->g->pkt_size,
531 limit, options);
532 sent += m;
533 targ->count = sent;

--- 70 unchanged lines hidden (view full) ---

604 goto quit;
605
606 /* setup poll(2) mechanism. */
607 memset(fds, 0, sizeof(fds));
608 fds[0].fd = targ->fd;
609 fds[0].events = (POLLIN);
610
611 /* unbounded wait for the first packet. */
605 for (;;) {
612 while (!targ->cancel) {
606 i = poll(fds, 1, 1000);
607 if (i > 0 && !(fds[0].revents & POLLERR))
608 break;
609 D("waiting for initial packets, poll returns %d %d", i, fds[0].revents);
610 }
611
612 /* main loop, exit after 1s silence */
613 gettimeofday(&targ->tic, NULL);

--- 97 unchanged lines hidden (view full) ---

711static void
712usage(void)
713{
714 const char *cmd = "pkt-gen";
715 fprintf(stderr,
716 "Usage:\n"
717 "%s arguments\n"
718 "\t-i interface interface name\n"
613 i = poll(fds, 1, 1000);
614 if (i > 0 && !(fds[0].revents & POLLERR))
615 break;
616 D("waiting for initial packets, poll returns %d %d", i, fds[0].revents);
617 }
618
619 /* main loop, exit after 1s silence */
620 gettimeofday(&targ->tic, NULL);

--- 97 unchanged lines hidden (view full) ---

718static void
719usage(void)
720{
721 const char *cmd = "pkt-gen";
722 fprintf(stderr,
723 "Usage:\n"
724 "%s arguments\n"
725 "\t-i interface interface name\n"
719 "\t-t pkts_to_send also forces send mode\n"
726 "\t-t pkts_to_send also forces send mode, 0 = continuous\n"
720 "\t-r pkts_to_receive also forces receive mode\n"
721 "\t-l pkts_size in bytes excluding CRC\n"
722 "\t-d dst-ip end with %%n to sweep n addresses\n"
723 "\t-s src-ip end with %%n to sweep n addresses\n"
724 "\t-D dst-mac end with %%n to sweep n addresses\n"
725 "\t-S src-mac end with %%n to sweep n addresses\n"
726 "\t-b burst size testing, mostly\n"
727 "\t-c cores cores to use\n"

--- 395 unchanged lines hidden ---
727 "\t-r pkts_to_receive also forces receive mode\n"
728 "\t-l pkts_size in bytes excluding CRC\n"
729 "\t-d dst-ip end with %%n to sweep n addresses\n"
730 "\t-s src-ip end with %%n to sweep n addresses\n"
731 "\t-D dst-mac end with %%n to sweep n addresses\n"
732 "\t-S src-mac end with %%n to sweep n addresses\n"
733 "\t-b burst size testing, mostly\n"
734 "\t-c cores cores to use\n"

--- 395 unchanged lines hidden ---