[mle] add RouterTable::LogRouteTable() (#8189)

This commit updates the logging format of the route table. It adds
`LogRouteTable()` method in `RouterTable`.
This commit is contained in:
Abtin Keshavarzian
2022-09-22 11:33:46 -07:00
committed by GitHub
parent 13df0374d1
commit 8988bd84c3
3 changed files with 53 additions and 15 deletions
+2 -15
View File
@@ -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<RouterTable>().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<RouterTable>().LogRouteTable();
}
#else
OT_UNUSED_VARIABLE(changed);
#endif
exit:
return;
}
+41
View File
@@ -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<kStringSize> string;
string.Append(" %2d 0x%04x", router.GetRouterId(), router.GetRloc16());
if (router.GetRloc16() == Get<Mle::Mle>().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<Mle::Mle>().GetLeaderId())
{
string.Append(" - leader");
}
LogInfo("%s", string.AsCString());
}
}
#endif
} // namespace ot
#endif // OPENTHREAD_FTD
+10
View File
@@ -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
{