-// Copyright (C) 2017-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
using namespace isc::dhcp;
using namespace isc::util;
-namespace {
+namespace {
/// @brief Test fixture class for @c NetworkState class.
class NetworkStateTest : public ::testing::Test {
/// @brief This test verifies the default is enable state.
void defaultTest();
- /// @brief This test verifies that it is possible to disable and then enable DHCPv4
+ /// @brief This test verifies that it is possible to disable and then enable
/// service using 'user command' origin.
- void disableEnableService4UsingUserCommandOriginTest();
+ void disableEnableServiceUsingUserCommandOriginTest();
- /// @brief This test verifies that it is possible to disable and then enable DHCPv4
- /// service using 'HA command' origin.
- void disableEnableService4UsingHACommandOriginTest();
+ /// @brief This test verifies that it is possible to disable and then enable
+ /// service using 'HA local command' origin.
+ void disableEnableServiceUsingHALocalCommandOriginTest();
- /// @brief This test verifies that it is possible to disable and then enable DHCPv4
- /// service using 'DB connection' origin.
- void disableEnableService4UsingDBConnectionOriginTest();
+ /// @brief This test verifies that it is possible to disable and then enable
+ /// service using 'HA remote command' origin.
+ void disableEnableServiceUsingHARemoteCommandOriginTest();
- /// @brief This test verifies that it is possible to disable and then enable DHCPv4
- /// service using a combination of origins.
- /// 1. Disable using 'user command' origin 2 times (expect disabled state).
- /// 2. Disable using 'HA command' origin 2 times (expect disabled state).
- /// 3. Disable using 'DB connection' origin 2 times (expect disabled state).
- /// 4. Enable using 'user command' origin 1 time (expect disabled state).
- /// 5. Enable using 'HA command' origin 1 time (expect disabled state).
- /// 6. Enable using 'DB connection' origin 2 times (expect enabled state).
- void disableEnableService4UsingMultipleOriginsTest();
-
- /// @brief This test verifies that it is possible to disable and then enable DHCPv6
- /// service using 'user command' origin.
- void disableEnableService6UsingUserCommandOriginTest();
-
- /// @brief This test verifies that it is possible to disable and then enable DHCPv6
- /// service using 'HA command' origin.
- void disableEnableService6UsingHACommandOriginTest();
-
- /// @brief This test verifies that it is possible to disable and then enable DHCPv6
+ /// @brief This test verifies that it is possible to disable and then enable
/// service using 'DB connection' origin.
- void disableEnableService6UsingDBConnectionOriginTest();
+ void disableEnableServiceUsingDBConnectionOriginTest();
- /// @brief This test verifies that it is possible to disable and then enable DHCPv6
+ /// @brief This test verifies that it is possible to disable and then enable
/// service using a combination of origins.
- /// 1. Disable using 'user command' origin 2 times (expect disabled state).
- /// 2. Disable using 'HA command' origin 2 times (expect disabled state).
- /// 3. Disable using 'DB connection' origin 2 times (expect disabled state).
- /// 4. Enable using 'user command' origin 1 time (expect disabled state).
- /// 5. Enable using 'HA command' origin 1 time (expect disabled state).
- /// 6. Enable using 'DB connection' origin 2 times (expect enabled state).
- void disableEnableService6UsingMultipleOriginsTest();
+ // 1. Disable using 'user command' origin 2 times (expect disabled state).
+ // 2. Disable using 'HA local command' origin 2 times (expect disabled state).
+ // 3. Disable using 'HA local command' origin 1 time different id (expect disabled state).
+ // 4. Disable using 'HA remote command' origin 2 times (expect disabled state).
+ // 5. Disable using 'HA remote command' origin 1 time different id (expect disabled state).
+ // 6. Disable using 'DB connection' origin 2 times (expect disabled state).
+ // 7. Disable using 'DB connection' origin 1 time different id (expect disabled state).
+ // 8. Enable using 'user command' origin 1 time (expect disabled state).
+ // 9. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 10. Enable using 'HA local command' origin 1 time different id (expect disabled state).
+ // 11. Enable using 'HA remote command' origin 1 time (expect disabled state).
+ // 12. Enable using 'HA remote command' origin 1 time different id (expect disabled state).
+ // 13. Enable using 'DB connection' origin 1 times (expect disabled state).
+ // 14. Enable using 'DB connection' origin 1 time different id (expect disabled state).
+ void disableEnableServiceUsingMultipleOriginsTest();
/// @brief This test verifies that reset works, so that internal state is reset after
/// all managers are recreated.
/// @brief This test verifies that reset works, so that internal state is reset after
/// all managers are recreated.
- /// 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).
- /// 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).
- void resetUsingHACommandOriginTest();
+ // 1. Disable using 'user command' origin 1 time (expect disabled state).
+ // 2. Disable using 'HA local command' origin 3 times with same id (expect disabled state).
+ // 3. Disable using 'DB connection' origin 1 time (expect disabled state).
+ // 4. Disable using 'HA remote command' origin 1 time (expect disabled state).
+ // 5. Enable using 'HA local command' origin (expect disabled state).
+ // 6. Enable using 'user command' origin 1 time (expect disabled state).
+ // 7. Enable using 'HA remote command' origin 1 time (expect disabled state).
+ // 8. Enable using 'DB connection' origin 1 time (expect enabled state).
+ // 9. Disable using 'user command' origin 1 time (expect disabled state).
+ // 10. Disable using 'HA local command' origin 3 times with different ids (expect disabled state).
+ // 11. Disable using 'DB connection' origin 1 time (expect disabled state).
+ // 12. Disable using 'HA remote command' origin 1 time (expect disabled state).
+ // 13. Enable using 'user command' origin 1 time (expect disabled state).
+ // 14. Enable using 'HA remote command' origin 1 time (expect disabled state).
+ // 15. Enable using 'DB connection' origin 1 time (expect disabled state).
+ // 16. Enable using 'HA local command' origin 3 times with different ids (expect enabled state).
+ // 17. Disable using 'user command' origin 1 time (expect disabled state).
+ // 18. Disable using 'HA local command' origin 3 times with different ids (expect disabled state).
+ // 19. Disable using 'DB connection' origin 1 time (expect disabled state).
+ // 20. Disable using 'HA remote command' origin 1 time (expect disabled state).
+ // 21. Enable using 'user command' origin 1 time (expect disabled state).
+ // 22. Enable using 'HA remote command' origin 1 time (expect disabled state).
+ // 23. Enable using 'DB connection' origin 1 time (expect disabled state).
+ // 24. Reset using 'HA local command' origin (expect enabled state).
+ // 25. Disable using 'HA local command' origin 3 times (expect disabled state).
+ // 26. Enable using 'HA local command' origin (expect enabled state).
+ void resetUsingHALocalCommandOriginTest();
/// @brief This test verifies that reset works, so that internal state is reset after
/// all managers are recreated.
- /// 1. Disable using 'user command' origin 1 time (expect disabled state).
- /// 2. Disable using 'HA command' origin 1 time (expect disabled state).
- /// 3. Disable using 'DB connection' origin 3 time (expect disabled state).
- /// 4. Reset using 'DB connection' 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 'DB connection' origin 3 times (expect disabled state).
- /// 8. Reset using 'DB connection' origin (expect enabled state).
+ // 1. Disable using 'user command' origin 1 time (expect disabled state).
+ // 2. Disable using 'HA remote command' origin 3 times with same id (expect disabled state).
+ // 3. Disable using 'DB connection' origin 1 time (expect disabled state).
+ // 4. Disable using 'HA local command' origin 1 time (expect disabled state).
+ // 5. Enable using 'HA remote command' origin (expect disabled state).
+ // 6. Enable using 'user command' origin 1 time (expect disabled state).
+ // 7. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 8. Enable using 'DB connection' origin 1 time (expect enabled state).
+ // 9. Disable using 'user command' origin 1 time (expect disabled state).
+ // 10. Disable using 'HA remote command' origin 3 times with different ids (expect disabled state).
+ // 11. Disable using 'DB connection' origin 1 time (expect disabled state).
+ // 12. Disable using 'HA local command' origin 1 time (expect disabled state).
+ // 13. Enable using 'user command' origin 1 time (expect disabled state).
+ // 14. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 15. Enable using 'DB connection' origin 1 time (expect disabled state).
+ // 16. Enable using 'HA remote command' origin 3 times with different ids (expect enabled state).
+ // 17. Disable using 'user command' origin 1 time (expect disabled state).
+ // 18. Disable using 'HA remote command' origin 3 times with different ids (expect disabled state).
+ // 19. Disable using 'DB connection' origin 1 time (expect disabled state).
+ // 20. Disable using 'HA local command' origin 1 time (expect disabled state).
+ // 21. Enable using 'user command' origin 1 time (expect disabled state).
+ // 22. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 23. Enable using 'DB connection' origin 1 time (expect disabled state).
+ // 24. Reset using 'HA remote command' origin (expect enabled state).
+ // 25. Disable using 'HA remote command' origin 3 times (expect disabled state).
+ // 26. Enable using 'HA remote command' origin (expect enabled state).
+ void resetUsingHARemoteCommandOriginTest();
+
+ /// @brief This test verifies that reset works, so that internal state is reset after
+ /// all managers are recreated.
+ // 1. Disable using 'user command' origin 1 time (expect disabled state).
+ // 2. Disable using 'DB connection' origin 3 times with same id (expect disabled state).
+ // 3. Disable using 'HA remote command' origin 1 time (expect disabled state).
+ // 4. Disable using 'HA local command' origin 1 time (expect disabled state).
+ // 5. Enable using 'DB connection' origin (expect disabled state).
+ // 6. Enable using 'user command' origin 1 time (expect disabled state).
+ // 7. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 8. Enable using 'HA remote command' origin 1 time (expect enabled state).
+ // 9. Disable using 'user command' origin 1 time (expect disabled state).
+ // 10. Disable using 'DB connection' origin 3 times with different ids (expect disabled state).
+ // 11. Disable using 'HA remote command' origin 1 time (expect disabled state).
+ // 12. Disable using 'HA local command' origin 1 time (expect disabled state).
+ // 13. Enable using 'user command' origin 1 time (expect disabled state).
+ // 14. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 15. Enable using 'HA remote command' origin 1 time (expect disabled state).
+ // 16. Enable using 'DB connection' origin 3 times with different ids (expect enabled state).
+ // 17. Disable using 'user command' origin 1 time (expect disabled state).
+ // 18. Disable using 'DB connection' origin 3 times with different ids (expect disabled state).
+ // 19. Disable using 'HA remote command' origin 1 time (expect disabled state).
+ // 20. Disable using 'HA local command' origin 1 time (expect disabled state).
+ // 21. Enable using 'user command' origin 1 time (expect disabled state).
+ // 22. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 23. Enable using 'HA remote command' origin 1 time (expect disabled state).
+ // 24. Reset using 'DB connection' origin (expect enabled state).
+ // 25. Disable using 'DB connection' origin 3 times (expect disabled state).
+ // 26. Enable using 'DB connection' origin (expect enabled state).
void resetUsingDBConnectionOriginTest();
/// @brief This test verifies that it is possible to setup delayed execution of enableAll
io_service_->poll();
}
+ /// @brief Check network state.
+ ///
+ /// @brief state The network state to check.
+ /// @brief user Flag which indicates if user command disabled the state.
+ /// @brief local The list of local IDs which disabled the state.
+ /// @brief remote The list of remote IDs which disabled the state.
+ /// @brief db The list of manager IDs which disabled the state because of a
+ /// db connection failure.
+ /// @brief global Flag which indicates if the state is disabled.
+ void checkNetworkState(const NetworkState& state,
+ bool user,
+ std::vector<uint32_t> local,
+ std::vector<uint32_t> remote,
+ std::vector<uint32_t> db,
+ bool global) {
+ std::ostringstream data;
+ data << std::boolalpha;
+ data << "{ \"disabled-by-db-connection\": [ ";
+ bool not_first = false;
+ for (auto const value : db) {
+ if (not_first) {
+ data << ", ";
+ }
+ data << value;
+ not_first = true;
+ }
+ data << " ], \"disabled-by-local-command\": [ ";
+ not_first = false;
+ for (auto const value : local) {
+ if (not_first) {
+ data << ", ";
+ }
+ data << value;
+ not_first = true;
+ }
+ data << " ], \"disabled-by-remote-command\": [ ";
+ not_first = false;
+ for (auto const value : remote) {
+ if (not_first) {
+ data << ", ";
+ }
+ data << value;
+ not_first = true;
+ }
+ data << " ], \"disabled-by-user\": " << user
+ << ", \"globally-disabled\": " << global
+ << " }";
+ auto const& expected = data.str();
+ auto const& actual = state.toElement()->str();
+ EXPECT_EQ(expected, actual);
+ EXPECT_EQ(!global, state.isServiceEnabled());
+ }
+
/// @brief IO service used during the tests.
IOServicePtr io_service_;
};
// This test verifies the default is enable state.
void
NetworkStateTest::defaultTest() {
- NetworkState state4(NetworkState::DHCPv4);
- EXPECT_TRUE(state4.isServiceEnabled());
- NetworkState state6(NetworkState::DHCPv6);
- EXPECT_TRUE(state6.isServiceEnabled());
+ NetworkState state;
+
+ checkNetworkState(state, false, {}, {}, {}, false);
}
-// This test verifies that it is possible to disable and then enable DHCPv4
+// This test verifies that it is possible to disable and then enable
// service using 'user command' origin.
void
-NetworkStateTest::disableEnableService4UsingUserCommandOriginTest() {
- NetworkState state(NetworkState::DHCPv4);
+NetworkStateTest::disableEnableServiceUsingUserCommandOriginTest() {
+ NetworkState state;
// Test that enable/disable using 'user command' origin works
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
// Test that using 'user command' origin does not use internal counter
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
}
-// This test verifies that it is possible to disable and then enable DHCPv4
-// service using 'HA command' origin.
+// This test verifies that it is possible to disable and then enable
+// service using 'HA local command' origin.
void
-NetworkStateTest::disableEnableService4UsingHACommandOriginTest() {
- NetworkState state(NetworkState::DHCPv4);
+NetworkStateTest::disableEnableServiceUsingHALocalCommandOriginTest() {
+ NetworkState state;
- // Test that enable/disable using 'HA command' origin works
+ // Test that enable/disable using 'HA local command' origin works
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000 }, {}, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
- // Test that using 'HA command' origin does not use internal counter
+ // Test that using 'HA local command' origin does not use internal counter
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000 }, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000 }, {}, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
-}
+ checkNetworkState(state, false, {}, {}, {}, false);
-// This test verifies that it is possible to disable and then enable DHCPv4
-// service using 'DB connection' origin.
-void
-NetworkStateTest::disableEnableService4UsingDBConnectionOriginTest() {
- NetworkState state(NetworkState::DHCPv4);
-
- // Test that enable/disable using 'DB connection' origin works
- state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
-
- // Test that using 'DB connection' origin uses internal counter
- state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
- state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
-}
-
-// This test verifies that it is possible to disable and then enable DHCPv4
-// service using a combination of origins.
-// 1. Disable using 'user command' origin 2 times (expect disabled state).
-// 2. Disable using 'HA command' origin 2 times (expect disabled state).
-// 3. Disable using 'DB connection' origin 2 times (expect disabled state).
-// 4. Enable using 'user command' origin 1 time (expect disabled state).
-// 5. Enable using 'HA command' origin 1 time (expect disabled state).
-// 6. Enable using 'DB connection' origin 2 times (expect enabled state).
-void
-NetworkStateTest::disableEnableService4UsingMultipleOriginsTest() {
- NetworkState state(NetworkState::DHCPv4);
-
- // Test that a combination properly affects the state
- state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ // Test that using 'HA local command' origin does consider id
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, { 1000, 1001 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, false, { 1000, 1001, 1002 }, {}, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1001, 1002 }, {}, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, { 1002 }, {}, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, false, {}, {}, {}, false);
}
-// This test verifies that it is possible to disable and then enable DHCPv6
-// service using 'user command' origin.
+// This test verifies that it is possible to disable and then enable
+// service using 'HA remote command' origin.
void
-NetworkStateTest::disableEnableService6UsingUserCommandOriginTest() {
- NetworkState state(NetworkState::DHCPv6);
-
- // Test that enable/disable using 'user command' origin works
- state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
-
- // Test that using 'user command' origin does not use internal counter
- state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
- state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+NetworkStateTest::disableEnableServiceUsingHARemoteCommandOriginTest() {
+ NetworkState state;
+
+ // Test that enable/disable using 'HA remote command' origin works
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test that using 'HA remote command' origin does not use internal counter
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, {}, false);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test that using 'HA remote command' origin does consider id
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, {}, { 2000, 2001 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, false, {}, { 2000, 2001, 2002 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2001, 2002 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, {}, { 2002 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, false, {}, {}, {}, false);
}
-// This test verifies that it is possible to disable and then enable DHCPv6
-// service using 'HA command' origin.
-void
-NetworkStateTest::disableEnableService6UsingHACommandOriginTest() {
- NetworkState state(NetworkState::DHCPv6);
-
- // Test that enable/disable using 'HA command' origin works
- state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
-
- // Test that using 'HA command' origin does not use internal counter
- state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
- state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
-}
-
-// This test verifies that it is possible to disable and then enable DHCPv6
+// This test verifies that it is possible to disable and then enable
// service using 'DB connection' origin.
void
-NetworkStateTest::disableEnableService6UsingDBConnectionOriginTest() {
- NetworkState state(NetworkState::DHCPv6);
+NetworkStateTest::disableEnableServiceUsingDBConnectionOriginTest() {
+ NetworkState state;
// Test that enable/disable using 'DB connection' origin works
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
- // Test that using 'DB connection' origin uses internal counter
+ // Test that using 'DB connection' origin does not use internal counter
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test that using 'DB connection' origin does consider id
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
+ state.disableService(NetworkState::DB_CONNECTION + 1);
+ checkNetworkState(state, false, {}, {}, { 3000, 3001 }, true);
+ state.disableService(NetworkState::DB_CONNECTION + 2);
+ checkNetworkState(state, false, {}, {}, { 3000, 3001, 3002 }, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3001, 3002 }, true);
+ state.enableService(NetworkState::DB_CONNECTION + 1);
+ checkNetworkState(state, false, {}, {}, { 3002 }, true);
+ state.enableService(NetworkState::DB_CONNECTION + 2);
+ checkNetworkState(state, false, {}, {}, {}, false);
}
-// This test verifies that it is possible to disable and then enable DHCPv6
-// service using a combination of origins.
+/// @brief This test verifies that it is possible to disable and then enable
+/// service using a combination of origins.
// 1. Disable using 'user command' origin 2 times (expect disabled state).
-// 2. Disable using 'HA command' origin 2 times (expect disabled state).
-// 3. Disable using 'DB connection' origin 2 times (expect disabled state).
-// 4. Enable using 'user command' origin 1 time (expect disabled state).
-// 5. Enable using 'HA command' origin 1 time (expect disabled state).
-// 6. Enable using 'DB connection' origin 2 times (expect enabled state).
+// 2. Disable using 'HA local command' origin 2 times (expect disabled state).
+// 3. Disable using 'HA local command' origin 1 time different id (expect disabled state).
+// 4. Disable using 'HA remote command' origin 2 times (expect disabled state).
+// 5. Disable using 'HA remote command' origin 1 time different id (expect disabled state).
+// 6. Disable using 'DB connection' origin 2 times (expect disabled state).
+// 7. Disable using 'DB connection' origin 1 time different id (expect disabled state).
+// 8. Enable using 'user command' origin 1 time (expect disabled state).
+// 9. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 10. Enable using 'HA local command' origin 1 time different id (expect disabled state).
+// 11. Enable using 'HA remote command' origin 1 time (expect disabled state).
+// 12. Enable using 'HA remote command' origin 1 time different id (expect disabled state).
+// 13. Enable using 'DB connection' origin 1 times (expect disabled state).
+// 14. Enable using 'DB connection' origin 1 time different id (expect disabled state).
void
-NetworkStateTest::disableEnableService6UsingMultipleOriginsTest() {
- NetworkState state(NetworkState::DHCPv6);
+NetworkStateTest::disableEnableServiceUsingMultipleOriginsTest() {
+ NetworkState state;
// Test that a combination properly affects the state
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, true, { 1000, 1001 }, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, { 1000, 1001 }, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, { 1000, 1001 }, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, true, { 1000, 1001 }, { 2000, 2001 }, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000, 1001 }, { 2000, 2001 }, { 3000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000, 1001 }, { 2000, 2001 }, { 3000 }, true);
+ state.disableService(NetworkState::DB_CONNECTION + 1);
+ checkNetworkState(state, true, { 1000, 1001 }, { 2000, 2001 }, { 3000, 3001 }, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000, 1001 }, { 2000, 2001 }, { 3000, 3001 }, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1001 }, { 2000, 2001 }, { 3000, 3001 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, {}, { 2000, 2001 }, { 3000, 3001 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2001 }, { 3000, 3001 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, {}, {}, { 3000, 3001 }, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3001 },true);
+ state.enableService(NetworkState::DB_CONNECTION + 1);
+ checkNetworkState(state, false, {}, {}, {}, false);
}
// This test verifies that reset works, so that internal state is reset after
// 5. Enable using 'HA command' origin 1 time (expect disabled state).
// 6. Enable using 'DB connection' origin 1 time (expect enabled state).
// 7. Disable using 'user command' origin 3 times (expect disabled state).
-// 8. Reset using 'user command' origin (expect enabled state).
+// 8. Enable using 'user command' origin (expect enabled state).
void
NetworkStateTest::resetUsingUserCommandOriginTest() {
- NetworkState state(NetworkState::DHCPv4);
+ NetworkState state;
// Test User COMMAND + HA COMMAND + DB CONNECTION origins
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, { 1000 }, { 2000 }, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, { 2000 }, { 3000 }, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000 }, { 2000 }, { 3000 }, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
// Test User COMMAND origin only
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
}
// This test verifies that reset works, so that internal state is reset after
// all managers are recreated.
// 1. Disable using 'user command' origin 1 time (expect disabled state).
-// 2. Disable using 'HA command' origin 3 times (expect disabled state).
+// 2. Disable using 'HA local command' origin 3 times with same id (expect disabled state).
// 3. Disable using 'DB connection' origin 1 time (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. Enable using 'HA command' origin (expect enabled state).
+// 4. Disable using 'HA remote command' origin 1 time (expect disabled state).
+// 5. Enable using 'HA local command' origin (expect disabled state).
+// 6. Enable using 'user command' origin 1 time (expect disabled state).
+// 7. Enable using 'HA remote command' origin 1 time (expect disabled state).
+// 8. Enable using 'DB connection' origin 1 time (expect enabled state).
+// 9. Disable using 'user command' origin 1 time (expect disabled state).
+// 10. Disable using 'HA local command' origin 3 times with different ids (expect disabled state).
+// 11. Disable using 'DB connection' origin 1 time (expect disabled state).
+// 12. Disable using 'HA remote command' origin 1 time (expect disabled state).
+// 13. Enable using 'user command' origin 1 time (expect disabled state).
+// 14. Enable using 'HA remote command' origin 1 time (expect disabled state).
+// 15. Enable using 'DB connection' origin 1 time (expect disabled state).
+// 16. Enable using 'HA local command' origin 3 times with different ids (expect enabled state).
+// 17. Disable using 'user command' origin 1 time (expect disabled state).
+// 18. Disable using 'HA local command' origin 3 times with different ids (expect disabled state).
+// 19. Disable using 'DB connection' origin 1 time (expect disabled state).
+// 20. Disable using 'HA remote command' origin 1 time (expect disabled state).
+// 21. Enable using 'user command' origin 1 time (expect disabled state).
+// 22. Enable using 'HA remote command' origin 1 time (expect disabled state).
+// 23. Enable using 'DB connection' origin 1 time (expect disabled state).
+// 24. Reset using 'HA local command' origin (expect enabled state).
+// 25. Disable using 'HA local command' origin 3 times (expect disabled state).
+// 26. Enable using 'HA local command' origin (expect enabled state).
void
-NetworkStateTest::resetUsingHACommandOriginTest() {
- NetworkState state(NetworkState::DHCPv4);
+NetworkStateTest::resetUsingHALocalCommandOriginTest() {
+ NetworkState state;
// Test HA COMMAND + User COMMAND + DB CONNECTION origins
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, { 3000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, { 1000 }, { 2000 }, { 3000 }, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, { 2000 }, { 3000 }, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
- // Test HA COMMAND origin only
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, true, { 1000, 1001 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, true, { 1000, 1001, 1002 }, {}, {}, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, { 1000, 1001, 1002 }, {}, { 3000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, { 1000, 1001, 1002 }, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, { 1000, 1001, 1002 }, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, { 1000, 1001, 1002 }, {}, { 3000 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, { 1000, 1001, 1002 }, {}, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, { 1001, 1002 }, {}, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, { 1002 }, {}, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, true, { 1000, 1001 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, true, { 1000, 1001, 1002 }, {}, {}, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, { 1000, 1001, 1002 }, {}, { 3000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, { 1000, 1001, 1002 }, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, { 1000, 1001, 1002 }, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, { 1000, 1001, 1002 }, {}, { 3000 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, { 1000, 1001, 1002 }, {}, {}, true);
+ state.resetForLocalCommands();
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test HA LOCAL COMMAND origin only
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, { 1000 }, {}, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, { 1000 }, {}, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, {}, false);
}
-// This test verifies that reset works, so that internal state is reset after
+// This test verifies that reset works, so that internal state is reset after
// all managers are recreated.
// 1. Disable using 'user command' origin 1 time (expect disabled state).
-// 2. Disable using 'HA command' origin 1 time (expect disabled state).
-// 3. Disable using 'DB connection' origin 3 time (expect disabled state).
-// 4. Reset using 'DB connection' 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 'DB connection' origin 3 times (expect disabled state).
-// 8. Reset using 'DB connection' origin (expect enabled state).
+// 2. Disable using 'HA remote command' origin 3 times with same id (expect disabled state).
+// 3. Disable using 'DB connection' origin 1 time (expect disabled state).
+// 4. Disable using 'HA local command' origin 1 time (expect disabled state).
+// 5. Enable using 'HA remote command' origin (expect disabled state).
+// 6. Enable using 'user command' origin 1 time (expect disabled state).
+// 7. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 8. Enable using 'DB connection' origin 1 time (expect enabled state).
+// 9. Disable using 'user command' origin 1 time (expect disabled state).
+// 10. Disable using 'HA remote command' origin 3 times with different ids (expect disabled state).
+// 11. Disable using 'DB connection' origin 1 time (expect disabled state).
+// 12. Disable using 'HA local command' origin 1 time (expect disabled state).
+// 13. Enable using 'user command' origin 1 time (expect disabled state).
+// 14. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 15. Enable using 'DB connection' origin 1 time (expect disabled state).
+// 16. Enable using 'HA remote command' origin 3 times with different ids (expect enabled state).
+// 17. Disable using 'user command' origin 1 time (expect disabled state).
+// 18. Disable using 'HA remote command' origin 3 times with different ids (expect disabled state).
+// 19. Disable using 'DB connection' origin 1 time (expect disabled state).
+// 20. Disable using 'HA local command' origin 1 time (expect disabled state).
+// 21. Enable using 'user command' origin 1 time (expect disabled state).
+// 22. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 23. Enable using 'DB connection' origin 1 time (expect disabled state).
+// 24. Reset using 'HA remote command' origin (expect enabled state).
+// 25. Disable using 'HA remote command' origin 3 times (expect disabled state).
+// 26. Enable using 'HA remote command' origin (expect enabled state).
void
-NetworkStateTest::resetUsingDBConnectionOriginTest() {
- NetworkState state(NetworkState::DHCPv4);
+NetworkStateTest::resetUsingHARemoteCommandOriginTest() {
+ NetworkState state;
- // Test DB CONNECTION + User COMMAND + HA COMMAND origins
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, {}, { 2000 }, { 3000 }, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, { 1000 }, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, { 1000 }, {}, { 3000 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, { 1000 }, {}, { 3000 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, {}, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, true, {}, { 2000, 2001 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, true, {}, { 2000, 2001, 2002 }, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, { 1000 }, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, { 1000 }, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, {}, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, {}, { 2000, 2001, 2002 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2001, 2002 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, {}, { 2002 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, {}, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, true, {}, { 2000, 2001 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, true, {}, { 2000, 2001, 2002 }, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, { 1000 }, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, { 1000 }, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, {}, { 2000, 2001, 2002 }, { 3000 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, {}, { 2000, 2001, 2002 }, {}, true);
+ state.resetForRemoteCommands();
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test HA REMOTE COMMAND origin only
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, {}, false);
+}
+
+/// @brief This test verifies that reset works, so that internal state is reset after
+/// all managers are recreated.
+// 1. Disable using 'user command' origin 1 time (expect disabled state).
+// 2. Disable using 'DB connection' origin 3 times with same id (expect disabled state).
+// 3. Disable using 'HA remote command' origin 1 time (expect disabled state).
+// 4. Disable using 'HA local command' origin 1 time (expect disabled state).
+// 5. Enable using 'DB connection' origin (expect disabled state).
+// 6. Enable using 'user command' origin 1 time (expect disabled state).
+// 7. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 8. Enable using 'HA remote command' origin 1 time (expect enabled state).
+// 9. Disable using 'user command' origin 1 time (expect disabled state).
+// 10. Disable using 'DB connection' origin 3 times with different ids (expect disabled state).
+// 11. Disable using 'HA remote command' origin 1 time (expect disabled state).
+// 12. Disable using 'HA local command' origin 1 time (expect disabled state).
+// 13. Enable using 'user command' origin 1 time (expect disabled state).
+// 14. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 15. Enable using 'HA remote command' origin 1 time (expect disabled state).
+// 16. Enable using 'DB connection' origin 3 times with different ids (expect enabled state).
+// 17. Disable using 'user command' origin 1 time (expect disabled state).
+// 18. Disable using 'DB connection' origin 3 times with different ids (expect disabled state).
+// 19. Disable using 'HA remote command' origin 1 time (expect disabled state).
+// 20. Disable using 'HA local command' origin 1 time (expect disabled state).
+// 21. Enable using 'user command' origin 1 time (expect disabled state).
+// 22. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 23. Enable using 'HA remote command' origin 1 time (expect disabled state).
+// 24. Reset using 'DB connection' origin (expect enabled state).
+// 25. Disable using 'DB connection' origin 3 times (expect disabled state).
+// 26. Enable using 'DB connection' origin (expect enabled state).
+void
+NetworkStateTest::resetUsingDBConnectionOriginTest() {
+ NetworkState state;
+
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, {}, {}, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.resetForDbConnection();
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, {}, {}, { 3000 }, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, {}, {}, { 3000 }, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, {}, {}, { 3000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, { 3000 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, { 1000 }, { 2000 }, { 3000 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, { 1000 }, { 2000 }, {}, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, { 1000 }, { 2000 }, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, { 2000 }, {}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, {}, {}, {}, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, {}, {}, { 3000 }, true);
+ state.disableService(NetworkState::DB_CONNECTION + 1);
+ checkNetworkState(state, true, {}, {}, { 3000, 3001 }, true);
+ state.disableService(NetworkState::DB_CONNECTION + 2);
+ checkNetworkState(state, true, {}, {}, { 3000, 3001, 3002 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, { 1000 }, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, { 1000 }, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, { 3000, 3001, 3002 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, {}, {}, { 3001, 3002 }, true);
+ state.enableService(NetworkState::DB_CONNECTION + 1);
+ checkNetworkState(state, false, {}, {}, { 3002 }, true);
+ state.enableService(NetworkState::DB_CONNECTION + 2);
+ checkNetworkState(state, false, {}, {}, {}, false);
+
+ // Test HA COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, {}, {}, {}, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, {}, {}, { 3000 }, true);
+ state.disableService(NetworkState::DB_CONNECTION + 1);
+ checkNetworkState(state, true, {}, {}, { 3000, 3001 }, true);
+ state.disableService(NetworkState::DB_CONNECTION + 2);
+ checkNetworkState(state, true, {}, {}, { 3000, 3001, 3002 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, {}, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, { 1000 }, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, { 1000 }, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, {}, { 2000 }, { 3000, 3001, 3002 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, {}, {}, { 3000, 3001, 3002 }, true);
+ state.resetForDbConnection();
+ checkNetworkState(state, false, {}, {}, {}, false);
// Test DB CONNECTION origin only
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
- state.resetForDbConnection();
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, {}, {}, { 3000 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, {}, {}, {}, false);
}
// This test verifies that it is possible to setup delayed execution of enableAll
// function.
void
NetworkStateTest::delayedEnableServiceTest() {
- NetworkState state(NetworkState::DHCPv4);
+ NetworkState state;
// Disable the service and then schedule enabling it in 1 second.
state.disableService(NetworkState::USER_COMMAND);
state.delayedEnableService(1, NetworkState::USER_COMMAND);
// scheduled for automatically enabling it.
void
NetworkStateTest::earlyEnableServiceTest() {
- NetworkState state(NetworkState::DHCPv4);
+ NetworkState state;
// Disable the service.
state.disableService(NetworkState::USER_COMMAND);
EXPECT_FALSE(state.isServiceEnabled());
// and that it results in only one timer being scheduled.
void
NetworkStateTest::multipleDelayedEnableServiceTest() {
- NetworkState state(NetworkState::DHCPv4);
+ NetworkState state;
// Disable the service and then schedule enabling it in 5 second.
state.disableService(NetworkState::USER_COMMAND);
// Schedule the first timer for 5 seconds.
// from different origins and that it results in each timer being scheduled.
void
NetworkStateTest::multipleDifferentOriginsDelayedEnableServiceTest() {
- NetworkState state(NetworkState::DHCPv4);
+ NetworkState state;
// 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.
defaultTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingUserCommandOriginTest) {
- disableEnableService4UsingUserCommandOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService4UsingUserCommandOriginTestMultilThreading) {
- MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingUserCommandOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService4UsingHACommandOriginTest) {
- disableEnableService4UsingHACommandOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService4UsingHACommandOriginTestMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingHACommandOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService4UsingDBConnectionOriginTest) {
- disableEnableService4UsingDBConnectionOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService4UsingDBConnectionOriginTestMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingDBConnectionOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService4UsingMultipleOriginsTest) {
- disableEnableService4UsingMultipleOriginsTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingUserCommandOriginTest) {
+ disableEnableServiceUsingUserCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingMultipleOriginsTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingUserCommandOriginTestMultilThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingMultipleOriginsTest();
+ disableEnableServiceUsingUserCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingUserCommandOriginTest) {
- disableEnableService6UsingUserCommandOriginTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingHALocalCommandOriginTest) {
+ disableEnableServiceUsingHALocalCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingUserCommandOriginTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingHALocalCommandOriginTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingUserCommandOriginTest();
+ disableEnableServiceUsingHALocalCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingHACommandOriginTest) {
- disableEnableService6UsingHACommandOriginTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingHARemoteCommandOriginTest) {
+ disableEnableServiceUsingHARemoteCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingHACommandOriginTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingHARemoteCommandOriginTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingHACommandOriginTest();
+ disableEnableServiceUsingHARemoteCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingDBConnectionOriginTest) {
- disableEnableService6UsingDBConnectionOriginTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingDBConnectionOriginTest) {
+ disableEnableServiceUsingDBConnectionOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingDBConnectionOriginTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingDBConnectionOriginTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingDBConnectionOriginTest();
+ disableEnableServiceUsingDBConnectionOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingMultipleOriginsTest) {
- disableEnableService6UsingMultipleOriginsTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingMultipleOriginsTest) {
+ disableEnableServiceUsingMultipleOriginsTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingMultipleOriginsTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingMultipleOriginsTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingMultipleOriginsTest();
+ disableEnableServiceUsingMultipleOriginsTest();
}
TEST_F(NetworkStateTest, resetUsingUserCommandOriginTest) {
resetUsingDBConnectionOriginTest();
}
-TEST_F(NetworkStateTest, resetUsingHACommandOriginTest) {
- resetUsingHACommandOriginTest();
+TEST_F(NetworkStateTest, resetUsingHALocalCommandOriginTest) {
+ resetUsingHALocalCommandOriginTest();
+}
+
+TEST_F(NetworkStateTest, resetUsingHALocalCommandOriginTestMultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ resetUsingHALocalCommandOriginTest();
+}
+
+TEST_F(NetworkStateTest, resetUsingHARemoteCommandOriginTest) {
+ resetUsingHARemoteCommandOriginTest();
}
-TEST_F(NetworkStateTest, resetUsingHACommandOriginTestMultiThreading) {
+TEST_F(NetworkStateTest, resetUsingHARemoteCommandOriginTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- resetUsingHACommandOriginTest();
+ resetUsingHARemoteCommandOriginTest();
}
TEST_F(NetworkStateTest, delayedEnableServiceTest) {