lease_mgr.h 24.2 KB
Newer Older
1
// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

15 16
#ifndef LEASE_MGR_H
#define LEASE_MGR_H
17

18
#include <asiolink/io_address.h>
19
#include <dhcp/duid.h>
20
#include <dhcp/option.h>
21
#include <dhcp/hwaddr.h>
22
#include <dhcpsrv/subnet.h>
23 24 25 26 27
#include <exceptions/exceptions.h>

#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>

28
#include <fstream>
29
#include <iostream>
30
#include <map>
31 32 33 34
#include <string>
#include <utility>
#include <vector>

35
/// @file lease_mgr.h
36 37 38 39 40 41 42 43 44 45 46
/// @brief An abstract API for lease database
///
/// This file contains declarations of Lease4, Lease6 and LeaseMgr classes.
/// They are essential components of the interface to any database backend.
/// Each concrete database backend (e.g. MySQL) will define a class derived
/// from LeaseMgr class.
///
/// Failover considerations:
/// There are no intermediate plans to implement DHCPv4 failover
/// (draft-ietf-dhc-failover-12.txt). Currently (Oct. 2012) the DHCPv6 failover
/// is being defined in DHC WG in IETF (draft-ietf-dhcpv6-failover-requirements,
47
/// draft-ietf-dhcpv6-failover-design), but the work is not advanced enough
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/// for implementation plans yet. v4 failover requires additional parameters
/// to be kept with a lease. It is likely that v6 failover will require similar
/// fields. Such implementation will require database schema extension.
/// We have designed a way to expand/upgrade schemas during upgrades: a database
/// schema is versioned and sanity checks about required version will be done
/// upon start and/or upgrade. With this mechanism in place, we can add new
/// fields to the database. In particular we can use that capability to
/// introduce failover related fields.
///
/// However, there is another approach that can be reliably used to provide
/// failover, even without the actual failover protocol implemented. As the
/// first backend will use MySQL, we will be able to use Multi-Master capability
/// offered by MySQL and use two separatate Kea instances connecting to the
/// same database.
///
/// Nevertheless, we hope to have failover protocol eventually implemented in
/// the Kea.

