[address-resolver] simplify EntryInfo and Iterator (#8055)

This commit is contained in:
Abtin Keshavarzian
2022-08-22 17:47:07 -07:00
committed by GitHub
parent 8942e7f895
commit 570e30522f
3 changed files with 46 additions and 22 deletions
+2 -4
View File
@@ -260,10 +260,8 @@ otError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRoute
otError otThreadGetNextCacheEntry(otInstance *aInstance, otCacheEntryInfo *aEntryInfo, otCacheEntryIterator *aIterator)
{
AssertPointerIsNotNull(aIterator);
AssertPointerIsNotNull(aEntryInfo);
return AsCoreType(aInstance).Get<AddressResolver>().GetNextCacheEntry(*aEntryInfo, *aIterator);
return AsCoreType(aInstance).Get<AddressResolver>().GetNextCacheEntry(AsCoreType(aEntryInfo),
AsCoreType(aIterator));
}
#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE
+9 -12
View File
@@ -96,11 +96,8 @@ void AddressResolver::Clear(void)
Error AddressResolver::GetNextCacheEntry(EntryInfo &aInfo, Iterator &aIterator) const
{
Error error = kErrorNone;
const CacheEntryList *list;
const CacheEntry * entry;
list = reinterpret_cast<const CacheEntryList *>(aIterator.mData[kIteratorListIndex]);
entry = reinterpret_cast<const CacheEntry *>(aIterator.mData[kIteratorEntryIndex]);
const CacheEntryList *list = aIterator.GetList();
const CacheEntry * entry = aIterator.GetEntry();
while (entry == nullptr)
{
@@ -130,16 +127,16 @@ Error AddressResolver::GetNextCacheEntry(EntryInfo &aInfo, Iterator &aIterator)
// Update the iterator then populate the `aInfo`.
aIterator.mData[kIteratorEntryIndex] = entry->GetNext();
aIterator.mData[kIteratorListIndex] = list;
aIterator.SetEntry(entry->GetNext());
aIterator.SetList(list);
memset(&aInfo, 0, sizeof(aInfo));
aInfo.Clear();
aInfo.mTarget = entry->GetTarget();
aInfo.mRloc16 = entry->GetRloc16();
if (list == &mCachedList)
{
aInfo.mState = OT_CACHE_ENTRY_STATE_CACHED;
aInfo.mState = MapEnum(EntryInfo::kStateCached);
aInfo.mCanEvict = true;
aInfo.mValidLastTrans = entry->IsLastTransactionTimeValid();
@@ -154,15 +151,15 @@ Error AddressResolver::GetNextCacheEntry(EntryInfo &aInfo, Iterator &aIterator)
if (list == &mSnoopedList)
{
aInfo.mState = OT_CACHE_ENTRY_STATE_SNOOPED;
aInfo.mState = MapEnum(EntryInfo::kStateSnooped);
}
else if (list == &mQueryList)
{
aInfo.mState = OT_CACHE_ENTRY_STATE_QUERY;
aInfo.mState = MapEnum(EntryInfo::kStateQuery);
}
else
{
aInfo.mState = OT_CACHE_ENTRY_STATE_RETRY_QUERY;
aInfo.mState = MapEnum(EntryInfo::kStateRetryQuery);
}
aInfo.mCanEvict = entry->CanEvict();
+35 -6
View File
@@ -37,6 +37,7 @@
#include "openthread-core-config.h"
#include "coap/coap.hpp"
#include "common/as_core_type.hpp"
#include "common/linked_list.hpp"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
@@ -66,18 +67,42 @@ class AddressResolver : public InstanceLocator, private NonCopyable
{
friend class TimeTicker;
class CacheEntry;
class CacheEntryList;
public:
/**
* This type represents an iterator used for iterating through the EID cache table entries.
*
*/
typedef otCacheEntryIterator Iterator;
class Iterator : public otCacheEntryIterator, public Clearable<Iterator>
{
friend class AddressResolver;
static constexpr uint8_t kListIndex = 0;
static constexpr uint8_t kEntryIndex = 1;
const CacheEntry * GetEntry(void) const { return static_cast<const CacheEntry *>(mData[kEntryIndex]); }
void SetEntry(const CacheEntry *aEntry) { mData[kEntryIndex] = aEntry; }
const CacheEntryList *GetList(void) const { return static_cast<const CacheEntryList *>(mData[kListIndex]); }
void SetList(const CacheEntryList *aList) { mData[kListIndex] = aList; }
};
/**
* This type represents an EID cache entry.
*
*/
typedef otCacheEntryInfo EntryInfo;
class EntryInfo : public otCacheEntryInfo, public Clearable<EntryInfo>
{
public:
enum State : uint8_t ///< Entry state.
{
kStateCached = OT_CACHE_ENTRY_STATE_CACHED, ///< Cached and in-use.
kStateSnooped = OT_CACHE_ENTRY_STATE_SNOOPED, ///< Created by snoop optimization.
kStateQuery = OT_CACHE_ENTRY_STATE_QUERY, ///< Ongoing query for the EID.
kStateRetryQuery = OT_CACHE_ENTRY_STATE_RETRY_QUERY, ///< In retry wait mode.
};
};
/**
* This constructor initializes the object.
@@ -215,9 +240,6 @@ private:
static constexpr uint16_t kAddressQueryMaxRetryDelay = OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY;
static constexpr uint16_t kSnoopBlockEvictionTimeout = OPENTHREAD_CONFIG_TMF_SNOOP_CACHE_ENTRY_TIMEOUT;
static constexpr uint8_t kIteratorListIndex = 0;
static constexpr uint8_t kIteratorEntryIndex = 1;
class CacheEntry : public InstanceLocatorInit
{
public:
@@ -281,7 +303,10 @@ private:
};
typedef Pool<CacheEntry, kCacheEntries> CacheEntryPool;
typedef LinkedList<CacheEntry> CacheEntryList;
class CacheEntryList : public LinkedList<CacheEntry>
{
};
enum EntryChange : uint8_t
{
@@ -367,6 +392,10 @@ private:
* @}
*/
DefineCoreType(otCacheEntryIterator, AddressResolver::Iterator);
DefineCoreType(otCacheEntryInfo, AddressResolver::EntryInfo);
DefineMapEnum(otCacheEntryState, AddressResolver::EntryInfo::State);
} // namespace ot
#endif // ADDRESS_RESOLVER_HPP_