]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1087] Return additional parameters
authorMarcin Siodelski <marcin@isc.org>
Fri, 15 May 2020 16:55:05 +0000 (18:55 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 20 May 2020 15:48:16 +0000 (17:48 +0200)
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.

src/hooks/dhcp/high_availability/communication_state.cc
src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc

index e4dfcc0f9e50eb6d16a2288a285daa5c11a9f3c8..8500d4663e93a7153d2841b46157b4944d4fe328 100644 (file)
@@ -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<long long>(getConnectingClientsCount())));
+    report->set("unacked-clients", Element::create(static_cast<long long>(getUnackedClientsCount())));
+
+    long long unacked_clients_left = 0;
+    if (isCommunicationInterrupted() && (config_->getMaxUnackedClients() > getUnackedClientsCount())) {
+        unacked_clients_left = static_cast<long long>(config_->getMaxUnackedClients() -
+                                                      getUnackedClientsCount());
+    }
+    report->set("unacked-clients-left", Element::create(unacked_clients_left));
+    report->set("analyzed-packets", Element::create(static_cast<long long>(getAnalyzedMessagesCount())));
 
     return (report);
 }
index 2fa03725e8a2af64f09f44c0d8dbce7557ab4d4f..032ff7a3e583fda47fa887ba1c14caa839003e50 100644 (file)
@@ -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());
 }
 
 }
index 39713c7cefad499498b27a127f4bd9d0f6ac7aa4..bec75ae5e1196a523053b7ea67a11421d2a908b6 100644 (file)
@@ -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"
index 3a77faea06a67df3bb7a92707a09624da797c1c2..8b2aa09d6303b58b4d7c17bb528595b8f275f0b6 100644 (file)
@@ -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));