|
@@ -27,7 +27,7 @@ GenericHostDataSourceTest::~GenericHostDataSourceTest() {
|
|
}
|
|
}
|
|
|
|
|
|
std::string
|
|
std::string
|
|
-GenericHostDataSourceTest::generateHWAddr() {
|
|
|
|
|
|
+GenericHostDataSourceTest::generateHWAddr(const bool new_identifier) {
|
|
/// @todo: Consider moving this somewhere to lib/testutils.
|
|
/// @todo: Consider moving this somewhere to lib/testutils.
|
|
|
|
|
|
// Let's use something that is easily printable. That's convenient
|
|
// Let's use something that is easily printable. That's convenient
|
|
@@ -43,18 +43,20 @@ GenericHostDataSourceTest::generateHWAddr() {
|
|
<< static_cast<unsigned int>(hwaddr[i]);
|
|
<< static_cast<unsigned int>(hwaddr[i]);
|
|
}
|
|
}
|
|
|
|
|
|
- // Increase the address for the next time we use it.
|
|
|
|
- // This is primitive, but will work for 65k unique
|
|
|
|
- // addresses.
|
|
|
|
- hwaddr[sizeof(hwaddr) - 1]++;
|
|
|
|
- if (hwaddr[sizeof(hwaddr) - 1] == 0) {
|
|
|
|
- hwaddr[sizeof(hwaddr) - 2]++;
|
|
|
|
|
|
+ if (new_identifier) {
|
|
|
|
+ // Increase the address for the next time we use it.
|
|
|
|
+ // This is primitive, but will work for 65k unique
|
|
|
|
+ // addresses.
|
|
|
|
+ hwaddr[sizeof(hwaddr) - 1]++;
|
|
|
|
+ if (hwaddr[sizeof(hwaddr) - 1] == 0) {
|
|
|
|
+ hwaddr[sizeof(hwaddr) - 2]++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return (tmp.str());
|
|
return (tmp.str());
|
|
}
|
|
}
|
|
|
|
|
|
std::string
|
|
std::string
|
|
-GenericHostDataSourceTest::generateDuid() {
|
|
|
|
|
|
+GenericHostDataSourceTest::generateDuid(const bool new_identifier) {
|
|
/// @todo: Consider moving this somewhere to lib/testutils.
|
|
/// @todo: Consider moving this somewhere to lib/testutils.
|
|
|
|
|
|
// Let's use something that is easily printable. That's convenient
|
|
// Let's use something that is easily printable. That's convenient
|
|
@@ -70,9 +72,11 @@ GenericHostDataSourceTest::generateDuid() {
|
|
// Increase the DUID for the next time we use it.
|
|
// Increase the DUID for the next time we use it.
|
|
// This is primitive, but will work for 65k unique
|
|
// This is primitive, but will work for 65k unique
|
|
// DUIDs.
|
|
// DUIDs.
|
|
- duid[sizeof(duid) - 1]++;
|
|
|
|
- if (duid[sizeof(duid) - 1] == 0) {
|
|
|
|
- duid[sizeof(duid) - 2]++;
|
|
|
|
|
|
+ if (new_identifier) {
|
|
|
|
+ duid[sizeof(duid) - 1]++;
|
|
|
|
+ if (duid[sizeof(duid) - 1] == 0) {
|
|
|
|
+ duid[sizeof(duid) - 2]++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return (tmp.str());
|
|
return (tmp.str());
|
|
}
|
|
}
|
|
@@ -105,18 +109,19 @@ HostPtr GenericHostDataSourceTest::initializeHost4(std::string address,
|
|
}
|
|
}
|
|
|
|
|
|
HostPtr GenericHostDataSourceTest::initializeHost6(std::string address,
|
|
HostPtr GenericHostDataSourceTest::initializeHost6(std::string address,
|
|
- BaseHostDataSource::IdType identifier,
|
|
|
|
- bool prefix) {
|
|
|
|
|
|
+ Host::IdentifierType identifier,
|
|
|
|
+ bool prefix,
|
|
|
|
+ bool new_identifier) {
|
|
string ident;
|
|
string ident;
|
|
string ident_type;
|
|
string ident_type;
|
|
|
|
|
|
switch (identifier) {
|
|
switch (identifier) {
|
|
- case BaseHostDataSource::ID_HWADDR:
|
|
|
|
- ident = generateHWAddr();
|
|
|
|
|
|
+ case Host::IDENT_HWADDR:
|
|
|
|
+ ident = generateHWAddr(new_identifier);
|
|
ident_type = "hw-address";
|
|
ident_type = "hw-address";
|
|
break;
|
|
break;
|
|
- case BaseHostDataSource::ID_DUID:
|
|
|
|
- ident = generateDuid();
|
|
|
|
|
|
+ case Host::IDENT_DUID:
|
|
|
|
+ ident = generateDuid(new_identifier);
|
|
ident_type = "duid";
|
|
ident_type = "duid";
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
@@ -416,8 +421,14 @@ void GenericHostDataSourceTest::testGet4ByHWAddr() {
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
SubnetID subnet2 = host2->getIPv4SubnetID();
|
|
SubnetID subnet2 = host2->getIPv4SubnetID();
|
|
|
|
|
|
- ConstHostPtr from_hds1 = hdsptr_->get4(subnet1, host1->getHWAddress());
|
|
|
|
- ConstHostPtr from_hds2 = hdsptr_->get4(subnet2, host2->getHWAddress());
|
|
|
|
|
|
+ ConstHostPtr from_hds1 = hdsptr_->get4(subnet1,
|
|
|
|
+ Host::IDENT_HWADDR,
|
|
|
|
+ &host1->getIdentifier()[0],
|
|
|
|
+ host1->getIdentifier().size());
|
|
|
|
+ ConstHostPtr from_hds2 = hdsptr_->get4(subnet2,
|
|
|
|
+ Host::IDENT_HWADDR,
|
|
|
|
+ &host2->getIdentifier()[0],
|
|
|
|
+ host2->getIdentifier().size());
|
|
|
|
|
|
// Now let's check if we got what we expected.
|
|
// Now let's check if we got what we expected.
|
|
ASSERT_TRUE(from_hds1);
|
|
ASSERT_TRUE(from_hds1);
|
|
@@ -445,8 +456,15 @@ void GenericHostDataSourceTest::testGet4ByClientId() {
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
SubnetID subnet1 = host1->getIPv4SubnetID();
|
|
SubnetID subnet2 = host2->getIPv4SubnetID();
|
|
SubnetID subnet2 = host2->getIPv4SubnetID();
|
|
|
|
|
|
- ConstHostPtr from_hds1 = hdsptr_->get4(subnet1, HWAddrPtr(), host1->getDuid());
|
|
|
|
- ConstHostPtr from_hds2 = hdsptr_->get4(subnet2, HWAddrPtr(), host2->getDuid());
|
|
|
|
|
|
+ ConstHostPtr from_hds1 = hdsptr_->get4(subnet1,
|
|
|
|
+ Host::IDENT_DUID,
|
|
|
|
+ &host1->getIdentifier()[0],
|
|
|
|
+ host1->getIdentifier().size());
|
|
|
|
+
|
|
|
|
+ ConstHostPtr from_hds2 = hdsptr_->get4(subnet2,
|
|
|
|
+ Host::IDENT_DUID,
|
|
|
|
+ &host2->getIdentifier()[0],
|
|
|
|
+ host2->getIdentifier().size());
|
|
|
|
|
|
// Now let's check if we got what we expected.
|
|
// Now let's check if we got what we expected.
|
|
ASSERT_TRUE(from_hds1);
|
|
ASSERT_TRUE(from_hds1);
|
|
@@ -472,10 +490,14 @@ void GenericHostDataSourceTest::testHWAddrNotClientId() {
|
|
DuidPtr duid = HWAddrToDuid(host->getHWAddress());
|
|
DuidPtr duid = HWAddrToDuid(host->getHWAddress());
|
|
|
|
|
|
// Get the host by HW address (should succeed)
|
|
// Get the host by HW address (should succeed)
|
|
- ConstHostPtr by_hwaddr = hdsptr_->get4(subnet, host->getHWAddress(), DuidPtr());
|
|
|
|
|
|
+ ConstHostPtr by_hwaddr = hdsptr_->get4(subnet, Host::IDENT_HWADDR,
|
|
|
|
+ &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
|
|
|
|
// Get the host by DUID (should fail)
|
|
// Get the host by DUID (should fail)
|
|
- ConstHostPtr by_duid = hdsptr_->get4(subnet, HWAddrPtr(), duid);
|
|
|
|
|
|
+ ConstHostPtr by_duid = hdsptr_->get4(subnet, Host::IDENT_DUID,
|
|
|
|
+ &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
|
|
|
|
// Now let's check if we got what we expected.
|
|
// Now let's check if we got what we expected.
|
|
EXPECT_TRUE(by_hwaddr);
|
|
EXPECT_TRUE(by_hwaddr);
|
|
@@ -499,10 +521,15 @@ void GenericHostDataSourceTest::testClientIdNotHWAddr() {
|
|
HWAddrPtr hwaddr = DuidToHWAddr(host->getDuid());
|
|
HWAddrPtr hwaddr = DuidToHWAddr(host->getDuid());
|
|
|
|
|
|
// Get the host by DUID (should succeed)
|
|
// Get the host by DUID (should succeed)
|
|
- ConstHostPtr by_duid = hdsptr_->get4(subnet, HWAddrPtr(), host->getDuid());
|
|
|
|
|
|
+ ConstHostPtr by_duid = hdsptr_->get4(subnet, Host::IDENT_DUID,
|
|
|
|
+ &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
|
|
+
|
|
|
|
|
|
// Get the host by HW address (should fail)
|
|
// Get the host by HW address (should fail)
|
|
- ConstHostPtr by_hwaddr = hdsptr_->get4(subnet, hwaddr, DuidPtr());
|
|
|
|
|
|
+ ConstHostPtr by_hwaddr = hdsptr_->get4(subnet, Host::IDENT_HWADDR,
|
|
|
|
+ &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
|
|
|
|
// Now let's check if we got what we expected.
|
|
// Now let's check if we got what we expected.
|
|
EXPECT_TRUE(by_duid);
|
|
EXPECT_TRUE(by_duid);
|
|
@@ -588,7 +615,10 @@ GenericHostDataSourceTest::testMultipleSubnets(int subnets, bool hwaddr) {
|
|
EXPECT_EQ(i + 1000, from_hds->getIPv4SubnetID());
|
|
EXPECT_EQ(i + 1000, from_hds->getIPv4SubnetID());
|
|
|
|
|
|
// Try to retrieve the host by either HW address of client-id
|
|
// Try to retrieve the host by either HW address of client-id
|
|
- from_hds = hdsptr_->get4(i + 1000, host->getHWAddress(), host->getDuid());
|
|
|
|
|
|
+ from_hds = hdsptr_->get4(i + 1000,
|
|
|
|
+ hwaddr ? Host::IDENT_HWADDR : Host::IDENT_DUID,
|
|
|
|
+ &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
ASSERT_TRUE(from_hds);
|
|
ASSERT_TRUE(from_hds);
|
|
EXPECT_EQ(i + 1000, from_hds->getIPv4SubnetID());
|
|
EXPECT_EQ(i + 1000, from_hds->getIPv4SubnetID());
|
|
}
|
|
}
|
|
@@ -606,8 +636,10 @@ GenericHostDataSourceTest::testMultipleSubnets(int subnets, bool hwaddr) {
|
|
}
|
|
}
|
|
|
|
|
|
// Finally, check that the hosts can be retrived by HW address or DUID
|
|
// Finally, check that the hosts can be retrived by HW address or DUID
|
|
- ConstHostCollection all_by_id = hdsptr_->getAll(host->getHWAddress(),
|
|
|
|
- host->getDuid());
|
|
|
|
|
|
+ ConstHostCollection all_by_id =
|
|
|
|
+ hdsptr_->getAll(hwaddr ? Host::IDENT_HWADDR : Host::IDENT_DUID,
|
|
|
|
+ &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
ASSERT_EQ(subnets, all_by_id.size());
|
|
ASSERT_EQ(subnets, all_by_id.size());
|
|
|
|
|
|
// Check that the returned values are as expected.
|
|
// Check that the returned values are as expected.
|
|
@@ -624,8 +656,8 @@ void GenericHostDataSourceTest::testGet6ByHWAddr() {
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
|
|
|
|
// Create a host reservations.
|
|
// Create a host reservations.
|
|
- HostPtr host1 = initializeHost6("2001:db8::1", BaseHostDataSource::ID_HWADDR, true);
|
|
|
|
- HostPtr host2 = initializeHost6("2001:db8::2", BaseHostDataSource::ID_HWADDR, true);
|
|
|
|
|
|
+ HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true);
|
|
|
|
+ HostPtr host2 = initializeHost6("2001:db8::2", Host::IDENT_HWADDR, true);
|
|
|
|
|
|
// Sanity check: make sure the hosts have different HW addresses.
|
|
// Sanity check: make sure the hosts have different HW addresses.
|
|
ASSERT_TRUE(host1->getHWAddress());
|
|
ASSERT_TRUE(host1->getHWAddress());
|
|
@@ -640,8 +672,13 @@ void GenericHostDataSourceTest::testGet6ByHWAddr() {
|
|
SubnetID subnet1 = host1->getIPv6SubnetID();
|
|
SubnetID subnet1 = host1->getIPv6SubnetID();
|
|
SubnetID subnet2 = host2->getIPv6SubnetID();
|
|
SubnetID subnet2 = host2->getIPv6SubnetID();
|
|
|
|
|
|
- ConstHostPtr from_hds1 = hdsptr_->get6(subnet1, DuidPtr(), host1->getHWAddress());
|
|
|
|
- ConstHostPtr from_hds2 = hdsptr_->get6(subnet2, DuidPtr(), host2->getHWAddress());
|
|
|
|
|
|
+ ConstHostPtr from_hds1 = hdsptr_->get6(subnet1, Host::IDENT_HWADDR,
|
|
|
|
+ &host1->getIdentifier()[0],
|
|
|
|
+ host1->getIdentifier().size());
|
|
|
|
+
|
|
|
|
+ ConstHostPtr from_hds2 = hdsptr_->get6(subnet2, Host::IDENT_HWADDR,
|
|
|
|
+ &host2->getIdentifier()[0],
|
|
|
|
+ host2->getIdentifier().size());
|
|
|
|
|
|
// Now let's check if we got what we expected.
|
|
// Now let's check if we got what we expected.
|
|
ASSERT_TRUE(from_hds1);
|
|
ASSERT_TRUE(from_hds1);
|
|
@@ -655,8 +692,8 @@ void GenericHostDataSourceTest::testGet6ByClientId() {
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
|
|
|
|
// Create a host reservations.
|
|
// Create a host reservations.
|
|
- HostPtr host1 = initializeHost6("2001:db8::1", BaseHostDataSource::ID_DUID, true);
|
|
|
|
- HostPtr host2 = initializeHost6("2001:db8::2", BaseHostDataSource::ID_DUID, true);
|
|
|
|
|
|
+ HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
|
|
|
|
+ HostPtr host2 = initializeHost6("2001:db8::2", Host::IDENT_DUID, true);
|
|
|
|
|
|
// Sanity check: make sure the hosts have different HW addresses.
|
|
// Sanity check: make sure the hosts have different HW addresses.
|
|
ASSERT_TRUE(host1->getDuid());
|
|
ASSERT_TRUE(host1->getDuid());
|
|
@@ -671,8 +708,13 @@ void GenericHostDataSourceTest::testGet6ByClientId() {
|
|
SubnetID subnet1 = host1->getIPv6SubnetID();
|
|
SubnetID subnet1 = host1->getIPv6SubnetID();
|
|
SubnetID subnet2 = host2->getIPv6SubnetID();
|
|
SubnetID subnet2 = host2->getIPv6SubnetID();
|
|
|
|
|
|
- ConstHostPtr from_hds1 = hdsptr_->get6(subnet1, host1->getDuid(), HWAddrPtr());
|
|
|
|
- ConstHostPtr from_hds2 = hdsptr_->get6(subnet2, host2->getDuid(), HWAddrPtr());
|
|
|
|
|
|
+ ConstHostPtr from_hds1 = hdsptr_->get6(subnet1, Host::IDENT_DUID,
|
|
|
|
+ &host1->getIdentifier()[0],
|
|
|
|
+ host1->getIdentifier().size());
|
|
|
|
+
|
|
|
|
+ ConstHostPtr from_hds2 = hdsptr_->get6(subnet2, Host::IDENT_DUID,
|
|
|
|
+ &host2->getIdentifier()[0],
|
|
|
|
+ host2->getIdentifier().size());
|
|
|
|
|
|
// Now let's check if we got what we expected.
|
|
// Now let's check if we got what we expected.
|
|
ASSERT_TRUE(from_hds1);
|
|
ASSERT_TRUE(from_hds1);
|
|
@@ -682,35 +724,43 @@ void GenericHostDataSourceTest::testGet6ByClientId() {
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
void
|
|
-GenericHostDataSourceTest::testSubnetId6(int subnets, BaseHostDataSource::IdType id) {
|
|
|
|
|
|
+GenericHostDataSourceTest::testSubnetId6(int subnets, Host::IdentifierType id) {
|
|
|
|
|
|
// Make sure we have a pointer to the host data source.
|
|
// Make sure we have a pointer to the host data source.
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
|
|
|
|
- HostPtr host = initializeHost6("2001:db8::0", id, true);
|
|
|
|
-
|
|
|
|
|
|
+ HostPtr host;
|
|
|
|
+ IOAddress current_address("2001:db8::0");
|
|
for (int i = 0; i < subnets; ++i) {
|
|
for (int i = 0; i < subnets; ++i) {
|
|
|
|
+ // Last boolean value set to false indicates that the same identifier
|
|
|
|
+ // must be used for each generated host.
|
|
|
|
+ host = initializeHost6(current_address.toText(), id, true, false);
|
|
|
|
+
|
|
host->setIPv4SubnetID(i + 1000);
|
|
host->setIPv4SubnetID(i + 1000);
|
|
host->setIPv6SubnetID(i + 1000);
|
|
host->setIPv6SubnetID(i + 1000);
|
|
|
|
|
|
// Check that the same host can have reservations in multiple subnets.
|
|
// Check that the same host can have reservations in multiple subnets.
|
|
EXPECT_NO_THROW(hdsptr_->add(host));
|
|
EXPECT_NO_THROW(hdsptr_->add(host));
|
|
|
|
+
|
|
|
|
+ // Increase address to make sure we don't assign the same address
|
|
|
|
+ // in different subnets.
|
|
|
|
+ current_address = IOAddress::increase(current_address);
|
|
}
|
|
}
|
|
|
|
|
|
// Check that the reservations can be retrieved from each subnet separately.
|
|
// Check that the reservations can be retrieved from each subnet separately.
|
|
for (int i = 0; i < subnets; ++i) {
|
|
for (int i = 0; i < subnets; ++i) {
|
|
|
|
|
|
// Try to retrieve the host
|
|
// Try to retrieve the host
|
|
- ConstHostPtr from_hds = hdsptr_->get6(i + 1000, host->getDuid(),
|
|
|
|
- host->getHWAddress());
|
|
|
|
|
|
+ ConstHostPtr from_hds = hdsptr_->get6(i + 1000, id, &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
|
|
|
|
- ASSERT_TRUE(from_hds);
|
|
|
|
|
|
+ ASSERT_TRUE(from_hds) << "failed for i=" << i;
|
|
EXPECT_EQ(i + 1000, from_hds->getIPv6SubnetID());
|
|
EXPECT_EQ(i + 1000, from_hds->getIPv6SubnetID());
|
|
}
|
|
}
|
|
|
|
|
|
// Check that the hosts can all be retrived by HW address or DUID
|
|
// Check that the hosts can all be retrived by HW address or DUID
|
|
- ConstHostCollection all_by_id = hdsptr_->getAll(host->getHWAddress(),
|
|
|
|
- host->getDuid());
|
|
|
|
|
|
+ ConstHostCollection all_by_id = hdsptr_->getAll(id, &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
ASSERT_EQ(subnets, all_by_id.size());
|
|
ASSERT_EQ(subnets, all_by_id.size());
|
|
|
|
|
|
// Check that the returned values are as expected.
|
|
// Check that the returned values are as expected.
|
|
@@ -722,7 +772,7 @@ GenericHostDataSourceTest::testSubnetId6(int subnets, BaseHostDataSource::IdType
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void GenericHostDataSourceTest::testGetByIPv6(BaseHostDataSource::IdType id,
|
|
|
|
|
|
+void GenericHostDataSourceTest::testGetByIPv6(Host::IdentifierType id,
|
|
bool prefix) {
|
|
bool prefix) {
|
|
// Make sure we have a pointer to the host data source.
|
|
// Make sure we have a pointer to the host data source.
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
@@ -770,7 +820,7 @@ void GenericHostDataSourceTest::testAddDuplicate6WithSameDUID() {
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
|
|
|
|
// Create a host reservations.
|
|
// Create a host reservations.
|
|
- HostPtr host = initializeHost6("2001:db8::1", BaseHostDataSource::ID_DUID, true);
|
|
|
|
|
|
+ HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
|
|
|
|
|
|
// Add this reservation once.
|
|
// Add this reservation once.
|
|
ASSERT_NO_THROW(hdsptr_->add(host));
|
|
ASSERT_NO_THROW(hdsptr_->add(host));
|
|
@@ -784,7 +834,7 @@ void GenericHostDataSourceTest::testAddDuplicate6WithSameHWAddr() {
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
|
|
|
|
// Create a host reservations.
|
|
// Create a host reservations.
|
|
- HostPtr host = initializeHost6("2001:db8::1", BaseHostDataSource::ID_HWADDR, true);
|
|
|
|
|
|
+ HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true);
|
|
|
|
|
|
// Add this reservation once.
|
|
// Add this reservation once.
|
|
ASSERT_NO_THROW(hdsptr_->add(host));
|
|
ASSERT_NO_THROW(hdsptr_->add(host));
|
|
@@ -805,6 +855,17 @@ void GenericHostDataSourceTest::testAddDuplicate4() {
|
|
|
|
|
|
// Then try to add it again, it should throw an exception.
|
|
// Then try to add it again, it should throw an exception.
|
|
ASSERT_THROW(hdsptr_->add(host), DuplicateEntry);
|
|
ASSERT_THROW(hdsptr_->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);
|
|
|
|
+
|
|
|
|
+ // 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));
|
|
}
|
|
}
|
|
|
|
|
|
void GenericHostDataSourceTest::testAddr6AndPrefix(){
|
|
void GenericHostDataSourceTest::testAddr6AndPrefix(){
|
|
@@ -812,7 +873,7 @@ void GenericHostDataSourceTest::testAddr6AndPrefix(){
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
|
|
|
|
// Create a host reservations with prefix reservation (prefix = true)
|
|
// Create a host reservations with prefix reservation (prefix = true)
|
|
- HostPtr host = initializeHost6("2001:db8::1", BaseHostDataSource::ID_DUID, true);
|
|
|
|
|
|
+ HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
|
|
|
|
|
|
// Create IPv6 reservation (for an address) and add it to the host
|
|
// Create IPv6 reservation (for an address) and add it to the host
|
|
IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::2"), 128);
|
|
IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::2"), 128);
|
|
@@ -822,13 +883,17 @@ void GenericHostDataSourceTest::testAddr6AndPrefix(){
|
|
ASSERT_NO_THROW(hdsptr_->add(host));
|
|
ASSERT_NO_THROW(hdsptr_->add(host));
|
|
|
|
|
|
// Get this host by DUID
|
|
// Get this host by DUID
|
|
- ConstHostPtr from_hds = hdsptr_->get6(host->getIPv6SubnetID(), host->getDuid(), HWAddrPtr());
|
|
|
|
|
|
+ ConstHostPtr from_hds = hdsptr_->get6(host->getIPv6SubnetID(),
|
|
|
|
+ Host::IDENT_DUID,
|
|
|
|
+ &host->getIdentifier()[0],
|
|
|
|
+ host->getIdentifier().size());
|
|
|
|
|
|
// Make sure we got something back
|
|
// Make sure we got something back
|
|
ASSERT_TRUE(from_hds);
|
|
ASSERT_TRUE(from_hds);
|
|
|
|
|
|
// Check if reservations are the same
|
|
// Check if reservations are the same
|
|
- compareReservations6(host->getIPv6Reservations(), from_hds->getIPv6Reservations());
|
|
|
|
|
|
+ compareReservations6(host->getIPv6Reservations(),
|
|
|
|
+ from_hds->getIPv6Reservations());
|
|
}
|
|
}
|
|
|
|
|
|
void GenericHostDataSourceTest::testMultipleReservations(){
|
|
void GenericHostDataSourceTest::testMultipleReservations(){
|
|
@@ -836,7 +901,7 @@ void GenericHostDataSourceTest::testMultipleReservations(){
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
uint8_t len = 128;
|
|
uint8_t len = 128;
|
|
|
|
|
|
- HostPtr host = initializeHost6("2001:db8::1", BaseHostDataSource::ID_DUID, false);
|
|
|
|
|
|
+ HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
|
|
|
|
|
|
// Add some reservations
|
|
// Add some reservations
|
|
IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
|
|
IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
|
|
@@ -866,8 +931,8 @@ void GenericHostDataSourceTest::testMultipleReservationsDifferentOrder(){
|
|
ASSERT_TRUE(hdsptr_);
|
|
ASSERT_TRUE(hdsptr_);
|
|
uint8_t len = 128;
|
|
uint8_t len = 128;
|
|
|
|
|
|
- HostPtr host1 = initializeHost6("2001:db8::1", BaseHostDataSource::ID_DUID, false);
|
|
|
|
- HostPtr host2 = initializeHost6("2001:db8::1", BaseHostDataSource::ID_DUID, false);
|
|
|
|
|
|
+ HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
|
|
|
|
+ HostPtr host2 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
|
|
|
|
|
|
// Add some reservations
|
|
// Add some reservations
|
|
IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
|
|
IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
|