Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/netmap/pkt-gen.c
Show First 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | |||||
#define OPT_ACCESS 2 | #define OPT_ACCESS 2 | ||||
#define OPT_COPY 4 | #define OPT_COPY 4 | ||||
#define OPT_MEMCPY 8 | #define OPT_MEMCPY 8 | ||||
#define OPT_TS 16 /* add a timestamp */ | #define OPT_TS 16 /* add a timestamp */ | ||||
#define OPT_INDIRECT 32 /* use indirect buffers, tx only */ | #define OPT_INDIRECT 32 /* use indirect buffers, tx only */ | ||||
#define OPT_DUMP 64 /* dump rx/tx traffic */ | #define OPT_DUMP 64 /* dump rx/tx traffic */ | ||||
#define OPT_MONITOR_TX 128 | #define OPT_MONITOR_TX 128 | ||||
#define OPT_MONITOR_RX 256 | #define OPT_MONITOR_RX 256 | ||||
#define OPT_RANDOM_SRC 512 | |||||
#define OPT_RANDOM_DST 1024 | |||||
int dev_type; | int dev_type; | ||||
#ifndef NO_PCAP | #ifndef NO_PCAP | ||||
pcap_t *p; | pcap_t *p; | ||||
#endif | #endif | ||||
int tx_rate; | int tx_rate; | ||||
struct timespec tx_period; | struct timespec tx_period; | ||||
▲ Show 20 Lines • Show All 368 Lines • ▼ Show 20 Lines | |||||
update_addresses(struct pkt *pkt, struct glob_arg *g) | update_addresses(struct pkt *pkt, struct glob_arg *g) | ||||
{ | { | ||||
uint32_t a; | uint32_t a; | ||||
uint16_t p; | uint16_t p; | ||||
struct ip *ip = &pkt->ip; | struct ip *ip = &pkt->ip; | ||||
struct udphdr *udp = &pkt->udp; | struct udphdr *udp = &pkt->udp; | ||||
do { | do { | ||||
/* XXX for now it doesn't handle non-random src, random dst */ | |||||
if (g->options & OPT_RANDOM_SRC) { | |||||
udp->uh_sport = random(); | |||||
ip->ip_src.s_addr = random(); | |||||
} else { | |||||
p = ntohs(udp->uh_sport); | p = ntohs(udp->uh_sport); | ||||
if (p < g->src_ip.port1) { /* just inc, no wrap */ | if (p < g->src_ip.port1) { /* just inc, no wrap */ | ||||
udp->uh_sport = htons(p + 1); | udp->uh_sport = htons(p + 1); | ||||
break; | break; | ||||
} | } | ||||
udp->uh_sport = htons(g->src_ip.port0); | udp->uh_sport = htons(g->src_ip.port0); | ||||
a = ntohl(ip->ip_src.s_addr); | a = ntohl(ip->ip_src.s_addr); | ||||
hiren: Are these all whitespace changes or something funky that phabricator is doing? | |||||
if (a < g->src_ip.end) { /* just inc, no wrap */ | if (a < g->src_ip.end) { /* just inc, no wrap */ | ||||
ip->ip_src.s_addr = htonl(a + 1); | ip->ip_src.s_addr = htonl(a + 1); | ||||
break; | break; | ||||
} | } | ||||
ip->ip_src.s_addr = htonl(g->src_ip.start); | ip->ip_src.s_addr = htonl(g->src_ip.start); | ||||
udp->uh_sport = htons(g->src_ip.port0); | udp->uh_sport = htons(g->src_ip.port0); | ||||
} | |||||
if (g->options & OPT_RANDOM_DST) { | |||||
udp->uh_dport = random(); | |||||
ip->ip_dst.s_addr = random(); | |||||
} else { | |||||
p = ntohs(udp->uh_dport); | p = ntohs(udp->uh_dport); | ||||
if (p < g->dst_ip.port1) { /* just inc, no wrap */ | if (p < g->dst_ip.port1) { /* just inc, no wrap */ | ||||
udp->uh_dport = htons(p + 1); | udp->uh_dport = htons(p + 1); | ||||
break; | break; | ||||
} | } | ||||
udp->uh_dport = htons(g->dst_ip.port0); | udp->uh_dport = htons(g->dst_ip.port0); | ||||
a = ntohl(ip->ip_dst.s_addr); | a = ntohl(ip->ip_dst.s_addr); | ||||
if (a < g->dst_ip.end) { /* just inc, no wrap */ | if (a < g->dst_ip.end) { /* just inc, no wrap */ | ||||
ip->ip_dst.s_addr = htonl(a + 1); | ip->ip_dst.s_addr = htonl(a + 1); | ||||
break; | break; | ||||
} | } | ||||
} | |||||
ip->ip_dst.s_addr = htonl(g->dst_ip.start); | ip->ip_dst.s_addr = htonl(g->dst_ip.start); | ||||
} while (0); | } while (0); | ||||
// update checksum | // update checksum | ||||
} | } | ||||
/* | /* | ||||
* initialize one packet and prepare for the next one. | * initialize one packet and prepare for the next one. | ||||
* The copy could be done better instead of repeating it each time. | * The copy could be done better instead of repeating it each time. | ||||
▲ Show 20 Lines • Show All 784 Lines • ▼ Show 20 Lines | fprintf(stderr, | ||||
"\t-c cores cores to use\n" | "\t-c cores cores to use\n" | ||||
"\t-p threads processes/threads to use\n" | "\t-p threads processes/threads to use\n" | ||||
"\t-T report_ms milliseconds between reports\n" | "\t-T report_ms milliseconds between reports\n" | ||||
"\t-P use libpcap instead of netmap\n" | "\t-P use libpcap instead of netmap\n" | ||||
"\t-w wait_for_link_time in seconds\n" | "\t-w wait_for_link_time in seconds\n" | ||||
"\t-R rate in packets per second\n" | "\t-R rate in packets per second\n" | ||||
"\t-X dump payload\n" | "\t-X dump payload\n" | ||||
"\t-H len add empty virtio-net-header with size 'len'\n" | "\t-H len add empty virtio-net-header with size 'len'\n" | ||||
"\t-P file load packet from pcap file" | "\t-P file load packet from pcap file\n" | ||||
"\t-z use random IPv4 src address/port\n" | |||||
"\t-Z use random IPv4 dst address/port\n" | |||||
"", | "", | ||||
cmd); | cmd); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
static void | static void | ||||
start_threads(struct glob_arg *g) | start_threads(struct glob_arg *g) | ||||
▲ Show 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | main(int arc, char **argv) | ||||
g.cpus = 1; | g.cpus = 1; | ||||
g.forever = 1; | g.forever = 1; | ||||
g.tx_rate = 0; | g.tx_rate = 0; | ||||
g.frags = 1; | g.frags = 1; | ||||
g.nmr_config = ""; | g.nmr_config = ""; | ||||
g.virt_header = 0; | g.virt_header = 0; | ||||
while ( (ch = getopt(arc, argv, | while ( (ch = getopt(arc, argv, | ||||
"a:f:F:n:i:Il:d:s:D:S:b:c:o:p:T:w:WvR:XC:H:e:m:P:")) != -1) { | "a:f:F:n:i:Il:d:s:D:S:b:c:o:p:T:w:WvR:XC:H:e:m:P:zZ")) != -1) { | ||||
struct sf *fn; | struct sf *fn; | ||||
switch(ch) { | switch(ch) { | ||||
default: | default: | ||||
D("bad option %c %s", ch, optarg); | D("bad option %c %s", ch, optarg); | ||||
usage(); | usage(); | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | case 'm': | ||||
g.options |= OPT_MONITOR_RX; | g.options |= OPT_MONITOR_RX; | ||||
} else { | } else { | ||||
D("unrecognized monitor mode %s", optarg); | D("unrecognized monitor mode %s", optarg); | ||||
} | } | ||||
break; | break; | ||||
case 'P': | case 'P': | ||||
g.packet_file = strdup(optarg); | g.packet_file = strdup(optarg); | ||||
break; | break; | ||||
case 'z': | |||||
g.options |= OPT_RANDOM_SRC; | |||||
break; | |||||
case 'Z': | |||||
g.options |= OPT_RANDOM_DST; | |||||
break; | |||||
} | } | ||||
} | } | ||||
if (strlen(g.ifname) <=0 ) { | if (strlen(g.ifname) <=0 ) { | ||||
D("missing ifname"); | D("missing ifname"); | ||||
usage(); | usage(); | ||||
} | } | ||||
i = system_ncpus(); | i = system_ncpus(); | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |
Are these all whitespace changes or something funky that phabricator is doing?