perfdhcp_internals.dox 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. /// @namespace perfdhcp
  15. /// @page perfdhcpInternals perfdhcp Internals
  16. ///
  17. /// The perfdhcp utility provides a way of measuring the performance of
  18. /// DHCP servers by generating large amounts of traffic. Written in C++,
  19. /// its use is described in detail in the DHCP Performance Guide.
  20. ///
  21. /// This document is aimed at people wishing to understand the internals
  22. /// of the perfdhcp program. It describes the major components in the
  23. /// utility and their interaction.
  24. ///
  25. /// @section perfdhcpClasses perfdhcp Classes
  26. ///
  27. /// @subsection perfdhcpCommandOptions CommandOptions (Command Options)
  28. ///
  29. /// isc::perfdhcp::CommandOptions is a singleton class that parses
  30. /// the perfdhcp command line parameters and initializes its members
  31. /// accordingly. If the parameters are invalid, the parser method throws
  32. /// an exception. Usage is simple:
  33. ///
  34. /// @code int main(int argc, char* argv[]) {
  35. /// try {
  36. /// CommandOptions& command_options = CommandOptions::instance();
  37. /// command_options.parse(argc, argv);
  38. /// } catch(const Exception& e) {
  39. /// ...
  40. /// }
  41. /// @endcode
  42. ///
  43. /// If the argument parsing is successful, the parsed values can be read
  44. /// from the isc::perfdhcp::CommandOptions singleton from any class or
  45. /// function in the program, e.g.
  46. ///
  47. /// @code
  48. /// int rate = CommandOptions::instance().getRate();
  49. /// @endcode
  50. ///
  51. /// @subsection perfdhcpTestControl TestControl (Test Control)
  52. ///
  53. /// The isc::perfdhcp::TestControl singleton is responsible
  54. /// for test execution coordination. It relies on the
  55. /// isc::perfdhcp::CommandOptions object to get all required test
  56. /// parameters and for this reason, isc::perfdhcp::CommandOptions has
  57. /// to be initialized and isc::perfdhcp::CommandOptions::parse() called
  58. /// prior to calling isc::perfdhcp::TestControl::run().
  59. ///
  60. /// isc::perfdhcp::TestControl::run() performs initialization of
  61. /// isc::perfdhcp::TestControl then executes the main program loop. In
  62. /// detail, isc::perfdhcp::TestControl::run() performs the following
  63. /// major operations:
  64. ///
  65. /// -# check if the command line has been parsed,
  66. /// -# print diagnostics if specified from command line,
  67. /// -# register DHCP options factory functions,
  68. /// -# read packet templates from files,
  69. /// -# initialize the isc::perfdhcp::StatisticsManager object,
  70. /// -# set interrupt signal handler (handle ^C),
  71. /// -# open and close socket for communication with server,
  72. /// -# coordinate sending and receiving packets,
  73. /// -# coordinate intermediate reporting,
  74. /// -# prints test statistics.
  75. ///
  76. /// isc::perfdhcp::TestControl is a singleton object, so there is one sole
  77. /// instance of it throughout the program. In order to allow the running
  78. /// of unit tests, where a single instance of isc::perfdhcp::TestControl
  79. /// is used multiple times with different command line options, a
  80. /// isc::perfdhcp::TestControl::reset() function is provided to reset
  81. /// the state of the class members. Also, functions that initialize
  82. /// various class members (such as Statistics Manager) will release
  83. /// any objects from previous test runs.
  84. ///
  85. /// @subsection perfStatsMgr StatsMgr (Statistics Manager)
  86. ///
  87. /// isc::perfdhcp::StatsMgr is a class that holds all performance
  88. /// statistics gathered throughout the test execution and is created
  89. /// in isc::perfdhcp::TestControl. isc::perfdhcp::TestControl posts all
  90. /// sent and received packets to isc::perfdhcp::StatsMgr: outgoing packets
  91. /// are recorded and incoming packets are matched with the corresponding
  92. /// outgoing packer to calculate calculate round trip time, number of
  93. /// packet drops etc. Apart from the standard counters implemented in
  94. /// isc::perfdhcp::StatsMgr, custom (named) counters can be specified and
  95. /// incremented by the calling class. isc::perfdhcp::StatsMgr also exposes
  96. /// multiple functions that print gathered statistics into the console.
  97. ///
  98. /// isc::perfdhcp::StatsMgr is a template class that takes an
  99. /// isc::dhcp::Pkt4, isc::dhcp::Pkt6, isc::perfdhcp::PerfPkt4
  100. /// or isc::perfdhcp::PerfPkt6 as a typename. An instance of
  101. /// isc::perfdhcp::StatsMgr can be created by:
  102. ///
  103. /// @code
  104. /// typedef StatsMgr<Pkt4> StatsMgr4; StatsMgr4 stats_mgr4 =
  105. /// boost::shared_ptr<StatsMgr4>(new StatsMgr4()); try {
  106. /// stats_mgr->addExchangeStats(StatsMgr4::XCHG_DO);
  107. /// } catch(const Exception& e) {
  108. /// std::cout << e.what() << std::endl;
  109. /// }
  110. /// @endcode
  111. ///
  112. /// The isc::perfdhcp::StatsMgr instance created in the example above will be used
  113. /// for DHCPv4 testing (i.e. to collect DHCPv4 packets) and will be
  114. /// configured to monitor statistics for DISCOVER-OFFER packet exchanges.
  115. ///
  116. /// @subsection perfdhcpPkt PerfPkt4 and PerfPkt6
  117. ///
  118. /// The isc::perfdhcp::PerfPkt4 and isc::perfdhcp::PerfPkt6 classes
  119. /// are derived from isc::dhcp::Pkt4 and isc::dhcp::Pkt6. They extend
  120. /// the parent class functionality by adding support for template
  121. /// files. Instances of these classes can be created using a raw buffer
  122. /// (read from a packet template file). Once the packet object is
  123. /// initialized, it is possible to replace parts of the on-wire data by
  124. /// using the isc::perfdhcp::LocalizedOption mechanism.
  125. ///
  126. /// @subsection perfdhcpLocalizedOption LocalizedOption (Localized Option)
  127. ///
  128. /// isc::perfdhcp::LocalizedOption derives from the isc::dhcp::Option
  129. /// class. It represents the DHCP option (v4 or v6) to be
  130. /// placed at specified position in the packet buffer (see @ref
  131. /// perfdhcpPkt). Such an option is added to the option collection in
  132. /// a isc::perfdhcp::PerfPkt4 or isc::perfdhcp::PerfPkt6 object; when
  133. /// any of PerfPktX::rawPack() functions are called their content is
  134. /// stored in the packet output buffer at the position pointed to by
  135. /// the isc::perfdhcp::LocalizedOption object.
  136. ///
  137. /// isc::perfdhcp::LocalizedOption also allows the reading of the
  138. /// on wire data in received packet at the specified position. In
  139. /// this case, isc::perfdhcp::LocalizedOption has to be created and
  140. /// added to the received packet. When PerfPktX::rawUnpack() is
  141. /// called, the contents of the buffer will be read and stored in a
  142. /// isc::perfdhcp::LocalizedOption object for further processing.
  143. ///
  144. /// The following code shows how to create a packet from a
  145. /// (template) buffer and replace option data in the buffer with
  146. /// isc::perfdhcp::LocalizedOption.
  147. ///
  148. /// @code
  149. /// OptionBuffer buf; // fill buf with data here. ...
  150. /// boost::scoped_ptr<PerfPkt4> pkt(new PerfPkt4(&buf[0], buf.size());
  151. /// const size_t offset_hostname = 240;
  152. /// OptionBuffer vec_hostname;
  153. /// // fill the hostname vector with data ...
  154. /// LocalizedOptionPtr opt_hostname(new LocalizedOption(Option::V4,
  155. /// DHO_HOST_NAME,
  156. /// vec_hostname,
  157. /// offset_hostname));
  158. /// pkt->addOption(opt_hostname);
  159. /// // by calling rawPack() we replace the packet contents with option
  160. /// // contents at buffer position 240.
  161. /// pkt->rawPack();
  162. /// @endcode
  163. ///
  164. /// @subsection perfdhcpPktTransform PktTransform (Packet Transform)
  165. ///
  166. /// The isc::perfdhcp::PktTransform helper class contains the
  167. /// static functions to pack and unpack DHCP options (specifically
  168. /// isc::perfdhcp::LocalizedOption) to and from the packet buffer. This
  169. /// logic has been moved away from isc::perfdhcp::PerfPkt4 and
  170. /// isc::perfdhcp::PerfPkt6 classes to isc::perfdhcp::PktTransform
  171. /// because PerfPktX classes share the logic here.