Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipv4 addr plus port #63

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
233950b
added address plus port
Feb 1, 2018
43f201b
fixed merge
Feb 1, 2018
a238b7c
add static casts
Feb 1, 2018
67483dc
minor changes
Feb 1, 2018
0868823
minor changes
Feb 1, 2018
6012b29
fixed unit tests
Feb 2, 2018
62ce579
updated unit tests
Feb 2, 2018
26e8bf4
removed unsupported options
Feb 3, 2018
a875ea1
updated cql schema and added minor changes (including spelling mistak…
Feb 7, 2018
f804d7e
minor chnages
Feb 9, 2018
7ecf8fb
Merge remote-tracking branch 'isc-kea/master' into cql_clean_code
Feb 15, 2018
01d56b8
Merge remote-tracking branch 'isc-kea/master' into cql_clean_code
Feb 15, 2018
098865d
Merge remote-tracking branch 'isc-kea/master' into HEAD
Feb 15, 2018
10e19f3
Merge branch 'cql_clean_code' of https://github.com/razvan-becheriu/k…
Feb 15, 2018
e2317a1
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
Feb 19, 2018
448cf73
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
Feb 28, 2018
ae60f3f
Merge remote-tracking branch 'isc-kea/master' into cql_clean_code
Feb 28, 2018
14c3a55
minor changes - fixed eventual memory leak
Mar 1, 2018
45464c5
minor changes
Mar 1, 2018
16c80de
minor changes
Mar 1, 2018
5637d01
minor changes
Mar 1, 2018
4637a23
refactored cql recount leases plus minor changes
Mar 1, 2018
d3f8281
minor changes
Mar 1, 2018
b2d80eb
minor changes
Mar 1, 2018
ffc8c78
Merge remote-tracking branch 'isc-kea/master' into cassandra_improvem…
Mar 2, 2018
afddd8a
Merge remote-tracking branch 'isc-kea/master' into cql_clean_code
Mar 7, 2018
d32a318
Merge remote-tracking branch 'isc-kea/master' into cassandra_improvem…
Mar 7, 2018
c3e4fe2
enabled tests for cql
Mar 7, 2018
e728823
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
Mar 7, 2018
8b1f21a
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
Mar 7, 2018
55a57d4
enabled tests for cql
Mar 7, 2018
38b5430
fixed unit tests
Mar 7, 2018
400abf1
fixed merge
Mar 13, 2018
33e4b4f
Merge remote-tracking branch 'isc-kea/master' into cassandra_improvem…
Mar 13, 2018
42d8ad3
minor changes
Mar 13, 2018
1b6df23
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
Mar 13, 2018
39bc0b7
fixed merge
Mar 13, 2018
61f9562
Merge branch 'cql_clean_code' into ipv4_addr_plus_port
Mar 13, 2018
b65cd1f
fixed merge
Mar 13, 2018
a1ab751
fixed comments
Mar 13, 2018
387ffa4
minor changes
Mar 13, 2018
746acc8
minor changes
Mar 13, 2018
78f3ad6
Merge branch 'cassandra_improvements' into cql_clean_code
Mar 13, 2018
38a837f
minor changes
Mar 14, 2018
9ed1f3d
minor changes
Mar 14, 2018
d61a05b
minor changes
Mar 14, 2018
cc59e9a
minor changes
Mar 14, 2018
365e64f
minor changes
Mar 14, 2018
85e88a2
Merge remote-tracking branch 'isc-kea/master' into cql_clean_code
Mar 15, 2018
594bd9e
Merge branch 'cql_clean_code' into ipv4_addr_plus_port
Mar 15, 2018
053d2f3
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
Mar 19, 2018
aac7d46
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
May 24, 2018
8670f46
minor changes
May 24, 2018
552f467
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
Jun 5, 2018
3d23cef
minor changes
Jun 14, 2018
0872bf5
Merge remote-tracking branch 'isc-kea/master' into ipv4_addr_plus_port
Jun 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/bin/dhcp6/dhcp6_parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ using namespace std;
REQUEST_TIMEOUT "request-timeout"
TCP_KEEPALIVE "tcp-keepalive"
CONTACT_POINTS "contact-points"
MAX_RECONNECT_TRIES "max-reconnect-tries"
KEYSPACE "keyspace"
MAX_RECONNECT_TRIES "max-reconnect-tries"

PREFERRED_LIFETIME "preferred-lifetime"
VALID_LIFETIME "valid-lifetime"
Expand Down Expand Up @@ -664,11 +664,6 @@ contact_points: CONTACT_POINTS {
ctx.leave();
};

max_reconnect_tries: MAX_RECONNECT_TRIES COLON INTEGER {
ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("max-reconnect-tries", n);
};

keyspace: KEYSPACE {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
Expand All @@ -677,6 +672,10 @@ keyspace: KEYSPACE {
ctx.leave();
};

max_reconnect_tries: MAX_RECONNECT_TRIES COLON INTEGER {
ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("max-reconnect-tries", n);
};

mac_sources: MAC_SOURCES {
ElementPtr l(new ListElement(ctx.loc2pos(@1)));
Expand Down
6 changes: 3 additions & 3 deletions src/lib/dhcpsrv/cql_host_data_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1162,12 +1162,12 @@ CqlHostExchange::retrieve() {
asiolink::IOAddress ipv4_reservation =
asiolink::IOAddress(static_cast<uint32_t>(host_ipv4_address_));

Host* host = new Host(host_identifier.data(), host_identifier.size(),
HostPtr host(new Host(host_identifier.data(), host_identifier.size(),
host_identifier_type, ipv4_subnet_id, ipv6_subnet_id,
ipv4_reservation, hostname_,
host_ipv4_client_classes_, host_ipv6_client_classes_,
static_cast<uint32_t>(host_ipv4_next_server_),
host_ipv4_server_hostname_, host_ipv4_boot_file_name_);
host_ipv4_server_hostname_, host_ipv4_boot_file_name_));

// Set the user context if there is one.
if (!user_context_.empty()) {
Expand Down Expand Up @@ -2044,7 +2044,7 @@ CqlHostDataSourceImpl::getHostCollection(StatementTag statement_tag,
// Form HostPtr objects.
HostCollection host_collection;
for (boost::any& host : collection) {
host_collection.push_back(HostPtr(boost::any_cast<Host*>(host)));
host_collection.push_back(boost::any_cast<HostPtr>(host));
}

// Merge the denormalized table entries that belong to the same host
Expand Down
203 changes: 54 additions & 149 deletions src/lib/dhcpsrv/cql_lease_mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1456,19 +1456,19 @@ CqlLease6Exchange::getExpiredLeases(const size_t &max_leases,
/// This class provides the functionality such as results storage and row
/// fetching common to fulfilling the statistical lease data query.
///
class CqlLeaseStatsQuery : public LeaseStatsQuery {
class CqlLeaseStatsQuery : public LeaseStatsQuery, public CqlExchange {
public:
/// @brief Constructor
///
/// @param conn An open connection to the database housing the lease data
/// @param statement The lease data SQL prepared statement tag to execute
/// @param fetch_type Indicates whether or not lease_type should be
/// fetched from the result set (should be true for v6)
CqlLeaseStatsQuery(CqlConnection& conn, StatementTag& statement,
const bool fetch_type)
: conn_(conn), statement_(statement), fetch_type_(fetch_type),
CqlLeaseStatsQuery(CqlConnection& connection, StatementTag& statement,
const bool fetch_type)
: connection_(connection), statement_(statement), fetch_type_(fetch_type),
cummulative_rows_(), next_row_(cummulative_rows_.begin()),
subnet_id_(0), lease_type_(0), lease_state_(0) {
subnet_id_(0), lease_type_(0), state_(0) {
}

/// @brief Destructor
Expand All @@ -1482,35 +1482,6 @@ class CqlLeaseStatsQuery : public LeaseStatsQuery {
/// first row of the aggregate results.
void start();

/// @brief Executes protocol specific lease query SELECT statement
///
/// Currently we do not have a good way for Cassandra to roll up the
/// lease counts per subnet, type, and state as we do the other back
/// ends. This method executes the select statement which returns
/// a result set containing a row of data for every lease:
/// -v4 - subnet-id, lease-state
/// -v6 - subnet-id, lease-type, lease-state
///
/// It then iterates over this result set, aggregating the data into a
/// a map of LeaseStatRows.
///
/// If we didn't have to roll up the raw lease data first, we could
/// have derived this class from CqlExchange and used it's executeSelect
/// (from which this method borrows heavily). However, that would mean
/// copying all the raw lease data into a collection returned by
/// executeSelect and then aggregating that into cummulative rows.
/// The way we are now we go turn the raw lease data directly into the
/// cummulative row map.
///
/// @param connection connection used to communicate with the Cassandra
/// database
/// @param where_values array of bound objects used to filter the results
/// @param statement_tag prepared statement being executed
///
/// @throw DbOperationError
void executeSelect(const CqlConnection& connection, const AnyArray& data,
StatementTag statement_tag);

/// @brief Fetches the next row in the result set
///
/// Once the internal result set has been populated by invoking the
Expand All @@ -1534,6 +1505,15 @@ class CqlLeaseStatsQuery : public LeaseStatsQuery {
virtual void
createBindForSelect(AnyArray& data, StatementTag statement_tag = NULL);

/// @brief Copy received data into the derived class' object.
///
/// Copies information about the entity to be retrieved into a holistic
/// object. Called in @ref executeSelect(). Not implemented for base class
/// CqlExchange. To be implemented in derived classes.
///
/// @return a pointer to the object retrieved.
virtual boost::any retrieve();

/// @brief Statement tags definitions
/// @{
// Return recalculated lease4 lease statistics
Expand All @@ -1546,28 +1526,29 @@ class CqlLeaseStatsQuery : public LeaseStatsQuery {
static StatementMap tagged_statements_;

private:
/// @brief Database connection to use to execute the query
CqlConnection& conn_;
/// @brief Database connection
const CqlConnection &connection_;

/// @brief The query's prepared statement tag
StatementTag statement_;

/// @brief Indicates if query supplies lease type
bool fetch_type_;


/// @brief map containing the aggregated lease counts
std::map<LeaseStatsRow, int> cummulative_rows_;

/// @brief cursor pointing to the next row to read in aggregate map
std::map<LeaseStatsRow, int>::iterator next_row_;

/// @brief bind variable for retrieving subnet-id from a result set row
int subnet_id_;
/// @brief bind variable for retrieving lease-type from a result set row
int lease_type_;
/// @brief bind variable for retrieving lease-state from a result set row
int lease_state_;
/// @brief Subnet identifier
cass_int32_t subnet_id_;

/// @brief Lease type (NA, TA or PD)
cass_int32_t lease_type_;

/// @brief Lease state
cass_int32_t state_;
};

constexpr StatementTag CqlLeaseStatsQuery::RECOUNT_LEASE4_STATS;
Expand Down Expand Up @@ -1597,7 +1578,20 @@ CqlLeaseStatsQuery::start() {

// This gets a collection of data for ALL leases, and
// then rolls them up into cummulative_rows_
executeSelect(conn_, data, statement_);
AnyArray collection = executeSelect(connection_, data, statement_);

// Form LeaseStatsRowPtr objects.
LeaseStatsCollection stats_collection;
for (boost::any& stats : collection) {
LeaseStatsRowPtr data(boost::any_cast<LeaseStatsRowPtr>(stats));
stats_collection.push_back(data);
auto cum_row = cummulative_rows_.find(*data);
if (cum_row != cummulative_rows_.end()) {
cummulative_rows_[*data] = cum_row->second + 1;
} else {
cummulative_rows_.insert(std::make_pair(*data, 1));
}
}

// Set our row iterator to the beginning
next_row_ = cummulative_rows_.begin();
Expand All @@ -1624,118 +1618,29 @@ CqlLeaseStatsQuery::getNextRow(LeaseStatsRow& row) {
}

void
CqlLeaseStatsQuery::createBindForSelect(AnyArray& data, StatementTag) {
data.clear();
data.add(&subnet_id_);
if (fetch_type_) {
data.add(&lease_type_);
}
CqlLeaseStatsQuery::createBindForSelect(AnyArray& data, StatementTag statement_tag) {

data.add(&lease_state_);
}
// Start with a fresh array.
data.clear();

void
CqlLeaseStatsQuery::executeSelect(const CqlConnection& connection, const AnyArray& data,
StatementTag statement_tag) {
CassError rc;
CassStatement* statement = NULL;
CassFuture* future = NULL;
AnyArray local_data = data;

// Find the query statement first.
StatementMap::const_iterator it = connection.statements_.find(statement_tag);
if (it == connection.statements_.end()) {
isc_throw(DbOperationError,
"CqlLeastStatsQuery::executeSelect(): Statement "
<< statement_tag << "has not been prepared.");
}
// subnet_id: int
data.add(&subnet_id_);

// Bind the data before the query is executed.
CqlTaggedStatement tagged_statement = it->second;
if (tagged_statement.is_raw_) {
// The entire query is the first element in data.
std::string* query = boost::any_cast<std::string*>(local_data.back());
local_data.pop_back();
statement = cass_statement_new(query->c_str(), local_data.size());
// lease_type: int
if (statement_tag == CqlLeaseStatsQuery::RECOUNT_LEASE6_STATS) {
data.add(&lease_type_);
} else {
statement = cass_prepared_bind(tagged_statement.prepared_statement_);
if (!statement) {
isc_throw(DbOperationError,
"CqlLeaseStatsQuery::executeSelect(): unable to bind statement "
<< tagged_statement.name_);
}
}

// Set specific level of consistency if we're told to do so.
if (connection.force_consistency_) {
rc = cass_statement_set_consistency(statement, connection.consistency_);
if (rc != CASS_OK) {
cass_statement_free(statement);
isc_throw(DbOperationError,
"CqlLeaseStatsQuery::executeSelect(): unable to set statement "
"consistency for statement "
<< tagged_statement.name_
<< ", Cassandra error code: " << cass_error_desc(rc));
}
}

CqlCommon::bindData(local_data, statement);

// Everything's ready. Call the actual statement.
future = cass_session_execute(connection.session_, statement);
if (!future) {
cass_statement_free(statement);
isc_throw(DbOperationError,
"CqlLeaseStatsQuery::executeSelect(): no CassFuture for statement "
<< tagged_statement.name_);
lease_type_ = Lease::TYPE_NA; // lease type is always NA for v4
}

// Wait for the statement execution to complete.
cass_future_wait(future);
const std::string error = connection.checkFutureError(
"CqlLeaseStatsQuery::executeSelect(): cass_session_execute() != CASS_OK",
future, statement_tag);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
cass_future_free(future);
cass_statement_free(statement);
isc_throw(DbOperationError, error);
}

// Get column values.
const CassResult* result_collection = cass_future_get_result(future);

// lease type is always NA for v4
if (!fetch_type_) {
lease_type_ = Lease::TYPE_NA;
}

// Since we're currently forced to pull data for all leases, we
// iterate over them, aggregating them into cummulative LeaseStatsRows
AnyArray return_values;
CassIterator* rows = cass_iterator_from_result(result_collection);
while (cass_iterator_next(rows)) {
const CassRow* row = cass_iterator_get_row(rows);
createBindForSelect(return_values, statement_tag);
CqlCommon::getData(row, return_values);

LeaseStatsRow raw_row(subnet_id_, static_cast<Lease::Type>(lease_type_),
lease_state_, 1);

auto cum_row = cummulative_rows_.find(raw_row);
if (cum_row != cummulative_rows_.end()) {
cummulative_rows_[raw_row] = cum_row->second + 1;
} else {
cummulative_rows_.insert(std::make_pair(raw_row, 1));
}
}
// state: int
data.add(&state_);
}

// Free resources.
cass_iterator_free(rows);
cass_result_free(result_collection);
cass_future_free(future);
cass_statement_free(statement);
return;
boost::any
CqlLeaseStatsQuery::retrieve() {
return (LeaseStatsRowPtr(new LeaseStatsRow(subnet_id_,
static_cast<Lease::Type>(lease_type_), state_, 1)));
}

CqlLeaseMgr::CqlLeaseMgr(const DatabaseConnection::ParameterMap &parameters)
Expand Down
5 changes: 4 additions & 1 deletion src/lib/dhcpsrv/lease_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct LeaseStatsRow {

if (subnet_id_ == rhs.subnet_id_ &&
lease_type_ == rhs.lease_type_ &&
lease_state_ < rhs.lease_state_) {
lease_state_ < rhs.lease_state_) {
return (true);
}

Expand Down Expand Up @@ -166,6 +166,9 @@ typedef boost::shared_ptr<LeaseStatsQuery> LeaseStatsQueryPtr;
/// @brief Defines a pointer to a LeaseStatsRow.
typedef boost::shared_ptr<LeaseStatsRow> LeaseStatsRowPtr;

/// @brief Collection of the @c LeaseStatsRow objects.
typedef std::vector<LeaseStatsRowPtr> LeaseStatsCollection;

/// @brief Abstract Lease Manager
///
/// This is an abstract API for lease database backends. It provides unified
Expand Down
12 changes: 12 additions & 0 deletions src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ TEST_F(CqlHostDataSourceTest, basic4HWAddr) {
testBasic4(Host::IDENT_HWADDR);
}

// Verifies that IPv4 host reservation with options can have a max value
// for dhcp4_subnet id
TEST_F(CqlHostDataSourceTest, maxSubnetId4) {
testMaxSubnetId4();
}

// Verifies that IPv6 host reservation with options can have a max value
// for dhcp6_subnet id
TEST_F(CqlHostDataSourceTest, maxSubnetId6) {
testMaxSubnetId6();
}

// Test verifies if a host reservation can be added and later retrieved by IPv4
// address. Host uses client-id (DUID) as identifier.
TEST_F(CqlHostDataSourceTest, basic4ClientId) {
Expand Down
Loading