]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
calidns: add --increment and --want-recursion flags
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 23 May 2017 12:07:52 +0000 (13:07 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 23 May 2017 19:20:53 +0000 (20:20 +0100)
docs/manpages/calidns.1.md
pdns/calidns.cc

index ee434e42b0677ee7b109b6d191b0d61f03c8aedd..bf7f3d879a738d171dfeb4cfb44a43bd502a8399 100644 (file)
@@ -6,7 +6,7 @@
 **calidns** - A DNS recursor testing tool
 
 # SYNOPSIS
-**calidns** *QUERY_FILE* *DESTINATION* *INITIAL_QPS* *HITRATE*
+**calidns** [*OPTIONS*] *QUERY_FILE* *DESTINATION* *INITIAL_QPS* *HITRATE*
 
 # DESCRIPTION
 **calidns** reads queries from *QUERY_FILE* and sends them as a recursive query to
@@ -28,4 +28,9 @@ google.com A
 This is similar to Alexa top 1 million list.
 
 # OPTIONS
-None
+--increment *NUM*
+:    On every subsequent run, multiply the number of queries per second by *NUM*.
+     By default, this is 1.1.
+
+--want-recursion
+:    Set this flag to send queries with the Recursion Desired flag set.
index 9cdd58be8b403e2d78042f2baafb57ef0c61c3f9..d3fa8f53b04171d6475e31e6fdf0126fdc686b51 100644 (file)
@@ -149,7 +149,12 @@ void sendPackets(const vector<Socket*>* sockets, const vector<vector<uint8_t>* >
 }
 
 void usage() {
-  cerr<<"Syntax: calidns QUERY_FILE DESTINATION INITIAL_QPS HITRATE"<<endl;
+  cerr<<"Syntax: calidns [OPTIONS] QUERY_FILE DESTINATION INITIAL_QPS HITRATE"<<endl;
+  cerr<<"OPTIONS:"<<endl;
+  cerr<<"  --want-recursion Set the RD bit in the query"<<endl;
+  cerr<<"  --increment      Set the factor by which the QPS should increase (default=1.1)"<<endl;
+  cerr<<"  --help           Show this helpful message"<<endl;
+  cerr<<"  --version        Show the version of calidns"<<endl;
 }
 
 /*
@@ -181,34 +186,54 @@ try
 {
   struct sched_param param;
   param.sched_priority=99;
+  int arg_i = 1;
+  int increment = 1.1;
+  bool wantRecursion = false;
 
-  if (argc == 1 || (argc > 1 && argc <5)) {
-    for(int i = 1; i<argc; i++) {
-      string opt(argv[i]);
+  if (argc < 5) {
+    usage();
+    exit(EXIT_FAILURE);
+  }
 
-      if(opt == "--help") {
-        usage();
-        exit(EXIT_SUCCESS);
-      }
+  for(; arg_i<argc; arg_i++) {
+    string opt(argv[arg_i]);
 
-      if(opt == "--version") {
-        cerr<<"calidns "<<VERSION<<endl;
-        exit(EXIT_SUCCESS);
-      }
+    if(opt == "--help") {
+      usage();
+      exit(EXIT_SUCCESS);
     }
 
-    usage();
-    if (argc == 1)
+    if(opt == "--version") {
+      cerr<<"calidns "<<VERSION<<endl;
       exit(EXIT_SUCCESS);
+    }
+
+    if(opt == "--increment") {
+      increment = std::stoi(argv[arg_i+1]);
+      arg_i++;
+      continue;
+    }
+
+    if(opt == "--want-recursion") {
+      wantRecursion = true;
+      continue;
+    }
+    break;
+  }
+
+  if (argc - arg_i != 4) {
+    usage();
     exit(EXIT_FAILURE);
   }
 
+
+
   if(sched_setscheduler(0, SCHED_FIFO, &param) < 0)
     cerr<<"Unable to set SCHED_FIFO: "<<strerror(errno)<<endl;
 
-  double hitrate=atof(argv[4])/100.0;
-  int qpsstart=atoi(argv[3]);
-  ifstream ifs(argv[1]);
+  double hitrate=atof(argv[arg_i+3])/100.0;
+  int qpsstart=atoi(argv[arg_i+2]);
+  ifstream ifs(argv[arg_i]);
   string line;
   reportAllTypes();
   vector<std::shared_ptr<vector<uint8_t> > > unknown, known;
@@ -217,7 +242,7 @@ try
     boost::trim(line);
     auto p = splitField(line, ' ');
     DNSPacketWriter pw(packet, DNSName(p.first), DNSRecordContent::TypeToNumber(p.second));
-    pw.getHeader()->rd=0;
+    pw.getHeader()->rd=wantRecursion;
     pw.getHeader()->id=random();
     if(pw.getHeader()->id % 2) {
         pw.addOpt(1500, 0, EDNSOpts::DNSSECOK);
@@ -229,7 +254,7 @@ try
   cout<<"Generated "<<unknown.size()<<" ready to use queries"<<endl;
   
   vector<Socket*> sockets;
-  ComboAddress dest(argv[2], 53);  
+  ComboAddress dest(argv[arg_i+1], 53);
   for(int i=0; i < 24; ++i) {
     Socket *sock = new Socket(dest.sin4.sin_family, SOCK_DGRAM);
     //    sock->connect(dest);
@@ -241,7 +266,7 @@ try
   int qps;
 
   ofstream plot("plot");
-  for(qps=qpsstart;;qps *= 1.1) {
+  for(qps=qpsstart;;qps *= increment) {
     double seconds=1;
     cout<<"Aiming at "<<qps<< "qps for "<<seconds<<" seconds at cache hitrate "<<100.0*hitrate<<"%";
     unsigned int misses=(1-hitrate)*qps*seconds;