37static constexpr size_t HOSTNAME_MAX_LEN = 255u;
38static constexpr size_t ADDRESS6_TEXT_MAX_LEN = 39u;
39static constexpr char NULL_USER_CONTEXT[] =
"";
176 virtual boost::any
retrieve()
override;
240 cass_int32_t address_;
264 "INSERT INTO lease4( "
265 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
266 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
268 "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? "
279 "valid_lifetime = ?, "
292 "DELETE FROM lease4 "
300 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
301 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
306 "ALLOW FILTERING "}},
312 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
313 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
320 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
321 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
323 "WHERE address = ? "}},
326 {GET_LEASE4_CLIENTID,
327 {GET_LEASE4_CLIENTID,
329 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
330 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
332 "WHERE client_id = ? "
333 "ALLOW FILTERING "}},
336 {GET_LEASE4_CLIENTID_SUBID,
337 {GET_LEASE4_CLIENTID_SUBID,
339 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
340 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
342 "WHERE client_id = ? "
344 "ALLOW FILTERING "}},
350 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
351 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
354 "ALLOW FILTERING "}},
357 {GET_LEASE4_HWADDR_SUBID,
358 {GET_LEASE4_HWADDR_SUBID,
360 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
361 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
365 "ALLOW FILTERING "}},
371 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
372 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
375 "ALLOW FILTERING "}},
381 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
382 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
384 "WHERE TOKEN(address) > TOKEN(?) "
386 "ALLOW FILTERING "}},
392 "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
393 "fqdn_fwd, fqdn_rev, hostname, state, user_context "
395 "WHERE subnet_id = ? "
407 "Lease4 object is NULL");
418 address_ =
static_cast<cass_int32_t
>(lease->addr_.toUint32());
421 if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
425 << lease_->hwaddr_->toText() <<
" of length "
426 << lease_->hwaddr_->hwaddr_.size()
427 <<
" exceeds maximum allowed length of "
430 hwaddr_ = lease_->hwaddr_->hwaddr_;
436 if (lease_->client_id_ && lease_->client_id_->getClientId().size() > 0) {
437 client_id_ = lease_->client_id_->getClientId();
455 subnet_id_ =
static_cast<cass_int32_t
>(lease_->subnet_id_);
458 fqdn_fwd_ = lease_->fqdn_fwd_ ? cass_true : cass_false;
461 fqdn_rev_ = lease_->fqdn_rev_ ? cass_true : cass_false;
464 if (lease_->hostname_.size() > HOSTNAME_MAX_LEN) {
466 "hostname " << lease_->hostname_ <<
" of length "
467 << lease_->hostname_.size()
468 <<
" exceeds maximum allowed length of "
469 << HOSTNAME_MAX_LEN);
474 state_ =
static_cast<cass_int32_t
>(lease_->state_);
488 data.
add(&client_id_);
500 "could not create bind array from Lease4: " << lease_->addr_.toText()
501 <<
", reason: " << ex.
what());
510 "Lease4 object is NULL");
521 address_ =
static_cast<cass_int32_t
>(lease->addr_.toUint32());
524 if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
528 << lease_->hwaddr_->toText() <<
" of length "
529 << lease_->hwaddr_->hwaddr_.size()
530 <<
" exceeds maximum allowed length of "
533 hwaddr_ = lease_->hwaddr_->hwaddr_;
539 if (lease_->client_id_ && lease_->client_id_->getClientId().size() > 0) {
540 client_id_ = lease_->client_id_->getClientId();
558 subnet_id_ =
static_cast<cass_int32_t
>(lease_->subnet_id_);
561 fqdn_fwd_ = lease_->fqdn_fwd_ ? cass_true : cass_false;
564 fqdn_rev_ = lease_->fqdn_rev_ ? cass_true : cass_false;
567 if (lease_->hostname_.size() > HOSTNAME_MAX_LEN) {
569 "hostname " << lease_->hostname_ <<
" of length "
570 << lease_->hostname_.size()
571 <<
" exceeds maximum allowed length of "
572 << HOSTNAME_MAX_LEN);
577 state_ =
static_cast<cass_int32_t
>(lease_->state_);
590 data.
add(&client_id_);
603 "CqlLease4Exchange::createBindUpdate(): "
604 "could not create bind array from Lease4: "
605 << lease_->addr_.toText() <<
", reason: " << ex.
what());
617 address_ =
static_cast<cass_int32_t
>(address.
toUint32());
625 "CqlLease4Exchange::createBindForDelete(): "
626 "could not create bind array with address: "
627 << address_ <<
", reason: " << ex.
what());
644 data.
add(&client_id_);
679 <<
" of length " <<
hwaddr_.size()
680 <<
" exceeds maximum allowed length of "
685 "client ID " <<
ClientId(client_id_).toText()
686 <<
" of length " << client_id_.size()
687 <<
" exceeds maximum allowed length of "
690 if (
hostname_.size() > HOSTNAME_MAX_LEN) {
694 <<
" exceeds maximum allowed length of "
695 << HOSTNAME_MAX_LEN);
703 uint32_t addr4 =
static_cast<uint32_t
>(address_);
710 <<
"' is not a JSON map");
722 result->setContext(ctx);
728 "CqlLease4Exchange::retrieve(): "
729 "could not convert data to Lease4, reason: "
740 for (boost::any &element : collection) {
741 result.push_back(boost::any_cast<Lease4Ptr>(element));
754 const size_t collection_size = collection.size();
755 if (collection_size >= 2u) {
757 "CqlLease4Exchange::getLease(): multiple records were found in "
758 "the database where only one was expected for statement "
760 }
else if (collection_size == 0u) {
763 result = *collection.begin();
772 cass_int64_t timestamp =
static_cast<cass_int64_t
>(time(NULL));
776 cass_int32_t limit = max_leases > 0u ?
777 static_cast<cass_int32_t
>(max_leases) :
778 std::numeric_limits<cass_int32_t>::max();
782 if (state == keep_state) {
788 data.
add(×tamp);
796 for (
Lease4Ptr &lease : temp_collection) {
797 expired_leases.push_back(lease);
869 virtual boost::any
retrieve()
override;
918 std::string address_;
921 cass_int64_t pref_lifetime_;
930 cass_int32_t lease_type_;
933 cass_int32_t prefix_len_;
936 cass_int32_t hwtype_;
939 cass_int32_t hwaddr_source_;
958 "INSERT INTO lease6("
959 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
960 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
961 "hwaddr_source, state, user_context "
963 "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
971 "valid_lifetime = ?, "
973 "pref_lifetime = ?, "
984 "hwaddr_source = ?, "
993 "DELETE FROM lease6 "
1001 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
1002 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
1003 "hwaddr_source, state, user_context "
1008 "ALLOW FILTERING "}},
1014 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
1015 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
1016 "hwaddr_source, state, user_context "
1018 "WHERE address = ? "
1019 "AND lease_type = ? "
1020 "ALLOW FILTERING "}},
1026 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
1027 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
1028 "hwaddr_source, state, user_context "
1031 "ALLOW FILTERING "}},
1034 {GET_LEASE6_DUID_IAID,
1035 {GET_LEASE6_DUID_IAID,
1037 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
1038 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
1039 "hwaddr_source, state, user_context "
1041 "WHERE duid = ? AND iaid = ? "
1042 "AND lease_type = ? "
1043 "ALLOW FILTERING "}},
1046 {GET_LEASE6_DUID_IAID_SUBID,
1047 {GET_LEASE6_DUID_IAID_SUBID,
1049 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
1050 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
1051 "hwaddr_source, state, user_context "
1053 "WHERE duid = ? AND iaid = ? "
1054 "AND lease_type = ? "
1055 "AND subnet_id = ? "
1056 "ALLOW FILTERING "}},
1062 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
1063 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
1064 "hwaddr_source, state, user_context "
1067 "ALLOW FILTERING "}},
1073 "address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
1074 "lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
1075 "hwaddr_source, state, user_context "
1077 "WHERE TOKEN(address) > TOKEN(?) "
1079 "ALLOW FILTERING "}}
1083 :
CqlLeaseExchange(connection), pref_lifetime_(0), iaid_(0), lease_type_(0),
1084 prefix_len_(0), hwtype_(0), hwaddr_source_(0) {
1091 "Lease6 object is NULL");
1100 address_ = lease_->addr_.toText();
1101 if (address_.size() > ADDRESS6_TEXT_MAX_LEN) {
1103 <<
" exceeds maximum allowed length of " << ADDRESS6_TEXT_MAX_LEN);
1118 subnet_id_ =
static_cast<cass_int32_t
>(lease_->subnet_id_);
1121 pref_lifetime_ =
static_cast<cass_int64_t
>(lease_->preferred_lft_);
1124 if (!lease_->duid_) {
1126 <<
" is missing mandatory duid");
1128 duid_ = lease_->duid_->getDuid();
1131 iaid_ =
static_cast<cass_int32_t
>(lease_->iaid_);
1134 lease_type_ =
static_cast<cass_int32_t
>(lease_->type_);
1137 prefix_len_ =
static_cast<cass_int32_t
>(lease_->prefixlen_);
1140 fqdn_fwd_ = lease_->fqdn_fwd_ ? cass_true : cass_false;
1143 fqdn_rev_ = lease_->fqdn_rev_ ? cass_true : cass_false;
1146 if (lease_->hostname_.size() > HOSTNAME_MAX_LEN) {
1148 << lease_->hostname_.size() <<
" exceeds maximum allowed length of "
1149 << HOSTNAME_MAX_LEN);
1154 if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
1157 <<
" of length " << lease_->hwaddr_->hwaddr_.size()
1160 hwaddr_ = lease_->hwaddr_->hwaddr_;
1166 if (lease_->hwaddr_) {
1167 hwtype_ =
static_cast<cass_int32_t
>(lease_->hwaddr_->htype_);
1173 if (lease_->hwaddr_) {
1174 hwaddr_source_ =
static_cast<cass_int32_t
>(lease_->hwaddr_->source_);
1180 state_ =
static_cast<cass_int32_t
>(lease_->state_);
1194 data.
add(&address_);
1198 data.
add(&pref_lifetime_);
1201 data.
add(&lease_type_);
1202 data.
add(&prefix_len_);
1208 data.
add(&hwaddr_source_);
1214 "could not create bind array from Lease6: " << lease_->addr_.toText()
1215 <<
", reason: " << ex.
what());
1224 "Lease6 object is NULL");
1233 address_ = lease_->addr_.toText();
1234 if (address_.size() > ADDRESS6_TEXT_MAX_LEN) {
1236 "address " << address_ <<
" of length " << address_.size()
1237 <<
" exceeds maximum allowed length of "
1238 << ADDRESS6_TEXT_MAX_LEN);
1254 subnet_id_ =
static_cast<cass_int32_t
>(lease_->subnet_id_);
1257 pref_lifetime_ =
static_cast<cass_int64_t
>(lease_->preferred_lft_);
1260 if (!lease_->duid_) {
1262 "lease6 with address " << address_
1263 <<
" is missing mandatory duid");
1265 duid_ = lease_->duid_->getDuid();
1268 iaid_ =
static_cast<cass_int32_t
>(lease_->iaid_);
1271 lease_type_ =
static_cast<cass_int32_t
>(lease_->type_);
1274 prefix_len_ =
static_cast<cass_int32_t
>(lease_->prefixlen_);
1277 fqdn_fwd_ = lease_->fqdn_fwd_ ? cass_true : cass_false;
1280 fqdn_rev_ = lease_->fqdn_rev_ ? cass_true : cass_false;
1283 if (lease_->hostname_.size() > HOSTNAME_MAX_LEN) {
1285 "hostname" << lease_->hostname_ <<
" of length "
1286 << lease_->hostname_.size()
1287 <<
" exceeds maximum allowed length of "
1288 << HOSTNAME_MAX_LEN);
1293 if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
1297 << lease_->hwaddr_->toText() <<
" of length "
1298 << lease_->hwaddr_->hwaddr_.size()
1299 <<
" exceeds maximum allowed length of "
1302 hwaddr_ = lease_->hwaddr_->hwaddr_;
1308 if (lease_->hwaddr_) {
1309 hwtype_ =
static_cast<cass_int32_t
>(lease_->hwaddr_->htype_);
1315 if (lease_->hwaddr_) {
1316 hwaddr_source_ =
static_cast<cass_int32_t
>(lease_->hwaddr_->source_);
1322 state_ =
static_cast<cass_int32_t
>(lease_->state_);
1338 data.
add(&pref_lifetime_);
1342 data.
add(&lease_type_);
1343 data.
add(&prefix_len_);
1349 data.
add(&hwaddr_source_);
1352 data.
add(&address_);
1356 "CqlLease6Exchange::createBindForUpdate(): "
1357 "could not create bind array from Lease6: "
1358 << lease_->addr_.toText() <<
", reason: " << ex.
what());
1370 address_ = address.
toText();
1374 data.
add(&address_);
1378 "CqlLease6Exchange::createBindForDelete(): "
1379 "could not create bind array with address: "
1380 << address_ <<
", reason: " << ex.
what());
1391 data.
add(&address_);
1403 data.
add(&pref_lifetime_);
1412 data.
add(&lease_type_);
1415 data.
add(&prefix_len_);
1433 data.
add(&hwaddr_source_);
1446 if (address_.size() > ADDRESS6_TEXT_MAX_LEN) {
1448 "address " << address_ <<
" of length " << address_.size()
1449 <<
" exceeds maximum allowed length of "
1450 << ADDRESS6_TEXT_MAX_LEN);
1454 "duid " <<
DUID(duid_).toText() <<
" of length "
1456 <<
" exceeds maximum allowed length of "
1462 "invalid lease type "
1463 << lease_type_ <<
" for lease with address "
1464 << address_ <<
". Expected 0, 1 or 2.");
1466 if (
hostname_.size() > HOSTNAME_MAX_LEN) {
1468 "hostname " <<
hostname_ <<
" of length "
1470 <<
" exceeds maximum allowed length of "
1471 << HOSTNAME_MAX_LEN);
1476 <<
" of length " <<
hwaddr_.size()
1477 <<
" exceeds maximum allowed length of "
1488 hwaddr->source_ = hwaddr_source_;
1496 <<
"' is not a JSON map");
1509 result->cltt_ = cltt;
1514 result->setContext(ctx);
1520 "CqlLease6Exchange::retrieve(): "
1521 "could not convert data to Lease6, reason: "
1533 for (boost::any &lease : collection) {
1534 result.push_back(boost::any_cast<Lease6Ptr>(lease));
1547 const size_t collection_size = collection.size();
1548 if (collection_size >= 2u) {
1550 "CqlLease6Exchange::getLease(): multiple records were found in "
1551 "the database where only one was expected for statement "
1553 }
else if (collection_size == 0u) {
1556 result = *collection.begin();
1565 cass_int64_t timestamp =
static_cast<cass_int64_t
>(time(NULL));
1569 cass_int32_t limit = max_leases > 0u ?
1570 static_cast<cass_int32_t
>(max_leases) :
1571 std::numeric_limits<cass_int32_t>::max();
1575 if (state == keep_state) {
1581 data.
add(×tamp);
1589 for (
Lease6Ptr &lease : temp_collection) {
1590 expired_leases.push_back(lease);
1611 const bool fetch_type)
1612 : conn_(conn), statement_(statement), fetch_type_(fetch_type),
1613 cummulative_rows_(), next_row_(cummulative_rows_.begin()),
1614 subnet_id_(0), lease_type_(0), lease_state_(0) {
1627 const bool fetch_type,
const SubnetID& subnet_id)
1629 fetch_type_(fetch_type), cummulative_rows_(),
1630 next_row_(cummulative_rows_.begin()),
1631 subnet_id_(0), lease_type_(0), lease_state_(0) {
1646 const bool fetch_type,
const SubnetID& first_subnet_id,
1649 statement_(statement), fetch_type_(fetch_type), cummulative_rows_(),
1650 next_row_(cummulative_rows_.begin()),
1651 subnet_id_(0), lease_type_(0), lease_state_(0) {
1749 std::map<LeaseStatsRow, int> cummulative_rows_;
1752 std::map<LeaseStatsRow, int>::iterator next_row_;
1779 {SUBNET_LEASE4_STATS,
1780 {SUBNET_LEASE4_STATS,
1784 "WHERE subnet_id = ? "
1788 {SUBNET_RANGE_LEASE4_STATS,
1789 {SUBNET_RANGE_LEASE4_STATS,
1793 "WHERE subnet_id >= ? and subnet_id <= ? "
1801 "subnet_id, lease_type, state "
1806 {SUBNET_LEASE6_STATS,
1807 {SUBNET_LEASE6_STATS,
1809 "subnet_id, lease_type, state "
1811 "WHERE subnet_id = ? "
1815 {SUBNET_RANGE_LEASE6_STATS,
1816 {SUBNET_RANGE_LEASE6_STATS,
1818 "subnet_id, lease_type, state "
1820 "WHERE subnet_id >= ? and subnet_id <= ? "
1831 cass_int32_t first_subnet_id_data;
1832 cass_int32_t last_subnet_id_data;
1835 data.
add(&first_subnet_id_data);
1839 data.
add(&last_subnet_id_data);
1849 next_row_ = cummulative_rows_.begin();
1855 if (next_row_ == cummulative_rows_.end()) {
1860 row.
subnet_id_ = next_row_->first.subnet_id_;
1875 data.
add(&subnet_id_);
1877 data.
add(&lease_type_);
1880 data.
add(&lease_state_);
1887 CassStatement* statement = NULL;
1888 CassFuture* future = NULL;
1892 StatementMap::const_iterator it = connection.
statements_.find(statement_tag);
1895 "CqlLeastStatsQuery::executeSelect(): Statement "
1896 << statement_tag <<
"has not been prepared.");
1901 if (tagged_statement.
is_raw_) {
1903 std::string* query = boost::any_cast<std::string*>(local_data.back());
1904 local_data.pop_back();
1905 statement = cass_statement_new(query->c_str(), local_data.size());
1910 "CqlLeaseStatsQuery::executeSelect(): unable to bind statement "
1911 << tagged_statement.
name_);
1917 rc = cass_statement_set_consistency(statement, connection.
consistency_);
1918 if (rc != CASS_OK) {
1919 cass_statement_free(statement);
1921 "CqlLeaseStatsQuery::executeSelect(): unable to set statement "
1922 "consistency for statement "
1923 << tagged_statement.
name_
1924 <<
", Cassandra error code: " << cass_error_desc(rc));
1931 future = cass_session_execute(connection.
session_, statement);
1933 cass_statement_free(statement);
1935 "CqlLeaseStatsQuery::executeSelect(): no CassFuture for statement "
1936 << tagged_statement.
name_);
1940 cass_future_wait(future);
1942 "CqlLeaseStatsQuery::executeSelect(): cass_session_execute() != CASS_OK",
1943 future, statement_tag);
1944 rc = cass_future_error_code(future);
1945 if (rc != CASS_OK) {
1946 cass_future_free(future);
1947 cass_statement_free(statement);
1952 const CassResult* result_collection = cass_future_get_result(future);
1962 CassIterator* rows = cass_iterator_from_result(result_collection);
1963 while (cass_iterator_next(rows)) {
1964 const CassRow* row = cass_iterator_get_row(rows);
1976 auto cum_row = cummulative_rows_.find(raw_row);
1977 if (cum_row != cummulative_rows_.end()) {
1978 cummulative_rows_[raw_row] = cum_row->second + 1;
1980 cummulative_rows_.insert(std::make_pair(raw_row, 1));
1985 cass_iterator_free(rows);
1986 cass_result_free(result_collection);
1987 cass_future_free(future);
1988 cass_statement_free(statement);
1993 :
LeaseMgr(), dbconn_(parameters) {
2002 std::pair<uint32_t, uint32_t> db_version =
getVersion();
2003 if (code_version != db_version) {
2005 << code_version.first <<
"." << code_version.second
2006 <<
" found version: " << db_version.first <<
"."
2007 << db_version.second);
2023 std::stringstream tmp;
2026 tmp <<
", library cassandra";
2033 .arg(lease->addr_.toText());
2038 exchange4->createBindForInsert(lease, data);
2043 .arg(exception.
what());
2052 .arg(lease->addr_.toText());
2057 exchange6->createBindForInsert(lease, data);
2062 .arg(exception.
what());
2076 cass_int32_t address =
static_cast<cass_int32_t
>(addr.
toUint32());
2097 data.
add(&hwaddr_data);
2110 DHCPSRV_CQL_GET_SUBID_HWADDR)
2118 data.
add(&hwaddr_data);
2120 cass_int32_t subnet_id_data =
static_cast<cass_int32_t
>(subnet_id);
2121 data.
add(&subnet_id_data);
2140 data.
add(&client_id_data);
2176 data.
add(&client_id_data);
2178 cass_int32_t subnet_id_data =
static_cast<cass_int32_t
>(subnet_id);
2179 data.
add(&subnet_id_data);
2197 cass_int32_t subnet_id_data =
static_cast<cass_int32_t
>(subnet_id);
2198 data.
add(&subnet_id_data);
2227 if (!lower_bound_address.
isV4()) {
2229 "retrieving leases from the lease database, got "
2230 << lower_bound_address);
2237 if (page_size.
page_size_ > std::numeric_limits<uint32_t>::max()) {
2239 << std::numeric_limits<uint32_t>::max());
2244 .arg(lower_bound_address.
toText());
2248 cass_int32_t address_data = 0;
2249 if (!lower_bound_address.
isV4Zero()) {
2250 address_data =
static_cast<cass_int32_t
>(lower_bound_address.
toUint32());
2251 data.
add(&address_data);
2254 cass_int32_t page_size_data =
static_cast<cass_int32_t
>(page_size.
page_size_);
2255 data.
add(&page_size_data);
2260 exchange4->getLeaseCollection(lower_bound_address.
isV4Zero() ?
2270 std::string addr_data = addr.
toText();
2278 if (addr_data.size() > ADDRESS6_TEXT_MAX_LEN) {
2280 "CqlLeaseMgr::getLease6(): "
2282 << addr_data <<
" of length " << addr_data.size()
2283 <<
" exceeds maximum allowed length of "
2284 << ADDRESS6_TEXT_MAX_LEN);
2286 data.
add(&addr_data);
2288 cass_int32_t lease_type_data =
static_cast<cass_int32_t
>(lease_type);
2289 data.
add(&lease_type_data);
2306 data.
add(&duid_data);
2328 cass_int32_t iaid_data =
static_cast<cass_int32_t
>(iaid);
2330 data.
add(&duid_data);
2331 data.
add(&iaid_data);
2333 cass_int32_t lease_type_data =
static_cast<cass_int32_t
>(lease_type);
2334 data.
add(&lease_type_data);
2357 cass_int32_t iaid_data =
static_cast<cass_int32_t
>(iaid);
2359 data.
add(&duid_data);
2360 data.
add(&iaid_data);
2362 cass_int32_t lease_type_data =
static_cast<cass_int32_t
>(lease_type);
2363 data.
add(&lease_type_data);
2365 cass_int32_t subnet_id_data =
static_cast<cass_int32_t
>(subnet_id);
2366 data.
add(&subnet_id_data);
2390 if (!lower_bound_address.
isV6()) {
2392 "retrieving leases from the lease database, got "
2393 << lower_bound_address);
2400 if (page_size.
page_size_ > std::numeric_limits<uint32_t>::max()) {
2402 << std::numeric_limits<uint32_t>::max());
2407 .arg(lower_bound_address.
toText());
2411 std::string lb_address_data;
2412 if (!lower_bound_address.
isV6Zero()) {
2413 lb_address_data = lower_bound_address.
toText();
2414 if (lb_address_data.size() > ADDRESS6_TEXT_MAX_LEN) {
2416 "CqlLeaseMgr::getLeases6(lower_bound_address, page_size): "
2418 << lb_address_data <<
" of length " << lb_address_data.size()
2419 <<
" exceeds maximum allowed length of "
2420 << ADDRESS6_TEXT_MAX_LEN);
2422 data.
add(&lb_address_data);
2425 cass_int32_t page_size_data =
static_cast<cass_int32_t
>(page_size.
page_size_);
2426 data.
add(&page_size_data);
2431 exchange6->getLeaseCollection(lower_bound_address.
isV6Zero() ?
2441 const size_t max_leases)
const {
2446 exchange4->getExpiredLeases(max_leases, expired_leases);
2451 const size_t max_leases)
const {
2456 exchange6->getExpiredLeases(max_leases, expired_leases);
2462 .arg(lease->addr_.toText());
2478 .arg(lease->addr_.toText());
2493 std::string addr_data = addr.
toText();
2505 }
else if (addr.
isV6()) {
2514 .arg(exception.
what());
2523 DHCPSRV_CQL_DELETE_EXPIRED_RECLAIMED4)
2526 uint64_t deleted = 0u;
2527 cass_int32_t limit = 1024;
2534 cass_int64_t expiration =
static_cast<cass_int64_t
>(time(NULL) -
static_cast<time_t
>(secs));
2535 data.
add(&expiration);
2554 DHCPSRV_CQL_DELETE_EXPIRED_RECLAIMED6)
2557 uint64_t n_of_deleted_leases = 0u;
2558 cass_int32_t limit = 1024;
2565 cass_int64_t expiration =
static_cast<cass_int64_t
>(time(NULL) -
static_cast<time_t
>(secs));
2566 data.
add(&expiration);
2576 ++n_of_deleted_leases;
2579 return n_of_deleted_leases;
2605 false, first_subnet_id, last_subnet_id));
2633 true, first_subnet_id, last_subnet_id));
2652 std::string name =
"";
2663 return std::string(
"Cassandra Database");
2671 return version_exchange->retrieveVersion(dbconn_);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown 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 isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
std::string toText() const
Convert the address to a string.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
Structure used to bind C++ input values to dynamic CQL parameters.
void add(const boost::any &value)
Add a value at the end of the vector.
static void bindData(const AnyArray &data, CassStatement *statement)
Assigns values to every column of an INSERT or an UPDATE statement.
static void getData(const CassRow *row, AnyArray &data)
Retrieves data returned by Cassandra.
Common CQL connector pool.
StatementMap statements_
Pointer to external array of tagged statements containing statement name, array of names of bind para...
virtual void commit()
Commit Transactions.
virtual void rollback()
Rollback Transactions.
CassSession * session_
CQL session handle.
bool force_consistency_
CQL consistency enabled.
void openDatabase()
Open database.
CassConsistency consistency_
CQL consistency.
static const std::string checkFutureError(const std::string &what, CassFuture *future, StatementTag statement_tag=NULL)
Check for errors.
void prepareStatements(StatementMap &statements)
Prepare statements.
AnyArray executeSelect(const CqlConnection &connection, const AnyArray &where_values, StatementTag statement_tag, const bool &single=false)
Executes SELECT statements.
static void convertFromDatabaseTime(const cass_int64_t &expire, const cass_int64_t &valid_lifetime, time_t &cltt)
Converts time from Cassandra format.
static void convertToDatabaseTime(const time_t &cltt, const uint32_t &valid_lifetime, cass_int64_t &expire)
Exchange used to retrieve schema version from the keyspace.
static StatementMap tagged_statements_
Cassandra statements.
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown on failure to open database.
Exception thrown on failure to execute a database function.
Invalid address family used as input to Lease Manager.
Multiple lease records found where one expected.
Database statement not applied.
Holds Client identifier or client IPv4 address.
static const size_t MAX_CLIENT_ID_LEN
Maximum size of a client ID.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
Exchange Lease4 information between Kea and CQL.
static constexpr StatementTag GET_LEASE4_HWADDR_SUBID
static constexpr StatementTag GET_LEASE4_EXPIRE
void createBindForUpdate(const Lease4Ptr &lease, AnyArray &data, StatementTag statement_tag=NULL)
Create CQL_BIND objects for Lease4 Pointer.
static StatementMap tagged_statements_
Cassandra statements.
static constexpr StatementTag GET_LEASE4_PAGE
void createBindForDelete(const IOAddress &address, AnyArray &data, StatementTag statement_tag=NULL)
Create CQL_BIND objects for Lease4 Pointer.
void getLeaseCollection(StatementTag &statement_tag, AnyArray &data, Lease4Collection &result)
Retrieves zero or more IPv4 leases.
static constexpr StatementTag GET_LEASE4_LIMIT
void createBindForInsert(const Lease4Ptr &lease, AnyArray &data)
Create CQL_BIND objects for Lease4 Pointer.
void getLease(StatementTag &statement_tag, AnyArray &data, Lease4Ptr &result)
Retrieves one IPv4 lease.
virtual void createBindForSelect(AnyArray &data, StatementTag statement_tag=NULL) override
Create BIND array to receive data.
static constexpr StatementTag INSERT_LEASE4
Statement tags definitions.
CqlLease4Exchange(const CqlConnection &connection)
Constructor.
static constexpr StatementTag GET_LEASE4_CLIENTID_SUBID
static constexpr StatementTag UPDATE_LEASE4
virtual boost::any retrieve() override
Retrieves the Lease4 object in Kea format.
static constexpr StatementTag DELETE_LEASE4
static constexpr StatementTag GET_LEASE4
static constexpr StatementTag GET_LEASE4_ADDR
static constexpr StatementTag GET_LEASE4_SUBID
void getExpiredLeases(const size_t &max_leases, Lease4Collection &expired_leases)
Returns expired leases.
static constexpr StatementTag GET_LEASE4_CLIENTID
static constexpr StatementTag GET_LEASE4_HWADDR
Exchange Lease6 information between Kea and CQL.
static constexpr StatementTag DELETE_LEASE6
virtual boost::any retrieve() override
Retrieves the Lease6 object in Kea format.
static StatementMap tagged_statements_
Cassandra statements.
static constexpr StatementTag GET_LEASE6_DUID
static constexpr StatementTag UPDATE_LEASE6
void createBindForInsert(const Lease6Ptr &lease, AnyArray &data)
Create CQL_BIND objects for Lease6 Pointer.
void getLease(StatementTag &statement_tag, AnyArray &data, Lease6Ptr &result)
Retrieves one IPv6 lease.
void createBindForDelete(const IOAddress &address, AnyArray &data, StatementTag statement_tag=NULL)
Create CQL_BIND objects for Lease4 Pointer.
static constexpr StatementTag GET_LEASE6_PAGE
virtual void createBindForSelect(AnyArray &data, StatementTag statement_tag=NULL) override
Create BIND array to receive data.
void getExpiredLeases(const size_t &max_leases, Lease6Collection &expired_leases)
Returns expired leases.
static constexpr StatementTag INSERT_LEASE6
Statement tags definitions.
static constexpr StatementTag GET_LEASE6_EXPIRE
static constexpr StatementTag GET_LEASE6_DUID_IAID
static constexpr StatementTag GET_LEASE6_ADDR
void createBindForUpdate(const Lease6Ptr &lease, AnyArray &data, StatementTag statement_tag=NULL)
Create CQL_BIND objects for Lease6 Pointer.
void getLeaseCollection(StatementTag &statement_tag, AnyArray &data, Lease6Collection &result)
Retrieves zero or more IPv6 leases.
static constexpr StatementTag GET_LEASE6_LIMIT
CqlLease6Exchange(const CqlConnection &connection)
Constructor.
static constexpr StatementTag GET_LEASE6_DUID_IAID_SUBID
Common CQL and Lease Data Methods.
virtual void createBindForSelect(AnyArray &data, StatementTag statement_tag=NULL) override=0
Create BIND array to receive C++ data.
cass_bool_t fqdn_fwd_
Has forward DNS update been performed?
std::string user_context_
User context.
std::string hostname_
Client hostname.
cass_int64_t valid_lifetime_
Lease timer.
cass_int32_t subnet_id_
Subnet identifier.
cass_int32_t state_
Lease state.
cass_bool_t fqdn_rev_
Has reverse DNS update been performed?
cass_int64_t expire_
Lease expiry time.
virtual boost::any retrieve() override=0
Copy received data into the derived class' object.
const CqlConnection & connection_
Database connection.
CqlLeaseExchange(const CqlConnection &connection)
Constructor.
CassBlob hwaddr_
Hardware address.
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 leases.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
virtual void updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
virtual std::string getDescription() const override
Returns description of the backend.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Basic lease access methods.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
static std::string getDBVersion()
Local version of getDBVersion() class method.
virtual std::string getName() const override
Returns name of the database.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
virtual VersionPair getVersion() const override
Returns backend version.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired and reclaimed DHCPv4 leases.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual void rollback() override
Rollback Transactions.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired and reclaimed DHCPv6 leases.
virtual bool deleteLease(const isc::asiolink::IOAddress &addr) override
Deletes a lease.
CqlLeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
Constructor.
virtual ~CqlLeaseMgr()
Destructor (closes database)
virtual void commit() override
Commit Transactions.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
Base CQL derivation of the statistical lease data query.
static constexpr StatementTag ALL_LEASE6_STATS
bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
void executeSelect(const CqlConnection &connection, const AnyArray &data, StatementTag statement_tag)
Executes protocol specific lease query SELECT statement.
static StatementMap tagged_statements_
Cassandra statements.
static constexpr StatementTag SUBNET_LEASE4_STATS
Return lease4 lease statistics for a single subnet.
static constexpr StatementTag ALL_LEASE4_STATS
Statement tags definitions.
static constexpr StatementTag SUBNET_LEASE6_STATS
Return lease6 lease statistics for a single subnet.
static constexpr StatementTag SUBNET_RANGE_LEASE6_STATS
Return lease6 lease statistics for a range of subnets.
void start()
Creates the lease statistical data result set.
virtual ~CqlLeaseStatsQuery()
Destructor.
virtual void createBindForSelect(AnyArray &data, StatementTag statement_tag=NULL)
Create BIND array to receive C++ data.
CqlLeaseStatsQuery(CqlConnection &conn, StatementTag &statement, const bool fetch_type, const SubnetID &subnet_id)
Constructor to query for a single subnet's stats.
static constexpr StatementTag SUBNET_RANGE_LEASE4_STATS
Return lease4 lease statistics for a range of subnets.
CqlLeaseStatsQuery(CqlConnection &conn, StatementTag &statement, const bool fetch_type, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor to query for the stats for a range of subnets.
CqlLeaseStatsQuery(CqlConnection &conn, StatementTag &statement, const bool fetch_type)
Constructor to query for all subnets' stats.
Holds DUID (DHCPv6 Unique Identifier)
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
static const size_t MAX_DUID_LEN
maximum duid size As defined in RFC 8415, section 11.1
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
Wraps value holding size of the page with leases.
const size_t page_size_
Holds page size.
Base class for fulfilling a statistical lease data query.
SubnetID first_subnet_id_
First (or only) subnet_id in the selection criteria.
SelectMode getSelectMode() const
Returns the selection criteria mode The value returned is based upon the constructor variant used and...
SubnetID last_subnet_id_
Last subnet_id in the selection criteria when a range is given.
Attempt to update lease that was not there.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< const Element > ConstElementPtr
char const *const StatementTag
Statement index representing the statement name.
std::vector< cass_byte_t > CassBlob
Host identifier converted to Cassandra data type.
constexpr uint32_t CQL_SCHEMA_VERSION_MINOR
constexpr uint32_t CQL_SCHEMA_VERSION_MAJOR
Define CQL schema version: 3.0.
std::unordered_map< StatementTag, CqlTaggedStatement, StatementTagHash, StatementTagEqual > StatementMap
A container for all statements.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
std::pair< uint32_t, uint32_t > VersionPair
Pair containing major and minor versions.
boost::shared_ptr< DUID > DuidPtr
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::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
@ HTYPE_ETHER
Ethernet 10Mbps.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Defines a single statement or query.
StatementTag name_
Short description of the query.
bool is_raw_
Should the statement be executed raw or with binds?
const CassPrepared * prepared_statement_
Internal Cassandra object representing the prepared statement.
Hardware type that represents information from DHCPv4 packet.
static const size_t MAX_HWADDR_LEN
Maximum size of a hardware address.
std::vector< uint8_t > hwaddr_
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
Structure that holds a lease for IPv4 address.
Structure that holds a lease for IPv6 address and/or prefix.
Contains a single row of lease statistical data.
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.
static const uint32_t STATE_DEFAULT
A lease in the default state.
static const uint32_t STATE_DECLINED
Declined lease.
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Type
Type of lease or pool.
@ TYPE_TA
the lease contains temporary IPv6 address
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address