diff --git a/configure.ac b/configure.ac index c2f1e55b6f..ec8e3267d2 100644 --- a/configure.ac +++ b/configure.ac @@ -1581,6 +1581,9 @@ AC_CONFIG_FILES([src/hooks/dhcp/stat_cmds/tests/Makefile]) AC_CONFIG_FILES([src/hooks/dhcp/user_chk/Makefile]) AC_CONFIG_FILES([src/hooks/dhcp/user_chk/tests/Makefile]) AC_CONFIG_FILES([src/hooks/dhcp/user_chk/tests/test_data_files_config.h]) +AC_CONFIG_FILES([src/hooks/dhcp/perfmon/Makefile]) +AC_CONFIG_FILES([src/hooks/dhcp/perfmon/libloadtests/Makefile]) +AC_CONFIG_FILES([src/hooks/dhcp/perfmon/tests/Makefile]) AC_CONFIG_FILES([src/lib/Makefile]) AC_CONFIG_FILES([src/lib/asiodns/Makefile]) AC_CONFIG_FILES([src/lib/asiodns/tests/Makefile]) diff --git a/doc/sphinx/arm/hooks-perfmon.rst b/doc/sphinx/arm/hooks-perfmon.rst new file mode 100644 index 0000000000..3c039dc011 --- /dev/null +++ b/doc/sphinx/arm/hooks-perfmon.rst @@ -0,0 +1,39 @@ +.. ischooklib:: libdhcp_perfmon.so +.. _hooks-perfmon: + +``libdhcp_perfmon.so``: PerfMon +=============================== + +This hook library can be loaded by either kea-dhcp4 or kea-dhcp6 servers +to extend them with the ability to track and report performance related data. + +.. note:: + + This library is currently under development and not yet functional. + +Overview +~~~~~~~~ + +The library, added in Kea 2.5.6, can be loaded by the :iscman:`kea-dhcp4` or +:iscman:`kea-dhcp6` daemon by adding it to the ``hooks-libraries`` element of +the server's configuration: + +.. code-block:: javascript + + { + "hooks-libraries": [ + { + "library": "/usr/local/lib/libdhcp_perfmon.so", + "parameters": { + ... + } + }, + ... + ], + ... + } + +Configuration +~~~~~~~~~~~~~ + + TBD diff --git a/doc/sphinx/arm/hooks.rst b/doc/sphinx/arm/hooks.rst index 606efe3c8b..73a26b900c 100644 --- a/doc/sphinx/arm/hooks.rst +++ b/doc/sphinx/arm/hooks.rst @@ -527,6 +527,10 @@ loaded by the correct process per the table below. | | | a repository for the Kea configuration information. Kea | | | | servers use this library to fetch their configurations. | +-----------------------------------------------------------+--------------+--------------------------------------------------------------+ + | :ref:`PerfMon ` | Kea open | With this hook library, :iscman:`kea-dhcp4` server and | + | | source | :iscman:`kea-dhcp6` servers can track and report performance | + | | | data. CURRENTLY UNDER DEVELOPMENT | + +-----------------------------------------------------------+--------------+--------------------------------------------------------------+ | :ref:`Ping Check ` | ISC support | With this hook library, :iscman:`kea-dhcp4` server can | | | customers | perform ping checks of candidate lease addresses before | | | | offering them to clients. | @@ -611,6 +615,7 @@ sections. .. include:: hooks-legal-log.rst .. include:: hooks-limits.rst .. include:: hooks-cb-mysql.rst +.. include:: hooks-perfmon.rst .. include:: hooks-ping-check.rst .. include:: hooks-cb-pgsql.rst .. include:: hooks-radius.rst diff --git a/doc/sphinx/arm/logging.rst b/doc/sphinx/arm/logging.rst index 4f3780ce1c..834cdd5655 100644 --- a/doc/sphinx/arm/logging.rst +++ b/doc/sphinx/arm/logging.rst @@ -427,6 +427,10 @@ libraries), or hook libraries (open source or premium). | | | message carried in | | | | the packet is parsed. | +----------------------------------+---------------------------------------+--------------------------------+ + | ``kea-dhcp4.perfmon-hooks`` | :ischooklib:`libdhcp_perfmon.so` | Used | + | ``kea-dhcp6.perfmon-hooks`` | open-source hook library | to log messages related to | + | | | performan monitoring. | + +----------------------------------+---------------------------------------+--------------------------------+ | ``kea-dhcp4.ping-check-hooks`` | :ischooklib:`libdhcp_ping_check.so` | Used | | | subscription hook library | to log messages related to | | | | carrying out pre-offer ping | diff --git a/doc/sphinx/arm/rst_arm_sources.mk b/doc/sphinx/arm/rst_arm_sources.mk index 6ed67efbca..dc2cf45e41 100644 --- a/doc/sphinx/arm/rst_arm_sources.mk +++ b/doc/sphinx/arm/rst_arm_sources.mk @@ -31,6 +31,7 @@ rst_arm_sources += arm/hooks-limits.rst rst_arm_sources += arm/hooks-cb-mysql.rst rst_arm_sources += arm/hooks-cb-pgsql.rst rst_arm_sources += arm/hooks-legal-log.rst +rst_arm_sources += arm/hooks-perfmon.rst rst_arm_sources += arm/hooks-ping-check.rst rst_arm_sources += arm/hooks-radius.rst rst_arm_sources += arm/hooks-rbac.rst diff --git a/doc/sphinx/conf.py b/doc/sphinx/conf.py index 3fe30f5de5..29f49b8211 100644 --- a/doc/sphinx/conf.py +++ b/doc/sphinx/conf.py @@ -96,6 +96,7 @@ exclude_patterns = [ 'arm/hooks-lease-cmds.rst', 'arm/hooks-lease-query.rst', 'arm/hooks-limits.rst', + 'arm/hooks-perfmon.rst', 'arm/hooks-ping-check.rst', 'arm/hooks-radius.rst', 'arm/hooks-rbac.rst', diff --git a/src/hooks/dhcp/Makefile.am b/src/hooks/dhcp/Makefile.am index e9d64c44e4..1b77976424 100644 --- a/src/hooks/dhcp/Makefile.am +++ b/src/hooks/dhcp/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = bootp flex_option high_availability lease_cmds +SUBDIRS = bootp flex_option high_availability lease_cmds perfmon if HAVE_MYSQL SUBDIRS += mysql_cb diff --git a/src/hooks/dhcp/perfmon/.gitattributes b/src/hooks/dhcp/perfmon/.gitattributes new file mode 100644 index 0000000000..5663e7eef0 --- /dev/null +++ b/src/hooks/dhcp/perfmon/.gitattributes @@ -0,0 +1,2 @@ +/perfmon_messages.cc -diff merge=ours +/perfmon_messages.h -diff merge=ours diff --git a/src/hooks/dhcp/perfmon/.gitignore b/src/hooks/dhcp/perfmon/.gitignore new file mode 100644 index 0000000000..35b5e99aee --- /dev/null +++ b/src/hooks/dhcp/perfmon/.gitignore @@ -0,0 +1 @@ +/html diff --git a/src/hooks/dhcp/perfmon/Makefile.am b/src/hooks/dhcp/perfmon/Makefile.am new file mode 100644 index 0000000000..e032c66f55 --- /dev/null +++ b/src/hooks/dhcp/perfmon/Makefile.am @@ -0,0 +1,86 @@ +SUBDIRS = . tests libloadtests + +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CXXFLAGS = $(KEA_CXXFLAGS) + +# Ensure that the message file and doxygen file is included in the distribution +EXTRA_DIST = perfmon_messages.mes +EXTRA_DIST += perfmon.dox + +CLEANFILES = *.gcno *.gcda + +# convenience archive + +noinst_LTLIBRARIES = libperfmon.la + +libperfmon_la_SOURCES = perfmon_callouts.cc +libperfmon_la_SOURCES += perfmon_log.cc perfmon_log.h +libperfmon_la_SOURCES += perfmon_messages.cc perfmon_messages.h +libperfmon_la_SOURCES += version.cc + +libperfmon_la_CXXFLAGS = $(AM_CXXFLAGS) +libperfmon_la_CPPFLAGS = $(AM_CPPFLAGS) + +# install the shared object into $(libdir)/kea/hooks +lib_hooksdir = $(libdir)/kea/hooks +lib_hooks_LTLIBRARIES = libdhcp_perfmon.la + +libdhcp_perfmon_la_SOURCES = +libdhcp_perfmon_la_LDFLAGS = $(AM_LDFLAGS) +libdhcp_perfmon_la_LDFLAGS += -avoid-version -export-dynamic -module +libdhcp_perfmon_la_LIBADD = libperfmon.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/process/libkea-process.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/eval/libkea-eval.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/stats/libkea-stats.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/http/libkea-http.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/database/libkea-database.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/dns/libkea-dns++.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/util/libkea-util.la +libdhcp_perfmon_la_LIBADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +libdhcp_perfmon_la_LIBADD += $(LOG4CPLUS_LIBS) +libdhcp_perfmon_la_LIBADD += $(CRYPTO_LIBS) +libdhcp_perfmon_la_LIBADD += $(BOOST_LIBS) + +# If we want to get rid of all generated messages files, we need to use +# make maintainer-clean. The proper way to introduce custom commands for +# that operation is to define maintainer-clean-local target. However, +# make maintainer-clean also removes Makefile, so running configure script +# is required. To make it easy to rebuild messages without going through +# reconfigure, a new target messages-clean has been added. +maintainer-clean-local: + rm -f perfmon_messages.h perfmon_messages.cc + +# To regenerate messages files, one can do: +# +# make messages-clean +# make messages +# +# This is needed only when a .mes file is modified. +messages-clean: maintainer-clean-local + +if GENERATE_MESSAGES + +# Define rule to build logging source files from message file +messages: perfmon_messages.h perfmon_messages.cc + @echo Message files regenerated + +perfmon_messages.h perfmon_messages.cc: perfmon_messages.mes + $(top_builddir)/src/lib/log/compiler/kea-msg-compiler $(top_srcdir)/src/hooks/dhcp/perfmon/perfmon_messages.mes + +else + +messages perfmon_messages.h perfmon_messages.cc: + @echo Messages generation disabled. Configure with --enable-generate-messages to enable it. + +endif + diff --git a/src/hooks/dhcp/perfmon/libloadtests/.gitignore b/src/hooks/dhcp/perfmon/libloadtests/.gitignore new file mode 100644 index 0000000000..ada6ed5036 --- /dev/null +++ b/src/hooks/dhcp/perfmon/libloadtests/.gitignore @@ -0,0 +1 @@ +hook_load_unittests diff --git a/src/hooks/dhcp/perfmon/libloadtests/Makefile.am b/src/hooks/dhcp/perfmon/libloadtests/Makefile.am new file mode 100644 index 0000000000..2f1261022f --- /dev/null +++ b/src/hooks/dhcp/perfmon/libloadtests/Makefile.am @@ -0,0 +1,55 @@ +SUBDIRS = . + +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += -I$(top_builddir)/src/hooks/dhcp/perfmon -I$(top_srcdir)/src/hooks/dhcp/perfmon +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CPPFLAGS += -DLIBDHCP_PERFMON_SO=\"$(abs_top_builddir)/src/hooks/dhcp/perfmon/.libs/libdhcp_perfmon.so\" +AM_CXXFLAGS = $(KEA_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +EXTRA_DIST = + +CLEANFILES = *.gcno *.gcda + +TESTS_ENVIRONMENT = \ + $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND) + +if HAVE_GTEST + +TESTS = hook_load_unittests + +hook_load_unittests_SOURCES = +hook_load_unittests_SOURCES += load_unload_unittests.cc +hook_load_unittests_SOURCES += run_unittests.cc +hook_load_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES) +hook_load_unittests_CXXFLAGS = $(AM_CXXFLAGS) +hook_load_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) + +hook_load_unittests_LDADD = $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la +hook_load_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +hook_load_unittests_LDADD += $(LOG4CPLUS_LIBS) +hook_load_unittests_LDADD += $(CRYPTO_LIBS) +hook_load_unittests_LDADD += $(BOOST_LIBS) +hook_load_unittests_LDADD += $(GTEST_LDADD) + +noinst_PROGRAMS = $(TESTS) + +endif diff --git a/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc b/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc new file mode 100644 index 0000000000..981ba8db79 --- /dev/null +++ b/src/hooks/dhcp/perfmon/libloadtests/load_unload_unittests.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +/// @file This file contains tests which exercise the load and unload +/// functions in the perfmon hook library. In order to test the load +/// function, one must be able to pass it hook library parameters. The +/// the only way to populate these parameters is by actually loading the +/// library via HooksManager::loadLibraries(). + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace std; +using namespace isc; +using namespace isc::hooks; +using namespace isc::data; +using namespace isc::dhcp; +using namespace isc::process; + +namespace { + +/// @brief Test fixture for testing loading and unloading the stat cmds library +class PerfMonLibLoadTest : public isc::test::LibLoadTest { +public: + /// @brief Constructor + PerfMonLibLoadTest() : LibLoadTest(LIBDHCP_PERFMON_SO) { + } + + /// @brief Destructor + virtual ~PerfMonLibLoadTest() { + unloadLibraries(); + } +}; + +// Simple V4 test that checks the library can be loaded and unloaded several times. +TEST_F(PerfMonLibLoadTest, validLoad4) { + validDaemonTest("kea-dhcp4"); +} + +// Simple V6 test that checks the library can be loaded and unloaded several times. +TEST_F(PerfMonLibLoadTest, validLoad6) { + validDaemonTest("kea-dhcp6", AF_INET6); +} + +// Simple V6 test that checks the library cannot by loaded by invalid daemons. +TEST_F(PerfMonLibLoadTest, invalidDaemonLoad) { + invalidDaemonTest("kea-ctrl-agent"); + invalidDaemonTest("kea-dhcp-ddns"); + invalidDaemonTest("bogus"); +} + +} // end of anonymous namespace diff --git a/src/hooks/dhcp/perfmon/libloadtests/run_unittests.cc b/src/hooks/dhcp/perfmon/libloadtests/run_unittests.cc new file mode 100644 index 0000000000..d9e195d96f --- /dev/null +++ b/src/hooks/dhcp/perfmon/libloadtests/run_unittests.cc @@ -0,0 +1,20 @@ +// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the End User License +// Agreement. See COPYING file in the premium/ directory. + +#include + +#include + +#include + +int +main(int argc, char* argv[]) { + ::testing::InitGoogleTest(&argc, argv); + isc::log::initLogger(); + + int result = RUN_ALL_TESTS(); + + return (result); +} diff --git a/src/hooks/dhcp/perfmon/perfmon.dox b/src/hooks/dhcp/perfmon/perfmon.dox new file mode 100644 index 0000000000..02552fca1b --- /dev/null +++ b/src/hooks/dhcp/perfmon/perfmon.dox @@ -0,0 +1,43 @@ +// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +/** + +@page libdhcp_perfmon Kea PerfMon Hooks Library + +@section libdhcp_perfmonIntro Introduction + +Welcome to Kea PerfMon Hooks Library. This documentation is addressed to +developers who are interested in the internal operation of the PerfMon +library. This file provides information needed to understand and perhaps extend +this library. + +This documentation is stand-alone: you should have read and understood the Kea Developer's Guide and in +particular its section about hooks. + +@section perfmon PerfMon Overview + +PerfMon (or perfmon) is a Hook library that can be loaded by +either kea-dhcp4 and kea-dhcp6 servers to extend them with the +ability to track and report performance related data. + +The initial purpose of this library is provide supplemental data and +commands for monitoring the performance of kea-dhcp4 and kea-dhcp6 +servers in real time. + + + + THIS LIBRARY IS CURRENTLY UNDER DEVELOPMENT + + + + +@section perfmonMTCompatibility Multi-Threading Compatibility + +The PerfMon Hook library is compatible with multi-threading. + +*/ diff --git a/src/hooks/dhcp/perfmon/perfmon_callouts.cc b/src/hooks/dhcp/perfmon/perfmon_callouts.cc new file mode 100644 index 0000000000..635e7d9f17 --- /dev/null +++ b/src/hooks/dhcp/perfmon/perfmon_callouts.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +// Functions accessed by the hooks framework use C linkage to avoid the name +// mangling that accompanies use of the C++ compiler as well as to avoid +// issues related to namespaces. + +#include + +#include +#include +#include +#include +#include + +using namespace isc::dhcp; +using namespace isc::hooks; +using namespace isc::process; +using namespace isc::perfmon; + +extern "C" { + +/// @brief This callout is called at the "pkt4_send" hook. +/// +/// @param handle CalloutHandle which provides access to context. +/// +/// @return 0 upon success, non-zero otherwise. +int pkt4_send(CalloutHandle& handle) { + CalloutHandle::CalloutNextStep status = handle.getStatus(); + if (status == CalloutHandle::NEXT_STEP_DROP || + status == CalloutHandle::NEXT_STEP_SKIP) { + return (0); + } + + return (0); +} + +/// @brief This callout is called at the "pkt6_send" hook. +/// +/// @param handle CalloutHandle which provides access to context. +/// +/// @return 0 upon success, non-zero otherwise. +int pkt6_send(CalloutHandle& handle) { + CalloutHandle::CalloutNextStep status = handle.getStatus(); + if (status == CalloutHandle::NEXT_STEP_DROP || + status == CalloutHandle::NEXT_STEP_SKIP) { + return (0); + } + + return (0); +} + +/// @brief This function is called when the library is loaded. +/// +/// @param handle library handle +/// @return 0 when initialization is successful, 1 otherwise +int load(LibraryHandle& /* handle */) { + // Make the hook library not loadable by d2 or ca. + uint16_t family = CfgMgr::instance().getFamily(); + const std::string& proc_name = Daemon::getProcName(); + if (family == AF_INET) { + if (proc_name != "kea-dhcp4") { + isc_throw(isc::Unexpected, "Bad process name: " << proc_name + << ", expected kea-dhcp4"); + } + } else { + if (proc_name != "kea-dhcp6") { + isc_throw(isc::Unexpected, "Bad process name: " << proc_name + << ", expected kea-dhcp6"); + } + } + + /// @todo register commands + /// handle.registerCommandCallout("command-here", handler_here); + + LOG_INFO(perfmon_logger, PERFMON_INIT_OK); + return (0); +} + +/// @brief This function is called when the library is unloaded. +/// +/// @return 0 if deregistration was successful, 1 otherwise +int unload() { + LOG_INFO(perfmon_logger, PERFMON_DEINIT_OK); + return (0); +} + +/// @brief This function is called to retrieve the multi-threading compatibility. +/// +/// @return 1 which means compatible with multi-threading. +int multi_threading_compatible() { + return (1); +} + +} // end extern "C" diff --git a/src/hooks/dhcp/perfmon/perfmon_log.cc b/src/hooks/dhcp/perfmon/perfmon_log.cc new file mode 100644 index 0000000000..29d49c9d22 --- /dev/null +++ b/src/hooks/dhcp/perfmon/perfmon_log.cc @@ -0,0 +1,18 @@ +// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include + +namespace isc { +namespace perfmon { + +isc::log::Logger perfmon_logger("perfmon-hooks"); + +} +} + diff --git a/src/hooks/dhcp/perfmon/perfmon_log.h b/src/hooks/dhcp/perfmon/perfmon_log.h new file mode 100644 index 0000000000..70d00b2736 --- /dev/null +++ b/src/hooks/dhcp/perfmon/perfmon_log.h @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef PERFMON_LOG_H +#define PERFMON_LOG_H + +#include +#include +#include + +namespace isc { +namespace perfmon { + +extern isc::log::Logger perfmon_logger; + +} // end of isc::perfmon +} // end of isc namespace + + +#endif diff --git a/src/hooks/dhcp/perfmon/perfmon_messages.cc b/src/hooks/dhcp/perfmon/perfmon_messages.cc new file mode 100644 index 0000000000..280c876ad0 --- /dev/null +++ b/src/hooks/dhcp/perfmon/perfmon_messages.cc @@ -0,0 +1,25 @@ +// File created from ../../../../src/hooks/dhcp/perfmon/perfmon_messages.mes + +#include +#include +#include + +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_INIT_FAILED = "PERFMON_INIT_FAILED"; +extern const isc::log::MessageID PERFMON_INIT_OK = "PERFMON_INIT_OK"; + +namespace { + +const char* values[] = { + "PERFMON_DEINIT_FAILED", "unloading PerfMon hooks library failed: %1", + "PERFMON_DEINIT_OK", "unloading PerfMon hooks library successful", + "PERFMON_INIT_FAILED", "loading PerfMon hooks library failed: %1", + "PERFMON_INIT_OK", "loading PerfMon hooks library successful", + NULL +}; + +const isc::log::MessageInitializer initializer(values); + +} // Anonymous namespace + diff --git a/src/hooks/dhcp/perfmon/perfmon_messages.h b/src/hooks/dhcp/perfmon/perfmon_messages.h new file mode 100644 index 0000000000..192cbd470f --- /dev/null +++ b/src/hooks/dhcp/perfmon/perfmon_messages.h @@ -0,0 +1,13 @@ +// File created from ../../../../src/hooks/dhcp/perfmon/perfmon_messages.mes + +#ifndef PERFMON_MESSAGES_H +#define PERFMON_MESSAGES_H + +#include + +extern const isc::log::MessageID PERFMON_DEINIT_FAILED; +extern const isc::log::MessageID PERFMON_DEINIT_OK; +extern const isc::log::MessageID PERFMON_INIT_FAILED; +extern const isc::log::MessageID PERFMON_INIT_OK; + +#endif // PERFMON_MESSAGES_H diff --git a/src/hooks/dhcp/perfmon/perfmon_messages.mes b/src/hooks/dhcp/perfmon/perfmon_messages.mes new file mode 100644 index 0000000000..6b80fe63de --- /dev/null +++ b/src/hooks/dhcp/perfmon/perfmon_messages.mes @@ -0,0 +1,19 @@ +# Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC") + +% PERFMON_DEINIT_FAILED unloading PerfMon hooks library failed: %1 +This error message indicates an error unloading the PerfMon hooks +library. The details of the error are provided as argument of +the log message. + +% PERFMON_DEINIT_OK unloading PerfMon hooks library successful +This info message indicates that the PerfMon hooks library has been +removed successfully. + +% PERFMON_INIT_FAILED loading PerfMon hooks library failed: %1 +This error message indicates an error during loading the PerfMon +hooks library. The details of the error are provided as argument of +the log message. + +% PERFMON_INIT_OK loading PerfMon hooks library successful +This info message indicates that the PerfMon hooks library has been +loaded successfully. Enjoy! diff --git a/src/hooks/dhcp/perfmon/tests/.gitignore b/src/hooks/dhcp/perfmon/tests/.gitignore new file mode 100644 index 0000000000..442389384e --- /dev/null +++ b/src/hooks/dhcp/perfmon/tests/.gitignore @@ -0,0 +1 @@ +perfmon_unittests diff --git a/src/hooks/dhcp/perfmon/tests/Makefile.am b/src/hooks/dhcp/perfmon/tests/Makefile.am new file mode 100644 index 0000000000..050fb155ea --- /dev/null +++ b/src/hooks/dhcp/perfmon/tests/Makefile.am @@ -0,0 +1,56 @@ +SUBDIRS = . + +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += -I$(top_builddir)/src/hooks/dhcp/perfmon -I$(top_srcdir)/src/hooks/dhcp/perfmon +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CPPFLAGS += -DPERFMON_LIB_SO=\"$(abs_top_builddir)/src/hooks/dhcp/perfmon/.libs/libdhcp_perfmon.so\" +AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\" + +AM_CXXFLAGS = $(KEA_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +# Unit test data files need to get installed. +EXTRA_DIST = + +CLEANFILES = *.gcno *.gcda + +TESTS_ENVIRONMENT = $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND) + +LOG_COMPILER = $(LIBTOOL) +AM_LOG_FLAGS = --mode=execute + +TESTS = +if HAVE_GTEST +TESTS += perfmon_unittests + +perfmon_unittests_SOURCES = run_unittests.cc +#perfmon_unittests_SOURCES += perfmon_unittests.cc + +perfmon_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES) + +perfmon_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS) + +perfmon_unittests_CXXFLAGS = $(AM_CXXFLAGS) + +perfmon_unittests_LDADD = $(top_builddir)/src/hooks/dhcp/perfmon/libperfmon.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la +perfmon_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +perfmon_unittests_LDADD += $(LOG4CPLUS_LIBS) +perfmon_unittests_LDADD += $(CRYPTO_LIBS) +perfmon_unittests_LDADD += $(BOOST_LIBS) +perfmon_unittests_LDADD += $(GTEST_LDADD) +endif +noinst_PROGRAMS = $(TESTS) diff --git a/src/hooks/dhcp/perfmon/tests/run_unittests.cc b/src/hooks/dhcp/perfmon/tests/run_unittests.cc new file mode 100644 index 0000000000..f5014ce44f --- /dev/null +++ b/src/hooks/dhcp/perfmon/tests/run_unittests.cc @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include +#include + +int +main(int argc, char* argv[]) { + ::testing::InitGoogleTest(&argc, argv); + isc::log::initLogger(); + int result = RUN_ALL_TESTS(); + + return (result); +} diff --git a/src/hooks/dhcp/perfmon/version.cc b/src/hooks/dhcp/perfmon/version.cc new file mode 100644 index 0000000000..32834cec8b --- /dev/null +++ b/src/hooks/dhcp/perfmon/version.cc @@ -0,0 +1,17 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include +#include + +extern "C" { + +/// @brief returns Kea hooks version. +int version() { + return (KEA_HOOKS_VERSION); +} + +}