Commit 7e90410c authored by Franciszek Gorski's avatar Franciszek Gorski Committed by Razvan Becheriu

[731-Kea_statistics_enhancements] new statistics commands

parent cdf12c66
......@@ -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.
......
......@@ -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");
}
......
......@@ -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 (...) {
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment