From: Pieter Lexis Date: Thu, 25 May 2017 13:50:50 +0000 (+0200) Subject: calidns: switch to boost::program_options X-Git-Tag: rec-4.1.0-alpha1~95^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7c8bdee4d5c48d20a1d6db1de6e2faccc3b85f8;p=pdns calidns: switch to boost::program_options --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index bda281e1a..8d8b509ec 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -489,8 +489,10 @@ calidns_SOURCES = \ statbag.cc \ unix_utility.cc -calidns_LDADD = $(LIBCRYPTO_LIBS) -calidns_LDFLAGS = $(AM_LDFLAGS) $(THREADFLAGS) $(LIBCRYPTO_LDFLAGS) +calidns_LDADD = $(LIBCRYPTO_LIBS) \ + $(BOOST_PROGRAM_OPTIONS_LIBS) +calidns_LDFLAGS = $(AM_LDFLAGS) $(THREADFLAGS) $(LIBCRYPTO_LDFLAGS) \ + $(BOOST_PROGRAM_OPTIONS_LDFLAGS) dumresp_SOURCES = \ dnslabeltext.cc \ diff --git a/pdns/calidns.cc b/pdns/calidns.cc index e0225aaf6..85876ec89 100644 --- a/pdns/calidns.cc +++ b/pdns/calidns.cc @@ -34,6 +34,7 @@ #include #include #include +#include using std::thread; using std::unique_ptr; @@ -42,6 +43,9 @@ StatBag S; std::atomic g_recvcounter, g_recvbytes; volatile bool g_done; +namespace po = boost::program_options; +po::variables_map g_vm; + void* recvThread(const vector* sockets) { vector rfds, fds; @@ -148,13 +152,9 @@ void sendPackets(const vector* sockets, const vector* > } } -void usage() { +void usage(po::options_description &desc) { cerr<<"Syntax: calidns [OPTIONS] QUERY_FILE DESTINATION INITIAL_QPS HITRATE"<()->default_value(1.1), "Set the factor to increase the QPS load per run") + ("want-recursion", "Set the Recursion Desired flag on queries"); + po::options_description alloptions; + po::options_description hidden("hidden options"); + hidden.add_options() + ("query-file", po::value(), "File with queries") + ("destination", po::value(), "Destination address") + ("initital-qps", po::value(), "Initial number of queries per second") + ("hitrate", po::value(), "Aim this percent cache hitrate"); + + alloptions.add(desc).add(hidden); + po::positional_options_description p; + p.add("query-file", 1); + p.add("destination", 1); + p.add("initital-qps", 1); + p.add("hitrate", 1); + + po::store(po::command_line_parser(argc, argv).options(alloptions).positional(p).run(), g_vm); + po::notify(g_vm); + + if (g_vm.count("help")) { + usage(desc); + return EXIT_SUCCESS; } - for(; arg_i(); } + catch(...) { + } + + bool wantRecursion = g_vm.count("want-recursion"); + double hitrate = g_vm["hitrate"].as() / 100; + uint32_t qpsstart = g_vm["initital-qps"].as(); + struct sched_param param; + param.sched_priority=99; if(sched_setscheduler(0, SCHED_FIFO, ¶m) < 0) cerr<<"Unable to set SCHED_FIFO: "<()); string line; reportAllTypes(); vector > > unknown, known; @@ -254,7 +262,7 @@ try cout<<"Generated "< sockets; - ComboAddress dest(argv[arg_i+1], 53); + ComboAddress dest(g_vm["destination"].as(), 53); for(int i=0; i < 24; ++i) { Socket *sock = new Socket(dest.sin4.sin_family, SOCK_DGRAM); // sock->connect(dest); @@ -268,7 +276,7 @@ try ofstream plot("plot"); for(qps=qpsstart;;qps *= increment) { double seconds=1; - cout<<"Aiming at "<