// If I'm still alive I'll be too old to care. You fix it.
static const time_t MAX_DB_TIME;
- /// Database configuration parameter map
- typedef std::map<std::string, std::string> ParameterMap;
-
/// @brief Constructor
///
- /// @param parameters A data structure relating keywords and values
- /// concerned with the database.
- LeaseMgr(const ParameterMap& parameters)
- : parameters_(parameters)
- LeaseMgr() : io_service_(new asiolink::IOService())
++ LeaseMgr()
{}
/// @brief Destructor
/// @todo: Add host management here
/// As host reservation is outside of scope for 2012, support for hosts
/// is currently postponed.
--
- /// @brief returns value of the parameter
- virtual std::string getParameter(const std::string& name) const;
--
- private:
- /// @brief list of parameters passed in dbconfig
- /// @brief Returns the interval at which the @c IOService events should
- /// be released.
-- ///
- /// 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.
- ParameterMap parameters_;
- /// The implementations of this class may install the timers which
- /// periodically trigger event handlers defined for them. Depending
- /// on the intervals specified for these timers the @c IOService::poll,
- /// @c IOService::run etc. have to be executed to allow the timers
- /// for checking whether they have already expired and the handler
- /// must be executed. Running the @c IOService with a lower interval
- /// would cause the desynchronization of timers with the clock.
- ///
- /// @return A maximum interval in seconds at which the @c IOService
- /// should be executed. A value of 0 means that no timers are installed
- /// and that there is no requirement for the @c IOService to be
- /// executed at any specific interval.
- virtual uint32_t getIOServiceExecInterval() const {
- return (0);
- }
-
- /// @brief Returns a reference to the @c IOService object used
- /// by the Lease Manager.
- const asiolink::IOServicePtr& getIOService() const {
- return (io_service_);
- }
-
-
-private:
-
- /// @brief Pointer to the IO service object used by the derived classes
- /// to trigger interval timers.
- asiolink::IOServicePtr io_service_;
-
};
}; // end of isc::dhcp namespace
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_file_loader.h>
#include <dhcpsrv/memfile_lease_mgr.h>
+#include <dhcpsrv/timer_mgr.h>
+ #include <dhcpsrv/database_connection.h>
#include <exceptions/exceptions.h>
#include <util/pid_file.h>
#include <util/process_spawn.h>
return (process_->getExitStatus(pid_));
}
-Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters):
- lfc_setup_(new LFCSetup(boost::bind(&Memfile_LeaseMgr::lfcCallback, this),
- *getIOService())),
- conn_(parameters)
+// Explicit definition of class static constants. Values are given in the
+// declaration so they're not needed here.
+const int Memfile_LeaseMgr::MAJOR_VERSION;
+const int Memfile_LeaseMgr::MINOR_VERSION;
+
- Memfile_LeaseMgr::Memfile_LeaseMgr(const ParameterMap& parameters)
- : LeaseMgr(parameters), lfc_setup_()
++Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters)
++ : LeaseMgr(), lfc_setup_(), conn_(parameters)
{
// Check the universe and use v4 file or v6 file.
- std::string universe = getParameter("universe");
+ std::string universe = conn_.getParameter("universe");
if (universe == "4") {
std::string file4 = initLeaseFilePath(V4);
if (!file4.empty()) {
Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
std::string persist_val;
try {
- persist_val = getParameter("persist");
+ persist_val = conn_.getParameter("persist");
- } catch (const Exception& ex) {
+ } catch (const Exception&) {
// If parameter persist hasn't been specified, we use a default value
// 'yes'.
persist_val = "true";
std::string lease_file;
try {
- lease_file = getParameter("name");
+ lease_file = conn_.getParameter("name");
- } catch (const Exception& ex) {
+ } catch (const Exception&) {
lease_file = getDefaultLeaseFilePath(u);
}
return (lease_file);
Memfile_LeaseMgr::lfcSetup() {
std::string lfc_interval_str = "0";
try {
- lfc_interval_str = getParameter("lfc-interval");
+ lfc_interval_str = conn_.getParameter("lfc-interval");
- } catch (const std::exception& ex) {
+ } catch (const std::exception&) {
// Ignore and default to 0.
}
"UPDATE schema_version SET version=\"2\", minor=\"0\";",
// Schema upgrade to 2.0 ends here.
+ // Schema upgrade to 3.0 starts here.
+
+ "CREATE TABLE IF NOT EXISTS hosts ("
+ "host_id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+ "dhcp_identifier VARBINARY(128) NOT NULL,"
+ "dhcp_identifier_type TINYINT NOT NULL,"
+ "dhcp4_subnet_id INT UNSIGNED NULL,"
+ "dhcp6_subnet_id INT UNSIGNED NULL,"
+ "ipv4_address INT UNSIGNED NULL,"
+ "hostname VARCHAR(255) NULL,"
+ "dhcp4_client_classes VARCHAR(255) NULL,"
+ "dhcp6_client_classes VARCHAR(255) NULL,"
+ "PRIMARY KEY (host_id),"
+ "INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC),"
+ "INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC , dhcp6_subnet_id ASC)"
+ ") ENGINE=INNODB",
+
+ "CREATE TABLE IF NOT EXISTS ipv6_reservations ("
+ "reservation_id INT NOT NULL AUTO_INCREMENT,"
+ "address VARCHAR(39) NOT NULL,"
+ "prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128,"
+ "type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0,"
+ "dhcp6_iaid INT UNSIGNED NULL,"
+ "host_id INT UNSIGNED NOT NULL,"
+ "PRIMARY KEY (reservation_id),"
+ "INDEX fk_ipv6_reservations_host_idx (host_id ASC),"
+ "CONSTRAINT fk_ipv6_reservations_Host FOREIGN KEY (host_id)"
+ "REFERENCES hosts (host_id)"
+ "ON DELETE NO ACTION ON UPDATE NO ACTION"
+ ") ENGINE=INNODB",
+
+ "CREATE TABLE IF NOT EXISTS dhcp4_options ("
+ "option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+ "code TINYINT UNSIGNED NOT NULL,"
+ "value BLOB NULL,"
+ "formatted_value TEXT NULL,"
+ "space VARCHAR(128) NULL,"
+ "persistent TINYINT(1) NOT NULL DEFAULT 0,"
+ "dhcp_client_class VARCHAR(128) NULL,"
+ "dhcp4_subnet_id INT NULL,"
+ "host_id INT UNSIGNED NULL,"
+ "PRIMARY KEY (option_id),"
+ "UNIQUE INDEX option_id_UNIQUE (option_id ASC),"
+ "INDEX fk_options_host1_idx (host_id ASC),"
+ "CONSTRAINT fk_options_host1 FOREIGN KEY (host_id)"
+ "REFERENCES hosts (host_id)"
+ "ON DELETE NO ACTION ON UPDATE NO ACTION"
+ ") ENGINE=INNODB",
+
+ "CREATE TABLE IF NOT EXISTS dhcp6_options ("
+ "option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+ "code INT UNSIGNED NOT NULL,"
+ "value BLOB NULL,"
+ "formatted_value TEXT NULL,"
+ "space VARCHAR(128) NULL,"
+ "persistent TINYINT(1) NOT NULL DEFAULT 0,"
+ "dhcp_client_class VARCHAR(128) NULL,"
+ "dhcp6_subnet_id INT NULL,"
+ "host_id INT UNSIGNED NULL,"
+ "PRIMARY KEY (option_id),"
+ "UNIQUE INDEX option_id_UNIQUE (option_id ASC),"
+ "INDEX fk_options_host1_idx (host_id ASC),"
+ "CONSTRAINT fk_options_host10 FOREIGN KEY (host_id)"
+ "REFERENCES hosts (host_id)"
+ "ON DELETE NO ACTION ON UPDATE NO ACTION"
+ ") ENGINE=INNODB",
+
+
+ //"DELIMITER $$ ",
+ "CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW "
+ "BEGIN "
+ "DELETE FROM ipv6_reservations WHERE ipv6_reservations.host_id = OLD.host_id; "
+ "END ",
+ //"$$ ",
+ //"DELIMITER ;",
+
+ "UPDATE schema_version SET version = '3', minor = '0';",
+
+ // This line concludes database upgrade to version 3.0.
+
+ // Schema upgrade to 4.0 starts here.
+ "ALTER TABLE lease4 "
+ "ADD COLUMN state INT UNSIGNED DEFAULT 0",
+
+ "ALTER TABLE lease6 "
+ "ADD COLUMN state INT UNSIGNED DEFAULT 0",
+
+ "CREATE INDEX lease4_by_state_expire ON lease4 (state, expire)",
+ "CREATE INDEX lease6_by_state_expire ON lease6 (state, expire)",
+
+ // Production schema includes the lease_state table which maps
+ // the lease states to their names. This is not used in the unit tests
+ // so it is commented out.
+
+ /*"CREATE TABLE IF NOT EXISTS lease_state (",
+ "state INT UNSIGNED PRIMARY KEY NOT NULL,"
+ "name VARCHAR(64) NOT NULL);",
+
+ "INSERT INTO lease_state VALUES (0, \"default\");",
+ "INSERT INTO lease_state VALUES (1, \"declined\");",
+ "INSERT INTO lease_state VALUES (2, \"expired-reclaimed\");",*/
+
+
+ // Schema upgrade to 4.0 ends here.
+
NULL
};