From 434e6bbffc26a5eef1f5e4f5733b8bd536c250a6 Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Fri, 17 Jul 2020 23:53:40 +0800 Subject: [PATCH] [logging] add MLR log region (#5250) --- etc/cmake/options.cmake | 1 + examples/common-switches.mk | 1 + include/openthread/instance.h | 2 +- include/openthread/platform/logging.h | 1 + src/core/common/logging.hpp | 128 ++++++++++++++++++++++++++ src/core/config/logging.h | 12 +++ src/lib/spinel/spinel.h | 1 + src/ncp/ncp_base.cpp | 3 + 8 files changed, 148 insertions(+), 1 deletion(-) diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index d0657508e..e9414a9d7 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -244,6 +244,7 @@ if(OT_FULL_LOGS) target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_MEM=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_MESHCOP=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_MLE=1") + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_MLR=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_NETDATA=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_NETDIAG=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_PKT_DUMP=1") diff --git a/examples/common-switches.mk b/examples/common-switches.mk index 49713cdb6..59fc043f6 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -292,6 +292,7 @@ LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_MAC=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_MEM=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_MESHCOP=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_MLE=1 +LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_MLR=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_NETDATA=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_NETDIAG=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_PKT_DUMP=1 diff --git a/include/openthread/instance.h b/include/openthread/instance.h index e0e4010bb..3b9fb4604 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (15) +#define OPENTHREAD_API_VERSION (16) /** * @addtogroup api-instance diff --git a/include/openthread/platform/logging.h b/include/openthread/platform/logging.h index 12f361c42..df40aeeef 100644 --- a/include/openthread/platform/logging.h +++ b/include/openthread/platform/logging.h @@ -135,6 +135,7 @@ typedef enum otLogRegion OT_LOG_REGION_CORE = 15, ///< OpenThread Core OT_LOG_REGION_UTIL = 16, ///< Utility module OT_LOG_REGION_BBR = 17, ///< Backbone Router (available since Thread 1.2) + OT_LOG_REGION_MLR = 18, ///< Multicast Listener Registration (available since Thread 1.2) } otLogRegion; /** diff --git a/src/core/common/logging.hpp b/src/core/common/logging.hpp index eda0ac726..6e9ff1661 100644 --- a/src/core/common/logging.hpp +++ b/src/core/common/logging.hpp @@ -90,6 +90,7 @@ extern "C" { #define _OT_REGION_CORE_PREFIX "-CORE----: " #define _OT_REGION_UTIL_PREFIX "-UTIL----: " #define _OT_REGION_BBR_PREFIX "-BBR-----: " +#define _OT_REGION_MLR_PREFIX "-MLR-----: " #else #define _OT_REGION_API_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_MLE_PREFIX _OT_REGION_SUFFIX @@ -108,6 +109,7 @@ extern "C" { #define _OT_REGION_CORE_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_UTIL_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_BBR_PREFIX _OT_REGION_SUFFIX +#define _OT_REGION_MLR_PREFIX _OT_REGION_SUFFIX #endif /** @@ -483,6 +485,64 @@ extern "C" { #define otLogDebgBbr(...) #endif +/** + * @def otLogCritMlr + * + * This method generates a log with level critical for the Multicast Listener Registration (MLR) region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogWarnMlr + * + * This method generates a log with level warning for the Multicast Listener Registration (MLR) region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogNoteMlr + * + * This method generates a log with level note for the Multicast Listener Registration (MLR) region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogInfoMlr + * + * This method generates a log with level info for the Multicast Listener Registration (MLR) region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogDebgMlr + * + * This method generates a log with level debug for the Multicast Listener Registration (MLR) region. + * + * @param[in] ... Arguments for the format specification. + * + */ +#if OPENTHREAD_CONFIG_LOG_MLR == 1 +#define otLogCritMlr(...) otLogCrit(OT_LOG_REGION_MLR, _OT_REGION_MLR_PREFIX __VA_ARGS__) +#define otLogWarnMlr(...) otLogWarn(OT_LOG_REGION_MLR, _OT_REGION_MLR_PREFIX __VA_ARGS__) +#define otLogNoteMlr(...) otLogNote(OT_LOG_REGION_MLR, _OT_REGION_MLR_PREFIX __VA_ARGS__) +#define otLogInfoMlr(...) otLogInfo(OT_LOG_REGION_MLR, _OT_REGION_MLR_PREFIX __VA_ARGS__) +#define otLogDebgMlr(...) otLogDebg(OT_LOG_REGION_MLR, _OT_REGION_MLR_PREFIX __VA_ARGS__) +#else +#define otLogCritMlr(...) +#define otLogWarnMlr(...) +#define otLogNoteMlr(...) +#define otLogInfoMlr(...) +#define otLogDebgMlr(...) +#endif + /** * @def otLogCritNetData * @@ -1523,6 +1583,74 @@ extern "C" { #define otDumpDebgBbr(aId, aBuf, aLength) #endif +/** + * @def otDumpCritMlr + * + * This method generates a memory dump with log level critical and region Multicast Listener Registration (MLR). + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpWarnMlr + * + * This method generates a memory dump with log level warning and region Multicast Listener Registration (MLR). + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpNoteMlr + * + * This method generates a memory dump with log level note and region Multicast Listener Registration (MLR). + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpInfoMlr + * + * This method generates a memory dump with log level info and region Multicast Listener Registration (MLR). + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpDebgMlr + * + * This method generates a memory dump with log level debug and region Multicast Listener Registration (MLR). + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ +#if OPENTHREAD_CONFIG_LOG_MLR == 1 +#define otDumpCritMlr(aId, aBuf, aLength) otDumpCrit(OT_LOG_REGION_MLR, aId, aBuf, aLength) +#define otDumpWarnMlr(aId, aBuf, aLength) otDumpWarn(OT_LOG_REGION_MLR, aId, aBuf, aLength) +#define otDumpNoteMlr(aId, aBuf, aLength) otDumpNote(OT_LOG_REGION_MLR, aId, aBuf, aLength) +#define otDumpInfoMlr(aId, aBuf, aLength) otDumpInfo(OT_LOG_REGION_MLR, aId, aBuf, aLength) +#define otDumpDebgMlr(aId, aBuf, aLength) otDumpDebg(OT_LOG_REGION_MLR, aId, aBuf, aLength) +#else +#define otDumpCritMlr(aId, aBuf, aLength) +#define otDumpWarnMlr(aId, aBuf, aLength) +#define otDumpNoteMlr(aId, aBuf, aLength) +#define otDumpInfoMlr(aId, aBuf, aLength) +#define otDumpDebgMlr(aId, aBuf, aLength) +#endif + /** * @def otDumpCritIcmp * diff --git a/src/core/config/logging.h b/src/core/config/logging.h index 5d35108e7..c8d46ed29 100644 --- a/src/core/config/logging.h +++ b/src/core/config/logging.h @@ -275,6 +275,18 @@ #define OPENTHREAD_CONFIG_LOG_BBR 1 #endif +/** + * @def OPENTHREAD_CONFIG_LOG_MLR + * + * Note: available since Thread 1.2. + * + * Define to enable Multicast Listener Registration (MLR) region logging. + * + */ +#ifndef OPENTHREAD_CONFIG_LOG_MLR +#define OPENTHREAD_CONFIG_LOG_MLR 1 +#endif + /** * @def OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL * diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index 082279574..915751f68 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -644,6 +644,7 @@ enum SPINEL_NCP_LOG_REGION_OT_CORE = 15, SPINEL_NCP_LOG_REGION_OT_UTIL = 16, SPINEL_NCP_LOG_REGION_OT_BBR = 17, + SPINEL_NCP_LOG_REGION_OT_MLR = 18, }; enum diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index fe7dc6e03..bd17952fe 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -612,6 +612,9 @@ unsigned int NcpBase::ConvertLogRegion(otLogRegion aLogRegion) case OT_LOG_REGION_BBR: spinelLogRegion = SPINEL_NCP_LOG_REGION_OT_BBR; break; + case OT_LOG_REGION_MLR: + spinelLogRegion = SPINEL_NCP_LOG_REGION_OT_MLR; + break; } return spinelLogRegion;