test_control.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef __TEST_CONTROL_H
  15. #define __TEST_CONTROL_H
  16. #include <string>
  17. #include <vector>
  18. #include <boost/noncopyable.hpp>
  19. #include <boost/date_time/posix_time/posix_time.hpp>
  20. #include <dhcp/pkt4.h>
  21. #include <dhcp/pkt6.h>
  22. namespace isc {
  23. namespace perfdhcp {
  24. /// \brief Test Control class.
  25. ///
  26. /// This class is responsible for running whole perfdhcp test.
  27. ///
  28. class TestControl : public boost::noncopyable {
  29. public:
  30. /// TestControl is a singleton class. This method returns reference
  31. /// to its sole instance.
  32. ///
  33. /// \return the only existing instance of test control
  34. static TestControl& instance();
  35. /// Run performance test.
  36. ///
  37. /// Method runs whole performance test. Command line options must
  38. /// be parsed prior to running this function. Othewise function will
  39. /// throw exception.
  40. ///
  41. /// \throw isc::InvalidOperation if command line options are not parsed.
  42. /// \throw isc::Unexpected if internal Test Controler error occured.
  43. void run();
  44. private:
  45. /// \brief Private default constructor.
  46. ///
  47. /// Default constructor is private as the object can be created
  48. /// only via \ref instance method.
  49. TestControl();
  50. /// \brief Check if test exit condtitions fulfiled.
  51. ///
  52. /// Method checks if test exit conditions are fulfiled.
  53. /// Exit conditions are checked periodically from the
  54. /// main loop. Program should break the main loop when
  55. /// this method returns true. It is calling function
  56. /// responsibility to break main loop gracefully and
  57. /// cleanup after test execution.
  58. ///
  59. /// \return true if any of the exit conditions is fulfiled.
  60. bool checkExitConditions() const;
  61. dhcp::Pkt4* createDiscoverPkt4();
  62. static dhcp::OptionPtr factoryRequestList4(dhcp::Option::Universe u,
  63. uint16_t type,
  64. const dhcp::OptionBuffer& buf);
  65. /// \brief Returns number of exchanges to be started.
  66. ///
  67. /// Method returns number of new exchanges to be started as soon
  68. /// as possible to satisfy expected rate. Calculation used here
  69. /// is based on current time, due time calculated with
  70. /// \ref updateSendTime function and expected rate.
  71. ///
  72. /// \return number of exchanges to be started immediatelly.
  73. uint64_t getNextExchangesNum() const;
  74. void registerOptionFactories4() const;
  75. void registerOptionFactories6() const;
  76. void registerOptionFactories() const;
  77. /// \brief Start new exchange of DHCP messages.
  78. ///
  79. void startExchange();
  80. /// \brief Update due time to initiate next chunk of exchanges.
  81. ///
  82. /// Method updates due time to initiate next chunk of exchanges.
  83. /// Function takes current time, last sent packet's time and
  84. /// expected rate in its calculations.
  85. void updateSendDue();
  86. boost::posix_time::ptime send_due_; ///< Due time to initiate next chunk
  87. ///< of exchanges.
  88. boost::posix_time::ptime last_sent_; ///< Indicates when the last exchange
  89. /// was initiated.
  90. uint64_t sent_packets_0_;
  91. uint64_t sent_packets_1_;
  92. };
  93. } // namespace perfdhcp
  94. } // namespace isc
  95. #endif // __COMMAND_OPTIONS_H