]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[731-Kea_statistics_enhancements] new statistics commands
authorFranciszek Gorski <fagorski9@gmail.com>
Wed, 17 Jul 2019 17:13:26 +0000 (19:13 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 5 Aug 2019 17:34:27 +0000 (20:34 +0300)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc

index b74f149f7d225343151fb263c3883977398665c3..a6af5b31460c584b9dfa7bd934d1307fbe985f0c 100644 (file)
@@ -864,6 +864,19 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P
     CommandMgr::instance().registerCommand("statistic-remove-all",
         boost::bind(&StatsMgr::statisticRemoveAllHandler, _1, _2));
 
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-age",
+        boost::bind(&StatsMgr::statisticSetMaxSampleAgeHandler, _1, _2));
+
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-count",
+        boost::bind(&StatsMgr::statisticSetMaxSampleCountHandler, _1, _2));
+
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-age-all",
+        boost::bind(&StatsMgr::statisticSetMaxSampleAgeAllHandler, _1, _2));
+
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all",
+        boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2));
+
+
 }
 
 void ControlledDhcpv4Srv::shutdown() {
@@ -903,8 +916,13 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
         CommandMgr::instance().deregisterCommand("statistic-remove-all");
         CommandMgr::instance().deregisterCommand("statistic-reset");
         CommandMgr::instance().deregisterCommand("statistic-reset-all");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age-all");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count-all");
         CommandMgr::instance().deregisterCommand("version-get");
 
+
     } catch (...) {
         // Don't want to throw exceptions from the destructor. The server
         // is shutting down anyway.
index 9a0cc3ee63fc7c28d96412f608a66cd99aaa4c95..9aed6c614739cb951cb11524e98d738ea5058e4f 100644 (file)
@@ -491,6 +491,10 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commandsRegistration) {
     EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"statistic-reset\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"statistic-reset-all\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age-all\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count-all\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos);
 
     // Ok, and now delete the server. It should deregister its commands.
@@ -709,6 +713,34 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) {
                     "  \"arguments\": {}}", response);
     EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }",
               response);
+
+    // Check statistic-set-max-sample-age
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age\", "
+                    "  \"arguments\": {"
+                    "  \"name\":\"bogus\", \"duration\": 1245 }}", response);
+    EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }",
+              response);
+
+    // Check statistic-set-max-sample-age-all
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age-all\", "
+                    "  \"arguments\": {"
+                    "  \"duration\": 1245 }}", response);
+    EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics duration limit are set.\" }",
+              response);
+
+    // Check statistic-set-max-sample-count
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count\", "
+                    "  \"arguments\": {"
+                    "  \"name\":\"bogus\", \"max-samples\": 100 }}", response);
+    EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }",
+              response);
+
+    // Check statistic-set-max-sample-count-all
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count-all\", "
+                    "  \"arguments\": {"
+                    "  \"max-samples\": 100 }}", response);
+    EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics count limit are set.\" }",
+              response);
 }
 
 // Check that the "config-set" command will replace current configuration
@@ -883,6 +915,10 @@ TEST_F(CtrlChannelDhcpv4SrvTest, listCommands) {
     checkListCommands(rsp, "statistic-remove-all");
     checkListCommands(rsp, "statistic-reset");
     checkListCommands(rsp, "statistic-reset-all");
+    checkListCommands(rsp, "statistic-set-max-sample-age");
+    checkListCommands(rsp, "statistic-set-max-sample-age-all");
+    checkListCommands(rsp, "statistic-set-max-sample-count");
+    checkListCommands(rsp, "statistic-set-max-sample-count-all");
     checkListCommands(rsp, "version-get");
 }
 
index aba2e9b091ec71759f3d7735bf44e42d714831fc..6d4a74b3d1898817b8b93cb29d093c3fe1d481c2 100644 (file)
@@ -887,6 +887,18 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port,
 
     CommandMgr::instance().registerCommand("statistic-remove-all",
         boost::bind(&StatsMgr::statisticRemoveAllHandler, _1, _2));
+
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-age",
+        boost::bind(&StatsMgr::statisticSetMaxSampleAgeHandler, _1, _2));
+
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-count",
+        boost::bind(&StatsMgr::statisticSetMaxSampleCountHandler, _1, _2));
+
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-age-all",
+        boost::bind(&StatsMgr::statisticSetMaxSampleAgeAllHandler, _1, _2));
+
+    CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all",
+        boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2));
 }
 
 void ControlledDhcpv6Srv::shutdown() {
@@ -926,6 +938,10 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() {
         CommandMgr::instance().deregisterCommand("statistic-remove-all");
         CommandMgr::instance().deregisterCommand("statistic-reset");
         CommandMgr::instance().deregisterCommand("statistic-reset-all");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age-all");
+        CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count-all");        
         CommandMgr::instance().deregisterCommand("version-get");
 
     } catch (...) {
index d0dfb536e86649b9d63137a7224a74d1647ebe46..733ca4e8f183d61222afb9c9dd302347977b0dde 100644 (file)
@@ -798,6 +798,10 @@ TEST_F(CtrlDhcpv6SrvTest, commandsRegistration) {
     EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"statistic-reset\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"statistic-reset-all\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age-all\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count-all\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos);
 
     // Ok, and now delete the server. It should deregister its commands.
@@ -1023,6 +1027,34 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) {
                     "  \"arguments\": {}}", response);
     EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }",
               response);
+
+    // Check statistic-set-max-sample-age
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age\", "
+                    "  \"arguments\": {"
+                    "  \"name\":\"bogus\", \"duration\": 1245 }}", response);
+    EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }",
+              response);
+
+    // Check statistic-set-max-sample-age-all
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age-all\", "
+                    "  \"arguments\": {"
+                    "  \"duration\": 1245 }}", response);
+    EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics duration limit are set.\" }",
+              response);
+
+    // Check statistic-set-max-sample-count
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count\", "
+                    "  \"arguments\": {"
+                    "  \"name\":\"bogus\", \"max-samples\": 100 }}", response);
+    EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }",
+              response);
+
+    // Check statistic-set-max-sample-count-all
+    sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count-all\", "
+                    "  \"arguments\": {"
+                    "  \"max-samples\": 100 }}", response);
+    EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics count limit are set.\" }",
+              response);
 }
 
 // Tests that the server properly responds to shtudown command sent
@@ -1054,6 +1086,10 @@ TEST_F(CtrlChannelDhcpv6SrvTest, commandsList) {
     checkListCommands(rsp, "statistic-remove-all");
     checkListCommands(rsp, "statistic-reset");
     checkListCommands(rsp, "statistic-reset-all");
+    checkListCommands(rsp, "statistic-set-max-sample-age");
+    checkListCommands(rsp, "statistic-set-max-sample-age-all");
+    checkListCommands(rsp, "statistic-set-max-sample-count");
+    checkListCommands(rsp, "statistic-set-max-sample-count-all");    
 }
 
 // Tests if the server returns its configuration using config-get.