summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2024-07-11 19:17:26 +0200
committerRazvan Becheriu <razvan@isc.org>2024-07-16 14:43:21 +0200
commit2da36722eae42e36154e779b9f13892ab6cd4b91 (patch)
treefc30dc73a719705c1faf64336887deacdd512db2 /src
parent[#3446] added unittests (diff)
downloadkea-2da36722eae42e36154e779b9f13892ab6cd4b91.tar.xz
kea-2da36722eae42e36154e779b9f13892ab6cd4b91.zip
[#3446] added unittests
Diffstat (limited to 'src')
-rw-r--r--src/bin/dhcp4/dhcp4_srv.cc2
-rw-r--r--src/bin/dhcp6/dhcp6_srv.cc2
-rw-r--r--src/hooks/dhcp/high_availability/libloadtests/close_unittests.cc8
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc102
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_test.cc2
-rw-r--r--src/lib/dhcpsrv/network_state.cc28
-rw-r--r--src/lib/dhcpsrv/network_state.h10
-rw-r--r--src/lib/dhcpsrv/tests/network_state_unittest.cc840
8 files changed, 596 insertions, 398 deletions
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 3b3c9de81e..41492ce155 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -624,7 +624,7 @@ Dhcpv4Srv::Dhcpv4Srv(uint16_t server_port, uint16_t client_port,
: io_service_(new IOService()), server_port_(server_port),
client_port_(client_port), shutdown_(true),
alloc_engine_(), use_bcast_(use_bcast),
- network_state_(new NetworkState(NetworkState::DHCPv4)),
+ network_state_(new NetworkState()),
cb_control_(new CBControlDHCPv4()),
test_send_responses_to_source_(false) {
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index aca7ac1f16..381536ed21 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -218,7 +218,7 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t server_port, uint16_t client_port)
: io_service_(new IOService()), server_port_(server_port),
client_port_(client_port), serverid_(), shutdown_(true),
alloc_engine_(), name_change_reqs_(),
- network_state_(new NetworkState(NetworkState::DHCPv6)),
+ network_state_(new NetworkState()),
cb_control_(new CBControlDHCPv6()) {
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET)
.arg(server_port);
diff --git a/src/hooks/dhcp/high_availability/libloadtests/close_unittests.cc b/src/hooks/dhcp/high_availability/libloadtests/close_unittests.cc
index b1b148cc80..422e063696 100644
--- a/src/hooks/dhcp/high_availability/libloadtests/close_unittests.cc
+++ b/src/hooks/dhcp/high_availability/libloadtests/close_unittests.cc
@@ -355,7 +355,7 @@ TEST_F(CloseHATest, close4) {
// Prepare objects.
IOServicePtr io_service(new IOService());
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
Pkt4Ptr query(new Pkt4(DHCPREQUEST, 12345));
HWAddrPtr hwaddr(new HWAddr(std::vector<uint8_t>(6, 1), HTYPE_ETHER));
query->setHWAddr(hwaddr);
@@ -501,7 +501,7 @@ TEST_F(CloseHATest, close4Backup) {
// Prepare objects.
IOServicePtr io_service(new IOService());
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
// Check that the state is computed on dhcp4_srv_configured.
// It is first reset by the constructor and then adjusted by running the
@@ -592,7 +592,7 @@ TEST_F(CloseHATest, close6) {
// Prepare objects.
IOServicePtr io_service(new IOService());
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
Pkt6Ptr query(new Pkt6(DHCPV6_REQUEST, 12345));
DuidPtr duid(new DUID(std::vector<uint8_t>(8, 2)));
OptionPtr opt_duid(new Option(Option::V6, D6O_CLIENTID, duid->getDuid()));
@@ -738,7 +738,7 @@ TEST_F(CloseHATest, close6Backup) {
// Prepare objects.
IOServicePtr io_service(new IOService());
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
// Check that the state is computed on dhcp6_srv_configured.
// It is first reset by the constructor and then adjusted by running the
diff --git a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
index 1508b5cc72..ee272ba8d9 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
@@ -121,7 +121,7 @@ public:
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -159,7 +159,7 @@ TEST_F(HAImplTest, startServices) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidJsonConfiguration()));
// Network state is also required.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
// Start the service for DHCPv4 server.
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
@@ -179,7 +179,7 @@ TEST_F(HAImplTest, startServices6) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidJsonConfiguration()));
// Network state is also required.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
// Start the service for DHCPv4 server.
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
@@ -203,7 +203,7 @@ TEST_F(HAImplTest, buffer4Receive) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -317,7 +317,7 @@ TEST_F(HAImplTest, subnet4Select) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -375,7 +375,7 @@ TEST_F(HAImplTest, subnet4SelectSharedNetwork) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -436,7 +436,7 @@ TEST_F(HAImplTest, subnet4SelectSingleRelationship) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -478,7 +478,7 @@ TEST_F(HAImplTest, subnet4SelectDropNoServerName) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -524,7 +524,7 @@ TEST_F(HAImplTest, subnet4SelectDropInvalidServerNameType) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -574,7 +574,7 @@ TEST_F(HAImplTest, subnet4SelectDropNotInScope) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -627,7 +627,7 @@ TEST_F(HAImplTest, subnet4SelectNoSubnet) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -674,7 +674,7 @@ TEST_F(HAImplTest, buffer6Receive) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -765,7 +765,7 @@ TEST_F(HAImplTest, subnet6Select) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -820,7 +820,7 @@ TEST_F(HAImplTest, subnet6SelectSharedNetwork) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -881,7 +881,7 @@ TEST_F(HAImplTest, subnet6SelectSingleRelationship) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -923,7 +923,7 @@ TEST_F(HAImplTest, subnet6SelectDropNoServerName) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -969,7 +969,7 @@ TEST_F(HAImplTest, subnet6SelectDropInvalidServerNameType) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -1019,7 +1019,7 @@ TEST_F(HAImplTest, subnet6SelectDropNotInScope) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -1072,7 +1072,7 @@ TEST_F(HAImplTest, subnet6SelectNoSubnet) {
ASSERT_NO_THROW(test_ha_impl_->configure(ha_config));
// Starting the service is required before any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -1115,7 +1115,7 @@ TEST_F(HAImplTest, leases4Committed) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1202,7 +1202,7 @@ TEST_F(HAImplTest, leases4CommittedMultipleRelationships) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidHubJsonConfiguration()));
// Starting the service is required before running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1259,7 +1259,7 @@ TEST_F(HAImplTest, leases4CommittedMultipleRelationshipsNoServerName) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidHubJsonConfiguration()));
// Starting the service is required before running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1312,7 +1312,7 @@ TEST_F(HAImplTest, leases4CommittedMultipleRelationshipsInvalidServerName) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidHubJsonConfiguration()));
// Starting the service is required before running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1367,7 +1367,7 @@ TEST_F(HAImplTest, leases6Committed) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -1453,7 +1453,7 @@ TEST_F(HAImplTest, leases6CommittedMultipleRelationships) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidHubJsonConfiguration()));
// Starting the service is required before running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -1509,7 +1509,7 @@ TEST_F(HAImplTest, leases6CommittedMultipleRelationshipsNoServerName) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidHubJsonConfiguration()));
// Starting the service is required before running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -1561,7 +1561,7 @@ TEST_F(HAImplTest, leases6CommittedMultipleRelationshipsInvalidServerName) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidHubJsonConfiguration()));
// Starting the service is required before running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv6));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv6));
@@ -1693,7 +1693,7 @@ TEST_F(HAImplTest, continueHandler) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1723,7 +1723,7 @@ TEST_F(HAImplTest, continueHandlerWithNoServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1748,7 +1748,7 @@ TEST_F(HAImplTest, continueHandlerWithWrongServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1778,7 +1778,7 @@ TEST_F(HAImplTest, statusGet) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1841,7 +1841,7 @@ TEST_F(HAImplTest, statusGetBackupServer) {
test_ha_impl_->config_->get()->setThisServerName("server3");
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1891,7 +1891,7 @@ TEST_F(HAImplTest, statusGetPassiveBackup) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidPassiveBackupJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -1941,7 +1941,7 @@ TEST_F(HAImplTest, statusGetHubAndSpoke) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidHubJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2027,7 +2027,7 @@ TEST_F(HAImplTest, maintenanceNotify) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2060,7 +2060,7 @@ TEST_F(HAImplTest, maintenanceNotifyNoServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2092,7 +2092,7 @@ TEST_F(HAImplTest, maintenanceNotifyBadServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2125,7 +2125,7 @@ TEST_F(HAImplTest, haReset) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2157,7 +2157,7 @@ TEST_F(HAImplTest, haResetNoServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2186,7 +2186,7 @@ TEST_F(HAImplTest, haResetBadServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2218,7 +2218,7 @@ TEST_F(HAImplTest, haHeartbeat) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2250,7 +2250,7 @@ TEST_F(HAImplTest, haHeartbeatNoServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2279,7 +2279,7 @@ TEST_F(HAImplTest, haHeartbeatBadServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2312,7 +2312,7 @@ TEST_F(HAImplTest, haSyncCompleteNotifyOriginId) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2357,7 +2357,7 @@ TEST_F(HAImplTest, haSyncCompleteNotifyOrigin) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2401,7 +2401,7 @@ TEST_F(HAImplTest, haSyncCompleteNotifyNoServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2431,7 +2431,7 @@ TEST_F(HAImplTest, haSyncCompleteNotifyBadServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2463,7 +2463,7 @@ TEST_F(HAImplTest, haScopes) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2496,7 +2496,7 @@ TEST_F(HAImplTest, haScopesNoServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2528,7 +2528,7 @@ TEST_F(HAImplTest, haScopesBadServerName) {
ASSERT_NO_THROW(ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
@@ -2562,7 +2562,7 @@ TEST_F(HAImplTest, lease4ServerDecline) {
ASSERT_NO_THROW(test_ha_impl_->configure(createValidJsonConfiguration()));
// Starting the service is required prior to running any callouts.
- NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ NetworkStatePtr network_state(new NetworkState());
ASSERT_NO_THROW(test_ha_impl_->startServices(network_state,
HAServerType::DHCPv4));
diff --git a/src/hooks/dhcp/high_availability/tests/ha_test.cc b/src/hooks/dhcp/high_availability/tests/ha_test.cc
index bf07480c65..350df09a71 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_test.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_test.cc
@@ -52,7 +52,7 @@ namespace test {
HATest::HATest()
: io_service_(new IOService()),
- network_state_(new NetworkState(NetworkState::DHCPv4)) {
+ network_state_(new NetworkState()) {
}
HATest::~HATest() {
diff --git a/src/lib/dhcpsrv/network_state.cc b/src/lib/dhcpsrv/network_state.cc
index 61aba7df00..4bf7c098db 100644
--- a/src/lib/dhcpsrv/network_state.cc
+++ b/src/lib/dhcpsrv/network_state.cc
@@ -27,11 +27,9 @@ class NetworkStateImpl : public boost::enable_shared_from_this<NetworkStateImpl>
public:
/// @brief Constructor.
- NetworkStateImpl(const NetworkState::ServerType& server_type)
- : server_type_(server_type), globally_disabled_(false),
- disabled_subnets_(), disabled_networks_(),
- timer_mgr_(TimerMgr::instance()), disabled_by_origin_(),
- disabled_by_db_connection_(0) {
+ NetworkStateImpl() : globally_disabled_(false), disabled_subnets_(),
+ disabled_networks_(), timer_mgr_(TimerMgr::instance()),
+ disabled_by_origin_(), disabled_by_db_connection_(0) {
}
/// @brief Destructor.
@@ -178,22 +176,23 @@ public:
/// @brief The network state as Element.
///
/// @return The network state as Element.
- ConstElementPtr toElement() {
+ ConstElementPtr toElement() const {
ElementPtr result = Element::createMap();
result->set("globally-disabled", Element::create(globally_disabled_));
result->set("disabled-by-db-connection", Element::create(disabled_by_db_connection_ != 0));
bool disabled_by_user = false;
ElementPtr local_origin = Element::createList();
ElementPtr remote_origin = Element::createList();
- for (auto const& origin : disabled_by_origin_) {
+ std::set<uint32_t> ordered(disabled_by_origin_.begin(), disabled_by_origin_.end());
+ for (auto const& origin : ordered) {
if (origin == NetworkState::USER_COMMAND) {
disabled_by_user = true;
}
if (origin >= NetworkState::HA_LOCAL_COMMAND && origin < NetworkState::HA_REMOTE_COMMAND) {
- local_origin->add(Element::create(origin - NetworkState::HA_LOCAL_COMMAND));
+ local_origin->add(Element::create(origin));
}
if (origin >= NetworkState::HA_REMOTE_COMMAND && origin < NetworkState::DB_CONNECTION) {
- remote_origin->add(Element::create(origin - NetworkState::HA_REMOTE_COMMAND));
+ remote_origin->add(Element::create(origin));
}
}
result->set("disabled-by-user", Element::create(disabled_by_user));
@@ -203,9 +202,6 @@ public:
return (result);
}
- /// @brief Server type.
- NetworkState::ServerType server_type_;
-
/// @brief A flag indicating if DHCP service is globally disabled.
bool globally_disabled_;
@@ -222,15 +218,15 @@ public:
TimerMgrPtr timer_mgr_;
/// @brief A set of requests to disable the service by origin.
- std::unordered_set<unsigned int> disabled_by_origin_;
+ std::unordered_set<uint32_t> disabled_by_origin_;
/// @brief Flag which indicates the state has been disabled by a DB
/// connection loss.
uint32_t disabled_by_db_connection_;
};
-NetworkState::NetworkState(const NetworkState::ServerType& server_type)
- : impl_(new NetworkStateImpl(server_type)), mutex_(new std::mutex()) {
+NetworkState::NetworkState()
+ : impl_(new NetworkStateImpl()), mutex_(new std::mutex()) {
}
void
@@ -305,7 +301,7 @@ NetworkState::selectiveEnable(const NetworkState::Networks&) {
isc_throw(NotImplemented, "selectiveEnableService is not implemented");
}
-ConstElementPtr NetworkState::toElement() {
+ConstElementPtr NetworkState::toElement() const {
MultiThreadingLock lock(*mutex_);
return (impl_->toElement());
}
diff --git a/src/lib/dhcpsrv/network_state.h b/src/lib/dhcpsrv/network_state.h
index ab20f67cae..b48697b91e 100644
--- a/src/lib/dhcpsrv/network_state.h
+++ b/src/lib/dhcpsrv/network_state.h
@@ -71,12 +71,6 @@ class NetworkStateImpl;
class NetworkState {
public:
- /// @brief DHCP server type.
- enum ServerType {
- DHCPv4,
- DHCPv6
- };
-
/// @brief Origin of the network state transition.
///
/// The enumeration indicates the originator of the state transition of the
@@ -113,7 +107,7 @@ public:
typedef std::set<std::string> Networks;
/// @brief Constructor.
- NetworkState(const ServerType& server_type);
+ NetworkState();
/// @brief Disable the DHCP service state for respective transition origin.
///
@@ -211,7 +205,7 @@ public:
/// @brief The network state as Element.
///
/// @return The network state as Element.
- isc::data::ConstElementPtr toElement();
+ isc::data::ConstElementPtr toElement() const;
//@}
diff --git a/src/lib/dhcpsrv/tests/network_state_unittest.cc b/src/lib/dhcpsrv/tests/network_state_unittest.cc
index 4f7b539e49..3b67daf853 100644
--- a/src/lib/dhcpsrv/tests/network_state_unittest.cc
+++ b/src/lib/dhcpsrv/tests/network_state_unittest.cc
@@ -46,49 +46,37 @@ public:
/// @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 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
+ /// service using 'HA remote command' origin.
+ void disableEnableServiceUsingHARemoteCommandOriginTest();
- /// @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. Enable using 'user command' origin 1 time (expect disabled state).
+ // 8. Enable using 'HA local command' origin 1 time (expect disabled state).
+ // 9. Enable using 'HA local command' origin 1 time different id (expect disabled state).
+ // 10. Enable using 'HA remote command' origin 1 time (expect disabled state).
+ // 11. Enable using 'HA remote command' origin 1 time different id (expect disabled state).
+ // 12. Enable using 'DB connection' origin 2 times (expect enabled state).
+ void disableEnableServiceUsingMultipleOriginsTest();
/// @brief This test verifies that reset works, so that internal state is reset after
/// all managers are recreated.
@@ -104,15 +92,63 @@ public:
/// @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 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.
@@ -150,6 +186,50 @@ public:
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 db_connection Flag which indicates if db connection 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 global Flag which indicates if the state is disabled.
+ void checkNetworkState(const NetworkState& state,
+ bool user,
+ bool db_connection,
+ std::vector<uint32_t> local,
+ std::vector<uint32_t> remote,
+ bool global) {
+ std::string expected = "{ \"disabled-by-db-connection\": ";
+ expected += db_connection ? "true" : "false";
+ expected += ", \"disabled-by-local-command\": [ ";
+ bool not_first = false;
+ for (auto const value : local) {
+ if (not_first) {
+ expected += ", ";
+ }
+ expected += std::to_string(value);
+ not_first = true;
+ }
+ expected += " ], \"disabled-by-remote-command\": [ ";
+ not_first = false;
+ for (auto const value : remote) {
+ if (not_first) {
+ expected += ", ";
+ }
+ expected += std::to_string(value);
+ not_first = true;
+ }
+ expected += " ], \"disabled-by-user\": ";
+ expected += user ? "true" : "false";
+ expected += ", \"globally-disabled\": ";
+ expected += global ? "true" : "false";
+ expected += " }";
+ EXPECT_EQ(expected, state.toElement()->str());
+ EXPECT_EQ(!global, state.isServiceEnabled());
+ }
+
/// @brief IO service used during the tests.
IOServicePtr io_service_;
};
@@ -157,233 +237,188 @@ public:
// This test verifies the default is enable state.
void
NetworkStateTest::defaultTest() {
- std::string expected("{ \"disabled-by-db-connection\": false, "
- "\"disabled-by-local-command\": [ ], "
- "\"disabled-by-remote-command\": [ ], "
- "\"disabled-by-user\": false, "
- "\"globally-disabled\": false }");
- NetworkState state4(NetworkState::DHCPv4);
- EXPECT_TRUE(state4.isServiceEnabled());
- EXPECT_EQ(expected, state4.toElement()->str());
- NetworkState state6(NetworkState::DHCPv6);
- EXPECT_TRUE(state6.isServiceEnabled());
- EXPECT_EQ(expected, state6.toElement()->str());
-}
-
-// This test verifies that it is possible to disable and then enable DHCPv4
+ NetworkState state;
+
+ checkNetworkState(state, false, false, {}, {}, false);
+}
+
+// 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, false, {}, {}, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, 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, false, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, 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, false, { 1000 }, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, 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, false, { 1000 }, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, { 1000 }, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
-}
-
-// 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);
+ checkNetworkState(state, false, false, {}, {}, false);
- // 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, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, false, { 1000, 1001 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, false, 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, false, { 1001, 1002 }, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, false, { 1002 }, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, false, 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());
-}
-
-// 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
+NetworkStateTest::disableEnableServiceUsingHARemoteCommandOriginTest() {
+ NetworkState state;
+
+ // Test that enable/disable using 'HA remote command' origin works
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, {}, false);
+
+ // Test that using 'HA remote command' origin does not use internal counter
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, {}, false);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, {}, false);
+
+ // Test that using 'HA remote command' origin does consider id
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, false, {}, { 2000, 2001 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, false, false, {}, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2001, 2002 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, false, {}, { 2002 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, false, false, {}, {}, false);
+}
+
+// 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, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
// Test that using 'DB connection' origin uses internal counter
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
}
-// 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 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. Enable using 'user command' origin 1 time (expect disabled state).
+// 8. Enable using 'HA local command' origin 1 time (expect disabled state).
+// 9. Enable using 'HA local command' origin 1 time different id (expect disabled state).
+// 10. Enable using 'HA remote command' origin 1 time (expect disabled state).
+// 11. Enable using 'HA remote command' origin 1 time different id (expect disabled state).
+// 12. Enable using 'DB connection' origin 2 times (expect enabled 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, false, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, true, false, { 1000, 1001 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, { 1000, 1001 }, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, { 1000, 1001 }, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, true, false, { 1000, 1001 }, { 2000, 2001 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, { 1000, 1001 }, { 2000, 2001 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, { 1000, 1001 }, { 2000, 2001 }, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, { 1000, 1001 }, { 2000, 2001 }, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, { 1001 }, { 2000, 2001 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, true, {}, { 2000, 2001 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, true, {}, { 2001 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
}
// This test verifies that reset works, so that internal state is reset after
@@ -395,81 +430,268 @@ NetworkStateTest::disableEnableService6UsingMultipleOriginsTest() {
// 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, false, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, { 1000 }, { 2000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, { 1000 }, { 2000 }, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, { 1000 }, { 2000 }, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
// Test User COMMAND origin only
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, 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
+ // Test HA LOCAL COMMAND + User COMMAND + DB CONNECTION origins
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, true, { 1000 }, { 2000 }, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, {}, { 2000 }, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, true, {}, {}, true);
state.enableService(NetworkState::DB_CONNECTION);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, {}, false);
- // Test HA COMMAND origin only
+ // Test HA LOCAL COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, true, false, { 1000, 1001 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, true, false, { 1000, 1001, 1002 }, {}, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, true, { 1000, 1001, 1002 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, true, { 1000, 1001, 1002 }, { 2000 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, true, { 1000, 1001, 1002 }, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, true, { 1000, 1001, 1002 }, {}, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, false, { 1000, 1001, 1002 }, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, false, { 1001, 1002 }, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, false, false, { 1002 }, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, false, false, {}, {}, false);
+
+ // Test HA LOCAL COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 1);
+ checkNetworkState(state, true, false, { 1000, 1001 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND + 2);
+ checkNetworkState(state, true, false, { 1000, 1001, 1002 }, {}, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, true, { 1000, 1001, 1002 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, true, { 1000, 1001, 1002 }, { 2000 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, true, { 1000, 1001, 1002 }, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, true, { 1000, 1001, 1002 }, {}, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, false, { 1000, 1001, 1002 }, {}, true);
+ state.resetForLocalCommands();
+ checkNetworkState(state, false, false, {}, {}, false);
+
+ // Test HA LOCAL COMMAND origin only
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, false, { 1000 }, {}, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, 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 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::resetUsingHARemoteCommandOriginTest() {
+ NetworkState state;
+
+ // Test HA REMOTE COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, false, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, true, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, true, { 1000 }, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, true, { 1000 }, {}, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, true, { 1000 }, {}, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, true, {}, {}, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, false, {}, {}, false);
+
+ // Test HA REMOTE COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, false, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, true, false, {}, { 2000, 2001 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, true, false, {}, { 2000, 2001, 2002 }, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, true, {}, { 2000, 2001, 2002 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, true, { 1000 }, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, true, { 1000 }, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, true, {}, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, false, {}, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2001, 2002 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, false, false, {}, { 2002}, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, false, false, {}, {}, false);
+
+ // Test HA REMOTE COMMAND + User COMMAND + DB CONNECTION origins
+ state.disableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, true, false, {}, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 1);
+ checkNetworkState(state, true, false, {}, { 2000, 2001 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND + 2);
+ checkNetworkState(state, true, false, {}, { 2000, 2001, 2002 }, true);
+ state.disableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, true, true, {}, { 2000, 2001, 2002 }, true);
+ state.disableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, true, true, { 1000 }, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::USER_COMMAND);
+ checkNetworkState(state, false, true, { 1000 }, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::HA_LOCAL_COMMAND);
+ checkNetworkState(state, false, true, {}, { 2000, 2001, 2002 }, true);
+ state.enableService(NetworkState::DB_CONNECTION);
+ checkNetworkState(state, false, false, {}, { 2000, 2001, 2002 }, true);
+ state.resetForRemoteCommands();
+ checkNetworkState(state, false, false, {}, {}, false);
+
+ // Test HA RELOTE COMMAND origin only
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, {}, false);
}
// This test verifies that reset works, so that internal state is reset after
@@ -484,42 +706,46 @@ NetworkStateTest::resetUsingHACommandOriginTest() {
// 8. Reset using 'DB connection' origin (expect enabled state).
void
NetworkStateTest::resetUsingDBConnectionOriginTest() {
- NetworkState state(NetworkState::DHCPv4);
+ NetworkState state;
// Test DB CONNECTION + User COMMAND + HA COMMAND origins
state.disableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, {}, {}, true);
state.disableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, {}, true);
+ state.disableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, true, false, { 1000 }, { 2000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, { 1000 }, { 2000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, { 1000 }, { 2000 }, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, true, { 1000 }, { 2000 }, true);
state.resetForDbConnection();
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, true, false, { 1000 }, { 2000 }, true);
state.enableService(NetworkState::USER_COMMAND);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, { 1000 }, { 2000 }, true);
state.enableService(NetworkState::HA_LOCAL_COMMAND);
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, false, {}, { 2000 }, true);
+ state.enableService(NetworkState::HA_REMOTE_COMMAND);
+ checkNetworkState(state, false, false, {}, {}, false);
// Test DB CONNECTION origin only
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.disableService(NetworkState::DB_CONNECTION);
- EXPECT_FALSE(state.isServiceEnabled());
+ checkNetworkState(state, false, true, {}, {}, true);
state.resetForDbConnection();
- EXPECT_TRUE(state.isServiceEnabled());
+ checkNetworkState(state, false, 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);
@@ -545,7 +771,7 @@ NetworkStateTest::delayedEnableServiceTest() {
// 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());
@@ -562,7 +788,7 @@ NetworkStateTest::earlyEnableServiceTest() {
// 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.
@@ -584,7 +810,7 @@ NetworkStateTest::multipleDelayedEnableServiceTest() {
// 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.
@@ -621,76 +847,49 @@ TEST_F(NetworkStateTest, defaultTestMultiThreading) {
defaultTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingUserCommandOriginTest) {
- disableEnableService4UsingUserCommandOriginTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingUserCommandOriginTest) {
+ disableEnableServiceUsingUserCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingUserCommandOriginTestMultilThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingUserCommandOriginTestMultilThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingUserCommandOriginTest();
+ disableEnableServiceUsingUserCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingHACommandOriginTest) {
- disableEnableService4UsingHACommandOriginTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingHALocalCommandOriginTest) {
+ disableEnableServiceUsingHALocalCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingHACommandOriginTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingHALocalCommandOriginTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingHACommandOriginTest();
+ disableEnableServiceUsingHALocalCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingDBConnectionOriginTest) {
- disableEnableService4UsingDBConnectionOriginTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingHARemoteCommandOriginTest) {
+ disableEnableServiceUsingHARemoteCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingDBConnectionOriginTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingHARemoteCommandOriginTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingDBConnectionOriginTest();
+ disableEnableServiceUsingHARemoteCommandOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingMultipleOriginsTest) {
- disableEnableService4UsingMultipleOriginsTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingDBConnectionOriginTest) {
+ disableEnableServiceUsingDBConnectionOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService4UsingMultipleOriginsTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingDBConnectionOriginTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService4UsingMultipleOriginsTest();
+ disableEnableServiceUsingDBConnectionOriginTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingUserCommandOriginTest) {
- disableEnableService6UsingUserCommandOriginTest();
+TEST_F(NetworkStateTest, disableEnableServiceUsingMultipleOriginsTest) {
+ disableEnableServiceUsingMultipleOriginsTest();
}
-TEST_F(NetworkStateTest, disableEnableService6UsingUserCommandOriginTestMultiThreading) {
+TEST_F(NetworkStateTest, disableEnableServiceUsingMultipleOriginsTestMultiThreading) {
MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingUserCommandOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService6UsingHACommandOriginTest) {
- disableEnableService6UsingHACommandOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService6UsingHACommandOriginTestMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingHACommandOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService6UsingDBConnectionOriginTest) {
- disableEnableService6UsingDBConnectionOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService6UsingDBConnectionOriginTestMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingDBConnectionOriginTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService6UsingMultipleOriginsTest) {
- disableEnableService6UsingMultipleOriginsTest();
-}
-
-TEST_F(NetworkStateTest, disableEnableService6UsingMultipleOriginsTestMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
- disableEnableService6UsingMultipleOriginsTest();
+ disableEnableServiceUsingMultipleOriginsTest();
}
TEST_F(NetworkStateTest, resetUsingUserCommandOriginTest) {
@@ -711,13 +910,22 @@ TEST_F(NetworkStateTest, resetUsingDBConnectionOriginTestMultiThreading) {
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) {