generic_lease_mgr_unittest.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // Copyright (C) 2014 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 GENERIC_LEASE_MGR_UNITTEST_H
  15. #define GENERIC_LEASE_MGR_UNITTEST_H
  16. #include <dhcpsrv/lease_mgr.h>
  17. #include <gtest/gtest.h>
  18. #include <vector>
  19. namespace isc {
  20. namespace dhcp {
  21. namespace test {
  22. /// @brief Test Fixture class with utility functions for LeaseMgr backends
  23. ///
  24. /// It contains utility functions, like dummy lease creation.
  25. /// All concrete LeaseMgr test classes should be derived from it.
  26. class GenericLeaseMgrTest : public ::testing::Test {
  27. public:
  28. /// @brief Default constructor.
  29. GenericLeaseMgrTest();
  30. /// @brief Virtual destructor.
  31. virtual ~GenericLeaseMgrTest();
  32. /// @brief Reopen the database
  33. ///
  34. /// Closes the database and re-opens it. It must be implemented
  35. /// in derived classes.
  36. virtual void reopen() = 0;
  37. /// @brief Initialize Lease4 Fields
  38. ///
  39. /// Returns a pointer to a Lease4 structure. Different values are put into
  40. /// the lease according to the address passed.
  41. ///
  42. /// This is just a convenience function for the test methods.
  43. ///
  44. /// @param address Address to use for the initialization
  45. ///
  46. /// @return Lease4Ptr. This will not point to anything if the
  47. /// initialization failed (e.g. unknown address).
  48. Lease4Ptr initializeLease4(std::string address);
  49. /// @brief Initialize Lease6 Fields
  50. ///
  51. /// Returns a pointer to a Lease6 structure. Different values are put into
  52. /// the lease according to the address passed.
  53. ///
  54. /// This is just a convenience function for the test methods.
  55. ///
  56. /// @param address Address to use for the initialization
  57. ///
  58. /// @return Lease6Ptr. This will not point to anything if the initialization
  59. /// failed (e.g. unknown address).
  60. Lease6Ptr initializeLease6(std::string address);
  61. /// @brief Check Leases present and different
  62. ///
  63. /// Checks a vector of lease pointers and ensures that all the leases
  64. /// they point to are present and different. If not, a GTest assertion
  65. /// will fail.
  66. ///
  67. /// @param leases Vector of pointers to leases
  68. /// @tparam Type of the leases held in the vector: @c Lease4 or
  69. /// @c Lease6.
  70. template <typename T>
  71. void checkLeasesDifferent(const std::vector<T>& leases) const;
  72. /// @brief Creates leases for the test
  73. ///
  74. /// Creates all leases for the test and checks that they are different.
  75. ///
  76. /// @return vector<Lease4Ptr> Vector of pointers to leases
  77. std::vector<Lease4Ptr> createLeases4();
  78. /// @brief Creates leases for the test
  79. ///
  80. /// Creates all leases for the test and checks that they are different.
  81. ///
  82. /// @return vector<Lease6Ptr> Vector of pointers to leases
  83. std::vector<Lease6Ptr> createLeases6();
  84. /// @brief checks that addLease, getLease4(addr) and deleteLease() works
  85. void testBasicLease4();
  86. /// @brief Test lease retrieval using client id.
  87. void testGetLease4ClientId();
  88. /// @brief Test lease retrieval when leases with NULL client id are present.
  89. void testGetLease4NullClientId();
  90. /// @brief Test lease retrieval using HW address.
  91. void testGetLease4HWAddr1();
  92. /// @brief Check GetLease4 methods - access by Hardware Address
  93. ///
  94. /// Adds leases to the database and checks that they can be accessed using
  95. /// HWAddr information.
  96. void testGetLease4HWAddr2();
  97. /// @brief Test lease retrieval using client id, HW address and subnet id.
  98. void testGetLease4ClientIdHWAddrSubnetId();
  99. // @brief Get lease4 by hardware address (2)
  100. //
  101. // Check that the system can cope with getting a hardware address of
  102. // any size.
  103. void testGetLease4HWAddrSize();
  104. /// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
  105. ///
  106. /// Adds leases to the database and checks that they can be accessed via
  107. /// a combination of hardware address and subnet ID
  108. void testGetLease4HWAddrSubnetId();
  109. /// @brief Get lease4 by hardware address and subnet ID (2)
  110. ///
  111. /// Check that the system can cope with getting a hardware address of
  112. /// any size.
  113. void testGetLease4HWAddrSubnetIdSize();
  114. /// @brief Check GetLease4 methods - access by Client ID
  115. ///
  116. /// Adds leases to the database and checks that they can be accessed via
  117. /// the Client ID.
  118. void testGetLease4ClientId2();
  119. /// @brief Get Lease4 by client ID (2)
  120. ///
  121. /// Check that the system can cope with a client ID of any size.
  122. void testGetLease4ClientIdSize();
  123. /// @brief Check GetLease4 methods - access by Client ID & Subnet ID
  124. ///
  125. /// Adds leases to the database and checks that they can be accessed via
  126. /// a combination of client and subnet IDs.
  127. void testGetLease4ClientIdSubnetId();
  128. /// @brief Basic Lease4 Checks
  129. ///
  130. /// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
  131. /// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id.
  132. /// (client-id is optional and may not be present)
  133. ///
  134. /// @todo: check if it does overlap with @ref testGetLease4NullClientId()
  135. void testLease4NullClientId();
  136. /// @brief Basic Lease6 Checks
  137. ///
  138. /// Checks that the addLease, getLease6 (by address) and deleteLease (with an
  139. /// IPv6 address) works.
  140. void testBasicLease6();
  141. /// @brief Test that IPv6 lease can be added, retrieved and deleted.
  142. ///
  143. /// This method checks basic IPv6 lease operations. There's check_t1_t2
  144. /// parameter that controls whether the backend supports storing T1, T2
  145. /// parameters. memfile supports it, while MySQL doesn't. If T1,T2
  146. /// storage is not supported, the expected values are 0.
  147. ///
  148. /// @param check_t1_t2 controls whether T1,T2 timers should be checked
  149. void testAddGetDelete6(bool check_t1_t2);
  150. /// @brief Check GetLease6 methods - access by DUID/IAID
  151. ///
  152. /// Adds leases to the database and checks that they can be accessed via
  153. /// a combination of DUID and IAID.
  154. void testGetLeases6DuidIaid();
  155. /// @brief Check that the system can cope with a DUID of allowed size.
  156. void testGetLeases6DuidSize();
  157. /// @brief Check that getLease6 methods discriminate by lease type.
  158. ///
  159. /// Adds six leases, two per lease type all with the same duid and iad but
  160. /// with alternating subnet_ids.
  161. /// It then verifies that all of getLeases6() method variants correctly
  162. /// discriminate between the leases based on lease type alone.
  163. void testLease6LeaseTypeCheck();
  164. /// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
  165. ///
  166. /// Adds leases to the database and checks that they can be accessed via
  167. /// a combination of DIUID and IAID.
  168. void testGetLease6DuidIaidSubnetId();
  169. /// @brief Checks that getLease6() works with different DUID sizes
  170. void testGetLease6DuidIaidSubnetIdSize();
  171. /// @brief Verify that too long hostname for Lease4 is not accepted.
  172. ///
  173. /// Checks that the it is not possible to create a lease when the hostname
  174. /// length exceeds 255 characters.
  175. void testLease4InvalidHostname();
  176. /// @brief Verify that too long hostname for Lease6 is not accepted.
  177. ///
  178. /// Checks that the it is not possible to create a lease when the hostname
  179. /// length exceeds 255 characters.
  180. void testLease6InvalidHostname();
  181. /// @brief Lease4 update test
  182. ///
  183. /// Checks that the code is able to update an IPv4 lease in the database.
  184. void testUpdateLease4();
  185. /// @brief Lease6 update test
  186. ///
  187. /// Checks that the code is able to update an IPv6 lease in the database.
  188. void testUpdateLease6();
  189. /// @brief String forms of IPv4 addresses
  190. std::vector<std::string> straddress4_;
  191. /// @brief IOAddress forms of IPv4 addresses
  192. std::vector<isc::asiolink::IOAddress> ioaddress4_;
  193. /// @brief String forms of IPv6 addresses
  194. std::vector<std::string> straddress6_;
  195. /// @brief Types of IPv6 Leases
  196. std::vector<Lease::Type> leasetype6_;
  197. /// @brief IOAddress forms of IPv6 addresses
  198. std::vector<isc::asiolink::IOAddress> ioaddress6_;
  199. /// @brief Pointer to the lease manager
  200. LeaseMgr* lmptr_;
  201. };
  202. }; // namespace test
  203. }; // namespace dhcp
  204. }; // namespace isc
  205. #endif