/// the two peers. If the connection is lost it is an indicator that
/// the partner server may be down and failover actions should be triggered.
///
-/// Any command successfully sent over the control channel is an indicator
-/// that the connection is healthy. The most common command sent over the
-/// control channel is a lease update. If the DHCP traffic is heavy, the
-/// number of generated lease updates is sufficient to determine whether
-/// the connection is healthy or not. There is no need to send heartbeat
-/// commands in this case. However, if the DHCP traffic is low there is
-/// a need to send heartbeat commands to the partner at the specified
-/// rate to keep up-to-date information about the state of the connection.
+/// A heartbeat command successfully sent over the control channel is an
+/// indicator that the connection is healthy. A reply to the heartbeat
+/// command includes information about the recipient state, its notion of
+/// time, and other information useful for determining its health and
+/// current activity.
///
/// This class uses an interval timer to run heartbeat commands over the
/// control channel. The implementation of the heartbeat is external to
/// this class and is provided via @c CommunicationState::startHeartbeat
/// method. This implementation is required to run the @c poke method
/// in case of receiving a successful response to the heartbeat command.
-/// It must also run @c poke when the lease update is successful.
///
/// The @c poke method sets the "last poke time" to current time, thus
/// indicating that the connection is healthy. The @c getDurationInMillisecs
/// the partner is online or offline.
///
/// @param unpark_handler a function called when packet is unparked.
- /// @param should_pass indicates if the update is expected to be successful.
+ /// @param should_fail indicates if the update is expected to be unsuccessful.
/// @param num_updates expected number of servers to which lease updates are
/// sent.
/// @param my_state state of the server while lease updates are sent.
/// @param wait_backup_ack indicates if the server should wait for the acknowledgment
/// from the backup servers.
void testSendLeaseUpdates(std::function<void()> unpark_handler,
- const bool should_pass,
+ const bool should_fail,
const size_t num_updates,
const MyState& my_state = MyState(HA_LOAD_BALANCING_ST),
const bool wait_backup_ack = false) {
// an acknowledgment.
EXPECT_EQ(2 * num_updates, service_->getPendingRequest(query));
- EXPECT_FALSE(state->isPoked());
-
// Let's park the packet and associate it with the callback function which
// simply records the fact that it has been called. We expect that it wasn't
// because the parked packet should be dropped as a result of lease updates
// The updates should not be sent to this server.
EXPECT_TRUE(factory_->getResponseCreator()->getReceivedRequests().empty());
- if (should_pass) {
- EXPECT_TRUE(state->isPoked());
- } else {
- EXPECT_FALSE(state->isPoked());
+ if (should_fail) {
+ EXPECT_EQ(HA_UNAVAILABLE_ST, state->getPartnerState());
}
}
/// the partner is online or offline.
///
/// @param unpark_handler a function called when packet is unparked.
- /// @param should_pass indicates if the update is expected to be successful.
+ /// @param should_fail indicates if the update is expected to be unsuccessful.
/// @param num_updates expected number of servers to which lease updates are
/// sent.
/// @param my_state state of the server while lease updates are sent.
/// @param wait_backup_ack indicates if the server should wait for the acknowledgment
/// from the backup servers.
void testSendLeaseUpdates6(std::function<void()> unpark_handler,
- const bool should_pass,
+ const bool should_fail,
const size_t num_updates,
const MyState& my_state = MyState(HA_LOAD_BALANCING_ST),
const bool wait_backup_ack = false) {
// The updates should not be sent to this server.
EXPECT_TRUE(factory_->getResponseCreator()->getReceivedRequests().empty());
- if (should_pass) {
- EXPECT_TRUE(state->isPoked());
- } else {
- EXPECT_FALSE(state->isPoked());
+ if (should_fail) {
+ EXPECT_EQ(HA_UNAVAILABLE_ST, state->getPartnerState());
}
}
// This flag will be set to true if unpark is called.
bool unpark_called = false;
testSendLeaseUpdates([&unpark_called] { unpark_called = true; },
- true, 1);
+ false, 1);
// Expecting that the packet was unparked because lease
// updates are expected to be successful.
testSendLeaseUpdates([] {
ADD_FAILURE() << "unpark function called but expected that "
"the packet is dropped";
- }, false, 1);
+ }, true, 1);
// Server 2 should not receive lease4-update.
auto update_request2 =
testSendLeaseUpdates([] {
ADD_FAILURE() << "unpark function called but expected that "
"the packet is dropped";
- }, false, 1);
+ }, true, 1);
// The updates should be sent to server 2 and this server should
// return error code.
testSendLeaseUpdates([] {
ADD_FAILURE() << "unpark function called but expected that "
"the packet is dropped";
- }, false, 1);
+ }, true, 1);
// The updates should be sent to server 2 and this server should
// return error code.
bool unpark_called = false;
testSendLeaseUpdates([&unpark_called] { unpark_called = true; },
- true, 1);
+ false, 1);
EXPECT_TRUE(unpark_called);
// This flag will be set to true if unpark is called.
bool unpark_called = false;
testSendLeaseUpdates6([&unpark_called] { unpark_called = true; },
- true, 1);
+ false, 1);
// Expecting that the packet was unparked because lease
// updates are expected to be successful.
testSendLeaseUpdates6([] {
ADD_FAILURE() << "unpark function called but expected that "
"the packet is dropped";
- }, false, 1);
+ }, true, 1);
// Server 2 should not receive lease6-bulk-apply.
auto update_request2 =
bool unpark_called = false;
testSendLeaseUpdates6([&unpark_called] { unpark_called = true; },
- true, 1);
+ false, 1);
EXPECT_TRUE(unpark_called);
testSendLeaseUpdates6([] {
ADD_FAILURE() << "unpark function called but expected that "
"the packet is dropped";
- }, false, 1);
+ }, true, 1);
// The updates should be sent to server 2 and this server should return error code.
EXPECT_EQ(1, factory2_->getResponseCreator()->getReceivedRequests().size());
testSendLeaseUpdates6([] {
ADD_FAILURE() << "unpark function called but expected that "
"the packet is dropped";
- }, false, 1);
+ }, true, 1);
// The updates should be sent to server 2 and this server should return error code.
EXPECT_TRUE(factory2_->getResponseCreator()->getReceivedRequests().empty());
// This flag will be set to true if unpark is called.
bool unpark_called = false;
testSendLeaseUpdates6([&unpark_called] { unpark_called = true; },
- true, 1);
+ false, 1);
// Expecting that the packet was unparked because lease
// updates are expected to be successful.