68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * Copyright (C) 2000, 2001 Nominum, Inc.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *** DNS Query Performance Testing Tool (queryperf.c)
9db88ce113701a6fb600a67aaa65764d800e25b0Mark Andrews *** Version $Id: queryperf.c,v 1.12 2007/09/05 07:36:04 marka Exp $
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *** Stephen Jacob <sj@nominum.com>
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews#define BIND_8_COMPAT /* Pull in <arpa/nameser_compat.h> */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Configuration defaults
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define DEF_QUERY_TIMEOUT 5 /* in seconds */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉#define DEF_RTTARRAY_UNIT 100 /* in usec */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Other constants / definitions
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define MAX_BUFFER_LEN 8192 /* in bytes */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define HARD_TIMEOUT_EXTRA 5 /* in seconds */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define RESPONSE_BLOCKING_WAIT_TIME 0.1 /* in seconds */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonenum directives_enum { V_SERVER, V_PORT, V_MAXQUERIES, V_MAXWAIT };
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define DIRECTIVES { "server", "port", "maxqueries", "maxwait" }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define DIR_VALUES { V_SERVER, V_PORT, V_MAXQUERIES, V_MAXWAIT }
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "A", "NS", "MD", "MF", "CNAME", "SOA", "MB", "MG", "MR", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "NULL", "WKS", "PTR", "HINFO", "MINFO", "MX", "TXT", "RP", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "AFSDB", "X25", "ISDN", "RT", "NSAP", "NSAP-PTR", "SIG", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "KEY", "PX", "GPOS", "AAAA", "LOC", "NXT", "EID", "NIMLOC", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "SRV", "ATMA", "NAPTR", "KX", "CERT", "A6", "DNAME", "SINK", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "OPT", "APL", "DS", "SSHFP", "IPSECKEY", "RRSIG", "NSEC", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "DNSKEY", "DHCID", "NSEC3", "NSEC3PARAM", "TLSA", "HIP", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "NINFO", "RKEY", "TALINK", "CDS", "SPF", "UINFO", "UID", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "GID", "UNSPEC", "NID", "L32", "L64", "LP", "TKEY", "TSIG", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt "IXFR", "AXFR", "MAILB", "MAILA", "URI", "CAA", "*", "ANY", \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt 49, 50, 51, 52, 55, 56, 57, 58, 59, 99, 100, 101, 102, 103, \
3192f9981331ae89c91a03f1c0f1e3b843fd4f21Evan Hunt 104, 105, 106, 107, 249, 250, 251, 252, 253, 254, 255, 255, \
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews "NOERROR", "FORMERR", "SERVFAIL", "NXDOMAIN", \
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Data type definitions
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define QUERY_STATUS_MAGIC 0x51535441U /* QSTA */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define VALID_QUERY_STATUS(q) ((q) != NULL && \
384fef003441df4067b773688237700513390f9eEvan Huntstruct query_mininfo { /* minimum info for timeout queries */
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews * Forward declarations.
66f51d8678c8fcc7256354b599317f67455120fdMark Andrewsint is_uint(char *test_int, unsigned int *result);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Configuration options (global)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int max_queries_outstanding; /* init 0 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int query_timeout = DEF_QUERY_TIMEOUT;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int socket_bufsize = DEF_BUFFER_SIZE;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉struct addrinfo *server_ai; /* init NULL */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonint queriesset = FALSE, timeoutset = FALSE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Other global stuff
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int runs_through_file; /* init 0 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int num_queries_sent; /* init 0 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int num_queries_outstanding; /* init 0 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int num_queries_timed_out; /* init 0 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉unsigned int num_queries_possiblydelayed; /* init 0 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉unsigned int num_queries_timed_out_interval;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉unsigned int num_queries_possiblydelayed_interval;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉struct timeval time_of_first_query_interval;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstruct query_status *status; /* init NULL */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonunsigned int query_status_allocated; /* init 0 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Get an unsigned short integer from a buffer (in network order)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic unsigned short
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * show_startup_info:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson"DNS Query Performance Testing Tool\n"
9db88ce113701a6fb600a67aaa65764d800e25b0Mark Andrews"Version: $Id: queryperf.c,v 1.12 2007/09/05 07:36:04 marka Exp $\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Print out usage/syntax information
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson"Usage: queryperf [-d datafile] [-s server_addr] [-p port] [-q num_queries]\n"
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉" [-b bufsize] [-t timeout] [-n] [-l limit] [-f family] [-1]\n"
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉" [-i interval] [-r arraysize] [-u unit] [-H histfile]\n"
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews" [-T qps] [-e] [-D] [-R] [-c] [-v] [-h]\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -d specifies the input data file (default: stdin)\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -s sets the server to query (default: %s)\n"
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉" -p sets the port on which to query the server (default: %s)\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -q specifies the maximum number of queries outstanding (default: %d)\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -t specifies the timeout for query completion in seconds (default: %d)\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -n causes configuration changes to be ignored\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -l specifies how a limit for how long to run tests in seconds (no default)\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -1 run through input only once (default: multiple iff limit given)\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson" -b set input/output buffer size in kilobytes (default: %d k)\n"
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉" -i specifies interval of intermediate outputs in seconds (default: 0=none)\n"
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉" -f specify address family of DNS transport, inet or inet6 (default: any)\n"
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉" -r set RTT statistics array size (default: %d)\n"
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉" -u set RTT statistics time unit in usec (default: %d)\n"
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉" -H specifies RTT histogram data file (default: none)\n"
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉" -T specify the target qps (default: 0=unspecified)\n"
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews" -e enable EDNS 0\n"
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews" -D set the DNSSEC OK bit (implies EDNS)\n"
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews" -R disable recursion\n"
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews" -c print the number of packets with each rcode\n"
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson" -v verbose: report the RCODE of each response on stdout\n"
bd3946db298667e769804b2e978df2d6dcd85e29Mark Andrews" -h print this usage\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson DEF_MAX_QUERIES_OUTSTANDING, DEF_QUERY_TIMEOUT,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 DEF_BUFFER_SIZE, DEF_RTTARRAY_SIZE, DEF_RTTARRAY_UNIT);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * set_datafile:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set the datafile to read
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return a non-negative integer otherwise
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((new_file == NULL) || (new_file[0] == '\0')) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error: null datafile name\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((dfname_tmp = malloc(strlen(new_file) + 1)) == NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error allocating memory for datafile name: "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * set_input_stdin:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set the input to be stdin (instead of a datafile)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set the server to be queried
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return a non-negative integer otherwise
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* If no change in server name, don't do anything... */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((server_to_query != NULL) && (new_name != NULL))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (strcmp(new_name, server_to_query) == 0)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((new_name == NULL) || (new_name[0] == '\0')) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error: null server name\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((server_to_query = malloc(strlen(new_name) + 1)) == NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error allocating memory for server name: "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * set_server_port:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set the port on which to contact the server
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 if port is invalid
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return a non-negative integer otherwise
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((is_uint(new_port, &uint_val)) != TRUE)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (server_port != NULL && new_port != NULL &&
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((server_port = malloc(strlen(new_port) + 1)) == NULL) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "Error allocating memory for server port: "
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (proto == NULL && (proto = getprotobyname("udp")) == NULL) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "Error: getprotobyname call failed");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((error = getaddrinfo(server_to_query, server_port,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "Error: getaddrinfo(%s, %s) failed\n",
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /* replace the server's addrinfo */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Tests if a character is a digit
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return TRUE if it is
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return FALSE if it is not
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Tests if a string, test_int, is a valid unsigned integer
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Sets *result to be the unsigned integer if it is valid
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return TRUE if it is
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return FALSE if it is not
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonis_uint(char *test_int, unsigned int *result) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((errno == ERANGE) || (*end != '\0') || (value > UINT_MAX))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * set_max_queries:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set the maximum number of outstanding queries
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Returns -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Returns a non-negative integer otherwise
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson static unsigned int size_qs = sizeof(struct query_status);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson temp_stat = realloc(status, new_max * size_qs);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error resizing query_status\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Be careful to only initialise between above
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * the previously allocated space. Note that the
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * allocation may be larger than the current
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * max_queries_outstanding. We don't want to
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * "forget" any outstanding queries! We might
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * still have some above the bounds of the max.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson status[count].magic = QUERY_STATUS_MAGIC;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Parse program arguments and set configuration options
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return a non-negative integer otherwise
7d8bfa8f8ea4c222b9403fe97dba0523d768f667Mark Andrews "f:q:t:i:nd:s:p:1l:b:eDcvr:RT:u:H:h")) != -1) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "Invalid address family: %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (is_uint(optarg, &uint_arg_val) == TRUE) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Option requires a positive "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "integer value: -%c %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (is_uint(optarg, &uint_arg_val) == TRUE) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Option requires a positive "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "integer value: -%c %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error setting datafile "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (is_uint(optarg, &uint_arg_val) == TRUE &&
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Option requires a positive "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "integer between 0 and %d: -%c %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (is_uint(optarg, &uint_arg_val) == TRUE) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Option requires a positive "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "integer: -%c %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (is_uint(optarg, &uint_arg_val) == TRUE) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Option requires a positive "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "integer: -%c %s\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (is_uint(optarg, &uint_arg_val) == TRUE)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 fprintf(stderr, "Invalid interval: %s\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (is_uint(optarg, &uint_arg_val) == TRUE)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 fprintf(stderr, "Invalid RTT array size: %s\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (is_uint(optarg, &uint_arg_val) == TRUE)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 fprintf(stderr, "Invalid RTT unit: %s\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (is_uint(optarg, &uint_arg_val) == TRUE)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 fprintf(stderr, "Invalid target qps: %s\n",
bd3946db298667e769804b2e978df2d6dcd85e29Mark Andrews return (-1);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Invalid option: -%c\n", optopt);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (run_only_once == FALSE && use_timelimit == FALSE)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * open_datafile:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Open the data file ready for reading
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return non-negative integer on success
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((datafile_ptr = fopen(datafile_name, "r")) == NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error: unable to open datafile: %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * close_datafile:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Close the data file if any is open
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return non-negative integer on success, including if not needed
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((use_stdin == FALSE) && (datafile_ptr != NULL)) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error: unable to close datafile\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * open_socket:
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Open a socket for the queries. When we have an active socket already,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * close it and open a new one.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Return the socket identifier
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 hints.ai_socktype = server_ai->ai_socktype;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 hints.ai_protocol = server_ai->ai_protocol;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((ret = getaddrinfo(NULL, "0", &hints, &res)) != 0) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "Error: getaddrinfo for bind socket failed: %s\n",
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((sock = socket(res->ai_family, SOCK_DGRAM,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error: socket call failed");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#if defined(AF_INET6) && defined(IPV6_V6ONLY)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "Warning: setsockopt(IPV6_V6ONLY) failed\n");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (bind(sock, res->ai_addr, res->ai_addrlen) == -1)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "Error: bind call failed");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Warning: setsockbuf(SO_RCVBUF) failed\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Warning: setsockbuf(SO_SNDBUF) failed\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * close_socket:
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Close the query socket(s)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return a non-negative integer otherwise
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "Error: unable to close IPv4 socket\n");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "Error: unable to close IPv6 socket\n");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * change_socket:
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Choose an appropriate socket according to the address family of the
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * current server. Open a new socket if necessary.
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Return -1 on failure
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Return the socket identifier
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "unexpected address family: %d\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * reset_rttarray:
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * (re)allocate RTT array and zero-clear the whole buffer.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * if array is being used, it is freed.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Returns -1 on failure
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Returns a non-negative integer otherwise
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 rttarray = malloc(size * sizeof(rttarray[0]));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "Error: allocating memory for RTT array\n");
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 memset(rttarray, 0, size * sizeof(rttarray[0]));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "Error: allocating memory for RTT array\n");
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * set_query_interval:
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * set the interval of consecutive queries if the target qps are specified.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Returns -1 on failure
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Returns a non-negative integer otherwise
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set configuration options from command line arguments
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Open datafile ready for reading
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return non-negative integer on success
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (set_max_queries(DEF_MAX_QUERIES_OUTSTANDING) == -1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s: Unable to set default max outstanding "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (set_server(DEF_SERVER_TO_QUERY) == -1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s: Error setting default server name\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (set_server_port(DEF_SERVER_PORT) == -1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s: Error setting default server port\n",
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((query_socket = change_socket()) == -1)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (set_query_interval(target_qps) == -1)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * set_timenow:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set a timeval struct to indicate the current time
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error in gettimeofday(). Using inaccurate "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "time() instead\n");
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * add tv1 and tv2, store the result in tv_result.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉addtv(struct timeval *tv1, struct timeval *tv2, struct timeval *tv_result) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 tv_result->tv_sec = tv1->tv_sec + tv2->tv_sec;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 tv_result->tv_usec = tv1->tv_usec + tv2->tv_usec;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Find the difference in seconds between two timeval structs.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return the difference between tv1 and tv2 in seconds in a double.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssondifftv(struct timeval tv1, struct timeval tv2) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson diff = (double)diff_sec + ((double)diff_usec / 1000000.0);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * timelimit_reached:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Have we reached the time limit (if any)?
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Returns FALSE if there is no time limit or if we have not reached it
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Returns TRUE otherwise
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (difftv(time_now, time_of_program_start)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson < (double)(run_timelimit + HARD_TIMEOUT_EXTRA))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (difftv(time_now, time_of_first_query)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * keep_sending:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Should we keep sending queries or stop here?
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return TRUE if we should keep on sending queries
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return FALSE if we should stop
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Side effects:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Rewinds the input and clears reached_end_input if we have reached the
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * end of the input, but we are meant to run through it multiple times
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * and have not hit the time limit yet (if any is set).
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((*reached_end_input == FALSE) && (timelimit_reached() == FALSE))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson else if ((*reached_end_input == TRUE) && (run_only_once == FALSE)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * queries_outstanding:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * How many queries are outstanding?
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Returns the number of outstanding queries
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * next_input_line:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Get the next non-comment line from the input file
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Put text in line, up to max of n chars. Skip comment lines.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Skip empty lines.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return line length on success
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return 0 if cannot read a non-comment line (EOF or error)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ((line[0] == COMMENT_CHAR) || (line[0] == '\n')));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * identify_directive:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Gives us a numerical value equivelant for a directive string
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Returns the value for the directive
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Returns -1 if not a valid directive
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson num_directives = sizeof(directives) / sizeof(directives[0]);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (num_directives > (sizeof(dir_values) / sizeof(int)))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson num_directives = sizeof(dir_values) / sizeof(int);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson for (index = 0; index < num_directives; index++) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * update_config:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Update configuration options from a line from the input file
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char *directive, *config_value, *trailing_garbage;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Ignoring configuration change: %s",
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson fprintf(stderr, "Invalid config: No directive present: %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (index(WHITESPACE, *config_change_desc) != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Invalid config: Space before directive or "
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson "no directive present: %s\n", conf_copy);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson directive = strtok(config_change_desc, WHITESPACE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson trailing_garbage = strtok(NULL, WHITESPACE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((directive_number = identify_directive(directive)) == -1) {
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson fprintf(stderr, "Invalid config: Bad directive: %s\n",
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson fprintf(stderr, "Invalid config: No value present: %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (serverset && (setup_phase == TRUE)) {
6d7939a85025621aa11e9cfe933629113bd0963aMark Andrews fprintf(stderr, "Config change overridden by command "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Set server error: unable to change "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "the server name to '%s'\n", config_value);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "Set server error: unable to resolve "
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "a new server '%s'\n",
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((query_socket = change_socket()) == -1) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /* XXX: this is fatal */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "unable to open a new socket "
6d7939a85025621aa11e9cfe933629113bd0963aMark Andrews fprintf(stderr, "Config change overridden by command "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson check = is_uint(config_value, &uint_val);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (set_server_port(config_value) == -1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Invalid config: Bad value for"
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "Failed to set a new port\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Invalid config: Bad value for "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (queriesset && (setup_phase == TRUE)) {
6d7939a85025621aa11e9cfe933629113bd0963aMark Andrews fprintf(stderr, "Config change overridden by command "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson check = is_uint(config_value, &uint_val);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Invalid config: Bad value for "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (timeoutset && (setup_phase == TRUE)) {
6d7939a85025621aa11e9cfe933629113bd0963aMark Andrews fprintf(stderr, "Config change overridden by command "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson check = is_uint(config_value, &uint_val);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Invalid config: Bad value for "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Invalid config: Bad directive: %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * parse_query:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Parse a query line from the input file
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set qname to be the domain to query (up to a max of qnlen chars)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Set qtype to be the type of the query
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return a non-negative integer otherwise
384fef003441df4067b773688237700513390f9eEvan Huntparse_query(char *input, char *qname, unsigned int qnlen, int *qtype) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson static char *qtype_strings[] = QTYPE_STRINGS;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson num_types = sizeof(qtype_strings) / sizeof(qtype_strings[0]);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (num_types > (sizeof(qtype_codes) / sizeof(int)))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson num_types = sizeof(qtype_codes) / sizeof(int);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((domain_str == NULL) || (type_str == NULL)) {
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews fprintf(stderr, "Invalid query input format: %s\n", input);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Query domain too long: %s\n", domain_str);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson for (index = 0; (index < num_types) && (found == FALSE); index++) {
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews if (strcasecmp(type_str, qtype_strings[index]) == 0) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Query type not understood: %s\n", type_str);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * dispatch_query:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Send the query packet for the entry
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return -1 on failure
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Return a non-negative integer otherwise
384fef003441df4067b773688237700513390f9eEvan Huntdispatch_query(unsigned short int id, char *dom, int qt, u_char **pktp,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson static u_char packet_buffer[PACKETSZ + 1];
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson buffer_len = res_mkquery(QUERY, dom, C_IN, qt, NULL, 0,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Failed to create query packet: %s %d\n",
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews unsigned char *p;
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews fprintf(stderr, "Failed to add OPT to query packet\n");
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews return (-1);
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews *p++ = 0; /* root name */
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews *p++ = 0; /* UDP payload size (4K) */
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews *p++ = 0; /* extended rcode */
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews *p++ = 0; /* version */
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews *p++ = 0; /* upper flag bits */
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews *p++ = 0; /* lower flag bit */
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews *p++ = 0; /* rdlen == 0 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson bytes_sent = sendto(query_socket, packet_buffer, buffer_len, 0,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 server_ai->ai_addr, server_ai->ai_addrlen);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Failed to send query packet: %s %d\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Warning: incomplete packet sent: %s %d\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Send a query based on a line of input
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson static unsigned short int use_query_id = 0;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (parse_query(query_desc, domain, qname_len, &query_type) == -1) {
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson fprintf(stderr, "Error parsing query: %s\n", query_desc);
384fef003441df4067b773688237700513390f9eEvan Hunt if (dispatch_query(use_query_id, domain, query_type,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (getnameinfo(server_ai->ai_addr, server_ai->ai_addrlen,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 addrstr = "???"; /* XXX: this should not happen */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "Error sending query to %s: %s\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 time_of_first_query_sec = (double)time_of_first_query.tv_sec +
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ((double)time_of_first_query.tv_usec / 1000000.0);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (getnameinfo(server_ai->ai_addr, server_ai->ai_addrlen,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "Error printing server address\n");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 printf("[Status] Sending queries (beginning with %s)\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* Find the first slot in status[] that is not in use */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 for (count = 0; (status[count].in_use == TRUE)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 && (count < max_queries_outstanding); count++);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Unexpected error: We have run out of "
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "status[] space!\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* Register the query in status[] */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson set_timenow(&status[count].sent_timestamp);
384fef003441df4067b773688237700513390f9eEvan Hunt if (dn_expand(qpkt, qpkt + qpkt_len, qpkt + DNS_HEADERLEN,
384fef003441df4067b773688237700513390f9eEvan Hunt "query message doesn't have qname?\n");
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 set_timenow(&time_of_first_query_interval);
384fef003441df4067b773688237700513390f9eEvan Huntregister_rtt(struct timeval *timestamp, char *qname, int qtype,
384fef003441df4067b773688237700513390f9eEvan Hunt unsigned int rcode)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (difftv(*timestamp, time_of_first_query_interval) < 0)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (rtt_max_interval < 0 || rtt_max_interval < rtt)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (rtt_min_interval < 0 || rtt_min_interval > rtt)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 i = (int)(rtt * (1000000.0 / rttarray_unit));
384fef003441df4067b773688237700513390f9eEvan Hunt fprintf(stderr, "Warning: RTT is out of range: %.6lf "
384fef003441df4067b773688237700513390f9eEvan Hunt "[query=%s/%d, rcode=%u]\n", rtt, qname, qtype, rcode);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * register_response:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Register receipt of a query
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Removes (sets in_use = FALSE) the record for the given query id in
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * status[] if any exists.
384fef003441df4067b773688237700513390f9eEvan Huntregister_response(unsigned short int id, unsigned int rcode, char *qname,
384fef003441df4067b773688237700513390f9eEvan Hunt if (qi->qtype == qtype && strcasecmp(qi->qname, qname) == 0) {
384fef003441df4067b773688237700513390f9eEvan Hunt register_rtt(&qi->sent_timestamp, qname, qtype, rcode);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 for (; (ct < query_status_allocated) && (found == FALSE); ct++) {
384fef003441df4067b773688237700513390f9eEvan Hunt if (status[ct].in_use == TRUE && status[ct].id == id &&
384fef003441df4067b773688237700513390f9eEvan Hunt register_rtt(&status[ct].sent_timestamp, qname, qtype,
384fef003441df4067b773688237700513390f9eEvan Hunt if (countrcodes && (found == TRUE || target_qps > 0))
384fef003441df4067b773688237700513390f9eEvan Hunt "Warning: Received a response with an "
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "unexpected (maybe timed out) id: %u\n", id);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * process_single_response:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Receive from the given socket & process an invididual response packet.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Remove it from the list of open queries (status[]) and decrement the
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * number of outstanding queries if it matches an open query.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson static unsigned char in_buf[MAX_BUFFER_LEN];
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 memset(&from_addr_ss, 0, sizeof(from_addr_ss));
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 from_addr = (struct sockaddr *)&from_addr_ss;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((numbytes = recvfrom(sockfd, in_buf, MAX_BUFFER_LEN,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "Error receiving datagram\n");
384fef003441df4067b773688237700513390f9eEvan Hunt qnamelen = dn_expand(in_buf, in_buf + numbytes, in_buf + DNS_HEADERLEN,
384fef003441df4067b773688237700513390f9eEvan Hunt "Failed to retrieve qname from response\n");
384fef003441df4067b773688237700513390f9eEvan Hunt qtype = get_uint16(in_buf + DNS_HEADERLEN + qnamelen);
384fef003441df4067b773688237700513390f9eEvan Hunt register_response(resp_id, flags & 0xF, qname, qtype);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * data_available:
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Is there data available on the given file descriptor?
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Return TRUE if there is
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Return FALSE otherwise
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /* Set list of file descriptors */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if ((wait > 0.0) && (wait < (double)LONG_MAX)) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 tv.tv_usec = (long)(1000000.0 * (wait - floor(wait)));
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 retval = select(maxfd + 1, &read_fds, NULL, NULL, &tv);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (socket4 != -1 && FD_ISSET(socket4, &read_fds)) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (socket6 != -1 && FD_ISSET(socket6, &read_fds)) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * process_responses:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Go through any/all received responses and remove them from the list of
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * open queries (set in_use = FALSE for their entry in status[]), also
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * decrementing the number of outstanding queries.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson double first_packet_wait = RESPONSE_BLOCKING_WAIT_TIME;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson unsigned int outstanding = queries_outstanding();
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 waituntil.tv_usec = (long)(1000000.0 * (u - waituntil.tv_sec));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Wait until a response arrives or the specified limit is
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * We have reached the limit. Read as many responses
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * as possible without waiting, and exit.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Don't block waiting for packets at all if we aren't
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * looking for any responses or if we are now able to send new
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 (outstanding < max_queries_outstanding)) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (data_available(first_packet_wait) == TRUE) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * retire_old_queries:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Go through the list of open queries (status[]) and remove any queries
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * (i.e. set in_use = FALSE) which are older than the timeout, decrementing
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * the number of queries outstanding for each one removed.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * If we have target qps and would not be able to send any packets
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * due to buffer full, check whether we are behind the schedule.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * If we are, purge some queries more aggressively.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (target_qps > 0 && sending == TRUE && count == 0 &&
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 queries_outstanding() == max_queries_outstanding) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 next.tv_usec = (long)(1000000.0 * (n - next.tv_sec));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 for (; count < query_status_allocated; count++) {
384fef003441df4067b773688237700513390f9eEvan Hunt status[count].sent_timestamp) >= (double)timeout))
384fef003441df4067b773688237700513390f9eEvan Hunt /* now really retire this query */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "msg id %u\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * print_histogram
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Print RTT histogram to the specified file in the gnuplot format
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (rtt_histogram_file == NULL || rttarray == NULL)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 fp = fopen((const char *)rtt_histogram_file, "w+");
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 fprintf(stderr, "Error opening RTT histogram file: %s\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 for (i = 0; i < rttarray_size; i++) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ratio = ((double)rttarray[i] / (double)total) * 100;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * print_statistics:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Print out statistics based on the results of the test
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉print_statistics(int intermediate, unsigned int sent, unsigned int timed_out,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 struct timeval *end_perf, struct timeval *end_query,
384fef003441df4067b773688237700513390f9eEvan Hunt unsigned int rcounted, double rmax, double rmin, double rtotal,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 unsigned int roverflows, unsigned int *rarray)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 double per_lost, per_completed, per_lost2, per_completed2;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 double run_time, queries_per_sec, queries_per_sec2;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 num_queries_completed = sent - timed_out;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 per_lost = (100.0 * (double)timed_out) / (double)sent;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 per_lost2 = (100.0 * (double)(timed_out - possibly_delayed))
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 start_time.tv_sec = program_start->tv_sec;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 start_time.tv_usec = program_start->tv_usec;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 start_time.tv_usec = first_query->tv_usec;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 run_time = difftv(*end_perf, *first_query);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson queries_per_sec = (double)num_queries_completed / run_time;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 queries_per_sec2 = (double)(num_queries_completed +
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 for (i = 0; i < rttarray_size; i++) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (rarray[i] != 0) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf("%sStatistics:\n", intermediate ? "Intermediate " : "");
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ((run_only_once == TRUE) ? "once" : "multiple times"));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 : "end of file"));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" Queries sent: %u queries\n", sent);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf(" Queries completed: %u queries\n", num_queries_completed);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" Queries lost: %u queries\n", timed_out);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" Queries delayed(?): %u queries\n", possibly_delayed);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" RTT average: %3.6lf sec\n", rtt_average);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" RTT std deviation: %3.6lf sec\n", rtt_stddev);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" RTT out of range: %u queries\n", roverflows);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (!intermediate) /* XXX should we print this case also? */
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews unsigned int i;
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews for (i = 0; i < 16; i++) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf(" Percentage completed: %6.2lf%%\n", per_completed);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" (w/ delayed qrys): %6.2lf%%\n", per_completed2);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf(" Percentage lost: %6.2lf%%\n", per_lost);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" (w/o delayed qrys): %6.2lf%%\n", per_lost2);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ctime((const time_t *)&start_time.tv_sec));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ctime((const time_t *)&end_perf->tv_sec));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf(" Ran for: %.6lf seconds\n", run_time);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf(" Queries per second: %.6lf qps\n", queries_per_sec);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" (w/ delayed qrys): %.6lf qps\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 printf(" Total QPS/target: %.6lf/%d qps\n",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (difftv(time_now, time_of_first_query_interval)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /* Don't count currently outstanding queries */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 num_queries_sent_interval -= queries_outstanding();
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 print_statistics(TRUE, num_queries_sent_interval,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 &time_of_first_query_interval, &time_now, &time_now,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /* Reset intermediate counters */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 num_queries_possiblydelayed_interval = 0;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 sizeof(rttarray_interval[0]) * rttarray_size);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * queryperf Program Mainline
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 time_of_first_query_interval.tv_usec = 0;
384fef003441df4067b773688237700513390f9eEvan Hunt /* XXX: move this to setup: */
384fef003441df4067b773688237700513390f9eEvan Hunt timeout_queries = malloc(sizeof(struct query_mininfo) * 65536);
384fef003441df4067b773688237700513390f9eEvan Hunt "failed to allocate memory for timeout queries\n");
384fef003441df4067b773688237700513390f9eEvan Hunt return (-1);
384fef003441df4067b773688237700513390f9eEvan Hunt for (i = 0; i < 65536; i++)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf("[Status] Processing input data\n");
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 while ((sending = keep_sending(&got_eof)) == TRUE ||
a18fc12ba3d48b66bea298c80f3e3f09f3c91527Evan Hunt * After statistics are printed, send_query()
a18fc12ba3d48b66bea298c80f3e3f09f3c91527Evan Hunt * needs to be called at least once so that
a18fc12ba3d48b66bea298c80f3e3f09f3c91527Evan Hunt * time_of_first_query_interval is reset
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 while ((sending = keep_sending(&got_eof)) == TRUE &&
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson int len = next_input_line(input_line, input_length);
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson /* Zap the trailing newline */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * TODO: Should test if we got a whole line
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * and flush to the next \n in input if not
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * here... Add this later. Only do the next
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * few lines if we got a whole line, else
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * print a warning. Alternative: Make the
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * max line size really big. BAD! :)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 print_statistics(FALSE, num_queries_sent, num_queries_timed_out,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 &time_of_first_query, &time_of_program_start,