}
void
-Dhcpv4SrvTest::acquireAndDecline(const std::string& hw_address_1,
+Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
+ const std::string& hw_address_1,
const std::string& client_id_1,
const std::string& hw_address_2,
const std::string& client_id_2,
// Ok, do the normal lease aquisition.
CfgMgr::instance().clear();
- Dhcp4Client client(Dhcp4Client::SELECTING);
+
// Configure DHCP server.
configure(DECLINE_CONFIGS[0], *client.getServer());
// Explicitly set the client id.
// This test checks that the client can acquire and decline the lease.
TEST_F(DeclineTest, declineNoIdentifierChange) {
- acquireAndDecline("01:02:03:04:05:06", "12:14",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:14",
SHOULD_PASS);
}
// client identifier.
// - The server successfully declines the lease.
TEST_F(DeclineTest, declineHWAddressOnly) {
- acquireAndDecline("01:02:03:04:05:06", "",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "",
"01:02:03:04:05:06", "",
SHOULD_PASS);
}
// client identifier.
// - The server successfully declines the lease.
TEST_F(DeclineTest, declineNoClientId) {
- acquireAndDecline("01:02:03:04:05:06", "12:14",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "",
SHOULD_PASS);
}
// - The server identifies the lease using HW address and declines
// this lease.
TEST_F(DeclineTest, declineNoClientId2) {
- acquireAndDecline("01:02:03:04:05:06", "",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "",
"01:02:03:04:05:06", "12:14",
SHOULD_PASS);
}
// client identifier.
// - The server should not remove the lease.
TEST_F(DeclineTest, declineNonMatchingClientId) {
- acquireAndDecline("01:02:03:04:05:06", "12:14",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:15:16",
SHOULD_FAIL);
}
// - The server uses client identifier to find the client's lease and
// declines it.
TEST_F(DeclineTest, declineNonMatchingHWAddress) {
- acquireAndDecline("01:02:03:04:05:06", "12:14",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"06:06:06:06:06:06", "12:14",
SHOULD_PASS);
}
using Dhcpv4Srv::alloc_engine_;
};
+// We need to pass one reference to the Dhcp4Client, which is defined in
+// dhcp4_client.h. That header includes this file. To avoid circular
+// dependencies, we use forward declaration here.
+class Dhcp4Client;
+
class Dhcpv4SrvTest : public ::testing::Test {
public:
/// @brief Tests if the acquired lease is or is not declined.
///
+ /// @param client Dhcp4Client instance
/// @param hw_address_1 HW Address to be used to acquire the lease.
/// @param client_id_1 Client id to be used to acquire the lease.
/// @param hw_address_2 HW Address to be used to decline the lease.
/// @param expected_result SHOULD_PASS if the lease is expected to
/// be successfully declined, or SHOULD_FAIL if the lease is expected
/// to not be declined.
- void acquireAndDecline(const std::string& hw_address_1,
+ void acquireAndDecline(Dhcp4Client& client,
+ const std::string& hw_address_1,
const std::string& client_id_1,
const std::string& hw_address_2,
const std::string& client_id_2,
#include <config.h>
#include <dhcp4/tests/dhcp4_test_utils.h>
+#include <dhcp4/tests/dhcp4_client.h>
#include <dhcp4/json_config_parser.h>
#include <cc/command_interpreter.h>
#include <config/command_mgr.h>
"lease4_decline", lease4_decline_callout));
// Conduct the actual DORA + Decline.
- acquireAndDecline("01:02:03:04:05:06", "12:14",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:14",
SHOULD_PASS);
// Conduct the actual DORA + Decline. The DECLINE should fail, as the
// hook will set the status to DROP.
- acquireAndDecline("01:02:03:04:05:06", "12:14",
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:14",
SHOULD_FAIL);