66 67 68
namespace isc {
namespace dhcp {

69 70 71 72 73 74 75
/// @brief Exception thrown if name of database is not specified
class NoDatabaseName : public Exception {
public:
    NoDatabaseName(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) {}
};

76 77
/// @brief Exception thrown on failure to open database
class DbOpenError : public Exception {
78
public:
79 80 81 82
    DbOpenError(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) {}
};

83 84 85 86 87 88 89
/// @brief Exception thrown on failure to execute a database function
class DbOperationError : public Exception {
public:
    DbOperationError(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) {}
};

90 91 92 93 94 95 96
/// @brief Multiple lease records found where one expected
class MultipleRecords : public Exception {
public:
    MultipleRecords(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) {}
};

97 98 99 100 101 102 103
/// @brief Attempt to update lease that was not there
class NoSuchLease : public Exception {
public:
    NoSuchLease(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) {}
};

104 105 106 107 108 109 110
/// @brief Data is truncated
class DataTruncated : public Exception {
public:
    DataTruncated(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) {}
};

111
/// @brief a common structure for IPv4 and IPv6 leases
112
///
113 114 115
/// This structure holds all information that is common between IPv4 and IPv6
/// leases.
struct Lease {
116

117 118 119 120 121 122 123 124
    /// @brief Constructor
    ///
    /// @param addr IP address
    /// @param t1 renewal time
    /// @param t2 rebinding time
    /// @param valid_lft Lifetime of the lease
    /// @param subnet_id Subnet identification
    /// @param cltt Client last transmission time
125 126 127
    /// @param fqdn_fwd If true, forward DNS update is performed for a lease.
    /// @param fqdn_rev If true, reverse DNS update is performed for a lease.
    /// @param hostname FQDN of the client which gets the lease.
128
    Lease(const isc::asiolink::IOAddress& addr, uint32_t t1, uint32_t t2,
129 130 131
          uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
          const bool fqdn_fwd, const bool fqdn_rev,
          const std::string& hostname);
132

133
    /// @brief Destructor
134
    virtual ~Lease() {}
135

136
    /// @brief IPv4 ot IPv6 address
137
    ///
138 139
    /// IPv4, IPv6 address or, in the case of a prefix delegation, the prefix.
    isc::asiolink::IOAddress addr_;
140

141
    /// @brief Renewal timer
142
    ///
143 144 145 146 147
    /// Specifies renewal time. Although technically it is a property of the
    /// IA container and not the address itself, since our data model does not
    /// define a separate IA entity, we are keeping it in the lease. In the
    /// case of multiple addresses/prefixes for the same IA, each must have
    /// consistent T1 and T2 values. This is specified in seconds since cltt.
148 149
    uint32_t t1_;

150
    /// @brief Rebinding timer
151
    ///
152 153 154 155
    /// Specifies rebinding time. Although technically it is a property of the
    /// IA container and not the address itself, since our data model does not
    /// define a separate IA entity, we are keeping it in the lease. In the
    /// case of multiple addresses/prefixes for the same IA, each must have
156
    /// consistent T1 and T2 values. This is specified in seconds since cltt.
157 158
    uint32_t t2_;

159
    /// @brief Valid lifetime
160
    ///
161
    /// Expressed as number of seconds since cltt.
162
    uint32_t valid_lft_;
163

164
    /// @brief Client last transmission time
165
    ///
166 167
    /// Specifies a timestamp giving the time when the last transmission from a
    /// client was received.
168
    time_t cltt_;
169

170
    /// @brief Subnet identifier
171
    ///
172
    /// Specifies the identification of the subnet to which the lease belongs.
173
    SubnetID subnet_id_;
174

175
    /// @brief Fixed lease?
176 177
    ///
    /// Fixed leases are kept after they are released/expired.
178
    bool fixed_;
179

180
    /// @brief Client hostname
181 182
    ///
    /// This field may be empty
183
    std::string hostname_;
184

185 186 187
    /// @brief Forward zone updated?
    ///
    /// Set true if the DNS AAAA record for this lease has been updated.
188
    bool fqdn_fwd_;
189

190 191 192
    /// @brief Reverse zone updated?
    ///
    /// Set true if the DNS PTR record for this lease has been updated.
193
    bool fqdn_rev_;
194

195
    /// @brief Lease comments
196 197 198
    ///
    /// Currently not used. It may be used for keeping comments made by the
    /// system administrator.
199
    std::string comments_;
200

201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
    /// @brief Convert Lease to Printable Form
    ///
    /// @return String form of the lease
    virtual std::string toText() const = 0;

    /// @brief returns true if the lease is expired
    /// @return true if the lease is expired
    bool expired() const;

};

/// @brief Structure that holds a lease for IPv4 address
///
/// For performance reasons it is a simple structure, not a class. If we chose
/// make it a class, all fields would have to made private and getters/setters
/// would be required. As this is a critical part of the code that will be used
/// extensively, direct access is warranted.
struct Lease4 : public Lease {

    /// @brief Address extension
    ///
    /// It is envisaged that in some cases IPv4 address will be accompanied
    /// with some additional data. One example of such use are Address + Port
    /// solutions (or Port-restricted Addresses), where several clients may get
    /// the same address, but different port ranges. This feature is not
    /// expected to be widely used.  Under normal circumstances, the value
    /// should be 0.
    uint32_t ext_;

    /// @brief Hardware address
    std::vector<uint8_t> hwaddr_;

    /// @brief Client identifier
    ///
    /// @todo Should this be a pointer to a client ID or the ID itself?
    ///       Compare with the DUID in the Lease6 structure.
    ClientIdPtr client_id_;

239 240
    /// @brief Constructor
    ///
241
    /// @param addr IPv4 address.
242 243 244 245 246
    /// @param hwaddr Hardware address buffer
    /// @param hwaddr_len Length of hardware address buffer
    /// @param clientid Client identification buffer
    /// @param clientid_len Length of client identification buffer
    /// @param valid_lft Lifetime of the lease
247 248
    /// @param t1 renewal time
    /// @param t2 rebinding time
249 250
    /// @param cltt Client last transmission time
    /// @param subnet_id Subnet identification
251 252 253
    /// @param fqdn_fwd If true, forward DNS update is performed for a lease.
    /// @param fqdn_rev If true, reverse DNS update is performed for a lease.
    /// @param hostname FQDN of the client which gets the lease.
254
    Lease4(const isc::asiolink::IOAddress& addr, const uint8_t* hwaddr, size_t hwaddr_len,
255
           const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
256 257 258 259 260
           uint32_t t1, uint32_t t2, time_t cltt, uint32_t subnet_id,
           const bool fqdn_fwd = false, const bool fqdn_rev = false,
           const std::string& hostname = "")
        : Lease(addr, t1, t2, valid_lft, subnet_id, cltt, fqdn_fwd, fqdn_rev,
                hostname),
261 262 263 264
        ext_(0), hwaddr_(hwaddr, hwaddr + hwaddr_len) {
        if (clientid_len) {
            client_id_.reset(new ClientId(clientid, clientid_len));
        }
265
    }
266

267
    /// @brief Default constructor
268 269
    ///
    /// Initialize fields that don't have a default constructor.
270
    Lease4() : Lease(0, 0, 0, 0, 0, 0, false, false, "") {
271
    }
272

273 274 275 276 277 278 279 280 281 282
    /// @brief Copy constructor
    ///
    /// @param other the @c Lease4 object to be copied.
    Lease4(const Lease4& other);

    /// @brief Assignment operator.
    ///
    /// @param other the @c Lease4 object to be assigned.
    Lease4& operator=(const Lease4& other);

283 284 285 286 287 288 289 290 291 292 293 294
    /// @brief Compare two leases for equality
    ///
    /// @param other lease6 object with which to compare
    bool operator==(const Lease4& other) const;

    /// @brief Compare two leases for inequality
    ///
    /// @param other lease6 object with which to compare
    bool operator!=(const Lease4& other) const {
        return (!operator==(other));
    }

295
    /// @brief Convert lease to printable form
296
    ///
297
    /// @return Textual represenation of lease data
298 299
    virtual std::string toText() const;

300
    /// @todo: Add DHCPv4 failover related fields here
301 302 303 304 305
};

/// @brief Pointer to a Lease4 structure.
typedef boost::shared_ptr<Lease4> Lease4Ptr;

306
/// @brief A collection of IPv4 leases.
307
typedef std::vector<Lease4Ptr> Lease4Collection;
308

309 310


311 312
/// @brief Structure that holds a lease for IPv6 address and/or prefix
///
313 314
/// For performance reasons it is a simple structure, not a class. If we chose
/// make it a class, all fields would have to made private and getters/setters
315
/// would be required. As this is a critical part of the code that will be used
316
/// extensively, direct access is warranted.
317
struct Lease6 : public Lease {
318 319

    /// @brief Type of lease contents
320
    typedef enum {
321 322 323
        LEASE_IA_NA = 0, /// the lease contains non-temporary IPv6 address
        LEASE_IA_TA = 1, /// the lease contains temporary IPv6 address
        LEASE_IA_PD = 2  /// the lease contains IPv6 prefix (for prefix delegation)
324 325
    } LeaseType;

326 327 328 329 330 331 332 333
    /// @brief Lease type
    ///
    /// One of normal address, temporary address, or prefix.
    LeaseType type_;

    /// @brief IPv6 prefix length
    ///
    /// This is used only for prefix delegations and is ignored otherwise.
334 335
    uint8_t prefixlen_;

336
    /// @brief Identity Association Identifier (IAID)
337
    ///
338
    /// DHCPv6 stores all addresses and prefixes in IA containers (IA_NA,
339
    /// IA_TA, IA_PD). All containers may appear more than once in a message.
340
    /// To differentiate between them, the IAID field is present
341 342
    uint32_t iaid_;

343
    /// @brief Client identifier
344
    DuidPtr duid_;
345 346 347

    /// @brief preferred lifetime
    ///
348 349
    /// This parameter specifies the preferred lifetime since the lease was
    /// assigned or renewed (cltt), expressed in seconds.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
350
    uint32_t preferred_lft_;
351

352
    /// @todo: Add DHCPv6 failover related fields here
353

354
    /// @brief Constructor
355 356 357 358 359 360 361 362 363 364
    /// @param type Lease type.
    /// @param addr Assigned address.
    /// @param duid A pointer to an object representing DUID.
    /// @param iaid IAID.
    /// @param preferred Preferred lifetime.
    /// @param valid Valid lifetime.
    /// @param t1 A value of the T1 timer.
    /// @param t2 A value of the T2 timer.
    /// @param subnet_id A Subnet identifier.
    /// @param prefixlen An address prefix length.
365 366
    Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
           uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
           uint32_t t2, SubnetID subnet_id, uint8_t prefixlen = 0);

    /// @brief Constructor, including FQDN data.
    ///
    /// @param type Lease type.
    /// @param addr Assigned address.
    /// @param duid A pointer to an object representing DUID.
    /// @param iaid IAID.
    /// @param preferred Preferred lifetime.
    /// @param valid Valid lifetime.
    /// @param t1 A value of the T1 timer.
    /// @param t2 A value of the T2 timer.
    /// @param subnet_id A Subnet identifier.
    /// @param fqdn_fwd If true, forward DNS update is performed for a lease.
    /// @param fqdn_rev If true, reverse DNS update is performed for a lease.
    /// @param hostname FQDN of the client which gets the lease.
    /// @param prefixlen An address prefix length.
    Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
           uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
           uint32_t t2, SubnetID subnet_id, const bool fqdn_fwd,
           const bool fqdn_rev, const std::string& hostname,
           uint8_t prefixlen = 0);
389

390 391 392
    /// @brief Constructor
    ///
    /// Initialize fields that don't have a default constructor.
393 394
    Lease6() : Lease(isc::asiolink::IOAddress("::"), 0, 0, 0, 0, 0,
                     false, false, ""),
395 396
        type_(LEASE_IA_NA) {
    }
397

398 399 400 401 402 403 404 405 406 407 408
    /// @brief Compare two leases for equality
    ///
    /// @param other lease6 object with which to compare
    bool operator==(const Lease6& other) const;

    /// @brief Compare two leases for inequality
    ///
    /// @param other lease6 object with which to compare
    bool operator!=(const Lease6& other) const {
        return (!operator==(other));
    }
409 410 411 412 413

    /// @brief Convert Lease to Printable Form
    ///
    /// @return String form of the lease
    virtual std::string toText() const;
414 415 416 417 418
};

/// @brief Pointer to a Lease6 structure.
typedef boost::shared_ptr<Lease6> Lease6Ptr;

Stephen Morris's avatar
Stephen Morris committed
419
/// @brief Pointer to a const Lease6 structure.
420 421
typedef boost::shared_ptr<const Lease6> ConstLease6Ptr;

422
/// @brief A collection of IPv6 leases.
423
typedef std::vector<Lease6Ptr> Lease6Collection;
424

425
/// @brief Abstract Lease Manager
426
///
427 428 429 430
/// This is an abstract API for lease database backends. It provides unified
/// interface to all backends. As this is an abstract class, it should not
/// be used directly, but rather specialized derived class should be used
/// instead.
431 432 433 434
///
/// As all methods are virtual, this class throws no exceptions.  However,
/// methods in concrete implementations of this class may throw exceptions:
/// see the documentation of those classes for details.
435 436
class LeaseMgr {
public:
437 438 439
    /// Database configuration parameter map
    typedef std::map<std::string, std::string> ParameterMap;

440
    /// @brief Constructor
441
    ///
442 443
    /// @param parameters A data structure relating keywords and values
    ///        concerned with the database.
444 445
    LeaseMgr(const ParameterMap& parameters) : parameters_(parameters)
    {}
446

447
    /// @brief Destructor
448 449
    virtual ~LeaseMgr()
    {}
450

451
    /// @brief Adds an IPv4 lease.
452 453
    ///
    /// @param lease lease to be added
454 455 456 457
    ///
    /// @result true if the lease was added, false if not (because a lease
    ///         with the same address was already there).
    virtual bool addLease(const Lease4Ptr& lease) = 0;
458

459
    /// @brief Adds an IPv6 lease.
460 461
    ///
    /// @param lease lease to be added
462 463 464 465
    ///
    /// @result true if the lease was added, false if not (because a lease
    ///         with the same address was already there).
    virtual bool addLease(const Lease6Ptr& lease) = 0;
466

467 468 469 470 471 472 473 474
    /// @brief Returns an IPv4 lease for specified IPv4 address
    ///
    /// This method return a lease that is associated with a given address.
    /// For other query types (by hardware addr, by client-id) there can be
    /// several leases in different subnets (e.g. for mobile clients that
    /// got address in different subnets). However, for a single address
    /// there can be only one lease, so this method returns a pointer to
    /// a single lease, not a container of leases.
475 476 477
    ///
    /// @param addr address of the searched lease
    ///
478
    /// @return smart pointer to the lease (or NULL if a lease is not found)
479
    virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const = 0;
480

481 482 483 484 485 486
    /// @brief Returns existing IPv4 leases for specified hardware address.
    ///
    /// Although in the usual case there will be only one lease, for mobile
    /// clients or clients with multiple static/fixed/reserved leases there
    /// can be more than one. Thus return type is a container, not a single
    /// pointer.
487 488 489
    ///
    /// @param hwaddr hardware address of the client
    ///
490
    /// @return lease collection
491
    virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const = 0;
492 493 494 495 496 497 498 499 500 501 502

    /// @brief Returns existing IPv4 leases for specified hardware address
    ///        and a subnet
    ///
    /// There can be at most one lease for a given HW address in a single
    /// pool, so this method with either return a single lease or NULL.
    ///
    /// @param hwaddr hardware address of the client
    /// @param subnet_id identifier of the subnet that lease must belong to
    ///
    /// @return a pointer to the lease (or NULL if a lease is not found)
503
    virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr,
504
                                SubnetID subnet_id) const = 0;
505

506 507
    /// @brief Returns existing IPv4 lease for specified client-id
    ///
508 509 510 511 512
    /// Although in the usual case there will be only one lease, for mobile
    /// clients or clients with multiple static/fixed/reserved leases there
    /// can be more than one. Thus return type is a container, not a single
    /// pointer.
    ///
513
    /// @param clientid client identifier
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
    ///
    /// @return lease collection
    virtual Lease4Collection getLease4(const ClientId& clientid) const = 0;

    /// @brief Returns existing IPv4 lease for specified client-id
    ///
    /// There can be at most one lease for a given HW address in a single
    /// pool, so this method with either return a single lease or NULL.
    ///
    /// @param clientid client identifier
    /// @param subnet_id identifier of the subnet that lease must belong to
    ///
    /// @return a pointer to the lease (or NULL if a lease is not found)
    virtual Lease4Ptr getLease4(const ClientId& clientid,
                                SubnetID subnet_id) const = 0;
529

530
    /// @brief Returns existing IPv6 lease for a given IPv6 address.
531
    ///
532
    /// For a given address, we assume that there will be only one lease.
533
    /// The assumption here is that there will not be site or link-local
534 535
    /// addresses used, so there is no way of having address duplication.
    ///
536
    /// @param type specifies lease type: (NA, TA or PD)
537 538
    /// @param addr address of the searched lease
    ///
539
    /// @return smart pointer to the lease (or NULL if a lease is not found)
540 541
    virtual Lease6Ptr getLease6(Lease6::LeaseType type,
                                const isc::asiolink::IOAddress& addr) const = 0;
542

543 544 545 546 547 548 549
    /// @brief Returns existing IPv6 leases for a given DUID+IA combination
    ///
    /// Although in the usual case there will be only one lease, for mobile
    /// clients or clients with multiple static/fixed/reserved leases there
    /// can be more than one. Thus return type is a container, not a single
    /// pointer.
    ///
550
    /// @param type specifies lease type: (NA, TA or PD)
551 552 553 554
    /// @param duid client DUID
    /// @param iaid IA identifier
    ///
    /// @return smart pointer to the lease (or NULL if a lease is not found)
555
    virtual Lease6Collection getLease6(Lease6::LeaseType type, const DUID& duid,
556 557
                                       uint32_t iaid) const = 0;

