From 54e7a9b7afa103da43197a7b7c318d35f9c274bd Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 19 Jun 2019 11:39:18 -0700 Subject: [PATCH] [indirect-sender] define ChildInfo for child indirect tx related info (#3952) This commit defines `IndirectSender::ChildInfo` class in child sender module which contains all the info needed to store (per child) for handling of indirect transmissions to the child. The `Child` class inherits from the new class. This helps keep the indirect tx info in the same file. --- src/core/thread/indirect_sender.cpp | 14 ++ src/core/thread/indirect_sender.hpp | 72 +++++++++ src/core/thread/mle_router.cpp | 2 - src/core/thread/topology.cpp | 14 -- src/core/thread/topology.hpp | 226 +--------------------------- 5 files changed, 93 insertions(+), 235 deletions(-) diff --git a/src/core/thread/indirect_sender.cpp b/src/core/thread/indirect_sender.cpp index c373c8620..92c2c7684 100644 --- a/src/core/thread/indirect_sender.cpp +++ b/src/core/thread/indirect_sender.cpp @@ -45,6 +45,20 @@ namespace ot { +const Mac::Address &IndirectSender::ChildInfo::GetMacAddress(Mac::Address &aMacAddress) const +{ + if (mUseShortAddress) + { + aMacAddress.SetShort(static_cast(this)->GetRloc16()); + } + else + { + aMacAddress.SetExtended(static_cast(this)->GetExtAddress()); + } + + return aMacAddress; +} + IndirectSender::IndirectSender(Instance &aInstance) : InstanceLocator(aInstance) , mEnabled(false) diff --git a/src/core/thread/indirect_sender.hpp b/src/core/thread/indirect_sender.hpp index c209df238..de6835aa9 100644 --- a/src/core/thread/indirect_sender.hpp +++ b/src/core/thread/indirect_sender.hpp @@ -63,6 +63,78 @@ class IndirectSender : public InstanceLocator friend class Instance; public: + /** + * This class defines all the child info required for indirect transmission. + * + * `Child` class publicly inherits from this class. + */ + class ChildInfo + { + friend class IndirectSender; + friend class SourceMatchController; + + public: + /** + * This method returns the number of queued messages for the child. + * + * @returns Number of queued messages for the child. + * + */ + uint16_t GetIndirectMessageCount(void) const { return mQueuedMessageCount; } + + private: + bool IsDataRequestPending(void) const { return mDataRequestPendig; } + void SetDataRequestPending(bool aPending) { mDataRequestPendig = aPending; } + + Message *GetIndirectMessage(void) { return mIndirectMessage; } + void SetIndirectMessage(Message *aMessage) { mIndirectMessage = aMessage; } + + uint16_t GetIndirectFragmentOffset(void) const { return mIndirectFragmentOffset; } + void SetIndirectFragmentOffset(uint16_t aFragmentOffset) { mIndirectFragmentOffset = aFragmentOffset; } + + bool GetIndirectTxSuccess(void) const { return mIndirectTxSuccess; } + void SetIndirectTxSuccess(bool aTxStatus) { mIndirectTxSuccess = aTxStatus; } + + uint32_t GetIndirectFrameCounter(void) const { return mIndirectFrameCounter; } + void SetIndirectFrameCounter(uint32_t aFrameCounter) { mIndirectFrameCounter = aFrameCounter; } + + uint8_t GetIndirectKeyId(void) const { return mIndirectKeyId; } + void SetIndirectKeyId(uint8_t aKeyId) { mIndirectKeyId = aKeyId; } + + uint8_t GetIndirectTxAttempts(void) const { return mIndirectTxAttempts; } + void ResetIndirectTxAttempts(void) { mIndirectTxAttempts = 0; } + void IncrementIndirectTxAttempts(void) { mIndirectTxAttempts++; } + + uint8_t GetIndirectDataSequenceNumber(void) const { return mIndirectDsn; } + void SetIndirectDataSequenceNumber(uint8_t aDsn) { mIndirectDsn = aDsn; } + + bool IsIndirectSourceMatchShort(void) const { return mUseShortAddress; } + void SetIndirectSourceMatchShort(bool aShort) { mUseShortAddress = aShort; } + + bool IsIndirectSourceMatchPending(void) const { return mSourceMatchPending; } + void SetIndirectSourceMatchPending(bool aPending) { mSourceMatchPending = aPending; } + + void IncrementIndirectMessageCount(void) { mQueuedMessageCount++; } + void DecrementIndirectMessageCount(void) { mQueuedMessageCount--; } + void ResetIndirectMessageCount(void) { mQueuedMessageCount = 0; } + + const Mac::Address &GetMacAddress(Mac::Address &aMacAddress) const; + + Message *mIndirectMessage; // Current indirect message. + uint16_t mIndirectFragmentOffset : 15; // 6LoWPAN fragment offset for the indirect message. + bool mIndirectTxSuccess : 1; // Indicates tx success/failure of current indirect message. + uint16_t mQueuedMessageCount : 13; // Number of queued indirect messages for the child. + bool mUseShortAddress : 1; // Indicates whether to use short or extended address. + bool mSourceMatchPending : 1; // Indicates whether or not pending to add to src match table. + bool mDataRequestPendig : 1; // Indicates whether or not a Data Poll was received, + uint32_t mIndirectFrameCounter; // Frame counter for current indirect message (used fore retx). + uint8_t mIndirectKeyId; // Key Id for current indirect message (used for retx). + uint8_t mIndirectTxAttempts; // Number of data poll triggered tx attempts. + uint8_t mIndirectDsn; // MAC level Data Sequence Number (DSN) for retx attempts. + + OT_STATIC_ASSERT(OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS < 8192, "mQueuedMessageCount cannot fit max required!"); + }; + /** * This constructor initializes the object. * diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index e9375143e..9e2558da7 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -1394,7 +1394,6 @@ otError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::Messa router->ResetLinkFailures(); router->SetLastHeard(TimerMilli::GetNow()); router->SetState(Neighbor::kStateLinkRequest); - router->SetDataRequestPending(false); SendLinkRequest(router); ExitNow(error = OT_ERROR_NO_ROUTE); } @@ -1638,7 +1637,6 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa child->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); child->ResetLinkFailures(); child->SetState(Neighbor::kStateParentRequest); - child->SetDataRequestPending(false); #if OPENTHREAD_CONFIG_ENABLE_TIME_SYNC if (Tlv::GetTlv(aMessage, Tlv::kTimeRequest, sizeof(timeRequest), timeRequest) == OT_ERROR_NONE) { diff --git a/src/core/thread/topology.cpp b/src/core/thread/topology.cpp index 09800b1dc..01a245f0f 100644 --- a/src/core/thread/topology.cpp +++ b/src/core/thread/topology.cpp @@ -240,18 +240,4 @@ void Child::GenerateChallenge(void) Random::NonCrypto::FillBuffer(mAttachChallenge, sizeof(mAttachChallenge)); } -const Mac::Address &Child::GetMacAddress(Mac::Address &aMacAddress) const -{ - if (mUseShortAddress) - { - aMacAddress.SetShort(GetRloc16()); - } - else - { - aMacAddress.SetExtended(GetExtAddress()); - } - - return aMacAddress; -} - } // namespace ot diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index b82495296..035be8c2b 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -42,6 +42,7 @@ #include "common/random.hpp" #include "mac/mac_frame.hpp" #include "net/ip6.hpp" +#include "thread/indirect_sender.hpp" #include "thread/link_quality.hpp" #include "thread/mle_tlvs.hpp" @@ -272,22 +273,6 @@ public: */ void SetRloc16(uint16_t aRloc16) { mRloc16 = aRloc16; } - /** - * This method indicates whether an IEEE 802.15.4 Data Request message was received. - * - * @returns TRUE if an IEEE 802.15.4 Data Request message was received, FALSE otherwise. - * - */ - bool IsDataRequestPending(void) const { return mDataRequest; } - - /** - * This method sets the indicator for whether an IEEE 802.15.4 Data Request message was received. - * - * @param[in] aPending TRUE if an IEEE 802.15.4 Data Request message was received, FALSE otherwise. - * - */ - void SetDataRequestPending(bool aPending) { mDataRequest = aPending; } - /** * This method gets the number of consecutive link failures. * @@ -372,11 +357,10 @@ private: } mPending; } mValidPending; - uint32_t mKeySequence; ///< Current key sequence - uint16_t mRloc16; ///< The RLOC16 - uint8_t mState : 3; ///< The link state - uint8_t mMode : 4; ///< The MLE device mode - bool mDataRequest : 1; ///< Indicates whether or not a Data Poll was received + uint32_t mKeySequence; ///< Current key sequence + uint16_t mRloc16; ///< The RLOC16 + uint8_t mState : 4; ///< The link state + uint8_t mMode : 4; ///< The MLE device mode #if OPENTHREAD_CONFIG_ENABLE_TIME_SYNC uint8_t mLinkFailures : 7; ///< Consecutive link failure count bool mTimeSyncEnabled : 1; ///< Indicates whether or not time sync feature is enabled. @@ -390,7 +374,7 @@ private: * This class represents a Thread Child. * */ -class Child : public Neighbor +class Child : public Neighbor, public IndirectSender::ChildInfo { public: enum @@ -583,180 +567,6 @@ public: */ uint8_t GetChallengeSize(void) const { return sizeof(mAttachChallenge); } - /** - * This method gets the IEEE 802.15.4 Frame Counter used during indirect retransmissions. - * - * @returns The IEEE 802.15.4 Frame Counter value. - * - */ - uint32_t GetIndirectFrameCounter(void) const { return mIndirectFrameCounter; } - - /** - * This method sets the IEEE 802.15.4 Frame Counter to use during indirect retransmissions. - * - * @param[in] aFrameCounter The IEEE 802.15.4 Frame Counter value. - * - */ - void SetIndirectFrameCounter(uint32_t aFrameCounter) { mIndirectFrameCounter = aFrameCounter; } - - /** - * This method gets the message buffer to use for indirect transmissions. - * - * @returns The message buffer. - * - */ - Message *GetIndirectMessage(void) { return mIndirectMessage; } - - /** - * This method sets the message buffer to use for indirect transmissions. - * - * @param[in] aMessage The message buffer. - * - */ - void SetIndirectMessage(Message *aMessage) { mIndirectMessage = aMessage; } - - /** - * This method gets the 6LoWPAN Fragment Offset to use for indirect transmissions. - * - * @returns The 6LoWPAN Fragment Offset value. - * - */ - uint16_t GetIndirectFragmentOffset(void) const { return mIndirectFragmentOffset; } - - /** - * This method sets the 6LoWPAN Fragment Offset to use for indirect transmissions. - * - * @param[in] aFragmentOffset The 6LoWPAN Fragment Offset value to use. - * - */ - void SetIndirectFragmentOffset(uint16_t aFragmentOffset) { mIndirectFragmentOffset = aFragmentOffset; } - - /** - * This method gets the transmission status (success/failure) of the indirect transmission. - * - * @returns The transmission status of indirect transmission, `true` indicating success, `false` indicating failure. - * - */ - bool GetIndirectTxSuccess(void) const { return mIndirectTxSuccess; } - - /** - * This method sets the transmission status (success/failure) of the indirect transmission. - * - * @param[in] aTxStatus The transmission status, `true` indicating success, `false` indicating failure. - * - */ - void SetIndirectTxSuccess(bool aTxStatus) { mIndirectTxSuccess = aTxStatus; } - - /** - * This method gets the IEEE 802.15.4 Key ID to use for indirect retransmissions. - * - * @returns The IEEE 802.15.4 Key ID value. - * - */ - uint8_t GetIndirectKeyId(void) const { return mIndirectKeyId; } - - /** - * This method sets the IEEE 802.15.4 Key ID value to use for indirect retransmissions. - * - * @param[in] aKeyId The IEEE 802.15.4 Key ID value. - * - */ - void SetIndirectKeyId(uint8_t aKeyId) { mIndirectKeyId = aKeyId; } - - /** - * This method gets the number of indirect transmission attempts for the current message. - * - * @returns The number of indirect transmission attempts. - * - */ - uint8_t GetIndirectTxAttempts(void) const { return mIndirectTxAttempts; } - - /** - * This method resets the number of indirect transmission attempts to zero. - * - */ - void ResetIndirectTxAttempts(void) { mIndirectTxAttempts = 0; } - - /** - * This method increments the number of indirect transmission attempts. - * - */ - void IncrementIndirectTxAttempts(void) { mIndirectTxAttempts++; } - - /** - * This method gets the IEEE 802.15.4 Data Sequence Number to use during indirect retransmissions. - * - * @returns The IEEE 802.15.4 Data Sequence Number value. - * - */ - uint8_t GetIndirectDataSequenceNumber(void) const { return mIndirectDsn; } - - /** - * This method sets the IEEE 802.15.4 Data Sequence Number to use during indirect retransmissions. - * - * @param[in] aDsn The IEEE 802.15.4 Data Sequence Number value. - * - */ - void SetIndirectDataSequenceNumber(uint8_t aDsn) { mIndirectDsn = aDsn; } - - /** - * This method indicates whether or not to source match on the short address. - * - * @returns TRUE if using the short address, FALSE if using the extended address. - * - */ - bool IsIndirectSourceMatchShort(void) const { return mUseShortAddress; } - - /** - * This method sets whether or not to source match on the short address. - * - * @param[in] aShort TRUE if using the short address, FALSE if using the extended address. - * - */ - void SetIndirectSourceMatchShort(bool aShort) { mUseShortAddress = aShort; } - - /** - * This method indicates whether or not the child needs to be added to the source match table. - * - * @returns TRUE if the child needs to be added to the source match table, FALSE otherwise. - * - */ - bool IsIndirectSourceMatchPending(void) const { return mSourceMatchPending; } - - /** - * This method sets whether or not the child needs to be added to the source match table. - * - * @param[in] aPending TRUE if the child needs to be added to the source match table, FALSE otherwise. - * - */ - void SetIndirectSourceMatchPending(bool aPending) { mSourceMatchPending = aPending; } - - /** - * This method returns the number of queued message(s) for the child - * - * @returns Number of queues message(s). - * - */ - uint16_t GetIndirectMessageCount(void) const { return mQueuedMessageCount; } - - /** - * This method increments the indirect message count. - * - */ - void IncrementIndirectMessageCount(void) { mQueuedMessageCount++; } - - /** - * This method decrements the indirect message count. - * - */ - void DecrementIndirectMessageCount(void) { mQueuedMessageCount--; } - - /** - * This method resets the indirect message count to zero. - * - */ - void ResetIndirectMessageCount(void) { mQueuedMessageCount = 0; } - /** * This method clears the requested TLV list. * @@ -782,17 +592,6 @@ public: */ void SetRequestTlv(uint8_t aIndex, uint8_t aType) { mRequestTlvs[aIndex] = aType; } - /** - * This method gets the mac address of child (either rloc16 or extended address depending on `UseShortAddress` - * flag). - * - * @param[out] aMacAddress A reference to a mac address object to which the child's address is copied. - * - * @returns A (const) reference to the mac address @a aMacAddress. - * - */ - const Mac::Address &GetMacAddress(Mac::Address &aMacAddress) const; - #if OPENTHREAD_ENABLE_CHILD_SUPERVISION /** @@ -827,6 +626,7 @@ private: kNumIp6Addresses = OPENTHREAD_CONFIG_IP_ADDRS_PER_CHILD - 1, }; + uint8_t mNetworkDataVersion; ///< Current Network Data version uint8_t mMeshLocalIid[Ip6::Address::kInterfaceIdentifierSize]; ///< IPv6 address IID for mesh-local address Ip6::Address mIp6Address[kNumIp6Addresses]; ///< Registered IPv6 addresses @@ -838,18 +638,6 @@ private: uint8_t mAttachChallenge[Mle::ChallengeTlv::kMaxSize]; ///< The challenge value }; - uint32_t mIndirectFrameCounter; ///< Frame counter for current indirect message (used fore retx). - Message *mIndirectMessage; ///< Current indirect message. - uint16_t mIndirectFragmentOffset : 15; ///< 6LoWPAN fragment offset for the indirect message. - bool mIndirectTxSuccess : 1; ///< Indicates tx success/failure of current indirect message. - uint8_t mIndirectKeyId; ///< Key Id for current indirect message (used for retx). - uint8_t mIndirectTxAttempts; ///< Number of data poll triggered tx attempts. - uint8_t mIndirectDsn; ///< MAC level Data Sequence Number (DSN) for retx attempts. - uint8_t mNetworkDataVersion; ///< Current Network Data version - uint16_t mQueuedMessageCount : 13; ///< Number of queued indirect messages for the child. - bool mUseShortAddress : 1; ///< Indicates whether to use short or extended address. - bool mSourceMatchPending : 1; ///< Indicates whether or not pending to add to src match table. - #if OPENTHREAD_ENABLE_CHILD_SUPERVISION uint16_t mSecondsSinceSupervision; ///< Number of seconds since last supervision of the child. #endif // OPENTHREAD_ENABLE_CHILD_SUPERVISION