From 4b487f1aa6642097e7e851789acac1651683dd21 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Fri, 1 Jul 2016 13:27:50 -0700 Subject: [PATCH] Add API to retrieve EID cache diag information. (#229) --- include/openthread-types.h | 26 +++++++++++++++--------- include/openthread.h | 12 +++++++++++ src/cli/README.md | 12 +++++++++++ src/cli/cli.cpp | 30 ++++++++++++++++++++++++++++ src/cli/cli.hpp | 1 + src/core/openthread.cpp | 11 ++++++++++ src/core/thread/address_resolver.cpp | 13 ++++++++++++ src/core/thread/address_resolver.hpp | 12 +++++++++++ 8 files changed, 108 insertions(+), 9 deletions(-) diff --git a/include/openthread-types.h b/include/openthread-types.h index f867847e8..4d7d07364 100644 --- a/include/openthread-types.h +++ b/include/openthread-types.h @@ -123,6 +123,8 @@ typedef enum ThreadError #define OT_EXT_ADDRESS_SIZE 8 ///< Size of an IEEE 802.15.4 Extended Address (bytes) #define OT_EXT_PAN_ID_SIZE 8 ///< Size of a Thread PAN ID (bytes) #define OT_NETWORK_NAME_SIZE 16 ///< Size of the Thread Network Name field (bytes) +#define OT_IP6_ADDRESS_SIZE 16 ///< Size of an IPv6 address (bytes) +#define OT_IP6_IID_SIZE 8 ///< Size of an IPv6 Interface Identifier (bytes) /** * This type represents the IEEE 802.15.4 PAN ID. @@ -243,11 +245,6 @@ enum * */ -enum -{ - kIp6AddressSize = 16, -}; - /** * This structure represents an IPv6 address. */ @@ -255,10 +252,10 @@ typedef OT_TOOL_PACKED_BEGIN struct otIp6Address { union { - uint8_t m8[kIp6AddressSize]; ///< 8-bit fields - uint16_t m16[kIp6AddressSize / sizeof(uint16_t)]; ///< 16-bit fields - uint32_t m32[kIp6AddressSize / sizeof(uint32_t)]; ///< 32-bit fields - } mFields; ///< IPv6 accessor fields + uint8_t m8[OT_IP6_ADDRESS_SIZE]; ///< 8-bit fields + uint16_t m16[OT_IP6_ADDRESS_SIZE / sizeof(uint16_t)]; ///< 16-bit fields + uint32_t m32[OT_IP6_ADDRESS_SIZE / sizeof(uint32_t)]; ///< 32-bit fields + } mFields; ///< IPv6 accessor fields } OT_TOOL_PACKED_END otIp6Address; /** @@ -444,6 +441,17 @@ typedef struct bool mLinkEstablished : 1; ///< Link established with Router ID or not } otRouterInfo; +/** + * This structure represents an EID cache entry. + * + */ +typedef struct otEidCacheEntry +{ + otIp6Address mTarget; ///< Target + otShortAddress mRloc16; ///< RLOC16 + bool mValid : 1; ///< Indicates whether or not the cache entry is valid +} otEidCacheEntry; + /** * This structure represents the MAC layer counters. */ diff --git a/include/openthread.h b/include/openthread.h index 82bd870c2..320688a89 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -917,6 +917,18 @@ ThreadError otGetChildInfoByIndex(uint8_t aChildIndex, otChildInfo *aChildInfo); */ otDeviceRole otGetDeviceRole(void); +/** + * This function gets an EID cache entry. + * + * @param[in] aIndex An index into the EID cache table. + * @param[out] aEntry A pointer to where the EID information is placed. + * + * @retval kThreadError_None Successfully retreieved the EID cache entry. + * @retval kThreadError_InvalidArgs @p aIndex was out of bounds or @p aEntry was NULL. + * + */ +ThreadError otGetEidCacheEntry(uint8_t aIndex, otEidCacheEntry *aEntry); + /** * Get the Leader's Router ID. * diff --git a/src/cli/README.md b/src/cli/README.md index 30ae9d4bd..55f1cb60d 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -12,6 +12,7 @@ OpenThread test scripts use the CLI to execute test cases. * [childtimeout](#childtimeout) * [contextreusedelay](#contextreusedelay) * [counter](#counter) +* [eidcache](#eidcache) * [extaddr](#extaddr) * [extpanid](#extpanid) * [ipaddr](#ipaddr) @@ -166,6 +167,17 @@ RxTotal: 11 RxErrOther: 0 ``` +### eidcache + +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 +Done +``` + ### extaddr Get the IEEE 802.15.4 Extended Address. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 7479bd58f..d02c0d749 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -55,6 +55,7 @@ const struct Command Interpreter::sCommands[] = { "childtimeout", &ProcessChildTimeout }, { "contextreusedelay", &ProcessContextIdReuseDelay }, { "counter", &ProcessCounters }, + { "eidcache", &ProcessEidCache }, { "extaddr", &ProcessExtAddress }, { "extpanid", &ProcessExtPanId }, { "ipaddr", &ProcessIpAddr }, @@ -346,6 +347,35 @@ void Interpreter::ProcessCounters(int argc, char *argv[]) } } +void Interpreter::ProcessEidCache(int argc, char *argv[]) +{ + otEidCacheEntry entry; + + for (int i = 0; ; i++) + { + SuccessOrExit(otGetEidCacheEntry(i, &entry)); + + if (entry.mValid == false) + { + continue; + } + + sServer->OutputFormat("%x:%x:%x:%x:%x:%x:%x:%x %04x\r\n", + HostSwap16(entry.mTarget.mFields.m16[0]), + HostSwap16(entry.mTarget.mFields.m16[1]), + HostSwap16(entry.mTarget.mFields.m16[2]), + HostSwap16(entry.mTarget.mFields.m16[3]), + HostSwap16(entry.mTarget.mFields.m16[4]), + HostSwap16(entry.mTarget.mFields.m16[5]), + HostSwap16(entry.mTarget.mFields.m16[6]), + HostSwap16(entry.mTarget.mFields.m16[7]), + entry.mRloc16); + } + +exit: + AppendResult(kThreadError_None); +} + void Interpreter::ProcessExtAddress(int argc, char *argv[]) { OutputBytes(otGetExtendedAddress(), OT_EXT_ADDRESS_SIZE); diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 8d296e57d..420bdeede 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -93,6 +93,7 @@ private: static void ProcessChildTimeout(int argc, char *argv[]); static void ProcessContextIdReuseDelay(int argc, char *argv[]); static void ProcessCounters(int argc, char *argv[]); + static void ProcessEidCache(int argc, char *argv[]); static void ProcessExtAddress(int argc, char *argv[]); static void ProcessExtPanId(int argc, char *argv[]); static void ProcessIpAddr(int argc, char *argv[]); diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 32b8d83d8..be6fdcf6d 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -524,6 +524,17 @@ otDeviceRole otGetDeviceRole(void) return rval; } +ThreadError otGetEidCacheEntry(uint8_t aIndex, otEidCacheEntry *aEntry) +{ + ThreadError error; + + VerifyOrExit(aEntry != NULL, error = kThreadError_InvalidArgs); + error = sThreadNetif->GetAddressResolver().GetEntry(aIndex, *aEntry); + +exit: + return error; +} + uint8_t otGetLeaderRouterId(void) { return sThreadNetif->GetMle().GetLeaderDataTlv().GetLeaderRouterId(); diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index 01307df55..3abd61db4 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -75,6 +75,19 @@ void AddressResolver::Clear() memset(&mCache, 0, sizeof(mCache)); } +ThreadError AddressResolver::GetEntry(uint8_t aIndex, otEidCacheEntry &aEntry) const +{ + ThreadError error = kThreadError_None; + + VerifyOrExit(aIndex < kCacheEntries, error = kThreadError_InvalidArgs); + memcpy(&aEntry.mTarget, &mCache[aIndex].mTarget, sizeof(aEntry.mTarget)); + aEntry.mRloc16 = mCache[aIndex].mRloc16; + aEntry.mValid = mCache[aIndex].mState == Cache::kStateCached; + +exit: + return error; +} + void AddressResolver::Remove(uint8_t routerId) { for (int i = 0; i < kCacheEntries; i++) diff --git a/src/core/thread/address_resolver.hpp b/src/core/thread/address_resolver.hpp index b43c05345..d0829121e 100644 --- a/src/core/thread/address_resolver.hpp +++ b/src/core/thread/address_resolver.hpp @@ -78,6 +78,18 @@ public: */ void Clear(void); + /** + * This method gets an EID cache entry. + * + * @param[in] aIndex An index into the EID cache table. + * @param[out] aEntry A pointer to where the EID information is placed. + * + * @retval kThreadError_None Successfully retreieved the EID cache entry. + * @retval kThreadError_InvalidArgs @p aIndex was out of bounds or @p aEntry was NULL. + * + */ + ThreadError GetEntry(uint8_t aIndex, otEidCacheEntry &aEntry) const; + /** * This method removes a Router ID from the EID-to-RLOC cache. *