From 414cba3048d8f6c06a7b3ec9eb75cdd46f73bb14 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 7 Apr 2021 08:41:08 -0700 Subject: [PATCH] [cli] add more output to `eidcache` command (#6408) --- src/cli/README.md | 4 ++-- src/cli/cli.cpp | 44 ++++++++++++++++++++++++++++++++++++++--- src/cli/cli.hpp | 1 + tools/otci/otci/otci.py | 2 +- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/cli/README.md b/src/cli/README.md index bfb93a68d..0d124f388 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -1071,8 +1071,8 @@ Print the EID-to-RLOC cache entries. ```bash > eidcache -fdde:ad00:beef:0:bb1:ebd6:ad10:f33 ac00 -fdde:ad00:beef:0:110a:e041:8399:17cd 6000 +fd49:caf4:a29f:dc0e:97fc:69dd:3c16:df7d 2000 cache canEvict=1 transTime=0 eid=fd49:caf4:a29f:dc0e:97fc:69dd:3c16:df7d +fd49:caf4:a29f:dc0e:97fc:69dd:3c16:df7f fffe retry canEvict=1 timeout=10 retryDelay=30 Done ``` diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 1452458c2..0bfffefb2 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1630,6 +1630,46 @@ void Interpreter::HandleDnsServiceResponse(otError aError, const otDnsServiceRes #endif // OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE #if OPENTHREAD_FTD +const char *EidCacheStateToString(otCacheEntryState aState) +{ + static const char *const kStateStrings[4] = { + "cache", + "snoop", + "query", + "retry", + }; + + return static_cast(aState) < OT_ARRAY_LENGTH(kStateStrings) ? kStateStrings[aState] : "unknown"; +} + +void Interpreter::OutputEidCacheEntry(const otCacheEntryInfo &aEntry) +{ + OutputIp6Address(aEntry.mTarget); + OutputFormat(" %04x", aEntry.mRloc16); + OutputFormat(" %s", EidCacheStateToString(aEntry.mState)); + OutputFormat(" canEvict=%d", aEntry.mCanEvict); + + if (aEntry.mState == OT_CACHE_ENTRY_STATE_CACHED) + { + if (aEntry.mValidLastTrans) + { + OutputFormat(" transTime=%u eid=", aEntry.mLastTransTime); + OutputIp6Address(aEntry.mMeshLocalEid); + } + } + else + { + OutputFormat(" timeout=%u", aEntry.mTimeout); + } + + if (aEntry.mState == OT_CACHE_ENTRY_STATE_RETRY_QUERY) + { + OutputFormat(" retryDelay=%u", aEntry.mRetryDelay); + } + + OutputLine(""); +} + otError Interpreter::ProcessEidCache(uint8_t aArgsLength, char *aArgs[]) { OT_UNUSED_VARIABLE(aArgsLength); @@ -1643,9 +1683,7 @@ otError Interpreter::ProcessEidCache(uint8_t aArgsLength, char *aArgs[]) for (uint8_t i = 0;; i++) { SuccessOrExit(otThreadGetNextCacheEntry(mInstance, &entry, &iterator)); - - OutputIp6Address(entry.mTarget); - OutputLine(" %04x", entry.mRloc16); + OutputEidCacheEntry(entry); } exit: diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 3091d846c..2830510c7 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -376,6 +376,7 @@ private: otError ProcessDiscover(uint8_t aArgsLength, char *aArgs[]); otError ProcessDns(uint8_t aArgsLength, char *aArgs[]); #if OPENTHREAD_FTD + void OutputEidCacheEntry(const otCacheEntryInfo &aEntry); otError ProcessEidCache(uint8_t aArgsLength, char *aArgs[]); #endif otError ProcessEui64(uint8_t aArgsLength, char *aArgs[]); diff --git a/tools/otci/otci/otci.py b/tools/otci/otci/otci.py index a03b8dbe8..08a118df3 100644 --- a/tools/otci/otci/otci.py +++ b/tools/otci/otci/otci.py @@ -1681,7 +1681,7 @@ class OTCI(object): cache = {} for line in output: - ip, rloc16 = line.split() + ip, rloc16, _ = line.split(" ", 2) cache[Ip6Addr(ip)] = Rloc16(rloc16, 16)