using namespace isc::dhcp;
using namespace isc::hooks;
using namespace isc::log;
+using namespace isc::stats;
namespace isc {
namespace ha {
.arg(ex.what());
// Increase the statistics of parse failures and dropped packets.
- isc::stats::StatsMgr::instance().addValue("pkt4-parse-failed",
- static_cast<int64_t>(1));
- isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
- static_cast<int64_t>(1));
+ StatsMgr::instance().addValue("pkt4-parse-failed", static_cast<int64_t>(1));
+ StatsMgr::instance().addValue("pkt4-receive-drop", static_cast<int64_t>(1));
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
LOG_DEBUG(ha_logger, DBGLVL_TRACE_BASIC, HA_SUBNET4_SELECT_NO_SUBNET_SELECTED)
.arg(query4->getLabel());
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt4-receive-drop", static_cast<int64_t>(1));
return;
}
.arg(query4->getLabel())
.arg(subnet4->toText());
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt4-receive-drop", static_cast<int64_t>(1));
return;
}
.arg(query4->getLabel())
.arg(subnet4->toText());
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt4-receive-drop", static_cast<int64_t>(1));
return;
}
.arg(query4->getLabel())
.arg(server_name);
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt4-receive-drop", static_cast<int64_t>(1));
return;
}
.arg(ex.what());
// Increase the statistics of parse failures and dropped packets.
- isc::stats::StatsMgr::instance().addValue("pkt6-parse-failed",
- static_cast<int64_t>(1));
- isc::stats::StatsMgr::instance().addValue("pkt6-receive-drop",
- static_cast<int64_t>(1));
+ StatsMgr::instance().addValue("pkt6-parse-failed", static_cast<int64_t>(1));
+ StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
LOG_DEBUG(ha_logger, DBGLVL_TRACE_BASIC, HA_SUBNET6_SELECT_NO_SUBNET_SELECTED)
.arg(query6->getLabel());
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
return;
}
.arg(query6->getLabel())
.arg(subnet6->toText());
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
return;
}
.arg(query6->getLabel())
.arg(subnet6->toText());
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
return;
}
.arg(query6->getLabel())
.arg(server_name);
callout_handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
+ StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
return;
}
#include <dhcpsrv/shared_network.h>
#include <dhcpsrv/subnet.h>
#include <hooks/hooks_manager.h>
+#include <stats/stats_mgr.h>
#include <testutils/gtest_utils.h>
#include <boost/pointer_cast.hpp>
#include <gtest/gtest.h>
using namespace isc::ha;
using namespace isc::ha::test;
using namespace isc::hooks;
+using namespace isc::stats;
namespace {
public:
/// @brief Constructor.
HAImplTest() {
+ // Clear statistics.
+ StatsMgr::instance().removeAll();
}
/// @brief Destructor.
io_service_->poll();
} catch (...) {
}
+ // Clear statistics.
+ StatsMgr::instance().removeAll();
+ }
+
+ /// @brief Fetches the current value of the given statistic.
+ ///
+ /// @param name name of the desired statistic.
+ /// @return Current value of the statistic, or zero if the
+ /// statistic is not found.
+ uint64_t getStatistic(const std::string& name) {
+ ObservationPtr stat = StatsMgr::instance().getObservation(name);
+ if (!stat) {
+ return (0);
+ }
+
+ return (stat->getInteger().first);
}
/// @brief Tests handler of a ha-sync command.
// Malformed message should not be classified.
EXPECT_TRUE(query4->getClasses().empty());
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt4-receive-drop"));
+
// Turn this into the DHCP message by appending a magic cookie and the
// options.
std::vector<uint8_t> magic_cookie = {
EXPECT_FALSE(query4->getOption(DHO_VIVSO_SUBOPTIONS));
// Domain name should not be skipped because the vendor option was truncated.
EXPECT_TRUE(query4->getOption(DHO_DOMAIN_NAME));
+
+ // Drop statistics should not change.
+ EXPECT_EQ(1, getStatistic("pkt4-receive-drop"));
}
// Tests subnet4_select callout implementation when the server name
// to which the query belongs.
ASSERT_EQ(1, query4->getClasses().size());
EXPECT_TRUE(query4->inClass("HA_server3"));
+
+ // Drop statistics should not increase.
+ EXPECT_EQ(0, getStatistic("pkt4-receive-drop"));
}
// Tests subnet4_select callout implementation when the server name
// to which the query belongs.
ASSERT_EQ(1, query4->getClasses().size());
EXPECT_TRUE(query4->inClass("HA_server3"));
+
+ // Drop statistics should not increase.
+ EXPECT_EQ(0, getStatistic("pkt4-receive-drop"));
}
// Tests that subnet4_select callout returns when there is a single relationship.
// because the callout didn't call the HAService::inScope function.
EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, callout_handle->getStatus());
EXPECT_TRUE(query4->getClasses().empty());
+
+ // Drop statistics should not increase.
+ EXPECT_EQ(0, getStatistic("pkt4-receive-drop"));
}
// Tests that the subnet4_select drops the packet when server name is not
// The request should be dropped and no classes assigned to it.
EXPECT_EQ(CalloutHandle::NEXT_STEP_DROP, callout_handle->getStatus());
EXPECT_TRUE(query4->getClasses().empty());
+
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt4-receive-drop"));
}
// Tests that the subnet4_select drops the packet when server name has
// The request should be dropped and no classes assigned to it.
EXPECT_EQ(CalloutHandle::NEXT_STEP_DROP, callout_handle->getStatus());
EXPECT_TRUE(query4->getClasses().empty());
+
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt4-receive-drop"));
}
// Tests that the subnet4_select drops the packet when server name is valid
// However, the class should be assigned after calling HAService::inScope.
ASSERT_EQ(1, query4->getClasses().size());
EXPECT_TRUE(query4->inClass("HA_server3"));
+
+ // Drop statistics should not increase when the server doesn't serve the
+ // particular scope.
+ EXPECT_EQ(0, getStatistic("pkt4-receive-drop"));
}
// Tests that the subnet4_select drops a packet when no subnet has been selected.
// No HA-specific classes should be assigned.
EXPECT_TRUE(query4->getClasses().empty());
+
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt4-receive-drop"));
}
// Tests for buffer6_receive callout implementation.
// Malformed message should not be classified.
EXPECT_TRUE(query6->getClasses().empty());
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt6-receive-drop"));
+
// Append transaction id (3 bytes, each set to 1).
msg.insert(msg.end(), 3, 1);
// to which the query belongs.
ASSERT_EQ(1, query6->getClasses().size());
EXPECT_TRUE(query6->inClass("HA_server3"));
+
+ // Drop statistics should not increase.
+ EXPECT_EQ(0, getStatistic("pkt6-receive-drop"));
}
// Tests that subnet6_select callout returns when there is a single relationship.
// because the callout didn't call the HAService::inScope function.
EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, callout_handle->getStatus());
EXPECT_TRUE(query6->getClasses().empty());
+
+ // Drop statistics should not increase.
+ EXPECT_EQ(0, getStatistic("pkt6-receive-drop"));
}
// Tests that the subnet6_select drops the packet when server name is not
// The request should be dropped and no classes assigned to it.
EXPECT_EQ(CalloutHandle::NEXT_STEP_DROP, callout_handle->getStatus());
EXPECT_TRUE(query6->getClasses().empty());
+
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt6-receive-drop"));
}
// Tests that the subnet6_select drops the packet when server name has
// The request should be dropped and no classes assigned to it.
EXPECT_EQ(CalloutHandle::NEXT_STEP_DROP, callout_handle->getStatus());
EXPECT_TRUE(query6->getClasses().empty());
+
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt6-receive-drop"));
}
// Tests that the subnet6_select drops the packet when server name is valid
// However, the class should be assigned after calling HAService::inScope.
ASSERT_EQ(1, query6->getClasses().size());
EXPECT_TRUE(query6->inClass("HA_server3"));
+
+ // Drop statistics should not increase when the server doesn't serve the
+ // particular scope.
+ EXPECT_EQ(0, getStatistic("pkt6-receive-drop"));
}
// Tests that the subnet6_select drops a packet when no subnet has been selected.
// No HA-specific classes should be assigned.
EXPECT_TRUE(query6->getClasses().empty());
+
+ // Drop statistics should have been increased.
+ EXPECT_EQ(1, getStatistic("pkt6-receive-drop"));
}
// Tests leases4_committed callout implementation.