558 559
    /// @brief Returns existing IPv6 lease for a given DUID+IA combination
    ///
560
    /// @param type specifies lease type: (NA, TA or PD)
561 562
    /// @param duid client DUID
    /// @param iaid IA identifier
563
    /// @param subnet_id subnet id of the subnet the lease belongs to
564 565
    ///
    /// @return smart pointer to the lease (or NULL if a lease is not found)
566 567
    virtual Lease6Ptr getLease6(Lease6::LeaseType type, const DUID& duid,
                                uint32_t iaid, SubnetID subnet_id) const = 0;
568

569 570 571 572 573
    /// @brief Updates IPv4 lease.
    ///
    /// @param lease4 The lease to be updated.
    ///
    /// If no such lease is present, an exception will be thrown.
574
    virtual void updateLease4(const Lease4Ptr& lease4) = 0;
575

Marcin Siodelski's avatar
Marcin Siodelski committed
576
    /// @brief Updates IPv6 lease.
577
    ///
Marcin Siodelski's avatar
Marcin Siodelski committed
578
    /// @param lease6 The lease to be updated.
579
    virtual void updateLease6(const Lease6Ptr& lease6) = 0;
580 581 582

    /// @brief Deletes a lease.
    ///
583 584
    /// @param addr Address of the lease to be deleted. (This can be IPv4 or
    ///        IPv6.)
585 586
    ///
    /// @return true if deletion was successful, false if no such lease exists
587
    virtual bool deleteLease(const isc::asiolink::IOAddress& addr) = 0;
588

589 590 591 592 593 594 595
    /// @brief Return backend type
    ///
    /// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
    ///
    /// @return Type of the backend.
    virtual std::string getType() const = 0;

596 597
    /// @brief Returns backend name.
    ///
598 599 600 601
    /// If the backend is a database, this is the name of the database or the
    /// file.  Otherwise it is just the same as the type.
    ///
    /// @return Name of the backend.
602
    virtual std::string getName() const = 0;
603

604 605 606
    /// @brief Returns description of the backend.
    ///
    /// This description may be multiline text that describes the backend.
607 608
    ///
    /// @return Description of the backend.
609
    virtual std::string getDescription() const = 0;
610

611
    /// @brief Returns backend version.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
612
    ///
613 614 615
    /// @return Version number as a pair of unsigned integers.  "first" is the
    ///         major version number, "second" the minor number.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
616 617 618 619 620 621 622 623
    /// @todo: We will need to implement 3 version functions eventually:
    /// A. abstract API version
    /// B. backend version
    /// C. database version (stored in the database scheme)
    ///
    /// and then check that:
    /// B>=A and B=C (it is ok to have newer backend, as it should be backward
    /// compatible)
624
    /// Also if B>C, some database upgrade procedure may be triggered
625
    virtual std::pair<uint32_t, uint32_t> getVersion() const = 0;
626

627 628 629 630 631 632 633 634 635 636 637 638
    /// @brief Commit Transactions
    ///
    /// Commits all pending database operations.  On databases that don't
    /// support transactions, this is a no-op.
    virtual void commit() = 0;

    /// @brief Rollback Transactions
    ///
    /// Rolls back all pending database operations.  On databases that don't
    /// support transactions, this is a no-op.
    virtual void rollback() = 0;

639
    /// @todo: Add host management here
Tomek Mrugalski's avatar
Tomek Mrugalski committed
640 641 642 643
    /// As host reservation is outside of scope for 2012, support for hosts
    /// is currently postponed.

    /// @brief returns value of the parameter
644
    virtual std::string getParameter(const std::string& name) const;
645

646
private:
647
    /// @brief list of parameters passed in dbconfig
Tomek Mrugalski's avatar
Tomek Mrugalski committed
648 649 650 651
    ///
    /// That will be mostly used for storing database name, username,
    /// password and other parameters required for DB access. It is not
    /// intended to keep any DHCP-related parameters.
652
    ParameterMap parameters_;
653
};
654 655 656

}; // end of isc::dhcp namespace
}; // end of isc namespace
657

658
#endif // LEASE_MGR_H