memfile_lease_mgr.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 MEMFILE_LEASE_MGR_H
  15. #define MEMFILE_LEASE_MGR_H
  16. #include <dhcp/lease_mgr.h>
  17. #include <boost/multi_index_container.hpp>
  18. #include <boost/multi_index/indexed_by.hpp>
  19. #include <boost/multi_index/ordered_index.hpp>
  20. #include <boost/multi_index/member.hpp>
  21. namespace isc {
  22. namespace dhcp {
  23. namespace test {
  24. // This is a concrete implementation of a Lease database.
  25. //
  26. // It is for testing purposes only. It is NOT a production code.
  27. //
  28. // It does not do anything useful now, and is used for abstract LeaseMgr
  29. // class testing. It may later evolve into more useful backend if the
  30. // need arises. We can reuse code from memfile benchmark. See code in
  31. // tests/tools/dhcp-ubench/memfile_bench.{cc|h}
  32. class Memfile_LeaseMgr : public LeaseMgr {
  33. public:
  34. /// @brief The sole lease manager constructor
  35. ///
  36. /// dbconfig is a generic way of passing parameters. Parameters
  37. /// are passed in the "name=value" format, separated by spaces.
  38. /// Values may be enclosed in double quotes, if needed.
  39. ///
  40. /// @param dbconfig database configuration
  41. Memfile_LeaseMgr(const std::string& dbconfig);
  42. /// @brief Destructor (closes file)
  43. virtual ~Memfile_LeaseMgr();
  44. /// @brief Adds an IPv4 lease.
  45. ///
  46. /// @todo Not implemented yet
  47. /// @param lease lease to be added
  48. virtual bool addLease(const Lease4Ptr& lease);
  49. /// @brief Adds an IPv6 lease.
  50. ///
  51. /// @param lease lease to be added
  52. virtual bool addLease(const Lease6Ptr& lease);
  53. /// @brief Returns existing IPv4 lease for specified IPv4 address.
  54. ///
  55. /// @todo Not implemented yet
  56. /// @param addr address of the searched lease
  57. ///
  58. /// @return a collection of leases
  59. virtual Lease4Ptr getLease4(isc::asiolink::IOAddress addr) const;
  60. /// @brief Returns existing IPv4 lease for specific address and subnet
  61. ///
  62. /// @todo Not implemented yet
  63. /// @param addr address of the searched lease
  64. /// @param subnet_id ID of the subnet the lease must belong to
  65. ///
  66. /// @return smart pointer to the lease (or NULL if a lease is not found)
  67. virtual Lease4Ptr getLease4(isc::asiolink::IOAddress addr,
  68. SubnetID subnet_id) const;
  69. /// @brief Returns existing IPv4 leases for specified hardware address.
  70. ///
  71. /// @todo Not implemented yet
  72. ///
  73. /// Although in the usual case there will be only one lease, for mobile
  74. /// clients or clients with multiple static/fixed/reserved leases there
  75. /// can be more than one. Thus return type is a container, not a single
  76. /// pointer.
  77. ///
  78. /// @param hwaddr hardware address of the client
  79. ///
  80. /// @return lease collection
  81. virtual Lease4Collection getLease4(const HWAddr& hwaddr) const;
  82. /// @brief Returns existing IPv4 leases for specified hardware address
  83. /// and a subnet
  84. ///
  85. /// @todo Not implemented yet
  86. ///
  87. /// There can be at most one lease for a given HW address in a single
  88. /// pool, so this method with either return a single lease or NULL.
  89. ///
  90. /// @param hwaddr hardware address of the client
  91. /// @param subnet_id identifier of the subnet that lease must belong to
  92. ///
  93. /// @return a pointer to the lease (or NULL if a lease is not found)
  94. virtual Lease4Ptr getLease4(const HWAddr& hwaddr,
  95. SubnetID subnet_id) const;
  96. /// @brief Returns existing IPv4 lease for specified client-id
  97. ///
  98. /// @todo Not implemented yet
  99. ///
  100. /// @param clientid client identifier
  101. virtual Lease4Collection getLease4(const ClientId& clientid) const;
  102. /// @brief Returns existing IPv4 lease for specified client-id
  103. ///
  104. /// There can be at most one lease for a given HW address in a single
  105. /// pool, so this method with either return a single lease or NULL.
  106. ///
  107. /// @todo Not implemented yet
  108. ///
  109. /// @param clientid client identifier
  110. /// @param subnet_id identifier of the subnet that lease must belong to
  111. ///
  112. /// @return a pointer to the lease (or NULL if a lease is not found)
  113. virtual Lease4Ptr getLease4(const ClientId& clientid,
  114. SubnetID subnet_id) const;
  115. /// @brief Returns existing IPv6 lease for a given IPv6 address.
  116. ///
  117. /// @param addr address of the searched lease
  118. ///
  119. /// @return smart pointer to the lease (or NULL if a lease is not found)
  120. Lease6Ptr getLease6(const isc::asiolink::IOAddress& addr) const;
  121. /// @brief Returns existing IPv6 lease for a given DUID+IA combination
  122. ///
  123. /// @todo Not implemented yet
  124. ///
  125. /// @param duid client DUID
  126. /// @param iaid IA identifier
  127. ///
  128. /// @return collection of IPv6 leases
  129. Lease6Collection getLease6(const DUID& duid, uint32_t iaid) const;
  130. /// @brief Returns existing IPv6 lease for a given DUID+IA combination
  131. ///
  132. /// @todo Not implemented yet
  133. ///
  134. /// @param duid client DUID
  135. /// @param iaid IA identifier
  136. /// @param subnet_id identifier of the subnet the lease must belong to
  137. ///
  138. /// @return smart pointer to the lease (or NULL if a lease is not found)
  139. Lease6Ptr getLease6(const DUID& duid, uint32_t iaid, SubnetID subnet_id) const;
  140. /// @brief Updates IPv4 lease.
  141. ///
  142. /// @todo Not implemented yet
  143. ///
  144. /// @param lease4 The lease to be updated.
  145. ///
  146. /// If no such lease is present, an exception will be thrown.
  147. void updateLease4(const Lease4Ptr& lease4);
  148. /// @brief Updates IPv4 lease.
  149. ///
  150. /// @todo Not implemented yet
  151. ///
  152. /// @param lease4 The lease to be updated.
  153. ///
  154. /// If no such lease is present, an exception will be thrown.
  155. void updateLease6(const Lease6Ptr& lease6);
  156. /// @brief Deletes a lease.
  157. ///
  158. /// @todo Not implemented yet
  159. ///
  160. /// @param addr IPv4 address of the lease to be deleted.
  161. ///
  162. /// @return true if deletion was successful, false if no such lease exists
  163. bool deleteLease4(uint32_t addr);
  164. /// @brief Deletes a lease.
  165. ///
  166. /// @param addr IPv4 address of the lease to be deleted.
  167. ///
  168. /// @return true if deletion was successful, false if no such lease exists
  169. bool deleteLease6(const isc::asiolink::IOAddress& addr);
  170. /// @brief Returns backend name.
  171. ///
  172. /// Each backend have specific name, e.g. "mysql" or "sqlite".
  173. std::string getName() const { return ("memfile"); }
  174. /// @brief Returns description of the backend.
  175. ///
  176. /// This description may be multiline text that describes the backend.
  177. std::string getDescription() const;
  178. /// @brief Returns backend version.
  179. std::string getVersion() const { return ("test-version"); }
  180. using LeaseMgr::getParameter;
  181. protected:
  182. typedef boost::multi_index_container< // this is a multi-index container...
  183. Lease6Ptr, // it will hold shared_ptr to leases6
  184. boost::multi_index::indexed_by< // and will be sorted by
  185. // IPv6 address that are unique. That particular key is a member
  186. // of the Lease6 structure, is of type IOAddress and can be accessed
  187. // by doing &Lease6::addr_
  188. boost::multi_index::ordered_unique<
  189. boost::multi_index::member<Lease6, isc::asiolink::IOAddress, &Lease6::addr_>
  190. >
  191. >
  192. > Lease6Storage; // Let the whole contraption be called Lease6Storage.
  193. Lease6Storage storage6_;
  194. };
  195. }; // end of isc::dhcp::test namespace
  196. }; // end of isc::dhcp namespace
  197. }; // end of isc namespace
  198. #endif // MEMFILE_LEASE_MGR_H