23#include <boost/algorithm/string.hpp>
54 if (
page_size_ > std::numeric_limits<uint32_t>::max()) {
56 << std::numeric_limits<uint32_t>::max());
62 uint32_t iaid,
SubnetID subnet_id)
const {
67 <<
static_cast<int>(type) <<
", duid "
68 << duid.
toText() <<
", iaid " << iaid
69 <<
" and subnet-id " << subnet_id);
74 return (*col.begin());
79 using namespace stats;
94 stats_mgr.
setValue(
"assigned-addresses", zero);
96 stats_mgr.
setValue(
"declined-addresses", zero);
100 stats_mgr.
setValue(
"reclaimed-declined-addresses", zero);
105 stats_mgr.
setValue(
"reclaimed-leases", zero);
110 stats_mgr.
setValue(
"cumulative-assigned-addresses", zero);
118 for (
auto const& subnet : *subnets) {
119 SubnetID subnet_id = subnet->getID();
121 "assigned-addresses"),
125 "declined-addresses"),
129 "reclaimed-declined-addresses"));
131 stats_mgr.
setValue(name_rec_dec, zero);
135 "reclaimed-leases"));
143 "assigned-addresses")));
150 "declined-addresses")));
157 "reclaimed-declined-addresses")));
159 stats_mgr.
setValue(pname_rec_dec, zero);
164 "reclaimed-leases")));
166 stats_mgr.
setValue(pname_rec, zero);
174 while (query->getNextRow(row)) {
181 "assigned-addresses"),
186 "declined-addresses"),
198 "assigned-addresses"),
211 while (query->getNextRow(row)) {
216 "assigned-addresses")),
222 "declined-addresses")),
229 "assigned-addresses")),
238 isc_throw(
BadValue,
"LeaseStatsQuery: mode must be either ALL_SUBNETS or ALL_SUBNET_POOLS");
266 "LeaseStatsQuery: last_subnet_id_must be > first_subnet_id_");
298 using namespace stats;
314 stats_mgr.
setValue(
"assigned-nas", zero);
316 stats_mgr.
setValue(
"assigned-pds", zero);
318 stats_mgr.
setValue(
"declined-addresses", zero);
321 stats_mgr.
setValue(
"reclaimed-declined-addresses", zero);
325 stats_mgr.
setValue(
"reclaimed-leases", zero);
330 stats_mgr.
setValue(
"cumulative-assigned-nas", zero);
335 stats_mgr.
setValue(
"cumulative-assigned-pds", zero);
340 stats_mgr.
setValue(
"cumulative-registered-nas", zero);
348 for (
auto const& subnet : *subnets) {
349 SubnetID subnet_id = subnet->getID();
359 "declined-addresses"),
364 "reclaimed-declined-addresses"))) {
367 "reclaimed-declined-addresses"),
373 "reclaimed-leases"))) {
382 "registered-nas"))) {
394 stats_mgr.
setValue(name_anas, zero);
399 "declined-addresses")));
406 "reclaimed-declined-addresses")));
408 stats_mgr.
setValue(name_rec_dec, zero);
413 "reclaimed-leases")));
424 stats_mgr.
setValue(name_apds, zero);
429 "reclaimed-leases")));
439 while (query->getNextRow(row)) {
453 "declined-addresses"),
501 while (query->getNextRow(row)) {
514 "declined-addresses")),
571 std::string extended_info_tables;
573 extended_info_tables = parameters.at(
"extended-info-tables");
574 }
catch (
const exception&) {
575 extended_info_tables =
"false";
578 if (extended_info_tables ==
"true") {
588 bool changed =
false;
606 string verifying =
"";
607 bool removed_extended_info =
false;
610 verifying =
"user context";
614 if (user_context->empty()) {
621 isc = user_context->get(
"ISC");
625 mutable_user_context =
626 boost::const_pointer_cast<Element>(user_context);
627 if (!mutable_user_context) {
629 mutable_user_context =
copy(user_context, 0);
630 lease->setContext(mutable_user_context);
638 mutable_user_context->remove(
"ISC");
639 if (mutable_user_context->empty()) {
645 verifying =
"relay-agent-info";
646 extended_info =
isc->get(
"relay-agent-info");
647 if (!extended_info) {
650 mutable_isc = boost::const_pointer_cast<Element>(
isc);
654 mutable_user_context->set(
"ISC", mutable_isc);
661 upgraded->set(
"sub-options", extended_info);
662 mutable_isc->set(
"relay-agent-info", upgraded);
666 string rai_hex = extended_info->stringValue();
667 vector<uint8_t> rai_data;
676 vector<uint8_t> bytes = remote_id->toBinary();
677 if (bytes.size() > 0) {
678 upgraded->set(
"remote-id",
685 vector<uint8_t> bytes = relay_id->toBinary(
false);
686 if (bytes.size() > 0) {
687 upgraded->set(
"relay-id",
694 .arg(lease->addr_.toText());
697 mutable_isc->remove(
"relay-agent-info");
698 removed_extended_info =
true;
709 verifying =
"sub-options";
711 mutable_isc->remove(
"relay-agent-info");
712 removed_extended_info =
true;
715 string rai_hex = sub_options->stringValue();
716 vector<uint8_t> rai_data;
722 verifying =
"remote-id";
724 mutable_isc->remove(
"relay-agent-info");
725 removed_extended_info =
true;
728 string remote_id_hex = remote_id->stringValue();
729 vector<uint8_t> remote_id_data;
731 if (remote_id_data.empty()) {
732 mutable_isc->remove(
"relay-agent-info");
733 removed_extended_info =
true;
740 verifying =
"relay-id";
742 mutable_isc->remove(
"relay-agent-info");
743 removed_extended_info =
true;
746 string relay_id_hex = relay_id->stringValue();
747 vector<uint8_t> relay_id_data;
749 if (relay_id_data.empty()) {
750 mutable_isc->remove(
"relay-agent-info");
751 removed_extended_info =
true;
760 verifying =
"relay-agent-info";
761 for (
auto const& elem : extended_info->mapValue()) {
762 if ((elem.first !=
"sub-options") &&
763 (elem.first !=
"remote-id") &&
764 (elem.first !=
"relay-id") &&
765 (elem.first !=
"comment")) {
766 mutable_isc->remove(
"relay-agent-info");
767 removed_extended_info =
true;
769 "' entry in relay-agent-info");
774 }
catch (
const exception& ex) {
776 err <<
"in " << verifying <<
" a problem was found: " << ex.what();
778 .arg(lease->addr_.toText())
782 if (verifying ==
"user context") {
784 }
else if (verifying ==
"isc") {
785 mutable_user_context->remove(
"ISC");
786 if (mutable_user_context->empty()) {
790 if (!removed_extended_info) {
791 mutable_isc->remove(
"relay-agent-info");
793 if (mutable_isc->empty()) {
794 mutable_user_context->remove(
"ISC");
795 if (mutable_user_context->empty()) {
807 bool changed =
false;
825 string verifying =
"";
826 bool removed_relay_info =
false;
827 bool upgraded =
false;
828 bool have_both =
false;
832 verifying =
"user context";
836 if (user_context->empty()) {
843 isc = user_context->get(
"ISC");
847 mutable_user_context =
848 boost::const_pointer_cast<Element>(user_context);
849 if (!mutable_user_context) {
851 mutable_user_context =
copy(user_context, 0);
852 lease->setContext(mutable_user_context);
860 mutable_user_context->remove(
"ISC");
861 if (mutable_user_context->empty()) {
866 mutable_isc = boost::const_pointer_cast<Element>(
isc);
870 mutable_user_context->set(
"ISC", mutable_isc);
873 relay_info = mutable_isc->get(
"relays");
874 if (relay_info &&
isc->contains(
"relay-info")) {
876 mutable_isc->remove(
"relays");
884 verifying =
"relays";
885 mutable_isc->set(
"relay-info", relay_info);
886 mutable_isc->remove(
"relays");
889 mutable_isc->remove(
"relay-info");
890 removed_relay_info =
true;
893 if (relay_info->empty()) {
894 mutable_isc->remove(
"relay-info");
895 removed_relay_info =
true;
900 for (i = 0;
static_cast<size_t>(i) < relay_info->size(); ++i) {
901 ElementPtr relay = relay_info->getNonConst(i);
903 mutable_isc->remove(
"relay-info");
904 removed_relay_info =
true;
908 mutable_isc->remove(
"relay-info");
909 removed_relay_info =
true;
919 verifying =
"options";
921 mutable_isc->remove(
"relay-info");
922 removed_relay_info =
true;
925 string options_hex = options->stringValue();
926 vector<uint8_t> options_data;
932 if (remote_id_it != opts.end()) {
933 OptionPtr remote_id = remote_id_it->second;
935 vector<uint8_t> bytes = remote_id->toBinary();
936 if (bytes.size() > 0) {
937 relay->set(
"remote-id",
944 if (relay_id_it != opts.end()) {
945 OptionPtr relay_id = relay_id_it->second;
947 vector<uint8_t> bytes = relay_id->toBinary(
false);
948 if (bytes.size() > 0) {
949 relay->set(
"relay-id",
957 verifying = (upgraded ?
"relays" :
"relay-info");
959 relay_info = mutable_isc->get(
"relay-info");
964 mutable_isc->remove(
"relay-info");
965 removed_relay_info =
true;
968 if (!upgraded && relay_info->empty()) {
969 mutable_isc->remove(
"relay-info");
970 removed_relay_info =
true;
975 for (i = 0;
static_cast<size_t>(i) < relay_info->size(); ++i) {
976 ElementPtr relay = relay_info->getNonConst(i);
977 if (!upgraded && !relay) {
978 mutable_isc->remove(
"relay-info");
979 removed_relay_info =
true;
983 mutable_isc->remove(
"relay-info");
984 removed_relay_info =
true;
989 if (!upgraded && options) {
991 verifying =
"options";
993 mutable_isc->remove(
"relay-info");
994 removed_relay_info =
true;
997 string options_hex = options->stringValue();
998 vector<uint8_t> options_data;
1010 mutable_isc->remove(
"relay-info");
1011 removed_relay_info =
true;
1015 mutable_isc->remove(
"relay-info");
1016 removed_relay_info =
true;
1019 IOAddress laddr(link_addr->stringValue());
1020 if (!laddr.
isV6()) {
1021 mutable_isc->remove(
"relay-info");
1022 removed_relay_info =
true;
1027 if (!upgraded && remote_id) {
1028 verifying =
"remote-id";
1030 mutable_isc->remove(
"relay-info");
1031 removed_relay_info =
true;
1034 string remote_id_hex = remote_id->stringValue();
1035 vector<uint8_t> remote_id_data;
1037 if (remote_id_data.empty()) {
1038 mutable_isc->remove(
"relay-info");
1039 removed_relay_info =
true;
1045 if (!upgraded && relay_id) {
1046 verifying =
"relay-id";
1048 mutable_isc->remove(
"relay-info");
1049 removed_relay_info =
true;
1052 string relay_id_hex = relay_id->stringValue();
1053 vector<uint8_t> relay_id_data;
1055 if (relay_id_data.empty()) {
1056 mutable_isc->remove(
"relay-info");
1057 removed_relay_info =
true;
1069 mutable_isc->remove(
"relay-info");
1070 removed_relay_info =
true;
1074 mutable_isc->remove(
"relay-info");
1075 removed_relay_info =
true;
1078 IOAddress paddr(peer_addr->stringValue());
1079 if (!paddr.
isV6()) {
1080 mutable_isc->remove(
"relay-info");
1081 removed_relay_info =
true;
1088 mutable_isc->remove(
"relay-info");
1089 removed_relay_info =
true;
1093 mutable_isc->remove(
"relay-info");
1094 removed_relay_info =
true;
1098 verifying = (upgraded ?
"relays" :
"relay-info");
1099 for (
auto const& elem : relay->mapValue()) {
1100 if ((elem.first !=
"hop") &&
1101 (elem.first !=
"link") &&
1102 (elem.first !=
"peer") &&
1103 (elem.first !=
"options") &&
1104 (elem.first !=
"remote-id") &&
1105 (elem.first !=
"relay-id") &&
1106 (elem.first !=
"comment")) {
1107 mutable_isc->remove(
"relay-info");
1108 removed_relay_info =
true;
1117 .arg(lease->addr_.toText());
1121 }
catch (
const exception& ex) {
1123 err <<
"in " << verifying;
1125 err <<
" [relay#" << i <<
"]";
1127 err <<
" a problem was found: " << ex.what();
1129 .arg(lease->addr_.toText())
1133 have_both = !have_both;
1134 if (verifying ==
"user context") {
1136 }
else if (verifying ==
"isc") {
1137 mutable_user_context->remove(
"ISC");
1138 if (mutable_user_context->empty()) {
1142 if (!removed_relay_info) {
1143 mutable_isc->remove(
"relay-info");
1145 if (mutable_isc->empty()) {
1146 mutable_user_context->remove(
"ISC");
1147 if (mutable_user_context->empty()) {
1158 bool ignore_errors) {
1164 if (!user_context) {
1168 if (ignore_errors) {
1173 if (user_context->empty()) {
1182 if (ignore_errors) {
1192 if (!extended_info) {
1196 if (ignore_errors) {
1201 if (extended_info->empty()) {
1208 vector<uint8_t> bytes;
1213 if (!ignore_errors) {
1217 lease->relay_id_ = bytes;
1218 }
else if (!ignore_errors) {
1226 vector<uint8_t> bytes;
1231 if (!ignore_errors) {
1235 lease->remote_id_ = bytes;
1236 }
else if (!ignore_errors) {
1251 if (!user_context || (user_context->getType() !=
Element::map) ||
1252 user_context->empty()) {
1262 if (!relay_info || (relay_info->getType() !=
Element::list) ||
1263 relay_info->empty()) {
1267 for (
unsigned i = 0; i < relay_info->size(); ++i) {
1269 if (!relay || (relay->getType() !=
Element::map) || relay->empty()) {
1275 string relay_id_hex = relay_id->stringValue();
1276 vector<uint8_t> relay_id_data;
1278 if (relay_id_data.empty()) {
1287 string remote_id_hex = remote_id->stringValue();
1288 vector<uint8_t> remote_id_data;
1290 if (remote_id_data.empty()) {
1296 }
catch (
const exception&) {
1321 msg <<
"lease backend '" <<
getName() <<
"' is not 'memfile'";
1327 if (!lease->stateExpiredReclaimed()) {
1332 "assigned-addresses"),
1333 static_cast<int64_t
>(1));
1343 "assigned-addresses")),
1344 static_cast<int64_t
>(1));
1348 if (lease->stateDeclined()) {
1353 "declined-addresses"),
1354 static_cast<int64_t
>(1));
1360 "declined-addresses")),
1361 static_cast<int64_t
>(1));
1369 if (lease->stateRegistered()) {
1372 static_cast<int64_t
>(1));
1373 }
else if (!lease->stateExpiredReclaimed()) {
1375 "assigned-nas" :
"assigned-pds",
1376 static_cast<int64_t
>(1));
1381 "assigned-nas" :
"assigned-pds"),
1382 static_cast<int64_t
>(1));
1387 pool = subnet->getPool(lease->type_, lease->addr_,
false);
1392 "pool" :
"pd-pool", pool->getID(),
1394 "assigned-nas" :
"assigned-pds")),
1395 static_cast<int64_t
>(1));
1399 if (lease->stateDeclined()) {
1404 "declined-addresses"),
1405 static_cast<int64_t
>(1));
1411 "declined-addresses")),
1412 static_cast<int64_t
>(1));
1422 static_cast<int64_t
>(value));
1426 static_cast<int64_t
>(value));
1434 static_cast<int64_t
>(value));
1438 static_cast<int64_t
>(value));
1443#define STATE_MASK(new_state, old_state) ((new_state << 4) | old_state)
1514 if (existing->subnet_id_ == lease->subnet_id_) {
1515 if (existing->state_ == lease->state_) {
1523 getCfgSubnets4()->getBySubnetId(existing->subnet_id_);
1529 switch (
STATE_MASK(lease->state_ , existing->state_)) {
1531 bumpStat(
"declined-addresses", existing->subnet_id_, pool, -1);
1536 bumpStat(
"assigned-addresses", existing->subnet_id_, pool, 1);
1540 bumpStat(
"declined-addresses", existing->subnet_id_, pool, 1);
1545 bumpStat(
"assigned-addresses", existing->subnet_id_, pool, 1);
1546 bumpStat(
"declined-addresses", existing->subnet_id_, pool, 1);
1551 bumpStat(
"assigned-addresses", existing->subnet_id_, pool, -1);
1556 bumpStat(
"assigned-addresses", existing->subnet_id_, pool, -1);
1557 bumpStat(
"declined-addresses", existing->subnet_id_, pool, -1);
1570 getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
1573 new_pool = new_subnet->getPool(
Lease::TYPE_V4, lease->addr_,
false);
1578 getCfgSubnets4()->getBySubnetId(existing->subnet_id_);
1580 if (existing_subnet) {
1581 existing_pool = existing_subnet->getPool(
Lease::TYPE_V4, existing->addr_,
false);
1585 switch (
STATE_MASK(lease->state_ , existing->state_)) {
1587 bumpStat(
"assigned-addresses", existing->subnet_id_, existing_pool, -1);
1588 bumpStat(
"assigned-addresses", lease->subnet_id_, new_pool, 1);
1592 bumpStat(
"assigned-addresses", existing->subnet_id_, existing_pool, -1);
1593 bumpStat(
"declined-addresses", existing->subnet_id_, existing_pool, -1);
1594 bumpStat(
"assigned-addresses", lease->subnet_id_, new_pool, 1);
1599 bumpStat(
"assigned-addresses", lease->subnet_id_, new_pool, 1);
1603 bumpStat(
"assigned-addresses", existing->subnet_id_, existing_pool, -1);
1604 bumpStat(
"assigned-addresses", lease->subnet_id_, new_pool, 1);
1605 bumpStat(
"declined-addresses", lease->subnet_id_, new_pool, 1);
1609 bumpStat(
"assigned-addresses", existing->subnet_id_, existing_pool, -1);
1610 bumpStat(
"declined-addresses", existing->subnet_id_, existing_pool, -1);
1611 bumpStat(
"assigned-addresses", lease->subnet_id_, new_pool, 1);
1612 bumpStat(
"declined-addresses", lease->subnet_id_, new_pool, 1);
1617 bumpStat(
"assigned-addresses", lease->subnet_id_, new_pool, 1);
1618 bumpStat(
"declined-addresses", lease->subnet_id_, new_pool, 1);
1623 bumpStat(
"assigned-addresses", existing->subnet_id_, existing_pool, -1);
1628 bumpStat(
"assigned-addresses", existing->subnet_id_, existing_pool, -1);
1629 bumpStat(
"declined-addresses", existing->subnet_id_, existing_pool, -1);
1643 if (existing->type_ != lease->type_) {
1657 if (existing->subnet_id_ == lease->subnet_id_) {
1658 if (existing->state_ == lease->state_) {
1666 getCfgSubnets6()->getBySubnetId(existing->subnet_id_);
1668 pool = subnet->getPool(existing->type_, existing->addr_,
false);
1672 switch (
STATE_MASK(lease->state_, existing->state_)) {
1674 bumpStat(
"declined-addresses", existing->subnet_id_, pool, -1);
1680 bumpStat(
"assigned-nas", existing->subnet_id_, pool, 1);
1687 bumpStat(
"assigned-nas", existing->subnet_id_, pool, 1);
1692 bumpStat(
"declined-addresses", existing->subnet_id_, pool, 1);
1697 bumpStat(
"assigned-nas", existing->subnet_id_, pool, 1);
1698 bumpStat(
"declined-addresses", existing->subnet_id_, pool, 1);
1702 bumpStat(
"declined-addresses", existing->subnet_id_, pool, 1);
1709 bumpStat(
"assigned-nas", existing->subnet_id_, pool, -1);
1722 bumpStat(
"assigned-nas", existing->subnet_id_, pool, -1);
1723 bumpStat(
"declined-addresses", existing->subnet_id_, pool, -1);
1727 bumpStat(
"assigned-nas", existing->subnet_id_, pool, -1);
1732 bumpStat(
"assigned-nas", existing->subnet_id_, pool, -1);
1733 bumpStat(
"declined-addresses", existing->subnet_id_, pool, -1);
1753 getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
1756 new_pool = new_subnet->getPool(lease->type_, lease->addr_,
false);
1761 getCfgSubnets6()->getBySubnetId(existing->subnet_id_);
1763 if (existing_subnet) {
1764 existing_pool = existing_subnet->getPool(existing->type_, existing->addr_,
false);
1768 switch (
STATE_MASK(lease->state_, existing->state_)) {
1771 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1772 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1774 bumpStatPrefix(
"assigned-pds", existing->subnet_id_, existing_pool, -1);
1780 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1781 bumpStat(
"declined-addresses", existing->subnet_id_, existing_pool, -1);
1782 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1788 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1796 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1800 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1801 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1802 bumpStat(
"declined-addresses", lease->subnet_id_, new_pool, 1);
1806 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1807 bumpStat(
"declined-addresses", existing->subnet_id_, existing_pool, -1);
1808 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1809 bumpStat(
"declined-addresses", lease->subnet_id_, new_pool, 1);
1814 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1815 bumpStat(
"declined-addresses", lease->subnet_id_, new_pool, 1);
1820 bumpStat(
"assigned-nas", lease->subnet_id_, new_pool, 1);
1821 bumpStat(
"declined-addresses", lease->subnet_id_, new_pool, 1);
1827 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1829 bumpStatPrefix(
"assigned-pds", existing->subnet_id_, existing_pool, -1);
1835 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1836 bumpStat(
"declined-addresses", existing->subnet_id_, existing_pool, -1);
1845 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1850 bumpStat(
"assigned-nas", existing->subnet_id_, existing_pool, -1);
1851 bumpStat(
"declined-addresses", existing->subnet_id_, existing_pool, -1);
1875 if (!lease->stateExpiredReclaimed()) {
1880 "assigned-addresses"),
1881 static_cast<int64_t
>(-1));
1891 "assigned-addresses")),
1892 static_cast<int64_t
>(-1));
1896 if (lease->stateDeclined()) {
1901 "declined-addresses"),
1902 static_cast<int64_t
>(-1));
1908 "declined-addresses")),
1909 static_cast<int64_t
>(-1));
1917 if (lease->stateRegistered()) {
1921 static_cast<int64_t
>(-1));
1922 }
else if (!lease->stateExpiredReclaimed()) {
1924 "assigned-nas" :
"assigned-pds",
1925 static_cast<int64_t
>(-1));
1930 "assigned-nas" :
"assigned-pds"),
1931 static_cast<int64_t
>(-1));
1936 pool = subnet->getPool(lease->type_, lease->addr_,
false);
1941 "pool" :
"pd-pool", pool->getID(),
1943 "assigned-nas" :
"assigned-pds")),
1944 static_cast<int64_t
>(-1));
1948 if (lease->stateDeclined()) {
1953 "declined-addresses"),
1954 static_cast<int64_t
>(-1));
1960 "declined-addresses")),
1961 static_cast<int64_t
>(-1));
2058 getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
2062 return (subnet->getAllocator(
Lease::TYPE_V4)->getType() ==
"shared-flq");
2074 getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
2078 return (subnet->getAllocator(lease->getType())->getType() ==
"shared-flq");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when a function is not implemented.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The IOAddress class represents an IP addresses (version agnostic)
bool isV6() const
Convenience function to check for an IPv6 address.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Notes: IntElement type is changed to int64_t.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Multiple lease records found where one expected.
ExtendedInfoSanity
Values for extended info sanity checks done for leases.
@ EXTENDED_INFO_CHECK_PEDANTIC
@ EXTENDED_INFO_CHECK_FIX
@ EXTENDED_INFO_CHECK_NONE
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Holds DUID (DHCPv6 Unique Identifier)
std::string toText() const
Returns textual representation of the identifier (e.g.
virtual bool sflqPool4Del(asiolink::IOAddress start_address, asiolink::IOAddress end_address, bool force=false)
Delete the SFLQ V4 pool that matches a start and end address.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets and pools.
virtual Lease6Collection getLeases6() const =0
Returns all IPv6 leases.
void recountLeaseStats6()
Recalculates per-subnet and global stats for IPv6 leases.
virtual data::ElementPtr getStatus() const
Return status information.
void setExtendedInfoTablesEnabled(const bool enabled)
Modifies the setting whether the lease6 extended info tables are enabled.
virtual bool sflqPool6Del(asiolink::IOAddress start_address, asiolink::IOAddress end_address, bool force=false)
Delete the SFLQ V6 pool that matches a start and end address.
virtual size_t byRelayId6size() const
Return the by-relay-id table size.
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.
virtual SflqPoolInfoCollectionPtr sflqPool4Get(SubnetID subnet_id)
Fetch all SFLQ V4 pools belonging to a subnet.
virtual SflqPoolInfoCollectionPtr sflqPool4GetAll()
Fetch all SFLQ V4 pools.
static void updateStatsOnAdd(const Lease4Ptr &lease)
Update in-memory stats when adding a v4 lease.
virtual size_t byRemoteId6size() const
Return the by-remote-id table size.
virtual asiolink::IOAddress sflqPickFreeLease4(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V4 address within the given pool range.
static void updateStatsOnUpdate(const Lease4Ptr &existing, const Lease4Ptr &lease)
Update in-memory stats when updating a v4 lease.
static bool useSharedFlqStatement(Lease4Ptr lease)
Determine if SFLQ alternate SQL statements should be used for a given v4 lease.
virtual void addRelayId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &relay_id)=0
Add lease6 extended info into by-relay-id table.
static void bumpStatPrefix(const std::string &stat, SubnetID &subnet_id, PoolPtr pool, int value)
Helper function that adds a value to a prefix stat's global, subnet, and pool level values.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
virtual std::string getName() const =0
Returns backend name.
void recountLeaseStats4()
Recalculates per-subnet and global stats for IPv4 leases.
static std::string getDBVersion()
Class method to return extended version info This class method must be redeclared and redefined in de...
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
static void updateStatsOnDelete(const Lease4Ptr &lease)
Update in-memory stats when deleting a v4 lease.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const =0
Returns existing IPv6 lease for a given IPv6 address.
virtual isc::data::ConstElementPtr lfcStartHandler()
Handler for kea-lfc-start command.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets.
static void extractLease4ExtendedInfo(const Lease4Ptr &lease, bool ignore_errors=true)
Extract relay and remote identifiers from the extended info.
virtual bool sflqCreateFlqPool4(asiolink::IOAddress start_address, asiolink::IOAddress end_address, SubnetID subnet_id, bool recreate=false)
Creates a v4 SFLQ Pool.
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 SflqPoolInfoCollectionPtr sflqPool6GetAll()
Fetch all SFLQ V6 pools.
virtual void addRemoteId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &remote_id)=0
Add lease6 extended info into by-remote-id table.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query for all subnets and pools.
static void bumpStat(const std::string &stat, SubnetID &subnet_id, PoolPtr pool, int value)
Helper function that adds a value to an address stat's global, subnet, and pool level values.
virtual bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
virtual asiolink::IOAddress sflqPickFreeLease6(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V6 address/prefix within the given pool range.
virtual SflqPoolInfoCollectionPtr sflqPool6Get(SubnetID subnet_id)
Fetch all SFLQ V6 pools belonging to a subnet.
virtual bool sflqCreateFlqPool6(asiolink::IOAddress start_address, asiolink::IOAddress end_address, Lease::Type lease_type, uint8_t delegated_len, SubnetID subnet_id, bool recreate=false)
Calls stored procedure to create an SFLQ pool for v6.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query for all subnets.
const size_t page_size_
Holds page size.
LeasePageSize(const size_t page_size)
Constructor.
LeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor to query statistics for all subnets.
SubnetID first_subnet_id_
First (or only) subnet_id in the selection criteria.
SubnetID last_subnet_id_
Last subnet_id in the selection criteria when a range is given.
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row of data.
SelectMode
Defines the types of selection criteria supported.
static const OptionDefinition & DHO_DHCP_AGENT_OPTIONS_DEF()
Get definition of DHO_DHCP_AGENT_OPTIONS option.
static size_t unpackOptions6(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, size_t *relay_msg_offset=0, size_t *relay_msg_len=0)
Parses provided buffer as DHCPv6 options and creates Option objects.
Option with defined data fields represented as buffers that can be accessed using data field index.
Base class representing a DHCP option definition.
data::ConstElementPtr toElement() const
boost::posix_time::ptime modified_ts_
boost::posix_time::ptime created_ts_
asiolink::IOAddress start_address_
asiolink::IOAddress end_address_
static bool inUse()
Returns the global in-use flag.
Statistics Manager class.
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
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.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
#define STATE_MASK(new_state, old_state)
Creates a mask out of two states: new state and old state.
An abstract API for lease database.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
constexpr uint16_t DECLINED_RECLAIMED
constexpr uint16_t RECLAIMED_ASSIGNED
constexpr uint16_t REGISTERED_RELEASED
boost::shared_ptr< SflqPoolInfoCollection > SflqPoolInfoCollectionPtr
const isc::log::MessageID DHCPSRV_LEASE6_EXTENDED_INFO_UPGRADED
boost::shared_ptr< OptionCustom > OptionCustomPtr
A pointer to the OptionCustom object.
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.
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet6Collection
A collection of Subnet6 objects.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
constexpr uint16_t REGISTERED_ASSIGNED
constexpr uint16_t RELEASED_DECLINED
constexpr uint16_t ASSIGNED_ASSIGNED
Constant expression state masks for use in switch statements.
constexpr uint16_t ASSIGNED_DECLINED
constexpr uint16_t RECLAIMED_REGISTERED
constexpr uint16_t RELEASED_ASSIGNED
constexpr uint16_t RECLAIMED_DECLINED
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet4Collection
A collection of Subnet4 objects.
constexpr uint16_t REGISTERED_REGISTERED
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
constexpr uint16_t DECLINED_ASSIGNED
constexpr uint16_t RELEASED_REGISTERED
constexpr uint16_t ASSIGNED_RECLAIMED
constexpr uint16_t DECLINED_REGISTERED
constexpr uint16_t DECLINED_RELEASED
constexpr uint16_t ASSIGNED_RELEASED
constexpr uint16_t DECLINED_DECLINED
const isc::log::MessageID DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL
const isc::log::MessageID DHCPSRV_LEASE4_EXTENDED_INFO_UPGRADED
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
boost::shared_ptr< Option > OptionPtr
const isc::log::MessageID DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL
constexpr uint16_t REGISTERED_DECLINED
constexpr uint16_t ASSIGNED_REGISTERED
constexpr uint16_t REGISTERED_RECLAIMED
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
std::string ptimeToText(boost::posix_time::ptime t, size_t fsecs_precision=MAX_FSECS_PRECISION)
Converts ptime structure to text.
Defines the logger used by the top-level component of kea-lfc.
#define DHCP6_OPTION_SPACE
Contains a single row of lease statistical data.
uint32_t pool_id_
The pool ID to which this data applies.
int64_t state_count_
state_count The count of leases in the lease state
uint32_t lease_state_
The lease_state to which the count applies.
SubnetID subnet_id_
The subnet ID to which this data applies.
Lease::Type lease_type_
The lease_type to which the count applies.
a common structure for IPv4 and IPv6 leases
static constexpr uint32_t STATE_DEFAULT
A lease in the default state.
static constexpr uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
static constexpr uint32_t STATE_DECLINED
Declined lease.
static constexpr uint32_t STATE_REGISTERED
Registered self-generated lease.
static constexpr uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
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 std::string typeToText(Type type)
returns text representation of a lease type