version 1.24, 2011/08/23 04:13:38 |
version 1.25, 2011/09/09 00:40:54 |
|
|
static void tcp_server_accept(int, short, void *); |
static void tcp_server_accept(int, short, void *); |
static void server_init(struct addrinfo *, struct statctx *); |
static void server_init(struct addrinfo *, struct statctx *); |
static void client_handle_sc(int, short, void *); |
static void client_handle_sc(int, short, void *); |
static void client_init(struct addrinfo *, int, struct statctx *); |
static void client_init(struct addrinfo *, int, struct statctx *, |
|
struct addrinfo *); |
static int clock_gettime_tv(clockid_t, struct timeval *); |
static int clock_gettime_tv(clockid_t, struct timeval *); |
static void udp_server_handle_sc(int, short, void *); |
static void udp_server_handle_sc(int, short, void *); |
static void udp_process_slice(int, short, void *); |
static void udp_process_slice(int, short, void *); |
|
|
{ |
{ |
fprintf(stderr, |
fprintf(stderr, |
"usage: tcpbench -l\n" |
"usage: tcpbench -l\n" |
" tcpbench [-uv] [-B buf] [-k kvars] [-n connections] [-p port]\n" |
" tcpbench [-uv] [-B buf] [-b addr] [-k kvars] [-n connections]\n" |
" [-r interval] [-S space] [-T toskeyword] [-V rtable]\n" |
" [-p port] [-r interval] [-S space] [-T toskeyword]\n" |
" hostname\n" |
" [-V rtable] hostname\n" |
" tcpbench -s [-uv] [-B buf] [-k kvars] [-p port]\n" |
" tcpbench -s [-uv] [-B buf] [-k kvars] [-p port]\n" |
" [-r interval] [-S space] [-T toskeyword] [-V rtable]\n"); |
" [-r interval] [-S space] [-T toskeyword] [-V rtable]\n"); |
exit(1); |
exit(1); |
|
|
} |
} |
|
|
static void |
static void |
client_init(struct addrinfo *aitop, int nconn, struct statctx *udp_sc) |
client_init(struct addrinfo *aitop, int nconn, struct statctx *udp_sc, |
|
struct addrinfo *aib) |
{ |
{ |
struct statctx *sc; |
struct statctx *sc; |
struct addrinfo *ai; |
struct addrinfo *ai; |
|
|
warn("socket"); |
warn("socket"); |
continue; |
continue; |
} |
} |
|
if (aib != NULL) { |
|
saddr_ntop(aib->ai_addr, aib->ai_addrlen, |
|
tmp, sizeof(tmp)); |
|
if (ptb->vflag) |
|
fprintf(stderr, |
|
"Try to bind to %s\n", tmp); |
|
if (bind(sock, (struct sockaddr *)aib->ai_addr, |
|
aib->ai_addrlen) == -1) |
|
err(1, "bind"); |
|
freeaddrinfo(aib); |
|
} |
if (ptb->Tflag != -1 && ai->ai_family == AF_INET) { |
if (ptb->Tflag != -1 && ai->ai_family == AF_INET) { |
if (setsockopt(sock, IPPROTO_IP, IP_TOS, |
if (setsockopt(sock, IPPROTO_IP, IP_TOS, |
&ptb->Tflag, sizeof(ptb->Tflag))) |
&ptb->Tflag, sizeof(ptb->Tflag))) |
|
|
extern char *optarg; |
extern char *optarg; |
|
|
char kerr[_POSIX2_LINE_MAX], *tmp; |
char kerr[_POSIX2_LINE_MAX], *tmp; |
struct addrinfo *aitop, hints; |
struct addrinfo *aitop, *aib, hints; |
const char *errstr; |
const char *errstr; |
struct rlimit rl; |
struct rlimit rl; |
int ch, herr, nconn; |
int ch, herr, nconn; |
struct nlist nl[] = { { "_tcbtable" }, { "" } }; |
struct nlist nl[] = { { "_tcbtable" }, { "" } }; |
const char *host = NULL, *port = DEFAULT_PORT; |
const char *host = NULL, *port = DEFAULT_PORT, *srcbind = NULL; |
struct event ev_sigint, ev_sigterm, ev_sighup; |
struct event ev_sigint, ev_sigterm, ev_sighup; |
struct statctx *udp_sc = NULL; |
struct statctx *udp_sc = NULL; |
|
|
|
|
ptb->rflag = DEFAULT_STATS_INTERVAL; |
ptb->rflag = DEFAULT_STATS_INTERVAL; |
ptb->Tflag = -1; |
ptb->Tflag = -1; |
nconn = 1; |
nconn = 1; |
|
aib = NULL; |
|
|
while ((ch = getopt(argc, argv, "B:hlk:n:p:r:sS:T:uvV:")) != -1) { |
while ((ch = getopt(argc, argv, "b:B:hlk:n:p:r:sS:T:uvV:")) != -1) { |
switch (ch) { |
switch (ch) { |
|
case 'b': |
|
srcbind = optarg; |
|
break; |
case 'l': |
case 'l': |
list_kvars(); |
list_kvars(); |
exit(0); |
exit(0); |
|
|
} |
} |
|
|
bzero(&hints, sizeof(hints)); |
bzero(&hints, sizeof(hints)); |
if (UDP_MODE) |
if (UDP_MODE) { |
hints.ai_socktype = SOCK_DGRAM; |
hints.ai_socktype = SOCK_DGRAM; |
else |
hints.ai_protocol = IPPROTO_UDP; |
|
} |
|
else { |
hints.ai_socktype = SOCK_STREAM; |
hints.ai_socktype = SOCK_STREAM; |
|
hints.ai_protocol = IPPROTO_TCP; |
|
} |
if (ptb->sflag) |
if (ptb->sflag) |
hints.ai_flags = AI_PASSIVE; |
hints.ai_flags = AI_PASSIVE; |
|
if (srcbind != NULL) { |
|
hints.ai_flags |= AI_NUMERICHOST; |
|
herr = getaddrinfo(srcbind, NULL, &hints, &aib); |
|
hints.ai_flags &= ~AI_NUMERICHOST; |
|
if (herr != 0) { |
|
if (herr == EAI_SYSTEM) |
|
err(1, "getaddrinfo"); |
|
else |
|
errx(1, "getaddrinfo: %s", gai_strerror(herr)); |
|
} |
|
} |
if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) { |
if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) { |
if (herr == EAI_SYSTEM) |
if (herr == EAI_SYSTEM) |
err(1, "getaddrinfo"); |
err(1, "getaddrinfo"); |
|
|
if (ptb->sflag) { |
if (ptb->sflag) { |
server_init(aitop, udp_sc); |
server_init(aitop, udp_sc); |
} else |
} else |
client_init(aitop, nconn, udp_sc); |
client_init(aitop, nconn, udp_sc, aib); |
|
|
/* libevent main loop*/ |
/* libevent main loop*/ |
event_dispatch(); |
event_dispatch(); |