memfile_ubench.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <string>
  15. #include <fstream>
  16. #include <vector>
  17. #include <boost/shared_ptr.hpp>
  18. #include "benchmark.h"
  19. /// @brief Structure of the Lease4 that is kept in memory
  20. struct Lease4 {
  21. uint32_t addr; /// IPv4 address
  22. std::vector<uint8_t> hwaddr; /// hardware address
  23. std::vector<uint8_t> client_id; /// client-identifier
  24. uint32_t valid_lft; /// valid lifetime timestamp
  25. uint32_t recycle_time; /// timer for keeping lease after expiration/release
  26. /// (currently not used)
  27. time_t cltt; /// client last transmission time
  28. uint32_t pool_id; /// ID of the pool the lease belongs to
  29. bool fixed; /// is this lease fixed?
  30. std::string hostname; /// client hostname (may be empty)
  31. bool fqdn_fwd; /// did we do AAAA update for this lease?
  32. bool fqdn_rev; /// did we do PTR update for this lease?
  33. std::string options; /// additional options stored with this lease
  34. /// (currently not used)
  35. std::string comments; /// comments on that lease
  36. /// (currently not used)
  37. };
  38. /// Pointer to a Lease4 structure
  39. typedef boost::shared_ptr<Lease4> Lease4Ptr;
  40. /// an implementation of in-memory+file database
  41. /// The actual implementation is in memfile_ubench.cc
  42. class memfile_LeaseMgr;
  43. /// @brief In-memory + file micro-benchmark.
  44. ///
  45. /// That is a specific backend implementation. See \ref uBenchmark class for
  46. /// detailed explanation of its operations. This class uses custom in-memory
  47. /// pseudo-database and external write-only lease file. That approach simulates
  48. /// modernized model of ISC DHCP4. It uses standard STL maps together with
  49. /// shared_ptr from boost library. The "database" is implemented in the Lease
  50. /// Manager (see \ref LeaseMgr in memfile_ubench.cc). All lease changes are
  51. /// appended to the end of the file, speeding up the process.
  52. class memfile_uBenchmark: public uBenchmark {
  53. public:
  54. /// @brief The sole memfile benchmark constructor.
  55. ///
  56. /// @param filename name of the write-only lease file
  57. /// @param num_iterations number of iterations
  58. /// @param sync should fsync() be called after every file write?
  59. /// @param verbose would you like extra logging?
  60. memfile_uBenchmark(const std::string& filename,
  61. uint32_t num_iterations, bool sync, bool verbose);
  62. /// @brief Prints backend info.
  63. virtual void printInfo();
  64. /// @brief Spawns lease manager that create empty lease file, initializes
  65. /// empty STL maps.
  66. virtual void connect();
  67. /// @brief Delete lease manager that closes lease file.
  68. virtual void disconnect();
  69. /// @brief Creates new leases.
  70. ///
  71. /// See uBenchmark::createLease4Test() for detailed explanation.
  72. virtual void createLease4Test();
  73. /// @brief Searches for existing leases.
  74. ///
  75. /// See uBenchmark::searchLease4Test() for detailed explanation.
  76. virtual void searchLease4Test();
  77. /// @brief Updates existing leases.
  78. ///
  79. /// See uBenchmark::updateLease4Test() for detailed explanation.
  80. virtual void updateLease4Test();
  81. /// @brief Deletes existing leases.
  82. ///
  83. /// See uBenchmark::deleteLease4Test() for detailed explanation.
  84. virtual void deleteLease4Test();
  85. protected:
  86. /// Lease Manager (concrete backend implementation, based on STL maps)
  87. memfile_LeaseMgr * leaseMgr_;
  88. };