Deleted Added
sdiff udiff text old ( 278641 ) new ( 281746 )
full compact
1/*
2 * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved.
3 * Copyright (C) 2013-2014 Universita` di Pisa. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

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

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

178#define OPT_ACCESS 2
179#define OPT_COPY 4
180#define OPT_MEMCPY 8
181#define OPT_TS 16 /* add a timestamp */
182#define OPT_INDIRECT 32 /* use indirect buffers, tx only */
183#define OPT_DUMP 64 /* dump rx/tx traffic */
184#define OPT_MONITOR_TX 128
185#define OPT_MONITOR_RX 256
186#define OPT_RANDOM_SRC 512
187#define OPT_RANDOM_DST 1024
188 int dev_type;
189#ifndef NO_PCAP
190 pcap_t *p;
191#endif
192
193 int tx_rate;
194 struct timespec tx_period;
195

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

564update_addresses(struct pkt *pkt, struct glob_arg *g)
565{
566 uint32_t a;
567 uint16_t p;
568 struct ip *ip = &pkt->ip;
569 struct udphdr *udp = &pkt->udp;
570
571 do {
572 /* XXX for now it doesn't handle non-random src, random dst */
573 if (g->options & OPT_RANDOM_SRC) {
574 udp->uh_sport = random();
575 ip->ip_src.s_addr = random();
576 } else {
577 p = ntohs(udp->uh_sport);
578 if (p < g->src_ip.port1) { /* just inc, no wrap */
579 udp->uh_sport = htons(p + 1);
580 break;
581 }
582 udp->uh_sport = htons(g->src_ip.port0);
583
584 a = ntohl(ip->ip_src.s_addr);
585 if (a < g->src_ip.end) { /* just inc, no wrap */
586 ip->ip_src.s_addr = htonl(a + 1);
587 break;
588 }
589 ip->ip_src.s_addr = htonl(g->src_ip.start);
590
591 udp->uh_sport = htons(g->src_ip.port0);
592 }
593
594 if (g->options & OPT_RANDOM_DST) {
595 udp->uh_dport = random();
596 ip->ip_dst.s_addr = random();
597 } else {
598 p = ntohs(udp->uh_dport);
599 if (p < g->dst_ip.port1) { /* just inc, no wrap */
600 udp->uh_dport = htons(p + 1);
601 break;
602 }
603 udp->uh_dport = htons(g->dst_ip.port0);
604
605 a = ntohl(ip->ip_dst.s_addr);
606 if (a < g->dst_ip.end) { /* just inc, no wrap */
607 ip->ip_dst.s_addr = htonl(a + 1);
608 break;
609 }
610 }
611 ip->ip_dst.s_addr = htonl(g->dst_ip.start);
612 } while (0);
613 // update checksum
614}
615
616/*
617 * initialize one packet and prepare for the next one.

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

1403 "\t-c cores cores to use\n"
1404 "\t-p threads processes/threads to use\n"
1405 "\t-T report_ms milliseconds between reports\n"
1406 "\t-P use libpcap instead of netmap\n"
1407 "\t-w wait_for_link_time in seconds\n"
1408 "\t-R rate in packets per second\n"
1409 "\t-X dump payload\n"
1410 "\t-H len add empty virtio-net-header with size 'len'\n"
1411 "\t-P file load packet from pcap file\n"
1412 "\t-z use random IPv4 src address/port\n"
1413 "\t-Z use random IPv4 dst address/port\n"
1414 "",
1415 cmd);
1416
1417 exit(0);
1418}
1419
1420static void
1421start_threads(struct glob_arg *g)

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

1678 g.cpus = 1;
1679 g.forever = 1;
1680 g.tx_rate = 0;
1681 g.frags = 1;
1682 g.nmr_config = "";
1683 g.virt_header = 0;
1684
1685 while ( (ch = getopt(arc, argv,
1686 "a:f:F:n:i:Il:d:s:D:S:b:c:o:p:T:w:WvR:XC:H:e:m:P:zZ")) != -1) {
1687 struct sf *fn;
1688
1689 switch(ch) {
1690 default:
1691 D("bad option %c %s", ch, optarg);
1692 usage();
1693 break;
1694

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

1824 g.options |= OPT_MONITOR_RX;
1825 } else {
1826 D("unrecognized monitor mode %s", optarg);
1827 }
1828 break;
1829 case 'P':
1830 g.packet_file = strdup(optarg);
1831 break;
1832 case 'z':
1833 g.options |= OPT_RANDOM_SRC;
1834 break;
1835 case 'Z':
1836 g.options |= OPT_RANDOM_DST;
1837 break;
1838 }
1839 }
1840
1841 if (strlen(g.ifname) <=0 ) {
1842 D("missing ifname");
1843 usage();
1844 }
1845
1846 i = system_ncpus();

--- 184 unchanged lines hidden ---