mirror of
https://github.com/espressif/openthread.git
synced 2026-08-21 18:09:52 +00:00
[data-poll-sender] add GetParent() (#4419)
This commit changes the `Mle::GetParentCandidate()` to return a reference to the parent candidate and moves the selection logic between parent or parent candidate when sending data polls to `DataPollSender` from the newly added `GetParent()` method.
This commit is contained in:
committed by
Jonathan Hui
parent
1996d42d9d
commit
636352431f
@@ -62,6 +62,13 @@ DataPollSender::DataPollSender(Instance &aInstance)
|
||||
{
|
||||
}
|
||||
|
||||
const Neighbor &DataPollSender::GetParent(void) const
|
||||
{
|
||||
const Neighbor &parentCandidate = Get<Mle::MleRouter>().GetParentCandidate();
|
||||
|
||||
return parentCandidate.IsStateValid() ? parentCandidate : Get<Mle::MleRouter>().GetParent();
|
||||
}
|
||||
|
||||
otError DataPollSender::StartPolling(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
@@ -90,14 +97,12 @@ void DataPollSender::StopPolling(void)
|
||||
|
||||
otError DataPollSender::SendDataPoll(void)
|
||||
{
|
||||
otError error;
|
||||
Neighbor *parent;
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(mEnabled, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!Get<Mac::Mac>().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
parent = Get<Mle::MleRouter>().GetParentCandidate();
|
||||
VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(GetParent().IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mTimer.Stop();
|
||||
|
||||
@@ -133,18 +138,20 @@ exit:
|
||||
|
||||
otError DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
Neighbor *parent = Get<Mle::MleRouter>().GetParentCandidate();
|
||||
otError error = OT_ERROR_NONE;
|
||||
const Neighbor &parent = GetParent();
|
||||
|
||||
VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_ABORT);
|
||||
VerifyOrExit(parent.IsStateValidOrRestoring(), error = OT_ERROR_ABORT);
|
||||
|
||||
if ((Get<Mac::Mac>().GetShortAddress() == Mac::kShortAddrInvalid) || (parent != &Get<Mle::MleRouter>().GetParent()))
|
||||
// Use extended address attaching to a new parent (i.e. parent is the parent candidate).
|
||||
if ((Get<Mac::Mac>().GetShortAddress() == Mac::kShortAddrInvalid) ||
|
||||
(&parent == &Get<Mle::MleRouter>().GetParentCandidate()))
|
||||
{
|
||||
aDest.SetExtended(parent->GetExtAddress());
|
||||
aDest.SetExtended(parent.GetExtAddress());
|
||||
}
|
||||
else
|
||||
{
|
||||
aDest.SetShort(parent->GetRloc16());
|
||||
aDest.SetShort(parent.GetRloc16());
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -205,7 +212,7 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
|
||||
Get<MeshForwarder>().UpdateNeighborOnSentFrame(aFrame, aError, macDest);
|
||||
}
|
||||
|
||||
if (Get<Mle::MleRouter>().GetParentCandidate()->IsStateInvalid())
|
||||
if (GetParent().IsStateInvalid())
|
||||
{
|
||||
StopPolling();
|
||||
Get<Mle::MleRouter>().BecomeDetached();
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
#include "thread/topology.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
@@ -266,10 +267,11 @@ private:
|
||||
kRecalculatePollPeriod,
|
||||
};
|
||||
|
||||
void ScheduleNextPoll(PollPeriodSelector aPollPeriodSelector);
|
||||
uint32_t CalculatePollPeriod(void) const;
|
||||
static void HandlePollTimer(Timer &aTimer);
|
||||
static void UpdateIfLarger(uint32_t &aPeriod, uint32_t aNewPeriod);
|
||||
void ScheduleNextPoll(PollPeriodSelector aPollPeriodSelector);
|
||||
uint32_t CalculatePollPeriod(void) const;
|
||||
const Neighbor &GetParent(void) const;
|
||||
static void HandlePollTimer(Timer &aTimer);
|
||||
static void UpdateIfLarger(uint32_t &aPeriod, uint32_t aNewPeriod);
|
||||
|
||||
TimeMilli mTimerStartTime;
|
||||
uint32_t mPollPeriod;
|
||||
|
||||
@@ -3959,22 +3959,6 @@ bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const
|
||||
return aAddress.PrefixMatch(GetMeshLocal16()) >= Ip6::Address::kMeshLocalPrefixLength;
|
||||
}
|
||||
|
||||
Router *Mle::GetParentCandidate(void)
|
||||
{
|
||||
Router *rval;
|
||||
|
||||
if (mParentCandidate.IsStateValid())
|
||||
{
|
||||
rval = &mParentCandidate;
|
||||
}
|
||||
else
|
||||
{
|
||||
rval = &mParent;
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
otError Mle::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header)
|
||||
{
|
||||
otError error = OT_ERROR_DROP;
|
||||
|
||||
@@ -755,15 +755,12 @@ public:
|
||||
Router &GetParent(void) { return mParent; }
|
||||
|
||||
/**
|
||||
* This method returns a pointer to the parent candidate or parent.
|
||||
* This method get the parent candidate.
|
||||
*
|
||||
* This method is useful when sending IEEE 802.15.4 Data Request frames while attempting to attach to a new parent.
|
||||
*
|
||||
* If attempting to attach to a new parent, this method returns the parent candidate.
|
||||
* If not attempting to attach, this method returns the parent.
|
||||
* The parent candidate is valid when attempting to attach to a new parent.
|
||||
*
|
||||
*/
|
||||
Router *GetParentCandidate(void);
|
||||
Router &GetParentCandidate(void) { return mParentCandidate; }
|
||||
|
||||
/**
|
||||
* This method indicates whether or not an IPv6 address is an RLOC.
|
||||
|
||||
Reference in New Issue
Block a user