if (duid){
// DUID
// set proper dhcp_identifier_type
- inbind[1].buffer = reinterpret_cast<char*>(1);
+ dhcp_identifier_type = 1; // 1 = IDENT_DUID
+ inbind[1].buffer = reinterpret_cast<char*>(&dhcp_identifier_type);
const vector<uint8_t>& duid_vector = duid->getDuid();
unsigned long duid_length = duid_vector.size();
inbind[0].length = &duid_length;
} else if (hwaddr) {
// HW Address
- // set proper dhcp_identifier_type
- inbind[1].buffer = reinterpret_cast<char*>(0);
+ dhcp_identifier_type = 0; // 0 = IDENT_HWADDR
+ inbind[1].buffer = reinterpret_cast<char*>(&dhcp_identifier_type);
const vector<uint8_t>& hwaddr_vector = hwaddr->hwaddr_;
unsigned long hwaddr_length = hwaddr_vector.size();
if (host1->getDuid()) {
if (expect_match) {
- EXPECT_TRUE(*host1->getDuid() == *host1->getDuid());
+ EXPECT_TRUE(*host1->getDuid() == *host2->getDuid());
} else {
- EXPECT_FALSE(*host1->getDuid() == *host1->getDuid());
+ EXPECT_FALSE(*host1->getDuid() == *host2->getDuid());
}
if (*host1->getDuid() != *host2->getDuid()) {
cout << host1->getDuid()->toText() << endl;
}
}
+void
+GenericHostDataSourceTest::testMultipleSubnets(int subnets, bool hwaddr) {
+
+ // Make sure we have a pointer to the host data source.
+ ASSERT_TRUE(hdsptr_);
+
+ HostPtr host = initializeHost4("192.0.2.1", hwaddr);
+
+ for (int i = 0; i < subnets; ++i) {
+ host->setIPv4SubnetID(i + 1000);
+
+ // Check that the same host can have reservations in multiple subnets.
+ EXPECT_NO_THROW(hdsptr_->add(host));
+ }
+
+ // Now check that the reservations can be retrieved by IPv4 address from
+ // each subnet separately.
+ for (int i = 0; i < subnets; ++i) {
+
+ // Try to retrieve the host by IPv4 address.
+ ConstHostPtr from_hds = hdsptr_->get4(i + 1000, host->getIPv4Reservation());
+
+ ASSERT_TRUE(from_hds);
+ EXPECT_EQ(i + 1000, from_hds->getIPv4SubnetID());
+
+ // Try to retrieve the host by either HW address of client-id
+ from_hds = hdsptr_->get4(i + 1000, host->getHWAddress(), host->getDuid());
+ ASSERT_TRUE(from_hds);
+ EXPECT_EQ(i + 1000, from_hds->getIPv4SubnetID());
+ }
+
+ // Now check that they can be retrieved all at once, by IPv4 address.
+ ConstHostCollection all_by_addr = hdsptr_->getAll4(IOAddress("192.0.2.1"));
+ ASSERT_EQ(subnets, all_by_addr.size());
+
+ // Verify that the values returned are proper.
+ int i = 0;
+ for (ConstHostCollection::const_iterator it = all_by_addr.begin();
+ it != all_by_addr.end(); ++it) {
+ EXPECT_EQ(IOAddress("192.0.2.1"), (*it)->getIPv4Reservation());
+ EXPECT_EQ(1000 + i++, (*it)->getIPv4SubnetID());
+ }
+
+ // Finally, check that the hosts can be retrived by HW address or DUID
+ ConstHostCollection all_by_id = hdsptr_->getAll(host->getHWAddress(), host->getDuid());
+ ASSERT_EQ(subnets, all_by_id.size());
+
+ // Check that the returned values are as expected.
+ i = 0;
+ for (ConstHostCollection::const_iterator it = all_by_id.begin();
+ it != all_by_id.end(); ++it) {
+ EXPECT_EQ(IOAddress("192.0.2.1"), (*it)->getIPv4Reservation());
+ EXPECT_EQ(1000 + i++, (*it)->getIPv4SubnetID());
+ }
+}
+
}; // namespace test
}; // namespace dhcp
}; // namespace isc
/// @param num number of hostnames to be added.
void testHostname(std::string name, int num);
+ /// @brief Test inserts multiple reservations for the same host for different
+ /// subnets and check that they can be retrieved properly.
+ ///
+ /// Uses gtest macros to report failures.
+ ///
+ /// @param subnets number of subnets to test
+ /// @param hwaddr true = use HW address, false = use client-id
+ void testMultipleSubnets(int subnets, bool hwaddr);
+
/// @brief Returns DUID with identical content as specified HW address
///
/// This method does not have any sense in real life and is only useful
/// check that the classes are not confused.
}
-// Test if retrieving hosts by hardware addresses is working correctly.
-TEST_F(MySqlHostDataSourceTest, uniqueHW) {
- /// @todo: Insert 100 host reservations, each with unique hardware address,
- /// try to retrieve each and make sure that the correct host is returned.
-}
-
// Test if the same host can have reservations in different subnets (with the
// same hardware address)
-TEST_F(MySqlHostDataSourceTest, MultipleSubnetsHWAddr) {
+TEST_F(MySqlHostDataSourceTest, multipleSubnetsHWAddr) {
+ testMultipleSubnets(10, true);
+
/// @todo: Insert 10 host reservations for a given physical host (the same
/// hardware address), but for different subnets (different subnet-ids).
/// Make sure that getAll() returns them all correctly.
// Test if the same host can have reservations in different subnets (with the
// same client identifier)
-TEST_F(MySqlHostDataSourceTest, MultipleSubnetsClientId) {
+TEST_F(MySqlHostDataSourceTest, multipleSubnetsClientId) {
+ testMultipleSubnets(10, false);
/// @todo: Insert 10 host reservations for a given physical host (the same
/// client-identifier), but for different subnets (different subnet-ids).
/// Make sure that getAll() returns them correctly.
}
-// Test if host reservations made for different IPv4 subnets are handled correctly.
-TEST_F(MySqlHostDataSourceTest, subnetId4) {
- /// @todo: Insert 10 host reservations for different subnets. Make sure that
- /// get4(subnet-id, ...) calls return correct reservation.
-}
-
// Test if host reservations made for different IPv6 subnets are handled correctly.
TEST_F(MySqlHostDataSourceTest, subnetId6) {
/// @todo: Insert 10 host reservations for different subnets. Make sure that