From: Marcin Siodelski Date: Fri, 15 May 2020 16:55:05 +0000 (+0200) Subject: [#1087] Return additional parameters X-Git-Tag: Kea-1.7.8~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ff60422119ca3b72144eb48dcac1712381cd98b;p=thirdparty%2Fkea.git [#1087] Return additional parameters There are additional parameters returned in the response to the status-get command which indicate the failover status. These parameters are: a bool value indicating if the communication is interrupted, number of clients trying to get a lease, number of unacked clients and the number of packets analyzed. --- diff --git a/src/hooks/dhcp/high_availability/communication_state.cc b/src/hooks/dhcp/high_availability/communication_state.cc index e4dfcc0f9e..8500d4663e 100644 --- a/src/hooks/dhcp/high_availability/communication_state.cc +++ b/src/hooks/dhcp/high_availability/communication_state.cc @@ -292,6 +292,18 @@ CommunicationState::getReport() const { list->add(Element::create(scope)); } report->set("last-scopes", list); + report->set("communication-interrupted", + Element::create(isCommunicationInterrupted())); + report->set("connecting-clients", Element::create(static_cast(getConnectingClientsCount()))); + report->set("unacked-clients", Element::create(static_cast(getUnackedClientsCount()))); + + long long unacked_clients_left = 0; + if (isCommunicationInterrupted() && (config_->getMaxUnackedClients() > getUnackedClientsCount())) { + unacked_clients_left = static_cast(config_->getMaxUnackedClients() - + getUnackedClientsCount()); + } + report->set("unacked-clients-left", Element::create(unacked_clients_left)); + report->set("analyzed-packets", Element::create(static_cast(getAnalyzedMessagesCount()))); return (report); } diff --git a/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc b/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc index 2fa03725e8..032ff7a3e5 100644 --- a/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc @@ -503,8 +503,16 @@ TEST_F(CommunicationStateTest, getReport) { state_.setPartnerScopes(scopes); state_.poke(); - state_.modifyPokeTime(-10); + // Simulate the communications interrupted state. + state_.modifyPokeTime(-100); + + // Send two DHCP packets of which one has secs value beyond the threshold and + // the other one lower than the threshold. + ASSERT_NO_THROW(state_.analyzeMessage(createMessage4(DHCPDISCOVER, 0, 0, 5))); + ASSERT_NO_THROW(state_.analyzeMessage(createMessage4(DHCPDISCOVER, 1, 0, 15))); + + // Get the report. auto report = state_.getReport(); ASSERT_TRUE(report); @@ -518,7 +526,7 @@ TEST_F(CommunicationStateTest, getReport) { auto age = report->get("age"); ASSERT_TRUE(age); EXPECT_EQ(Element::integer, age->getType()); - EXPECT_GE(age->intValue(), 10); + EXPECT_GE(age->intValue(), 100); auto last_state = report->get("last-state"); ASSERT_TRUE(last_state); @@ -531,6 +539,31 @@ TEST_F(CommunicationStateTest, getReport) { EXPECT_EQ(1, last_scopes->listValue().size()); EXPECT_EQ(Element::string, last_scopes->listValue()[0]->getType()); EXPECT_EQ("server1", last_scopes->listValue()[0]->stringValue()); + + auto comm_interrupted = report->get("communication-interrupted"); + ASSERT_TRUE(comm_interrupted); + EXPECT_EQ(Element::boolean, comm_interrupted->getType()); + EXPECT_TRUE(comm_interrupted->boolValue()); + + auto connecting_clients = report->get("connecting-clients"); + ASSERT_TRUE(connecting_clients); + EXPECT_EQ(Element::integer, connecting_clients->getType()); + EXPECT_EQ(2, connecting_clients->intValue()); + + auto unacked_clients = report->get("unacked-clients"); + ASSERT_TRUE(unacked_clients); + EXPECT_EQ(Element::integer, unacked_clients->getType()); + EXPECT_EQ(1, unacked_clients->intValue()); + + auto unacked_clients_left = report->get("unacked-clients-left"); + ASSERT_TRUE(unacked_clients_left); + EXPECT_EQ(Element::integer, unacked_clients_left->getType()); + EXPECT_EQ(9, unacked_clients_left->intValue()); + + auto analyzed_packets = report->get("analyzed-packets"); + ASSERT_TRUE(analyzed_packets); + EXPECT_EQ(Element::integer, analyzed_packets->getType()); + EXPECT_EQ(2, analyzed_packets->intValue()); } // Tests unusual values used to create the report. @@ -559,6 +592,26 @@ TEST_F(CommunicationStateTest, getReportDefaultValues) { ASSERT_TRUE(last_scopes); EXPECT_EQ(Element::list, last_scopes->getType()); EXPECT_TRUE(last_scopes->listValue().empty()); + + auto comm_interrupted = report->get("communication-interrupted"); + ASSERT_TRUE(comm_interrupted); + EXPECT_EQ(Element::boolean, comm_interrupted->getType()); + EXPECT_FALSE(comm_interrupted->boolValue()); + + auto clients_attempting = report->get("connecting-clients"); + ASSERT_TRUE(clients_attempting); + EXPECT_EQ(Element::integer, clients_attempting->getType()); + EXPECT_EQ(0, clients_attempting->intValue()); + + auto clients_unacked = report->get("unacked-clients"); + ASSERT_TRUE(clients_unacked); + EXPECT_EQ(Element::integer, clients_unacked->getType()); + EXPECT_EQ(0, clients_unacked->intValue()); + + auto packets_analyzed = report->get("analyzed-packets"); + ASSERT_TRUE(packets_analyzed); + EXPECT_EQ(Element::integer, packets_analyzed->getType()); + EXPECT_EQ(0, packets_analyzed->intValue()); } } 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 39713c7cef..bec75ae5e1 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc @@ -584,7 +584,12 @@ TEST_F(HAImplTest, statusGet) { " \"in-touch\": false," " \"last-scopes\": [ ]," " \"last-state\": \"\"," - " \"role\": \"secondary\"" + " \"role\": \"secondary\"," + " \"communication-interrupted\": false," + " \"connecting-clients\": 0," + " \"unacked-clients\": 0," + " \"unacked-clients-left\": 0," + " \"analyzed-packets\": 0" " }" " }," " \"pid\": 1" diff --git a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc index 3a77faea06..8b2aa09d63 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -1539,7 +1539,12 @@ TEST_F(HAServiceTest, hotStandbyScopeSelectionThisPrimary) { " \"in-touch\": false," " \"role\": \"standby\"," " \"last-scopes\": [ ]," - " \"last-state\": \"\"" + " \"last-state\": \"\"," + " \"communication-interrupted\": false," + " \"connecting-clients\": 0," + " \"unacked-clients\": 0," + " \"unacked-clients-left\": 0," + " \"analyzed-packets\": 0" " }" "}"; EXPECT_TRUE(isEquivalent(Element::fromJSON(expected), ha_servers)); @@ -1587,7 +1592,12 @@ TEST_F(HAServiceTest, hotStandbyScopeSelectionThisStandby) { " \"in-touch\": false," " \"role\": \"primary\"," " \"last-scopes\": [ ]," - " \"last-state\": \"\"" + " \"last-state\": \"\"," + " \"communication-interrupted\": false," + " \"connecting-clients\": 0," + " \"unacked-clients\": 0," + " \"unacked-clients-left\": 0," + " \"analyzed-packets\": 0" " }" "}"; EXPECT_TRUE(isEquivalent(Element::fromJSON(expected), ha_servers)); @@ -3604,7 +3614,12 @@ TEST_F(HAServiceStateMachineTest, waitingParterDownLoadBalancingPartnerDown) { " \"in-touch\": true," " \"role\": \"secondary\"," " \"last-scopes\": [ \"server1\", \"server2\" ]," - " \"last-state\": \"ready\"" + " \"last-state\": \"ready\"," + " \"communication-interrupted\": false," + " \"connecting-clients\": 0," + " \"unacked-clients\": 0," + " \"unacked-clients-left\": 0," + " \"analyzed-packets\": 0" " }" "}"; EXPECT_TRUE(isEquivalent(Element::fromJSON(expected), ha_servers));