lease_mgr.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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 lease statistical data
  137. ///
  138. /// The contents of the row consist of a subnet ID, a lease
  139. /// type, a lease state, and the number of leases in that state
  140. /// for that type for that subnet ID.
  141. struct LeaseStatsRow {
  142. /// @brief Default constructor
  143. LeaseStatsRow() :
  144. subnet_id_(0), lease_type_(Lease::TYPE_NA),
  145. lease_state_(Lease::STATE_DEFAULT), state_count_(0) {
  146. }
  147. /// @brief Constructor
  148. ///
  149. /// Constructor which defaults the type to TYPE_NA.
  150. ///
  151. /// @param subnet_id The subnet id to which this data applies
  152. /// @param lease_state The lease state counted
  153. /// @param state_count The count of leases in the lease state
  154. LeaseStatsRow(const SubnetID& subnet_id, const uint32_t lease_state,
  155. const int64_t state_count)
  156. : subnet_id_(subnet_id), lease_type_(Lease::TYPE_NA),
  157. lease_state_(lease_state), state_count_(state_count) {
  158. }
  159. /// @brief Constructor
  160. ///
  161. /// @param subnet_id The subnet id to which this data applies
  162. /// @param lease_type The lease type for this state count
  163. /// @param lease_state The lease state counted
  164. /// @param state_count The count of leases in the lease state
  165. LeaseStatsRow(const SubnetID& subnet_id, const Lease::Type& lease_type,
  166. const uint32_t lease_state, const int64_t state_count)
  167. : subnet_id_(subnet_id), lease_type_(lease_type),
  168. lease_state_(lease_state), state_count_(state_count) {
  169. }
  170. /// @brief The subnet ID to which this data applies
  171. SubnetID subnet_id_;
  172. /// @brief The lease_type to which the count applies
  173. Lease::Type lease_type_;
  174. /// @brief The lease_state to which the count applies
  175. uint32_t lease_state_;
  176. /// @brief state_count The count of leases in the lease state
  177. int64_t state_count_;
  178. };
  179. /// @brief Base class for fulfilling a statistical lease data query
  180. ///
  181. /// LeaseMgr derivations implement this class such that it provides
  182. /// upto date statistical lease data organized as rows of LeaseStatsRow
  183. /// instances. The rows must be accessible in ascending order by subnet id.
  184. class LeaseStatsQuery {
  185. public:
  186. /// @brief Default constructor
  187. LeaseStatsQuery() {};
  188. /// @brief virtual destructor
  189. virtual ~LeaseStatsQuery() {};
  190. /// @brief Executes the query
  191. ///
  192. /// This method should conduct whatever steps are required to
  193. /// calculate the lease statistical data by examining the
  194. /// lease data and making that results available row by row.
  195. virtual void start() {};
  196. /// @brief Fetches the next row of data
  197. ///
  198. /// @param[out] row Storage into which the row is fetched
  199. ///
  200. /// @return True if a row was fetched, false if there are no
  201. /// more rows.
  202. virtual bool getNextRow(LeaseStatsRow& row);
  203. };
  204. /// @brief Defines a pointer to an LeaseStatsQuery.
  205. typedef boost::shared_ptr<LeaseStatsQuery> LeaseStatsQueryPtr;
  206. /// @brief Abstract Lease Manager
  207. ///
  208. /// This is an abstract API for lease database backends. It provides unified
  209. /// interface to all backends. As this is an abstract class, it should not
  210. /// be used directly, but rather specialized derived class should be used
  211. /// instead.
  212. ///
  213. /// This class throws no exceptions. However, methods in concrete
  214. /// implementations of this class may throw exceptions: see the documentation
  215. /// of those classes for details.
  216. class LeaseMgr {
  217. public:
  218. /// @brief Constructor
  219. ///
  220. LeaseMgr()
  221. {}
  222. /// @brief Destructor
  223. virtual ~LeaseMgr()
  224. {}
  225. /// @brief Class method to return extended version info
  226. /// This class method must be redeclared and redefined in derived classes
  227. static std::string getDBVersion();
  228. /// @brief Adds an IPv4 lease.
  229. ///
  230. /// @param lease lease to be added
  231. ///
  232. /// @result true if the lease was added, false if not (because a lease
  233. /// with the same address was already there).
  234. virtual bool addLease(const isc::dhcp::Lease4Ptr& lease) = 0;
  235. /// @brief Adds an IPv6 lease.
  236. ///
  237. /// @param lease lease to be added
  238. ///
  239. /// @result true if the lease was added, false if not (because a lease
  240. /// with the same address was already there).
  241. virtual bool addLease(const Lease6Ptr& lease) = 0;
  242. /// @brief Returns an IPv4 lease for specified IPv4 address
  243. ///
  244. /// This method return a lease that is associated with a given address.
  245. /// For other query types (by hardware addr, by client-id) there can be
  246. /// several leases in different subnets (e.g. for mobile clients that
  247. /// got address in different subnets). However, for a single address
  248. /// there can be only one lease, so this method returns a pointer to
  249. /// a single lease, not a container of leases.
  250. ///
  251. /// @param addr address of the searched lease
  252. ///
  253. /// @return smart pointer to the lease (or NULL if a lease is not found)
  254. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const = 0;
  255. /// @brief Returns existing IPv4 leases for specified hardware address.
  256. ///
  257. /// Although in the usual case there will be only one lease, for mobile
  258. /// clients or clients with multiple static/fixed/reserved leases there
  259. /// can be more than one. Thus return type is a container, not a single
  260. /// pointer.
  261. ///
  262. /// @param hwaddr hardware address of the client
  263. ///
  264. /// @return lease collection
  265. virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const = 0;
  266. /// @brief Returns existing IPv4 leases for specified hardware address
  267. /// and a subnet
  268. ///
  269. /// There can be at most one lease for a given HW address in a single
  270. /// pool, so this method will either return a single lease or NULL.
  271. ///
  272. /// @param hwaddr hardware address of the client
  273. /// @param subnet_id identifier of the subnet that lease must belong to
  274. ///
  275. /// @return a pointer to the lease (or NULL if a lease is not found)
  276. virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr,
  277. SubnetID subnet_id) const = 0;
  278. /// @brief Returns existing IPv4 lease for specified client-id
  279. ///
  280. /// Although in the usual case there will be only one lease, for mobile
  281. /// clients or clients with multiple static/fixed/reserved leases there
  282. /// can be more than one. Thus return type is a container, not a single
  283. /// pointer.
  284. ///
  285. /// @param clientid client identifier
  286. ///
  287. /// @return lease collection
  288. virtual Lease4Collection getLease4(const ClientId& clientid) const = 0;
  289. /// @brief Returns existing IPv4 lease for a given client identifier,
  290. /// HW address and subnet identifier.
  291. ///
  292. /// @todo Consider whether this function is needed or not. In the basic
  293. /// DHCPv4 server implementation it is not used by the allocation engine.
  294. ///
  295. /// @param client_id A client identifier.
  296. /// @param hwaddr Hardware address.
  297. /// @param subnet_id A subnet identifier.
  298. ///
  299. /// @return A pointer to the lease or NULL if the lease is not found.
  300. virtual Lease4Ptr getLease4(const ClientId& client_id, const HWAddr& hwaddr,
  301. SubnetID subnet_id) const = 0;
  302. /// @brief Returns existing IPv4 lease for specified client-id
  303. ///
  304. /// There can be at most one lease for a given client-id in a single
  305. /// pool, so this method will either return a single lease or NULL.
  306. ///
  307. /// @param clientid client identifier
  308. /// @param subnet_id identifier of the subnet that lease must belong to
  309. ///
  310. /// @return a pointer to the lease (or NULL if a lease is not found)
  311. virtual Lease4Ptr getLease4(const ClientId& clientid,
  312. SubnetID subnet_id) const = 0;
  313. /// @brief Returns existing IPv6 lease for a given IPv6 address.
  314. ///
  315. /// For a given address, we assume that there will be only one lease.
  316. /// The assumption here is that there will not be site or link-local
  317. /// addresses used, so there is no way of having address duplication.
  318. ///
  319. /// @param type specifies lease type: (NA, TA or PD)
  320. /// @param addr address of the searched lease
  321. ///
  322. /// @return smart pointer to the lease (or NULL if a lease is not found)
  323. virtual Lease6Ptr getLease6(Lease::Type type,
  324. const isc::asiolink::IOAddress& addr) const = 0;
  325. /// @brief Returns existing IPv6 leases for a given DUID+IA combination
  326. ///
  327. /// Although in the usual case there will be only one lease, for mobile
  328. /// clients or clients with multiple static/fixed/reserved leases there
  329. /// can be more than one. Thus return type is a container, not a single
  330. /// pointer.
  331. ///
  332. /// @param type specifies lease type: (NA, TA or PD)
  333. /// @param duid client DUID
  334. /// @param iaid IA identifier
  335. ///
  336. /// @return Lease collection (may be empty if no lease is found)
  337. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
  338. uint32_t iaid) const = 0;
  339. /// @brief Returns existing IPv6 lease for a given DUID+IA combination
  340. ///
  341. /// There may be more than one address, temp. address or prefix
  342. /// for specified duid/iaid/subnet-id tuple.
  343. ///
  344. /// @param type specifies lease type: (NA, TA or PD)
  345. /// @param duid client DUID
  346. /// @param iaid IA identifier
  347. /// @param subnet_id subnet id of the subnet the lease belongs to
  348. ///
  349. /// @return Lease collection (may be empty if no lease is found)
  350. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
  351. uint32_t iaid, SubnetID subnet_id) const = 0;
  352. /// @brief returns zero or one IPv6 lease for a given duid+iaid+subnet_id
  353. ///
  354. /// This function is mostly intended to be used in unit-tests during the
  355. /// transition from single to multi address per IA. It may also be used
  356. /// in other cases where at most one lease is expected in the database.
  357. ///
  358. /// It is a wrapper around getLeases6(), which returns a collection of
  359. /// leases. That collection can be converted into a single pointer if
  360. /// there are no leases (NULL pointer) or one lease (use that single lease).
  361. /// If there are more leases in the collection, the function will
  362. /// throw MultipleRecords exception.
  363. ///
  364. /// Note: This method is not virtual on purpose. It is common for all
  365. /// backends.
  366. ///
  367. /// @param type specifies lease type: (NA, TA or PD)
  368. /// @param duid client DUID
  369. /// @param iaid IA identifier
  370. /// @param subnet_id subnet id of the subnet the lease belongs to
  371. ///
  372. /// @throw MultipleRecords if there is more than one lease matching
  373. ///
  374. /// @return Lease pointer (or NULL if none is found)
  375. Lease6Ptr getLease6(Lease::Type type, const DUID& duid,
  376. uint32_t iaid, SubnetID subnet_id) const;
  377. /// @brief Returns a collection of expired DHCPv6 leases.
  378. ///
  379. /// This method returns at most @c max_leases expired leases. The leases
  380. /// returned haven't been reclaimed, i.e. the database query must exclude
  381. /// reclaimed leases from the results returned.
  382. ///
  383. /// @param [out] expired_leases A container to which expired leases returned
  384. /// by the database backend are added.
  385. /// @param max_leases A maximum number of leases to be returned. If this
  386. /// value is set to 0, all expired (but not reclaimed) leases are returned.
  387. virtual void getExpiredLeases6(Lease6Collection& expired_leases,
  388. const size_t max_leases) const = 0;
  389. /// @brief Returns a collection of expired DHCPv4 leases.
  390. ///
  391. /// This method returns at most @c max_leases expired leases. The leases
  392. /// returned haven't been reclaimed, i.e. the database query must exclude
  393. /// reclaimed leases from the results returned.
  394. ///
  395. /// @param [out] expired_leases A container to which expired leases returned
  396. /// by the database backend are added.
  397. /// @param max_leases A maximum number of leases to be returned. If this
  398. /// value is set to 0, all expired (but not reclaimed) leases are returned.
  399. virtual void getExpiredLeases4(Lease4Collection& expired_leases,
  400. const size_t max_leases) const = 0;
  401. /// @brief Updates IPv4 lease.
  402. ///
  403. /// @param lease4 The lease to be updated.
  404. ///
  405. /// If no such lease is present, an exception will be thrown.
  406. virtual void updateLease4(const Lease4Ptr& lease4) = 0;
  407. /// @brief Updates IPv6 lease.
  408. ///
  409. /// @param lease6 The lease to be updated.
  410. virtual void updateLease6(const Lease6Ptr& lease6) = 0;
  411. /// @brief Deletes a lease.
  412. ///
  413. /// @param addr Address of the lease to be deleted. (This can be IPv4 or
  414. /// IPv6.)
  415. ///
  416. /// @return true if deletion was successful, false if no such lease exists
  417. virtual bool deleteLease(const isc::asiolink::IOAddress& addr) = 0;
  418. /// @brief Deletes all expired and reclaimed DHCPv4 leases.
  419. ///
  420. /// @param secs Number of seconds since expiration of leases before
  421. /// they can be removed. Leases which have expired later than this
  422. /// time will not be deleted.
  423. ///
  424. /// @return Number of leases deleted.
  425. virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) = 0;
  426. /// @brief Deletes all expired and reclaimed DHCPv6 leases.
  427. ///
  428. /// @param secs Number of seconds since expiration of leases before
  429. /// they can be removed. Leases which have expired later than this
  430. /// time will not be deleted.
  431. ///
  432. /// @return Number of leases deleted.
  433. virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) = 0;
  434. /// @brief Recalculates per-subnet and global stats for IPv4 leases
  435. ///
  436. /// This method recalculates the following statistics:
  437. /// per-subnet:
  438. /// - assigned-addresses
  439. /// - declined-addresses
  440. /// - declined-reclaimed-addresses (reset to zero)
  441. /// global:
  442. /// - declined-addresses
  443. /// - declined-reclaimed-addresses (reset to zero)
  444. ///
  445. /// It invokes the virtual method, startLeaseStatsQuery4(), which
  446. /// returns an instance of an LeaseStatsQuery. The query
  447. /// query contains a "result set" where each row is an LeaseStatRow
  448. /// that contains a subnet id, a lease type (currently always TYPE_NA),
  449. /// a lease state, and the number of leases of that type, in that state
  450. /// and is ordered by subnet id. The method iterates over the
  451. /// result set rows, setting the appropriate statistic per subnet and
  452. /// adding to the approporate global statistic.
  453. void recountLeaseStats4();
  454. /// @brief Virtual method which creates and runs the IPv4 lease stats query
  455. ///
  456. /// LeaseMgr derivations implement this method such that it creates and
  457. /// returns an instance of an LeaseStatsQuery whose result set has been
  458. /// populated with upto date IPv4 lease statistical data. Each row of the
  459. /// result set is an LeaseStatRow which ordered ascending by subnet ID.
  460. ///
  461. /// @return A populated LeaseStatsQuery
  462. virtual LeaseStatsQueryPtr startLeaseStatsQuery4();
  463. /// @brief Recalculates per-subnet and global stats for IPv6 leases
  464. ///
  465. /// This method recalculates the following statistics:
  466. /// per-subnet:
  467. /// - assigned-addresses
  468. /// - declined-addresses
  469. /// - declined-reclaimed-addresses (reset to zero)
  470. /// - assigned-pds
  471. /// global:
  472. /// - declined-addresses
  473. /// - declined-reclaimed-addresses (reset to zero)
  474. ///
  475. /// It invokes the virtual method, startLeaseStatsQuery6(), which
  476. /// returns an instance of an LeaseStatsQuery. The query contains
  477. /// a "result set" where each row is an LeaseStatRow that contains
  478. /// a subnet id, a lease type, a lease state, and the number of leases
  479. /// of that type, in that state and is ordered by subnet id. The method
  480. /// iterates over the result set rows, setting the appropriate statistic
  481. /// per subnet and adding to the approporate global statistic.
  482. void recountLeaseStats6();
  483. /// @brief Virtual method which creates and runs the IPv6 lease stats query
  484. ///
  485. /// LeaseMgr derivations implement this method such that it creates and
  486. /// returns an instance of an LeaseStatsQuery whose result set has been
  487. /// populated with upto date IPv6 lease statistical data. Each row of the
  488. /// result set is an LeaseStatRow which ordered ascending by subnet ID.
  489. ///
  490. /// @return A populated LeaseStatsQuery
  491. virtual LeaseStatsQueryPtr startLeaseStatsQuery6();
  492. /// @brief Return backend type
  493. ///
  494. /// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
  495. ///
  496. /// @return Type of the backend.
  497. virtual std::string getType() const = 0;
  498. /// @brief Returns backend name.
  499. ///
  500. /// If the backend is a database, this is the name of the database or the
  501. /// file. Otherwise it is just the same as the type.
  502. ///
  503. /// @return Name of the backend.
  504. virtual std::string getName() const = 0;
  505. /// @brief Returns description of the backend.
  506. ///
  507. /// This description may be multiline text that describes the backend.
  508. ///
  509. /// @return Description of the backend.
  510. virtual std::string getDescription() const = 0;
  511. /// @brief Returns backend version.
  512. ///
  513. /// @return Version number as a pair of unsigned integers. "first" is the
  514. /// major version number, "second" the minor number.
  515. ///
  516. /// @todo: We will need to implement 3 version functions eventually:
  517. /// A. abstract API version
  518. /// B. backend version
  519. /// C. database version (stored in the database scheme)
  520. ///
  521. /// and then check that:
  522. /// B>=A and B=C (it is ok to have newer backend, as it should be backward
  523. /// compatible)
  524. /// Also if B>C, some database upgrade procedure may be triggered
  525. virtual std::pair<uint32_t, uint32_t> getVersion() const = 0;
  526. /// @brief Commit Transactions
  527. ///
  528. /// Commits all pending database operations. On databases that don't
  529. /// support transactions, this is a no-op.
  530. virtual void commit() = 0;
  531. /// @brief Rollback Transactions
  532. ///
  533. /// Rolls back all pending database operations. On databases that don't
  534. /// support transactions, this is a no-op.
  535. virtual void rollback() = 0;
  536. /// @todo: Add host management here
  537. /// As host reservation is outside of scope for 2012, support for hosts
  538. /// is currently postponed.
  539. };
  540. }; // end of isc::dhcp namespace
  541. }; // end of isc namespace
  542. #endif // LEASE_MGR_H