summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2024-04-02 16:50:44 +0200
committerRazvan Becheriu <razvan@isc.org>2024-04-03 14:14:35 +0200
commit2a83ae203422090a744cb9a28dcc5498c22b40a3 (patch)
tree46040717075497045b9202148ccc27215120e871 /src
parent[#3297] PerfMonMgr::processPktEventStack tests (diff)
downloadkea-2a83ae203422090a744cb9a28dcc5498c22b40a3.tar.xz
kea-2a83ae203422090a744cb9a28dcc5498c22b40a3.zip
[#3297] pktX_send now calls processPktEventStack
src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc TEST_F(PerfMonLibLoadTest, verifyCallouts4) TEST_F(PerfMonLibLoadTest, verifyCallouts6) - new tests src/hooks/dhcp/perfmon/perfmon_callouts.cc pkt5_send(CalloutHandle& handle) pkt6_send(CalloutHandle& handle) - added logic to try-catch call processPktEventStack() src/hooks/dhcp/perfmon/perfmon_messages.mes PERFMON_DHCP4_PKT_PROCESS_ERROR PERFMON_DHCP6_PKT_PROCESS_ERROR - new debug messages
Diffstat (limited to 'src')
-rw-r--r--src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc61
-rw-r--r--src/hooks/dhcp/perfmon/perfmon_callouts.cc39
-rw-r--r--src/hooks/dhcp/perfmon/perfmon_messages.cc4
-rw-r--r--src/hooks/dhcp/perfmon/perfmon_messages.h2
-rw-r--r--src/hooks/dhcp/perfmon/perfmon_messages.mes14
5 files changed, 120 insertions, 0 deletions
diff --git a/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc b/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc
index e2996d245e..9a3f30c5ad 100644
--- a/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc
+++ b/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc
@@ -43,6 +43,27 @@ public:
unloadLibraries();
}
+ /// @brief Registers hooks in the hook manager.
+ /// Normally this is done by the server core code.
+ void registerHooks() {
+ if (isc::dhcp::CfgMgr::instance().getFamily() == AF_INET) {
+ hook_index_dhcpx_srv_configured_ = HooksManager::registerHook("dhcp4_srv_configured");
+ hook_index_pktx_send_ = HooksManager::registerHook("pkt4_send");
+ } else {
+ hook_index_dhcpx_srv_configured_ = HooksManager::registerHook("dhcp6_srv_configured");
+ hook_index_pktx_send_ = HooksManager::registerHook("pkt6_send");
+ }
+ }
+
+ /// @brief Checks that expected callouts are present.
+ void calloutsPresent() {
+ bool result;
+ ASSERT_NO_THROW_LOG(result = HooksManager::calloutsPresent(hook_index_dhcpx_srv_configured_));
+ EXPECT_TRUE(result);
+ ASSERT_NO_THROW_LOG(result = HooksManager::calloutsPresent(hook_index_pktx_send_));
+ EXPECT_TRUE(result);
+ }
+
/// @brief Creates a valid set configuration parameters valid for the library.
virtual isc::data::ElementPtr validConfigParams() {
std::string valid_config =
@@ -68,6 +89,10 @@ public:
// Convert JSON texts to Element map.
return (Element::fromJSON(valid_config));
}
+
+ /// @brief Hook index values.
+ int hook_index_pktx_send_;
+ int hook_index_dhcpx_srv_configured_;
};
// Simple V4 test that checks the library can be loaded and unloaded several times.
@@ -87,4 +112,40 @@ TEST_F(PerfMonLibLoadTest, invalidDaemonLoad) {
invalidDaemonTest("bogus");
}
+// Verifies that callout functions exist after loading the library.
+TEST_F(PerfMonLibLoadTest, verifyCallouts4) {
+ // Set family and daemon's proc name and register hook points.
+ isc::dhcp::CfgMgr::instance().setFamily(AF_INET);
+ isc::process::Daemon::setProcName("kea-dhcp4");
+ registerHooks();
+
+ // Add library to config and load it.
+ ASSERT_NO_THROW_LOG(addLibrary(lib_so_name_, valid_params_));
+ ASSERT_NO_THROW_LOG(loadLibraries());
+
+ // Verify that expected callouts are present.
+ calloutsPresent();
+
+ // Unload the library.
+ ASSERT_NO_THROW_LOG(unloadLibraries());
+}
+
+// Verifies that callout functions exist after loading the library.
+TEST_F(PerfMonLibLoadTest, verifyCallouts6) {
+ // Set family and daemon's proc name and register hook points.
+ isc::dhcp::CfgMgr::instance().setFamily(AF_INET6);
+ isc::process::Daemon::setProcName("kea-dhcp6");
+ registerHooks();
+
+ // Add library to config and load it.
+ ASSERT_NO_THROW_LOG(addLibrary(lib_so_name_, valid_params_));
+ ASSERT_NO_THROW_LOG(loadLibraries());
+
+ // Verify that expected callouts are present.
+ calloutsPresent();
+
+ // Unload the library.
+ ASSERT_NO_THROW_LOG(unloadLibraries());
+}
+
} // end of anonymous namespace
diff --git a/src/hooks/dhcp/perfmon/perfmon_callouts.cc b/src/hooks/dhcp/perfmon/perfmon_callouts.cc
index 49c2452d4e..99bdbb77fe 100644
--- a/src/hooks/dhcp/perfmon/perfmon_callouts.cc
+++ b/src/hooks/dhcp/perfmon/perfmon_callouts.cc
@@ -67,9 +67,28 @@ int pkt4_send(CalloutHandle& handle) {
Pkt4Ptr query;
handle.getArgument("query4", query);
+
+ Pkt4Ptr response;
+ handle.getArgument("response4", response);
+
+ Subnet4Ptr subnet;
+ handle.getArgument("subnet4", subnet);
+
+ if (!query) {
+ /// @todo this needs to be logged
+ return (0);
+ }
+
LOG_DEBUG(perfmon_logger, DBGLVL_TRACE_DETAIL, PERFMON_DHCP4_PKT_EVENTS)
.arg(query->getLabel())
.arg(query->dumpPktEvents());
+ try {
+ mgr->processPktEventStack(query, response, subnet->getID());
+ } catch (const std::exception& ex) {
+ LOG_DEBUG(perfmon_logger, DBGLVL_TRACE_DETAIL, PERFMON_DHCP4_PKT_PROCESS_ERROR)
+ .arg(query->getLabel())
+ .arg(ex.what());
+ }
return (0);
}
@@ -88,10 +107,30 @@ int pkt6_send(CalloutHandle& handle) {
Pkt6Ptr query;
handle.getArgument("query6", query);
+
+ Pkt6Ptr response;
+ handle.getArgument("response6", response);
+
+ Subnet6Ptr subnet;
+ handle.getArgument("subnet6", subnet);
+
+ if (!query) {
+ /// @todo this needs to be logged
+ return (0);
+ }
+
LOG_DEBUG(perfmon_logger, DBGLVL_TRACE_DETAIL, PERFMON_DHCP6_PKT_EVENTS)
.arg(query->getLabel())
.arg(query->dumpPktEvents());
+ try {
+ mgr->processPktEventStack(query, response, subnet->getID());
+ } catch (const std::exception& ex) {
+ LOG_DEBUG(perfmon_logger, DBGLVL_TRACE_DETAIL, PERFMON_DHCP6_PKT_PROCESS_ERROR)
+ .arg(query->getLabel())
+ .arg(ex.what());
+ }
+
return (0);
}
diff --git a/src/hooks/dhcp/perfmon/perfmon_messages.cc b/src/hooks/dhcp/perfmon/perfmon_messages.cc
index f3c1bdadb0..32edeff45a 100644
--- a/src/hooks/dhcp/perfmon/perfmon_messages.cc
+++ b/src/hooks/dhcp/perfmon/perfmon_messages.cc
@@ -9,8 +9,10 @@ extern const isc::log::MessageID PERFMON_ALARM_TRIGGERED = "PERFMON_ALARM_TRIGGE
extern const isc::log::MessageID PERFMON_DEINIT_FAILED = "PERFMON_DEINIT_FAILED";
extern const isc::log::MessageID PERFMON_DEINIT_OK = "PERFMON_DEINIT_OK";
extern const isc::log::MessageID PERFMON_DHCP4_PKT_EVENTS = "PERFMON_DHCP4_PKT_EVENTS";
+extern const isc::log::MessageID PERFMON_DHCP4_PKT_PROCESS_ERROR = "PERFMON_DHCP4_PKT_PROCESS_ERROR";
extern const isc::log::MessageID PERFMON_DHCP4_SOCKET_RECEIVED_TIME_SUPPORT = "PERFMON_DHCP4_SOCKET_RECEIVED_TIME_SUPPORT";
extern const isc::log::MessageID PERFMON_DHCP6_PKT_EVENTS = "PERFMON_DHCP6_PKT_EVENTS";
+extern const isc::log::MessageID PERFMON_DHCP6_PKT_PROCESS_ERROR = "PERFMON_DHCP6_PKT_PROCESS_ERROR";
extern const isc::log::MessageID PERFMON_DHCP6_SOCKET_RECEIVED_TIME_SUPPORT = "PERFMON_DHCP6_SOCKET_RECEIVED_TIME_SUPPORT";
extern const isc::log::MessageID PERFMON_INIT_FAILED = "PERFMON_INIT_FAILED";
extern const isc::log::MessageID PERFMON_INIT_OK = "PERFMON_INIT_OK";
@@ -23,8 +25,10 @@ const char* values[] = {
"PERFMON_DEINIT_FAILED", "unloading PerfMon hooks library failed: %1",
"PERFMON_DEINIT_OK", "unloading PerfMon hooks library successful",
"PERFMON_DHCP4_PKT_EVENTS", "query: %1 events=[%2]",
+ "PERFMON_DHCP4_PKT_PROCESS_ERROR", "Packet event stack was not processed for query %1, reason %2",
"PERFMON_DHCP4_SOCKET_RECEIVED_TIME_SUPPORT", "Kernel supports socket received time? %1",
"PERFMON_DHCP6_PKT_EVENTS", "query: %1 events=[%2]",
+ "PERFMON_DHCP6_PKT_PROCESS_ERROR", "Packet event stack was not processed for query %1, reason %2",
"PERFMON_DHCP6_SOCKET_RECEIVED_TIME_SUPPORT", "Kernel supports socket received time? %1",
"PERFMON_INIT_FAILED", "loading PerfMon hooks library failed: %1",
"PERFMON_INIT_OK", "loading PerfMon hooks library successful",
diff --git a/src/hooks/dhcp/perfmon/perfmon_messages.h b/src/hooks/dhcp/perfmon/perfmon_messages.h
index d87d8b722c..494bbc9dc3 100644
--- a/src/hooks/dhcp/perfmon/perfmon_messages.h
+++ b/src/hooks/dhcp/perfmon/perfmon_messages.h
@@ -10,8 +10,10 @@ extern const isc::log::MessageID PERFMON_ALARM_TRIGGERED;
extern const isc::log::MessageID PERFMON_DEINIT_FAILED;
extern const isc::log::MessageID PERFMON_DEINIT_OK;
extern const isc::log::MessageID PERFMON_DHCP4_PKT_EVENTS;
+extern const isc::log::MessageID PERFMON_DHCP4_PKT_PROCESS_ERROR;
extern const isc::log::MessageID PERFMON_DHCP4_SOCKET_RECEIVED_TIME_SUPPORT;
extern const isc::log::MessageID PERFMON_DHCP6_PKT_EVENTS;
+extern const isc::log::MessageID PERFMON_DHCP6_PKT_PROCESS_ERROR;
extern const isc::log::MessageID PERFMON_DHCP6_SOCKET_RECEIVED_TIME_SUPPORT;
extern const isc::log::MessageID PERFMON_INIT_FAILED;
extern const isc::log::MessageID PERFMON_INIT_OK;
diff --git a/src/hooks/dhcp/perfmon/perfmon_messages.mes b/src/hooks/dhcp/perfmon/perfmon_messages.mes
index 78cf358d83..85d893611b 100644
--- a/src/hooks/dhcp/perfmon/perfmon_messages.mes
+++ b/src/hooks/dhcp/perfmon/perfmon_messages.mes
@@ -56,3 +56,17 @@ triggered and this message will be repeated every alarm-report-secs.
Arguments detail the alarm's key, the time the alarm was first
triggered, the most recent reported average, and the high-watr-ms
value.
+
+% PERFMON_DHCP4_PKT_PROCESS_ERROR Packet event stack was not processed for query %1, reason %2
+This debug message is emitted when the a query's event stack could not
+be processed. This is most likely a programmatic error and should be
+reported. The arguments identify the query and the reason it could
+not be processed. These errors should not affect server's normal
+operations.
+
+% PERFMON_DHCP6_PKT_PROCESS_ERROR Packet event stack was not processed for query %1, reason %2
+This debug message is emitted when the a query's event stack could not
+be processed. This is most likely a programmatic error and should be
+reported. The arguments identify the query and the reason it could
+not be processed. These errors should not affect server's normal
+operations.