}
}
- /// @brief Reset internal counters for a specific origin.
+ /// @brief Reset internal counters for a database connection origin.
///
/// @note The dhcp service will remain disabled until all flags are cleared.
- ///
- /// @param origin The origin of the state transition.
- void reset(unsigned int origin) {
- if (origin == NetworkState::DB_CONNECTION) {
- disabled_by_db_connection_ = 0;
- } else {
- disabled_by_origin_.erase(origin);
- }
- // Enable the service only if all flags have been cleared.
- if (disabled_by_origin_.empty() && disabled_by_db_connection_ == 0) {
+ void resetForDbConnection() {
+ disabled_by_db_connection_ = 0;
+ if (disabled_by_origin_.empty()) {
globally_disabled_ = false;
}
}
- /// @brief Enables DHCP service globally and per scopes.
+ /// @brief Enables DHCP service for an origin.
///
/// If delayed enabling DHCP service has been scheduled, it cancels it.
///
/// @param origin The origin of the state transition.
- void enableAll(unsigned int origin) {
+ void delayedEnable(unsigned int origin) {
setDisableService(false, origin);
-
- /// @todo Enable service for all subnets and networks here.
-
destroyTimer(origin);
}
- /// @brief Creates a timer counting the time when @c enableAll should be
+ /// @brief Creates a timer counting the time when @c delayedEnable should be
/// automatically called.
///
/// If the timer has been already scheduled, it is destroyed and replaced
/// with a new timer.
///
- /// @param seconds Number of seconds to elapse before the @c enableAll is
+ /// @param seconds Number of seconds to elapse before the @c delayedEnable is
/// called.
/// @param origin The origin of the state transition.
void createTimer(const unsigned int seconds, unsigned int origin) {
}
auto timer_name = getTimerName(origin);
timer_mgr_->registerTimer(timer_name,
- std::bind(&NetworkStateImpl::enableAll,
+ std::bind(&NetworkStateImpl::delayedEnable,
shared_from_this(), origin),
seconds * 1000,
asiolink::IntervalTimer::ONE_SHOT);
NetworkState::enableService(unsigned int origin) {
if (MultiThreadingMgr::instance().getMode()) {
std::lock_guard<std::mutex> lk(*mutex_);
- impl_->setDisableService(false, origin);
- } else {
- impl_->setDisableService(false, origin);
- }
-}
-
-void
-NetworkState::reset(unsigned int origin) {
- if (MultiThreadingMgr::instance().getMode()) {
- std::lock_guard<std::mutex> lk(*mutex_);
- impl_->reset(origin);
+ impl_->delayedEnable(origin);
} else {
- impl_->reset(origin);
+ impl_->delayedEnable(origin);
}
}
void
-NetworkState::enableAll(unsigned int origin) {
+NetworkState::resetForDbConnection() {
if (MultiThreadingMgr::instance().getMode()) {
std::lock_guard<std::mutex> lk(*mutex_);
- impl_->enableAll(origin);
+ impl_->resetForDbConnection();
} else {
- impl_->enableAll(origin);
+ impl_->resetForDbConnection();
}
}
void
-NetworkState::delayedEnableAll(const unsigned int seconds, unsigned int origin) {
+NetworkState::delayedEnableService(const unsigned int seconds, unsigned int origin) {
if (MultiThreadingMgr::instance().getMode()) {
std::lock_guard<std::mutex> lk(*mutex_);
impl_->createTimer(seconds, origin);
}
bool
-NetworkState::isDelayedEnableAll() const {
+NetworkState::isDelayedEnableService() const {
for (auto origin : impl_->disabled_by_origin_) {
if (TimerMgr::instance()->isTimerRegistered(impl_->getTimerName(origin))) {
return (true);
/// 8. Reset using 'DB connection' origin (expect enabled state).
void resetUsingDBConnectionOriginTest();
- /// @brief This test verifies that enableAll() enables the service. This test will be
- /// extended in the future to verify that it also enables disabled scopes.
- void enableAllTest();
-
/// @brief This test verifies that it is possible to setup delayed execution of enableAll
/// function.
- void delayedEnableAllTest();
+ void delayedEnableServiceTest();
/// @brief This test verifies that explicitly enabling the service cancels the timer
/// scheduled for automatically enabling it.
- void earlyEnableAllTest();
+ void earlyEnableServiceTest();
- /// @brief This test verifies that it is possible to call delayedEnableAll multiple times
+ /// @brief This test verifies that it is possible to call delayedEnableService multiple times
/// and that it results in only one timer being scheduled.
- void multipleDelayedEnableAllTest();
+ void multipleDelayedEnableServiceTest();
- /// @brief This test verifies that it is possible to call delayedEnableAll multiple times
+ /// @brief This test verifies that it is possible to call delayedEnableService multiple times
/// from different origins and that it results in each timer being scheduled.
- void multipleDifferentOriginsDelayedEnableAllTest();
+ void multipleDifferentOriginsDelayedEnableServiceTest();
/// @brief Runs IO service with a timeout.
///
EXPECT_FALSE(state.isServiceEnabled());
state.disableService(NetworkState::DB_CONNECTION);
EXPECT_FALSE(state.isServiceEnabled());
- state.reset(NetworkState::USER_COMMAND);
+ state.enableService(NetworkState::USER_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
state.enableService(NetworkState::HA_LOCAL_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
EXPECT_FALSE(state.isServiceEnabled());
state.disableService(NetworkState::USER_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
- state.reset(NetworkState::USER_COMMAND);
+ state.enableService(NetworkState::USER_COMMAND);
EXPECT_TRUE(state.isServiceEnabled());
}
// 1. Disable using 'user command' origin 1 time (expect disabled state).
// 2. Disable using 'HA command' origin 3 times (expect disabled state).
// 3. Disable using 'DB connection' origin 1 time (expect disabled state).
-// 4. Reset using 'HA command' origin (expect disabled state).
+// 4. Enable using 'HA command' origin (expect disabled state).
// 5. Enable using 'user command' origin 1 time (expect disabled state).
// 6. Enable using 'DB connection' origin 1 time (expect enabled state).
// 7. Disable using 'HA command' origin 3 times (expect disabled state).
-// 8. Reset using 'HA command' origin (expect enabled state).
+// 8. Enable using 'HA command' origin (expect enabled state).
void
NetworkStateTest::resetUsingHACommandOriginTest() {
NetworkState state(NetworkState::DHCPv4);
EXPECT_FALSE(state.isServiceEnabled());
state.disableService(NetworkState::DB_CONNECTION);
EXPECT_FALSE(state.isServiceEnabled());
- state.reset(NetworkState::HA_LOCAL_COMMAND);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
state.enableService(NetworkState::USER_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
EXPECT_FALSE(state.isServiceEnabled());
state.disableService(NetworkState::HA_LOCAL_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
- state.reset(NetworkState::HA_LOCAL_COMMAND);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
EXPECT_TRUE(state.isServiceEnabled());
}
EXPECT_FALSE(state.isServiceEnabled());
state.disableService(NetworkState::DB_CONNECTION);
EXPECT_FALSE(state.isServiceEnabled());
- state.reset(NetworkState::DB_CONNECTION);
+ state.resetForDbConnection();
EXPECT_FALSE(state.isServiceEnabled());
state.enableService(NetworkState::USER_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
EXPECT_FALSE(state.isServiceEnabled());
state.disableService(NetworkState::DB_CONNECTION);
EXPECT_FALSE(state.isServiceEnabled());
- state.reset(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
-}
-
-// This test verifies that enableAll() enables the service. This test will be
-// extended in the future to verify that it also enables disabled scopes.
-void
-NetworkStateTest::enableAllTest() {
- NetworkState state(NetworkState::DHCPv4);
- state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableAll(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
- state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableAll(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
- state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableAll(NetworkState::DB_CONNECTION);
+ state.resetForDbConnection();
EXPECT_TRUE(state.isServiceEnabled());
}
// This test verifies that it is possible to setup delayed execution of enableAll
// function.
void
-NetworkStateTest::delayedEnableAllTest() {
+NetworkStateTest::delayedEnableServiceTest() {
NetworkState state(NetworkState::DHCPv4);
// Disable the service and then schedule enabling it in 1 second.
state.disableService(NetworkState::USER_COMMAND);
- state.delayedEnableAll(1, NetworkState::USER_COMMAND);
+ state.delayedEnableService(1, NetworkState::USER_COMMAND);
// Initially the service should be still disabled.
EXPECT_FALSE(state.isServiceEnabled());
// After running IO service for 2 seconds, the service should be enabled.
EXPECT_TRUE(state.isServiceEnabled());
// Disable the service and then schedule enabling it in 1 second.
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- state.delayedEnableAll(1, NetworkState::HA_LOCAL_COMMAND);
+ state.delayedEnableService(1, NetworkState::HA_LOCAL_COMMAND);
// Initially the service should be still disabled.
EXPECT_FALSE(state.isServiceEnabled());
// After running IO service for 2 seconds, the service should be enabled.
EXPECT_TRUE(state.isServiceEnabled());
// Disable the service and then schedule enabling it in 1 second.
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_THROW(state.delayedEnableAll(1, NetworkState::DB_CONNECTION), BadValue);
+ EXPECT_THROW(state.delayedEnableService(1, NetworkState::DB_CONNECTION), BadValue);
}
// This test verifies that explicitly enabling the service cancels the timer
// scheduled for automatically enabling it.
void
-NetworkStateTest::earlyEnableAllTest() {
+NetworkStateTest::earlyEnableServiceTest() {
NetworkState state(NetworkState::DHCPv4);
// Disable the service.
state.disableService(NetworkState::USER_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
// Schedule enabling the service in 2 seconds.
- state.delayedEnableAll(2, NetworkState::USER_COMMAND);
+ state.delayedEnableService(10, NetworkState::USER_COMMAND);
// Explicitly enable the service.
- state.enableAll(NetworkState::USER_COMMAND);
+ state.enableService(NetworkState::USER_COMMAND);
// The timer should be now canceled and the service should be enabled.
- EXPECT_FALSE(state.isDelayedEnableAll());
+ EXPECT_FALSE(state.isDelayedEnableService());
EXPECT_TRUE(state.isServiceEnabled());
}
-// This test verifies that it is possible to call delayedEnableAll multiple times
+// This test verifies that it is possible to call delayedEnableService multiple times
// and that it results in only one timer being scheduled.
void
-NetworkStateTest::multipleDelayedEnableAllTest() {
+NetworkStateTest::multipleDelayedEnableServiceTest() {
NetworkState state(NetworkState::DHCPv4);
// Disable the service and then schedule enabling it in 5 second.
state.disableService(NetworkState::USER_COMMAND);
// Schedule the first timer for 5 seconds.
- state.delayedEnableAll(5, NetworkState::USER_COMMAND);
+ state.delayedEnableService(5, NetworkState::USER_COMMAND);
// When calling it the second time the old timer should be destroyed and
// the timeout should be set to 2 seconds.
- state.delayedEnableAll(2, NetworkState::USER_COMMAND);
+ state.delayedEnableService(2, NetworkState::USER_COMMAND);
// Initially the service should be still disabled.
EXPECT_FALSE(state.isServiceEnabled());
// After running IO service for 3 seconds, the service should be enabled.
EXPECT_TRUE(state.isServiceEnabled());
// The timer should not be present, even though the first timer was created
// with 5 seconds interval.
- EXPECT_FALSE(state.isDelayedEnableAll());
+ EXPECT_FALSE(state.isDelayedEnableService());
}
-// This test verifies that it is possible to call delayedEnableAll multiple times
+// This test verifies that it is possible to call delayedEnableService multiple times
// from different origins and that it results in each timer being scheduled.
void
-NetworkStateTest::multipleDifferentOriginsDelayedEnableAllTest() {
+NetworkStateTest::multipleDifferentOriginsDelayedEnableServiceTest() {
NetworkState state(NetworkState::DHCPv4);
// Disable the service and then schedule enabling it in 5 second.
state.disableService(NetworkState::HA_LOCAL_COMMAND);
// Disable the service and then schedule enabling it in 2 second.
state.disableService(NetworkState::USER_COMMAND);
// Schedule the first timer for 5 seconds.
- state.delayedEnableAll(5, NetworkState::HA_LOCAL_COMMAND);
+ state.delayedEnableService(5, NetworkState::HA_LOCAL_COMMAND);
// When calling it the second time the old timer should not be destroyed and
// the new timeout should be set to 2 seconds.
- state.delayedEnableAll(2, NetworkState::USER_COMMAND);
+ state.delayedEnableService(2, NetworkState::USER_COMMAND);
// Initially the service should be still disabled.
EXPECT_FALSE(state.isServiceEnabled());
// After running IO service for 3 seconds, the service should not be enabled.
EXPECT_FALSE(state.isServiceEnabled());
// The timer should be present, because the first timer was created with 5
// seconds interval.
- EXPECT_TRUE(state.isDelayedEnableAll());
+ EXPECT_TRUE(state.isDelayedEnableService());
// After running IO service for 3 seconds, the service should be enabled.
runIOService(3000);
EXPECT_TRUE(state.isServiceEnabled());
// The timer should not be present, because the first timer was created with
// 5 seconds interval.
- EXPECT_FALSE(state.isDelayedEnableAll());
+ EXPECT_FALSE(state.isDelayedEnableService());
}
// Test invocations.
resetUsingHACommandOriginTest();
}
-TEST_F(NetworkStateTest, enableAllTest) {
- enableAllTest();
-}
-
-TEST_F(NetworkStateTest, enableAllTestMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
- enableAllTest();
-}
-
-TEST_F(NetworkStateTest, delayedEnableAllTest) {
- delayedEnableAllTest();
+TEST_F(NetworkStateTest, delayedEnableServiceTest) {
+ delayedEnableServiceTest();
}
TEST_F(NetworkStateTest, delayedEnableAllTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- delayedEnableAllTest();
+ delayedEnableServiceTest();
}
-TEST_F(NetworkStateTest, earlyEnableAllTest) {
- earlyEnableAllTest();
+TEST_F(NetworkStateTest, earlyEnableServiceTest) {
+ earlyEnableServiceTest();
}
-TEST_F(NetworkStateTest, earlyEnableAllTestMultiThreading) {
+TEST_F(NetworkStateTest, earlyEnableServiceTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- earlyEnableAllTest();
+ earlyEnableServiceTest();
}
-TEST_F(NetworkStateTest, multipleDelayedEnableAllTest) {
- multipleDelayedEnableAllTest();
+TEST_F(NetworkStateTest, multipleDelayedEnableServiceTest) {
+ multipleDelayedEnableServiceTest();
}
-TEST_F(NetworkStateTest, multipleDelayedEnableAllTestMultiThreading) {
+TEST_F(NetworkStateTest, multipleDelayedEnableServiceTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- multipleDelayedEnableAllTest();
+ multipleDelayedEnableServiceTest();
}
-TEST_F(NetworkStateTest, multipleDifferentOriginsDelayedEnableAllTest) {
- multipleDifferentOriginsDelayedEnableAllTest();
+TEST_F(NetworkStateTest, multipleDifferentOriginsDelayedEnableServiceTest) {
+ multipleDifferentOriginsDelayedEnableServiceTest();
}
-TEST_F(NetworkStateTest, multipleDifferentOriginsDelayedEnableAllTestMultiThreading) {
+TEST_F(NetworkStateTest, multipleDifferentOriginsDelayedEnableServiceTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- multipleDifferentOriginsDelayedEnableAllTest();
+ multipleDifferentOriginsDelayedEnableServiceTest();
}
} // end of anonymous namespace