[topology] define 'Neighbor::Info', 'Child::Info', and 'Router::Info' (#5328)

This commit adds new class definitions in `topology` to represent
neighbor/child/router info.
This commit is contained in:
Abtin Keshavarzian
2020-08-03 21:33:34 -07:00
committed by GitHub
parent 5c6c798576
commit 481f69703b
8 changed files with 134 additions and 90 deletions
+1 -1
View File
@@ -304,7 +304,7 @@ otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterato
OT_ASSERT((aInfo != nullptr) && (aIterator != nullptr));
return instance.Get<Mle::MleRouter>().GetNextNeighborInfo(*aIterator, *aInfo);
return instance.Get<Mle::MleRouter>().GetNextNeighborInfo(*aIterator, *static_cast<Neighbor::Info *>(aInfo));
}
otDeviceRole otThreadGetDeviceRole(otInstance *aInstance)
+3 -3
View File
@@ -259,7 +259,7 @@ otError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChi
OT_ASSERT(aChildInfo != nullptr);
return instance.Get<Mle::MleRouter>().GetChildInfoById(aChildId, *aChildInfo);
return instance.Get<Mle::MleRouter>().GetChildInfoById(aChildId, *static_cast<Child::Info *>(aChildInfo));
}
otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint16_t aChildIndex, otChildInfo *aChildInfo)
@@ -268,7 +268,7 @@ otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint16_t aChildIndex,
OT_ASSERT(aChildInfo != nullptr);
return instance.Get<Mle::MleRouter>().GetChildInfoByIndex(aChildIndex, *aChildInfo);
return instance.Get<Mle::MleRouter>().GetChildInfoByIndex(aChildIndex, *static_cast<Child::Info *>(aChildInfo));
}
otError otThreadGetChildNextIp6Address(otInstance * aInstance,
@@ -319,7 +319,7 @@ otError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRoute
OT_ASSERT(aRouterInfo != nullptr);
return instance.Get<RouterTable>().GetRouterInfo(aRouterId, *aRouterInfo);
return instance.Get<RouterTable>().GetRouterInfo(aRouterId, *static_cast<Router::Info *>(aRouterInfo));
}
otError otThreadGetNextCacheEntry(otInstance *aInstance, otCacheEntryInfo *aEntryInfo, otCacheEntryIterator *aIterator)
+12 -68
View File
@@ -3663,7 +3663,7 @@ void MleRouter::SetRouterId(uint8_t aRouterId)
mPreviousRouterId = mRouterId;
}
otError MleRouter::GetChildInfoById(uint16_t aChildId, otChildInfo &aChildInfo)
otError MleRouter::GetChildInfoById(uint16_t aChildId, Child::Info &aChildInfo)
{
otError error = OT_ERROR_NONE;
Child * child;
@@ -3675,24 +3675,24 @@ otError MleRouter::GetChildInfoById(uint16_t aChildId, otChildInfo &aChildInfo)
}
rloc16 = Get<Mac::Mac>().GetShortAddress() | aChildId;
child = mChildTable.FindChild(rloc16, Child::kInStateAnyExceptInvalid);
child = mChildTable.FindChild(rloc16, Child::kInStateValidOrRestoring);
VerifyOrExit(child != nullptr, error = OT_ERROR_NOT_FOUND);
error = GetChildInfo(*child, aChildInfo);
aChildInfo.SetFrom(*child);
exit:
return error;
}
otError MleRouter::GetChildInfoByIndex(uint16_t aChildIndex, otChildInfo &aChildInfo)
otError MleRouter::GetChildInfoByIndex(uint16_t aChildIndex, Child::Info &aChildInfo)
{
otError error = OT_ERROR_NONE;
Child * child = nullptr;
child = mChildTable.GetChildAtIndex(aChildIndex);
VerifyOrExit(child != nullptr, error = OT_ERROR_NOT_FOUND);
VerifyOrExit((child != nullptr) && child->IsStateValidOrRestoring(), error = OT_ERROR_NOT_FOUND);
error = GetChildInfo(*child, aChildInfo);
aChildInfo.SetFrom(*child);
exit:
return error;
@@ -3793,59 +3793,10 @@ exit:
return;
}
otError MleRouter::GetChildInfo(Child &aChild, otChildInfo &aChildInfo)
otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, Neighbor::Info &aNeighInfo)
{
otError error = OT_ERROR_NONE;
VerifyOrExit(aChild.IsStateValidOrRestoring(), error = OT_ERROR_NOT_FOUND);
memset(&aChildInfo, 0, sizeof(aChildInfo));
aChildInfo.mExtAddress = aChild.GetExtAddress();
aChildInfo.mTimeout = aChild.GetTimeout();
aChildInfo.mRloc16 = aChild.GetRloc16();
aChildInfo.mChildId = ChildIdFromRloc16(aChild.GetRloc16());
aChildInfo.mNetworkDataVersion = aChild.GetNetworkDataVersion();
aChildInfo.mAge = Time::MsecToSec(TimerMilli::GetNow() - aChild.GetLastHeard());
aChildInfo.mLinkQualityIn = aChild.GetLinkInfo().GetLinkQuality();
aChildInfo.mAverageRssi = aChild.GetLinkInfo().GetAverageRss();
aChildInfo.mLastRssi = aChild.GetLinkInfo().GetLastRss();
aChildInfo.mFrameErrorRate = aChild.GetLinkInfo().GetFrameErrorRate();
aChildInfo.mMessageErrorRate = aChild.GetLinkInfo().GetMessageErrorRate();
aChildInfo.mRxOnWhenIdle = aChild.IsRxOnWhenIdle();
aChildInfo.mSecureDataRequest = aChild.IsSecureDataRequest();
aChildInfo.mFullThreadDevice = aChild.IsFullThreadDevice();
aChildInfo.mFullNetworkData = aChild.IsFullNetworkData();
aChildInfo.mIsStateRestoring = aChild.IsStateRestoring();
exit:
return error;
}
void MleRouter::GetNeighborInfo(Neighbor &aNeighbor, otNeighborInfo &aNeighInfo)
{
aNeighInfo.mExtAddress = aNeighbor.GetExtAddress();
aNeighInfo.mAge = Time::MsecToSec(TimerMilli::GetNow() - aNeighbor.GetLastHeard());
aNeighInfo.mRloc16 = aNeighbor.GetRloc16();
aNeighInfo.mLinkFrameCounter = aNeighbor.GetLinkFrameCounter();
aNeighInfo.mMleFrameCounter = aNeighbor.GetMleFrameCounter();
aNeighInfo.mLinkQualityIn = aNeighbor.GetLinkInfo().GetLinkQuality();
aNeighInfo.mAverageRssi = aNeighbor.GetLinkInfo().GetAverageRss();
aNeighInfo.mLastRssi = aNeighbor.GetLinkInfo().GetLastRss();
aNeighInfo.mFrameErrorRate = aNeighbor.GetLinkInfo().GetFrameErrorRate();
aNeighInfo.mMessageErrorRate = aNeighbor.GetLinkInfo().GetMessageErrorRate();
aNeighInfo.mRxOnWhenIdle = aNeighbor.IsRxOnWhenIdle();
aNeighInfo.mSecureDataRequest = aNeighbor.IsSecureDataRequest();
aNeighInfo.mFullThreadDevice = aNeighbor.IsFullThreadDevice();
aNeighInfo.mFullNetworkData = aNeighbor.IsFullNetworkData();
}
otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeighborInfo &aNeighInfo)
{
otError error = OT_ERROR_NONE;
Neighbor *neighbor = nullptr;
int16_t index;
memset(&aNeighInfo, 0, sizeof(aNeighInfo));
int16_t index;
// Non-negative iterator value gives the Child index into child table
@@ -3862,7 +3813,7 @@ otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeig
if (child->IsStateValid())
{
neighbor = child;
aNeighInfo.SetFrom(*child);
aNeighInfo.mIsChild = true;
index++;
aIterator = index;
@@ -3881,7 +3832,7 @@ otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeig
if (router != nullptr && router->IsStateValid())
{
neighbor = router;
aNeighInfo.SetFrom(*router);
aNeighInfo.mIsChild = false;
index++;
aIterator = -index;
@@ -3893,12 +3844,6 @@ otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeig
error = OT_ERROR_NOT_FOUND;
exit:
if (neighbor != nullptr)
{
GetNeighborInfo(*neighbor, aNeighInfo);
}
return error;
}
@@ -4776,13 +4721,12 @@ void MleRouter::Signal(otNeighborTableEvent aEvent, Neighbor &aNeighbor)
{
case OT_NEIGHBOR_TABLE_EVENT_CHILD_ADDED:
case OT_NEIGHBOR_TABLE_EVENT_CHILD_REMOVED:
error = GetChildInfo(static_cast<Child &>(aNeighbor), info.mInfo.mChild);
OT_ASSERT(error == OT_ERROR_NONE);
static_cast<Child::Info &>(info.mInfo.mChild).SetFrom(static_cast<Child &>(aNeighbor));
break;
case OT_NEIGHBOR_TABLE_EVENT_ROUTER_ADDED:
case OT_NEIGHBOR_TABLE_EVENT_ROUTER_REMOVED:
GetNeighborInfo(aNeighbor, info.mInfo.mRouter);
static_cast<Neighbor::Info &>(info.mInfo.mRouter).SetFrom(aNeighbor);
break;
}
+3 -5
View File
@@ -430,7 +430,7 @@ public:
* @param[out] aChildInfo The child information.
*
*/
otError GetChildInfoById(uint16_t aChildId, otChildInfo &aChildInfo);
otError GetChildInfoById(uint16_t aChildId, Child::Info &aChildInfo);
/**
* This method retains diagnostic information for an attached child by the internal table index.
@@ -439,7 +439,7 @@ public:
* @param[out] aChildInfo The child information.
*
*/
otError GetChildInfoByIndex(uint16_t aChildIndex, otChildInfo &aChildInfo);
otError GetChildInfoByIndex(uint16_t aChildIndex, Child::Info &aChildInfo);
/**
* This method indicates whether or not the RLOC16 is an MTD child of this device.
@@ -464,7 +464,7 @@ public:
* @retval OT_ERROR_NOT_FOUND No subsequent neighbor entry exists in the table.
*
*/
otError GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeighborInfo &aNeighInfo);
otError GetNextNeighborInfo(otNeighborInfoIterator &aIterator, Neighbor::Info &aNeighInfo);
/**
* This method indicates whether or not the given Thread partition attributes are preferred.
@@ -706,8 +706,6 @@ private:
otError AppendRoute(Message &aMessage);
otError AppendActiveDataset(Message &aMessage);
otError AppendPendingDataset(Message &aMessage);
otError GetChildInfo(Child &aChild, otChildInfo &aChildInfo);
void GetNeighborInfo(Neighbor &aNeighbor, otNeighborInfo &aNeighInfo);
void RefreshStoredChildren(void);
void HandleDetachStart(void);
void HandleChildStart(AttachMode aMode);
+2 -12
View File
@@ -415,7 +415,7 @@ Router *RouterTable::GetRouter(const Mac::ExtAddress &aExtAddress)
return router;
}
otError RouterTable::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo)
otError RouterTable::GetRouterInfo(uint16_t aRouterId, Router::Info &aRouterInfo)
{
otError error = OT_ERROR_NONE;
Router *router;
@@ -435,17 +435,7 @@ otError RouterTable::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo
router = GetRouter(routerId);
VerifyOrExit(router != nullptr, error = OT_ERROR_NOT_FOUND);
memset(&aRouterInfo, 0, sizeof(aRouterInfo));
aRouterInfo.mRouterId = routerId;
aRouterInfo.mRloc16 = Mle::Mle::Rloc16FromRouterId(routerId);
aRouterInfo.mExtAddress = router->GetExtAddress();
aRouterInfo.mAllocated = true;
aRouterInfo.mNextHop = router->GetNextHop();
aRouterInfo.mLinkEstablished = router->IsStateValid();
aRouterInfo.mPathCost = router->GetCost();
aRouterInfo.mLinkQualityIn = router->GetLinkInfo().GetLinkQuality();
aRouterInfo.mLinkQualityOut = router->GetLinkQualityOut();
aRouterInfo.mAge = static_cast<uint8_t>(Time::MsecToSec(TimerMilli::GetNow() - router->GetLastHeard()));
aRouterInfo.SetFrom(*router);
exit:
return error;
+1 -1
View File
@@ -331,7 +331,7 @@ public:
* @retval OT_ERROR_NOT_FOUND No router entry with the given id.
*
*/
otError GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo);
otError GetRouterInfo(uint16_t aRouterId, Router::Info &aRouterInfo);
/**
* This method returns the Router ID Sequence.
+55
View File
@@ -41,6 +41,25 @@
namespace ot {
void Neighbor::Info::SetFrom(const Neighbor &aNeighbor)
{
Clear();
mExtAddress = aNeighbor.GetExtAddress();
mAge = Time::MsecToSec(TimerMilli::GetNow() - aNeighbor.GetLastHeard());
mRloc16 = aNeighbor.GetRloc16();
mLinkFrameCounter = aNeighbor.GetLinkFrameCounter();
mMleFrameCounter = aNeighbor.GetMleFrameCounter();
mLinkQualityIn = aNeighbor.GetLinkInfo().GetLinkQuality();
mAverageRssi = aNeighbor.GetLinkInfo().GetAverageRss();
mLastRssi = aNeighbor.GetLinkInfo().GetLastRss();
mFrameErrorRate = aNeighbor.GetLinkInfo().GetFrameErrorRate();
mMessageErrorRate = aNeighbor.GetLinkInfo().GetMessageErrorRate();
mRxOnWhenIdle = aNeighbor.IsRxOnWhenIdle();
mSecureDataRequest = aNeighbor.IsSecureDataRequest();
mFullThreadDevice = aNeighbor.IsFullThreadDevice();
mFullNetworkData = aNeighbor.IsFullNetworkData();
}
void Neighbor::Init(Instance &aInstance)
{
InstanceLocatorInit::Init(aInstance);
@@ -111,6 +130,27 @@ void Neighbor::GenerateChallenge(void)
Random::Crypto::FillBuffer(mValidPending.mPending.mChallenge, sizeof(mValidPending.mPending.mChallenge)));
}
void Child::Info::SetFrom(const Child &aChild)
{
Clear();
mExtAddress = aChild.GetExtAddress();
mTimeout = aChild.GetTimeout();
mRloc16 = aChild.GetRloc16();
mChildId = Mle::Mle::ChildIdFromRloc16(aChild.GetRloc16());
mNetworkDataVersion = aChild.GetNetworkDataVersion();
mAge = Time::MsecToSec(TimerMilli::GetNow() - aChild.GetLastHeard());
mLinkQualityIn = aChild.GetLinkInfo().GetLinkQuality();
mAverageRssi = aChild.GetLinkInfo().GetAverageRss();
mLastRssi = aChild.GetLinkInfo().GetLastRss();
mFrameErrorRate = aChild.GetLinkInfo().GetFrameErrorRate();
mMessageErrorRate = aChild.GetLinkInfo().GetMessageErrorRate();
mRxOnWhenIdle = aChild.IsRxOnWhenIdle();
mSecureDataRequest = aChild.IsSecureDataRequest();
mFullThreadDevice = aChild.IsFullThreadDevice();
mFullNetworkData = aChild.IsFullNetworkData();
mIsStateRestoring = aChild.IsStateRestoring();
}
const Ip6::Address *Child::AddressIterator::GetAddress(void) const
{
// `mIndex` value of zero indicates mesh-local IPv6 address.
@@ -343,6 +383,21 @@ void Child::SetAddressMlrState(const Ip6::Address &aAddress, MlrState aState)
}
#endif // OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE
void Router::Info::SetFrom(const Router &aRouter)
{
Clear();
mRloc16 = aRouter.GetRloc16();
mRouterId = Mle::Mle::RouterIdFromRloc16(mRloc16);
mExtAddress = aRouter.GetExtAddress();
mAllocated = true;
mNextHop = aRouter.GetNextHop();
mLinkEstablished = aRouter.IsStateValid();
mPathCost = aRouter.GetCost();
mLinkQualityIn = aRouter.GetLinkInfo().GetLinkQuality();
mLinkQualityOut = aRouter.GetLinkQualityOut();
mAge = static_cast<uint8_t>(Time::MsecToSec(TimerMilli::GetNow() - aRouter.GetLastHeard()));
}
void Router::Clear(void)
{
Instance &instance = GetInstance();
+57
View File
@@ -38,6 +38,7 @@
#include <openthread/thread_ftd.h>
#include "common/clearable.hpp"
#include "common/locator.hpp"
#include "common/message.hpp"
#include "common/random.hpp"
@@ -90,6 +91,22 @@ public:
kInStateAnyExceptValidOrRestoring, ///< Accept child in any state except `IsStateValidOrRestoring()`.
};
/**
* This type represents diagnostic information for a neighboring node.
*
*/
class Info : public otNeighborInfo, public Clearable<Info>
{
public:
/**
* This method sets the `Info` instance from a given `Neighbor`.
*
* @param[in] aNeighbor A neighbor.
*
*/
void SetFrom(const Neighbor &aNeighbor);
};
/**
* This method returns the current state.
*
@@ -412,6 +429,14 @@ public:
*/
LinkQualityInfo &GetLinkInfo(void) { return mLinkInfo; }
/**
* This method returns the LinkQualityInfo object.
*
* @returns The LinkQualityInfo object.
*
*/
const LinkQualityInfo &GetLinkInfo(void) const { return mLinkInfo; }
/**
* This method generates a new challenge value for MLE Link Request/Response exchanges.
*
@@ -505,6 +530,22 @@ public:
kMaxRequestTlvs = 5,
};
/**
* This class represents diagnostic information for a Thread Child.
*
*/
class Info : public otChildInfo, public Clearable<Info>
{
public:
/**
* This method sets the `Info` instance from a given `Child`.
*
* @param[in] aChild A neighbor.
*
*/
void SetFrom(const Child &aChild);
};
/**
* This class defines an iterator used to go through IPv6 address entries of a child.
*
@@ -986,6 +1027,22 @@ private:
class Router : public Neighbor
{
public:
/**
* This class represents diagnostic information for a Thread Router.
*
*/
class Info : public otRouterInfo, public Clearable<Info>
{
public:
/**
* This method sets the `Info` instance from a given `Router`.
*
* @param[in] aRouter A router.
*
*/
void SetFrom(const Router &aRouter);
};
/**
* This method initializes the `Router` object.
*