From 8988bd84c35eb555d3db9819c063fd1315695356 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 22 Sep 2022 11:33:46 -0700 Subject: [PATCH] [mle] add `RouterTable::LogRouteTable()` (#8189) This commit updates the logging format of the route table. It adds `LogRouteTable()` method in `RouterTable`. --- src/core/thread/mle_router.cpp | 17 ++----------- src/core/thread/router_table.cpp | 41 ++++++++++++++++++++++++++++++++ src/core/thread/router_table.hpp | 10 ++++++++ 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 1feda0d32..d11160726 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -1602,24 +1602,11 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) ResetAdvertiseInterval(); } -#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) - - VerifyOrExit(changed); - LogInfo("Route table updated"); - - for (Router &router : Get().Iterate()) + if (changed) { - LogInfo(" %04x -> %04x, cost:%d %d, lqin:%d, lqout:%d, link:%s", router.GetRloc16(), - (router.GetNextHop() == kInvalidRouterId) ? 0xffff : Rloc16FromRouterId(router.GetNextHop()), - router.GetCost(), mRouterTable.GetLinkCost(router), router.GetLinkQualityIn(), - router.GetLinkQualityOut(), - router.GetRloc16() == GetRloc16() ? "device" : ToYesNo(router.IsStateValid())); + Get().LogRouteTable(); } -#else - OT_UNUSED_VARIABLE(changed); -#endif - exit: return; } diff --git a/src/core/thread/router_table.cpp b/src/core/thread/router_table.cpp index 8175e694f..a45efe945 100644 --- a/src/core/thread/router_table.cpp +++ b/src/core/thread/router_table.cpp @@ -550,6 +550,47 @@ exit: } #endif +#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) +void RouterTable::LogRouteTable(void) +{ + static constexpr uint16_t kStringSize = 128; + + LogInfo("Route table"); + + for (Router &router : Iterate()) + { + String string; + + string.Append(" %2d 0x%04x", router.GetRouterId(), router.GetRloc16()); + + if (router.GetRloc16() == Get().GetRloc16()) + { + string.Append(" - me"); + } + else + { + if (router.IsStateValid()) + { + string.Append(" - nbr{lq[i/o]:%d/%d cost:%d}", router.GetLinkQualityIn(), router.GetLinkQualityOut(), + GetLinkCost(router)); + } + + if (router.GetNextHop() != Mle::kInvalidRouterId) + { + string.Append(" - nexthop{%d cost:%d}", router.GetNextHop(), router.GetCost()); + } + } + + if (router.GetRouterId() == Get().GetLeaderId()) + { + string.Append(" - leader"); + } + + LogInfo("%s", string.AsCString()); + } +} +#endif + } // namespace ot #endif // OPENTHREAD_FTD diff --git a/src/core/thread/router_table.hpp b/src/core/thread/router_table.hpp index 7fa65495a..d2e2721ce 100644 --- a/src/core/thread/router_table.hpp +++ b/src/core/thread/router_table.hpp @@ -344,6 +344,16 @@ public: Error SetRouterIdRange(uint8_t aMinRouterId, uint8_t aMaxRouterId); #endif +#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) + /** + * This method logs the route table. + * + */ + void LogRouteTable(void); +#else + void LogRouteTable(void) {} +#endif + private: class IteratorBuilder : public InstanceLocator {