Commit 4ffeedbb authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[5533a] Extra comments added

parent cbc6a8f6
......@@ -548,7 +548,7 @@ public:
/// @brief Sets the negative cached flag.
///
/// @param negative New valie for negative cache flag.
/// @param negative sets whether this is a negative cached host.
void setNegative(bool negative) {
negative_ = negative;
}
......@@ -618,6 +618,10 @@ private:
CfgOptionPtr cfg_option6_;
/// @brief Negative cached flag.
///
/// This flag determines whether this object is a negative cache, i.e.
/// we queried other backends for specific host and there was no
/// entry for it.
bool negative_;
};
......
......@@ -59,8 +59,8 @@ HostDataSourceFactory::add(HostDataSourceList& sources,
// No match?
if (index == map_.end()) {
isc_throw(InvalidType, "Hosts database access parameter 'type': " <<
db_type << " is invalid");
isc_throw(InvalidType, "The type of host backend: '" <<
db_type << "' is not currently supported");
}
// Call the factory and push the pointer on sources.
......@@ -75,8 +75,7 @@ HostDataSourceFactory::add(HostDataSourceList& sources,
}
bool
HostDataSourceFactory::del(HostDataSourceList& sources,
const string& db_type) {
HostDataSourceFactory::del(HostDataSourceList& sources, const string& db_type) {
for (auto it = sources.begin(); it != sources.end(); ++it) {
if ((*it)->getType() != db_type) {
continue;
......
......@@ -51,7 +51,7 @@ public:
/// a keyword/value pair of the form "type=dbtype" giving the database
/// type, e.q. "mysql" or "sqlite3".
///
/// @param sources host data source list.
/// @param sources host data source list (new backend will be added here)
/// @param dbaccess Database access parameters. These are in the form of
/// "keyword=value" pairs, separated by spaces. They are backend-
/// -end specific, although must include the "type" keyword which
......
......@@ -171,6 +171,9 @@ HostMgr::get4Any(const SubnetID& subnet_id,
const size_t identifier_len) const {
ConstHostPtr host = getCfgHosts()->get4(subnet_id, identifier_type,
identifier_begin, identifier_len);
// Found it the config file or there are no backends configured?
// Then we're done here.
if (host || alternate_sources_.empty()) {
return (host);
}
......@@ -181,6 +184,8 @@ HostMgr::get4Any(const SubnetID& subnet_id,
.arg(Host::getIdentifierAsText(identifier_type, identifier_begin,
identifier_len));
// Try to find a host in each configured backend. We return as soon
// as we find first hit.
for (auto it = alternate_sources_.begin();
it != alternate_sources_.end(); ++it) {
host = (*it)->get4(subnet_id, identifier_type,
......
......@@ -393,8 +393,9 @@ public:
protected:
/// @brief The negative caching flag.
///
/// When true and the first data source is a cache negative answers
/// to get[46] for aubnet and identifier are cached.
/// When true and the first cache source will be also
/// caching negative answers. This works for get[46]
/// for a subnet and an identifier.
bool negative_caching_;
/// @brief Cache an answer.
......
......@@ -106,7 +106,8 @@ host reservations in the MySQL database is required to establish
connection to the MySQL database and issue specific queries. A factory
method creating an instance of a base host data source object must be
registered (at global object initialization for built-in backends,
dynamically for backends loaded at run-time). Note, that this instance is
dynamically for backends loaded at run-time). See host_data_source_factory.cc
for example code that registers MySQL and PostgreSQL. Note, that this instance is
created as "alternate host data source" as opposed to the primary data
source which returns host reservations specified in the configuration file.
The primary data source is implemented internally in the
......
......@@ -103,7 +103,7 @@ public:
/// Closes the database and re-open it. Anything committed should be
/// visible.
///
/// Parameter is ignored for CQL backend as the v4 and v6 leases share
/// Parameter is ignored for CQL backend as the v4 and v6 hosts share
/// the same database.
void reopen(Universe) {
HostMgr::create();
......@@ -116,7 +116,7 @@ public:
///
/// This test checks if the CqlHostDataSource can be instantiated. This happens
/// only if the database can be opened. Note that this is not part of the
/// CqlLeaseMgr test fixure set. This test checks that the database can be
/// CqlHostMgr test fixure set. This test checks that the database can be
/// opened: the fixtures assume that and check basic operations.
TEST(CqlHostDataSource, OpenDatabase) {
......@@ -124,7 +124,7 @@ TEST(CqlHostDataSource, OpenDatabase) {
destroyCqlSchema(false, true);
createCqlSchema(false, true);
// Check that lease manager open the database opens correctly and tidy up.
// Check that host manager open the database opens correctly and tidy up.
// If it fails, print the error message.
try {
HostMgr::create();
......@@ -137,7 +137,7 @@ TEST(CqlHostDataSource, OpenDatabase) {
<< "*** before the CQL tests will run correctly.\n";
}
// Check that lease manager open the database opens correctly with a longer
// Check that host manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
std::string connection_string = validCqlConnectionString() + std::string(" ") +
......
......@@ -161,7 +161,7 @@ TEST_F(HostCacheTest, identifier4) {
// Create a host reservation.
HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1",
Host::IDENT_HWADDR);
ASSERT_TRUE(host); // Make sure the host is generate properly.
ASSERT_TRUE(host); // Make sure the host is generated properly.
const IOAddress& address = host->getIPv4Reservation();
// Try to add it to the host data source.
......@@ -215,7 +215,7 @@ TEST_F(HostCacheTest, identifier6) {
HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1",
Host::IDENT_DUID,
false);
ASSERT_TRUE(host); // Make sure the host is generate properly.
ASSERT_TRUE(host); // Make sure the host is generated properly.
// Get the address.
IPv6ResrvRange resrvs = host->getIPv6Reservations();
......@@ -273,7 +273,7 @@ TEST_F(HostCacheTest, address4) {
// Create a host reservation.
HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1",
Host::IDENT_HWADDR);
ASSERT_TRUE(host); // Make sure the host is generate properly.
ASSERT_TRUE(host); // Make sure the host is generated properly.
const IOAddress& address = host->getIPv4Reservation();
// Try to add it to the host data source.
......@@ -325,7 +325,7 @@ TEST_F(HostCacheTest, address6) {
HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1",
Host::IDENT_DUID,
false);
ASSERT_TRUE(host); // Make sure the host is generate properly.
ASSERT_TRUE(host); // Make sure the host is generated properly.
// Get the address.
IPv6ResrvRange resrvs = host->getIPv6Reservations();
......@@ -380,11 +380,10 @@ TEST_F(HostCacheTest, negativeIdentifier4) {
ASSERT_FALSE(HostMgr::instance().getNegativeCaching());
// Create a host reservation.
HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1",
Host::IDENT_HWADDR);
ASSERT_TRUE(host); // Make sure the host is generate properly.
// We will not add it anywhere, just will use its values.
HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
ASSERT_TRUE(host);
// Do not add it to the host data source.
// Try to get it cached.
ConstHostPtr got = HostMgr::instance().get4(host->getIPv4SubnetID(),
......@@ -403,7 +402,8 @@ TEST_F(HostCacheTest, negativeIdentifier4) {
HostMgr::instance().setNegativeCaching(true);
ASSERT_TRUE(HostMgr::instance().getNegativeCaching());
// Try it but it will be cached only the second time.
// Try it again. There is no such host, but this time negative cache is enabled,
// so this negative response will be added to the cache.
got = HostMgr::instance().get4Any(host->getIPv4SubnetID(),
host->getIdentifierType(),
&host->getIdentifier()[0],
......@@ -450,10 +450,11 @@ TEST_F(HostCacheTest, negativeIdentifier6) {
ASSERT_TRUE(memptr_);
// Create a host reservation.
// We will not add it anywhere, just will use its values.
HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1",
Host::IDENT_DUID,
false);
ASSERT_TRUE(host); // Make sure the host is generate properly.
ASSERT_TRUE(host); // Make sure the host is generated properly.
// Do not add it to the host data source.
......@@ -521,9 +522,10 @@ TEST_F(HostCacheTest, negativeAddress4) {
ASSERT_TRUE(memptr_);
// Create a host reservation.
// We will not add it anywhere, just will use its values.
HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1",
Host::IDENT_HWADDR);
ASSERT_TRUE(host); // Make sure the host is generate properly.
ASSERT_TRUE(host); // Make sure the host is generated properly.
const IOAddress& address = host->getIPv4Reservation();
// Do not add it to the host data source.
......@@ -550,10 +552,11 @@ TEST_F(HostCacheTest, negativeAddress6) {
ASSERT_TRUE(memptr_);
// Create a host reservation.
// We will not add it anywhere, just will use its values.
HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1",
Host::IDENT_DUID,
false);
ASSERT_TRUE(host); // Make sure the host is generate properly.
ASSERT_TRUE(host); // Make sure the host is generated properly.
// Get the address.
IPv6ResrvRange resrvs = host->getIPv6Reservations();
......
......@@ -110,7 +110,7 @@ protected:
void testGet4(BaseHostDataSource& data_source);
/// @brief This test verifies that it is possible to retrieve negative
/// cached reservation with and only with get4Any,
/// cached reservation with and only with get4Any.
void testGet4Any();
/// @brief This test verifies that it is possible to retrieve an IPv6
......@@ -121,7 +121,7 @@ protected:
void testGet6(BaseHostDataSource& data_source);
/// @brief This test verifies that it is possible to retrieve negative
/// cached reservation with and only with get6Any,
/// cached reservation with and only with get6Any.
void testGet6Any();
/// @brief This test verifies that it is possible to retrieve an IPv6
......@@ -336,13 +336,13 @@ HostMgrTest::testGet4Any() {
// Set the negative cache flag on the host.
new_host->setNegative(true);
// Get4 can't get it.
// get4 is not supposed to get it.
host = HostMgr::instance().get4(SubnetID(1), Host::IDENT_DUID,
&duids_[0]->getDuid()[0],
duids_[0]->getDuid().size());
EXPECT_FALSE(host);
// But Get4Any can.
// But get4Any should.
host = HostMgr::instance().get4Any(SubnetID(1), Host::IDENT_DUID,
&duids_[0]->getDuid()[0],
duids_[0]->getDuid().size());
......@@ -409,13 +409,13 @@ HostMgrTest::testGet6Any() {
// Set the negative cache flag on the host.
new_host->setNegative(true);
// Get6 can't get it.
// get6 is not supposed to get it.
host = HostMgr::instance().get6(SubnetID(2), Host::IDENT_HWADDR,
&hwaddrs_[0]->hwaddr_[0],
hwaddrs_[0]->hwaddr_.size());
EXPECT_FALSE(host);
// But Get4Any can.
// But get6Any should.
host = HostMgr::instance().get6Any(SubnetID(2), Host::IDENT_HWADDR,
&hwaddrs_[0]->hwaddr_[0],
hwaddrs_[0]->hwaddr_.size());
......
......@@ -148,7 +148,7 @@ TEST(MySqlHostDataSource, OpenDatabase) {
destroyMySQLSchema();
createMySQLSchema();
// Check that lease manager open the database opens correctly and tidy up.
// Check that host manager open the database opens correctly and tidy up.
// If it fails, print the error message.
try {
HostMgr::create();
......@@ -161,7 +161,7 @@ TEST(MySqlHostDataSource, OpenDatabase) {
<< "*** before the MySQL tests will run correctly.\n";
}
// Check that lease manager open the database opens correctly with a longer
// Check that host manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
string connection_string = validMySQLConnectionString() + string(" ") +
......@@ -176,7 +176,7 @@ TEST(MySqlHostDataSource, OpenDatabase) {
<< "*** before the MySQL tests will run correctly.\n";
}
// Check that attempting to get an instance of the lease manager when
// Check that attempting to get an instance of the host manager when
// none is set throws an exception.
EXPECT_FALSE(HostMgr::instance().getHostDataSource());
......
......@@ -148,7 +148,7 @@ TEST(PgSqlHostDataSource, OpenDatabase) {
destroyPgSQLSchema();
createPgSQLSchema();
// Check that lease manager open the database opens correctly and tidy up.
// Check that host manager open the database opens correctly and tidy up.
// If it fails, print the error message.
try {
HostMgr::create();
......@@ -161,7 +161,7 @@ TEST(PgSqlHostDataSource, OpenDatabase) {
<< "*** before the PostgreSQL tests will run correctly.\n";
}
// Check that lease manager open the database opens correctly with a longer
// Check that host manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
string connection_string = validPgSQLConnectionString() + string(" ") +
......@@ -175,7 +175,7 @@ TEST(PgSqlHostDataSource, OpenDatabase) {
<< "*** before the PostgreSQL tests will run correctly.\n";
}
// Check that attempting to get an instance of the lease manager when
// Check that attempting to get an instance of the host manager when
// none is set throws an exception.
EXPECT_FALSE(HostMgr::instance().getHostDataSource());
......
......@@ -31,6 +31,10 @@ public:
/// @brief Return all hosts for the specified HW address or DUID.
///
/// This may return hosts from multiple subnets.
///
/// Currently not implemented.
///
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
/// @param duid client id or NULL if not available, e.g. DHCPv4 client case.
......@@ -41,6 +45,10 @@ public:
/// @brief Return all hosts connected to any subnet for which reservations
/// have been made using a specified identifier.
///
/// This may return hosts from multiple subnets.
///
/// Currently not implemented.
///
/// @param identifier_type Identifier type.
/// @param identifier_begin Pointer to a beginning of a buffer containing
/// an identifier.
......@@ -53,6 +61,8 @@ public:
/// @brief Returns a collection of hosts using the specified IPv4 address.
///
/// Currently not implemented.
///
/// @param address IPv4 address for which the @c Host object is searched.
/// @return Empty collection of const @c Host objects.
virtual ConstHostCollection
......@@ -60,6 +70,8 @@ public:
/// @brief Returns a host connected to the IPv4 subnet.
///
/// Currently not implemented.
///
/// @param subnet_id Subnet identifier.
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
......@@ -97,6 +109,8 @@ public:
/// @brief Returns a host connected to the IPv6 subnet.
///
/// Currently not implemented.
///
/// @param subnet_id Subnet identifier.
/// @param hwaddr HW address of the client or NULL if no HW address
/// available.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment