root/trunk/pdns/pdns/dnspbench.cc @ 642

Revision 642, 2.1 KB (checked in by ahu, 7 years ago)

new tests in dnspbench

Line 
1#include "logger.hh"
2Logger L("dnspbench");
3
4#include "dnsparser.hh"
5#include "sstuff.hh"
6#include "misc.hh"
7#include "dnswriter.hh"
8#include "dnsrecords.hh"
9
10#include "statbag.hh"
11#include <stdint.h>
12#include <set>
13
14using namespace boost;
15
16
17StatBag S;
18
19#include <bits/atomicity.h>
20// This code is ugly but does speedup the recursor tremendously on multi-processor systems, and even has a large effect (20, 30%) on uniprocessor
21namespace __gnu_cxx
22{
23  _Atomic_word
24  __attribute__ ((__unused__))
25  __exchange_and_add(volatile _Atomic_word* __mem, int __val)
26  {
27    register _Atomic_word __result=*__mem;
28    *__mem+=__val;
29    return __result;
30  }
31
32  void
33  __attribute__ ((__unused__))
34  __atomic_add(volatile _Atomic_word* __mem, int __val)
35  {
36    *__mem+=__val;
37  }
38}
39
40int xcount;
41
42int main(int argc, char** argv)
43try
44{
45  reportAllTypes();
46  Socket s(InterNetwork, Datagram);
47
48  vector<uint8_t> vpacket;
49  string domain="www.ds9a.nl";
50  uint16_t type=1;
51
52  for(unsigned int n=0; n < 1000000; ++n) {
53    DNSPacketWriter pw(vpacket, domain, type);
54    pw.startRecord(domain, 1, 3600, 1, DNSPacketWriter::ANSWER);
55    shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(1, 1, "1.2.3.4"));     
56
57    drc->toPacket(pw);
58    pw.commit();
59    pw.getHeader()->rd=0;
60    //    IPEndpoint rem("127.0.0.1",5300);
61    //    string spacket((char*)(&*vpacket.begin()), vpacket.size());
62    //    s.sendTo(spacket, rem);
63  }
64  cout<<xcount<<endl;
65
66  return 0; 
67#if 0
68
69
70
71
72  vector<uint8_t> packet;
73
74  uint16_t type=DNSRecordContent::TypeToNumber(argv[2]);
75
76  DNSRecordContent* drc=DNSRecordContent::mastermake(type, 1, argv[3]);
77
78  cerr<<"In: "<<argv[1]<<" IN " <<argv[2]<<" "<< argv[3] << "\n";
79
80  string record=drc->serialize(argv[1]);
81
82  cerr<<"sizeof: "<<record.length()<<"\n";
83  cerr<<"hexdump: "<<makeHexDump(record)<<"\n";
84  //  cerr<<"record: "<<record<<"\n";
85
86  shared_ptr<DNSRecordContent> regen=DNSRecordContent::unserialize(argv[1], type, record);
87  cerr<<"Out: "<<argv[1]<<" IN "<<argv[2]<<" "<<regen->getZoneRepresentation()<<endl;
88#endif
89}
90catch(exception& e)
91{
92  cerr<<"Fatal: "<<e.what()<<"\n";
93}
94
95 
Note: See TracBrowser for help on using the browser.