BIND 10 trac2171, updated. ab4d20907abdb3ce972172463dcc73405b3dee79 Merge branch 'master' into trac2171

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Sep 5 13:27:17 UTC 2012


The branch, trac2171 has been updated
       via  ab4d20907abdb3ce972172463dcc73405b3dee79 (commit)
       via  ecb6a3aad71647bc11305fa8b8789a60ed591cfb (commit)
       via  94e17184270cda58f55e6da62e845695117fede3 (commit)
       via  9759be762e000ccdf9e17ca890fdb990bd773c02 (commit)
       via  06c7f0d32276b1359868632ba73f2fd5d34ef6fd (commit)
       via  4c8637f7ec592c0c0f827567a83663e985f9542d (commit)
       via  7743d37cd55250ae26687d7f6ca8a22f20da6799 (commit)
       via  dc26ce9dfdb9ea97e0a4f74485d6d6d9af0835da (commit)
       via  1ecb73e5bf38c5dc4efad44aac0331e487829d89 (commit)
       via  a77342a649b33001245341f2e6a038a7fc7673d6 (commit)
       via  7127237c184ff0fdf0535b9e8234dd71598b996e (commit)
       via  30061d1139aad8716e97d6b620c259752fd0a3cd (commit)
       via  336e7f1a28d2abe8568cb7001c5c38da42bc3f7b (commit)
       via  f3b0c13a93d6cf49c42d25f1383ad81317169a0d (commit)
       via  bb1471521f157d034bec34150d19698f3fa44d8f (commit)
       via  2ec3c8fcef449c8959fb0fb020ac58cfc00bbfd0 (commit)
       via  90f55cdeacd23a30412913ee3b6c4ba9ca850cc8 (commit)
       via  69d8e5e56fecccc1c9ff6e55543ab7361ef3de67 (commit)
       via  8145395b1a6680f3efc7baa0a05663c07b670dc1 (commit)
       via  8a9addc70d264708dc92a328d5ccf02465fcbb15 (commit)
       via  2175b280a686cc4aec2cf72c21f7ce839bf609ee (commit)
       via  0ef001aacb7a9da735d418504168420ddac0c3df (commit)
       via  731fac5042e88fa7611b0f99feace1e1b05fe4a0 (commit)
       via  3b17dac1ab05a635f39f73316be62f4783a0182f (commit)
       via  0048a810b5641bb7b35f7ccf790846cee6f89697 (commit)
       via  f40e523668cd8332238b7369470403e8b66b6f35 (commit)
       via  e1491225037840283b198a6042d90939d52906fe (commit)
       via  793457876fc93510db9814cd70c4ab2cc8a918b6 (commit)
       via  16e49803425ea35550a9787987215e5344ffe528 (commit)
       via  48755af6bfc85aa10e5eea2da1bde9478914e8df (commit)
       via  c69039221efe837760e74c93f5bb23cb19810a48 (commit)
       via  b594cc0f845bf8c2fa7238aa8d153f642a3337ff (commit)
       via  98c3fe102ae4b4e8769d2bf9412a5e5ab9225926 (commit)
       via  a14dd1bb813a03e9cedecc44b237c24fc0dbe08e (commit)
       via  bd1c6a351401bbd9b88a86c6e159083e4421398b (commit)
       via  f3a0b65d587b0758416bfb596a9ad696a6c9fb25 (commit)
       via  5d2116c14a18c5aa2f41fa75e0f893ad8a645bf3 (commit)
       via  df4d0be872ff9ff4e120e156b71d0abc25df0319 (commit)
       via  7017538fe54478e47fe1bdda055d3545a5d70f66 (commit)
       via  c76267ee3aa8434b218954619a9d261fb42a6810 (commit)
       via  e9f6a894ed38cdd6bd3165c67a0be64482e1a47d (commit)
       via  ffb9c0ae7609347a66ae4997b1cf5c6250d83256 (commit)
      from  b71313c089c3a2dce333061b5b243555743561c8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 .gitignore                                         |    1 +
 ChangeLog                                          |   15 +-
 configure.ac                                       |   15 +-
 doc/guide/bind10-guide.xml                         |  226 ++--
 doc/guide/bind10-messages.html                     |    2 +-
 src/bin/Makefile.am                                |    2 +-
 src/bin/bindctl/bindctl.1                          |   17 +-
 src/bin/cfgmgr/plugins/Makefile.am                 |    2 +-
 src/bin/cfgmgr/plugins/datasrc.spec.pre.in         |    8 +
 src/bin/cmdctl/b10-cmdctl.8                        |    9 +
 src/bin/resolver/b10-resolver.8                    |    9 +
 src/bin/showtech/.gitignore                        |    2 -
 src/bin/sysinfo/.gitignore                         |    2 +
 src/bin/{showtech => sysinfo}/Makefile.am          |   10 +-
 .../b10-showtech.1 => sysinfo/isc-sysinfo.1}       |   18 +-
 .../b10-showtech.xml => sysinfo/isc-sysinfo.xml}   |   12 +-
 .../showtech.py.in => sysinfo/sysinfo.py.in}       |    2 +-
 src/bin/zonemgr/b10-zonemgr.8                      |   11 +-
 src/lib/datasrc/tests/testdata/.gitignore          |    3 +-
 src/lib/dhcp/pkt6.h                                |    2 +-
 src/lib/testutils/testdata/.gitignore              |    1 +
 .../configurations/bindctl/bindctl.config.orig     |    3 +
 .../configurations/bindctl_commands.config.orig    |    3 +
 tests/tools/perfdhcp/Makefile.am                   |    2 +
 tests/tools/perfdhcp/stats_mgr.h                   | 1137 ++++++++++++++++++++
 tests/tools/perfdhcp/tests/Makefile.am             |    1 +
 tests/tools/perfdhcp/tests/stats_mgr_unittest.cc   |  450 ++++++++
 27 files changed, 1826 insertions(+), 139 deletions(-)
 delete mode 100644 src/bin/showtech/.gitignore
 create mode 100644 src/bin/sysinfo/.gitignore
 rename src/bin/{showtech => sysinfo}/Makefile.am (70%)
 rename src/bin/{showtech/b10-showtech.1 => sysinfo/isc-sysinfo.1} (84%)
 rename src/bin/{showtech/b10-showtech.xml => sysinfo/isc-sysinfo.xml} (89%)
 rename src/bin/{showtech/showtech.py.in => sysinfo/sysinfo.py.in} (99%)
 create mode 100644 tests/tools/perfdhcp/stats_mgr.h
 create mode 100644 tests/tools/perfdhcp/tests/stats_mgr_unittest.cc

-----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 3480cb6..dd6903c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,3 +35,4 @@ TAGS
 /coverage-cpp-html
 /dns++.pc
 /report.info
