From 756824b5fa752e0184c9669ffbae4d592eaa91f8 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Thu, 19 Mar 2020 23:24:15 -0700 Subject: [PATCH] [mpl] make MplSeedEntry private to Mpl (#4715) --- src/core/net/ip6_mpl.cpp | 48 +++++++++++++-------------- src/core/net/ip6_mpl.hpp | 70 +++++----------------------------------- 2 files changed, 32 insertions(+), 86 deletions(-) diff --git a/src/core/net/ip6_mpl.cpp b/src/core/net/ip6_mpl.cpp index 9e490a6ff..5a12c7930 100644 --- a/src/core/net/ip6_mpl.cpp +++ b/src/core/net/ip6_mpl.cpp @@ -136,16 +136,16 @@ exit: */ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) { - otError error = OT_ERROR_NONE; - MplSeedEntry *insert = NULL; - MplSeedEntry *group = mSeedSet; - MplSeedEntry *evict = mSeedSet; - uint8_t curCount = 0; - uint8_t maxCount = 0; + otError error = OT_ERROR_NONE; + SeedEntry *insert = NULL; + SeedEntry *group = mSeedSet; + SeedEntry *evict = mSeedSet; + uint8_t curCount = 0; + uint8_t maxCount = 0; for (uint32_t i = 0; i < kNumSeedEntries; i++, curCount++) { - if (mSeedSet[i].GetLifetime() == 0) + if (mSeedSet[i].mLifetime == 0) { // unused entries exist @@ -160,11 +160,11 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) break; } - if (mSeedSet[i].GetSeedId() != group->GetSeedId()) + if (mSeedSet[i].mSeedId != group->mSeedId) { // processing new group - if (aSeedId == group->GetSeedId() && insert == NULL) + if (aSeedId == group->mSeedId && insert == NULL) { // insert at end of existing group insert = &mSeedSet[i]; @@ -182,11 +182,11 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) curCount = 0; } - if (aSeedId == mSeedSet[i].GetSeedId()) + if (aSeedId == mSeedSet[i].mSeedId) { // have existing entries for aSeedId - int8_t diff = static_cast(aSequence - mSeedSet[i].GetSequence()); + int8_t diff = static_cast(aSequence - mSeedSet[i].mSequence); if (diff == 0) { @@ -202,12 +202,12 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) } } - if (evict->GetLifetime() != 0) + if (evict->mLifetime != 0) { // no free entries available, look to evict an existing entry OT_ASSERT(curCount != 0); - if (aSeedId == group->GetSeedId() && insert == NULL) + if (aSeedId == group->mSeedId && insert == NULL) { // insert at end of existing group insert = &mSeedSet[kNumSeedEntries]; @@ -232,25 +232,25 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) else { // require Sequence to be larger than oldest stored Sequence in group - VerifyOrExit(insert > mSeedSet && aSeedId == (insert - 1)->GetSeedId(), error = OT_ERROR_DROP); + VerifyOrExit(insert > mSeedSet && aSeedId == (insert - 1)->mSeedId, error = OT_ERROR_DROP); } } if (evict > insert) { OT_ASSERT(insert >= mSeedSet); - memmove(insert + 1, insert, static_cast(evict - insert) * sizeof(MplSeedEntry)); + memmove(insert + 1, insert, static_cast(evict - insert) * sizeof(SeedEntry)); } else if (evict < insert) { OT_ASSERT(evict >= mSeedSet); - memmove(evict, evict + 1, static_cast(insert - 1 - evict) * sizeof(MplSeedEntry)); + memmove(evict, evict + 1, static_cast(insert - 1 - evict) * sizeof(SeedEntry)); insert--; } - insert->SetSeedId(aSeedId); - insert->SetSequence(aSequence); - insert->SetLifetime(kSeedEntryLifetime); + insert->mSeedId = aSeedId; + insert->mSequence = aSequence; + insert->mLifetime = kSeedEntryLifetime; if (!mSeedSetTimer.IsRunning()) { @@ -271,20 +271,20 @@ void Mpl::HandleSeedSetTimer(void) bool startTimer = false; int j = 0; - for (int i = 0; i < kNumSeedEntries && mSeedSet[i].GetLifetime(); i++) + for (int i = 0; i < kNumSeedEntries && mSeedSet[i].mLifetime; i++) { - mSeedSet[i].SetLifetime(mSeedSet[i].GetLifetime() - 1); + mSeedSet[i].mLifetime--; - if (mSeedSet[i].GetLifetime() > 0) + if (mSeedSet[i].mLifetime > 0) { mSeedSet[j++] = mSeedSet[i]; startTimer = true; } } - for (; j < kNumSeedEntries && mSeedSet[j].GetLifetime(); j++) + for (; j < kNumSeedEntries && mSeedSet[j].mLifetime; j++) { - mSeedSet[j].SetLifetime(0); + mSeedSet[j].mLifetime = 0; } if (startTimer) diff --git a/src/core/net/ip6_mpl.hpp b/src/core/net/ip6_mpl.hpp index fb3ab8d04..b493a849f 100644 --- a/src/core/net/ip6_mpl.hpp +++ b/src/core/net/ip6_mpl.hpp @@ -182,67 +182,6 @@ private: uint16_t mSeedId; } OT_TOOL_PACKED_END; -/** - * This class represents an MPL's Seed Set entry. - * - */ -class MplSeedEntry -{ -public: - /** - * This method returns the MPL Seed Id value. - * - * @returns The MPL Seed Id value. - * - */ - uint16_t GetSeedId(void) const { return mSeedId; } - - /** - * This method sets the MPL Seed Id value. - * - * @param[in] aSeedId The MPL Seed Id value. - * - */ - void SetSeedId(uint16_t aSeedId) { mSeedId = aSeedId; } - - /** - * This method returns the MPL Sequence value. - * - * @returns The MPL Sequence value. - * - */ - uint8_t GetSequence(void) const { return mSequence; } - - /** - * This method sets the MPL Sequence value. - * - * @param[in] aSequence The MPL Sequence value. - * - */ - void SetSequence(uint8_t aSequence) { mSequence = aSequence; } - - /** - * This method returns the MPL Seed Set entry's remaining lifetime. - * - * @returns The MPL Seed Set entry's remaining lifetime. - * - */ - uint8_t GetLifetime(void) const { return mLifetime; } - - /** - * This method sets the remaining lifetime of the Seed Set entry. - * - * @param[in] aLifetime The remaining lifetime of the Seed Set entry. - * - */ - void SetLifetime(uint8_t aLifetime) { mLifetime = aLifetime; } - -private: - uint16_t mSeedId; - uint8_t mSequence; - uint8_t mLifetime; -}; - /** * This class implements MPL message processing. * @@ -344,12 +283,19 @@ private: kDataMessageInterval = 64 }; + struct SeedEntry + { + uint16_t mSeedId; + uint8_t mSequence; + uint8_t mLifetime; + }; + static void HandleSeedSetTimer(Timer &aTimer); void HandleSeedSetTimer(void); otError UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence); - MplSeedEntry mSeedSet[kNumSeedEntries]; + SeedEntry mSeedSet[kNumSeedEntries]; const Address *mMatchingAddress; TimerMilli mSeedSetTimer; uint16_t mSeedId;