Add API to retrieve EID cache diag information. (#229)

This commit is contained in:
Jonathan Hui
2016-07-01 13:27:50 -07:00
committed by GitHub
parent 51e5609456
commit 4b487f1aa6
8 changed files with 108 additions and 9 deletions
+17 -9
View File
@@ -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.
*/
+12
View File
@@ -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.
*
+12
View File
@@ -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.
+30
View File
@@ -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);
+1
View File
@@ -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[]);
+11
View File
@@ -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();
+13
View File
@@ -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++)
+12
View File
@@ -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.
*