+/logger_lockfile
diff --git a/ChangeLog b/ChangeLog
index 68f2ae2..7716b44 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+458.	[build]*	jinmei
+	BIND 10 now relies on Boost offset_ptr, which caused some new
+	portability issues.  Such issues are detected at ./configure time.
+	If ./configure stops due to this, try the following workaround:
+	- If it's about the use of mutable for a reference with clang++,
+	  upgrade Boost version to 1.44 or higher, or try a different
+	  compiler (e.g. g++ generally seems to be free from this issue)
+	- If it's about the use of "variadic templates", specify
+	  --without-werror so the warning won't be promoted to an error.
+	  Specifying BOOST_NO_USER_CONFIG in CXXFLAGS may also work
+	  (which would be the case if Boost is installed via pkgsrc)
+	(Trac #2147, git 30061d1139aad8716e97d6b620c259752fd0a3cd)
+
 457.	[build]*	muks
 	BIND 10 library names now have a "b10-" prefix. This is to avoid
 	clashes with other similarly named libraries on the system.
@@ -32,7 +45,7 @@
 	(Trac #1986, git bd6b0a5ed3481f78fb4e5cb0b18c7b6e5920f9f8)
 
 452.	[func]*		muks
-	b10-showtech: An initial implementation of the b10-showtech tool
+	isc-sysinfo: An initial implementation of the isc-sysinfo tool
 	is now available. It gathers and outputs system information which
 	can be used by future tech support staff.
 	(Trac #2062, git 144e80212746f8d55e6a59edcf689fec9f32ae95)
diff --git a/configure.ac b/configure.ac
index c9b0e14..e75cbd8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -809,6 +809,17 @@ AC_TRY_COMPILE([
  CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
 [AC_MSG_RESULT(yes)])
 
+# Boost offset_ptr is required in one library (not optional right now), and
+# it's known it doesn't compile on some platforms, depending on boost version,
+# its local configuration, and compiler.
+AC_MSG_CHECKING([Boost offset_ptr compiles])
+AC_TRY_COMPILE([
+#include <boost/interprocess/offset_ptr.hpp>
+],,
+[AC_MSG_RESULT(yes)],
+[AC_MSG_RESULT(no)
+ AC_MSG_ERROR([Failed to compile a required header file.  Try upgrading Boost to 1.44 or higher (when using clang++) or specifying --without-werror.  See the ChangeLog entry for Trac no. 2147 for more details.])])
+
 CPPFLAGS="$CPPFLAGS_SAVES $CPPFLAGS_BOOST_THREADCONF"
 AC_SUBST(BOOST_INCLUDES)
 
@@ -1078,7 +1089,7 @@ AC_CONFIG_FILES([Makefile
                  src/bin/dhcp4/tests/Makefile
                  src/bin/resolver/Makefile
                  src/bin/resolver/tests/Makefile
-                 src/bin/showtech/Makefile
+                 src/bin/sysinfo/Makefile
                  src/bin/sockcreator/Makefile
                  src/bin/sockcreator/tests/Makefile
                  src/bin/xfrin/Makefile
@@ -1216,7 +1227,7 @@ AC_OUTPUT([doc/version.ent
            src/bin/zonemgr/zonemgr.spec.pre
            src/bin/zonemgr/tests/zonemgr_test
            src/bin/zonemgr/run_b10-zonemgr.sh
-           src/bin/showtech/showtech.py
+           src/bin/sysinfo/sysinfo.py
            src/bin/stats/stats.py
            src/bin/stats/stats_httpd.py
            src/bin/bind10/bind10_src.py
diff --git a/doc/guide/bind10-guide.xml b/doc/guide/bind10-guide.xml
index 040b109..c5df326 100644
--- a/doc/guide/bind10-guide.xml
+++ b/doc/guide/bind10-guide.xml
@@ -1485,134 +1485,154 @@ can use various data source backends.
 
     </section>
 
-    <section>
+    <section id='datasrc'>
       <title>Data Source Backends</title>
 
+      <para>
+        Bind 10 has the concept of data sources. A data source is a place
+        where authoritative zone data reside and where they can be served
+        from. This can be a master file, a database or something completely
+        different.
+      </para>
+
+      <para>
+        Once a query arrives, <command>b10-auth</command> goes through a
+        configured list of data sources and finds the one containing a best
+        matching zone. From the equally good ones, the first one is taken.
+        This data source is then used to answer the query.
+      </para>
+
       <note><para>
-        For the development prototype release, <command>b10-auth</command>
-        supports a SQLite3 data source backend and in-memory data source
-        backend.
+        In the development prototype release, <command>b10-auth</command>
+        can serve data from a SQLite3 data source backend and from master
+        files.
         Upcoming versions will be able to use multiple different
         data sources, such as MySQL and Berkeley DB.
       </para></note>
 
-
       <para>
-        By default, the SQLite3 backend uses the data file located at
+        The configuration is located in data_sources/classes. Each item there
+        represents one RR class and a list used to answer queries for that
+        class. The default contains two classes. The CH class contains a static
+        data source — one that serves things like
+        <quote>AUTHORS.BIND.</quote>. The IN class contains single SQLite3
+        data source with database file located at
         <filename>/usr/local/var/bind10-devel/zone.sqlite3</filename>.
-        (The full path is what was defined at build configure time for
-        <option>--localstatedir</option>.
-        The default is <filename>/usr/local/var/</filename>.)
-	This data file location may be changed by defining the
-	<quote>database_file</quote> configuration.
       </para>
 
-      <section id="in-memory-datasource">
-	<title>In-memory Data Source</title>
-
-	<para>
-<!--	  How to configure it. -->
-	  The following commands to <command>bindctl</command>
-	  provide an example of configuring an in-memory data
-	  source containing the <quote>example.com</quote> zone
-	  with the zone file named <quote>example.com.zone</quote>:
-
-<!--
-	  <screen>> <userinput> config set Auth/datasources/ [{"type": "memory", "zones": [{"origin": "example.com", "file": "example.com.zone"}]}]</userinput></screen>
--->
-
-          <screen>> <userinput>config add Auth/datasources</userinput>
-> <userinput>config set Auth/datasources[0]/type "<option>memory</option>"</userinput>
-> <userinput>config add Auth/datasources[0]/zones</userinput>
-> <userinput>config set Auth/datasources[0]/zones[0]/origin "<option>example.com</option>"</userinput>
-> <userinput>config set Auth/datasources[0]/zones[0]/file "<option>example.com.zone</option>"</userinput>
-> <userinput>config commit</userinput></screen>
-
-	  The authoritative server will begin serving it immediately
-	  after the zone data is loaded from the master text file.
-	</para>
-
-      </section>
-
-      <section id="in-memory-datasource-with-sqlite3-backend">
-	<title>In-memory Data Source with SQLite3 Backend</title>
-
-	<para>
-<!--	  How to configure it. -->
-	  The following commands to <command>bindctl</command>
-	  provide an example of configuring an in-memory data
-	  source containing the <quote>example.org</quote> zone
-	  with a SQLite3 backend file named <quote>example.org.sqlite3</quote>:
-
-<!--
-	  <screen>> <userinput> config set Auth/datasources/ [{"type": "memory", "zones": [{"origin": "example.org", "file": "example.org.sqlite3", "filetype": "sqlite3"}]}]</userinput></screen>
--->
-
-          <screen>> <userinput>config add Auth/datasources</userinput>
-> <userinput>config set Auth/datasources[1]/type "<option>memory</option>"</userinput>
-> <userinput>config add Auth/datasources[1]/zones</userinput>
-> <userinput>config set Auth/datasources[1]/zones[0]/origin "<option>example.org</option>"</userinput>
-> <userinput>config set Auth/datasources[1]/zones[0]/file "<option>example.org.sqlite3</option>"</userinput>
-> <userinput>config set Auth/datasources[1]/zones[0]/filetype "<option>sqlite3</option>"</userinput>
-> <userinput>config commit</userinput></screen>
-
-	  The authoritative server will begin serving it immediately
-	  after the zone data is loaded from the database file.
-	</para>
-
-      </section>
-
-      <section id="in-memory-datasource-loading">
-	<title>Reloading an In-memory Data Source</title>
-
-	<para>
-	  Use the <command>Auth loadzone</command> command in
-	  <command>bindctl</command> to reload a changed master
-	  file into memory; for example:
+      <para>
+        Each data source has several options. The first one is
+        <varname>type</varname>, which specifies the type of data source to
+        use. Valid types include the ones listed below, but bind10 uses
+        dynamically loaded modules for them, so there may be more in your
+        case. This option is mandatory.
+      </para>
 
-	  <screen>> <userinput>Auth loadzone origin="example.com"</userinput>
-</screen>
+      <para>
+        Another option is <varname>params</varname>. This option is type
+        specific; it holds different data depending on the type
+        above. Also, depending on the type, it could be possible to omit it.
+      </para>
 
-	</para>
+      <para>
+        There are two options related to the so-called cache. If you enable
+        cache, zone data from the data source are loaded into memory.
+        Then, when answering a query, <command>b10-auth</command> looks
+        into the memory only instead of the data source, which speeds
+        answering up. The first option is <varname>cache-enable</varname>,
+        a boolean value turning the cache on and off (off is the default).
+        The second one, <varname>cache-zones</varname>, is a list of zone
+        origins to load into in-memory. Remember that zones in the data source
+        not listed here will not be loaded and will not be available at all.
+      </para>
 
-<!--
+      <section id='datasource-types'>
+        <title>Data source types</title>
         <para>
-          The <varname>file</varname> may be an absolute path to the
-          master zone file or it is relative to the directory BIND 10 is
-          started from.
-	</para>
--->
+          As mentioned, the type used by default is <quote>sqlite3</quote>.
+          It has single configuration option inside <varname>params</varname>
+          — <varname>database_file</varname>, which contains the path
+          to the sqlite3 file containing the data.
+        </para>
 
+        <para>
+          Another type is called <quote>MasterFiles</quote>. This one is
+          slightly special. The data are stored in RFC1034 master files.
+          Because answering directly from them would be impractical,
+          this type mandates the cache to be enabled. Also, the list of
+          zones (<varname>cache-zones</varname>) should be omitted. The
+          <varname>params</varname> is a dictionary mapping from zone
+          origins to the files they reside in.
+        </para>
       </section>
-      <section id="in-memory-datasource-disabling">
-	<title>Disabling In-memory Data Sources</title>
 
+      <section id='datasrc-examples'>
+        <title>Examples</title>
         <para>
-	By default, the memory data source is disabled; it must be
-	configured explicitly.  To disable all the in-memory zones,
-	specify a null list for <varname>Auth/datasources</varname>:
+          As this is one of the more complex configurations of Bind10,
+          we show some examples. They all assume they start with default
+          configuration.
+        </para>
 
-<!-- TODO: this assumes that Auth/datasources is for memory only -->
+        <para>
+          First, let's disable the static data source
+          (<quote>VERSION.BIND</quote> and friends). As it is the only
+          data source in the CH class, we can remove the whole class.
 
-	  <screen>> <userinput>config set Auth/datasources/ []</userinput>
+          <screen>> <userinput>config remove data_sources/classes CH</userinput>
 > <userinput>config commit</userinput></screen>
-	</para>
+        </para>
 
-	<para>
-          The following example stops serving a specific zone:
+        <para>
+          Another one, let's say our default data source contains zones
+          <quote>example.org.</quote> and <quote>example.net.</quote>.
+          We want them to be served from memory to make the answering
+          faster.
 
-	  <screen>> <userinput>config remove Auth/datasources[<option>0</option>]/zones[<option>0</option>]</userinput>
+          <screen>> <userinput>config set data_sources/classes/IN[0]/cache-enable true</userinput>
+> <userinput>config add data_sources/classes/IN[0]/cache-zones example.org.</userinput>
+> <userinput>config add data_sources/classes/IN[0]/cache-zones example.net.</userinput>
 > <userinput>config commit</userinput></screen>
 
-	  (Replace the list number(s) in
-	  <varname>datasources[<replaceable>0</replaceable>]</varname>
-	  and/or <varname>zones[<replaceable>0</replaceable>]</varname>
-	  for the relevant zone as needed.)
+          Now every time the zone in the data source is changed by the
+          operator, Bind10 needs to be told to reload it, by
+          <screen>> <userinput>Auth loadzone example.org</userinput></screen>
+          You don't need to do this when the zone is modified by
+          XfrIn, it does so automatically.
+        </para>
+
+        <para>
+          Now, the last example is when there are master files we want to
+          serve in addition to whatever is inside the sqlite3 database.
 
-	</para>
+          <screen>> <userinput>config add data_sources/classes/IN</userinput>
+> <userinput>config set data_sources/classes/IN[1]/type MasterFiles</userinput>
+> <userinput>config set data_sources/classes/IN[1]/cache-enable true</userinput>
+> <userinput>config set data_sources/classes/IN[1]/params { "example.org": "/path/to/example.org", "example.com": "/path/to/example.com" }</userinput>
+> <userinput>config commit</userinput></screen>
 
+          Unfortunately, due to current technical limitations, the params must
+          be set as one JSON blob, it can't be edited in
+          <command>bindctl</command>. To reload a zone, you the same command
+          as above.
+        </para>
       </section>
 
+      <note>
+      <para>
+        There's also <varname>Auth/database_file</varname> configuration
+        variable, pointing to a sqlite3 database file. This is no longer
+        used by <command>b10-auth</command>, but it is left in place for
+        now, since other modules use it. Once <command>b10-xfrin</command>,
+        <command>b10-xfrout</command> and <command>b10-ddns</command>
+        are ported to the new configuration, this will disappear. But for
+        now, make sure that if you use any of these modules, the new
+        and old configuration correspond. The defaults are consistent, so
+        unless you tweaked either the new or the old configuration, you're
+        good.
+      </para>
+      </note>
+
     </section>
 
     <section>
@@ -1854,7 +1874,7 @@ http://bind10.isc.org/wiki/ScalableZoneLoadDesign#a7.2UpdatingaZone
 	The administrator doesn't have to do anything for
 	<command>b10-auth</command> to serve the new version of the
 	zone, except for the configuration such as the one described in
-	<xref linkend="in-memory-datasource-with-sqlite3-backend" />.
+	<xref linkend="datasrc" />.
       </para>
     </section>
 
@@ -1965,11 +1985,11 @@ what is XfroutClient xfr_client??
       notify <command>b10-xfrout</command> so that other secondary
       servers will be notified via the DNS NOTIFY protocol.
       In addition, if <command>b10-auth</command> serves the updated
-      zone from its in-memory cache (as described in
-      <xref linkend="in-memory-datasource-with-sqlite3-backend" />),
+      zone (as described in
+      <xref linkend="datasrc" />),
       <command>b10-ddns</command> will also
       notify <command>b10-auth</command> so that <command>b10-auth</command>
-      will re-cache the updated zone content.
+      will re-cache the updated zone content if necessary.
     </para>
 
     <para>
@@ -2548,7 +2568,7 @@ const std::string HARDCODED_SERVER_ID = "192.0.2.1";</screen>
     </section>
 
     <section id="dhcp4-limit">
-      <title>DHCPv4 Server Limitations</title> 
+      <title>DHCPv4 Server Limitations</title>
       <para>These are the current limitations of the DHCPv4 server
       software. Most of them are reflections of the early stage of
       development and should be treated as <quote>not implemented
diff --git a/doc/guide/bind10-messages.html b/doc/guide/bind10-messages.html
index cfa27a6..37c742b 100644
--- a/doc/guide/bind10-messages.html
+++ b/doc/guide/bind10-messages.html
@@ -1,4 +1,4 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>BIND 10 Messages Manual</title><link rel="stylesheet" href="./bind10-guide.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.2"><meta name="description" content="BIND 10 is a Domain Name System (DNS) suite managed by Internet Systems Consortium (ISC). It includes DNS libraries and modular components for controlling authoritative and recursive DNS servers. This is the messages manual for BIND 10 version 20120712. The most up-to-date version of this document, along with other documents for BIND 10, can be found at ."></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" title="BIND 10 Messages Manual"><div class="titlepage"><div><div><h1 class="title"><a name="id1168229451102"></a>BIND 10 Messages Manual</h1></div><div><p class="releaseinfo">This is the messages manual for BIND 10 version
+<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>BIND 10 Messages Manual</title><link rel="stylesheet" href="./bind10-guide.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.2"><meta name="description" content="BIND 10 is a Domain Name System (DNS) suite managed by Internet Systems Consortium (ISC). It includes DNS libraries and modular components for controlling authoritative and recursive DNS servers. This is the messages manual for BIND 10 version 20120712. The most up-to-date version of this document, along with other documents for BIND 10, can be found at ."></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" title="BIND 10 Messages Manual"><div class="titlepage"><div><div><h1 class="title"><a name="idp98160"></a>BIND 10 Messages Manual</h1></div><div><p class="releaseinfo">This is the messages manual for BIND 10 version
         20120712.</p></div><div><p class="copyright">Copyright © 2011-2012 Internet Systems Consortium, Inc.</p></div><div><div class="abstract" title="Abstract"><p class="title"><b>Abstract</b></p><p>BIND 10 is a Domain Name System (DNS) suite managed by
 	  Internet Systems Consortium (ISC). It includes DNS libraries
 	  and modular components for controlling authoritative and
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index c821b9f..7af44f9 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -1,5 +1,5 @@
 SUBDIRS = bind10 bindctl cfgmgr ddns loadzone msgq host cmdctl auth xfrin \
 	xfrout usermgr zonemgr stats tests resolver sockcreator dhcp4 dhcp6 \
-	dbutil showtech
+	dbutil sysinfo
 
 check-recursive: all-recursive
diff --git a/src/bin/bindctl/bindctl.1 b/src/bin/bindctl/bindctl.1
index 6aee29c..dc20e61 100644
--- a/src/bin/bindctl/bindctl.1
+++ b/src/bin/bindctl/bindctl.1
@@ -9,6 +9,15 @@
 .\"
 .TH "BINDCTL" "1" "June 20, 2012" "BIND10" "BIND10"
 .\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\" -----------------------------------------------------------------
 .\" * set default formatting
 .\" -----------------------------------------------------------------
 .\" disable hyphenation
@@ -54,7 +63,7 @@ The PEM formatted server certificate validation chain file\&.
 .PP
 \fB\-\-csv\-file\-dir\fR\fIfile\fR
 .RS 4
-The directory name in which the user/password CSV file is stored (see AUTHENTICATION)\&. By default this option doesn\'t have any value, in which case the "\&.bind10" directory under the user\'s home directory will be used\&.
+The directory name in which the user/password CSV file is stored (see AUTHENTICATION)\&. By default this option doesn\*(Aqt have any value, in which case the "\&.bind10" directory under the user\*(Aqs home directory will be used\&.
 .RE
 .PP
 \fB\-h\fR, \fB\-\-help\fR
@@ -105,17 +114,17 @@ prompt shows
 \fIparam1 = value1 , \fR\fI\fIparam2 = value2\fR\fR
 .PP
 
-\fBbindctl\fR\'s interactive interface provides command\-line completion and hints\&. Press the Tab key to get a hint for the module, command, and/or parameters\&.
+\fBbindctl\fR\*(Aqs interactive interface provides command\-line completion and hints\&. Press the Tab key to get a hint for the module, command, and/or parameters\&.
 The arrow keys and Emacs\-style editing keys may be used to edit and recall previous lines\&.
 .PP
 You can use the
 \fBhelp\fR
-keyword to receive usage assistance for a module or a module\'s command\&.
+keyword to receive usage assistance for a module or a module\*(Aqs command\&.
 .PP
 The
 \fBquit\fR
 command is used to exit
-\fBbindctl\fR\&. (It doesn\'t stop the BIND 10 services\&.)
+\fBbindctl\fR\&. (It doesn\*(Aqt stop the BIND 10 services\&.)
 .PP
 The following module is available by default:
 \fBconfig\fR
diff --git a/src/bin/cfgmgr/plugins/Makefile.am b/src/bin/cfgmgr/plugins/Makefile.am
index eb7809c..e6ed127 100644
--- a/src/bin/cfgmgr/plugins/Makefile.am
+++ b/src/bin/cfgmgr/plugins/Makefile.am
@@ -3,7 +3,7 @@ SUBDIRS = tests
 EXTRA_DIST = README logging.spec tsig_keys.spec
 
 datasrc.spec: datasrc.spec.pre
-	$(SED) -e "s|@@PKGDATADIR@@|$(pkgdatadir)|" datasrc.spec.pre >$@
+	$(SED) -e "s|@@PKGDATADIR@@|$(pkgdatadir)|;s|@@LOCALSTATEDIR@@|$(localstatedir)|" datasrc.spec.pre >$@
 
 config_plugindir = @prefix@/share/@PACKAGE@/config_plugins
 config_plugin_DATA = logging.spec tsig_keys.spec datasrc.spec
diff --git a/src/bin/cfgmgr/plugins/datasrc.spec.pre.in b/src/bin/cfgmgr/plugins/datasrc.spec.pre.in
index 5bd20bb..f2c6a97 100644
--- a/src/bin/cfgmgr/plugins/datasrc.spec.pre.in
+++ b/src/bin/cfgmgr/plugins/datasrc.spec.pre.in
@@ -8,6 +8,14 @@
                 "item_type": "named_set",
                 "item_optional": false,
                 "item_default": {
+                    "IN": [
+                        {
+                            "type": "sqlite3",
+                            "params": {
+                                "database_file": "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3"
+                            }
+                        }
+                    ],
                     "CH": [
                         {
                             "type": "static",
diff --git a/src/bin/cmdctl/b10-cmdctl.8 b/src/bin/cmdctl/b10-cmdctl.8
index 0b478fe..ab3ec61 100644
--- a/src/bin/cmdctl/b10-cmdctl.8
+++ b/src/bin/cmdctl/b10-cmdctl.8
@@ -9,6 +9,15 @@
 .\"
 .TH "B10\-CMDCTL" "8" "February 28, 2012" "BIND10" "BIND10"
 .\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\" -----------------------------------------------------------------
 .\" * set default formatting
 .\" -----------------------------------------------------------------
 .\" disable hyphenation
diff --git a/src/bin/resolver/b10-resolver.8 b/src/bin/resolver/b10-resolver.8
index eed69b8..34eb610 100644
--- a/src/bin/resolver/b10-resolver.8
+++ b/src/bin/resolver/b10-resolver.8
@@ -9,6 +9,15 @@
 .\"
 .TH "B10\-RESOLVER" "8" "February 28, 2012" "BIND10" "BIND10"
 .\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\" -----------------------------------------------------------------
 .\" * set default formatting
 .\" -----------------------------------------------------------------
 .\" disable hyphenation
diff --git a/src/bin/showtech/.gitignore b/src/bin/showtech/.gitignore
deleted file mode 100644
index f3d5873..0000000
--- a/src/bin/showtech/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/b10-showtech
-/showtech.py
diff --git a/src/bin/showtech/Makefile.am b/src/bin/showtech/Makefile.am
deleted file mode 100644
index cc9923c..0000000
--- a/src/bin/showtech/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-bin_SCRIPTS = b10-showtech
-
-CLEANFILES = b10-showtech showtech.pyc
-
-# this is done here since configure.ac AC_OUTPUT doesn't expand exec_prefix
-b10-showtech: showtech.py
-	$(SED) -e "s|@@PYTHONPATH@@|@pyexecdir@|" showtech.py >$@
-	chmod a+x $@
-
-MAN1_FILES = \
-	b10-showtech.xml
-
-man_MANS = \
-	$(MAN1_FILES:.xml=.1)
-
-if ENABLE_MAN
-
-.xml.1:
-	xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
-
-endif
-
-EXTRA_DIST = $(man_MANS) $(MAN1_FILES)
-
-CLEANDIRS = __pycache__
-
-clean-local:
-	rm -rf $(CLEANDIRS)
diff --git a/src/bin/showtech/b10-showtech.1 b/src/bin/showtech/b10-showtech.1
deleted file mode 100644
index b331713..0000000
--- a/src/bin/showtech/b10-showtech.1
+++ /dev/null
@@ -1,66 +0,0 @@
-'\" t
-.\"     Title: b10-showtech
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\"      Date: June 26, 2012
-.\"    Manual: BIND10
-.\"    Source: BIND10
-.\"  Language: English
-.\"
-.TH "B10\-SHOWTECH" "1" "June 26, 2012" "BIND10" "BIND10"
-.\" -----------------------------------------------------------------
-.\" * Define some portability stuff
-.\" -----------------------------------------------------------------
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.\" http://bugs.debian.org/507673
-.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
-.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.ie \n(.g .ds Aq \(aq
-.el       .ds Aq '
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-b10-showtech \- BIND 10 system information display tool
-.SH "SYNOPSIS"
-.HP \w'\fBb10\-showtech\fR\ 'u
-\fBb10\-showtech\fR
-.SH "DESCRIPTION"
-.PP
-The
-\fBb10\-showtech\fR
-program collects and outputs a variety of information about the system that BIND 10 is running on\&. This information can be useful to people involved in debugging and technical support\&.
-.SH "ARGUMENTS"
-.PP
-\-h
-.RS 4
-Displays usage instructions\&.
-.RE
-.PP
-\-o \fIoutput\-file\fR
-.RS 4
-If an output file is specified, the output of
-\fBb10\-showtech\fR
-is written to this file\&. By default, the output is written to standard output\&.
-.RE
-.SH "SEE ALSO"
-.PP
-
-\fBbind10\fR(8),
-BIND 10 Guide\&.
-.SH "HISTORY"
-.PP
-The
-\fBb10\-showtech\fR
-daemon was initially implemented by ISC staff in June, 2012\&.
-.SH "COPYRIGHT"
-.br
-Copyright \(co 2012 Internet Systems Consortium, Inc. ("ISC")
-.br
diff --git a/src/bin/showtech/b10-showtech.xml b/src/bin/showtech/b10-showtech.xml
deleted file mode 100644
index fe11ed1..0000000
--- a/src/bin/showtech/b10-showtech.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
-               "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
-	       [<!ENTITY mdash "—">]>
-<!--
- - Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
- -
- - Permission to use, copy, modify, and/or distribute this software for any
- - purpose with or without fee is hereby granted, provided that the above
- - copyright notice and this permission notice appear in all copies.
- -
- - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- - AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- - PERFORMANCE OF THIS SOFTWARE.
--->
-
-<refentry>
-
-  <refentryinfo>
-    <date>June 26, 2012</date>
-  </refentryinfo>
-
-  <refmeta>
-    <refentrytitle>b10-showtech</refentrytitle>
-    <manvolnum>1</manvolnum>
-    <refmiscinfo>BIND10</refmiscinfo>
-  </refmeta>
-
-  <refnamediv>
-    <refname>b10-showtech</refname>
-    <refpurpose>BIND 10 system information display tool</refpurpose>
-  </refnamediv>
-
-  <docinfo>
-    <copyright>
-      <year>2012</year>
-      <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
-    </copyright>
-  </docinfo>
-
-  <refsynopsisdiv>
-    <cmdsynopsis>
-      <command>b10-showtech</command>
-    </cmdsynopsis>
-  </refsynopsisdiv>
-
-  <refsect1>
-    <title>DESCRIPTION</title>
-    <para>
-      The <command>b10-showtech</command> program collects and outputs a
-      variety of information about the system that BIND 10 is running
-      on. This information can be useful to people involved in debugging
-      and technical support.
-    </para>
-  </refsect1>
-
-  <refsect1>
-    <title>ARGUMENTS</title>
-
-    <variablelist>
-
-      <varlistentry>
-        <term>-h</term>
-        <listitem><para>
-          Displays usage instructions.
-        </para></listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>-o <replaceable class="parameter">output-file</replaceable></term>
-        <listitem><para>
-          If an output file is specified, the output
-          of <command>b10-showtech</command> is written to this file. By
-          default, the output is written to standard output.
-        </para></listitem>
-      </varlistentry>
-
-    </variablelist>
-
-  </refsect1>
-
-  <refsect1>
-    <title>SEE ALSO</title>
-    <para>
-      <citerefentry>
-        <refentrytitle>bind10</refentrytitle><manvolnum>8</manvolnum>
-      </citerefentry>,
-      <citetitle>BIND 10 Guide</citetitle>.
-    </para>
-  </refsect1>
-
-  <refsect1>
-    <title>HISTORY</title>
-    <para>
-      The <command>b10-showtech</command> daemon was initially
-      implemented by ISC staff in June, 2012.
-    </para>
-  </refsect1>
-</refentry><!--
- - Local variables:
- - mode: sgml
- - End:
--->
diff --git a/src/bin/showtech/showtech.py.in b/src/bin/showtech/showtech.py.in
deleted file mode 100755
index 5b67847..0000000
--- a/src/bin/showtech/showtech.py.in
+++ /dev/null
@@ -1,127 +0,0 @@
-#!@PYTHON@
-
-# Copyright (C) 2012  Internet Systems Consortium.
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
-# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-"""
-BIND 10 showtech program.
-
-"""
-
-import sys; sys.path.append ('@@PYTHONPATH@@')
-import getopt
-import isc.util.process
-from isc.sysinfo import *
-
-isc.util.process.rename()
-
-def usage():
-    print("Usage: %s [-h] [-o <output-file>]" % sys.argv[0], \
-              file=sys.stderr)
-    exit(1)
-
-def main():
-    try:
-        opts, args = getopt.getopt(sys.argv[1:], "o:h", \
-                                       ["output", "help"])
-    except getopt.GetoptError as e:
-        print(str(e))
-        usage()
-        exit(1)
-
-    output_filename = None
-    for option, arg in opts:
-        if option in ("-o", "--output"):
-            output_filename = arg
-        elif option in ("-h", "--help"):
-            usage()
-        else:
-            assert False, "unhandled option"
-
-    if output_filename is None:
-        f = sys.stdout
-    else:
-        f = open(output_filename, 'w')
-
-    s = SysInfoFromFactory()
-
-    f.write('BIND 10 ShowTech tool\n')
-    f.write('=====================\n')
-
-    f.write('\nCPU\n');
-    f.write(' + Number of processors: %d\n' % (s.get_num_processors()))
-    f.write(' + Endianness: %s\n' % (s.get_endianness()))
-
-    f.write('\nPlatform\n');
-    f.write(' + Operating system: %s\n' % (s.get_platform_name()))
-    f.write(' + Distribution: %s\n' % (s.get_platform_distro()))
-    f.write(' + Kernel version: %s\n' % (s.get_platform_version()))
-
-    f.write(' + SMP kernel: ')
-    if s.get_platform_is_smp():
-        f.write('yes')
-    else:
-        f.write('no')
-    f.write('\n')
-
-    f.write(' + Machine name: %s\n' % (s.get_platform_machine()))
-    f.write(' + Hostname: %s\n' % (s.get_platform_hostname()))
-    f.write(' + Uptime: %d seconds\n' % (s.get_uptime()))
-
-    l = s.get_loadavg()
-    f.write(' + Loadavg: %f %f %f\n' % (l[0], l[1], l[2]))
-
-    f.write('\nMemory\n');
-    f.write(' + Total: %d bytes\n' % (s.get_mem_total()))
-    f.write(' + Free: %d bytes\n' % (s.get_mem_free()))
-    f.write(' + Cached: %d bytes\n' % (s.get_mem_cached()))
-    f.write(' + Buffers: %d bytes\n' % (s.get_mem_buffers()))
-    f.write(' + Swap total: %d bytes\n' % (s.get_mem_swap_total()))
-    f.write(' + Swap free: %d bytes\n' % (s.get_mem_swap_free()))
-
-    f.write('\n\nNetwork\n');
-    f.write('-------\n\n');
-
-    f.write('Interfaces\n')
-    f.write('~~~~~~~~~~\n\n')
-
-    f.write(s.get_net_interfaces())
-
-    f.write('\nRouting table\n')
-    f.write('~~~~~~~~~~~~~\n\n')
-    f.write(s.get_net_routing_table())
-
-    f.write('\nStatistics\n')
-    f.write('~~~~~~~~~~\n\n')
-    f.write(s.get_net_stats())
-
-    f.write('\nConnections\n')
-    f.write('~~~~~~~~~~~\n\n')
-    f.write(s.get_net_connections())
-
-    try:
-        if os.getuid() != 0:
-            sys.stderr.write('\n')
-            sys.stderr.write('NOTE: You have to run this program as the root user so that it can\n')
-            sys.stderr.write('      collect all the information it requires. Some information is\n')
-            sys.stderr.write('      only available to the root user.\n\n')
-    except Exception:
-        pass
-
-    if f != sys.stdout:
-        f.close()
-
-if __name__ == '__main__':
-    main()
diff --git a/src/bin/sysinfo/.gitignore b/src/bin/sysinfo/.gitignore
new file mode 100644
index 0000000..7a91274
--- /dev/null
+++ b/src/bin/sysinfo/.gitignore
@@ -0,0 +1,2 @@
+/isc-sysinfo
+/sysinfo.py
diff --git a/src/bin/sysinfo/Makefile.am b/src/bin/sysinfo/Makefile.am
new file mode 100644
index 0000000..8023f51
--- /dev/null
+++ b/src/bin/sysinfo/Makefile.am
@@ -0,0 +1,28 @@
+bin_SCRIPTS = isc-sysinfo
+
+CLEANFILES = isc-sysinfo sysinfo.pyc
+
+# this is done here since configure.ac AC_OUTPUT doesn't expand exec_prefix
+isc-sysinfo: sysinfo.py
+	$(SED) -e "s|@@PYTHONPATH@@|@pyexecdir@|" sysinfo.py >$@
+	chmod a+x $@
+
+MAN1_FILES = \
+	isc-sysinfo.xml
+
+man_MANS = \
+	$(MAN1_FILES:.xml=.1)
+
+if ENABLE_MAN
+
+.xml.1:
+	xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
+
+endif
+
+EXTRA_DIST = $(man_MANS) $(MAN1_FILES)
+
+CLEANDIRS = __pycache__
+
+clean-local:
+	rm -rf $(CLEANDIRS)
diff --git a/src/bin/sysinfo/isc-sysinfo.1 b/src/bin/sysinfo/isc-sysinfo.1
new file mode 100644
index 0000000..e923fdd
--- /dev/null
+++ b/src/bin/sysinfo/isc-sysinfo.1
@@ -0,0 +1,66 @@
+'\" t
+.\"     Title: isc-sysinfo
+.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
+.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
+.\"      Date: June 26, 2012
+.\"    Manual: BIND10
+.\"    Source: BIND10
+.\"  Language: English
+.\"
+.TH "ISC\-SYSINFO" "1" "June 26, 2012" "BIND10" "BIND10"
+.\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\" -----------------------------------------------------------------
+.\" * set default formatting
+.\" -----------------------------------------------------------------
+.\" disable hyphenation
+.nh
+.\" disable justification (adjust text to left margin only)
+.ad l
+.\" -----------------------------------------------------------------
+.\" * MAIN CONTENT STARTS HERE *
+.\" -----------------------------------------------------------------
+.SH "NAME"
+isc-sysinfo \- BIND 10 system information display tool
+.SH "SYNOPSIS"
+.HP \w'\fBisc\-sysinfo\fR\ 'u
+\fBisc\-sysinfo\fR
+.SH "DESCRIPTION"
+.PP
+The
+\fBisc\-sysinfo\fR
+program collects and outputs a variety of information about the system that BIND 10 is running on\&. This information can be useful to people involved in debugging and technical support\&.
+.SH "ARGUMENTS"
+.PP
+\-h
+.RS 4
+Displays usage instructions\&.
+.RE
+.PP
+\-o \fIoutput\-file\fR
+.RS 4
+If an output file is specified, the output of
+\fBisc\-sysinfo\fR
+is written to this file\&. By default, the output is written to standard output\&.
+.RE
+.SH "SEE ALSO"
+.PP
+
+\fBbind10\fR(8),
+BIND 10 Guide\&.
+.SH "HISTORY"
+.PP
+The
+\fBisc\-sysinfo\fR
+daemon was initially implemented by ISC staff in June, 2012\&.
+.SH "COPYRIGHT"
+.br
+Copyright \(co 2012 Internet Systems Consortium, Inc. ("ISC")
+.br
diff --git a/src/bin/sysinfo/isc-sysinfo.xml b/src/bin/sysinfo/isc-sysinfo.xml
new file mode 100644
index 0000000..919ed83
--- /dev/null
+++ b/src/bin/sysinfo/isc-sysinfo.xml
@@ -0,0 +1,106 @@
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+               "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
+	       [<!ENTITY mdash "—">]>
+<!--
+ - Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+ -
+ - Permission to use, copy, modify, and/or distribute this software for any
+ - purpose with or without fee is hereby granted, provided that the above
+ - copyright notice and this permission notice appear in all copies.
+ -
+ - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ - AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ - PERFORMANCE OF THIS SOFTWARE.
+-->
+
+<refentry>
+
+  <refentryinfo>
+    <date>June 26, 2012</date>
+  </refentryinfo>
+
+  <refmeta>
+    <refentrytitle>isc-sysinfo</refentrytitle>
+    <manvolnum>1</manvolnum>
+    <refmiscinfo>BIND10</refmiscinfo>
+  </refmeta>
+
+  <refnamediv>
+    <refname>isc-sysinfo</refname>
+    <refpurpose>BIND 10 system information display tool</refpurpose>
+  </refnamediv>
+
+  <docinfo>
+    <copyright>
+      <year>2012</year>
+      <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
+    </copyright>
+  </docinfo>
+
+  <refsynopsisdiv>
+    <cmdsynopsis>
+      <command>isc-sysinfo</command>
+    </cmdsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>DESCRIPTION</title>
+    <para>
+      The <command>isc-sysinfo</command> program collects and outputs a
+      variety of information about the system that BIND 10 is running
+      on. This information can be useful to people involved in debugging
+      and technical support.
+    </para>
+  </refsect1>
+
+  <refsect1>
+    <title>ARGUMENTS</title>
+
+    <variablelist>
+
+      <varlistentry>
+        <term>-h</term>
+        <listitem><para>
+          Displays usage instructions.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>-o <replaceable class="parameter">output-file</replaceable></term>
+        <listitem><para>
+          If an output file is specified, the output
+          of <command>isc-sysinfo</command> is written to this file. By
+          default, the output is written to standard output.
+        </para></listitem>
+      </varlistentry>
+
+    </variablelist>
+
+  </refsect1>
+
+  <refsect1>
+    <title>SEE ALSO</title>
+    <para>
+      <citerefentry>
+        <refentrytitle>bind10</refentrytitle><manvolnum>8</manvolnum>
+      </citerefentry>,
+      <citetitle>BIND 10 Guide</citetitle>.
+    </para>
+  </refsect1>
+
+  <refsect1>
+    <title>HISTORY</title>
+    <para>
+      The <command>isc-sysinfo</command> daemon was initially
+      implemented by ISC staff in June, 2012.
+    </para>
+  </refsect1>
+</refentry><!--
+ - Local variables:
+ - mode: sgml
+ - End:
+-->
diff --git a/src/bin/sysinfo/sysinfo.py.in b/src/bin/sysinfo/sysinfo.py.in
new file mode 100755
index 0000000..1e77acb
--- /dev/null
+++ b/src/bin/sysinfo/sysinfo.py.in
@@ -0,0 +1,127 @@
+#!@PYTHON@
+
+# Copyright (C) 2012  Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+"""
+ISC sysinfo program.
+
+"""
+
+import sys; sys.path.append ('@@PYTHONPATH@@')
+import getopt
+import isc.util.process
+from isc.sysinfo import *
+
+isc.util.process.rename()
+
+def usage():
+    print("Usage: %s [-h] [-o <output-file>]" % sys.argv[0], \
+              file=sys.stderr)
+    exit(1)
+
+def main():
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "o:h", \
+                                       ["output", "help"])
+    except getopt.GetoptError as e:
+        print(str(e))
+        usage()
+        exit(1)
+
+    output_filename = None
+    for option, arg in opts:
+        if option in ("-o", "--output"):
+            output_filename = arg
+        elif option in ("-h", "--help"):
+            usage()
+        else:
+            assert False, "unhandled option"
+
+    if output_filename is None:
+        f = sys.stdout
+    else:
+        f = open(output_filename, 'w')
+
+    s = SysInfoFromFactory()
+
+    f.write('BIND 10 ShowTech tool\n')
+    f.write('=====================\n')
+
+    f.write('\nCPU\n');
+    f.write(' + Number of processors: %d\n' % (s.get_num_processors()))
+    f.write(' + Endianness: %s\n' % (s.get_endianness()))
+
+    f.write('\nPlatform\n');
+    f.write(' + Operating system: %s\n' % (s.get_platform_name()))
+    f.write(' + Distribution: %s\n' % (s.get_platform_distro()))
+    f.write(' + Kernel version: %s\n' % (s.get_platform_version()))
+
+    f.write(' + SMP kernel: ')
+    if s.get_platform_is_smp():
+        f.write('yes')
+    else:
+        f.write('no')
+    f.write('\n')
+
+    f.write(' + Machine name: %s\n' % (s.get_platform_machine()))
+    f.write(' + Hostname: %s\n' % (s.get_platform_hostname()))
+    f.write(' + Uptime: %d seconds\n' % (s.get_uptime()))
+
+    l = s.get_loadavg()
+    f.write(' + Loadavg: %f %f %f\n' % (l[0], l[1], l[2]))
+
+    f.write('\nMemory\n');
+    f.write(' + Total: %d bytes\n' % (s.get_mem_total()))
+    f.write(' + Free: %d bytes\n' % (s.get_mem_free()))
+    f.write(' + Cached: %d bytes\n' % (s.get_mem_cached()))
+    f.write(' + Buffers: %d bytes\n' % (s.get_mem_buffers()))
+    f.write(' + Swap total: %d bytes\n' % (s.get_mem_swap_total()))
+    f.write(' + Swap free: %d bytes\n' % (s.get_mem_swap_free()))
+
+    f.write('\n\nNetwork\n');
+    f.write('-------\n\n');
+
+    f.write('Interfaces\n')
+    f.write('~~~~~~~~~~\n\n')
+
+    f.write(s.get_net_interfaces())
+
+    f.write('\nRouting table\n')
+    f.write('~~~~~~~~~~~~~\n\n')
+    f.write(s.get_net_routing_table())
+
+    f.write('\nStatistics\n')
+    f.write('~~~~~~~~~~\n\n')
+    f.write(s.get_net_stats())
+
+    f.write('\nConnections\n')
+    f.write('~~~~~~~~~~~\n\n')
+    f.write(s.get_net_connections())
+
+    try:
+        if os.getuid() != 0:
+            sys.stderr.write('\n')
+            sys.stderr.write('NOTE: You have to run this program as the root user so that it can\n')
+            sys.stderr.write('      collect all the information it requires. Some information is\n')
+            sys.stderr.write('      only available to the root user.\n\n')
+    except Exception:
+        pass
+
+    if f != sys.stdout:
+        f.close()
+
+if __name__ == '__main__':
+    main()
diff --git a/src/bin/zonemgr/b10-zonemgr.8 b/src/bin/zonemgr/b10-zonemgr.8
index 1bce2af..99bd8ea 100644
--- a/src/bin/zonemgr/b10-zonemgr.8
+++ b/src/bin/zonemgr/b10-zonemgr.8
@@ -9,6 +9,15 @@
 .\"
 .TH "B10\-ZONEMGR" "8" "February 28, 2012" "BIND10" "BIND10"
 .\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\" -----------------------------------------------------------------
 .\" * set default formatting
 .\" -----------------------------------------------------------------
 .\" disable hyphenation
@@ -92,7 +101,7 @@ The configuration commands are:
 (sent by
 \fBb10-auth\fR(8)) tells
 \fBb10\-zonemgr\fR
-the zone name and class, and the IP address for the master (source of the NOTIFY message)\&. This will set the zone\'s refresh time to now\&.
+the zone name and class, and the IP address for the master (source of the NOTIFY message)\&. This will set the zone\*(Aqs refresh time to now\&.
 This is an internal command and not exposed to the administrator\&.
 .PP
 
diff --git a/src/lib/datasrc/tests/testdata/.gitignore b/src/lib/datasrc/tests/testdata/.gitignore
index 58ea8cd..98a9657 100644
--- a/src/lib/datasrc/tests/testdata/.gitignore
+++ b/src/lib/datasrc/tests/testdata/.gitignore
@@ -1 +1,2 @@
-/*.sqlite3.copied
+/*.copied
+
diff --git a/src/lib/dhcp/pkt6.h b/src/lib/dhcp/pkt6.h
index 2612f27..b3a3567 100644
--- a/src/lib/dhcp/pkt6.h
+++ b/src/lib/dhcp/pkt6.h
@@ -139,7 +139,7 @@ public:
     /// Returns value of transaction-id field
     ///
     /// @return transaction-id
-    uint32_t getTransid() { return (transid_); };
+    uint32_t getTransid() const { return (transid_); };
 
     /// Adds an option to this packet.
     ///
diff --git a/src/lib/testutils/testdata/.gitignore b/src/lib/testutils/testdata/.gitignore
index 4d41a44..b2bb76a 100644
--- a/src/lib/testutils/testdata/.gitignore
+++ b/src/lib/testutils/testdata/.gitignore
@@ -1,5 +1,6 @@
 /auth_test.sqlite3.copied
 /badExampleQuery_fromWire.wire
+/does-not-exist.sqlite3
 /examplequery_fromWire.wire
 /iquery_fromWire.wire
 /iquery_response_fromWire.wire
diff --git a/tests/lettuce/configurations/bindctl/bindctl.config.orig b/tests/lettuce/configurations/bindctl/bindctl.config.orig
index bf623c5..3530b3e 100644
--- a/tests/lettuce/configurations/bindctl/bindctl.config.orig
+++ b/tests/lettuce/configurations/bindctl/bindctl.config.orig
@@ -14,6 +14,9 @@
             "address": "127.0.0.1"
         } ]
     },
+    "data_sources": {
+        "classes": {}
+    },
     "Boss": {
         "components": {
             "b10-cmdctl": { "special": "cmdctl", "kind": "needed" }
diff --git a/tests/lettuce/configurations/bindctl_commands.config.orig b/tests/lettuce/configurations/bindctl_commands.config.orig
index d74b96e..b60201d 100644
--- a/tests/lettuce/configurations/bindctl_commands.config.orig
+++ b/tests/lettuce/configurations/bindctl_commands.config.orig
@@ -14,6 +14,9 @@
             "address": "127.0.0.1"
         } ]
     },
+    "data_sources": {
+        "classes": {}
+    },
     "StatsHttpd": {
         "listen_on": [ {
             "port": 47811,
diff --git a/tests/tools/perfdhcp/Makefile.am b/tests/tools/perfdhcp/Makefile.am
index d46f2d1..7c8064e 100644
--- a/tests/tools/perfdhcp/Makefile.am
+++ b/tests/tools/perfdhcp/Makefile.am
@@ -24,8 +24,10 @@ libb10_perfdhcp___la_SOURCES += localized_option.h
 libb10_perfdhcp___la_SOURCES += perf_pkt6.cc perf_pkt6.h
 libb10_perfdhcp___la_SOURCES += perf_pkt4.cc perf_pkt4.h
 libb10_perfdhcp___la_SOURCES += pkt_transform.cc pkt_transform.h
+libb10_perfdhcp___la_SOURCES += stats_mgr.h
 
 libb10_perfdhcp___la_CXXFLAGS = $(AM_CXXFLAGS)
+
 if USE_CLANGPP
 # Disable unused parameter warning caused by some of the
 # Boost headers when compiling with clang.
diff --git a/tests/tools/perfdhcp/stats_mgr.h b/tests/tools/perfdhcp/stats_mgr.h
new file mode 100644
index 0000000..245c69e
--- /dev/null
+++ b/tests/tools/perfdhcp/stats_mgr.h
@@ -0,0 +1,1137 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef __STATS_MGR_H
+#define __STATS_MGR_H
+
+#include <iostream>
+#include <map>
+
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+#include <boost/multi_index/sequenced_index.hpp>
+#include <boost/multi_index/global_fun.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include <exceptions/exceptions.h>
+
+namespace isc {
+namespace perfdhcp {
+
+/// \brief Statistics Manager
+///
+/// This class template is a storage for various performance statistics
+/// collected during performance tests execution with perfdhcp tool.
+///
+/// Statistics Manager holds lists of sent and received packets and
+/// groups them into exchanges. For example: DHCPDISCOVER message and
+/// corresponding DHCPOFFER messages belong to one exchange, DHCPREQUEST
+/// and corresponding DHCPACK message belong to another exchange etc.
+/// In order to update statistics for a particular exchange type, client
+/// class passes sent and received packets. Internally, Statistics Manager
+/// tries to match transaction id of received packet with sent packet
+/// stored on the list of sent packets. When packets are matched the
+/// round trip time can be calculated.
+///
+/// \tparam T class representing DHCPv4 or DHCPv6 packet.
+template <class T>
+class StatsMgr : public boost::noncopyable {
+public:
+
+    /// \brief Custom Counter
+    ///
+    /// This class represents custom statistics counters. Client class
+    /// may create unlimited number of counters. Such counters are
+    /// being stored in map in Statistics Manager and access using
+    /// unique string key.
+    class CustomCounter {
+    public:
+        /// \brief Constructor.
+        ///
+        /// This constructor sets counter name. This name is used in
+        /// log file to report value of each counter.
+        ///
+        /// \param name name of the counter used in log file.
+        CustomCounter(const std::string& name) :
+            counter_(0),
+            name_(name) { };
+
+        /// \brief Increment operator.
+        const CustomCounter& operator++() {
+            ++counter_;
+            return(*this);
+        }
+
+        /// \brief Increment operator.
+        const CustomCounter& operator++(int) {
+            CustomCounter& this_counter(*this);
+            operator++();
+            return(this_counter);
+        }
+
+        /// \brief Return counter value.
+        ///
+        /// Method returns counter value.
+        ///
+        /// \return counter value.
+        uint64_t getValue() const { return(counter_); }
+
+        /// \brief Return counter name.
+        ///
+        /// Method returns counter name.
+        ///
+        /// \return counter name.
+        const std::string& getName() const { return(name_); }
+    private:
+        /// \brief Default constructor.
+        ///
+        /// Default constrcutor is private because we don't want client
+        /// class to call it because we want client class to specify
+        /// counter's name.
+        CustomCounter() { };
+
+        uint64_t counter_;  ///< Counter's value.
+        std::string name_;            ///< Counter's name.
+    };
+
+    typedef typename boost::shared_ptr<CustomCounter> CustomCounterPtr;
+
+    /// DHCP packet exchange types.
+    enum ExchangeType {
+        XCHG_DO,  ///< DHCPv4 DISCOVER-OFFER
+        XCHG_RA,  ///< DHCPv4 REQUEST-ACK
+        XCHG_SA,  ///< DHCPv6 SOLICIT-ADVERTISE
+        XCHG_RR   ///< DHCPv6 REQUEST-REPLY
+    };
+
+    /// \brief Exchange Statistics.
+    ///
+    /// This class collects statistics for exchanges. Parent class
+    /// may define number of different packet exchanges like:
+    /// DHCPv4 DISCOVER-OFFER, DHCPv6 SOLICIT-ADVERTISE etc. Performance
+    /// statistics will be collected for each of those separately in
+    /// corresponding instance of ExchangeStats.
+    class ExchangeStats {
+    public:
+
+        /// \brief Hash transaction id of the packet.
+        ///
+        /// Function hashes transaction id of the packet. Hashing is
+        /// non-unique. Many packets may have the same hash value and thus
+        /// they belong to the same packet buckets. Packet buckets are
+        /// used for unordered packets search with multi index container.
+        ///
+        /// \param packet packet which transaction id is to be hashed.
+        /// \throw isc::BadValue if packet is null.
+        /// \return transaction id hash.
+        static uint32_t hashTransid(const boost::shared_ptr<const T>& packet) {
+            if (!packet) {
+                isc_throw(BadValue, "Packet is null");
+            }
+            return(packet->getTransid() & 1023);
+        }
+
+        /// \brief List of packets (sent or received).
+        ///
+        /// List of packets based on multi index container allows efficient
+        /// search of packets based on their sequence (order in which they
+        /// were inserted) as well as based on their hashed transaction id.
+        /// The first index (sequenced) provides the way to use container
+        /// as a regular list (including iterators, removal of elements from
+        /// the middle of the collection etc.). This index is meant to be used
+        /// more frequently than the latter one and it is based on the
+        /// assumption that responses from the DHCP server are received in
+        /// order. In this case, when next packet is received it can be
+        /// matched with next packet on the list of sent packets. This
+        /// prevents intensive searches on the list of sent packets every
+        /// time new packet arrives. In many cases however packets can be
+        /// dropped by the server or may be sent out of order and we still
+        ///  want to have ability to search packets using transaction id.
+        /// The second index can be used for this purpose. This index is
+        /// hashing transaction ids using custom function \ref hashTransid.
+        /// Note that other possibility would be to simply specify index
+        /// that uses transaction id directly (instead of hashing with
+        /// \ref hashTransid). In this case however we have chosen to use
+        /// hashing function because it shortens the index size to just
+        /// 1023 values maximum. Search operation on this index generally
+        /// returns the range of packets that have the same transaction id
+        /// hash assigned but most often these ranges will be short so further
+        /// search within a range to find a packet with pacrticular transaction
+        /// id will not be intensive.
+        ///
+        /// Example 1: Add elements to the list
+        /// \code
+        /// PktList packets_collection();
+        /// boost::shared_ptr<Pkt4> pkt1(new Pkt4(...));
+        /// boost::shared_ptr<Pkt4> pkt2(new Pkt4(...));
+        /// // Add new packet to the container, it will be available through
+        /// // both indexes
+        /// packets_collection.push_back(pkt1);
+        /// // Here is another way to add packet to the container. The result
+        /// // is exactly the same as previously.
+        /// packets_collection.template get<0>().push_back(pkt2);
+        /// \endcode
+        ///
+        /// Example 2: Access elements through sequencial index
+        /// \code
+        /// PktList packets_collection();
+        /// ...  # Add elements to the container
+        /// for (PktListIterator it = packets_collection.begin();
+        ///      it != packets_collection.end();
+        ///      ++it) {
+        ///          boost::shared_ptr<Pkt4> pkt = *it;
+        ///          # Do something with packet;
+        ///      }
+        /// \endcode
+        ///
+        /// Example 3: Access elements through hashed index
+        /// \code
+        /// // Get the instance of the second search index.
+        /// PktListTransidHashIndex& idx = sent_packets_.template get<1>();
+        /// // Get the range (bucket) of packets sharing the same transaction
+        /// // id hash.
+        /// std::pair<PktListTransidHashIterator,PktListTransidHashIterator> p =
+        ///     idx.equal_range(hashTransid(rcvd_packet));
+        /// // Iterate through the returned bucket.
+        /// for (PktListTransidHashIterator it = p.first; it != p.second;
+        ///     ++it) {
+        ///    boost::shared_ptr pkt = *it;
+        ///    ... # Do something with the packet (e.g. check transaction id)
+        /// }
+        /// \endcode
+        typedef boost::multi_index_container<
+            boost::shared_ptr<const T>,
+            boost::multi_index::indexed_by<
+                boost::multi_index::sequenced<>,
+                boost::multi_index::hashed_non_unique<
+                        boost::multi_index::global_fun<
+                            const boost::shared_ptr<const T>&,
+                            uint32_t,
+                            &ExchangeStats::hashTransid
+                        >
+                >
+            >
+        > PktList;
+
+        /// Packet list iterator for sequencial access to elements.
+        typedef typename PktList::const_iterator PktListIterator;
+        /// Packet list index to search packets using transaction id hash.
+        typedef typename PktList::template nth_index<1>::type
+            PktListTransidHashIndex;
+        /// Packet list iterator to access packets using transaction id hash.
+        typedef typename PktListTransidHashIndex::const_iterator
+            PktListTransidHashIterator;
+
+        /// \brief Constructor
+        ///
+        /// \param xchg_type exchange type
+        /// \param archive_enabled if true packets archive mode is enabled.
+        /// In this mode all packets are stored throughout the test execution.
+        ExchangeStats(const ExchangeType xchg_type, const bool archive_enabled)
+            : xchg_type_(xchg_type),
+            min_delay_(std::numeric_limits<double>::max()),
+            max_delay_(0.),
+            sum_delay_(0.),
+            orphans_(0),
+            sum_delay_squared_(0.),
+            ordered_lookups_(0),
+            unordered_lookup_size_sum_(0),
+            unordered_lookups_(0),
+            sent_packets_num_(0),
+            rcvd_packets_num_(0),
+            sent_packets_(),
+            rcvd_packets_(),
+            archived_packets_(),
+            archive_enabled_(archive_enabled) {
+            next_sent_ = sent_packets_.begin();
+        }
+
+        /// \brief Add new packet to list of sent packets.
+        ///
+        /// Method adds new packet to list of sent packets.
+        ///
+        /// \param packet packet object to be added.
+        /// \throw isc::BadValue if packet is null.
+        void appendSent(const boost::shared_ptr<const T>& packet) {
+            if (!packet) {
+                isc_throw(BadValue, "Packet is null");
+            }
+            ++sent_packets_num_;
+            sent_packets_.template get<0>().push_back(packet);
+        }
+
+        /// \brief Add new packet to list of received packets.
+        ///
+        /// Method adds new packet to list of received packets.
+        ///
+        /// \param packet packet object to be added.
+        /// \throw isc::BadValue if packet is null.
+        void appendRcvd(const boost::shared_ptr<const T>& packet) {
+            if (!packet) {
+                isc_throw(BadValue, "Packet is null");
+            }
+            rcvd_packets_.push_back(packet);
+        }
+
+        ///  \brief Update delay counters.
+        ///
+        /// Method updates delay counters based on timestamps of
+        /// sent and received packets.
+        ///
+        /// \param sent_packet sent packet
+        /// \param rcvd_packet received packet
+        /// \throw isc::BadValue if sent or received packet is null.
+        /// \throw isc::Unexpected if failed to calculate timestamps
+        void updateDelays(const boost::shared_ptr<const T>& sent_packet,
+                          const boost::shared_ptr<const T>& rcvd_packet) {
+            if (!sent_packet) {
+                isc_throw(BadValue, "Sent packet is null");
+            }
+            if (!rcvd_packet) {
+                isc_throw(BadValue, "Received packet is null");
+            }
+
+            boost::posix_time::ptime sent_time = sent_packet->getTimestamp();
+            boost::posix_time::ptime rcvd_time = rcvd_packet->getTimestamp();
+
+            if (sent_time.is_not_a_date_time() ||
+                rcvd_time.is_not_a_date_time()) {
+                isc_throw(Unexpected,
+                          "Timestamp must be set for sent and "
+                          "received packet to measure RTT");
+            }
+            boost::posix_time::time_period period(sent_time, rcvd_time);
+            // We don't bother calculating deltas in nanoseconds. It is much
+            // more convenient to use seconds instead because we are going to
+            // sum them up.
+            double delta =
+                static_cast<double>(period.length().total_nanoseconds()) / 1e9;
+
+            if (delta < 0) {
+                isc_throw(Unexpected, "Sent packet's timestamp must not be "
+                          "greater than received packet's timestamp");
+            }
+
+            // Record the minimum delay between sent and received packets.
+            if (delta < min_delay_) {
+                min_delay_ = delta;
+            }
+            // Record the maximum delay between sent and received packets.
+            if (delta > max_delay_) {
+                max_delay_ = delta;
+            }
+            // Update delay sum and square sum. That will be used to calculate
+            // mean delays.
+            sum_delay_ += delta;
+            sum_delay_squared_ += delta * delta;
+        }
+
+        /// \brief Match received packet with the corresponding sent packet.
+        ///
+        /// Method finds packet with specified transaction id on the list
+        /// of sent packets. It is used to match received packet with
+        /// corresponding sent packet.
+        /// Since packets from the server most often come in the same order
+        /// as they were sent by client, this method will first check if
+        /// next sent packet matches. If it doesn't, function will search
+        /// the packet using indexing by transaction id. This reduces
+        /// packet search time significantly.
+        ///
+        /// \param rcvd_packet received packet to be matched with sent packet.
+        /// \throw isc::BadValue if received packet is null.
+        /// \return packet having specified transaction or NULL if packet
+        /// not found
+        boost::shared_ptr<const T> matchPackets(const boost::shared_ptr<const T>& rcvd_packet) {
+            if (!rcvd_packet) {
+                isc_throw(BadValue, "Received packet is null");
+            }
+
+            if (sent_packets_.size() == 0) {
+                // List of sent packets is empty so there is no sense
+                // to continue looking fo the packet. It also means
+                // that the received packet we got has no corresponding
+                // sent packet so orphans counter has to be updated.
+                ++orphans_;
+                return(boost::shared_ptr<const T>());
+            } else if (next_sent_ == sent_packets_.end()) {
+                // Even if there are still many unmatched packets on the
+                // list we might hit the end of it because of unordered
+                // lookups. The next logical step is to reset iterator.
+                next_sent_ = sent_packets_.begin();
+            }
+
+            // With this variable we will be signalling success or failure
+            // to find the packet.
+            bool packet_found = false;
+            // Most likely responses are sent from the server in the same
+            // order as client's requests to the server. We are caching
+            // next sent packet and first try to match it with the next
+            // incoming packet. We are successful if there is no
+            // packet drop or out of order packets sent. This is actually
+            // the fastest way to look for packets.
+            if ((*next_sent_)->getTransid() == rcvd_packet->getTransid()) {
+                ++ordered_lookups_;
+                packet_found = true;
+            } else {
+                // If we are here, it means that we were unable to match the
+                // next incoming packet with next sent packet so we need to
+                // take a little more expensive approach to look packets using
+                // alternative index (transaction id & 1023).
+                PktListTransidHashIndex& idx = sent_packets_.template get<1>();
+                // Packets are grouped using trasaction id masked with value
+                // of 1023. For instance, packets with transaction id equal to
+                // 1, 1024 ... will belong to the same group (a.k.a. bucket).
+                // When using alternative index we don't find the packet but
+                // bucket of packets and we need to iterate through the bucket
+                // to find the one that has desired transaction id.
+                std::pair<PktListTransidHashIterator,PktListTransidHashIterator> p =
+                    idx.equal_range(hashTransid(rcvd_packet));
+                // We want to keep statistics of unordered lookups to make
+                // sure that there is a right balance between number of
+                // unordered lookups and ordered lookups. If number of unordered
+                // lookups is high it may mean that many packets are lost or
+                // sent out of order.
+                ++unordered_lookups_;
+                // We also want to keep the mean value of the bucket. The lower
+                // bucket size the better. If bucket sizes appear to big we
+                // might want to increase number of buckets.
+                unordered_lookup_size_sum_ += std::distance(p.first, p.second);
+                for (PktListTransidHashIterator it = p.first; it != p.second;
+                     ++it) {
+                    if ((*it)->getTransid() == rcvd_packet->getTransid()) {
+                        packet_found = true;
+                        next_sent_ =
+                            sent_packets_.template project<0>(it);
+                        break;
+                    }
+                }
+            }
+
+            if (!packet_found) {
+                // If we are here, it means that both ordered lookup and
+                // unordered lookup failed. Searched packet is not on the list.
+                ++orphans_;
+                return(boost::shared_ptr<const T>());
+            }
+
+            // Packet is matched so we count it. We don't count unmatched packets
+            // as they are counted as orphans with a separate counter.
+            ++rcvd_packets_num_;
+            boost::shared_ptr<const T> sent_packet(*next_sent_);
+            // If packet was found, we assume it will be never searched
+            // again. We want to delete this packet from the list to
+            // improve performance of future searches.
+            next_sent_ = eraseSent(next_sent_);
+            return(sent_packet);
+        }
+
+        /// \brief Return minumum delay between sent and received packet.
+        ///
+        /// Method returns minimum delay between sent and received packet.
+        ///
+        /// \return minimum delay between packets.
+        double getMinDelay() const { return(min_delay_); }
+
+        /// \brief Return maxmimum delay between sent and received packet.
+        ///
+        /// Method returns maximum delay between sent and received packet.
+        ///
+        /// \return maximum delay between packets.
+        double getMaxDelay() const { return(max_delay_); }
+
+        /// \brief Return avarage packet delay.
+        ///
+        /// Method returns average packet delay. If no packets have been
+        /// received for this exchange avg delay can't be calculated and
+        /// thus method throws exception.
+        ///
+        /// \throw isc::InvalidOperation if no packets for this exchange
+        /// have been received yet.
+        /// \return average packet delay.
+        double getAvgDelay() const {
+            if (rcvd_packets_num_  == 0) {
+                isc_throw(InvalidOperation, "no packets received");
+            }
+            return(sum_delay_ / rcvd_packets_num_);
+        }
+
+        /// \brief Return standard deviation of packet delay.
+        ///
+        /// Method returns standard deviation of packet delay. If no
+        /// packets have been received for this exchange, the standard
+        /// deviation can't be calculated and thus method throws
+        /// exception.
+        ///
+        /// \throw isc::InvalidOperation if number of received packets
+        /// for the exchange is equal to zero.
+        /// \return standard deviation of packet delay.
+        double getStdDevDelay() const {
+            if (rcvd_packets_num_ == 0) {
+                isc_throw(InvalidOperation, "no packets received");
+            }
+            return(sqrt(sum_delay_squared_ / rcvd_packets_num_ -
+                        getAvgDelay() * getAvgDelay()));
+        }
+
+        /// \brief Return number of orphant packets.
+        ///
+        /// Method returns number of received packets that had no matching
+        /// sent packet. It is possible that such packet was late or not
+        /// for us.
+        ///
+        /// \return number of orphant received packets.
+        uint64_t getOrphans() const { return(orphans_); }
+
+        /// \brief Return average unordered lookup set size.
+        ///
+        /// Method returns average unordered lookup set size.
+        /// This value changes every time \ref ExchangeStats::matchPackets
+        /// function performs unordered packet lookup.
+        ///
+        /// \throw isc::InvalidOperation if there have been no unordered
+        /// lookups yet.
+        /// \return average unordered lookup set size.
+        double getAvgUnorderedLookupSetSize() const {
+            if (unordered_lookups_ == 0) {
+                isc_throw(InvalidOperation, "no unordered lookups");
+            }
+            return(static_cast<double>(unordered_lookup_size_sum_) /
+                   static_cast<double>(unordered_lookups_));
+        }
+
+        /// \brief Return number of unordered sent packets lookups
+        ///
+        /// Method returns number of unordered sent packet lookups.
+        /// Unordered lookup is used when received packet was sent
+        /// out of order by server - transaction id of received
+        /// packet does not match transaction id of next sent packet.
+        ///
+        /// \return number of unordered lookups.
+        uint64_t getUnorderedLookups() const { return(unordered_lookups_); }
+
+        /// \brief Return number of ordered sent packets lookups
+        ///
+        /// Method returns number of ordered sent packet lookups.
+        /// Ordered lookup is used when packets are received in the
+        /// same order as they were sent to the server.
+        /// If packets are skipped or received out of order, lookup
+        /// function will use unordered lookup (with hash table).
+        ///
+        /// \return number of ordered lookups.
+        uint64_t getOrderedLookups() const { return(ordered_lookups_); }
+
+        /// \brief Return total number of sent packets
+        ///
+        /// Method returns total number of sent packets.
+        ///
+        /// \return number of sent packets.
+        uint64_t getSentPacketsNum() const { return(sent_packets_num_); }
+
+        /// \brief Return total number of received packets
+        ///
+        /// Method returns total number of received packets.
+        ///
+        /// \return number of received packets.
+        uint64_t getRcvdPacketsNum() const { return(rcvd_packets_num_); }
+
+        /// \brief Print main statistics for packet exchange.
+        ///
+        /// Method prints main statistics for particular exchange.
+        /// Statistics includes: number of sent and received packets,
+        /// number of dropped packets and number of orphans.
+        void printMainStats() const {
+            using namespace std;
+            uint64_t drops = getRcvdPacketsNum() - getSentPacketsNum();
+            cout << "sent packets: " << getSentPacketsNum() << endl
+                 << "received packets: " << getRcvdPacketsNum() << endl
+                 << "drops: " << drops << endl
+                 << "orphans: " << getOrphans() << endl;
+        }
+
+        /// \brief Print round trip time packets statistics.
+        ///
+        /// Method prints round trip time packets statistics. Statistics
+        /// includes minimum packet delay, maximum packet delay, average
+        /// packet delay and standard deviation of delays. Packet delay
+        /// is a duration between sending a packet to server and receiving
+        /// response from server.
+        void printRTTStats() const {
+            using namespace std;
+            try {
+                cout << fixed << setprecision(3)
+                     << "min delay: " << getMinDelay() * 1e3 << " ms" << endl
+                     << "avg delay: " << getAvgDelay() * 1e3 << " ms" << endl
+                     << "max delay: " << getMaxDelay() * 1e3 << " ms" << endl
+                     << "std deviation: " << getStdDevDelay() * 1e3 << " ms"
+                     << endl;
+            } catch (const Exception& e) {
+                cout << "Unavailable! No packets received." << endl;
+            }
+        }
+
+        //// \brief Print timestamps for sent and received packets.
+        ///
+        /// Method prints timestamps for all sent and received packets for
+        /// packet exchange. In order to run this method the packets
+        /// archiving mode has to be enabled during object constructions.
+        /// Otherwise sent packets are not stored during tests execution
+        /// and this method has no ability to get and print their timestamps.
+        ///
+        /// \throw isc::InvalidOperation if found packet with no timestamp or
+        /// if packets archive mode is disabled.
+        void printTimestamps() {
+            // If archive mode is disabled there is no sense to proceed
+            // because we don't have packets and their timestamps.
+            if (!archive_enabled_) {
+                isc_throw(isc::InvalidOperation,
+                          "packets archive mode is disabled");
+            }
+            if (rcvd_packets_num_ == 0) {
+                std::cout << "Unavailable! No packets received." << std::endl;
+            }
+            // We will be using boost::posix_time extensivelly here
+            using namespace boost::posix_time;
+
+            // Iterate through all received packets.
+            for (PktListIterator it = rcvd_packets_.begin();
+                 it != rcvd_packets_.end();
+                 ++it) {
+                boost::shared_ptr<const T> rcvd_packet = *it;
+                PktListTransidHashIndex& idx =
+                    archived_packets_.template get<1>();
+                std::pair<PktListTransidHashIterator,
+                          PktListTransidHashIterator> p =
+                    idx.equal_range(hashTransid(rcvd_packet));
+                for (PktListTransidHashIterator it_archived = p.first;
+                     it_archived != p.second;
+                     ++it) {
+                    if ((*it_archived)->getTransid() ==
+                        rcvd_packet->getTransid()) {
+                        boost::shared_ptr<const T> sent_packet = *it_archived;
+                        // Get sent and received packet times.
+                        ptime sent_time = sent_packet->getTimestamp();
+                        ptime rcvd_time = rcvd_packet->getTimestamp();
+                        // All sent and received packets should have timestamps
+                        // set but if there is a bug somewhere and packet does
+                        // not have timestamp we want to catch this here.
+                        if (sent_time.is_not_a_date_time() ||
+                            rcvd_time.is_not_a_date_time()) {
+                            isc_throw(InvalidOperation,
+                                      "packet time is not set");
+                        }
+                        // Calculate durations of packets from beginning of epoch.
+                        ptime epoch_time(min_date_time);
+                        time_period sent_period(epoch_time, sent_time);
+                        time_period rcvd_period(epoch_time, rcvd_time);
+                        // Print timestamps for sent and received packet.
+                        std::cout << "sent / received: "
+                                  << to_iso_string(sent_period.length())
+                                  << " / "
+                                  << to_iso_string(rcvd_period.length())
+                                  << std::endl;
+                        break;
+                    }
+                }
+            }
+        }
+
+    private:
+
+        /// \brief Private default constructor.
+        ///
+        /// Default constructor is private because we want the client
+        /// class to specify exchange type explicitely.
+        ExchangeStats();
+
+        /// \brief Erase packet from the list of sent packets.
+        ///
+        /// Method erases packet from the list of sent packets.
+        ///
+        /// \param it iterator pointing to packet to be erased.
+        /// \return iterator pointing to packet following erased
+        /// packet or sent_packets_.end() if packet not found.
+         PktListIterator eraseSent(const PktListIterator it) {
+             if (archive_enabled_) {
+                 // We don't want to keep list of all sent packets
+                 // because it will affect packet lookup performance.
+                 // If packet is matched with received packet we
+                 // move it to list of archived packets. List of
+                 // archived packets may be used for diagnostics
+                 // when test is completed.
+                 archived_packets_.push_back(*it);
+             }
+             // get<0>() template returns sequencial index to
+             // container.
+             return(sent_packets_.template get<0>().erase(it));
+        }
+
+        ExchangeType xchg_type_;             ///< Packet exchange type.
+        PktList sent_packets_;               ///< List of sent packets.
+
+        /// Iterator pointing to the packet on sent list which will most
+        /// likely match next received packet. This is based on the
+        /// assumption that server responds in order to incoming packets.
+        PktListIterator next_sent_;
+
+        PktList rcvd_packets_;         ///< List of received packets.
+
+        /// List of archived packets. All sent packets that have
+        /// been matched with received packet are moved to this
+        /// list for diagnostics purposes.
+        PktList archived_packets_;
+
+        /// Indicates all packets have to be preserved after matching.
+        /// By default this is disabled which means that when received
+        /// packet is matched with sent packet both are deleted. This
+        /// is important when test is executed for extended period of
+        /// time and high memory usage might be the issue.
+        /// When timestamps listing is specified from the command line
+        /// (using diagnostics selector), all packets have to be preserved
+        /// so as the printing method may read their timestamps and
+        /// print it to user. In such usage model it will be rare to
+        /// run test for extended period of time so it should be fine
+        /// to keep all packets archived throughout the test.
+        bool archive_enabled_;
+
+        double min_delay_;             ///< Minimum delay between sent
+                                       ///< and received packets.
+        double max_delay_;             ///< Maximum delay between sent
+                                       ///< and received packets.
+        double sum_delay_;             ///< Sum of delays between sent
+                                       ///< and received packets.
+        double sum_delay_squared_;     ///< Squared sum of delays between
+                                       ///< sent and recived packets.
+
+        uint64_t orphans_;   ///< Number of orphant received packets.
+
+        /// Sum of unordered lookup sets. Needed to calculate mean size of
+        /// lookup set. It is desired that number of unordered lookups is
+        /// minimal for performance reasons. Tracking number of lookups and
+        /// mean size of the lookup set should give idea of packets serach
+        /// complexity.
+        uint64_t unordered_lookup_size_sum_;
+
+        uint64_t unordered_lookups_;   ///< Number of unordered sent packets
+                                       ///< lookups.
+        uint64_t ordered_lookups_;     ///< Number of ordered sent packets
+                                       ///< lookups.
+
+        uint64_t sent_packets_num_;    ///< Total number of sent packets.
+        uint64_t rcvd_packets_num_;    ///< Total number of received packets.
+    };
+
+    /// Pointer to ExchangeStats.
+    typedef boost::shared_ptr<ExchangeStats> ExchangeStatsPtr;
+    /// Map containing all specified exchange types.
+    typedef typename std::map<ExchangeType, ExchangeStatsPtr> ExchangesMap;
+    /// Iterator poiting to \ref ExchangesMap
+    typedef typename ExchangesMap::const_iterator ExchangesMapIterator;
+    /// Map containing custom counters.
+    typedef typename std::map<std::string, CustomCounterPtr> CustomCountersMap;
+    /// Iterator for \ref CustomCountersMap.
+    typedef typename CustomCountersMap::const_iterator CustomCountersMapIterator;
+
+    /// \brief Constructor.
+    ///
+    /// This constructor by default disables packets archiving mode.
+    /// In this mode all packets from the list of sent packets are
+    /// moved to list of archived packets once they have been matched
+    /// with received packets. This is required if it has been selected
+    /// from the command line to print timestamps for all packets after
+    /// the test. If this is not selected archiving should be disabled
+    /// for performance reasons and to avoid waste of memory for storing
+    /// large list of archived packets.
+    ///
+    /// \param archive_enabled true indicates that packets
+    /// archive mode is enabled.
+    StatsMgr(const bool archive_enabled = false) :
+        exchanges_(),
+        custom_counters_(),
+        archive_enabled_(archive_enabled) {
+    }
+
+    /// \brief Specify new exchange type.
+    ///
+    /// This method creates new \ref ExchangeStats object that will
+    /// collect statistics data from packets exchange of the specified
+    /// type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if exchange of specified type exists.
+    void addExchangeStats(const ExchangeType xchg_type) {
+        if (exchanges_.find(xchg_type) != exchanges_.end()) {
+            isc_throw(BadValue, "Exchange of specified type already added.");
+        }
+        exchanges_[xchg_type] =
+            ExchangeStatsPtr(new ExchangeStats(xchg_type, archive_enabled_));
+    }
+
+    /// \brief Add named custom uint64 counter.
+    ///
+    /// Method creates new named counter and stores in counter's map under
+    /// key specified here as short_name.
+    ///
+    /// \param short_name key to use to access counter in the map.
+    /// \param long_name name of the counter presented in the log file.
+    void addCustomCounter(const std::string& short_name,
+                          const std::string& long_name) {
+        if (custom_counters_.find(short_name) != custom_counters_.end()) {
+            isc_throw(BadValue,
+                      "Custom counter " << short_name << " already added.");
+        }
+        custom_counters_[short_name] =
+            CustomCounterPtr(new CustomCounter(long_name));
+    }
+
+    /// \brief Return specified counter.
+    ///
+    /// Method returns specified counter.
+    ///
+    /// \param counter_key key poiting to the counter in the counters map.
+    /// The short counter name has to be used to access counter.
+    /// \return pointer to specified counter object.
+    CustomCounterPtr getCounter(const std::string& counter_key) {
+        CustomCountersMapIterator it = custom_counters_.find(counter_key);
+        if (it == custom_counters_.end()) {
+            isc_throw(BadValue,
+                      "Custom counter " << counter_key << "does not exist");
+        }
+        return(it->second);
+    }
+
+    /// \brief Increment specified counter.
+    ///
+    /// Increement counter value by one.
+    ///
+    /// \param counter_key key poitinh to the counter in the counters map.
+    /// \return pointer to specified counter after incrementation.
+    const CustomCounter& IncrementCounter(const std::string& counter_key) {
+        CustomCounterPtr counter = getCounter(counter_key);
+        return(++(*counter));
+    }
+
+    /// \brief Adds new packet to the sent packets list.
+    ///
+    /// Method adds new packet to the sent packets list.
+    /// Packets are added to the list sequentially and
+    /// most often read sequentially.
+    ///
+    /// \param xchg_type exchange type.
+    /// \param packet packet to be added to the list
+    /// \throw isc::BadValue if invalid exchange type specified or
+    /// packet is null.
+    void passSentPacket(const ExchangeType xchg_type,
+                        const boost::shared_ptr<const T>& packet) {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        xchg_stats->appendSent(packet);
+    }
+
+    /// \brief Add new received packet and match with sent packet.
+    ///
+    /// Method adds new packet to the list of received packets. It
+    /// also searches for corresponding packet on the list of sent
+    /// packets. When packets are matched the statistics counters
+    /// are updated accordingly for the particular exchange type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \param packet received packet
+    /// \throw isc::BadValue if invalid exchange type specified
+    /// or packet is null.
+    /// \throw isc::Unexpected if corresponding packet was not
+    /// found on the list of sent packets.
+    void passRcvdPacket(const ExchangeType xchg_type,
+                        const boost::shared_ptr<const T>& packet) {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        boost::shared_ptr<const T> sent_packet
+            = xchg_stats->matchPackets(packet);
+
+        if (sent_packet) {
+            xchg_stats->updateDelays(sent_packet, packet);
+            if (archive_enabled_) {
+                xchg_stats->appendRcvd(packet);
+            }
+        }
+    }
+
+    /// \brief Return minumum delay between sent and received packet.
+    ///
+    /// Method returns minimum delay between sent and received packet
+    /// for specified exchange type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return minimum delay between packets.
+    double getMinDelay(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getMinDelay());
+    }
+
+    /// \brief Return maxmimum delay between sent and received packet.
+    ///
+    /// Method returns maximum delay between sent and received packet
+    /// for specified exchange type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return maximum delay between packets.
+    double getMaxDelay(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getMaxDelay());
+    }
+
+    /// \brief Return avarage packet delay.
+    ///
+    /// Method returns average packet delay for specified
+    /// exchange type.
+    ///
+    /// \return average packet delay.
+    double getAvgDelay(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getAvgDelay());
+    }
+
+    /// \brief Return standard deviation of packet delay.
+    ///
+    /// Method returns standard deviation of packet delay
+    /// for specified exchange type.
+    ///
+    /// \return standard deviation of packet delay.
+    double getStdDevDelay(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getStdDevDelay());
+    }
+
+    /// \brief Return number of orphant packets.
+    ///
+    /// Method returns number of orphant packets for specified
+    /// exchange type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return number of orphant packets so far.
+    uint64_t getOrphans(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getOrphans());
+    }
+
+    /// \brief Return average unordered lookup set size.
+    ///
+    /// Method returns average unordered lookup set size.
+    /// This value changes every time \ref ExchangeStats::matchPackets
+    /// function performs unordered packet lookup.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return average unordered lookup set size.
+    double getAvgUnorderedLookupSetSize(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getAvgUnorderedLookupSetSize());
+    }
+
+    /// \brief Return number of unordered sent packets lookups
+    ///
+    /// Method returns number of unordered sent packet lookups.
+    /// Unordered lookup is used when received packet was sent
+    /// out of order by server - transaction id of received
+    /// packet does not match transaction id of next sent packet.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return number of unordered lookups.
+    uint64_t getUnorderedLookups(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getUnorderedLookups());
+    }
+
+    /// \brief Return number of ordered sent packets lookups
+    ///
+    /// Method returns number of ordered sent packet lookups.
+    /// Ordered lookup is used when packets are received in the
+    /// same order as they were sent to the server.
+    /// If packets are skipped or received out of order, lookup
+    /// function will use unordered lookup (with hash table).
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return number of ordered lookups.
+    uint64_t getOrderedLookups(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getOrderedLookups());
+    }
+
+    /// \brief Return total number of sent packets
+    ///
+    /// Method returns total number of sent packets for specified
+    /// exchange type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return number of sent packets.
+    uint64_t getSentPacketsNum(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getSentPacketsNum());
+    }
+
+    /// \brief Return total number of received packets
+    ///
+    /// Method returns total number of received packets for specified
+    /// exchange type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return number of received packets.
+    uint64_t getRcvdPacketsNum(const ExchangeType xchg_type) const {
+        ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type);
+        return(xchg_stats->getRcvdPacketsNum());
+    }
+
+    /// \brief Return name of the exchange.
+    ///
+    /// Method returns name of the specified exchange type.
+    /// This function is mainly for logging purposes.
+    ///
+    /// \param xchg_type exchange type.
+    /// \return string representing name of the exchange.
+    std::string exchangeToString(ExchangeType xchg_type) const {
+        switch(xchg_type) {
+        case XCHG_DO:
+            return("DISCOVER-OFFER");
+        case XCHG_RA:
+            return("REQUEST-ACK");
+        case XCHG_SA:
+            return("SOLICIT-ADVERTISE");
+        case XCHG_RR:
+            return("REQUEST-REPLY");
+        default:
+            return("Unknown exchange type");
+        }
+    }
+
+   /// \brief Print statistics counters for all exchange types.
+    ///
+    /// Method prints statistics for all exchange types.
+    /// Statistics includes:
+    /// - number of sent and received packets
+    /// - number of dropped packets and number of orphans
+    /// - minimum packets delay,
+    /// - average packets delay,
+    /// - maximum packets delay,
+    /// - standard deviation of packets delay.
+    ///
+    /// \throw isc::InvalidOperation if no exchange type added to
+    /// track statistics.
+     void printStats() const {
+        if (exchanges_.size() == 0) {
+            isc_throw(isc::InvalidOperation,
+                      "no exchange type added for tracking");
+        }
+        for (ExchangesMapIterator it = exchanges_.begin();
+             it != exchanges_.end();
+             ++it) {
+            ExchangeStatsPtr xchg_stats = it->second;
+            std::cout << "***Statistics for: " << exchangeToString(it->first)
+                      << "***" << std::endl;
+            xchg_stats->printMainStats();
+            std::cout << std::endl;
+            xchg_stats->printRTTStats();
+            std::cout << std::endl;
+        }
+    }
+
+    /// \brief Print timestamps of all packets.
+    ///
+    /// Method prints timestamps of all sent and received
+    /// packets for all defined exchange types.
+    ///
+    /// \throw isc::InvalidOperation if one of the packets has
+    /// no timestamp value set or if packets archive mode is
+    /// disabled.
+    ///
+    /// \throw isc::InvalidOperation if no exchange type added to
+    /// track statistics or packets archive mode is disabled.
+    void printTimestamps() const {
+        if (exchanges_.size() == 0) {
+            isc_throw(isc::InvalidOperation,
+                      "no exchange type added for tracking");
+        }
+        for (ExchangesMapIterator it = exchanges_.begin();
+             it != exchanges_.end();
+             ++it) {
+            ExchangeStatsPtr xchg_stats = it->second;
+            std::cout << "***Timestamps for packets: "
+                      << exchangeToString(it->first)
+                      << "***" << std::endl;
+            xchg_stats->printTimestamps();
+            std::cout << std::endl;
+        }
+    }
+
+    /// \brief Print names and values of custom counters.
+    ///
+    /// Method prints names and values of custom counters. Custom counters
+    /// are defined by client class for tracking different statistics.
+    ///
+    /// \throw isc::InvalidOperation if no custom counters added for tracking.
+    void printCustomCounters() const {
+        if (custom_counters_.size() == 0) {
+            isc_throw(isc::InvalidOperation, "no custom counters specified");
+        }
+        for (CustomCountersMapIterator it = custom_counters_.begin();
+             it != custom_counters_.end();
+             ++it) {
+            CustomCounterPtr counter = it->second;
+            std::cout << counter->getName() << ": " << counter->getValue()
+                      << std::endl;
+        }
+    }
+
+private:
+
+    /// \brief Return exchange stats object for given exchange type
+    ///
+    /// Method returns exchange stats object for given exchange type.
+    ///
+    /// \param xchg_type exchange type.
+    /// \throw isc::BadValue if invalid exchange type specified.
+    /// \return exchange stats object.
+    ExchangeStatsPtr getExchangeStats(const ExchangeType xchg_type) const {
+        ExchangesMapIterator it = exchanges_.find(xchg_type);
+        if (it == exchanges_.end()) {
+            isc_throw(BadValue, "Packets exchange not specified");
+        }
+        ExchangeStatsPtr xchg_stats = it->second;
+        return(xchg_stats);
+    }
+
+    ExchangesMap exchanges_;            ///< Map of exchange types.
+    CustomCountersMap custom_counters_; ///< Map with custom counters.
+
+    /// Indicates that packets from list of sent packets should be
+    /// archived (moved to list of archived packets) once they are
+    /// matched with received packets. This is required when it has
+    /// been selected from the command line to print packets'
+    /// timestamps after test. This may affect performance and
+    /// consume large amount of memory when the test is running
+    /// for extended period of time and many packets have to be
+    /// archived.
+    bool archive_enabled_;
+};
+
+} // namespace perfdhcp
+} // namespace isc
+
+#endif // __STATS_MGR_H
diff --git a/tests/tools/perfdhcp/tests/Makefile.am b/tests/tools/perfdhcp/tests/Makefile.am
index ec1b403..16e1842 100644
--- a/tests/tools/perfdhcp/tests/Makefile.am
+++ b/tests/tools/perfdhcp/tests/Makefile.am
@@ -21,6 +21,7 @@ run_unittests_SOURCES += command_options_unittest.cc
 run_unittests_SOURCES += perf_pkt6_unittest.cc
 run_unittests_SOURCES += perf_pkt4_unittest.cc
 run_unittests_SOURCES += localized_option_unittest.cc
+run_unittests_SOURCES += stats_mgr_unittest.cc
 run_unittests_SOURCES += $(top_builddir)/tests/tools/perfdhcp/command_options.cc
 run_unittests_SOURCES += $(top_builddir)/tests/tools/perfdhcp/pkt_transform.cc
 run_unittests_SOURCES += $(top_builddir)/tests/tools/perfdhcp/perf_pkt6.cc
diff --git a/tests/tools/perfdhcp/tests/stats_mgr_unittest.cc b/tests/tools/perfdhcp/tests/stats_mgr_unittest.cc
new file mode 100644
index 0000000..2233847
--- /dev/null
+++ b/tests/tools/perfdhcp/tests/stats_mgr_unittest.cc
@@ -0,0 +1,450 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <boost/shared_ptr.hpp>
+
+#include <exceptions/exceptions.h>
+#include <dhcp/dhcp4.h>
+#include <dhcp/dhcp6.h>
+#include <dhcp/pkt4.h>
+#include <dhcp/pkt6.h>
+
+#include <gtest/gtest.h>
+
+#include "../stats_mgr.h"
+
+using namespace std;
+using namespace isc;
+using namespace isc::dhcp;
+using namespace isc::perfdhcp;
+
+namespace {
+
+typedef StatsMgr<dhcp::Pkt4> StatsMgr4;
+typedef StatsMgr<dhcp::Pkt6> StatsMgr6;
+
+const uint32_t common_transid = 123;
+
+class StatsMgrTest : public ::testing::Test {
+public:
+    StatsMgrTest() {
+    }
+
+    /// \brief Create DHCPv4 packet.
+    ///
+    /// Method creates DHCPv4 packet and updates its timestamp.
+    ///
+    /// \param msg_type DHCPv4 message type.
+    /// \param transid transaction id for the packet.
+    /// \return DHCPv4 packet.
+    Pkt4* createPacket4(const uint8_t msg_type,
+                        const uint32_t transid) {
+        Pkt4* pkt = new Pkt4(msg_type, transid);
+        // Packet timestamp is normally updated by interface
+        // manager on packets reception or send. Unit tests
+        // do not use interface manager so we need to do it
+        // ourselfs.
+        pkt->updateTimestamp();
+        return pkt;
+    }
+
+    /// \brief Create DHCPv6 packet.
+    ///
+    /// Method creates DHCPv6 packet and updates its timestamp.
+    ///
+    /// \param msg_type DHCPv6 message type.
+    /// \param transid transaction id.
+    /// \return DHCPv6 packet.
+    Pkt6* createPacket6(const uint8_t msg_type,
+                        const uint32_t transid) {
+        Pkt6* pkt = new Pkt6(msg_type, transid);
+        // Packet timestamp is normally updated by interface
+        // manager on packets reception or send. Unit tests
+        // do not use interface manager so we need to do it
+        // ourselfs.
+        pkt->updateTimestamp();
+        return pkt;
+    }
+
+    /// \brief Pass multiple DHCPv6 packets to Statistics Manager.
+    ///
+    /// Method simulates sending or receiving  multiple DHCPv6 packets.
+    ///
+    /// \param stats_mgr Statistics Manager instance to be used.
+    /// \param xchg_type packet exchange types.
+    /// \param packet_type DHCPv6 packet type.
+    /// \param num_packets packets to be passed to Statistics Manager.
+    /// \param receive simulated packets are received (if true)
+    /// or sent (if false)
+    void passMultiplePackets6(const boost::shared_ptr<StatsMgr6> stats_mgr,
+                              const StatsMgr6::ExchangeType xchg_type,
+                              const uint8_t packet_type,
+                              const int num_packets,
+                              const bool receive = false) {
+        for (int i = 0; i < num_packets; ++i) {
+            boost::shared_ptr<Pkt6>
+                packet(createPacket6(packet_type, i));
+
+            if (receive) {
+                ASSERT_NO_THROW(
+                    stats_mgr->passRcvdPacket(xchg_type, packet);
+                );
+            } else {
+                ASSERT_NO_THROW(
+                    stats_mgr->passSentPacket(xchg_type, packet)
+                );
+            }
+        }
+    }
+
+    /// \brief Simulate DHCPv4 DISCOVER-OFFER with delay.
+    ///
+    /// Method simulates DHCPv4 DISCOVER-OFFER exchange. The OFFER packet
+    /// creation is delayed by the specified number of seconds. This imposes
+    /// different packet timestamps and affects delay counters in Statistics
+    /// Manager.
+    ///
+    /// \param stats_mgr Statistics Manager instance.
+    /// \param delay delay in seconds between DISCOVER and OFFER packets.
+    void passDOPacketsWithDelay(const boost::shared_ptr<StatsMgr4> stats_mgr,
+                                unsigned int delay,
+                                uint32_t transid) {
+        boost::shared_ptr<Pkt4> sent_packet(createPacket4(DHCPDISCOVER,
+                                                      transid));
+        ASSERT_NO_THROW(
+            stats_mgr->passSentPacket(StatsMgr4::XCHG_DO, sent_packet)
+        );
+
+        // There is way to differentiate timstamps of two packets other than
+        // sleep for before we create another packet. Packet is using current
+        // time to update its timestamp.
+        // Sleeping for X seconds will guarantee that delay between packets
+        // will be greater than 1 second. Note that posix time value is
+        // transformed to double value and it makes it hard to determine
+        // actual value to expect.
+        std::cout << "Sleeping for " << delay << "s to test packet delays"
+                  << std::endl;
+        sleep(delay);
+
+        boost::shared_ptr<Pkt4> rcvd_packet(createPacket4(DHCPOFFER,
+                                                      transid));
+        ASSERT_NO_THROW(
+            stats_mgr->passRcvdPacket(StatsMgr4::XCHG_DO, rcvd_packet);
+        );
+
+        // Calculate period between packets.
+        boost::posix_time::ptime sent_time = sent_packet->getTimestamp();
+        boost::posix_time::ptime rcvd_time = rcvd_packet->getTimestamp();
+
+        ASSERT_FALSE(sent_time.is_not_a_date_time());
+        ASSERT_FALSE(rcvd_time.is_not_a_date_time());
+    }
+
+};
+
+TEST_F(StatsMgrTest, Constructor) {
+    boost::scoped_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
+    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
+    EXPECT_DOUBLE_EQ(
+        std::numeric_limits<double>::max(),
+        stats_mgr->getMinDelay(StatsMgr4::XCHG_DO)
+    );
+    EXPECT_DOUBLE_EQ(0, stats_mgr->getMaxDelay(StatsMgr4::XCHG_DO));
+    EXPECT_EQ(0, stats_mgr->getOrphans(StatsMgr4::XCHG_DO));
+    EXPECT_EQ(0, stats_mgr->getOrderedLookups(StatsMgr4::XCHG_DO));
+    EXPECT_EQ(0, stats_mgr->getUnorderedLookups(StatsMgr4::XCHG_DO));
+    EXPECT_EQ(0, stats_mgr->getSentPacketsNum(StatsMgr4::XCHG_DO));
+    EXPECT_EQ(0, stats_mgr->getRcvdPacketsNum(StatsMgr4::XCHG_DO));
+
+    EXPECT_THROW(stats_mgr->getAvgDelay(StatsMgr4::XCHG_DO), InvalidOperation);
+    EXPECT_THROW(stats_mgr->getStdDevDelay(StatsMgr4::XCHG_DO),
+                 InvalidOperation);
+    EXPECT_THROW(stats_mgr->getAvgUnorderedLookupSetSize(StatsMgr4::XCHG_DO),
+                 InvalidOperation);
+}
+
+TEST_F(StatsMgrTest, Exchange) {
+    boost::scoped_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
+    boost::shared_ptr<Pkt4> sent_packet(createPacket4(DHCPDISCOVER,
+                                                      common_transid));
+    boost::shared_ptr<Pkt4> rcvd_packet(createPacket4(DHCPOFFER,
+                                                      common_transid));
+    // This is expected to throw because XCHG_DO was not yet
+    // added to Stats Manager for tracking.
+    EXPECT_THROW(
+        stats_mgr->passSentPacket(StatsMgr4::XCHG_DO, sent_packet),
+        BadValue
+    );
+    EXPECT_THROW(
+        stats_mgr->passRcvdPacket(StatsMgr4::XCHG_DO, rcvd_packet),
+        BadValue
+    );
+
+    // Adding DISCOVER-OFFER exchanges to be tracked by Stats Manager.
+    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
+    // The following two attempts are expected to throw because
+    // invalid exchange types are passed (XCHG_RA instead of XCHG_DO)
+    EXPECT_THROW(
+        stats_mgr->passSentPacket(StatsMgr4::XCHG_RA, sent_packet),
+        BadValue
+    );
+    EXPECT_THROW(
+        stats_mgr->passRcvdPacket(StatsMgr4::XCHG_RA, rcvd_packet),
+        BadValue
+    );
+
+    // The following two attempts are expected to run fine because
+    // right exchange type is specified.
+    EXPECT_NO_THROW(
+        stats_mgr->passSentPacket(StatsMgr4::XCHG_DO, sent_packet)
+    );
+    EXPECT_NO_THROW(
+        stats_mgr->passRcvdPacket(StatsMgr4::XCHG_DO, rcvd_packet)
+    );
+}
+
+TEST_F(StatsMgrTest, MultipleExchanges) {
+    boost::shared_ptr<StatsMgr6> stats_mgr(new StatsMgr6());
+    stats_mgr->addExchangeStats(StatsMgr6::XCHG_SA);
+    stats_mgr->addExchangeStats(StatsMgr6::XCHG_RR);
+
+    // Simulate sending number of solicit packets.
+    const int solicit_packets_num = 10;
+    passMultiplePackets6(stats_mgr, StatsMgr6::XCHG_SA, DHCPV6_SOLICIT,
+                         solicit_packets_num);
+
+    // Simulate sending number of request packets. It is important that
+    // number of request packets is different then number of solicit
+    // packets. We can now check if right number packets went to
+    // the right exchange type group.
+    const int request_packets_num = 5;
+    passMultiplePackets6(stats_mgr, StatsMgr6::XCHG_RR, DHCPV6_REQUEST,
+                         request_packets_num);
+
+    // Check if all packets are successfuly passed to packet lists.
+    EXPECT_EQ(solicit_packets_num,
+              stats_mgr->getSentPacketsNum(StatsMgr6::XCHG_SA));
+    EXPECT_EQ(request_packets_num,
+              stats_mgr->getSentPacketsNum(StatsMgr6::XCHG_RR));
+
+    // Simulate reception of multiple packets for both SOLICIT-ADVERTISE
+    // and REQUEST-REPLY exchanges. Assume no packet drops.
+    const bool receive_packets = true;
+    passMultiplePackets6(stats_mgr, StatsMgr6::XCHG_SA, DHCPV6_ADVERTISE,
+                         solicit_packets_num, receive_packets);
+
+    passMultiplePackets6(stats_mgr, StatsMgr6::XCHG_RR, DHCPV6_REPLY,
+                         request_packets_num, receive_packets);
+
+    // Verify that all received packets are counted.
+    EXPECT_EQ(solicit_packets_num,
+              stats_mgr->getRcvdPacketsNum(StatsMgr6::XCHG_SA));
+    EXPECT_EQ(request_packets_num,
+              stats_mgr->getRcvdPacketsNum(StatsMgr6::XCHG_RR));
+}
+
+TEST_F(StatsMgrTest, SendReceiveSimple) {
+    boost::scoped_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
+    boost::shared_ptr<Pkt4> sent_packet(createPacket4(DHCPDISCOVER,
+                                                      common_transid));
+    boost::shared_ptr<Pkt4> rcvd_packet(createPacket4(DHCPOFFER,
+                                                      common_transid));
+    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
+    // The following attempt is expected to pass becase the right
+    // exchange type is used.
+    ASSERT_NO_THROW(
+        stats_mgr->passSentPacket(StatsMgr4::XCHG_DO, sent_packet)
+    );
+    // It is ok, to pass to received packets here. First one will
+    // be matched with sent packet. The latter one will not be
+    // matched with sent packet but orphans counter will simply
+    // increase.
+    ASSERT_NO_THROW(
+        stats_mgr->passRcvdPacket(StatsMgr4::XCHG_DO, rcvd_packet)
+    );
+    ASSERT_NO_THROW(
+        stats_mgr->passRcvdPacket(StatsMgr4::XCHG_DO, rcvd_packet)
+    );
+    EXPECT_EQ(1, stats_mgr->getOrphans(StatsMgr4::XCHG_DO));
+}
+
+TEST_F(StatsMgrTest, SendReceiveUnordered) {
+    const int packets_num = 10;
+    boost::scoped_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
+    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
+
+    // Transaction ids of 10 packets to be sent and received.
+    uint32_t transid[packets_num] =
+        { 1, 1024, 2, 1025, 3, 1026, 4, 1027, 5, 1028 };
+    for (int i = 0; i < packets_num; ++i) {
+        boost::shared_ptr<Pkt4> sent_packet(createPacket4(DHCPDISCOVER,
+                                                          transid[i]));
+        ASSERT_NO_THROW(
+            stats_mgr->passSentPacket(StatsMgr4::XCHG_DO, sent_packet)
+        );
+    }
+
+    // We are simulating that received packets are coming in reverse order:
+    // 1028, 5, 1027 ....
+    for (int i = 0; i < packets_num; ++i) {
+        boost::shared_ptr<Pkt4>
+            rcvd_packet(createPacket4(DHCPDISCOVER,
+                                      transid[packets_num - 1 - i]));
+        ASSERT_NO_THROW(
+            stats_mgr->passRcvdPacket(StatsMgr4::XCHG_DO, rcvd_packet);
+        );
+    }
+    // All packets are expected to match (we did not drop any)
+    EXPECT_EQ(0, stats_mgr->getOrphans(StatsMgr4::XCHG_DO));
+    // Most of the time we have to do unordered lookups except for the last
+    // one. Packets are removed from the sent list every time we have a match
+    // so eventually we come up with the single packet that caching iterator
+    // is pointing to. This is counted as ordered lookup.
+    EXPECT_EQ(1, stats_mgr->getOrderedLookups(StatsMgr4::XCHG_DO));
+    EXPECT_EQ(9, stats_mgr->getUnorderedLookups(StatsMgr4::XCHG_DO));
+}
+
+TEST_F(StatsMgrTest, Orphans) {
+    const int packets_num = 6;
+    boost::scoped_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
+    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
+
+    // We skip every second packet to simulate drops.
+    for (int i = 0; i < packets_num; i += 2) {
+        boost::shared_ptr<Pkt4> sent_packet(createPacket4(DHCPDISCOVER, i));
+        ASSERT_NO_THROW(
+            stats_mgr->passSentPacket(StatsMgr4::XCHG_DO, sent_packet)
+        );
+    }
+    // We pass all received packets.
+    for (int i = 0; i < packets_num; ++i) {
+        boost::shared_ptr<Pkt4> rcvd_packet(createPacket4(DHCPOFFER, i));
+        ASSERT_NO_THROW(
+            stats_mgr->passRcvdPacket(StatsMgr4::XCHG_DO, rcvd_packet);
+        );
+    }
+    // The half of received packets are expected not to have matching
+    // sent packet.
+    EXPECT_EQ(packets_num / 2, stats_mgr->getOrphans(StatsMgr4::XCHG_DO));
+}
+
+TEST_F(StatsMgrTest, Delays) {
+
+    boost::shared_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
+    stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
+
+    // Send DISCOVER, wait 2s and receive OFFER. This will affect
+    // counters in Stats Manager.
+    const unsigned int delay1 = 2;
+    passDOPacketsWithDelay(stats_mgr, 2, common_transid);
+
+    // Initially min delay is equal to MAX_DOUBLE. After first packets
+    // are passed, it is expected to set to actual value.
+    EXPECT_LT(stats_mgr->getMinDelay(StatsMgr4::XCHG_DO),
+              std::numeric_limits<double>::max());
+    EXPECT_GT(stats_mgr->getMinDelay(StatsMgr4::XCHG_DO), 1);
+
+    // Max delay is supposed to the same value as mininimum
+    // or maximum delay.
+    EXPECT_GT(stats_mgr->getMaxDelay(StatsMgr4::XCHG_DO), 1);
+
+    // Delay sums are now the same as minimum or maximum delay.
+    EXPECT_GT(stats_mgr->getAvgDelay(StatsMgr4::XCHG_DO), 1);
+
+    // Simulate another DISCOVER-OFFER exchange with delay between
+    // sent and received packets. Delay is now shorter than earlier
+    // so standard deviation of delay will now increase.
+    const unsigned int delay2 = 1;
+    passDOPacketsWithDelay(stats_mgr, delay2, common_transid + 1);
+    // Standard deviation is expected to be non-zero.
+    EXPECT_GT(stats_mgr->getStdDevDelay(StatsMgr4::XCHG_DO), 0);
+}
+
+TEST_F(StatsMgrTest, CustomCounters) {
+    boost::scoped_ptr<StatsMgr4> stats_mgr(new StatsMgr4());
+
+    // Specify counter keys and names.
+    const std::string too_short_key("tooshort");
+    const std::string too_short_name("Too short packets");
+    const std::string too_late_key("toolate");
+    const std::string too_late_name("Packets sent too late");
+
+    // Add two custom counters.
+    stats_mgr->addCustomCounter(too_short_key, too_short_name);
+    stats_mgr->addCustomCounter(too_late_key, too_late_name);
+
+    // Increment one of the counters 10 times.
+    const uint64_t tooshort_num = 10;
+    for (uint64_t i = 0; i < tooshort_num; ++i) {
+        stats_mgr->IncrementCounter(too_short_key);
+    }
+
+    // Increment another counter by 5 times.
+    const uint64_t toolate_num = 5;
+    for (uint64_t i = 0; i < toolate_num; ++i) {
+        stats_mgr->IncrementCounter(too_late_key);
+    }
+
+    // Check counter's current value and name.
+    StatsMgr4::CustomCounterPtr tooshort_counter =
+        stats_mgr->getCounter(too_short_key);
+    EXPECT_EQ(too_short_name, tooshort_counter->getName());
+    EXPECT_EQ(tooshort_num, tooshort_counter->getValue());
+
+    // Check counter's current value and name.
+    StatsMgr4::CustomCounterPtr toolate_counter =
+        stats_mgr->getCounter(too_late_key);
+    EXPECT_EQ(too_late_name, toolate_counter->getName());
+    EXPECT_EQ(toolate_num, toolate_counter->getValue());
+
+}
+
+TEST_F(StatsMgrTest, PrintStats) {
+    std::cout << "This unit test is checking statistics printing "
+              << "capabilities. It is expected that some counters "
+              << "will be printed during this test. It may also "
+              << "cause spurious errors." << std::endl;
+    boost::shared_ptr<StatsMgr6> stats_mgr(new StatsMgr6());
+    stats_mgr->addExchangeStats(StatsMgr6::XCHG_SA);
+
+    // Simulate sending and receiving one packet. Otherwise printing
+    // functions will complain about lack of packets.
+    const int packets_num = 1;
+    passMultiplePackets6(stats_mgr, StatsMgr6::XCHG_SA, DHCPV6_SOLICIT,
+                         packets_num);
+    passMultiplePackets6(stats_mgr, StatsMgr6::XCHG_SA, DHCPV6_ADVERTISE,
+                         packets_num, true);
+
+    // This function will print statistics even if packets are not
+    // archived because it relies on counters. There is at least one
+    // exchange needed to count the average delay and std deviation.
+    EXPECT_NO_THROW(stats_mgr->printStats());
+
+    // Printing timestamps is expected to fail because by default we
+    // disable packets archiving mode. Without packets we can't get
+    // timestamps.
+    EXPECT_THROW(stats_mgr->printTimestamps(), isc::InvalidOperation);
+
+    // Now, we create another statistics manager instance and enable
+    // packets archiving mode.
+    const bool archive_packets = true;
+    boost::shared_ptr<StatsMgr6> stats_mgr2(new StatsMgr6(archive_packets));
+    stats_mgr2->addExchangeStats(StatsMgr6::XCHG_SA);
+
+    // Timestamps should now get printed because packets have been preserved.
+    EXPECT_NO_THROW(stats_mgr2->printTimestamps());
+}
+
+
+}



More information about the bind10-changes mailing list