mirror of
https://github.com/espressif/openthread.git
synced 2026-08-01 00:27:47 +00:00
[child-table] move StateFilter definition to Neighbor (#4419)
This commit is contained in:
committed by
Jonathan Hui
parent
5fd1083d14
commit
9398c591bf
@@ -79,7 +79,7 @@ DataPollHandler::DataPollHandler(Instance &aInstance)
|
||||
|
||||
void DataPollHandler::Clear(void)
|
||||
{
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
child.SetDataPollPending(false);
|
||||
@@ -134,7 +134,7 @@ void DataPollHandler::HandleDataPoll(Mac::RxFrame &aFrame)
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_DETACHED);
|
||||
|
||||
SuccessOrExit(aFrame.GetSrcAddr(macSource));
|
||||
child = Get<ChildTable>().FindChild(macSource, ChildTable::kInStateValidOrRestoring);
|
||||
child = Get<ChildTable>().FindChild(macSource, Child::kInStateValidOrRestoring);
|
||||
VerifyOrExit(child != NULL);
|
||||
|
||||
child->SetLastHeard(TimerMilli::GetNow());
|
||||
@@ -289,7 +289,7 @@ exit:
|
||||
|
||||
void DataPollHandler::ProcessPendingPolls(void)
|
||||
{
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child *child = iter.GetChild();
|
||||
|
||||
|
||||
@@ -600,7 +600,7 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes
|
||||
macAddr.Set(mlIidTlv.GetIid());
|
||||
macAddr.ToggleLocal();
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
|
||||
@@ -666,7 +666,7 @@ void AddressResolver::HandleAddressQuery(Coap::Message &aMessage, const Ip6::Mes
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace ot {
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
|
||||
ChildTable::Iterator::Iterator(Instance &aInstance, StateFilter aFilter)
|
||||
ChildTable::Iterator::Iterator(Instance &aInstance, Child::StateFilter aFilter)
|
||||
: InstanceLocator(aInstance)
|
||||
, mFilter(aFilter)
|
||||
, mStart(NULL)
|
||||
@@ -50,7 +50,7 @@ ChildTable::Iterator::Iterator(Instance &aInstance, StateFilter aFilter)
|
||||
Reset();
|
||||
}
|
||||
|
||||
ChildTable::Iterator::Iterator(Instance &aInstance, StateFilter aFilter, Child *aStartingChild)
|
||||
ChildTable::Iterator::Iterator(Instance &aInstance, Child::StateFilter aFilter, Child *aStartingChild)
|
||||
: InstanceLocator(aInstance)
|
||||
, mFilter(aFilter)
|
||||
, mStart(aStartingChild)
|
||||
@@ -68,7 +68,7 @@ void ChildTable::Iterator::Reset(void)
|
||||
|
||||
mChild = mStart;
|
||||
|
||||
if (!MatchesFilter(*mChild, mFilter))
|
||||
if (!mChild->MatchesFilter(mFilter))
|
||||
{
|
||||
Advance();
|
||||
}
|
||||
@@ -92,7 +92,7 @@ void ChildTable::Iterator::Advance(void)
|
||||
}
|
||||
|
||||
VerifyOrExit(mChild != mStart, mChild = NULL);
|
||||
} while (!MatchesFilter(*mChild, mFilter));
|
||||
} while (!mChild->MatchesFilter(mFilter));
|
||||
|
||||
exit:
|
||||
return;
|
||||
@@ -143,13 +143,13 @@ exit:
|
||||
return child;
|
||||
}
|
||||
|
||||
Child *ChildTable::FindChild(uint16_t aRloc16, StateFilter aFilter)
|
||||
Child *ChildTable::FindChild(uint16_t aRloc16, Child::StateFilter aFilter)
|
||||
{
|
||||
Child *child = mChildren;
|
||||
|
||||
for (uint16_t num = mMaxChildrenAllowed; num != 0; num--, child++)
|
||||
{
|
||||
if (MatchesFilter(*child, aFilter) && (child->GetRloc16() == aRloc16))
|
||||
if (child->MatchesFilter(aFilter) && (child->GetRloc16() == aRloc16))
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
@@ -161,13 +161,13 @@ exit:
|
||||
return child;
|
||||
}
|
||||
|
||||
Child *ChildTable::FindChild(const Mac::ExtAddress &aAddress, StateFilter aFilter)
|
||||
Child *ChildTable::FindChild(const Mac::ExtAddress &aAddress, Child::StateFilter aFilter)
|
||||
{
|
||||
Child *child = mChildren;
|
||||
|
||||
for (uint16_t num = mMaxChildrenAllowed; num != 0; num--, child++)
|
||||
{
|
||||
if (MatchesFilter(*child, aFilter) && (child->GetExtAddress() == aAddress))
|
||||
if (child->MatchesFilter(aFilter) && (child->GetExtAddress() == aAddress))
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
@@ -179,7 +179,7 @@ exit:
|
||||
return child;
|
||||
}
|
||||
|
||||
Child *ChildTable::FindChild(const Mac::Address &aAddress, StateFilter aFilter)
|
||||
Child *ChildTable::FindChild(const Mac::Address &aAddress, Child::StateFilter aFilter)
|
||||
{
|
||||
Child *child = NULL;
|
||||
|
||||
@@ -200,14 +200,14 @@ Child *ChildTable::FindChild(const Mac::Address &aAddress, StateFilter aFilter)
|
||||
return child;
|
||||
}
|
||||
|
||||
bool ChildTable::HasChildren(StateFilter aFilter) const
|
||||
bool ChildTable::HasChildren(Child::StateFilter aFilter) const
|
||||
{
|
||||
bool rval = false;
|
||||
const Child *child = mChildren;
|
||||
|
||||
for (uint16_t num = mMaxChildrenAllowed; num != 0; num--, child++)
|
||||
{
|
||||
if (MatchesFilter(*child, aFilter))
|
||||
if (child->MatchesFilter(aFilter))
|
||||
{
|
||||
ExitNow(rval = true);
|
||||
}
|
||||
@@ -217,14 +217,14 @@ exit:
|
||||
return rval;
|
||||
}
|
||||
|
||||
uint16_t ChildTable::GetNumChildren(StateFilter aFilter) const
|
||||
uint16_t ChildTable::GetNumChildren(Child::StateFilter aFilter) const
|
||||
{
|
||||
uint16_t numChildren = 0;
|
||||
const Child *child = mChildren;
|
||||
|
||||
for (uint16_t num = mMaxChildrenAllowed; num != 0; num--, child++)
|
||||
{
|
||||
if (MatchesFilter(*child, aFilter))
|
||||
if (child->MatchesFilter(aFilter))
|
||||
{
|
||||
numChildren++;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ otError ChildTable::SetMaxChildrenAllowed(uint16_t aMaxChildren)
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aMaxChildren > 0 && aMaxChildren <= kMaxChildren, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(!HasChildren(kInStateAnyExceptInvalid), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!HasChildren(Child::kInStateAnyExceptInvalid), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mMaxChildrenAllowed = aMaxChildren;
|
||||
|
||||
@@ -246,40 +246,6 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
bool ChildTable::MatchesFilter(const Child &aChild, StateFilter aFilter)
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
switch (aFilter)
|
||||
{
|
||||
case kInStateValid:
|
||||
rval = aChild.IsStateValid();
|
||||
break;
|
||||
|
||||
case kInStateValidOrRestoring:
|
||||
rval = aChild.IsStateValidOrRestoring();
|
||||
break;
|
||||
|
||||
case kInStateChildIdRequest:
|
||||
rval = aChild.IsStateChildIdRequest();
|
||||
break;
|
||||
|
||||
case kInStateValidOrAttaching:
|
||||
rval = aChild.IsStateValidOrAttaching();
|
||||
break;
|
||||
|
||||
case kInStateAnyExceptInvalid:
|
||||
rval = !aChild.IsStateInvalid();
|
||||
break;
|
||||
|
||||
case kInStateAnyExceptValidOrRestoring:
|
||||
rval = !aChild.IsStateValidOrRestoring();
|
||||
break;
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -50,22 +50,6 @@ namespace ot {
|
||||
class ChildTable : public InstanceLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This enumeration defines child state filters used for finding a child or iterating through the child table.
|
||||
*
|
||||
* Each filter definition accepts a subset of `Child:State` values.
|
||||
*
|
||||
*/
|
||||
enum StateFilter
|
||||
{
|
||||
kInStateValid, ///< Accept child only in `Child::kStateValid`.
|
||||
kInStateValidOrRestoring, ///< Accept child with `Child::IsStateValidOrRestoring()` being `true`.
|
||||
kInStateChildIdRequest, ///< Accept child only in `Child:kStateChildIdRequest`.
|
||||
kInStateValidOrAttaching, ///< Accept child with `Child::IsStateValidOrAttaching()` being `true`.
|
||||
kInStateAnyExceptInvalid, ///< Accept child in any state except `Child:kStateInvalid`.
|
||||
kInStateAnyExceptValidOrRestoring, ///< Accept child in any state except `Child::IsStateValidOrRestoring()`.
|
||||
};
|
||||
|
||||
/**
|
||||
* This class represents an iterator for iterating through the child entries in the child table.
|
||||
*
|
||||
@@ -80,7 +64,7 @@ public:
|
||||
* @param[in] aFilter A child state filter.
|
||||
*
|
||||
*/
|
||||
Iterator(Instance &aInstance, StateFilter aFilter);
|
||||
Iterator(Instance &aInstance, Child::StateFilter aFilter);
|
||||
|
||||
/**
|
||||
* This constructor initializes an `Iterator` instance to start from a given child.
|
||||
@@ -96,7 +80,7 @@ public:
|
||||
* @param[in] aStartingChild A pointer to a child. If non-NULL, the iterator starts from the given entry.
|
||||
*
|
||||
*/
|
||||
Iterator(Instance &aInstance, StateFilter aFilter, Child *aStartingChild);
|
||||
Iterator(Instance &aInstance, Child::StateFilter aFilter, Child *aStartingChild);
|
||||
|
||||
/**
|
||||
* This method resets the iterator to start over.
|
||||
@@ -153,9 +137,9 @@ public:
|
||||
Child *GetChild(void) { return mChild; }
|
||||
|
||||
private:
|
||||
StateFilter mFilter;
|
||||
Child * mStart;
|
||||
Child * mChild;
|
||||
Child::StateFilter mFilter;
|
||||
Child * mStart;
|
||||
Child * mChild;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -212,7 +196,7 @@ public:
|
||||
* @returns A pointer to the `Child` entry if one is found, or `NULL` otherwise.
|
||||
*
|
||||
*/
|
||||
Child *FindChild(uint16_t aRloc16, StateFilter aFilter);
|
||||
Child *FindChild(uint16_t aRloc16, Child::StateFilter aFilter);
|
||||
|
||||
/**
|
||||
* This method searches the child table for a `Child` with a given extended address also matching a given state
|
||||
@@ -224,7 +208,7 @@ public:
|
||||
* @returns A pointer to the `Child` entry if one is found, or `NULL` otherwise.
|
||||
*
|
||||
*/
|
||||
Child *FindChild(const Mac::ExtAddress &aAddress, StateFilter aFilter);
|
||||
Child *FindChild(const Mac::ExtAddress &aAddress, Child::StateFilter aFilter);
|
||||
|
||||
/**
|
||||
* This method searches the child table for a `Child` with a given address also matching a given state filter.
|
||||
@@ -235,7 +219,7 @@ public:
|
||||
* @returns A pointer to the `Child` entry if one is found, or `NULL` otherwise.
|
||||
*
|
||||
*/
|
||||
Child *FindChild(const Mac::Address &aAddress, StateFilter aFilter);
|
||||
Child *FindChild(const Mac::Address &aAddress, Child::StateFilter aFilter);
|
||||
|
||||
/**
|
||||
* This method indicates whether the child table contains any child matching a given state filter.
|
||||
@@ -245,7 +229,7 @@ public:
|
||||
* @returns TRUE if the table contains at least one child table matching the given filter, FALSE otherwise.
|
||||
*
|
||||
*/
|
||||
bool HasChildren(StateFilter aFilter) const;
|
||||
bool HasChildren(Child::StateFilter aFilter) const;
|
||||
|
||||
/**
|
||||
* This method returns the number of children in the child table matching a given state filter.
|
||||
@@ -255,7 +239,7 @@ public:
|
||||
* @returns Number of children matching the given state filer.
|
||||
*
|
||||
*/
|
||||
uint16_t GetNumChildren(StateFilter aFilter) const;
|
||||
uint16_t GetNumChildren(Child::StateFilter aFilter) const;
|
||||
|
||||
/**
|
||||
* This method returns the maximum number of children that can be supported (build-time constant).
|
||||
@@ -297,8 +281,6 @@ private:
|
||||
kMaxChildren = OPENTHREAD_CONFIG_MLE_MAX_CHILDREN,
|
||||
};
|
||||
|
||||
static bool MatchesFilter(const Child &aChild, StateFilter aFilter);
|
||||
|
||||
uint16_t mMaxChildrenAllowed;
|
||||
Child mChildren[kMaxChildren];
|
||||
};
|
||||
@@ -310,20 +292,11 @@ private:
|
||||
class ChildTable : public InstanceLocator
|
||||
{
|
||||
public:
|
||||
enum StateFilter
|
||||
{
|
||||
kInStateValid,
|
||||
kInStateValidOrRestoring,
|
||||
kInStateChildIdRequest,
|
||||
kInStateValidOrAttaching,
|
||||
kInStateAnyExceptInvalid,
|
||||
};
|
||||
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator(Instance &, StateFilter) {}
|
||||
Iterator(Instance &, StateFilter, Child *) {}
|
||||
Iterator(Instance &, Child::StateFilter) {}
|
||||
Iterator(Instance &, Child::StateFilter, Child *) {}
|
||||
void Reset(void) {}
|
||||
bool IsDone(void) const { return true; }
|
||||
void Advance(void) {}
|
||||
@@ -343,12 +316,12 @@ public:
|
||||
|
||||
Child *GetNewChild(void) { return NULL; }
|
||||
|
||||
Child *FindChild(uint16_t, StateFilter) { return NULL; }
|
||||
Child *FindChild(const Mac::ExtAddress &, StateFilter) { return NULL; }
|
||||
Child *FindChild(const Mac::Address &, StateFilter) { return NULL; }
|
||||
Child *FindChild(uint16_t, Child::StateFilter) { return NULL; }
|
||||
Child *FindChild(const Mac::ExtAddress &, Child::StateFilter) { return NULL; }
|
||||
Child *FindChild(const Mac::Address &, Child::StateFilter) { return NULL; }
|
||||
|
||||
bool HasChildren(StateFilter) const { return false; }
|
||||
uint16_t GetNumChildren(StateFilter) const { return 0; }
|
||||
bool HasChildren(Child::StateFilter) const { return false; }
|
||||
uint16_t GetNumChildren(Child::StateFilter) const { return 0; }
|
||||
uint16_t GetMaxChildren(void) const { return 0; }
|
||||
uint16_t GetMaxChildrenAllowed(void) const { return 0; }
|
||||
otError SetMaxChildrenAllowed(uint16_t) { return OT_ERROR_INVALID_STATE; }
|
||||
|
||||
@@ -72,7 +72,7 @@ void IndirectSender::Stop(void)
|
||||
{
|
||||
VerifyOrExit(mEnabled);
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
{
|
||||
iter.GetChild()->SetIndirectMessage(NULL);
|
||||
mSourceMatchController.ResetMessageCount(*iter.GetChild());
|
||||
@@ -557,8 +557,7 @@ exit:
|
||||
|
||||
void IndirectSender::ClearMessagesForRemovedChildren(void)
|
||||
{
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptValidOrRestoring); !iter.IsDone();
|
||||
iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
if (iter.GetChild()->GetIndirectMessageCount() == 0)
|
||||
{
|
||||
|
||||
@@ -133,7 +133,7 @@ otError KeyManager::SetMasterKey(const MasterKey &aKey)
|
||||
}
|
||||
|
||||
// reset child frame counters
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
{
|
||||
iter.GetChild()->SetKeySequence(0);
|
||||
iter.GetChild()->SetLinkFrameCounter(0);
|
||||
|
||||
@@ -140,7 +140,7 @@ exit:
|
||||
void MeshForwarder::RemoveMessage(Message &aMessage)
|
||||
{
|
||||
#if OPENTHREAD_FTD
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
{
|
||||
IgnoreReturnValue(mIndirectSender.RemoveMessageFromSleepyChild(aMessage, *iter.GetChild()));
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
ip6Header.GetDestination() == mle.GetRealmLocalAllThreadNodesAddress())
|
||||
{
|
||||
// destined for all sleepy children
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone();
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone();
|
||||
iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
@@ -94,7 +94,7 @@ otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
else
|
||||
{
|
||||
// destined for some sleepy children which subscribed the multicast address.
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone();
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone();
|
||||
iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
@@ -296,7 +296,7 @@ void MeshForwarder::RemoveDataResponseMessages(void)
|
||||
|
||||
if (!(ip6Header.GetDestination().IsMulticast()))
|
||||
{
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
{
|
||||
IgnoreReturnValue(mIndirectSender.RemoveMessageFromSleepyChild(*message, *iter.GetChild()));
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ void MleRouter::SetStateRouter(uint16_t aRloc16)
|
||||
Get<Mac::Mac>().SetBeaconEnabled(true);
|
||||
|
||||
// remove children that do not have matching RLOC16
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
if (GetRouterId(iter.GetChild()->GetRloc16()) != mRouterId)
|
||||
{
|
||||
@@ -356,7 +356,7 @@ void MleRouter::SetStateLeader(uint16_t aRloc16)
|
||||
Get<AddressResolver>().Clear();
|
||||
|
||||
// remove children that do not have matching RLOC16
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
if (GetRouterId(iter.GetChild()->GetRloc16()) != mRouterId)
|
||||
{
|
||||
@@ -1653,7 +1653,7 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kChallenge, sizeof(challenge), challenge));
|
||||
VerifyOrExit(challenge.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
child = mChildTable.FindChild(macAddr, ChildTable::kInStateAnyExceptInvalid);
|
||||
child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid);
|
||||
|
||||
if (child == NULL)
|
||||
{
|
||||
@@ -1799,7 +1799,7 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
}
|
||||
|
||||
// update children state
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child & child = *iter.GetChild();
|
||||
uint32_t timeout = 0;
|
||||
@@ -2052,7 +2052,7 @@ otError MleRouter::UpdateChildAddresses(const Message &aMessage, uint16_t aOffse
|
||||
// table is timed out and then trying to register its globally unique
|
||||
// IPv6 address as the new child.
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
if (iter.GetChild() == &aChild)
|
||||
{
|
||||
@@ -2112,7 +2112,7 @@ otError MleRouter::HandleChildIdRequest(const Message & aMessage,
|
||||
// Find Child
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
child = mChildTable.FindChild(macAddr, ChildTable::kInStateAnyExceptInvalid);
|
||||
child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid);
|
||||
VerifyOrExit(child != NULL, error = OT_ERROR_ALREADY);
|
||||
|
||||
// Response
|
||||
@@ -2289,7 +2289,7 @@ otError MleRouter::HandleChildUpdateRequest(const Message & aMessage,
|
||||
|
||||
// Find Child
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
child = mChildTable.FindChild(macAddr, ChildTable::kInStateAnyExceptInvalid);
|
||||
child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid);
|
||||
|
||||
tlvs[tlvslength++] = Tlv::kSourceAddress;
|
||||
|
||||
@@ -2616,7 +2616,7 @@ void MleRouter::SynchronizeChildNetworkData(void)
|
||||
{
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER);
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child & child = *iter.GetChild();
|
||||
uint8_t version;
|
||||
@@ -2889,7 +2889,7 @@ otError MleRouter::SendChildIdResponse(Child &aChild)
|
||||
|
||||
rloc16 = Get<Mac::Mac>().GetShortAddress() | mNextChildId;
|
||||
|
||||
} while (mChildTable.FindChild(rloc16, ChildTable::kInStateAnyExceptInvalid) != NULL);
|
||||
} while (mChildTable.FindChild(rloc16, Child::kInStateAnyExceptInvalid) != NULL);
|
||||
|
||||
// allocate Child ID
|
||||
aChild.SetRloc16(rloc16);
|
||||
@@ -3250,7 +3250,7 @@ Neighbor *MleRouter::GetNeighbor(uint16_t aAddress)
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
rval = mChildTable.FindChild(aAddress, ChildTable::kInStateValidOrRestoring);
|
||||
rval = mChildTable.FindChild(aAddress, Child::kInStateValidOrRestoring);
|
||||
VerifyOrExit(rval == NULL);
|
||||
|
||||
rval = mRouterTable.GetNeighbor(aAddress);
|
||||
@@ -3277,7 +3277,7 @@ Neighbor *MleRouter::GetNeighbor(const Mac::ExtAddress &aAddress)
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
rval = mChildTable.FindChild(aAddress, ChildTable::kInStateValidOrRestoring);
|
||||
rval = mChildTable.FindChild(aAddress, Child::kInStateValidOrRestoring);
|
||||
VerifyOrExit(rval == NULL);
|
||||
|
||||
rval = mRouterTable.GetNeighbor(aAddress);
|
||||
@@ -3347,7 +3347,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
|
||||
context.mContextId = 0xff;
|
||||
}
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
child = iter.GetChild();
|
||||
|
||||
@@ -3507,7 +3507,7 @@ otError MleRouter::GetChildInfoById(uint16_t aChildId, otChildInfo &aChildInfo)
|
||||
}
|
||||
|
||||
rloc16 = Get<Mac::Mac>().GetShortAddress() | aChildId;
|
||||
child = mChildTable.FindChild(rloc16, ChildTable::kInStateAnyExceptInvalid);
|
||||
child = mChildTable.FindChild(rloc16, Child::kInStateAnyExceptInvalid);
|
||||
VerifyOrExit(child != NULL, error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
error = GetChildInfo(*child, aChildInfo);
|
||||
@@ -3559,7 +3559,7 @@ void MleRouter::RestoreChildren(void)
|
||||
const Settings::ChildInfo &childInfo = iter.GetChildInfo();
|
||||
|
||||
child = mChildTable.FindChild(*static_cast<const Mac::ExtAddress *>(&childInfo.mExtAddress),
|
||||
ChildTable::kInStateAnyExceptInvalid);
|
||||
Child::kInStateAnyExceptInvalid);
|
||||
|
||||
if (child == NULL)
|
||||
{
|
||||
@@ -3635,7 +3635,7 @@ otError MleRouter::RefreshStoredChildren(void)
|
||||
|
||||
SuccessOrExit(error = Get<Settings>().DeleteChildInfo());
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++)
|
||||
{
|
||||
SuccessOrExit(error = StoreChild(*iter.GetChild()));
|
||||
}
|
||||
@@ -3802,7 +3802,7 @@ otError MleRouter::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, I
|
||||
else if (GetRouterId(aMeshDest) == mRouterId)
|
||||
{
|
||||
// mesh destination is a child of this device
|
||||
if (mChildTable.FindChild(aMeshDest, ChildTable::kInStateValidOrRestoring))
|
||||
if (mChildTable.FindChild(aMeshDest, Child::kInStateValidOrRestoring))
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
@@ -4008,7 +4008,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage,
|
||||
SendLinkRequest(NULL);
|
||||
|
||||
// send child id responses
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateChildIdRequest); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateChildIdRequest); !iter.IsDone(); iter++)
|
||||
{
|
||||
SendChildIdResponse(*iter.GetChild());
|
||||
}
|
||||
@@ -4215,7 +4215,7 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv)
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t numChildren = mChildTable.GetNumChildren(ChildTable::kInStateValid);
|
||||
uint16_t numChildren = mChildTable.GetNumChildren(Child::kInStateValid);
|
||||
uint16_t maxAllowed = mChildTable.GetMaxChildrenAllowed();
|
||||
|
||||
if ((maxAllowed - numChildren) < (maxAllowed / 3))
|
||||
@@ -4575,12 +4575,12 @@ exit:
|
||||
|
||||
bool MleRouter::HasChildren(void)
|
||||
{
|
||||
return mChildTable.HasChildren(ChildTable::kInStateValidOrAttaching);
|
||||
return mChildTable.HasChildren(Child::kInStateValidOrAttaching);
|
||||
}
|
||||
|
||||
void MleRouter::RemoveChildren(void)
|
||||
{
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
RemoveNeighbor(*iter.GetChild());
|
||||
}
|
||||
@@ -4593,7 +4593,7 @@ bool MleRouter::HasSmallNumberOfChildren(void)
|
||||
|
||||
VerifyOrExit(routerCount > mRouterDowngradeThreshold);
|
||||
|
||||
numChildren = mChildTable.GetNumChildren(ChildTable::kInStateValid);
|
||||
numChildren = mChildTable.GetNumChildren(Child::kInStateValid);
|
||||
|
||||
return numChildren < (routerCount - mRouterDowngradeThreshold) * 3;
|
||||
|
||||
@@ -4620,7 +4620,7 @@ otError MleRouter::GetMaxChildTimeout(uint32_t &aTimeout) const
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
|
||||
@@ -4686,7 +4686,7 @@ bool MleRouter::HasSleepyChildrenSubscribed(const Ip6::Address &aAddress)
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ otError NetworkDiagnostic::AppendChildTable(Message &aMessage)
|
||||
|
||||
tlv.Init();
|
||||
|
||||
count = Get<ChildTable>().GetNumChildren(ChildTable::kInStateValid);
|
||||
count = Get<ChildTable>().GetNumChildren(Child::kInStateValid);
|
||||
|
||||
// The length of the Child Table TLV may exceed the outgoing link's MTU (1280B).
|
||||
// As a workaround we limit the number of entries in the Child Table TLV,
|
||||
@@ -245,7 +245,7 @@ otError NetworkDiagnostic::AppendChildTable(Message &aMessage)
|
||||
|
||||
SuccessOrExit(error = aMessage.Append(&tlv, sizeof(ChildTableTlv)));
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
VerifyOrExit(count--);
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ otError SourceMatchController::AddPendingEntries(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
|
||||
{
|
||||
if (iter.GetChild()->IsIndirectSourceMatchPending())
|
||||
{
|
||||
|
||||
@@ -64,6 +64,40 @@ bool Neighbor::IsStateValidOrAttaching(void) const
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool Neighbor::MatchesFilter(StateFilter aFilter) const
|
||||
{
|
||||
bool matches = false;
|
||||
|
||||
switch (aFilter)
|
||||
{
|
||||
case kInStateValid:
|
||||
matches = IsStateValid();
|
||||
break;
|
||||
|
||||
case kInStateValidOrRestoring:
|
||||
matches = IsStateValidOrRestoring();
|
||||
break;
|
||||
|
||||
case kInStateChildIdRequest:
|
||||
matches = IsStateChildIdRequest();
|
||||
break;
|
||||
|
||||
case kInStateValidOrAttaching:
|
||||
matches = IsStateValidOrAttaching();
|
||||
break;
|
||||
|
||||
case kInStateAnyExceptInvalid:
|
||||
matches = !IsStateInvalid();
|
||||
break;
|
||||
|
||||
case kInStateAnyExceptValidOrRestoring:
|
||||
matches = !IsStateValidOrRestoring();
|
||||
break;
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
void Neighbor::GenerateChallenge(void)
|
||||
{
|
||||
Random::Crypto::FillBuffer(mValidPending.mPending.mChallenge, sizeof(mValidPending.mPending.mChallenge));
|
||||
|
||||
@@ -75,6 +75,22 @@ public:
|
||||
kStateValid, ///< Link is valid
|
||||
};
|
||||
|
||||
/**
|
||||
* This enumeration defines state filters used for finding a neighbor or iterating through the child/neighbor table.
|
||||
*
|
||||
* Each filter definition accepts a subset of `State` values.
|
||||
*
|
||||
*/
|
||||
enum StateFilter
|
||||
{
|
||||
kInStateValid, ///< Accept child only in `kStateValid`.
|
||||
kInStateValidOrRestoring, ///< Accept child with `IsStateValidOrRestoring()` being `true`.
|
||||
kInStateChildIdRequest, ///< Accept child only in `Child:kStateChildIdRequest`.
|
||||
kInStateValidOrAttaching, ///< Accept child with `IsStateValidOrAttaching()` being `true`.
|
||||
kInStateAnyExceptInvalid, ///< Accept child in any state except `kStateInvalid`.
|
||||
kInStateAnyExceptValidOrRestoring, ///< Accept child in any state except `IsStateValidOrRestoring()`.
|
||||
};
|
||||
|
||||
/**
|
||||
* This method returns the current state.
|
||||
*
|
||||
@@ -168,6 +184,16 @@ public:
|
||||
*/
|
||||
bool IsStateValidOrAttaching(void) const;
|
||||
|
||||
/**
|
||||
* This method indicates whether neighbor state matches a given state filter.
|
||||
*
|
||||
* @param[in] aFilter A state filter (`StateFilter` enumeration) to match against.
|
||||
*
|
||||
* @returns TRUE if the neighbor state matches the filter, FALSE otherwise.
|
||||
*
|
||||
*/
|
||||
bool MatchesFilter(StateFilter aFilter) const;
|
||||
|
||||
/**
|
||||
* This method gets the device mode flags.
|
||||
*
|
||||
|
||||
@@ -120,7 +120,7 @@ void ChildSupervisor::HandleTimer(void)
|
||||
{
|
||||
VerifyOrExit(mSupervisionInterval != 0);
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), ChildTable::kInStateValid); !iter.IsDone(); iter++)
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
Child &child = *iter.GetChild();
|
||||
|
||||
@@ -147,7 +147,7 @@ void ChildSupervisor::CheckState(void)
|
||||
// "valid" child in the child table.
|
||||
|
||||
shouldRun = ((mSupervisionInterval != 0) && (Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_DISABLED) &&
|
||||
Get<ChildTable>().HasChildren(ChildTable::kInStateValid));
|
||||
Get<ChildTable>().HasChildren(Child::kInStateValid));
|
||||
|
||||
if (shouldRun && !mTimer.IsRunning())
|
||||
{
|
||||
|
||||
@@ -51,12 +51,12 @@ struct TestChild
|
||||
otExtAddress mExtAddress;
|
||||
};
|
||||
|
||||
const ChildTable::StateFilter kAllFilters[] = {
|
||||
ChildTable::kInStateValid,
|
||||
ChildTable::kInStateValidOrRestoring,
|
||||
ChildTable::kInStateChildIdRequest,
|
||||
ChildTable::kInStateValidOrAttaching,
|
||||
ChildTable::kInStateAnyExceptInvalid,
|
||||
const Child::StateFilter kAllFilters[] = {
|
||||
Child::kInStateValid,
|
||||
Child::kInStateValidOrRestoring,
|
||||
Child::kInStateChildIdRequest,
|
||||
Child::kInStateValidOrAttaching,
|
||||
Child::kInStateAnyExceptInvalid,
|
||||
};
|
||||
|
||||
// Checks whether a `Child` matches the `TestChild` struct.
|
||||
@@ -66,8 +66,8 @@ static bool ChildMatches(const Child &aChild, const TestChild &aTestChild)
|
||||
(aChild.GetExtAddress() == static_cast<const Mac::ExtAddress &>(aTestChild.mExtAddress));
|
||||
}
|
||||
|
||||
// Checks whether a `Child::State` matches a `ChildTable::StateFilter`.
|
||||
static bool StateMatchesFilter(Child::State aState, ChildTable::StateFilter aFilter)
|
||||
// Checks whether a `Child::State` matches a `Child::StateFilter`.
|
||||
static bool StateMatchesFilter(Child::State aState, Child::StateFilter aFilter)
|
||||
{
|
||||
bool rval = false;
|
||||
Child child;
|
||||
@@ -76,27 +76,27 @@ static bool StateMatchesFilter(Child::State aState, ChildTable::StateFilter aFil
|
||||
|
||||
switch (aFilter)
|
||||
{
|
||||
case ChildTable::kInStateAnyExceptInvalid:
|
||||
case Child::kInStateAnyExceptInvalid:
|
||||
rval = (aState != Child::kStateInvalid);
|
||||
break;
|
||||
|
||||
case ChildTable::kInStateValid:
|
||||
case Child::kInStateValid:
|
||||
rval = (aState == Child::kStateValid);
|
||||
break;
|
||||
|
||||
case ChildTable::kInStateValidOrRestoring:
|
||||
case Child::kInStateValidOrRestoring:
|
||||
rval = child.IsStateValidOrRestoring();
|
||||
break;
|
||||
|
||||
case ChildTable::kInStateChildIdRequest:
|
||||
case Child::kInStateChildIdRequest:
|
||||
rval = (aState == Child::kStateChildIdRequest);
|
||||
break;
|
||||
|
||||
case ChildTable::kInStateValidOrAttaching:
|
||||
case Child::kInStateValidOrAttaching:
|
||||
rval = child.IsStateValidOrAttaching();
|
||||
break;
|
||||
|
||||
case ChildTable::kInStateAnyExceptValidOrRestoring:
|
||||
case Child::kInStateAnyExceptValidOrRestoring:
|
||||
rval = !child.IsStateValidOrRestoring();
|
||||
break;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons
|
||||
|
||||
for (uint16_t k = 0; k < OT_ARRAY_LENGTH(kAllFilters); k++)
|
||||
{
|
||||
ChildTable::StateFilter filter = kAllFilters[k];
|
||||
Child::StateFilter filter = kAllFilters[k];
|
||||
|
||||
// Verify that we can find all children from given list by rloc or extended address.
|
||||
|
||||
@@ -152,7 +152,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons
|
||||
|
||||
if (listIndex < aChildListLength)
|
||||
{
|
||||
startingChild = aTable.FindChild(aChildList[listIndex].mRloc16, ChildTable::kInStateAnyExceptInvalid);
|
||||
startingChild = aTable.FindChild(aChildList[listIndex].mRloc16, Child::kInStateAnyExceptInvalid);
|
||||
VerifyOrQuit(startingChild != NULL, "FindChild() failed");
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ void TestChildTable(void)
|
||||
|
||||
for (uint16_t i = 0; i < OT_ARRAY_LENGTH(kAllFilters); i++)
|
||||
{
|
||||
ChildTable::StateFilter filter = kAllFilters[i];
|
||||
Child::StateFilter filter = kAllFilters[i];
|
||||
|
||||
VerifyOrQuit(table->HasChildren(filter) == false, "HasChildren() failed after init");
|
||||
VerifyOrQuit(table->GetNumChildren(filter) == 0, "GetNumChildren() failed after init");
|
||||
|
||||
Reference in New Issue
Block a user