37 static constexpr
size_t HOSTNAME_MAX_LEN = 255u;
38 static constexpr
size_t ADDRESS6_TEXT_MAX_LEN = 39u;
39 static constexpr
char NULL_USER_CONTEXT[] =
"";
53 : connection_(connection), valid_lifetime_(0), expire_(0),
54 subnet_id_(0), fqdn_fwd_(cass_false), fqdn_rev_(cass_false),
55 state_(0), user_context_(NULL_USER_CONTEXT) {
160 void createBindForDelete(
const IOAddress &address,
176 virtual boost::any retrieve()
override;
201 void getExpiredLeases(
const size_t &max_leases,
Lease4Collection &expired_leases);
221 static constexpr
StatementTag GET_LEASE4_CLIENTID =
"GET_LEASE4_CLIENTID";
223 static constexpr
StatementTag GET_LEASE4_CLIENTID_SUBID =
"GET_LEASE4_CLIENTID_SUBID";
227 static constexpr
StatementTag GET_LEASE4_HWADDR_SUBID =
"GET_LEASE4_HWADDR_SUBID";
240 cass_int32_t address_;
245 constexpr
StatementTag CqlLease4Exchange::INSERT_LEASE4;
246 constexpr
StatementTag CqlLease4Exchange::UPDATE_LEASE4;
247 constexpr
StatementTag CqlLease4Exchange::DELETE_LEASE4;
248 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_EXPIRE;
250 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_ADDR;
251 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_CLIENTID;
252 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_CLIENTID_SUBID;
253 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_HWADDR;
254 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_HWADDR_SUBID;
255 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_LIMIT;
256 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_PAGE;
257 constexpr
StatementTag CqlLease4Exchange::GET_LEASE4_SUBID;
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();
451 CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
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();
554 CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
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_);
708 if (!ctx || (ctx->getType() != Element::map)) {
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);
1115 CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
expire_);
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);
1250 CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
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_;
1494 if (!ctx ||(ctx->getType() != Element::map)) {
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));
1928 CqlCommon::bindData(local_data, statement);
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);
1966 CqlCommon::getData(row, return_values);
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");