|
@@ -545,7 +545,7 @@ GenericHostDataSourceTest::testReadOnlyDatabase(const char* valid_db_type) {
|
|
|
// exception.
|
|
|
HostPtr host2 = initializeHost6("2001:db8::2", Host::IDENT_DUID, false);
|
|
|
ASSERT_TRUE(host2);
|
|
|
- ASSERT_THROW(hdsptr_->add(host2), ReadOnlyDb);
|
|
|
+ ASSERT_THROW(add(host2), ReadOnlyDb);
|
|
|
ASSERT_THROW(hdsptr_->commit(), ReadOnlyDb);
|
|
|
ASSERT_THROW(hdsptr_->rollback(), ReadOnlyDb);
|
|
|
|
|
@@ -567,7 +567,7 @@ void GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) {
|
|
|
SubnetID subnet = host->getIPv4SubnetID();
|
|
|
|
|
|
// Try to add it to the host data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// This should not return anything
|
|
|
ConstHostPtr from_hds = hdsptr_->get4(subnet, IOAddress("10.10.10.10"));
|
|
@@ -581,6 +581,25 @@ void GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) {
|
|
|
compareHosts(host, from_hds);
|
|
|
}
|
|
|
|
|
|
+void GenericHostDataSourceTest::add(const HostPtr& host) const {
|
|
|
+ hdsptr_->add(host);
|
|
|
+}
|
|
|
+
|
|
|
+bool GenericHostDataSourceTest::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) {
|
|
|
+ return hdsptr_->del(subnet_id, addr);
|
|
|
+}
|
|
|
+
|
|
|
+bool GenericHostDataSourceTest::del4(const SubnetID& subnet_id,
|
|
|
+ const Host::IdentifierType& identifier_type,
|
|
|
+ const uint8_t* identifier_begin, const size_t identifier_len) {
|
|
|
+ return hdsptr_->del4(subnet_id, identifier_type, identifier_begin, identifier_len);
|
|
|
+}
|
|
|
+
|
|
|
+bool GenericHostDataSourceTest::del6(const SubnetID& subnet_id,
|
|
|
+ const Host::IdentifierType& identifier_type,
|
|
|
+ const uint8_t* identifier_begin, const size_t identifier_len) {
|
|
|
+ return hdsptr_->del6(subnet_id, identifier_type, identifier_begin, identifier_len);
|
|
|
+}
|
|
|
|
|
|
void GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
|
|
|
// Make sure we have a pointer to the host data source.
|
|
@@ -593,10 +612,10 @@ void GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
|
|
|
HostPtr host4 = initializeHost4("192.0.2.4", id);
|
|
|
|
|
|
// ... and add them to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host2));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host3));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host4));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host2));
|
|
|
+ ASSERT_NO_THROW(add(host3));
|
|
|
+ ASSERT_NO_THROW(add(host4));
|
|
|
|
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
|
SubnetID subnet2 = host2->getIPv4SubnetID();
|
|
@@ -638,8 +657,8 @@ GenericHostDataSourceTest::testGet4ByIdentifier(const Host::IdentifierType& iden
|
|
|
ASSERT_FALSE(host1->getIdentifier() == host2->getIdentifier());
|
|
|
|
|
|
// Try to add both of them to the host data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host2));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host2));
|
|
|
|
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
|
SubnetID subnet2 = host2->getIPv4SubnetID();
|
|
@@ -671,7 +690,7 @@ void GenericHostDataSourceTest::testHWAddrNotClientId() {
|
|
|
ASSERT_FALSE(host->getDuid());
|
|
|
|
|
|
// Try to add it to the host data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
SubnetID subnet = host->getIPv4SubnetID();
|
|
|
|
|
@@ -702,7 +721,7 @@ void GenericHostDataSourceTest::testClientIdNotHWAddr() {
|
|
|
ASSERT_TRUE(host->getDuid());
|
|
|
|
|
|
// Try to add it to the host data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
SubnetID subnet = host->getIPv4SubnetID();
|
|
|
|
|
@@ -758,7 +777,7 @@ GenericHostDataSourceTest::testHostname(std::string name, int num) {
|
|
|
for (vector<HostPtr>::const_iterator it = hosts.begin();
|
|
|
it != hosts.end(); ++it) {
|
|
|
// Try to add both of the to the host data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(*it));
|
|
|
+ ASSERT_NO_THROW(add(*it));
|
|
|
}
|
|
|
|
|
|
// And finally retrieve them one by one and check
|
|
@@ -790,7 +809,7 @@ GenericHostDataSourceTest::testMultipleSubnets(int subnets,
|
|
|
host->setIPv6SubnetID(i + 1000);
|
|
|
|
|
|
// Check that the same host can have reservations in multiple subnets.
|
|
|
- EXPECT_NO_THROW(hdsptr_->add(host));
|
|
|
+ EXPECT_NO_THROW(add(host));
|
|
|
}
|
|
|
|
|
|
// Now check that the reservations can be retrieved by IPv4 address from
|
|
@@ -853,8 +872,8 @@ void GenericHostDataSourceTest::testGet6ByHWAddr() {
|
|
|
compareHwaddrs(host1, host2, false);
|
|
|
|
|
|
// Try to add both of them to the host data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host2));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host2));
|
|
|
|
|
|
SubnetID subnet1 = host1->getIPv6SubnetID();
|
|
|
SubnetID subnet2 = host2->getIPv6SubnetID();
|
|
@@ -889,8 +908,8 @@ void GenericHostDataSourceTest::testGet6ByClientId() {
|
|
|
compareDuids(host1, host2, false);
|
|
|
|
|
|
// Try to add both of them to the host data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host2));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host2));
|
|
|
|
|
|
SubnetID subnet1 = host1->getIPv6SubnetID();
|
|
|
SubnetID subnet2 = host2->getIPv6SubnetID();
|
|
@@ -927,7 +946,7 @@ GenericHostDataSourceTest::testSubnetId6(int subnets, Host::IdentifierType id) {
|
|
|
host->setIPv6SubnetID(i + 1000);
|
|
|
|
|
|
// Check that the same host can have reservations in multiple subnets.
|
|
|
- EXPECT_NO_THROW(hdsptr_->add(host));
|
|
|
+ EXPECT_NO_THROW(add(host));
|
|
|
|
|
|
// Increase address to make sure we don't assign the same address
|
|
|
// in different subnets.
|
|
@@ -971,10 +990,10 @@ void GenericHostDataSourceTest::testGetByIPv6(Host::IdentifierType id,
|
|
|
HostPtr host4 = initializeHost6("2001:db8::4", id, prefix);
|
|
|
|
|
|
// ... and add them to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host2));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host3));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host4));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host2));
|
|
|
+ ASSERT_NO_THROW(add(host3));
|
|
|
+ ASSERT_NO_THROW(add(host4));
|
|
|
|
|
|
// Are we talking about addresses or prefixes?
|
|
|
uint8_t len = prefix ? 64 : 128;
|
|
@@ -1013,10 +1032,10 @@ void GenericHostDataSourceTest::testGetBySubnetIPv6() {
|
|
|
HostPtr host4 = initializeHost6("2001:db8:4::", Host::IDENT_DUID, true);
|
|
|
|
|
|
// ... and add them to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host2));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host3));
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host4));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host2));
|
|
|
+ ASSERT_NO_THROW(add(host3));
|
|
|
+ ASSERT_NO_THROW(add(host4));
|
|
|
|
|
|
// And then try to retrieve them back.
|
|
|
ConstHostPtr from_hds1 = hdsptr_->get6(host1->getIPv6SubnetID(),
|
|
@@ -1050,10 +1069,10 @@ void GenericHostDataSourceTest::testAddDuplicate6WithSameDUID() {
|
|
|
HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
|
|
|
|
|
|
// Add this reservation once.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Then try to add it again, it should throw an exception.
|
|
|
- ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
|
|
|
+ ASSERT_THROW(add(host), DuplicateEntry);
|
|
|
}
|
|
|
|
|
|
void GenericHostDataSourceTest::testAddDuplicate6WithSameHWAddr() {
|
|
@@ -1064,10 +1083,10 @@ void GenericHostDataSourceTest::testAddDuplicate6WithSameHWAddr() {
|
|
|
HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true);
|
|
|
|
|
|
// Add this reservation once.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Then try to add it again, it should throw an exception.
|
|
|
- ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
|
|
|
+ ASSERT_THROW(add(host), DuplicateEntry);
|
|
|
}
|
|
|
|
|
|
void GenericHostDataSourceTest::testAddDuplicate4() {
|
|
@@ -1078,21 +1097,21 @@ void GenericHostDataSourceTest::testAddDuplicate4() {
|
|
|
HostPtr host = initializeHost4("192.0.2.1", Host::IDENT_DUID);
|
|
|
|
|
|
// Add this reservation once.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Then try to add it again, it should throw an exception.
|
|
|
- ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
|
|
|
+ ASSERT_THROW(add(host), DuplicateEntry);
|
|
|
|
|
|
// This time use a different host identifier and try again.
|
|
|
// This update should be rejected because of duplicated
|
|
|
// address.
|
|
|
ASSERT_NO_THROW(host->setIdentifier("01:02:03:04:05:06", "hw-address"));
|
|
|
- ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
|
|
|
+ ASSERT_THROW(add(host), DuplicateEntry);
|
|
|
|
|
|
// Modify address to avoid its duplication and make sure
|
|
|
// we can now add the host.
|
|
|
ASSERT_NO_THROW(host->setIPv4Reservation(IOAddress("192.0.2.3")));
|
|
|
- EXPECT_NO_THROW(hdsptr_->add(host));
|
|
|
+ EXPECT_NO_THROW(add(host));
|
|
|
}
|
|
|
|
|
|
void GenericHostDataSourceTest::testAddr6AndPrefix(){
|
|
@@ -1107,7 +1126,7 @@ void GenericHostDataSourceTest::testAddr6AndPrefix(){
|
|
|
host->addReservation(resv);
|
|
|
|
|
|
// Add this reservation
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Get this host by DUID
|
|
|
ConstHostPtr from_hds = hdsptr_->get6(host->getIPv6SubnetID(),
|
|
@@ -1141,7 +1160,7 @@ void GenericHostDataSourceTest::testMultipleReservations(){
|
|
|
host->addReservation(resv3);
|
|
|
host->addReservation(resv4);
|
|
|
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
|
|
|
ConstHostPtr from_hds = hdsptr_->get6(IOAddress("2001:db8::1"), len);
|
|
@@ -1187,7 +1206,7 @@ void GenericHostDataSourceTest::testOptionsReservations4(const bool formatted) {
|
|
|
// Add a bunch of DHCPv4 and DHCPv6 options for the host.
|
|
|
ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP4_ONLY));
|
|
|
// Insert host and the options into respective tables.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
// Subnet id will be used in queries to the database.
|
|
|
SubnetID subnet_id = host->getIPv4SubnetID();
|
|
|
|
|
@@ -1213,7 +1232,7 @@ void GenericHostDataSourceTest::testOptionsReservations6(const bool formatted) {
|
|
|
// Add a bunch of DHCPv4 and DHCPv6 options for the host.
|
|
|
ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP6_ONLY));
|
|
|
// Insert host, options and IPv6 reservations into respective tables.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
// Subnet id will be used in queries to the database.
|
|
|
SubnetID subnet_id = host->getIPv6SubnetID();
|
|
|
|
|
@@ -1234,7 +1253,7 @@ void GenericHostDataSourceTest::testOptionsReservations46(const bool formatted)
|
|
|
// Add a bunch of DHCPv4 and DHCPv6 options for the host.
|
|
|
ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP4_AND_DHCP6));
|
|
|
// Insert host, options and IPv6 reservations into respective tables.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// getAll(identifier_type, identifier, identifier_size)
|
|
|
ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getIdentifierType(),
|
|
@@ -1259,7 +1278,7 @@ GenericHostDataSourceTest::testMultipleClientClasses4() {
|
|
|
}
|
|
|
|
|
|
// Add the host.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Subnet id will be used in queries to the database.
|
|
|
SubnetID subnet_id = host->getIPv4SubnetID();
|
|
@@ -1321,7 +1340,7 @@ GenericHostDataSourceTest::testMultipleClientClasses6() {
|
|
|
}
|
|
|
|
|
|
// Add the host.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Subnet id will be used in queries to the database.
|
|
|
SubnetID subnet_id = host->getIPv6SubnetID();
|
|
@@ -1387,7 +1406,7 @@ GenericHostDataSourceTest::testMultipleClientClassesBoth() {
|
|
|
}
|
|
|
|
|
|
// Add the host.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Subnet id will be used in queries to the database.
|
|
|
SubnetID subnet_id = host->getIPv6SubnetID();
|
|
@@ -1416,7 +1435,7 @@ GenericHostDataSourceTest::testMessageFields4() {
|
|
|
});
|
|
|
|
|
|
// Add the host.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
+ ASSERT_NO_THROW(add(host));
|
|
|
|
|
|
// Subnet id will be used in queries to the database.
|
|
|
SubnetID subnet_id = host->getIPv4SubnetID();
|
|
@@ -1472,13 +1491,13 @@ void GenericHostDataSourceTest::testDeleteByAddr4() {
|
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
|
|
|
|
// ... and add it to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
|
|
|
// And then try to retrieve it back.
|
|
|
ConstHostPtr before = hdsptr_->get4(subnet1, IOAddress("192.0.2.1"));
|
|
|
|
|
|
// Now try to delete it: del(subnet-id, addr4)
|
|
|
- EXPECT_TRUE(hdsptr_->del(subnet1, IOAddress("192.0.2.1")));
|
|
|
+ EXPECT_TRUE(del(subnet1, IOAddress("192.0.2.1")));
|
|
|
|
|
|
// Check if it's still there.
|
|
|
ConstHostPtr after = hdsptr_->get4(subnet1, IOAddress("192.0.2.1"));
|
|
@@ -1499,7 +1518,7 @@ void GenericHostDataSourceTest::testDeleteById4() {
|
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
|
|
|
|
// ... and add it to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
|
|
|
// And then try to retrieve it back.
|
|
|
ConstHostPtr before = hdsptr_->get4(subnet1,
|
|
@@ -1508,7 +1527,7 @@ void GenericHostDataSourceTest::testDeleteById4() {
|
|
|
host1->getIdentifier().size());
|
|
|
|
|
|
// Now try to delete it: del4(subnet4-id, identifier-type, identifier)
|
|
|
- EXPECT_TRUE(hdsptr_->del4(subnet1, host1->getIdentifierType(),
|
|
|
+ EXPECT_TRUE(del4(subnet1, host1->getIdentifierType(),
|
|
|
&host1->getIdentifier()[0],
|
|
|
host1->getIdentifier().size()));
|
|
|
|
|
@@ -1540,7 +1559,7 @@ void GenericHostDataSourceTest::testDeleteById4Options() {
|
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
|
|
|
|
// ... and add it to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
|
|
|
// There must be some options
|
|
|
EXPECT_NE(0, countDBOptions4());
|
|
@@ -1552,7 +1571,7 @@ void GenericHostDataSourceTest::testDeleteById4Options() {
|
|
|
host1->getIdentifier().size());
|
|
|
|
|
|
// Now try to delete it: del4(subnet4-id, identifier-type, identifier)
|
|
|
- EXPECT_TRUE(hdsptr_->del4(subnet1, host1->getIdentifierType(),
|
|
|
+ EXPECT_TRUE(del4(subnet1, host1->getIdentifierType(),
|
|
|
&host1->getIdentifier()[0],
|
|
|
host1->getIdentifier().size()));
|
|
|
|
|
@@ -1581,7 +1600,7 @@ void GenericHostDataSourceTest::testDeleteById6() {
|
|
|
SubnetID subnet1 = host1->getIPv6SubnetID();
|
|
|
|
|
|
// ... and add it to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
|
|
|
// And then try to retrieve it back.
|
|
|
ConstHostPtr before = hdsptr_->get6(subnet1,
|
|
@@ -1590,7 +1609,7 @@ void GenericHostDataSourceTest::testDeleteById6() {
|
|
|
host1->getIdentifier().size());
|
|
|
|
|
|
// Now try to delete it: del4(subnet4-id, identifier-type, identifier)
|
|
|
- EXPECT_TRUE(hdsptr_->del6(subnet1, host1->getIdentifierType(),
|
|
|
+ EXPECT_TRUE(del6(subnet1, host1->getIdentifierType(),
|
|
|
&host1->getIdentifier()[0],
|
|
|
host1->getIdentifier().size()));
|
|
|
|
|
@@ -1617,7 +1636,7 @@ void GenericHostDataSourceTest::testDeleteById6Options() {
|
|
|
ASSERT_NO_THROW(addTestOptions(host1, true, DHCP6_ONLY));
|
|
|
|
|
|
// ... and add it to the data source.
|
|
|
- ASSERT_NO_THROW(hdsptr_->add(host1));
|
|
|
+ ASSERT_NO_THROW(add(host1));
|
|
|
|
|
|
// Check that the options are stored...
|
|
|
EXPECT_NE(0, countDBOptions6());
|
|
@@ -1632,7 +1651,7 @@ void GenericHostDataSourceTest::testDeleteById6Options() {
|
|
|
host1->getIdentifier().size());
|
|
|
|
|
|
// Now try to delete it: del4(subnet4-id, identifier-type, identifier)
|
|
|
- EXPECT_TRUE(hdsptr_->del6(subnet1, host1->getIdentifierType(),
|
|
|
+ EXPECT_TRUE(del6(subnet1, host1->getIdentifierType(),
|
|
|
&host1->getIdentifier()[0],
|
|
|
host1->getIdentifier().size()));
|
|
|
|