pkt-gen.c (278641) | pkt-gen.c (281746) |
---|---|
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/* | 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 278641 2015-02-12 23:00:31Z gnn $ | 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 | 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 |
|
186 int dev_type; 187#ifndef NO_PCAP 188 pcap_t *p; 189#endif 190 191 int tx_rate; 192 struct timespec tx_period; 193 --- 368 unchanged lines hidden (view full) --- 562update_addresses(struct pkt *pkt, struct glob_arg *g) 563{ 564 uint32_t a; 565 uint16_t p; 566 struct ip *ip = &pkt->ip; 567 struct udphdr *udp = &pkt->udp; 568 569 do { | 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 { |
570 p = ntohs(udp->uh_sport); 571 if (p < g->src_ip.port1) { /* just inc, no wrap */ 572 udp->uh_sport = htons(p + 1); 573 break; 574 } 575 udp->uh_sport = htons(g->src_ip.port0); | 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); |
576 | 583 |
577 a = ntohl(ip->ip_src.s_addr); 578 if (a < g->src_ip.end) { /* just inc, no wrap */ 579 ip->ip_src.s_addr = htonl(a + 1); 580 break; 581 } 582 ip->ip_src.s_addr = htonl(g->src_ip.start); | 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); |
583 | 590 |
584 udp->uh_sport = htons(g->src_ip.port0); 585 p = ntohs(udp->uh_dport); 586 if (p < g->dst_ip.port1) { /* just inc, no wrap */ 587 udp->uh_dport = htons(p + 1); 588 break; | 591 udp->uh_sport = htons(g->src_ip.port0); |
589 } | 592 } |
590 udp->uh_dport = htons(g->dst_ip.port0); | |
591 | 593 |
592 a = ntohl(ip->ip_dst.s_addr); 593 if (a < g->dst_ip.end) { /* just inc, no wrap */ 594 ip->ip_dst.s_addr = htonl(a + 1); 595 break; | 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 } |
596 } 597 ip->ip_dst.s_addr = htonl(g->dst_ip.start); 598 } while (0); 599 // update checksum 600} 601 602/* 603 * initialize one packet and prepare for the next one. --- 785 unchanged lines hidden (view full) --- 1389 "\t-c cores cores to use\n" 1390 "\t-p threads processes/threads to use\n" 1391 "\t-T report_ms milliseconds between reports\n" 1392 "\t-P use libpcap instead of netmap\n" 1393 "\t-w wait_for_link_time in seconds\n" 1394 "\t-R rate in packets per second\n" 1395 "\t-X dump payload\n" 1396 "\t-H len add empty virtio-net-header with size 'len'\n" | 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" |
1397 "\t-P file load packet from pcap file" | 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" |
1398 "", 1399 cmd); 1400 1401 exit(0); 1402} 1403 1404static void 1405start_threads(struct glob_arg *g) --- 256 unchanged lines hidden (view full) --- 1662 g.cpus = 1; 1663 g.forever = 1; 1664 g.tx_rate = 0; 1665 g.frags = 1; 1666 g.nmr_config = ""; 1667 g.virt_header = 0; 1668 1669 while ( (ch = getopt(arc, argv, | 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, |
1670 "a:f:F:n:i:Il:d:s:D:S:b:c:o:p:T:w:WvR:XC:H:e:m:P:")) != -1) { | 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) { |
1671 struct sf *fn; 1672 1673 switch(ch) { 1674 default: 1675 D("bad option %c %s", ch, optarg); 1676 usage(); 1677 break; 1678 --- 129 unchanged lines hidden (view full) --- 1808 g.options |= OPT_MONITOR_RX; 1809 } else { 1810 D("unrecognized monitor mode %s", optarg); 1811 } 1812 break; 1813 case 'P': 1814 g.packet_file = strdup(optarg); 1815 break; | 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; |
|
1816 } | 1838 } |
1817 | |
1818 } 1819 1820 if (strlen(g.ifname) <=0 ) { 1821 D("missing ifname"); 1822 usage(); 1823 } 1824 1825 i = system_ncpus(); --- 184 unchanged lines hidden --- | 1839 } 1840 1841 if (strlen(g.ifname) <=0 ) { 1842 D("missing ifname"); 1843 usage(); 1844 } 1845 1846 i = system_ncpus(); --- 184 unchanged lines hidden --- |