39 const 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);
105 bool isRunning()
const;
108 int getExitStatus()
const;
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");
220 if (lfc_interval > 0) {
227 timer_mgr_->registerTimer(
"memfile-lfc", callback_, lfc_interval * 1000,
229 timer_mgr_->setup(
"memfile-lfc");
237 .arg(process_->getCommandLine());
238 pid_ = process_->spawn();
247 return (process_ && process_->isRunning(pid_));
254 " the process is null");
256 return (process_->getExitStatus(pid_));
270 : rows_(0), next_pos_(rows_.end()) {
285 :
LeaseStatsQuery(first_subnet_id, last_subnet_id), rows_(0), next_pos_(rows_.end()) {
302 if (next_pos_ == rows_.end()) {
313 return (rows_.size());
382 Lease4StorageSubnetIdIndex::const_iterator lower;
383 Lease4StorageSubnetIdIndex::const_iterator upper;
384 switch (getSelectMode()) {
391 lower = idx.lower_bound(getFirstSubnetID());
392 upper = idx.upper_bound(getFirstSubnetID());
396 lower = idx.lower_bound(getFirstSubnetID());
397 upper = idx.upper_bound(getLastSubnetID());
402 if (lower == upper) {
410 int64_t assigned = 0;
411 int64_t declined = 0;
412 for (Lease4StorageSubnetIdIndex::const_iterator lease = lower;
413 lease != upper; ++lease) {
416 if ((*lease)->subnet_id_ != cur_id) {
434 cur_id = (*lease)->subnet_id_;
457 next_pos_ = rows_.begin();
524 Lease6StorageSubnetIdIndex::const_iterator lower;
525 Lease6StorageSubnetIdIndex::const_iterator upper;
526 switch (getSelectMode()) {
533 lower = idx.lower_bound(getFirstSubnetID());
534 upper = idx.upper_bound(getFirstSubnetID());
538 lower = idx.lower_bound(getFirstSubnetID());
539 upper = idx.upper_bound(getLastSubnetID());
544 if (lower == upper) {
552 int64_t assigned = 0;
553 int64_t declined = 0;
554 int64_t assigned_pds = 0;
555 for (Lease6StorageSubnetIdIndex::const_iterator lease = lower;
556 lease != upper; ++lease) {
559 if ((*lease)->subnet_id_ != cur_id) {
575 if (assigned_pds > 0) {
584 cur_id = (*lease)->subnet_id_;
589 switch((*lease)->type_) {
618 if (assigned_pds > 0) {
624 next_pos_ = rows_.begin();
640 :
LeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new
std::mutex) {
641 bool conversion_needed =
false;
648 if (universe ==
"4") {
649 std::string file4 = initLeaseFilePath(
V4);
650 if (!file4.empty()) {
651 conversion_needed = loadLeasesFromFiles<
Lease4,
657 std::string file6 = initLeaseFilePath(
V6);
658 if (!file6.empty()) {
659 conversion_needed = loadLeasesFromFiles<
Lease6,
663 static_cast<void>(buildExtendedInfoTables6Internal(
false,
false));
674 if (conversion_needed) {
679 lfcSetup(conversion_needed);
696 std::stringstream tmp;
697 tmp <<
"Memfile backend ";
700 }
else if (u ==
V6) {
707 Memfile_LeaseMgr::addLeaseInternal(
const Lease4Ptr& lease) {
708 if (getLease4Internal(lease->addr_)) {
720 storage4_.insert(lease);
724 lease->updateCurrentExpirationTime();
727 class_lease_counter_.
addLease(lease);
737 if (MultiThreadingMgr::instance().getMode()) {
738 std::lock_guard<std::mutex> lock(*mutex_);
739 return (addLeaseInternal(lease));
741 return (addLeaseInternal(lease));
746 Memfile_LeaseMgr::addLeaseInternal(
const Lease6Ptr& lease) {
747 if (getLease6Internal(lease->type_, lease->addr_)) {
760 storage6_.insert(lease);
764 lease->updateCurrentExpirationTime();
767 class_lease_counter_.
addLease(lease);
781 if (MultiThreadingMgr::instance().getMode()) {
782 std::lock_guard<std::mutex> lock(*mutex_);
783 return (addLeaseInternal(lease));
785 return (addLeaseInternal(lease));
792 Lease4StorageAddressIndex::iterator l = idx.find(addr);
793 if (l == idx.end()) {
805 if (MultiThreadingMgr::instance().getMode()) {
806 std::lock_guard<std::mutex> lock(*mutex_);
807 return (getLease4Internal(addr));
809 return (getLease4Internal(addr));
814 Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
820 std::pair<Lease4StorageHWAddressSubnetIdIndex::const_iterator,
821 Lease4StorageHWAddressSubnetIdIndex::const_iterator> l
822 = idx.equal_range(boost::make_tuple(hwaddr.
hwaddr_));
824 for (
auto lease = l.first; lease != l.second; ++lease) {
835 if (MultiThreadingMgr::instance().getMode()) {
836 std::lock_guard<std::mutex> lock(*mutex_);
837 getLease4Internal(hwaddr, collection);
839 getLease4Internal(hwaddr, collection);
846 Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
852 Lease4StorageHWAddressSubnetIdIndex::const_iterator lease =
853 idx.find(boost::make_tuple(hwaddr.
hwaddr_, subnet_id));
855 if (lease == idx.end()) {
870 if (MultiThreadingMgr::instance().getMode()) {
871 std::lock_guard<std::mutex> lock(*mutex_);
872 return (getLease4Internal(hwaddr, subnet_id));
874 return (getLease4Internal(hwaddr, subnet_id));
879 Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
885 std::pair<Lease4StorageClientIdSubnetIdIndex::const_iterator,
886 Lease4StorageClientIdSubnetIdIndex::const_iterator> l
887 = idx.equal_range(boost::make_tuple(client_id.
getClientId()));
889 for (
auto lease = l.first; lease != l.second; ++lease) {
900 if (MultiThreadingMgr::instance().getMode()) {
901 std::lock_guard<std::mutex> lock(*mutex_);
902 getLease4Internal(client_id, collection);
904 getLease4Internal(client_id, collection);
911 Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
917 Lease4StorageClientIdSubnetIdIndex::const_iterator lease =
918 idx.find(boost::make_tuple(client_id.
getClientId(), subnet_id));
920 if (lease == idx.end()) {
934 if (MultiThreadingMgr::instance().getMode()) {
935 std::lock_guard<std::mutex> lock(*mutex_);
936 return (getLease4Internal(client_id, subnet_id));
938 return (getLease4Internal(client_id, subnet_id));
943 Memfile_LeaseMgr::getLeases4Internal(
SubnetID subnet_id,
946 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
947 Lease4StorageSubnetIdIndex::const_iterator> l =
948 idx.equal_range(subnet_id);
950 for (
auto lease = l.first; lease != l.second; ++lease) {
961 if (MultiThreadingMgr::instance().getMode()) {
962 std::lock_guard<std::mutex> lock(*mutex_);
963 getLeases4Internal(subnet_id, collection);
965 getLeases4Internal(subnet_id, collection);
972 Memfile_LeaseMgr::getLeases4Internal(
const std::string& hostname,
975 std::pair<Lease4StorageHostnameIndex::const_iterator,
976 Lease4StorageHostnameIndex::const_iterator> l =
977 idx.equal_range(hostname);
979 for (
auto lease = l.first; lease != l.second; ++lease) {
990 if (MultiThreadingMgr::instance().getMode()) {
991 std::lock_guard<std::mutex> lock(*mutex_);
992 getLeases4Internal(hostname, collection);
994 getLeases4Internal(hostname, collection);
1002 for (
auto lease = storage4_.begin(); lease != storage4_.end(); ++lease) {
1012 if (MultiThreadingMgr::instance().getMode()) {
1013 std::lock_guard<std::mutex> lock(*mutex_);
1014 getLeases4Internal(collection);
1016 getLeases4Internal(collection);
1019 return (collection);
1027 Lease4StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1030 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1035 for (
auto lease = lb;
1036 (lease != idx.end()) && (std::distance(lb, lease) < page_size.
page_size_);
1046 if (!lower_bound_address.
isV4()) {
1048 "retrieving leases from the lease database, got " 1049 << lower_bound_address);
1054 .arg(lower_bound_address.
toText());
1057 if (MultiThreadingMgr::instance().getMode()) {
1058 std::lock_guard<std::mutex> lock(*mutex_);
1059 getLeases4Internal(lower_bound_address, page_size, collection);
1061 getLeases4Internal(lower_bound_address, page_size, collection);
1064 return (collection);
1068 Memfile_LeaseMgr::getLease6Internal(
Lease::Type type,
1070 Lease6Storage::iterator l = storage6_.find(addr);
1071 if (l == storage6_.end() || !(*l) || ((*l)->type_ != type)) {
1080 Lease6Storage::iterator l = storage6_.find(addr);
1081 if (l == storage6_.end() || !(*l)) {
1096 if (MultiThreadingMgr::instance().getMode()) {
1097 std::lock_guard<std::mutex> lock(*mutex_);
1098 return (getLease6Internal(type, addr));
1100 return (getLease6Internal(type, addr));
1105 Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1112 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1113 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1114 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1116 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1117 l.first; lease != l.second; ++lease) {
1125 uint32_t iaid)
const {
1133 if (MultiThreadingMgr::instance().getMode()) {
1134 std::lock_guard<std::mutex> lock(*mutex_);
1135 getLeases6Internal(type, duid, iaid, collection);
1137 getLeases6Internal(type, duid, iaid, collection);
1140 return (collection);
1144 Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1152 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1153 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1154 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1156 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1157 l.first; lease != l.second; ++lease) {
1159 if ((*lease)->subnet_id_ == subnet_id) {
1178 if (MultiThreadingMgr::instance().getMode()) {
1179 std::lock_guard<std::mutex> lock(*mutex_);
1180 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1182 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1185 return (collection);
1189 Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1192 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
1193 Lease6StorageSubnetIdIndex::const_iterator> l =
1194 idx.equal_range(subnet_id);
1196 for (
auto lease = l.first; lease != l.second; ++lease) {
1207 if (MultiThreadingMgr::instance().getMode()) {
1208 std::lock_guard<std::mutex> lock(*mutex_);
1209 getLeases6Internal(subnet_id, collection);
1211 getLeases6Internal(subnet_id, collection);
1214 return (collection);
1218 Memfile_LeaseMgr::getLeases6Internal(
const std::string& hostname,
1221 std::pair<Lease6StorageHostnameIndex::const_iterator,
1222 Lease6StorageHostnameIndex::const_iterator> l =
1223 idx.equal_range(hostname);
1225 for (
auto lease = l.first; lease != l.second; ++lease) {
1236 if (MultiThreadingMgr::instance().getMode()) {
1237 std::lock_guard<std::mutex> lock(*mutex_);
1238 getLeases6Internal(hostname, collection);
1240 getLeases6Internal(hostname, collection);
1243 return (collection);
1248 for (
auto lease = storage6_.begin(); lease != storage6_.end(); ++lease) {
1258 if (MultiThreadingMgr::instance().getMode()) {
1259 std::lock_guard<std::mutex> lock(*mutex_);
1260 getLeases6Internal(collection);
1262 getLeases6Internal(collection);
1265 return (collection);
1269 Memfile_LeaseMgr::getLeases6Internal(
const DUID& duid,
1272 std::pair<Lease6StorageDuidIndex::const_iterator,
1273 Lease6StorageDuidIndex::const_iterator> l =
1274 idx.equal_range(duid.
getDuid());
1276 for (
auto lease = l.first; lease != l.second; ++lease) {
1287 if (MultiThreadingMgr::instance().getMode()) {
1288 std::lock_guard<std::mutex> lock(*mutex_);
1289 getLeases6Internal(duid, collection);
1291 getLeases6Internal(duid, collection);
1294 return (collection);
1302 Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1305 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1310 for (
auto lease = lb;
1311 (lease != idx.end()) && (std::distance(lb, lease) < page_size.
page_size_);
1321 if (!lower_bound_address.
isV6()) {
1323 "retrieving leases from the lease database, got " 1324 << lower_bound_address);
1329 .arg(lower_bound_address.
toText());
1332 if (MultiThreadingMgr::instance().getMode()) {
1333 std::lock_guard<std::mutex> lock(*mutex_);
1334 getLeases6Internal(lower_bound_address, page_size, collection);
1336 getLeases6Internal(lower_bound_address, page_size, collection);
1339 return (collection);
1343 Memfile_LeaseMgr::getExpiredLeases4Internal(
Lease4Collection& expired_leases,
1344 const size_t max_leases)
const {
1352 Lease4StorageExpirationIndex::const_iterator ub =
1353 index.upper_bound(boost::make_tuple(
false, time(0)));
1356 for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
1357 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1366 const size_t max_leases)
const {
1370 if (MultiThreadingMgr::instance().getMode()) {
1371 std::lock_guard<std::mutex> lock(*mutex_);
1372 getExpiredLeases4Internal(expired_leases, max_leases);
1374 getExpiredLeases4Internal(expired_leases, max_leases);
1379 Memfile_LeaseMgr::getExpiredLeases6Internal(
Lease6Collection& expired_leases,
1380 const size_t max_leases)
const {
1388 Lease6StorageExpirationIndex::const_iterator ub =
1389 index.upper_bound(boost::make_tuple(
false, time(0)));
1392 for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
1393 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1402 const size_t max_leases)
const {
1406 if (MultiThreadingMgr::instance().getMode()) {
1407 std::lock_guard<std::mutex> lock(*mutex_);
1408 getExpiredLeases6Internal(expired_leases, max_leases);
1410 getExpiredLeases6Internal(expired_leases, max_leases);
1415 Memfile_LeaseMgr::updateLease4Internal(
const Lease4Ptr& lease) {
1422 Lease4StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1423 if (lease_it == index.end()) {
1425 << lease->addr_ <<
" - no such lease");
1426 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1427 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1431 << lease->addr_ <<
" - lease has changed in database");
1442 lease->updateCurrentExpirationTime();
1452 class_lease_counter_.
updateLease(lease, old_lease);
1460 if (MultiThreadingMgr::instance().getMode()) {
1461 std::lock_guard<std::mutex> lock(*mutex_);
1462 updateLease4Internal(lease);
1464 updateLease4Internal(lease);
1469 Memfile_LeaseMgr::updateLease6Internal(
const Lease6Ptr& lease) {
1480 Lease6StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1481 if (lease_it == index.end()) {
1483 << lease->addr_ <<
" - no such lease");
1484 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1485 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1489 << lease->addr_ <<
" - lease has changed in database");
1500 lease->updateCurrentExpirationTime();
1510 class_lease_counter_.
updateLease(lease, old_lease);
1514 switch (recorded_action) {
1535 if (MultiThreadingMgr::instance().getMode()) {
1536 std::lock_guard<std::mutex> lock(*mutex_);
1537 updateLease6Internal(lease);
1539 updateLease6Internal(lease);
1544 Memfile_LeaseMgr::deleteLeaseInternal(
const Lease4Ptr& lease) {
1546 Lease4Storage::iterator l = storage4_.find(addr);
1547 if (l == storage4_.end()) {
1562 if (((*l)->cltt_ != lease->current_cltt_) ||
1563 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
1582 if (MultiThreadingMgr::instance().getMode()) {
1583 std::lock_guard<std::mutex> lock(*mutex_);
1584 return (deleteLeaseInternal(lease));
1586 return (deleteLeaseInternal(lease));
1591 Memfile_LeaseMgr::deleteLeaseInternal(
const Lease6Ptr& lease) {
1595 Lease6Storage::iterator l = storage6_.find(addr);
1596 if (l == storage6_.end()) {
1611 if (((*l)->cltt_ != lease->current_cltt_) ||
1612 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
1636 if (MultiThreadingMgr::instance().getMode()) {
1637 std::lock_guard<std::mutex> lock(*mutex_);
1638 return (deleteLeaseInternal(lease));
1640 return (deleteLeaseInternal(lease));
1650 if (MultiThreadingMgr::instance().getMode()) {
1651 std::lock_guard<std::mutex> lock(*mutex_);
1652 return (deleteExpiredReclaimedLeases<
1656 return (deleteExpiredReclaimedLeases<
1668 if (MultiThreadingMgr::instance().getMode()) {
1669 std::lock_guard<std::mutex> lock(*mutex_);
1670 return (deleteExpiredReclaimedLeases<
1674 return (deleteExpiredReclaimedLeases<
1680 template<
typename IndexType,
typename LeaseType,
typename StorageType,
1681 typename LeaseFileType>
1683 Memfile_LeaseMgr::deleteExpiredReclaimedLeases(
const uint32_t secs,
1685 StorageType& storage,
1686 LeaseFileType& lease_file) {
1688 IndexType& index = storage.template get<ExpirationIndexTag>();
1699 typename IndexType::const_iterator upper_limit =
1700 index.upper_bound(boost::make_tuple(
true, time(0) - secs));
1709 typename IndexType::const_iterator lower_limit =
1710 index.upper_bound(boost::make_tuple(
true, std::numeric_limits<int64_t>::min()));
1713 uint64_t num_leases =
static_cast<uint64_t
>(std::distance(lower_limit, upper_limit));
1714 if (num_leases > 0) {
1724 for (
typename IndexType::const_iterator lease = lower_limit;
1725 lease != upper_limit; ++lease) {
1727 LeaseType lease_copy(**lease);
1730 lease_copy.valid_lft_ = 0;
1731 lease_file->append(lease_copy);
1738 if (universe ==
V6) {
1739 for (
typename IndexType::const_iterator lease = lower_limit;
1740 lease != upper_limit; ++lease) {
1747 index.erase(lower_limit, upper_limit);
1751 return (num_leases);
1756 return (std::string(
"In memory database with leases stored in a CSV file."));
1759 std::pair<uint32_t, uint32_t>
1761 std::string
const& universe(conn_.
getParameter(
"universe"));
1762 if (universe ==
"4") {
1764 }
else if (universe ==
"6") {
1784 std::string name(file_name);
1785 switch (file_type) {
1796 name +=
".completed";
1811 std::ostringstream s;
1813 s << (u ==
V4 ?
"4" :
"6");
1840 Memfile_LeaseMgr::initLeaseFilePath(
Universe u) {
1841 std::string persist_val;
1847 persist_val =
"true";
1851 if (persist_val ==
"false") {
1854 }
else if (persist_val !=
"true") {
1856 << persist_val <<
"'");
1859 std::string lease_file;
1865 return (lease_file);
1868 template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
1870 Memfile_LeaseMgr::loadLeasesFromFiles(
const std::string& filename,
1871 boost::shared_ptr<LeaseFileType>& lease_file,
1872 StorageType& storage) {
1880 if (pid_file.
check()) {
1882 "lease file cleanup is in progress");
1887 std::string max_row_errors_str =
"0";
1889 max_row_errors_str = conn_.
getParameter(
"max-row-errors");
1890 }
catch (
const std::exception&) {
1894 int64_t max_row_errors64;
1896 max_row_errors64 = boost::lexical_cast<int64_t>(max_row_errors_str);
1897 }
catch (
const boost::bad_lexical_cast&) {
1899 << max_row_errors_str <<
" specified");
1901 if ((max_row_errors64 < 0) ||
1902 (max_row_errors64 > std::numeric_limits<uint32_t>::max())) {
1904 << max_row_errors_str <<
" specified");
1906 uint32_t max_row_errors =
static_cast<uint32_t
>(max_row_errors64);
1909 bool conversion_needed =
false;
1910 lease_file.reset(
new LeaseFileType(std::string(filename +
".completed")));
1911 if (lease_file->exists()) {
1912 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1914 conversion_needed = conversion_needed || lease_file->needsConversion();
1919 if (lease_file->exists()) {
1920 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1922 conversion_needed = conversion_needed || lease_file->needsConversion();
1926 if (lease_file->exists()) {
1927 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1929 conversion_needed = conversion_needed || lease_file->needsConversion();
1939 lease_file.reset(
new LeaseFileType(filename));
1940 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1941 max_row_errors,
false);
1942 conversion_needed = conversion_needed || lease_file->needsConversion();
1944 return (conversion_needed);
1950 return (lfc_setup_->isRunning());
1955 return (lfc_setup_->getExitStatus());
1973 Memfile_LeaseMgr::lfcSetup(
bool conversion_needed) {
1974 std::string lfc_interval_str =
"3600";
1977 }
catch (
const std::exception&) {
1981 uint32_t lfc_interval = 0;
1983 lfc_interval = boost::lexical_cast<uint32_t>(lfc_interval_str);
1984 }
catch (
const boost::bad_lexical_cast&) {
1986 << lfc_interval_str <<
" specified");
1989 if (lfc_interval > 0 || conversion_needed) {
1995 template<
typename LeaseFileType>
1997 Memfile_LeaseMgr::lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file) {
2007 if (!lease_file_finish.
exists() && !lease_file_copy.
exists()) {
2009 lease_file->close();
2012 do_lfc = (rename(lease_file->getFilename().c_str(),
2017 .arg(lease_file->getFilename())
2019 .arg(strerror(errno));
2028 lease_file->open(
true);
2041 .arg(lease_file->getFilename())
2052 lfc_setup_->execute();
2059 if (MultiThreadingMgr::instance().getMode()) {
2060 std::lock_guard<std::mutex> lock(*mutex_);
2072 if (MultiThreadingMgr::instance().getMode()) {
2073 std::lock_guard<std::mutex> lock(*mutex_);
2087 if (MultiThreadingMgr::instance().getMode()) {
2088 std::lock_guard<std::mutex> lock(*mutex_);
2100 if (MultiThreadingMgr::instance().getMode()) {
2101 std::lock_guard<std::mutex> lock(*mutex_);
2113 if (MultiThreadingMgr::instance().getMode()) {
2114 std::lock_guard<std::mutex> lock(*mutex_);
2128 if (MultiThreadingMgr::instance().getMode()) {
2129 std::lock_guard<std::mutex> lock(*mutex_);
2147 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
2148 Lease4StorageSubnetIdIndex::const_iterator> l =
2149 idx.equal_range(subnet_id);
2153 for (
auto lease = l.first; lease != l.second; ++lease) {
2154 leases.push_back(*lease);
2157 size_t num = leases.size();
2158 for (
auto l = leases.begin(); l != leases.end(); ++l) {
2162 .arg(subnet_id).arg(num);
2176 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
2177 Lease6StorageSubnetIdIndex::const_iterator> l =
2178 idx.equal_range(subnet_id);
2182 for (
auto lease = l.first; lease != l.second; ++lease) {
2183 leases.push_back(*lease);
2186 size_t num = leases.size();
2187 for (
auto l = leases.begin(); l != leases.end(); ++l) {
2191 .arg(subnet_id).arg(num);
2198 class_lease_counter_.
clear();
2199 for (
auto lease = storage4_.begin(); lease != storage4_.end(); ++lease) {
2202 class_lease_counter_.
addLease(*lease);
2209 class_lease_counter_.
clear();
2210 for (
auto lease = storage6_.begin(); lease != storage6_.end(); ++lease) {
2213 class_lease_counter_.
addLease(*lease);
2221 if (MultiThreadingMgr::instance().getMode()) {
2222 std::lock_guard<std::mutex> lock(*mutex_);
2223 return(class_lease_counter_.
getClassCount(client_class, ltype));
2225 return(class_lease_counter_.
getClassCount(client_class, ltype));
2231 return(class_lease_counter_.
clear());
2236 if (!user_context) {
2249 for (
int i = 0; i < classes->size(); ++i) {
2258 std::string name = name_elem->stringValue();
2269 size_t lease_count = 0;
2275 if (lease_count >= limit) {
2276 std::ostringstream ss;
2277 ss <<
"address limit " << limit <<
" for client class \"" 2278 << name <<
"\", current lease count " << lease_count;
2294 SubnetID subnet_id = id_elem->intValue();
2301 int64_t lease_count = 0;
2303 lease_count = getSubnetStat(subnet_id,
"assigned-addresses");
2307 if (lease_count >= limit) {
2308 std::ostringstream ss;
2309 ss <<
"address limit " << limit <<
" for subnet ID " << subnet_id
2310 <<
", current lease count " << lease_count;
2322 if (!user_context) {
2336 for (
int i = 0; i < classes->size(); ++i) {
2345 std::string name = name_elem->stringValue();
2350 if (!getLeaseLimit(class_elem, ltype, limit)) {
2352 if (!getLeaseLimit(class_elem, ltype, limit)) {
2360 size_t lease_count = 0;
2366 if (lease_count >= limit) {
2367 std::ostringstream ss;
2369 <<
" limit " << limit <<
" for client class \"" 2370 << name <<
"\", current lease count " << lease_count;
2386 SubnetID subnet_id = id_elem->intValue();
2391 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2393 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2401 int64_t lease_count = 0;
2403 lease_count = getSubnetStat(subnet_id, (ltype ==
Lease::TYPE_NA ?
2404 "assigned-nas" :
"assigned-pds"));
2408 if (lease_count >= limit) {
2409 std::ostringstream ss;
2411 <<
" limit " << limit <<
" for subnet ID " << subnet_id
2412 <<
", current lease count " << lease_count;
2427 Memfile_LeaseMgr::getSubnetStat(
const SubnetID& subnet_id,
const std::string& stat_label)
const {
2430 std::string stat_name = StatsMgr::generateName(
"subnet", subnet_id, stat_label);
2433 if (samples && samples->size()) {
2434 auto sample = samples->get(0);
2435 if (sample->size()) {
2436 auto count_elem = sample->get(0);
2437 return (count_elem->intValue());
2447 "prefix-limit" :
"address-limit");
2449 limit = limit_elem->intValue();
2460 std::stringstream tmp;
2463 for (std::vector<uint8_t>::const_iterator it =
id.begin();
2464 it !=
id.end(); ++it) {
2468 tmp << std::setw(2) << std::setfill(
'0')
2469 <<
static_cast<unsigned int>(*it);
2481 const time_t& qry_start_time ,
2482 const time_t& qry_end_time ) {
2484 if (!lower_bound_address.
isV4()) {
2486 "retrieving leases from the lease database, got " 2487 << lower_bound_address);
2493 .arg(lower_bound_address.
toText())
2494 .arg(idToText(relay_id))
2495 .arg(qry_start_time)
2498 if (MultiThreadingMgr::instance().getMode()) {
2499 std::lock_guard<std::mutex> lock(*mutex_);
2500 return (getLeases4ByRelayIdInternal(relay_id,
2501 lower_bound_address,
2506 return (getLeases4ByRelayIdInternal(relay_id,
2507 lower_bound_address,
2515 Memfile_LeaseMgr::getLeases4ByRelayIdInternal(
const OptionBuffer&,
2527 const time_t& qry_start_time ,
2528 const time_t& qry_end_time ) {
2530 if (!lower_bound_address.
isV4()) {
2532 "retrieving leases from the lease database, got " 2533 << lower_bound_address);
2539 .arg(lower_bound_address.
toText())
2540 .arg(idToText(remote_id))
2541 .arg(qry_start_time)
2544 if (MultiThreadingMgr::instance().getMode()) {
2545 std::lock_guard<std::mutex> lock(*mutex_);
2546 return (getLeases4ByRemoteIdInternal(remote_id,
2547 lower_bound_address,
2552 return (getLeases4ByRemoteIdInternal(remote_id,
2553 lower_bound_address,
2561 Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(
const OptionBuffer&,
2576 if (!link_addr.
isV6()) {
2578 "retrieving leases from the lease database, got " 2581 if (link_len > 128) {
2583 << static_cast<unsigned>(link_len));
2585 if (!lower_bound_address.
isV6()) {
2587 "retrieving leases from the lease database, got " 2588 << lower_bound_address);
2594 .arg(lower_bound_address.
toText())
2597 .arg(static_cast<unsigned>(link_len));
2599 if (MultiThreadingMgr::instance().getMode()) {
2600 std::lock_guard<std::mutex> lock(*mutex_);
2601 return (getLeases6ByRelayIdInternal(relay_id,
2604 lower_bound_address,
2607 return (getLeases6ByRelayIdInternal(relay_id,
2610 lower_bound_address,
2616 Memfile_LeaseMgr::getLeases6ByRelayIdInternal(
const DUID& relay_id,
2621 const std::vector<uint8_t>& relay_id_data = relay_id.
getDuid();
2625 RelayIdIndex::const_iterator lb =
2626 idx.lower_bound(boost::make_tuple(relay_id_data,
2627 lower_bound_address));
2630 IOAddress last_addr = lower_bound_address;
2631 for (; lb != idx.end(); ++lb) {
2632 if ((*lb)->lease_addr_ == last_addr) {
2636 if ((*lb)->id_ != relay_id_data) {
2640 last_addr = (*lb)->lease_addr_;
2641 Lease6Ptr lease = getAnyLease6Internal(last_addr);
2643 collection.push_back(lease);
2644 if (collection.size() >= page_size.
page_size_) {
2653 (lower_bound_address < first_addr ? first_addr : lower_bound_address);
2654 RelayIdIndex::const_iterator lb =
2655 idx.lower_bound(boost::make_tuple(relay_id_data, start_addr));
2656 RelayIdIndex::const_iterator ub =
2657 idx.upper_bound(boost::make_tuple(relay_id_data, last_addr));
2660 IOAddress last_seen_addr = lower_bound_address;
2661 for (
auto it = lb; it != ub; ++it) {
2662 if ((*it)->lease_addr_ == last_seen_addr) {
2666 last_seen_addr = (*it)->lease_addr_;
2667 Lease6Ptr lease = getAnyLease6Internal(last_seen_addr);
2669 collection.push_back(lease);
2670 if (collection.size() >= page_size.
page_size_) {
2676 return (collection);
2686 if (!link_addr.
isV6()) {
2688 "retrieving leases from the lease database, got " 2691 if (link_len > 128) {
2693 << static_cast<unsigned>(link_len));
2695 if (!lower_bound_address.
isV6()) {
2697 "retrieving leases from the lease database, got " 2698 << lower_bound_address);
2704 .arg(lower_bound_address.
toText())
2705 .arg(idToText(remote_id))
2707 .arg(static_cast<unsigned>(link_len));
2709 if (MultiThreadingMgr::instance().getMode()) {
2710 std::lock_guard<std::mutex> lock(*mutex_);
2711 return (getLeases6ByRemoteIdInternal(remote_id,
2714 lower_bound_address,
2717 return (getLeases6ByRemoteIdInternal(remote_id,
2720 lower_bound_address,
2726 Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(
const OptionBuffer& remote_id,
2732 std::set<IOAddress> sorted;
2737 for (
auto it = er.first; it != er.second; ++it) {
2738 const IOAddress& addr = (*it)->lease_addr_;
2739 if (addr <= lower_bound_address) {
2742 static_cast<void>(sorted.insert(addr));
2747 Lease6Ptr lease = getAnyLease6Internal(addr);
2749 collection.push_back(lease);
2750 if (collection.size() >= page_size.
page_size_) {
2760 for (
auto it = er.first; it != er.second; ++it) {
2761 const IOAddress& addr = (*it)->lease_addr_;
2762 if (addr <= lower_bound_address) {
2765 if ((addr < first_addr) || (last_addr < addr)) {
2768 static_cast<void>(sorted.insert(addr));
2773 Lease6Ptr lease = getAnyLease6Internal(addr);
2775 collection.push_back(lease);
2776 if (collection.size() >= page_size.
page_size_) {
2782 return (collection);
2791 if (!link_addr.
isV6()) {
2793 "retrieving leases from the lease database, got " 2796 if ((link_len == 0) || (link_len > 128)) {
2798 << static_cast<unsigned>(link_len));
2800 if (!lower_bound_address.
isV6()) {
2802 "retrieving leases from the lease database, got " 2803 << lower_bound_address);
2809 .arg(lower_bound_address.
toText())
2811 .arg(static_cast<unsigned>(link_len));
2813 if (MultiThreadingMgr::instance().getMode()) {
2814 std::lock_guard<std::mutex> lock(*mutex_);
2815 return (getLeases6ByLinkInternal(link_addr,
2817 lower_bound_address,
2820 return (getLeases6ByLinkInternal(link_addr,
2822 lower_bound_address,
2828 Memfile_LeaseMgr::getLeases6ByLinkInternal(
const IOAddress& link_addr,
2835 (lower_bound_address < first_addr ? first_addr : lower_bound_address);
2838 Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(start_addr);
2839 Lease6StorageAddressIndex::const_iterator eb = idx.upper_bound(last_addr);
2842 IOAddress last_seen_addr = lower_bound_address;
2843 for (
auto it = lb; it != eb; ++it) {
2844 if ((*it)->addr_ == last_seen_addr) {
2848 last_seen_addr = (*it)->addr_;
2849 Lease6Ptr lease = getAnyLease6Internal(last_seen_addr);
2851 collection.push_back(lease);
2852 if (collection.size() >= page_size.
page_size_) {
2857 return (collection);
2861 Memfile_LeaseMgr::buildExtendedInfoTables6Internal(
bool update,
bool current) {
2870 <<
" consistency configuration is null");
2872 auto check = cfg->getExtendedInfoSanityCheck();
2878 .arg(update ?
" updating in file" :
"")
2879 .arg(enabled ?
"enabled" :
"disabled");
2888 size_t modified = 0;
2890 size_t processed = 0;
2892 for (
auto lease : storage6_) {
2905 }
catch (
const std::exception& ex) {
2908 .arg(lease->addr_.toText())
2924 if (MultiThreadingMgr::instance().getMode()) {
2925 std::lock_guard<std::mutex> lock(*mutex_);
2926 return (buildExtendedInfoTables6Internal(update, current));
2928 return (buildExtendedInfoTables6Internal(update, current));
2936 static_cast<void>(relay_id_idx.erase(addr));
2939 static_cast<void>(remote_id_idx.erase(addr));
2944 const std::vector<uint8_t>& relay_id) {
2952 const std::vector<uint8_t>& remote_id) {
2960 if (MultiThreadingMgr::instance().getMode()) {
2961 std::lock_guard<std::mutex> lock(*mutex_);
2962 writeLeases4Internal(filename);
2964 writeLeases4Internal(filename);
2969 Memfile_LeaseMgr::writeLeases4Internal(
const std::string& filename) {
2975 std::ostringstream old;
2976 old << filename <<
".bak" << getpid();
2977 ::rename(filename.c_str(), old.str().c_str());
2980 for (
const auto& lease : storage4_) {
2981 backup.append(*lease);
2987 }
catch (
const std::exception&) {
2997 if (MultiThreadingMgr::instance().getMode()) {
2998 std::lock_guard<std::mutex> lock(*mutex_);
2999 writeLeases6Internal(filename);
3001 writeLeases6Internal(filename);
3006 Memfile_LeaseMgr::writeLeases6Internal(
const std::string& filename) {
3012 std::ostringstream old;
3013 old << filename <<
".bak" << getpid();
3014 ::rename(filename.c_str(), old.str().c_str());
3017 for (
const auto& lease : storage6_) {
3018 backup.append(*lease);
3024 }
catch (
const std::exception&) {
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.
RAII class creating a critical section.
Represents a configuration for Lease File Cleanup.
Tag for indexes by DUID, IAID, lease type tuple.
virtual ~MemfileLeaseStatsQuery4()
Destructor.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HWADDR
bool exists() const
Checks if the CSV file exists and can be opened for reading.
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 leases.
virtual ~Memfile_LeaseMgr()
Destructor (closes file)
virtual void recountClassLeases4() override
Recount the leases per class for V4 leases.
MemfileLeaseStatsQuery(const SubnetID &subnet_id)
Constructor for single subnet query.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
Lease6ExtendedInfoRemoteIdTable::index< LeaseAddressIndexTag >::type LeaseAddressRemoteIdIndex
Lease6 extended information by lease address index of by remote id table.
util::Optional< std::string > getDataDir() const
returns path do the data directory
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
A generic exception that is thrown when a function is not implemented.
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR6
void removeLease(LeasePtr lease)
Decrement the counts for all of a lease's classes by one.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
Structure that holds a lease for IPv4 address.
virtual void setExtendedInfoTablesEnabled(const bool enabled)
Extended information / Bulk Lease Query shared interface.
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4
boost::shared_ptr< Lease6ExtendedInfo > Lease6ExtendedInfoPtr
Pointer to a Lease6ExtendedInfo object.
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.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
std::pair< RemoteIdIndex::const_iterator, RemoteIdIndex::const_iterator > RemoteIdIndexRange
Lease6 extended information by remote id range.
int getExitStatus() const
Returns exit code of the last completed cleanup.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_START
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.
std::vector< LeaseStatsRow >::iterator next_pos_
An iterator for accessing the next row within the result set.
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.
static std::string typeToText(Type type)
returns text representation of a lease type
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_BUILD_EXTENDED_INFO_TABLES6_ERROR
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.
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
Tag for index using relay-id.
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6
Memfile derivation of the IPv6 statistical lease data query.
const isc::log::MessageID DHCPSRV_MEMFILE_GET6_DUID
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.
void updateLease(LeasePtr new_lease, LeasePtr old_lease)
Adjust class lease counts given a new and old version of a lease.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
MemfileLeaseStatsQuery(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for subnet range query.
static CfgMgr & instance()
returns a single instance of Configuration Manager
uint32_t preferred_lft_
Preferred lifetime.
Manages a pool of asynchronous interval timers.
Attempt to update lease that was not there.
Lease6ExtendedInfoRelayIdTable::index< LeaseAddressIndexTag >::type LeaseAddressRelayIdIndex
Lease6 extended information by lease address index of by relay id table.
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
Lease4Storage::index< HostnameIndexTag >::type Lease4StorageHostnameIndex
DHCPv4 lease storage index by hostname.
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
Universe
Specifies universe (V4, V6)
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
the lease contains IPv6 prefix (for prefix delegation)
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED4
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_HWADDR
Tag for indexes by expiration time.
std::vector< uint8_t > hwaddr_
bool isRunning() const
Checks if the lease file cleanup is in progress.
boost::shared_ptr< CSVLeaseFile4 > lease_file4_
Holds the pointer to the DHCPv4 lease file IO.
const isc::log::MessageID DHCPSRV_MEMFILE_CONVERTING_LEASE_FILES
virtual void writeLeases4(const std::string &filename) override
Write V4 leases to a file.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet identifier.
Base class for fulfilling a statistical lease data query.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SETUP
std::string getFilename() const
Returns the path to the CSV file.
void start()
Creates the IPv4 lease statistical data result set.
Class to help with processing PID files.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
Memfile_LeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
The sole lease manager constructor.
virtual Lease6Collection getLeases6ByLink(const asiolink::IOAddress &link_addr, uint8_t link_len, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with on a given link.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID
std::function< void()> Callback
virtual std::pair< uint32_t, uint32_t > getVersion() const override
Returns backend version.
boost::shared_ptr< CfgConsistency > CfgConsistencyPtr
Type used to for pointing to CfgConsistency structure.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv6 leases.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
Lease6ExtendedInfoRemoteIdTable::index< RemoteIdIndexTag >::type RemoteIdIndex
Lease6 extended information by remote id index.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE6
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_RELAYID4
const isc::log::MessageID DHCPSRV_MEMFILE_BUILD_EXTENDED_INFO_TABLES6
LFCFileType
Types of the lease files used by the Lease File Cleanup.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
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 DUID (DHCPv6 Unique Identifier)
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID4
Tag for index using hostname.
Exception thrown on failure to open database.
Provides methods to access CSV file with DHCPv4 leases.
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR6
const isc::log::MessageID DHCPSRV_MEMFILE_GET6
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.
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &subnet_id)
Constructor for a single subnet query.
static std::string getDBVersion()
Class method to return extended version info This class method must be redeclared and redefined in de...
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.
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR4
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &link_addr, uint8_t link_len, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given remote-id.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6_FINISHED
virtual void lfcCallback()
A callback function triggering Lease File Cleanup (LFC).
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by DUID.
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
virtual void commit() override
Commit Transactions.
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index subnet identifier.
const size_t page_size_
Holds page size.
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_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< 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_ > > >> Lease6Storage
A multi index container holding DHCPv6 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_RELAYID6
bool isLFCRunning() const
Checks if the process performing lease file cleanup is running.
Tag for index using remote-id.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
virtual bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
static const int MINOR_VERSION_V4
the minor version of the v4 memfile backend
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_EXECUTE
const isc::log::MessageID DHCPSRV_MEMFILE_ROLLBACK
Lease6 extended informations for Bulk Lease Query.
Lease6ExtendedInfoRelayIdTable relay_id6_
stores IPv6 by-relay-id cross-reference table
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR4
A generic exception that is thrown when an unexpected error condition occurs.
virtual std::string getDescription() const override
Returns description of the backend.
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 size_t buildExtendedInfoTables6(bool update, bool current) override
Build extended info v6 tables.
boost::shared_ptr< const Element > ConstElementPtr
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME6
Structure that holds a lease for IPv6 address and/or prefix.
int version()
returns Kea hooks version.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_ADDR
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.
Lease6Storage::index< HostnameIndexTag >::type Lease6StorageHostnameIndex
DHCPv6 lease storage index by hostname.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_UNREGISTER_TIMER_FAILED
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual void writeLeases6(const std::string &filename) override
Write V6 leases to a file.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
virtual bool isJsonSupported() const override
Checks if JSON support is enabled in the database.
Tag for index using DUID.
bool getExtendedInfoTablesEnabled() const
Returns the setting indicating if lease extended info tables are enabled.
bool isV6() const
Convenience function to check for an IPv6 address.
void addLease(LeasePtr lease)
Increment the counts for all of a lease's classes by one.
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
MemfileLeaseStatsQuery()
Constructor for all subnets query.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
bool isV4() const
Convenience function to check for an IPv4 address.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED6
Tag for indexes by HW address, subnet identifier tuple.
virtual void updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
the lease contains non-temporary IPv6 address
Memfile derivation of the IPv4 statistical lease data query.
virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress &addr) override
Extended information / Bulk Lease Query shared interface.
const isc::log::MessageID DHCPSRV_MEMFILE_GET4
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
virtual Lease6Collection getLeases6ByRelayId(const DUID &relay_id, const asiolink::IOAddress &link_addr, uint8_t link_len, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given relay-id.
Invalid address family used as input to Lease Manager.
std::string getLeaseFilePath(Universe u) const
Returns an absolute path to the lease file.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
bool persistLeases(Universe u) const
Specifies whether or not leases are written to disk.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Returns existing IPv4 lease for specified IPv4 address.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL
void clear()
Remove all entries.
std::string toText() const
Convert the address to a string.
update extended info tables.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED_START
static std::string sanityCheckToText(LeaseSanity check_type)
Converts lease sanity check value to printable text.
Tag for indexes by address.
Tag for indexes by lease address.
const isc::log::MessageID DHCPSRV_MEMFILE_COMMIT
Lease6ExtendedInfoRelayIdTable::index< RelayIdIndexTag >::type RelayIdIndex
Lease6 extended information by relay id index.
std::string getDefaultLeaseFilePath(Universe u) const
Returns default path to the lease file.
Exception thrown when error occurs during spawning a process.
virtual ~MemfileLeaseStatsQuery6()
Destructor.
virtual void recountClassLeases6() override
Recount the leases per class for V6 leases.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
Type
Type of lease or pool.
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
Holds Client identifier or client IPv4 address.
static const int MAJOR_VERSION_V4
A generic exception that is thrown if a function is called in a prohibited way.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
Provides input/output access to CSV files.
MemfileLeaseStatsQuery6(Lease6Storage &storage6)
Constructor.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const isc::log::MessageID DHCPSRV_MEMFILE_BEGIN_BUILD_EXTENDED_INFO_TABLES6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SPAWN_FAIL
static const int MAJOR_VERSION_V6
Hardware type that represents information from DHCPv4 packet.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
Base Memfile derivation of the statistical lease data query.
static const uint32_t STATE_DEFAULT
A lease in the default state.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE4
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4_FINISHED
Lease6ExtendedInfoRemoteIdTable remote_id6_
stores IPv6 by-remote-id cross-reference table
const isc::log::MessageID DHCPSRV_MEMFILE_GET_REMOTEID6
Tag for indexes by client and subnet identifiers.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
static const uint32_t STATE_DECLINED
Declined lease.
Contains a single row of lease statistical data.
std::vector< LeaseStatsRow > rows_
A vector containing the "result set".
void execute()
Spawns a new process.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
std::vector< std::string > ProcessArgs
Type of the container holding arguments of the executable being run as a background process...
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &subnet_id)
Constructor for a single subnet query.
Wraps value holding size of the page with leases.
const isc::log::MessageID DHCPSRV_MEMFILE_NO_STORAGE
ExtendedInfoAction
Action on extended info tables.
uint32_t valid_lft_
Valid lifetime.
std::string ClientClass
Defines a single class name.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Tag for indexes by subnet-id.
virtual ~MemfileLeaseStatsQuery()
Destructor.
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client and subnet identifier.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL
The IOAddress class represents an IP addresses (version agnostic)
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
boost::shared_ptr< CSVLeaseFile6 > lease_file6_
Holds the pointer to the DHCPv6 lease file IO.
virtual void start()
Creates the IPv6 lease statistical data result set.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
int getLFCExitStatus() const
Returns the status code returned by the last executed LFC process.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED4
virtual void clearClassLeaseCounts() override
Clears the class-lease count map.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
static const int MINOR_VERSION_V6
the minor version of the v6 memfile backend
Provides methods to access CSV file with DHCPv6 leases.
delete reference to the lease
static std::string appendSuffix(const std::string &file_name, const LFCFileType &file_type)
Appends appropriate suffix to the file name.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_CLIENTID
const isc::log::MessageID DHCPSRV_MEMFILE_GET_REMOTEID4
MemfileLeaseStatsQuery4(Lease4Storage &storage4)
Constructor for an all subnets query.
int getRowCount() const
Returns the number of rows in the result set.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
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.
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_LINKADDR6
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by Subnet-id.
virtual void rollback() override
Rollback Transactions.
Exception thrown when an error occurs during CSV file processing.
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
Utility class for spawning new processes.
int check() const
Read the PID in from the file and check it.
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_ > > > >> Lease4Storage
A multi index container holding DHCPv4 leases.