lease_mgr.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef LEASE_MGR_H
  7. #define LEASE_MGR_H
  8. #include <asiolink/io_address.h>
  9. #include <asiolink/io_service.h>
  10. #include <dhcp/duid.h>
  11. #include <dhcp/option.h>
  12. #include <dhcp/hwaddr.h>
  13. #include <dhcpsrv/lease.h>
  14. #include <dhcpsrv/subnet.h>
  15. #include <dhcpsrv/db_exceptions.h>
  16. #include <boost/noncopyable.hpp>
  17. #include <boost/shared_ptr.hpp>
  18. #include <fstream>
  19. #include <iostream>
  20. #include <map>
  21. #include <string>
  22. #include <utility>
  23. #include <vector>
  24. /// @file lease_mgr.h
  25. /// @brief An abstract API for lease database
  26. ///
  27. /// This file contains declarations of Lease4, Lease6 and LeaseMgr classes.
  28. /// They are essential components of the interface to any database backend.
  29. /// Each concrete database backend (e.g. MySQL) will define a class derived
  30. /// from LeaseMgr class.
  31. ///
  32. /// Failover considerations:
  33. /// There are no intermediate plans to implement DHCPv4 failover
  34. /// (draft-ietf-dhc-failover-12.txt). Currently (Oct. 2012) the DHCPv6 failover
  35. /// is being defined in DHC WG in IETF (draft-ietf-dhcpv6-failover-requirements,
  36. /// draft-ietf-dhcpv6-failover-design), but the work is not advanced enough
  37. /// for implementation plans yet. v4 failover requires additional parameters
  38. /// to be kept with a lease. It is likely that v6 failover will require similar
  39. /// fields. Such implementation will require database schema extension.
  40. /// We have designed a way to expand/upgrade schemas during upgrades: a database
  41. /// schema is versioned and sanity checks about required version will be done
  42. /// upon start and/or upgrade. With this mechanism in place, we can add new
  43. /// fields to the database. In particular we can use that capability to
  44. /// introduce failover related fields.
  45. ///
  46. /// However, there is another approach that can be reliably used to provide
  47. /// failover, even without the actual failover protocol implemented. As the
  48. /// first backend will use MySQL, we will be able to use Multi-Master capability
  49. /// offered by MySQL and use two separatate Kea instances connecting to the
  50. /// same database.
  51. ///
  52. /// Nevertheless, we hope to have failover protocol eventually implemented in
  53. /// the Kea.
  54. namespace isc {
  55. namespace dhcp {
  56. /// @brief Used to map server data types with internal backend storage data
  57. /// types.
  58. enum ExchangeDataType {
  59. EXCHANGE_DATA_TYPE_NONE,
  60. EXCHANGE_DATA_TYPE_BOOL,
  61. EXCHANGE_DATA_TYPE_INT32,
  62. EXCHANGE_DATA_TYPE_INT64,
  63. EXCHANGE_DATA_TYPE_TIMESTAMP,
  64. EXCHANGE_DATA_TYPE_STRING,
  65. EXCHANGE_DATA_TYPE_BYTES
  66. };
  67. /// @brief Used to specify the direction of the data exchange between the
  68. /// database and the server.
  69. enum ExchangeDataTypeIO {
  70. EXCHANGE_DATA_TYPE_IO_IN,
  71. EXCHANGE_DATA_TYPE_IO_OUT,
  72. EXCHANGE_DATA_TYPE_IO_IN_OUT
  73. };
  74. /// @brief Used to map the column name with internal backend storage data types.
  75. struct ExchangeColumnInfo {
  76. ExchangeColumnInfo () : name_(""), index_(0), type_io_(EXCHANGE_DATA_TYPE_IO_IN),
  77. type_(EXCHANGE_DATA_TYPE_NONE) {};
  78. ExchangeColumnInfo (const char* name, const uint32_t index,
  79. const ExchangeDataTypeIO type_io, const ExchangeDataType type) :
  80. name_(name), index_(index), type_io_(type_io), type_(type) {};
  81. std::string name_;
  82. uint32_t index_;
  83. ExchangeDataTypeIO type_io_;
  84. ExchangeDataType type_;
  85. };
  86. typedef boost::shared_ptr<ExchangeColumnInfo> ExchangeColumnInfoPtr;
  87. typedef boost::multi_index_container<
  88. // Container comprises elements of ExchangeColumnInfoPtr type.
  89. ExchangeColumnInfoPtr,
  90. // Here we start enumerating various indexes.
  91. boost::multi_index::indexed_by<
  92. // Sequenced index allows accessing elements in the same way as elements
  93. // in std::list.
  94. // Sequenced is an index #0.
  95. boost::multi_index::sequenced<>,
  96. // Start definition of index #1.
  97. boost::multi_index::hashed_non_unique<
  98. boost::multi_index::member<
  99. ExchangeColumnInfo,
  100. std::string,
  101. &ExchangeColumnInfo::name_
  102. >
  103. >,
  104. // Start definition of index #2.
  105. boost::multi_index::hashed_non_unique<
  106. boost::multi_index::member<
  107. ExchangeColumnInfo,
  108. uint32_t,
  109. &ExchangeColumnInfo::index_
  110. >
  111. >
  112. >
  113. > ExchangeColumnInfoContainer;
  114. /// Pointer to the ExchangeColumnInfoContainer object.
  115. typedef boost::shared_ptr<ExchangeColumnInfoContainer> ExchangeColumnInfoContainerPtr;
  116. /// Type of the index #1 - name.
  117. typedef ExchangeColumnInfoContainer::nth_index<1>::type ExchangeColumnInfoContainerName;
  118. /// Pair of iterators to represent the range of ExchangeColumnInfo having the
  119. /// same name value. The first element in this pair represents
  120. /// the beginning of the range, the second element represents the end.
  121. typedef std::pair<ExchangeColumnInfoContainerName::const_iterator,
  122. ExchangeColumnInfoContainerName::const_iterator> ExchangeColumnInfoContainerNameRange;
  123. /// Type of the index #2 - index.
  124. typedef ExchangeColumnInfoContainer::nth_index<2>::type ExchangeColumnInfoContainerIndex;
  125. /// Pair of iterators to represent the range of ExchangeColumnInfo having the
  126. /// same index value. The first element in this pair represents
  127. /// the beginning of the range, the second element represents the end.
  128. typedef std::pair<ExchangeColumnInfoContainerIndex::const_iterator,
  129. ExchangeColumnInfoContainerIndex::const_iterator> ExchangeColumnInfoContainerIndexRange;
  130. class SqlExchange {
  131. public:
  132. SqlExchange () {};
  133. virtual ~SqlExchange() {};
  134. ExchangeColumnInfoContainer parameters_; ///< Column names and types
  135. };
  136. /// @brief Contains a single row of IPv4 lease statistical data
  137. ///
  138. /// The contents of the row consist of a subnet ID, a lease state,
  139. /// and the number of leases in that state for that subnet ID.
  140. struct AddressStatsRow4 {
  141. /// @brief Default constructor
  142. AddressStatsRow4() :
  143. subnet_id_(0), lease_state_(Lease::STATE_DEFAULT), state_count_(0) {
  144. }
  145. /// @brief Constructor
  146. ///
  147. /// @param subnet_id The subnet id to which this data applies
  148. /// @param lease_state The lease state counted
  149. /// @param state_count The count of leases in the lease state
  150. AddressStatsRow4(const SubnetID& subnet_id,
  151. const Lease::LeaseState& lease_state,
  152. const int64_t state_count)
  153. : subnet_id_(subnet_id), lease_state_(lease_state),
  154. state_count_(state_count) {
  155. }
  156. /// @brief The subnet ID to which this data applies
  157. SubnetID subnet_id_;
  158. /// @brief The lease_state to which the count applies
  159. Lease::LeaseState lease_state_;
  160. /// @brief state_count The count of leases in the lease state
  161. int64_t state_count_;
  162. };
  163. /// @brief Base class for fulfilling IPv4 statistical lease data query
  164. ///
  165. /// LeaseMgr derivations implement this class such that it provides
  166. /// upto date IPv4 statistical lease data organized as rows of
  167. /// AddressStatsRow4 instances. The rows must be accessible in
  168. /// ascending order by subnet id.
  169. class AddressStatsQuery4 {
  170. public:
  171. /// @brief Default constructor
  172. AddressStatsQuery4() {};
  173. /// @brief virtual destructor
  174. virtual ~AddressStatsQuery4() {};
  175. /// @brief Executes the query
  176. ///
  177. /// This method should conduct whatever steps are required to
  178. /// calculate the IPv4 lease statistical data by examining the
  179. /// IPv4 lease data and making that results available row by row.
  180. virtual void start() {};
  181. /// @brief Fetches the next row of data
  182. ///
  183. /// @param[out] row Storage into which the row is fetched
  184. ///
  185. /// @return True if a row was fetched, false if there are no
  186. /// more rows.
  187. virtual bool getNextRow(AddressStatsRow4& row) { return(false); };
  188. };
  189. /// @brief Defines a pointer to an AddressStatsQuery4.
  190. typedef boost::shared_ptr<AddressStatsQuery4> AddressStatsQuery4Ptr;
  191. /// @brief Contains a single row of IPv6 lease statistical data
  192. ///
  193. /// The contents of the row consist of a subnet ID, a lease state,
  194. /// and the number of leases in that state for that subnet ID.
  195. struct AddressStatsRow6 {
  196. /// @brief Default constructor
  197. AddressStatsRow6() :
  198. subnet_id_(0), lease_type_(Lease::TYPE_NA),
  199. lease_state_(Lease::STATE_DEFAULT), state_count_(0) {
  200. }
  201. /// @brief Constructor
  202. ///
  203. /// @param subnet_id The subnet id to which this data applies
  204. /// @param lease_state The lease state counted
  205. /// @param state_count The count of leases in the lease state
  206. AddressStatsRow6(const SubnetID& subnet_id, const Lease::Type& lease_type,
  207. const Lease::LeaseState& lease_state,
  208. const int64_t state_count)
  209. : subnet_id_(subnet_id), lease_state_(lease_state),
  210. state_count_(state_count) {
  211. }
  212. /// @brief The subnet ID to which this data applies
  213. SubnetID subnet_id_;
  214. /// @brief The lease_state to which the count applies
  215. Lease::Type lease_type_;
  216. /// @brief The lease_state to which the count applies
  217. uint32_t lease_state_;
  218. /// @brief state_count The count of leases in the lease state
  219. int64_t state_count_;
  220. };
  221. /// @brief Base class for fulfilling IPv6 statistical lease data query
  222. ///
  223. /// LeaseMgr derivations implement this class such that it provides
  224. /// upto date IPv6 statistical lease data organized as rows of
  225. /// AddressStatsRow6 instances. The rows must be accessible in
  226. /// ascending order by subnet id.
  227. class AddressStatsQuery6 {
  228. public:
  229. /// @brief Default constructor
  230. AddressStatsQuery6() {};
  231. /// @brief virtual destructor
  232. virtual ~AddressStatsQuery6() {};
  233. /// @brief Executes the query
  234. ///
  235. /// This method should conduct whatever steps are required to
  236. /// calculate the IPv6 lease statistical data by examining the
  237. /// IPv6 lease data and making that results available row by row.
  238. virtual void start() {};
  239. /// @brief Fetches the next row of data
  240. ///
  241. /// @param[out] row Storage into which the row is fetched
  242. ///
  243. /// @return True if a row was fetched, false if there are no
  244. /// more rows.
  245. virtual bool getNextRow(AddressStatsRow6& row) { return (false); };
  246. };
  247. /// @brief Defines a pointer to an AddressStatsQuery6.
  248. typedef boost::shared_ptr<AddressStatsQuery6> AddressStatsQuery6Ptr;
  249. /// @brief Abstract Lease Manager
  250. ///
  251. /// This is an abstract API for lease database backends. It provides unified
  252. /// interface to all backends. As this is an abstract class, it should not
  253. /// be used directly, but rather specialized derived class should be used
  254. /// instead.
  255. ///
  256. /// This class throws no exceptions. However, methods in concrete
  257. /// implementations of this class may throw exceptions: see the documentation
  258. /// of those classes for details.
  259. class LeaseMgr {
  260. public:
  261. /// @brief Constructor
  262. ///
  263. LeaseMgr()
  264. {}
  265. /// @brief Destructor
  266. virtual ~LeaseMgr()
  267. {}
  268. /// @brief Class method to return extended version info
  269. /// This class method must be redeclared and redefined in derived classes
  270. static std::string getDBVersion();
  271. /// @brief Adds an IPv4 lease.
  272. ///
  273. /// @param lease lease to be added
  274. ///
  275. /// @result true if the lease was added, false if not (because a lease
  276. /// with the same address was already there).
  277. virtual bool addLease(const isc::dhcp::Lease4Ptr& lease) = 0;
  278. /// @brief Adds an IPv6 lease.
  279. ///
  280. /// @param lease lease to be added
  281. ///
  282. /// @result true if the lease was added, false if not (because a lease
  283. /// with the same address was already there).
  284. virtual bool addLease(const Lease6Ptr& lease) = 0;
  285. /// @brief Returns an IPv4 lease for specified IPv4 address
  286. ///
  287. /// This method return a lease that is associated with a given address.
  288. /// For other query types (by hardware addr, by client-id) there can be
  289. /// several leases in different subnets (e.g. for mobile clients that
  290. /// got address in different subnets). However, for a single address
  291. /// there can be only one lease, so this method returns a pointer to
  292. /// a single lease, not a container of leases.
  293. ///
  294. /// @param addr address of the searched lease
  295. ///
  296. /// @return smart pointer to the lease (or NULL if a lease is not found)
  297. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const = 0;
  298. /// @brief Returns existing IPv4 leases for specified hardware address.
  299. ///
  300. /// Although in the usual case there will be only one lease, for mobile
  301. /// clients or clients with multiple static/fixed/reserved leases there
  302. /// can be more than one. Thus return type is a container, not a single
  303. /// pointer.
  304. ///
  305. /// @param hwaddr hardware address of the client
  306. ///
  307. /// @return lease collection
  308. virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const = 0;
  309. /// @brief Returns existing IPv4 leases for specified hardware address
  310. /// and a subnet
  311. ///
  312. /// There can be at most one lease for a given HW address in a single
  313. /// pool, so this method will either return a single lease or NULL.
  314. ///
  315. /// @param hwaddr hardware address of the client
  316. /// @param subnet_id identifier of the subnet that lease must belong to
  317. ///
  318. /// @return a pointer to the lease (or NULL if a lease is not found)
  319. virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr,
  320. SubnetID subnet_id) const = 0;
  321. /// @brief Returns existing IPv4 lease for specified client-id
  322. ///
  323. /// Although in the usual case there will be only one lease, for mobile
  324. /// clients or clients with multiple static/fixed/reserved leases there
  325. /// can be more than one. Thus return type is a container, not a single
  326. /// pointer.
  327. ///
  328. /// @param clientid client identifier
  329. ///
  330. /// @return lease collection
  331. virtual Lease4Collection getLease4(const ClientId& clientid) const = 0;
  332. /// @brief Returns existing IPv4 lease for a given client identifier,
  333. /// HW address and subnet identifier.
  334. ///
  335. /// @todo Consider whether this function is needed or not. In the basic
  336. /// DHCPv4 server implementation it is not used by the allocation engine.
  337. ///
  338. /// @param client_id A client identifier.
  339. /// @param hwaddr Hardware address.
  340. /// @param subnet_id A subnet identifier.
  341. ///
  342. /// @return A pointer to the lease or NULL if the lease is not found.
  343. virtual Lease4Ptr getLease4(const ClientId& client_id, const HWAddr& hwaddr,
  344. SubnetID subnet_id) const = 0;
  345. /// @brief Returns existing IPv4 lease for specified client-id
  346. ///
  347. /// There can be at most one lease for a given client-id in a single
  348. /// pool, so this method will either return a single lease or NULL.
  349. ///
  350. /// @param clientid client identifier
  351. /// @param subnet_id identifier of the subnet that lease must belong to
  352. ///
  353. /// @return a pointer to the lease (or NULL if a lease is not found)
  354. virtual Lease4Ptr getLease4(const ClientId& clientid,
  355. SubnetID subnet_id) const = 0;
  356. /// @brief Returns existing IPv6 lease for a given IPv6 address.
  357. ///
  358. /// For a given address, we assume that there will be only one lease.
  359. /// The assumption here is that there will not be site or link-local
  360. /// addresses used, so there is no way of having address duplication.
  361. ///
  362. /// @param type specifies lease type: (NA, TA or PD)
  363. /// @param addr address of the searched lease
  364. ///
  365. /// @return smart pointer to the lease (or NULL if a lease is not found)
  366. virtual Lease6Ptr getLease6(Lease::Type type,
  367. const isc::asiolink::IOAddress& addr) const = 0;
  368. /// @brief Returns existing IPv6 leases for a given DUID+IA combination
  369. ///
  370. /// Although in the usual case there will be only one lease, for mobile
  371. /// clients or clients with multiple static/fixed/reserved leases there
  372. /// can be more than one. Thus return type is a container, not a single
  373. /// pointer.
  374. ///
  375. /// @param type specifies lease type: (NA, TA or PD)
  376. /// @param duid client DUID
  377. /// @param iaid IA identifier
  378. ///
  379. /// @return Lease collection (may be empty if no lease is found)
  380. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
  381. uint32_t iaid) const = 0;
  382. /// @brief Returns existing IPv6 lease for a given DUID+IA combination
  383. ///
  384. /// There may be more than one address, temp. address or prefix
  385. /// for specified duid/iaid/subnet-id tuple.
  386. ///
  387. /// @param type specifies lease type: (NA, TA or PD)
  388. /// @param duid client DUID
  389. /// @param iaid IA identifier
  390. /// @param subnet_id subnet id of the subnet the lease belongs to
  391. ///
  392. /// @return Lease collection (may be empty if no lease is found)
  393. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
  394. uint32_t iaid, SubnetID subnet_id) const = 0;
  395. /// @brief returns zero or one IPv6 lease for a given duid+iaid+subnet_id
  396. ///
  397. /// This function is mostly intended to be used in unit-tests during the
  398. /// transition from single to multi address per IA. It may also be used
  399. /// in other cases where at most one lease is expected in the database.
  400. ///
  401. /// It is a wrapper around getLeases6(), which returns a collection of
  402. /// leases. That collection can be converted into a single pointer if
  403. /// there are no leases (NULL pointer) or one lease (use that single lease).
  404. /// If there are more leases in the collection, the function will
  405. /// throw MultipleRecords exception.
  406. ///
  407. /// Note: This method is not virtual on purpose. It is common for all
  408. /// backends.
  409. ///
  410. /// @param type specifies lease type: (NA, TA or PD)
  411. /// @param duid client DUID
  412. /// @param iaid IA identifier
  413. /// @param subnet_id subnet id of the subnet the lease belongs to
  414. ///
  415. /// @throw MultipleRecords if there is more than one lease matching
  416. ///
  417. /// @return Lease pointer (or NULL if none is found)
  418. Lease6Ptr getLease6(Lease::Type type, const DUID& duid,
  419. uint32_t iaid, SubnetID subnet_id) const;
  420. /// @brief Returns a collection of expired DHCPv6 leases.
  421. ///
  422. /// This method returns at most @c max_leases expired leases. The leases
  423. /// returned haven't been reclaimed, i.e. the database query must exclude
  424. /// reclaimed leases from the results returned.
  425. ///
  426. /// @param [out] expired_leases A container to which expired leases returned
  427. /// by the database backend are added.
  428. /// @param max_leases A maximum number of leases to be returned. If this
  429. /// value is set to 0, all expired (but not reclaimed) leases are returned.
  430. virtual void getExpiredLeases6(Lease6Collection& expired_leases,
  431. const size_t max_leases) const = 0;
  432. /// @brief Returns a collection of expired DHCPv4 leases.
  433. ///
  434. /// This method returns at most @c max_leases expired leases. The leases
  435. /// returned haven't been reclaimed, i.e. the database query must exclude
  436. /// reclaimed leases from the results returned.
  437. ///
  438. /// @param [out] expired_leases A container to which expired leases returned
  439. /// by the database backend are added.
  440. /// @param max_leases A maximum number of leases to be returned. If this
  441. /// value is set to 0, all expired (but not reclaimed) leases are returned.
  442. virtual void getExpiredLeases4(Lease4Collection& expired_leases,
  443. const size_t max_leases) const = 0;
  444. /// @brief Updates IPv4 lease.
  445. ///
  446. /// @param lease4 The lease to be updated.
  447. ///
  448. /// If no such lease is present, an exception will be thrown.
  449. virtual void updateLease4(const Lease4Ptr& lease4) = 0;
  450. /// @brief Updates IPv6 lease.
  451. ///
  452. /// @param lease6 The lease to be updated.
  453. virtual void updateLease6(const Lease6Ptr& lease6) = 0;
  454. /// @brief Deletes a lease.
  455. ///
  456. /// @param addr Address of the lease to be deleted. (This can be IPv4 or
  457. /// IPv6.)
  458. ///
  459. /// @return true if deletion was successful, false if no such lease exists
  460. virtual bool deleteLease(const isc::asiolink::IOAddress& addr) = 0;
  461. /// @brief Deletes all expired and reclaimed DHCPv4 leases.
  462. ///
  463. /// @param secs Number of seconds since expiration of leases before
  464. /// they can be removed. Leases which have expired later than this
  465. /// time will not be deleted.
  466. ///
  467. /// @return Number of leases deleted.
  468. virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) = 0;
  469. /// @brief Deletes all expired and reclaimed DHCPv6 leases.
  470. ///
  471. /// @param secs Number of seconds since expiration of leases before
  472. /// they can be removed. Leases which have expired later than this
  473. /// time will not be deleted.
  474. ///
  475. /// @return Number of leases deleted.
  476. virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) = 0;
  477. /// @brief Recalculates per-subnet and global stats for IPv4 leases
  478. ///
  479. /// This method recalculates the following statistics:
  480. /// per-subnet:
  481. /// - assigned-addresses
  482. /// - declined-addresses
  483. /// - declined-reclaimed-addresses (reset to zero)
  484. /// global:
  485. /// - declined-addresses
  486. /// - declined-reclaimed-addresses (reset to zero)
  487. ///
  488. /// It invokes the virtual method, startAddressStatsQuery4(), which
  489. /// returns an instance of an AddressStats4Qry. The query
  490. /// query contains a "result set" where each row is an AddressStatRow4
  491. /// that contains a subnet id, a lease state, the number of leases in that
  492. /// state and is ordered by subnet id. The method iterates over the
  493. /// result set rows, setting the appropriate statistic per subnet and
  494. /// adding to the approporate global statistic.
  495. void recountAddressStats4();
  496. /// @brief Virtual method which creates and runs the IPv4 lease stats query
  497. ///
  498. /// LeaseMgr derivations implement this method such that it creates and
  499. /// returns an instance of an AddressStatsQuery whose result set has been
  500. /// populated with upto date IPv4 lease statistical data. Each row of the
  501. /// result set is an AddressStatRow4 which ordered ascending by subnet ID.
  502. ///
  503. /// @return A populated AddressStatsQuery4
  504. virtual AddressStatsQuery4Ptr startAddressStatsQuery4();
  505. /// @brief Recalculates per-subnet and global stats for IPv6 leases
  506. ///
  507. /// This method recalculates the following statistics:
  508. /// per-subnet:
  509. /// - assigned-addresses
  510. /// - declined-addresses
  511. /// - declined-reclaimed-addresses (reset to zero)
  512. /// - assigned-pds
  513. /// global:
  514. /// - declined-addresses
  515. /// - declined-reclaimed-addresses (reset to zero)
  516. ///
  517. /// It invokes the virtual method, startAddressStatsQuery6(), which
  518. /// returns an instance of an AddressStats6Qry. The query
  519. /// query contains a "result set" where each row is an AddressStatRow6
  520. /// that contains a subnet id, a lease state, the number of leases in that
  521. /// state and is ordered by subnet id. The method iterates over the
  522. /// result set rows, setting the appropriate statistic per subnet and
  523. /// adding to the approporate global statistic.
  524. void recountAddressStats6();
  525. /// @brief Virtual method which creates and runs the IPv6 lease stats query
  526. ///
  527. /// LeaseMgr derivations implement this method such that it creates and
  528. /// returns an instance of an AddressStatsQuery whose result set has been
  529. /// populated with upto date IPv6 lease statistical data. Each row of the
  530. /// result set is an AddressStatRow6 which ordered ascending by subnet ID.
  531. ///
  532. /// @return A populated AddressStatsQuery6
  533. virtual AddressStatsQuery6Ptr startAddressStatsQuery6();
  534. /// @brief Return backend type
  535. ///
  536. /// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
  537. ///
  538. /// @return Type of the backend.
  539. virtual std::string getType() const = 0;
  540. /// @brief Returns backend name.
  541. ///
  542. /// If the backend is a database, this is the name of the database or the
  543. /// file. Otherwise it is just the same as the type.
  544. ///
  545. /// @return Name of the backend.
  546. virtual std::string getName() const = 0;
  547. /// @brief Returns description of the backend.
  548. ///
  549. /// This description may be multiline text that describes the backend.
  550. ///
  551. /// @return Description of the backend.
  552. virtual std::string getDescription() const = 0;
  553. /// @brief Returns backend version.
  554. ///
  555. /// @return Version number as a pair of unsigned integers. "first" is the
  556. /// major version number, "second" the minor number.
  557. ///
  558. /// @todo: We will need to implement 3 version functions eventually:
  559. /// A. abstract API version
  560. /// B. backend version
  561. /// C. database version (stored in the database scheme)
  562. ///
  563. /// and then check that:
  564. /// B>=A and B=C (it is ok to have newer backend, as it should be backward
  565. /// compatible)
  566. /// Also if B>C, some database upgrade procedure may be triggered
  567. virtual std::pair<uint32_t, uint32_t> getVersion() const = 0;
  568. /// @brief Commit Transactions
  569. ///
  570. /// Commits all pending database operations. On databases that don't
  571. /// support transactions, this is a no-op.
  572. virtual void commit() = 0;
  573. /// @brief Rollback Transactions
  574. ///
  575. /// Rolls back all pending database operations. On databases that don't
  576. /// support transactions, this is a no-op.
  577. virtual void rollback() = 0;
  578. /// @todo: Add host management here
  579. /// As host reservation is outside of scope for 2012, support for hosts
  580. /// is currently postponed.
  581. };
  582. }; // end of isc::dhcp namespace
  583. }; // end of isc namespace
  584. #endif // LEASE_MGR_H