From bfef9c6a035fe33e4727db6b85dd06750de74d51 Mon Sep 17 00:00:00 2001 From: Rongli Sun Date: Wed, 15 Apr 2020 14:54:57 +0800 Subject: [PATCH] [logging] add bbr region (#4819) --- etc/cmake/options.cmake | 1 + examples/common-switches.mk | 1 + include/openthread/platform/logging.h | 1 + src/core/backbone_router/leader.cpp | 16 ++-- src/core/backbone_router/leader.hpp | 2 +- src/core/backbone_router/local.cpp | 16 ++-- src/core/backbone_router/local.hpp | 2 +- src/core/common/logging.hpp | 133 ++++++++++++++++++++++++++ src/core/config/logging.h | 12 +++ src/lib/spinel/spinel.h | 1 + src/ncp/ncp_base.cpp | 4 + 11 files changed, 171 insertions(+), 18 deletions(-) diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 6e5440f3f..30082fafc 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -204,6 +204,7 @@ if(OT_FULL_LOGS) list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_LOG_LEVEL=OT_LOG_LEVEL_DEBG") list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_LOG_API=1") list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_LOG_ARP=1") + list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_LOG_BBR=1") list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_LOG_CLI=1") list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_LOG_COAP=1") list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_LOG_ICMP=1") diff --git a/examples/common-switches.mk b/examples/common-switches.mk index 91a36ee75..8f29ddb28 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -263,6 +263,7 @@ ifeq ($(FULL_LOGS),1) LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_LEVEL=OT_LOG_LEVEL_DEBG LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_API=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_ARP=1 +LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_BBR=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_CLI=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_COAP=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_ICMP=1 diff --git a/include/openthread/platform/logging.h b/include/openthread/platform/logging.h index 68687ed1f..12f361c42 100644 --- a/include/openthread/platform/logging.h +++ b/include/openthread/platform/logging.h @@ -134,6 +134,7 @@ typedef enum otLogRegion OT_LOG_REGION_CLI = 14, ///< CLI 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) } otLogRegion; /** diff --git a/src/core/backbone_router/leader.cpp b/src/core/backbone_router/leader.cpp index 1994499ad..4311132fa 100644 --- a/src/core/backbone_router/leader.cpp +++ b/src/core/backbone_router/leader.cpp @@ -83,26 +83,26 @@ exit: return error; } -#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_NETDATA == 1) +#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1) void Leader::LogBackboneRouterPrimary(State aState, const BackboneRouterConfig &aConfig) const { OT_UNUSED_VARIABLE(aConfig); - otLogInfoNetData("PBBR state: %s", StateToString(aState)); + otLogInfoBbr("PBBR state: %s", StateToString(aState)); if (aState != kStateRemoved && aState != kStateNone) { - otLogInfoNetData("Rloc16: 0x%4X, seqno: %d, delay: %d, timeout %d", aConfig.mServer16, aConfig.mSequenceNumber, - aConfig.mReregistrationDelay, aConfig.mMlrTimeout); + otLogInfoBbr("Rloc16: 0x%4X, seqno: %d, delay: %d, timeout %d", aConfig.mServer16, aConfig.mSequenceNumber, + aConfig.mReregistrationDelay, aConfig.mMlrTimeout); } } void Leader::LogDomainPrefix(DomainPrefixState aState, const otIp6Prefix &aPrefix) const { - otLogInfoNetData("Domain Prefix: %s/%d, state: %s", - aPrefix.mLength == 0 ? "" - : static_cast(&aPrefix.mPrefix)->ToString().AsCString(), - aPrefix.mLength, DomainPrefixStateToString(aState)); + otLogInfoBbr("Domain Prefix: %s/%d, state: %s", + aPrefix.mLength == 0 ? "" + : static_cast(&aPrefix.mPrefix)->ToString().AsCString(), + aPrefix.mLength, DomainPrefixStateToString(aState)); } const char *Leader::StateToString(State aState) diff --git a/src/core/backbone_router/leader.hpp b/src/core/backbone_router/leader.hpp index 1cf76dc44..aac702529 100644 --- a/src/core/backbone_router/leader.hpp +++ b/src/core/backbone_router/leader.hpp @@ -155,7 +155,7 @@ public: private: void UpdateBackboneRouterPrimary(void); void UpdateDomainPrefixConfig(void); -#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_NETDATA == 1) +#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1) void LogBackboneRouterPrimary(State aState, const BackboneRouterConfig &aConfig) const; void LogDomainPrefix(DomainPrefixState aState, const otIp6Prefix &aPrefix) const; static const char *StateToString(State aState); diff --git a/src/core/backbone_router/local.cpp b/src/core/backbone_router/local.cpp index 70e0eff03..aadde64d8 100644 --- a/src/core/backbone_router/local.cpp +++ b/src/core/backbone_router/local.cpp @@ -322,20 +322,20 @@ void Local::AddDomainPrefixToNetworkData(void) LogDomainPrefix("Add", error); } -#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_NETDATA == 1) +#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1) void Local::LogDomainPrefix(const char *aAction, otError aError) { - otLogInfoNetData("%s Domain Prefix: %s/%d, %s", aAction, - mDomainPrefixConfig.mPrefix.mLength > 0 - ? (*static_cast(&mDomainPrefixConfig.mPrefix.mPrefix)).ToString().AsCString() - : "", - mDomainPrefixConfig.mPrefix.mLength, otThreadErrorToString(aError)); + otLogInfoBbr("%s Domain Prefix: %s/%d, %s", aAction, + mDomainPrefixConfig.mPrefix.mLength > 0 + ? (*static_cast(&mDomainPrefixConfig.mPrefix.mPrefix)).ToString().AsCString() + : "", + mDomainPrefixConfig.mPrefix.mLength, otThreadErrorToString(aError)); } void Local::LogBackboneRouterService(const char *aAction, otError aError) { - otLogInfoNetData("%s BBR Service: seqno (%d), delay (%ds), timeout (%ds), %s", aAction, mSequenceNumber, - mReregistrationDelay, mMlrTimeout, otThreadErrorToString(aError)); + otLogInfoBbr("%s BBR Service: seqno (%d), delay (%ds), timeout (%ds), %s", aAction, mSequenceNumber, + mReregistrationDelay, mMlrTimeout, otThreadErrorToString(aError)); } #endif diff --git a/src/core/backbone_router/local.hpp b/src/core/backbone_router/local.hpp index 04ddfd5e0..ed30811b5 100644 --- a/src/core/backbone_router/local.hpp +++ b/src/core/backbone_router/local.hpp @@ -200,7 +200,7 @@ private: otError RemoveService(void); void AddDomainPrefixToNetworkData(void); void RemoveDomainPrefixFromNetworkData(void); -#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_NETDATA == 1) +#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1) void LogBackboneRouterService(const char *aAction, otError aError); void LogDomainPrefix(const char *aAction, otError aError); #else diff --git a/src/core/common/logging.hpp b/src/core/common/logging.hpp index d5d886c67..cf384eda7 100644 --- a/src/core/common/logging.hpp +++ b/src/core/common/logging.hpp @@ -89,6 +89,7 @@ extern "C" { #define _OT_REGION_CLI_PREFIX "-CLI-----: " #define _OT_REGION_CORE_PREFIX "-CORE----: " #define _OT_REGION_UTIL_PREFIX "-UTIL----: " +#define _OT_REGION_BBR_PREFIX "-BBR-----: " #else #define _OT_REGION_API_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_MLE_PREFIX _OT_REGION_SUFFIX @@ -106,6 +107,7 @@ extern "C" { #define _OT_REGION_CLI_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_CORE_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_UTIL_PREFIX _OT_REGION_SUFFIX +#define _OT_REGION_BBR_PREFIX _OT_REGION_SUFFIX #endif /** @@ -458,6 +460,69 @@ extern "C" { #define otLogDebgArp(aFormat, ...) #endif +/** + * @def otLogCritBbr + * + * This method generates a log with level critical for the Backbone Router (BBR) region. + * + * @param[in] aFormat A pointer to the format string. + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogWarnBbr + * + * This method generates a log with level warning for the Backbone Router (BBR) region. + * + * @param[in] aFormat A pointer to the format string. + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogInfoBbr + * + * This method generates a log with level note for the Backbone Router (BBR) region. + * + * @param[in] aFormat A pointer to the format string. + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogInfoBbr + * + * This method generates a log with level info for the Backbone Router (BBR) region. + * + * @param[in] aFormat A pointer to the format string. + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogDebgBbr + * + * This method generates a log with level debug for the Backbone Router (BBR) region. + * + * @param[in] aFormat A pointer to the format string. + * @param[in] ... Arguments for the format specification. + * + */ +#if OPENTHREAD_CONFIG_LOG_BBR == 1 +#define otLogCritBbr(aFormat, ...) otLogCrit(OT_LOG_REGION_BBR, _OT_REGION_BBR_PREFIX aFormat, ##__VA_ARGS__) +#define otLogWarnBbr(aFormat, ...) otLogWarn(OT_LOG_REGION_BBR, _OT_REGION_BBR_PREFIX aFormat, ##__VA_ARGS__) +#define otLogNoteBbr(aFormat, ...) otLogNote(OT_LOG_REGION_BBR, _OT_REGION_BBR_PREFIX aFormat, ##__VA_ARGS__) +#define otLogInfoBbr(aFormat, ...) otLogInfo(OT_LOG_REGION_BBR, _OT_REGION_BBR_PREFIX aFormat, ##__VA_ARGS__) +#define otLogDebgBbr(aFormat, ...) otLogDebg(OT_LOG_REGION_BBR, _OT_REGION_BBR_PREFIX aFormat, ##__VA_ARGS__) +#else +#define otLogCritBbr(aFormat, ...) +#define otLogWarnBbr(aFormat, ...) +#define otLogNoteBbr(aFormat, ...) +#define otLogInfoBbr(aFormat, ...) +#define otLogDebgBbr(aFormat, ...) +#endif + /** * @def otLogCritNetData * @@ -1484,6 +1549,74 @@ extern "C" { #define otDumpDebgArp(aId, aBuf, aLength) #endif +/** + * @def otDumpCritBbr + * + * This method generates a memory dump with log level critical and region Backbone Router (BBR). + * + * @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 otDumpWarnBbr + * + * This method generates a memory dump with log level warning and region Backbone Router (BBR). + * + * @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 otDumpNoteBbr + * + * This method generates a memory dump with log level note and region Backbone Router (BBR). + * + * @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 otDumpInfoBbr + * + * This method generates a memory dump with log level info and region Backbone Router (BBR). + * + * @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 otDumpDebgBbr + * + * This method generates a memory dump with log level debug and region Backbone Router (BBR). + * + * @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_BBR == 1 +#define otDumpCritBbr(aId, aBuf, aLength) otDumpCrit(OT_LOG_REGION_BBR, aId, aBuf, aLength) +#define otDumpWarnBbr(aId, aBuf, aLength) otDumpWarn(OT_LOG_REGION_BBR, aId, aBuf, aLength) +#define otDumpNoteBbr(aId, aBuf, aLength) otDumpNote(OT_LOG_REGION_BBR, aId, aBuf, aLength) +#define otDumpInfoBbr(aId, aBuf, aLength) otDumpInfo(OT_LOG_REGION_BBR, aId, aBuf, aLength) +#define otDumpDebgBbr(aId, aBuf, aLength) otDumpDebg(OT_LOG_REGION_BBR, aId, aBuf, aLength) +#else +#define otDumpCritBbr(aId, aBuf, aLength) +#define otDumpWarnBbr(aId, aBuf, aLength) +#define otDumpNoteBbr(aId, aBuf, aLength) +#define otDumpInfoBbr(aId, aBuf, aLength) +#define otDumpDebgBbr(aId, aBuf, aLength) +#endif + /** * @def otDumpCritIcmp * diff --git a/src/core/config/logging.h b/src/core/config/logging.h index 5a2bd8eb5..0fc572f6f 100644 --- a/src/core/config/logging.h +++ b/src/core/config/logging.h @@ -256,6 +256,18 @@ #define OPENTHREAD_CONFIG_LOG_UTIL 1 #endif +/** + * @def OPENTHREAD_CONFIG_LOG_BBR + * + * Note: available since Thread 1.2. + * + * Define to enable Backbone Router (BBR) region logging. + * + */ +#ifndef OPENTHREAD_CONFIG_LOG_BBR +#define OPENTHREAD_CONFIG_LOG_BBR 1 +#endif + /** * @def OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL * diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index 1f59fa20e..1c0970077 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -621,6 +621,7 @@ enum SPINEL_NCP_LOG_REGION_OT_CLI = 14, SPINEL_NCP_LOG_REGION_OT_CORE = 15, SPINEL_NCP_LOG_REGION_OT_UTIL = 16, + SPINEL_NCP_LOG_REGION_OT_BBR = 17, }; enum diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index e03b4a014..8c5dd76d9 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -608,6 +608,10 @@ unsigned int NcpBase::ConvertLogRegion(otLogRegion aLogRegion) case OT_LOG_REGION_UTIL: spinelLogRegion = SPINEL_NCP_LOG_REGION_OT_UTIL; break; + + case OT_LOG_REGION_BBR: + spinelLogRegion = SPINEL_NCP_LOG_REGION_OT_BBR; + break; } return spinelLogRegion;