22#include <boost/foreach.hpp>
39const char* KEA_LFC_EXECUTABLE_ENV_NAME =
"KEA_LFC_EXECUTABLE";
94 void setup(
const uint32_t lfc_interval,
95 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
96 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
97 bool run_once_now =
false);
114 boost::scoped_ptr<ProcessSpawn> process_;
130 : process_(), callback_(callback), pid_(0),
146 timer_mgr_->unregisterTimer(
"memfile-lfc");
148 }
catch (
const std::exception& ex) {
159 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
160 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
164 if (lfc_interval == 0 && !run_once_now) {
169 std::string executable;
170 char* c_executable = getenv(KEA_LFC_EXECUTABLE_ENV_NAME);
172 executable = KEA_LFC_EXECUTABLE;
174 executable = c_executable;
178 std::string lease_file = lease_file4 ? lease_file4->getFilename() :
179 lease_file6->getFilename();
184 args.push_back(lease_file4 ?
"-4" :
"-6");
187 args.push_back(
"-x");
191 args.push_back(
"-i");
195 args.push_back(
"-o");
199 args.push_back(
"-f");
203 args.push_back(
"-p");
208 args.push_back(
"-c");
209 args.push_back(
"ignored-path");
221 if (lfc_interval > 0) {
228 timer_mgr_->registerTimer(
"memfile-lfc", callback_, lfc_interval * 1000,
230 timer_mgr_->setup(
"memfile-lfc");
238 .arg(process_->getCommandLine());
239 pid_ = process_->spawn();
248 return (process_ && process_->isRunning(pid_));
255 " the process is null");
257 return (process_->getExitStatus(pid_));
316 return (
rows_.size());
412 void startSubnets() {
417 Lease4StorageSubnetIdIndex::const_iterator lower;
418 Lease4StorageSubnetIdIndex::const_iterator upper;
441 if (lower == upper) {
449 int64_t assigned = 0;
450 int64_t declined = 0;
451 for (Lease4StorageSubnetIdIndex::const_iterator lease = lower;
452 lease != upper; ++lease) {
455 if ((*lease)->subnet_id_ != cur_id) {
458 rows_.push_back(LeaseStatsRow(cur_id,
465 rows_.push_back(LeaseStatsRow(cur_id,
473 cur_id = (*lease)->subnet_id_;
513 void startSubnetPools() {
515 = storage4_.get<SubnetIdPoolIdIndexTag>();
518 Lease4StorageSubnetIdPoolIdIndex::const_iterator lower;
519 Lease4StorageSubnetIdPoolIdIndex::const_iterator upper;
531 if (lower == upper) {
539 uint32_t cur_pool_id = 0;
540 int64_t assigned = 0;
541 int64_t declined = 0;
542 for (Lease4StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
543 lease != upper; ++lease) {
546 if ((*lease)->pool_id_ != cur_pool_id) {
548 rows_.push_back(LeaseStatsRow(cur_id,
550 assigned, cur_pool_id));
555 rows_.push_back(LeaseStatsRow(cur_id,
557 declined, cur_pool_id));
562 cur_pool_id = (*lease)->pool_id_;
567 if ((*lease)->subnet_id_ != cur_id) {
570 rows_.push_back(LeaseStatsRow(cur_id,
572 assigned, cur_pool_id));
577 rows_.push_back(LeaseStatsRow(cur_id,
579 declined, cur_pool_id));
585 cur_id = (*lease)->subnet_id_;
602 assigned, cur_pool_id));
607 declined, cur_pool_id));
706 virtual void startSubnets() {
711 Lease6StorageSubnetIdIndex::const_iterator lower;
712 Lease6StorageSubnetIdIndex::const_iterator upper;
734 if (lower == upper) {
742 int64_t assigned = 0;
743 int64_t declined = 0;
744 int64_t assigned_pds = 0;
745 int64_t registered = 0;
746 for (Lease6StorageSubnetIdIndex::const_iterator lease = lower;
747 lease != upper; ++lease) {
750 if ((*lease)->subnet_id_ != cur_id) {
766 if (assigned_pds > 0) {
773 if (registered > 0) {
782 cur_id = (*lease)->subnet_id_;
787 switch((*lease)->type_) {
821 if (assigned_pds > 0) {
826 if (registered > 0) {
849 virtual void startSubnetPools() {
851 = storage6_.get<SubnetIdPoolIdIndexTag>();
854 Lease6StorageSubnetIdPoolIdIndex::const_iterator lower;
855 Lease6StorageSubnetIdPoolIdIndex::const_iterator upper;
867 if (lower == upper) {
875 uint32_t cur_pool_id = 0;
876 int64_t assigned = 0;
877 int64_t declined = 0;
878 int64_t assigned_pds = 0;
879 for (Lease6StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
880 lease != upper; ++lease) {
883 if ((*lease)->pool_id_ != cur_pool_id) {
887 assigned, cur_pool_id));
894 declined, cur_pool_id));
898 if (assigned_pds > 0) {
901 assigned_pds, cur_pool_id));
906 cur_pool_id = (*lease)->pool_id_;
911 if ((*lease)->subnet_id_ != cur_id) {
916 assigned, cur_pool_id));
923 declined, cur_pool_id));
927 if (assigned_pds > 0) {
930 assigned_pds, cur_pool_id));
936 cur_id = (*lease)->subnet_id_;
944 switch((*lease)->type_) {
975 if (assigned_pds > 0) {
997 :
TrackingLeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new std::mutex) {
998 bool conversion_needed =
false;
1005 if (universe ==
"4") {
1006 std::string file4 = initLeaseFilePath(
V4);
1007 if (!file4.empty()) {
1008 conversion_needed = loadLeasesFromFiles<
Lease4,
1015 std::string file6 = initLeaseFilePath(
V6);
1016 if (!file6.empty()) {
1017 conversion_needed = loadLeasesFromFiles<
Lease6,
1032 if (conversion_needed) {
1037 lfcSetup(conversion_needed);
1054 std::stringstream tmp;
1055 tmp <<
"Memfile backend ";
1058 }
else if (u ==
V6) {
1067 if (family == AF_INET6) {
1075Memfile_LeaseMgr::addLeaseInternal(
const Lease4Ptr& lease) {
1076 if (getLease4Internal(lease->addr_)) {
1088 storage4_.insert(lease);
1092 lease->updateCurrentExpirationTime();
1095 class_lease_counter_.
addLease(lease);
1111 std::lock_guard<std::mutex> lock(*mutex_);
1112 return (addLeaseInternal(lease));
1114 return (addLeaseInternal(lease));
1119Memfile_LeaseMgr::addLeaseInternal(
const Lease6Ptr& lease) {
1120 if (getLease6Internal(lease->type_, lease->addr_)) {
1133 storage6_.insert(lease);
1137 lease->updateCurrentExpirationTime();
1140 class_lease_counter_.
addLease(lease);
1160 std::lock_guard<std::mutex> lock(*mutex_);
1161 return (addLeaseInternal(lease));
1163 return (addLeaseInternal(lease));
1170 Lease4StorageAddressIndex::iterator l = idx.find(addr);
1171 if (l == idx.end()) {
1184 std::lock_guard<std::mutex> lock(*mutex_);
1185 return (getLease4Internal(addr));
1187 return (getLease4Internal(addr));
1192Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
1198 std::pair<Lease4StorageHWAddressSubnetIdIndex::const_iterator,
1199 Lease4StorageHWAddressSubnetIdIndex::const_iterator> l
1200 = idx.equal_range(boost::make_tuple(hwaddr.
hwaddr_));
1202 BOOST_FOREACH(
auto const& lease, l) {
1214 std::lock_guard<std::mutex> lock(*mutex_);
1215 getLease4Internal(hwaddr, collection);
1217 getLease4Internal(hwaddr, collection);
1220 return (collection);
1224Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
1230 Lease4StorageHWAddressSubnetIdIndex::const_iterator lease =
1231 idx.find(boost::make_tuple(hwaddr.
hwaddr_, subnet_id));
1233 if (lease == idx.end()) {
1238 return (
Lease4Ptr(
new Lease4(**lease)));
1249 std::lock_guard<std::mutex> lock(*mutex_);
1250 return (getLease4Internal(hwaddr, subnet_id));
1252 return (getLease4Internal(hwaddr, subnet_id));
1257Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
1263 std::pair<Lease4StorageClientIdSubnetIdIndex::const_iterator,
1264 Lease4StorageClientIdSubnetIdIndex::const_iterator> l
1265 = idx.equal_range(boost::make_tuple(client_id.
getClientId()));
1267 BOOST_FOREACH(
auto const& lease, l) {
1279 std::lock_guard<std::mutex> lock(*mutex_);
1280 getLease4Internal(client_id, collection);
1282 getLease4Internal(client_id, collection);
1285 return (collection);
1289Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
1295 Lease4StorageClientIdSubnetIdIndex::const_iterator lease =
1296 idx.find(boost::make_tuple(client_id.
getClientId(), subnet_id));
1298 if (lease == idx.end()) {
1302 return (
Lease4Ptr(
new Lease4(**lease)));
1310 .arg(client_id.
toText());
1313 std::lock_guard<std::mutex> lock(*mutex_);
1314 return (getLease4Internal(client_id, subnet_id));
1316 return (getLease4Internal(client_id, subnet_id));
1321Memfile_LeaseMgr::getLeases4Internal(
SubnetID subnet_id,
1324 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
1325 Lease4StorageSubnetIdIndex::const_iterator> l =
1326 idx.equal_range(subnet_id);
1328 BOOST_FOREACH(
auto const& lease, l) {
1340 std::lock_guard<std::mutex> lock(*mutex_);
1341 getLeases4Internal(subnet_id, collection);
1343 getLeases4Internal(subnet_id, collection);
1346 return (collection);
1350Memfile_LeaseMgr::getLeases4Internal(
const std::string& hostname,
1353 std::pair<Lease4StorageHostnameIndex::const_iterator,
1354 Lease4StorageHostnameIndex::const_iterator> l =
1355 idx.equal_range(hostname);
1357 BOOST_FOREACH(
auto const& lease, l) {
1369 std::lock_guard<std::mutex> lock(*mutex_);
1370 getLeases4Internal(hostname, collection);
1372 getLeases4Internal(hostname, collection);
1375 return (collection);
1380 for (
auto const& lease : storage4_) {
1391 std::lock_guard<std::mutex> lock(*mutex_);
1392 getLeases4Internal(collection);
1394 getLeases4Internal(collection);
1397 return (collection);
1405 Lease4StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1408 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1413 for (
auto lease = lb;
1414 (lease != idx.end()) &&
1415 (
static_cast<size_t>(std::distance(lb, lease)) < page_size.
page_size_);
1417 collection.push_back(
Lease4Ptr(
new Lease4(**lease)));
1425 if (!lower_bound_address.
isV4()) {
1427 "retrieving leases from the lease database, got "
1428 << lower_bound_address);
1433 .arg(lower_bound_address.
toText());
1437 std::lock_guard<std::mutex> lock(*mutex_);
1438 getLeases4Internal(lower_bound_address, page_size, collection);
1440 getLeases4Internal(lower_bound_address, page_size, collection);
1443 return (collection);
1447Memfile_LeaseMgr::getLease6Internal(
Lease::Type type,
1449 Lease6Storage::iterator l = storage6_.find(addr);
1450 if (l == storage6_.end() || !(*l) || ((*l)->type_ != type)) {
1459 Lease6Storage::iterator l = storage6_.find(addr);
1460 if (l == storage6_.end() || !(*l)) {
1476 std::lock_guard<std::mutex> lock(*mutex_);
1477 return (getLease6Internal(type, addr));
1479 return (getLease6Internal(type, addr));
1484Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1491 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1492 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1493 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1495 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1496 l.first; lease != l.second; ++lease) {
1504 uint32_t iaid)
const {
1513 std::lock_guard<std::mutex> lock(*mutex_);
1514 getLeases6Internal(type, duid, iaid, collection);
1516 getLeases6Internal(type, duid, iaid, collection);
1519 return (collection);
1523Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1531 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1532 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1533 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1535 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1536 l.first; lease != l.second; ++lease) {
1538 if ((*lease)->subnet_id_ == subnet_id) {
1558 std::lock_guard<std::mutex> lock(*mutex_);
1559 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1561 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1564 return (collection);
1568Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1571 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
1572 Lease6StorageSubnetIdIndex::const_iterator> l =
1573 idx.equal_range(subnet_id);
1575 BOOST_FOREACH(
auto const& lease, l) {
1587 std::lock_guard<std::mutex> lock(*mutex_);
1588 getLeases6Internal(subnet_id, collection);
1590 getLeases6Internal(subnet_id, collection);
1593 return (collection);
1597Memfile_LeaseMgr::getLeases6Internal(
const std::string& hostname,
1600 std::pair<Lease6StorageHostnameIndex::const_iterator,
1601 Lease6StorageHostnameIndex::const_iterator> l =
1602 idx.equal_range(hostname);
1604 BOOST_FOREACH(
auto const& lease, l) {
1616 std::lock_guard<std::mutex> lock(*mutex_);
1617 getLeases6Internal(hostname, collection);
1619 getLeases6Internal(hostname, collection);
1622 return (collection);
1627 for (
auto const& lease : storage6_) {
1638 std::lock_guard<std::mutex> lock(*mutex_);
1639 getLeases6Internal(collection);
1641 getLeases6Internal(collection);
1644 return (collection);
1648Memfile_LeaseMgr::getLeases6Internal(
const DUID& duid,
1651 std::pair<Lease6StorageDuidIndex::const_iterator,
1652 Lease6StorageDuidIndex::const_iterator> l =
1653 idx.equal_range(duid.
getDuid());
1655 BOOST_FOREACH(
auto const& lease, l) {
1667 std::lock_guard<std::mutex> lock(*mutex_);
1668 getLeases6Internal(duid, collection);
1670 getLeases6Internal(duid, collection);
1673 return (collection);
1681 Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1684 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1689 for (
auto lease = lb;
1690 (lease != idx.end()) &&
1691 (
static_cast<size_t>(std::distance(lb, lease)) < page_size.
page_size_);
1693 collection.push_back(
Lease6Ptr(
new Lease6(**lease)));
1701 if (!lower_bound_address.
isV6()) {
1703 "retrieving leases from the lease database, got "
1704 << lower_bound_address);
1709 .arg(lower_bound_address.
toText());
1713 std::lock_guard<std::mutex> lock(*mutex_);
1714 getLeases6Internal(lower_bound_address, page_size, collection);
1716 getLeases6Internal(lower_bound_address, page_size, collection);
1719 return (collection);
1723Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1728 Lease6StorageSubnetIdIndex::const_iterator lb =
1729 idx.lower_bound(boost::make_tuple(subnet_id, lower_bound_address));
1732 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1737 for (
auto it = lb; it != idx.end(); ++it) {
1738 if ((*it)->subnet_id_ != subnet_id) {
1742 collection.push_back(
Lease6Ptr(
new Lease6(**it)));
1743 if (collection.size() >= page_size.
page_size_) {
1747 return (collection);
1757 .arg(lower_bound_address.
toText())
1761 if (!lower_bound_address.
isV6()) {
1763 "retrieving leases from the lease database, got "
1764 << lower_bound_address);
1768 std::lock_guard<std::mutex> lock(*mutex_);
1769 return (getLeases6Internal(subnet_id,
1770 lower_bound_address,
1773 return (getLeases6Internal(subnet_id,
1774 lower_bound_address,
1780Memfile_LeaseMgr::getExpiredLeases4Internal(
Lease4Collection& expired_leases,
1781 const size_t max_leases)
const {
1789 Lease4StorageExpirationIndex::const_iterator ub =
1790 index.upper_bound(boost::make_tuple(
false, time(0)));
1793 for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
1795 ((max_leases == 0) ||
1796 (
static_cast<size_t>(std::distance(index.begin(), lease)) < max_leases));
1804 const size_t max_leases)
const {
1809 std::lock_guard<std::mutex> lock(*mutex_);
1810 getExpiredLeases4Internal(expired_leases, max_leases);
1812 getExpiredLeases4Internal(expired_leases, max_leases);
1817Memfile_LeaseMgr::getExpiredLeases6Internal(
Lease6Collection& expired_leases,
1818 const size_t max_leases)
const {
1826 Lease6StorageExpirationIndex::const_iterator ub =
1827 index.upper_bound(boost::make_tuple(
false, time(0)));
1830 for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
1832 ((max_leases == 0) ||
1833 (
static_cast<size_t>(std::distance(index.begin(), lease)) < max_leases));
1841 const size_t max_leases)
const {
1846 std::lock_guard<std::mutex> lock(*mutex_);
1847 getExpiredLeases6Internal(expired_leases, max_leases);
1849 getExpiredLeases6Internal(expired_leases, max_leases);
1854Memfile_LeaseMgr::updateLease4Internal(
const Lease4Ptr& lease) {
1861 Lease4StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1862 if (lease_it == index.end()) {
1864 << lease->addr_ <<
" - no such lease");
1865 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1866 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1869 isc_throw(NoSuchLease,
"unable to update lease for address " <<
1870 lease->addr_.toText() <<
" either because the lease does not exist, "
1871 "it has been deleted or it has changed in the database.");
1882 lease->updateCurrentExpirationTime();
1889 index.replace(lease_it,
Lease4Ptr(
new Lease4(*lease)));
1892 class_lease_counter_.
updateLease(lease, old_lease);
1906 std::lock_guard<std::mutex> lock(*mutex_);
1907 updateLease4Internal(lease);
1909 updateLease4Internal(lease);
1914Memfile_LeaseMgr::updateLease6Internal(
const Lease6Ptr& lease) {
1925 Lease6StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1926 if (lease_it == index.end()) {
1928 << lease->addr_ <<
" - no such lease");
1929 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1930 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1933 isc_throw(NoSuchLease,
"unable to update lease for address " <<
1934 lease->addr_.toText() <<
" either because the lease does not exist, "
1935 "it has been deleted or it has changed in the database.");
1946 lease->updateCurrentExpirationTime();
1953 index.replace(lease_it,
Lease6Ptr(
new Lease6(*lease)));
1956 class_lease_counter_.
updateLease(lease, old_lease);
1960 switch (recorded_action) {
1987 std::lock_guard<std::mutex> lock(*mutex_);
1988 updateLease6Internal(lease);
1990 updateLease6Internal(lease);
1995Memfile_LeaseMgr::deleteLeaseInternal(
const Lease4Ptr& lease) {
1997 Lease4Storage::iterator l = storage4_.find(addr);
1998 if (l == storage4_.end()) {
2005 Lease4 lease_copy = **l;
2008 lease_copy.valid_lft_ = 0;
2013 if (((*l)->cltt_ != lease->current_cltt_) ||
2014 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
2039 std::lock_guard<std::mutex> lock(*mutex_);
2040 return (deleteLeaseInternal(lease));
2042 return (deleteLeaseInternal(lease));
2047Memfile_LeaseMgr::deleteLeaseInternal(
const Lease6Ptr& lease) {
2051 Lease6Storage::iterator l = storage6_.find(addr);
2052 if (l == storage6_.end()) {
2059 Lease6 lease_copy = **l;
2061 lease_copy.valid_lft_ = 0;
2062 lease_copy.preferred_lft_ = 0;
2067 if (((*l)->cltt_ != lease->current_cltt_) ||
2068 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
2098 std::lock_guard<std::mutex> lock(*mutex_);
2099 return (deleteLeaseInternal(lease));
2101 return (deleteLeaseInternal(lease));
2112 std::lock_guard<std::mutex> lock(*mutex_);
2113 return (deleteExpiredReclaimedLeases<
2117 return (deleteExpiredReclaimedLeases<
2130 std::lock_guard<std::mutex> lock(*mutex_);
2131 return (deleteExpiredReclaimedLeases<
2135 return (deleteExpiredReclaimedLeases<
2141template<
typename IndexType,
typename LeaseType,
typename StorageType,
2142 typename LeaseFileType>
2144Memfile_LeaseMgr::deleteExpiredReclaimedLeases(
const uint32_t secs,
2145 const Universe& universe,
2146 StorageType& storage,
2147 LeaseFileType& lease_file) {
2149 IndexType& index = storage.template get<ExpirationIndexTag>();
2160 typename IndexType::const_iterator upper_limit =
2161 index.upper_bound(boost::make_tuple(
true, time(0) - secs));
2170 typename IndexType::const_iterator lower_limit =
2171 index.upper_bound(boost::make_tuple(
true, std::numeric_limits<int64_t>::min()));
2174 uint64_t num_leases =
static_cast<uint64_t
>(std::distance(lower_limit, upper_limit));
2175 if (num_leases > 0) {
2185 for (
typename IndexType::const_iterator lease = lower_limit;
2186 lease != upper_limit; ++lease) {
2188 LeaseType lease_copy(**lease);
2191 lease_copy.valid_lft_ = 0;
2192 lease_file->append(lease_copy);
2197 index.erase(lower_limit, upper_limit);
2201 return (num_leases);
2206 return (std::string(
"In memory database with leases stored in a CSV file."));
2209std::pair<uint32_t, uint32_t>
2211 std::string
const& universe(conn_.
getParameter(
"universe"));
2212 if (universe ==
"4") {
2214 }
else if (universe ==
"6") {
2234 std::string name(file_name);
2235 switch (file_type) {
2246 name +=
".completed";
2261 std::ostringstream s;
2263 s << (u ==
V4 ?
"4" :
"6");
2290Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
2291 std::string persist_val;
2297 persist_val =
"true";
2301 if (persist_val ==
"false") {
2304 }
else if (persist_val !=
"true") {
2306 << persist_val <<
"'");
2309 std::string lease_file;
2315 return (lease_file);
2318template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
2320Memfile_LeaseMgr::loadLeasesFromFiles(
const std::string& filename,
2321 boost::shared_ptr<LeaseFileType>& lease_file,
2322 StorageType& storage) {
2330 if (pid_file.check()) {
2332 "lease file cleanup is in progress");
2337 std::string max_row_errors_str =
"0";
2339 max_row_errors_str = conn_.
getParameter(
"max-row-errors");
2340 }
catch (
const std::exception&) {
2344 int64_t max_row_errors64;
2346 max_row_errors64 = boost::lexical_cast<int64_t>(max_row_errors_str);
2347 }
catch (
const boost::bad_lexical_cast&) {
2349 << max_row_errors_str <<
" specified");
2351 if ((max_row_errors64 < 0) ||
2352 (max_row_errors64 > std::numeric_limits<uint32_t>::max())) {
2354 << max_row_errors_str <<
" specified");
2356 uint32_t max_row_errors =
static_cast<uint32_t
>(max_row_errors64);
2359 bool conversion_needed =
false;
2360 lease_file.reset(
new LeaseFileType(std::string(filename +
".completed")));
2361 if (lease_file->exists()) {
2364 conversion_needed = conversion_needed || lease_file->needsConversion();
2369 if (lease_file->exists()) {
2372 conversion_needed = conversion_needed || lease_file->needsConversion();
2376 if (lease_file->exists()) {
2379 conversion_needed = conversion_needed || lease_file->needsConversion();
2389 lease_file.reset(
new LeaseFileType(filename));
2391 max_row_errors,
false);
2392 conversion_needed = conversion_needed || lease_file->needsConversion();
2394 return (conversion_needed);
2400 return (lfc_setup_->isRunning());
2405 return (lfc_setup_->getExitStatus());
2423Memfile_LeaseMgr::lfcSetup(
bool conversion_needed) {
2424 std::string lfc_interval_str =
"3600";
2427 }
catch (
const std::exception&) {
2431 uint32_t lfc_interval = 0;
2433 lfc_interval = boost::lexical_cast<uint32_t>(lfc_interval_str);
2434 }
catch (
const boost::bad_lexical_cast&) {
2436 << lfc_interval_str <<
" specified");
2439 if (lfc_interval > 0 || conversion_needed) {
2445template<
typename LeaseFileType>
2447Memfile_LeaseMgr::lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file) {
2457 if (!lease_file_finish.exists() && !lease_file_copy.exists()) {
2459 lease_file->close();
2462 do_lfc = (rename(lease_file->getFilename().c_str(),
2463 lease_file_copy.getFilename().c_str()) == 0);
2467 .arg(lease_file->getFilename())
2468 .arg(lease_file_copy.getFilename())
2469 .arg(strerror(errno));
2478 lease_file->open(
true);
2491 .arg(lease_file->getFilename())
2502 lfc_setup_->execute();
2510 std::lock_guard<std::mutex> lock(*mutex_);
2523 std::lock_guard<std::mutex> lock(*mutex_);
2536 std::lock_guard<std::mutex> lock(*mutex_);
2551 std::lock_guard<std::mutex> lock(*mutex_);
2564 std::lock_guard<std::mutex> lock(*mutex_);
2577 std::lock_guard<std::mutex> lock(*mutex_);
2590 std::lock_guard<std::mutex> lock(*mutex_);
2605 std::lock_guard<std::mutex> lock(*mutex_);
2623 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
2624 Lease4StorageSubnetIdIndex::const_iterator> r =
2625 idx.equal_range(subnet_id);
2629 BOOST_FOREACH(
auto const& lease, r) {
2630 leases.push_back(lease);
2633 size_t num = leases.size();
2634 for (
auto const& l : leases) {
2638 .arg(subnet_id).arg(num);
2652 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
2653 Lease6StorageSubnetIdIndex::const_iterator> r =
2654 idx.equal_range(subnet_id);
2658 BOOST_FOREACH(
auto const& lease, r) {
2659 leases.push_back(lease);
2662 size_t num = leases.size();
2663 for (
auto const& l : leases) {
2667 .arg(subnet_id).arg(num);
2674 class_lease_counter_.
clear();
2675 for (
auto const& lease : storage4_) {
2678 class_lease_counter_.
addLease(lease);
2685 class_lease_counter_.
clear();
2686 for (
auto const& lease : storage6_) {
2689 class_lease_counter_.
addLease(lease);
2698 std::lock_guard<std::mutex> lock(*mutex_);
2699 return(class_lease_counter_.
getClassCount(client_class, ltype));
2701 return(class_lease_counter_.
getClassCount(client_class, ltype));
2707 return(class_lease_counter_.
clear());
2712 if (!user_context) {
2725 for (
unsigned i = 0; i < classes->size(); ++i) {
2734 std::string name = name_elem->stringValue();
2745 size_t lease_count = 0;
2751 if (lease_count >= limit) {
2752 std::ostringstream ss;
2753 ss <<
"address limit " << limit <<
" for client class \""
2754 << name <<
"\", current lease count " << lease_count;
2770 SubnetID subnet_id = id_elem->intValue();
2777 int64_t lease_count = 0;
2779 lease_count = getSubnetStat(subnet_id,
"assigned-addresses");
2783 if (
static_cast<uint64_t
>(lease_count) >= limit) {
2784 std::ostringstream ss;
2785 ss <<
"address limit " << limit <<
" for subnet ID " << subnet_id
2786 <<
", current lease count " << lease_count;
2798 if (!user_context) {
2812 for (
unsigned i = 0; i < classes->size(); ++i) {
2821 std::string name = name_elem->stringValue();
2826 if (!getLeaseLimit(class_elem, ltype, limit)) {
2828 if (!getLeaseLimit(class_elem, ltype, limit)) {
2836 size_t lease_count = 0;
2842 if (lease_count >= limit) {
2843 std::ostringstream ss;
2845 <<
" limit " << limit <<
" for client class \""
2846 << name <<
"\", current lease count " << lease_count;
2862 SubnetID subnet_id = id_elem->intValue();
2867 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2869 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2877 int64_t lease_count = 0;
2879 lease_count = getSubnetStat(subnet_id, (ltype ==
Lease::TYPE_NA ?
2880 "assigned-nas" :
"assigned-pds"));
2884 if (
static_cast<uint64_t
>(lease_count) >= limit) {
2885 std::ostringstream ss;
2887 <<
" limit " << limit <<
" for subnet ID " << subnet_id
2888 <<
", current lease count " << lease_count;
2903Memfile_LeaseMgr::getSubnetStat(
const SubnetID& subnet_id,
const std::string& stat_label)
const {
2909 if (samples && samples->size()) {
2910 auto sample = samples->get(0);
2911 if (sample->size()) {
2912 auto count_elem = sample->get(0);
2913 return (count_elem->intValue());
2923 "prefix-limit" :
"address-limit");
2925 limit = limit_elem->intValue();
2936 std::stringstream tmp;
2939 for (
auto const& it :
id) {
2943 tmp << std::setw(2) << std::setfill(
'0')
2944 <<
static_cast<unsigned int>(it);
2956 const time_t& qry_start_time ,
2957 const time_t& qry_end_time ) {
2961 .arg(lower_bound_address.
toText())
2962 .arg(idToText(relay_id))
2963 .arg(qry_start_time)
2967 if (!lower_bound_address.
isV4()) {
2969 "retrieving leases from the lease database, got "
2970 << lower_bound_address);
2974 if ((qry_start_time < 0) || (qry_end_time < 0)) {
2979 if ((qry_start_time > 0) && (qry_end_time > 0) &&
2980 (qry_start_time > qry_end_time)) {
2985 std::lock_guard<std::mutex> lock(*mutex_);
2986 return (getLeases4ByRelayIdInternal(relay_id,
2987 lower_bound_address,
2992 return (getLeases4ByRelayIdInternal(relay_id,
2993 lower_bound_address,
3001Memfile_LeaseMgr::getLeases4ByRelayIdInternal(
const OptionBuffer& relay_id,
3004 const time_t& qry_start_time,
3005 const time_t& qry_end_time) {
3008 Lease4StorageRelayIdIndex::const_iterator lb =
3009 idx.lower_bound(boost::make_tuple(relay_id, lower_bound_address));
3011 IOAddress last_addr = lower_bound_address;
3012 for (; lb != idx.end(); ++lb) {
3013 if ((*lb)->addr_ == last_addr) {
3017 if ((*lb)->relay_id_ != relay_id) {
3021 last_addr = (*lb)->addr_;
3022 if ((qry_start_time > 0) && ((*lb)->cltt_ < qry_start_time)) {
3026 if ((qry_end_time > 0) && ((*lb)->cltt_ > qry_end_time)) {
3030 collection.push_back(
Lease4Ptr(
new Lease4(**lb)));
3031 if (collection.size() >= page_size.
page_size_) {
3035 return (collection);
3042 const time_t& qry_start_time ,
3043 const time_t& qry_end_time ) {
3047 .arg(lower_bound_address.
toText())
3048 .arg(idToText(remote_id))
3049 .arg(qry_start_time)
3053 if (!lower_bound_address.
isV4()) {
3055 "retrieving leases from the lease database, got "
3056 << lower_bound_address);
3060 if ((qry_start_time < 0) || (qry_end_time < 0)) {
3065 if ((qry_start_time > 0) && (qry_end_time > 0) &&
3066 (qry_start_time > qry_end_time)) {
3071 std::lock_guard<std::mutex> lock(*mutex_);
3072 return (getLeases4ByRemoteIdInternal(remote_id,
3073 lower_bound_address,
3078 return (getLeases4ByRemoteIdInternal(remote_id,
3079 lower_bound_address,
3087Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(
const OptionBuffer& remote_id,
3090 const time_t& qry_start_time,
3091 const time_t& qry_end_time) {
3093 std::map<IOAddress, Lease4Ptr> sorted;
3097 BOOST_FOREACH(
auto const& it, er) {
3099 if (addr <= lower_bound_address) {
3103 if ((qry_start_time > 0) && (it->cltt_ < qry_start_time)) {
3107 if ((qry_end_time > 0) && (it->cltt_ > qry_end_time)) {
3115 for (
auto const& it : sorted) {
3116 collection.push_back(
Lease4Ptr(
new Lease4(*it.second)));
3117 if (collection.size() >= page_size.
page_size_) {
3121 return (collection);
3127 std::lock_guard<std::mutex> lock(*mutex_);
3153 .arg(lower_bound_address.
toText())
3157 if (!lower_bound_address.
isV6()) {
3159 "retrieving leases from the lease database, got "
3160 << lower_bound_address);
3164 std::lock_guard<std::mutex> lock(*mutex_);
3165 return (getLeases6ByRelayIdInternal(relay_id,
3166 lower_bound_address,
3169 return (getLeases6ByRelayIdInternal(relay_id,
3170 lower_bound_address,
3176Memfile_LeaseMgr::getLeases6ByRelayIdInternal(
const DUID& relay_id,
3179 const std::vector<uint8_t>& relay_id_data = relay_id.
getDuid();
3182 RelayIdIndex::const_iterator lb =
3183 idx.lower_bound(boost::make_tuple(relay_id_data, lower_bound_address));
3186 IOAddress last_addr = lower_bound_address;
3187 for (; lb != idx.end(); ++lb) {
3188 if ((*lb)->lease_addr_ == last_addr) {
3192 if ((*lb)->id_ != relay_id_data) {
3196 last_addr = (*lb)->lease_addr_;
3197 Lease6Ptr lease = getAnyLease6Internal(last_addr);
3199 collection.push_back(lease);
3200 if (collection.size() >= page_size.
page_size_) {
3205 return (collection);
3215 .arg(lower_bound_address.
toText())
3216 .arg(idToText(remote_id));
3219 if (!lower_bound_address.
isV6()) {
3221 "retrieving leases from the lease database, got "
3222 << lower_bound_address);
3226 std::lock_guard<std::mutex> lock(*mutex_);
3227 return (getLeases6ByRemoteIdInternal(remote_id,
3228 lower_bound_address,
3231 return (getLeases6ByRemoteIdInternal(remote_id,
3232 lower_bound_address,
3238Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(
const OptionBuffer& remote_id,
3242 std::set<IOAddress> sorted;
3246 BOOST_FOREACH(
auto const& it, er) {
3247 const IOAddress& addr = it->lease_addr_;
3248 if (addr <= lower_bound_address) {
3251 static_cast<void>(sorted.insert(addr));
3256 Lease6Ptr lease = getAnyLease6Internal(addr);
3258 collection.push_back(lease);
3259 if (collection.size() >= page_size.
page_size_) {
3264 return (collection);
3277 <<
" consistency configuration is null");
3279 auto check = cfg->getExtendedInfoSanityCheck();
3284 .arg(update ?
" updating in file" :
"");
3287 size_t modified = 0;
3289 size_t processed = 0;
3291 auto lease_it = index.begin();
3292 auto next_it = index.end();
3294 for (; lease_it != index.end(); lease_it = next_it) {
3295 next_it = std::next(lease_it);
3310 if (!
copy->relay_id_.empty() || !
copy->remote_id_.empty()) {
3311 index.replace(lease_it,
copy);
3314 }
catch (
const std::exception& ex) {
3317 .arg(lease->addr_.toText())
3342 auto check = cfg->getExtendedInfoSanityCheck();
3348 .arg(enabled ?
"enabled" :
"disabled");
3357 size_t modified = 0;
3358 size_t processed = 0;
3360 for (
auto const& lease : storage6_) {
3369 }
catch (
const std::exception& ex) {
3372 .arg(lease->addr_.toText())
3392 static_cast<void>(relay_id_idx.erase(addr));
3395 static_cast<void>(remote_id_idx.erase(addr));
3400 const std::vector<uint8_t>& relay_id) {
3408 const std::vector<uint8_t>& remote_id) {
3417 std::lock_guard<std::mutex> lock(*mutex_);
3418 writeLeases4Internal(filename);
3420 writeLeases4Internal(filename);
3425Memfile_LeaseMgr::writeLeases4Internal(
const std::string& filename) {
3431 std::ostringstream old;
3432 old << filename <<
".bak" << getpid();
3433 ::rename(filename.c_str(), old.str().c_str());
3434 CSVLeaseFile4 backup(filename);
3436 for (
auto const& lease : storage4_) {
3437 backup.append(*lease);
3443 }
catch (
const std::exception&) {
3454 std::lock_guard<std::mutex> lock(*mutex_);
3455 writeLeases6Internal(filename);
3457 writeLeases6Internal(filename);
3462Memfile_LeaseMgr::writeLeases6Internal(
const std::string& filename) {
3468 std::ostringstream old;
3469 old << filename <<
".bak" << getpid();
3470 ::rename(filename.c_str(), old.str().c_str());
3471 CSVLeaseFile6 backup(filename);
3473 for (
auto const& lease : storage6_) {
3474 backup.append(*lease);
3480 }
catch (
const std::exception&) {
int version()
returns Kea hooks version.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
std::function< void()> Callback
Exception thrown when error occurs during spawning a process.
Utility class for spawning new processes.
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown on failure to open database.
Invalid address family used as input to Lease Manager.
Provides methods to access CSV file with DHCPv4 leases.
Provides methods to access CSV file with DHCPv6 leases.
static std::string sanityCheckToText(LeaseSanity check_type)
Converts lease sanity check value to printable text.
util::Optional< std::string > getDataDir() const
returns path do the data directory
uint16_t getFamily() const
Returns address family.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
void addLease(LeasePtr lease)
Increment the counts for all of a lease's classes by one.
void clear()
Remove all entries.
void removeLease(LeasePtr lease)
Decrement the counts for all of a lease's classes by one.
void updateLease(LeasePtr new_lease, LeasePtr old_lease)
Adjust class lease counts given a new and old version of a lease.
size_t getClassCount(const ClientClass &client_class, const Lease::Type <ype=Lease::TYPE_V4) const
Fetches the lease count for the given class and lease type.
Holds Client identifier or client IPv4 address.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
Holds DUID (DHCPv6 Unique Identifier)
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
std::string toText() const
Returns textual representation of the identifier (e.g.
Represents a configuration for Lease File Cleanup.
void execute()
Spawns a new process.
int getExitStatus() const
Returns exit code of the last completed cleanup.
bool isRunning() const
Checks if the lease file cleanup is in progress.
LFCSetup(asiolink::IntervalTimer::Callback callback)
Constructor.
void setup(const uint32_t lfc_interval, const boost::shared_ptr< CSVLeaseFile4 > &lease_file4, const boost::shared_ptr< CSVLeaseFile6 > &lease_file6, bool run_once_now=false)
Sets the new configuration for the Lease File Cleanup.
Lease6 extended informations for Bulk Lease Query.
static void load(LeaseFileType &lease_file, StorageType &storage, const uint32_t max_errors=0, const bool close_file_on_exit=true)
Load leases from the lease file into the specified storage.
void setExtendedInfoTablesEnabled(const bool enabled)
Modifies the setting whether the lease6 extended info tables are enabled.
static bool upgradeLease6ExtendedInfo(const Lease6Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
Upgrade a V6 lease user context to the new extended info entry.
bool getExtendedInfoTablesEnabled() const
Returns the setting indicating if lease6 extended info tables are enabled.
static void extractLease4ExtendedInfo(const Lease4Ptr &lease, bool ignore_errors=true)
Extract relay and remote identifiers from the extended info.
static bool upgradeLease4ExtendedInfo(const Lease4Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
The following queries are used to fulfill Bulk Lease Query queries.
virtual bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
Wraps value holding size of the page with leases.
const size_t page_size_
Holds page size.
Base class for fulfilling a statistical lease data query.
SubnetID getLastSubnetID() const
Returns the value of last subnet ID specified (or zero)
SubnetID getFirstSubnetID() const
Returns the value of first subnet ID specified (or zero)
SelectMode getSelectMode() const
Returns the selection criteria mode The value returned is based upon the constructor variant used and...
SelectMode
Defines the types of selection criteria supported.
Memfile derivation of the IPv4 statistical lease data query.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SelectMode &select_mode=ALL_SUBNETS)
Constructor for an all subnets query.
virtual ~MemfileLeaseStatsQuery4()
Destructor.
void start()
Creates the IPv4 lease statistical data result set.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &subnet_id)
Constructor for a single subnet query.
Memfile derivation of the IPv6 statistical lease data query.
void start()
Creates the IPv6 lease statistical data result set.
virtual ~MemfileLeaseStatsQuery6()
Destructor.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SelectMode &select_mode=ALL_SUBNETS)
Constructor.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &subnet_id)
Constructor for a single subnet query.
Base Memfile derivation of the statistical lease data query.
std::vector< LeaseStatsRow >::iterator next_pos_
An iterator for accessing the next row within the result set.
MemfileLeaseStatsQuery(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for subnet range query.
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
std::vector< LeaseStatsRow > rows_
A vector containing the "result set".
MemfileLeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor for all subnets query.
virtual ~MemfileLeaseStatsQuery()
Destructor.
int getRowCount() const
Returns the number of rows in the result set.
MemfileLeaseStatsQuery(const SubnetID &subnet_id)
Constructor for single subnet query.
Lease6ExtendedInfoRemoteIdTable remote_id6_
stores IPv6 by-remote-id cross-reference table
virtual void rollback() override
Rollback Transactions.
size_t extractExtendedInfo4(bool update, bool current)
Extract extended info for v4 leases.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual void clearClassLeaseCounts() override
Clears the class-lease count map.
virtual size_t byRelayId6size() const override
Return the by-relay-id table size.
virtual Lease4Collection getLeases4ByRelayId(const OptionBuffer &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
The following queries are used to fulfill Bulk Lease Query queries.
Memfile_LeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
The sole lease manager constructor.
bool isLFCRunning() const
Checks if the process performing lease file cleanup is running.
virtual void writeLeases4(const std::string &filename) override
Write V4 leases to a file.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress &addr) override
Delete lease6 extended info from tables.
virtual bool isJsonSupported() const override
Checks if JSON support is enabled in the database.
Universe
Specifies universe (V4, V6)
static TrackingLeaseMgrPtr factory(const isc::db::DatabaseConnection::ParameterMap ¶meters)
Factory class method.
LFCFileType
Types of the lease files used by the Lease File Cleanup.
@ FILE_PREVIOUS
Previous Lease File.
@ FILE_FINISH
LFC Finish File.
@ FILE_OUTPUT
LFC Output File.
@ FILE_INPUT
Lease File Copy
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
virtual void commit() override
Commit Transactions.
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
virtual std::pair< uint32_t, uint32_t > getVersion(const std::string &timer_name=std::string()) const override
Returns backend version.
int getLFCExitStatus() const
Returns the status code returned by the last executed LFC process.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query for all subnets and pools.
bool persistLeases(Universe u) const
Specifies whether or not leases are written to disk.
virtual void addRemoteId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &remote_id) override
Add lease6 extended info into by-remote-id table.
static std::string getDBVersion()
Return extended version info.
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
virtual size_t getClassLeaseCount(const ClientClass &client_class, const Lease::Type <ype=Lease::TYPE_V4) const override
Returns the class lease count for a given class and lease type.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
void buildExtendedInfoTables6()
Extended information / Bulk Lease Query shared interface.
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
virtual size_t byRemoteId6size() const override
Return the by-remote-id table size.
virtual void writeLeases6(const std::string &filename) override
Write V6 leases to a file.
Lease6ExtendedInfoRelayIdTable relay_id6_
stores IPv6 by-relay-id cross-reference table
virtual void recountClassLeases6() override
Recount the leases per class for V6 leases.
virtual Lease4Collection getLeases4ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
Returns existing IPv4 leases with a given remote-id.
virtual void wipeExtendedInfoTables6() override
Wipe extended info table (v6).
boost::shared_ptr< CSVLeaseFile4 > lease_file4_
Holds the pointer to the DHCPv4 lease file IO.
std::string getLeaseFilePath(Universe u) const
Returns an absolute path to the lease file.
virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given remote-id.
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
virtual void lfcCallback()
A callback function triggering Lease File Cleanup (LFC).
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual Lease6Collection getLeases6ByRelayId(const DUID &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given relay-id.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual std::string getDescription() const override
Returns description of the backend.
static std::string appendSuffix(const std::string &file_name, const LFCFileType &file_type)
Appends appropriate suffix to the file name.
virtual void addRelayId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &relay_id) override
Add lease6 extended info into by-relay-id table.
virtual size_t upgradeExtendedInfo6(const LeasePageSize &page_size) override
Upgrade extended info (v6).
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
virtual void recountClassLeases4() override
Recount the leases per class for V4 leases.
virtual void updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
static std::string getDBVersionInternal(Universe const &u)
Local version of getDBVersion() class method.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query for all subnets and pools.
virtual std::string checkLimits6(isc::data::ConstElementPtr const &user_context) const override
Checks if the IPv6 lease limits set in the given user context are exceeded.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Returns existing IPv4 lease for specified IPv4 address.
virtual ~Memfile_LeaseMgr()
Destructor (closes file)
virtual std::string checkLimits4(isc::data::ConstElementPtr const &user_context) const override
Checks if the IPv4 lease limits set in the given user context are exceeded.
boost::shared_ptr< CSVLeaseFile6 > lease_file6_
Holds the pointer to the DHCPv6 lease file IO.
std::string getDefaultLeaseFilePath(Universe u) const
Returns default path to the lease file.
virtual size_t upgradeExtendedInfo4(const LeasePageSize &page_size) override
Upgrade extended info (v4).
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv6 leases.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 leases.
Attempt to update lease that was not there.
Manages a pool of asynchronous interval timers.
Introduces callbacks into the LeaseMgr.
void trackAddLease(const LeasePtr &lease)
Invokes the callbacks when a new lease is added.
void trackUpdateLease(const LeasePtr &lease)
Invokes the callbacks when a lease is updated.
void trackDeleteLease(const LeasePtr &lease)
Invokes the callbacks when a lease is deleted.
bool hasCallbacks() const
Checks if any callbacks have been registered.
static StatsMgr & instance()
Statistics Manager accessor method.
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
Exception thrown when an error occurs during CSV file processing.
Provides input/output access to CSV files.
RAII class creating a critical section.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
Class to help with processing PID files.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
isc::data::ConstElementPtr get(const std::string &name) const
Returns a single statistic as a JSON structure.
static const int MAJOR_VERSION_V4
static const int MINOR_VERSION_V4
the minor version of the v4 memfile backend
static const int MAJOR_VERSION_V6
static const int MINOR_VERSION_V6
the minor version of the v6 memfile backend
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::vector< std::string > ProcessArgs
Type of the container holding arguments of the executable being run as a background process.
std::vector< std::string > ProcessEnvVars
Type of the container holding environment variables of the executable being run as a background proce...
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
boost::shared_ptr< const Element > ConstElementPtr
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_START
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_CLIENTID
const isc::log::MessageID DHCPSRV_MEMFILE_EXTRACT_EXTENDED_INFO4
std::string ClientClass
Defines a single class name.
boost::multi_index_container< Lease4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HWAddressSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, const std::vector< uint8_t > &, &Lease::getHWAddrVector >, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ClientIdSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease4, const std::vector< uint8_t > &, &Lease4::getClientIdVector >, boost::multi_index::member< Lease, uint32_t, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string, &Lease::hostname_ > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< RemoteIdIndexTag >, boost::multi_index::member< Lease4, std::vector< uint8_t >, &Lease4::remote_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< RelayIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::member< Lease4, std::vector< uint8_t >, &Lease4::relay_id_ >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdPoolIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ >, boost::multi_index::member< Lease, uint32_t, &Lease::pool_id_ > > > > > Lease4Storage
A multi index container holding DHCPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_HWADDR
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6
const isc::log::MessageID DHCPSRV_MEMFILE_GET4
const isc::log::MessageID DHCPSRV_MEMFILE_BUILD_EXTENDED_INFO_TABLES6_ERROR
const isc::log::MessageID DHCPSRV_MEMFILE_GET_REMOTEID6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_PAGE6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_UNREGISTER_TIMER_FAILED
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SPAWN_FAIL
const isc::log::MessageID DHCPSRV_MEMFILE_DB
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
const isc::log::MessageID DHCPSRV_MEMFILE_CONVERTING_LEASE_FILES
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SETUP
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6_FINISHED
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by DUID.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4
Lease6Storage::index< SubnetIdPoolIdIndexTag >::type Lease6StorageSubnetIdPoolIdIndex
DHCPv6 lease storage index subnet-id and pool-id.
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_RELAYID4
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED_START
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID6
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_ROLLBACK
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR6
Lease4Storage::index< HostnameIndexTag >::type Lease4StorageHostnameIndex
DHCPv4 lease storage index by hostname.
std::pair< Lease4StorageRemoteIdIndex::const_iterator, Lease4StorageRemoteIdIndex::const_iterator > Lease4StorageRemoteIdRange
DHCPv4 lease storage range by remote-id.
Lease6Storage::index< HostnameIndexTag >::type Lease6StorageHostnameIndex
DHCPv6 lease storage index by hostname.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME4
boost::multi_index_container< Lease6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIaidTypeIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector >, boost::multi_index::member< Lease6, uint32_t, &Lease6::iaid_ >, boost::multi_index::member< Lease6, Lease::Type, &Lease6::type_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIndexTag >, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string, &Lease::hostname_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdPoolIdIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ >, boost::multi_index::member< Lease, uint32_t, &Lease::pool_id_ > > > > > Lease6Storage
A multi index container holding DHCPv6 leases.
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client-id and subnet-id.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet-id.
const isc::log::MessageID DHCPSRV_MEMFILE_EXTRACT_EXTENDED_INFO4_ERROR
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR6
Lease6ExtendedInfoRelayIdTable::index< LeaseAddressIndexTag >::type LeaseAddressRelayIdIndex
Lease6 extended information by lease address index of by relay id table.
Lease6ExtendedInfoRelayIdTable::index< RelayIdIndexTag >::type RelayIdIndex
Lease6 extended information by relay id index.
Lease4Storage::index< RemoteIdIndexTag >::type Lease4StorageRemoteIdIndex
DHCPv4 lease storage index by remote-id.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
const isc::log::MessageID DHCPSRV_MEMFILE_BEGIN_EXTRACT_EXTENDED_INFO4
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4_FINISHED
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID4
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL
const isc::log::MessageID DHCPSRV_MEMFILE_COMMIT
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED4
boost::shared_ptr< CfgConsistency > CfgConsistencyPtr
Type used to for pointing to CfgConsistency structure.
const isc::log::MessageID DHCPSRV_MEMFILE_BEGIN_BUILD_EXTENDED_INFO_TABLES6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME6
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_EXECUTE
std::pair< RemoteIdIndex::const_iterator, RemoteIdIndex::const_iterator > RemoteIdIndexRange
Lease6 extended information by remote id range.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_RELAYID6
const isc::log::MessageID DHCPSRV_MEMFILE_NO_STORAGE
const isc::log::MessageID DHCPSRV_MEMFILE_BUILD_EXTENDED_INFO_TABLES6
std::unique_ptr< TrackingLeaseMgr > TrackingLeaseMgrPtr
TrackingLeaseMgr pointer.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HWADDR
const isc::log::MessageID DHCPSRV_MEMFILE_GET6_DUID
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index subnet-id.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_ADDR4
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR6
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_CLIENTID
Lease4Storage::index< AddressIndexTag >::type Lease4StorageAddressIndex
DHCPv4 lease storage index by address.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_DUID
const isc::log::MessageID DHCPSRV_MEMFILE_GET6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_REMOTEID4
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Lease6ExtendedInfoRemoteIdTable::index< LeaseAddressIndexTag >::type LeaseAddressRemoteIdIndex
Lease6 extended information by lease address index of by remote id table.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by subnet-id.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID
boost::shared_ptr< Lease6ExtendedInfo > Lease6ExtendedInfoPtr
Pointer to a Lease6ExtendedInfo object.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_ADDR6
Lease6ExtendedInfoRemoteIdTable::index< RemoteIdIndexTag >::type RemoteIdIndex
Lease6 extended information by remote id index.
Lease4Storage::index< SubnetIdPoolIdIndexTag >::type Lease4StorageSubnetIdPoolIdIndex
DHCPv4 lease storage index subnet-id and pool-id.
Lease4Storage::index< RelayIdIndexTag >::type Lease4StorageRelayIdIndex
DHCPv4 lease storage index by relay-id.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE6
Defines the logger used by the top-level component of kea-lfc.
Tag for indexes by address.
Tag for indexes by client-id, subnet-id tuple.
Tag for indexes by DUID, IAID, lease type tuple.
Tag for index using DUID.
Tag for indexes by expiration time.
Hardware type that represents information from DHCPv4 packet.
std::vector< uint8_t > hwaddr_
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
Tag for indexes by HW address, subnet-id tuple.
Tag for index using hostname.
Structure that holds a lease for IPv4 address.
Structure that holds a lease for IPv6 address and/or prefix.
ExtendedInfoAction
Action on extended info tables.
@ ACTION_UPDATE
update extended info tables.
@ ACTION_DELETE
delete reference to the lease
@ ACTION_IGNORE
ignore extended info,
Tag for indexes by lease address.
Contains a single row of lease statistical data.
static const uint32_t STATE_DEFAULT
A lease in the default state.
static const uint32_t STATE_DECLINED
Declined lease.
Type
Type of lease or pool.
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address
static const uint32_t STATE_REGISTERED
Registered self-generated lease.
static std::string typeToText(Type type)
returns text representation of a lease type
Tag for index using relay-id.
Tag for index using remote-id.
Tag for indexes by subnet-id (and address for v6).