/*
* testcode/perf.c - debug program to estimate name server performance.
*
* Copyright (c) 2008, NLnet Labs. All rights reserved.
*
* This software is open source.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the NLNET LABS nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file
*
* This program estimates DNS name server performance.
*/
/** usage information for perf */
static void usage(char* nm)
{
printf("usage: %s [options] server\n", nm);
printf("server: ip address of server, IP4 or IP6.\n");
printf(" If not on port %d add @port.\n", UNBOUND_DNS_PORT);
printf("-d sec duration of test in whole seconds (0: wait for ^C)\n");
printf("-a str query to ask, interpreted as a line from qfile\n");
printf("-f fnm query list to read from file\n");
printf(" every line has format: qname qclass qtype [+-]{E}\n");
printf(" where + means RD set, E means EDNS enabled\n");
printf("-q quiet mode, print only final qps\n");
exit(1);
}
struct perfinfo;
struct perfio;
/** Global info for perf */
struct perfinfo {
/** need to exit */
volatile int exit;
/** all purpose buffer (for UDP send and receive) */
sldns_buffer* buf;
/** destination */
struct sockaddr_storage dest;
/** length of dest socket addr */
socklen_t destlen;
/** when did this time slice start */
struct timeval since;
/** number of queries received in that time */
size_t numrecv;
/** number of queries sent out in that time */
size_t numsent;
/** duration of test in seconds */
int duration;
/** quiet mode? */
int quiet;
/** when did the total test start */
struct timeval start;
/** total number recvd */
size_t total_recv;
/** total number sent */
size_t total_sent;
/** numbers by rcode */
size_t by_rcode[32];
/** number of I/O ports */
size_t io_num;
/** I/O ports array */
struct perfio* io;
/** max fd value in io ports */
int maxfd;
/** readset */
fd_set rset;
/** size of querylist */
size_t qlist_size;
/** allocated size of qlist array */
size_t qlist_capacity;
/** list of query packets (data) */
uint8_t** qlist_data;
/** list of query packets (length of a packet) */
size_t* qlist_len;
/** index into querylist, for walking the list */
size_t qlist_idx;
};
/** I/O port for perf */
struct perfio {
/** id number */
size_t id;
/** file descriptor of socket */
int fd;
/** timeout value */
struct timeval timeout;
/** ptr back to perfinfo */
struct perfinfo* info;
};
/** number of msec between starting io ports */
#define START_IO_INTERVAL 10
/** number of msec timeout on io ports */
#define IO_TIMEOUT 10
/** signal handler global info */
static struct perfinfo* sig_info;
/** signal handler for user quit */
static RETSIGTYPE perf_sigh(int sig)
{
log_assert(sig_info);
if(!sig_info->quiet)
printf("exit on signal %d\n", sig);
sig_info->exit = 1;
}
/** got timeout for io */
static void
perftimeout(struct perfinfo* info, size_t n, struct timeval* now)
{
/* may not be a dropped packet, this is also used to start
* up the sending IOs */
perfsend(info, n, now);
}
/** getopt global, in case header files fail to declare it. */
extern int optind;
/** getopt global, in case header files fail to declare it. */
extern char* optarg;
/** main program for perf */
int main(int argc, char* argv[])
{
char* nm = argv[0];
int c;
struct perfinfo info;
#ifdef USE_WINSOCK
int r;
WSADATA wsa_data;
#endif