[mpl] remove retransmission logic from MTD build (#4715)

This commit is contained in:
Jonathan Hui
2020-03-23 20:59:41 -07:00
parent 8eeb1e83eb
commit 6c365287e7
4 changed files with 118 additions and 97 deletions
+5
View File
@@ -187,7 +187,12 @@ void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo)
instance.Get<Ip6::Ip6>().GetSendQueue().GetInfo(aBufferInfo->mIp6Messages, aBufferInfo->mIp6Buffers);
#if OPENTHREAD_FTD
instance.Get<Ip6::Mpl>().GetBufferedMessageSet().GetInfo(aBufferInfo->mMplMessages, aBufferInfo->mMplBuffers);
#else
aBufferInfo->mMplMessages = 0;
aBufferInfo->mMplBuffers = 0;
#endif
instance.Get<Mle::MleRouter>().GetMessageQueue().GetInfo(aBufferInfo->mMleMessages, aBufferInfo->mMleBuffers);
+84 -76
View File
@@ -43,24 +43,16 @@
namespace ot {
namespace Ip6 {
void MplBufferedMessageMetadata::GenerateNextTransmissionTime(TimeMilli aCurrentTime, uint8_t aInterval)
{
// Emulate Trickle timer behavior and set up the next retransmission within [0,I) range.
uint8_t t = (aInterval == 0) ? aInterval : Random::NonCrypto::GetUint8InRange(0, aInterval);
// Set transmission time at the beginning of the next interval.
SetTransmissionTime(aCurrentTime + static_cast<uint32_t>(GetIntervalOffset() + t));
SetIntervalOffset(aInterval - t);
}
Mpl::Mpl(Instance &aInstance)
: InstanceLocator(aInstance)
, mTimerExpirations(0)
, mSequence(0)
, mSeedId(0)
, mSeedSetTimer(aInstance, &Mpl::HandleSeedSetTimer, this)
, mRetransmissionTimer(aInstance, &Mpl::HandleRetransmissionTimer, this)
, mMatchingAddress(NULL)
, mSeedSetTimer(aInstance, &Mpl::HandleSeedSetTimer, this)
, mSeedId(0)
, mSequence(0)
#if OPENTHREAD_FTD
, mRetransmissionTimer(aInstance, &Mpl::HandleRetransmissionTimer, this)
, mTimerExpirations(0)
#endif
{
memset(mSeedSet, 0, sizeof(mSeedSet));
}
@@ -85,6 +77,42 @@ void Mpl::InitOption(OptionMpl &aOption, const Address &aAddress)
}
}
otError Mpl::ProcessOption(Message &aMessage, const Address &aAddress, bool aIsOutbound)
{
otError error;
OptionMpl option;
VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(option), &option) >= OptionMpl::kMinLength &&
(option.GetSeedIdLength() == OptionMpl::kSeedIdLength0 ||
option.GetSeedIdLength() == OptionMpl::kSeedIdLength2),
error = OT_ERROR_PARSE);
if (option.GetSeedIdLength() == OptionMpl::kSeedIdLength0)
{
// Retrieve MPL Seed Id from the IPv6 Source Address.
option.SetSeedId(HostSwap16(aAddress.mFields.m16[7]));
}
// Check if the MPL Data Message is new.
error = UpdateSeedSet(option.GetSeedId(), option.GetSequence());
if (error == OT_ERROR_NONE)
{
#if OPENTHREAD_FTD
AddBufferedMessage(aMessage, option.GetSeedId(), option.GetSequence(), aIsOutbound);
#endif
}
else if (aIsOutbound)
{
// In case MPL Data Message is generated locally, ignore potential error of the MPL Seed Set
// to allow subsequent retransmissions with the same sequence number.
ExitNow(error = OT_ERROR_NONE);
}
exit:
return error;
}
/*
* mSeedSet stores recently received (Seed ID, Sequence) values.
* - (Seed ID, Sequence) values are grouped by Seed ID.
@@ -233,6 +261,40 @@ exit:
return error;
}
void Mpl::HandleSeedSetTimer(Timer &aTimer)
{
aTimer.GetOwner<Mpl>().HandleSeedSetTimer();
}
void Mpl::HandleSeedSetTimer(void)
{
bool startTimer = false;
int j = 0;
for (int i = 0; i < kNumSeedEntries && mSeedSet[i].GetLifetime(); i++)
{
mSeedSet[i].SetLifetime(mSeedSet[i].GetLifetime() - 1);
if (mSeedSet[i].GetLifetime() > 0)
{
mSeedSet[j++] = mSeedSet[i];
startTimer = true;
}
}
for (; j < kNumSeedEntries && mSeedSet[j].GetLifetime(); j++)
{
mSeedSet[j].SetLifetime(0);
}
if (startTimer)
{
mSeedSetTimer.Start(kSeedEntryLifetimeDt);
}
}
#if OPENTHREAD_FTD
void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound)
{
otError error = OT_ERROR_NONE;
@@ -275,38 +337,14 @@ exit:
}
}
otError Mpl::ProcessOption(Message &aMessage, const Address &aAddress, bool aIsOutbound)
void MplBufferedMessageMetadata::GenerateNextTransmissionTime(TimeMilli aCurrentTime, uint8_t aInterval)
{
otError error;
OptionMpl option;
// Emulate Trickle timer behavior and set up the next retransmission within [0,I) range.
uint8_t t = (aInterval == 0) ? aInterval : Random::NonCrypto::GetUint8InRange(0, aInterval);
VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(option), &option) >= OptionMpl::kMinLength &&
(option.GetSeedIdLength() == OptionMpl::kSeedIdLength0 ||
option.GetSeedIdLength() == OptionMpl::kSeedIdLength2),
error = OT_ERROR_PARSE);
if (option.GetSeedIdLength() == OptionMpl::kSeedIdLength0)
{
// Retrieve MPL Seed Id from the IPv6 Source Address.
option.SetSeedId(aAddress.GetLocator());
}
// Check if the MPL Data Message is new.
error = UpdateSeedSet(option.GetSeedId(), option.GetSequence());
if (error == OT_ERROR_NONE)
{
AddBufferedMessage(aMessage, option.GetSeedId(), option.GetSequence(), aIsOutbound);
}
else if (aIsOutbound)
{
// In case MPL Data Message is generated locally, ignore potential error of the MPL Seed Set
// to allow subsequent retransmissions with the same sequence number.
ExitNow(error = OT_ERROR_NONE);
}
exit:
return error;
// Set transmission time at the beginning of the next interval.
SetTransmissionTime(aCurrentTime + static_cast<uint32_t>(GetIntervalOffset() + t));
SetIntervalOffset(aInterval - t);
}
void Mpl::HandleRetransmissionTimer(Timer &aTimer)
@@ -392,37 +430,7 @@ void Mpl::HandleRetransmissionTimer(void)
}
}
void Mpl::HandleSeedSetTimer(Timer &aTimer)
{
aTimer.GetOwner<Mpl>().HandleSeedSetTimer();
}
void Mpl::HandleSeedSetTimer(void)
{
bool startTimer = false;
int j = 0;
for (int i = 0; i < kNumSeedEntries && mSeedSet[i].GetLifetime(); i++)
{
mSeedSet[i].SetLifetime(mSeedSet[i].GetLifetime() - 1);
if (mSeedSet[i].GetLifetime() > 0)
{
mSeedSet[j++] = mSeedSet[i];
startTimer = true;
}
}
for (; j < kNumSeedEntries && mSeedSet[j].GetLifetime(); j++)
{
mSeedSet[j].SetLifetime(0);
}
if (startTimer)
{
mSeedSetTimer.Start(kSeedEntryLifetimeDt);
}
}
#endif // OPENTHREAD_FTD
} // namespace Ip6
} // namespace ot
+25 -21
View File
@@ -243,6 +243,7 @@ private:
uint8_t mLifetime;
};
#if OPENTHREAD_FTD
/**
* This class represents metadata required for MPL retransmissions.
*
@@ -406,6 +407,7 @@ private:
TimeMilli mTransmissionTime;
uint8_t mIntervalOffset;
};
#endif // OPENTHREAD_FTD
/**
* This class implements MPL message processing.
@@ -463,6 +465,15 @@ public:
*/
void SetSeedId(uint16_t aSeedId) { mSeedId = aSeedId; }
/**
* This method sets the IPv6 matching address, that allows to elide MPL Seed Id.
*
* @param[in] aAddress The reference to the IPv6 matching address.
*
*/
void SetMatchingAddress(const Address &aAddress) { mMatchingAddress = &aAddress; }
#if OPENTHREAD_FTD
/**
* This method gets the MPL number of Trickle timer expirations that occur before
* terminating the Trickle algorithm's retransmission of a given MPL Data Message.
@@ -481,14 +492,6 @@ public:
*/
void SetTimerExpirations(uint8_t aTimerExpirations) { mTimerExpirations = aTimerExpirations; }
/**
* This method sets the IPv6 matching address, that allows to elide MPL Seed Id.
*
* @param[in] aAddress The reference to the IPv6 matching address.
*
*/
void SetMatchingAddress(const Address &aAddress) { mMatchingAddress = &aAddress; }
/**
* This method returns a reference to the buffered message set.
*
@@ -496,6 +499,7 @@ public:
*
*/
const MessageQueue &GetBufferedMessageSet(void) const { return mBufferedMessageSet; }
#endif
private:
enum
@@ -506,27 +510,27 @@ private:
kDataMessageInterval = 64
};
otError UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence);
void UpdateBufferedSet(uint16_t aSeedId, uint8_t aSequence);
void AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound);
static void HandleSeedSetTimer(Timer &aTimer);
void HandleSeedSetTimer(void);
otError UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence);
MplSeedEntry mSeedSet[kNumSeedEntries];
const Address *mMatchingAddress;
TimerMilli mSeedSetTimer;
uint16_t mSeedId;
uint8_t mSequence;
#if OPENTHREAD_FTD
static void HandleRetransmissionTimer(Timer &aTimer);
void HandleRetransmissionTimer(void);
uint8_t mTimerExpirations;
uint8_t mSequence;
uint16_t mSeedId;
void AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound);
TimerMilli mSeedSetTimer;
TimerMilli mRetransmissionTimer;
const Address *mMatchingAddress;
MplSeedEntry mSeedSet[kNumSeedEntries];
MessageQueue mBufferedMessageSet;
TimerMilli mRetransmissionTimer;
uint8_t mTimerExpirations;
#endif
};
/**
+4
View File
@@ -759,7 +759,9 @@ void Mle::SetStateDetached(void)
Get<Mac::Mac>().SetBeaconEnabled(false);
Get<MleRouter>().HandleDetachStart();
Get<Ip6::Ip6>().SetForwardingEnabled(false);
#if OPENTHREAD_FTD
Get<Ip6::Mpl>().SetTimerExpirations(0);
#endif
}
void Mle::SetStateChild(uint16_t aRloc16)
@@ -789,7 +791,9 @@ void Mle::SetStateChild(uint16_t aRloc16)
Get<NetworkData::Local>().ClearResubmitDelayTimer();
#endif
Get<Ip6::Ip6>().SetForwardingEnabled(false);
#if OPENTHREAD_FTD
Get<Ip6::Mpl>().SetTimerExpirations(kMplChildDataMessageTimerExpirations);
#endif
// send announce after attached if needed
InformPreviousChannel();