diff --git a/src/core/thread/data_poll_manager.cpp b/src/core/thread/data_poll_manager.cpp index 9285a4fd8..a2e8f1b6b 100644 --- a/src/core/thread/data_poll_manager.cpp +++ b/src/core/thread/data_poll_manager.cpp @@ -58,7 +58,7 @@ DataPollManager::DataPollManager(MeshForwarder &aMeshForwarder): mNoBufferRetxMode(false), mPollTimeoutCounter(0), mPollTxFailureCounter(0), - mResponseExpectedPolls(0) + mRemainingFastPolls(0) { } @@ -90,7 +90,7 @@ void DataPollManager::StopPolling(void) mNoBufferRetxMode = false; mPollTimeoutCounter = 0; mPollTxFailureCounter = 0; - mResponseExpectedPolls = 0; + mRemainingFastPolls = 0; mEnabled = false; } @@ -171,10 +171,10 @@ void DataPollManager::HandlePollSent(ThreadError aError) { case kThreadError_None: - if (mResponseExpectedPolls != 0) + if (mRemainingFastPolls != 0) { - mResponseExpectedPolls--; - shouldRecalculatePollPeriod = (mResponseExpectedPolls == 0); + mRemainingFastPolls--; + shouldRecalculatePollPeriod = (mRemainingFastPolls == 0); } if (mRetxMode == true) @@ -242,7 +242,7 @@ exit: return; } -void DataPollManager::HandleReceivedFrame(Mac::Frame &aFrame) +void DataPollManager::CheckFramePending(Mac::Frame &aFrame) { VerifyOrExit(mEnabled); @@ -257,7 +257,7 @@ exit: return; } -void DataPollManager::HandleTimeoutChanged(void) +void DataPollManager::RecalculatePollPeriod(void) { if (mEnabled) { @@ -278,11 +278,24 @@ void DataPollManager::SetAttachMode(bool aMode) } } -void DataPollManager::HandleResponseExpected(void) +void DataPollManager::SendFastPolls(uint8_t aNumFastPolls) { - bool shouldRecalculatePollPeriod = (mResponseExpectedPolls == 0); + bool shouldRecalculatePollPeriod = (mRemainingFastPolls == 0); - mResponseExpectedPolls = kQuickPollsForResponse; + if (aNumFastPolls == 0) + { + aNumFastPolls = kDefaultFastPolls; + } + + if (aNumFastPolls > kMaxFastPolls) + { + aNumFastPolls = kMaxFastPolls; + } + + if (mRemainingFastPolls < aNumFastPolls) + { + mRemainingFastPolls = aNumFastPolls; + } if (mEnabled && shouldRecalculatePollPeriod) { @@ -344,11 +357,11 @@ uint32_t DataPollManager::CalculatePollPeriod(void) const } } - if (mResponseExpectedPolls != 0) + if (mRemainingFastPolls != 0) { - if ((period == 0) || (period > kResponseExpectedPeriod)) + if ((period == 0) || (period > kFastPollPeriod)) { - period = kResponseExpectedPeriod; + period = kFastPollPeriod; } } diff --git a/src/core/thread/data_poll_manager.hpp b/src/core/thread/data_poll_manager.hpp index 86443d3ea..9fbe3837c 100644 --- a/src/core/thread/data_poll_manager.hpp +++ b/src/core/thread/data_poll_manager.hpp @@ -60,6 +60,12 @@ class MeshForwarder; class DataPollManager { public: + enum + { + kDefaultFastPolls = 8, ///< Default number of fast poll transmissions (@sa StartFastPolls). + kMaxFastPolls = 15, ///< Maximum number of fast poll transmissions allowed. + }; + /** * This constructor initializes the data poll manager object. * @@ -147,27 +153,27 @@ public: void HandlePollTimeout(void); /** - * This method informs the data poll manager that a mac frame has been received. - * - * Data poll manager will check the "pending frame" in the received frame header and if it is set, it will send - * an immediate data poll to retrieve the pending frame. + * This method informs the data poll manager that a mac frame has been received. It checks the "frame pending" in + * the received frame header and if it is set, data poll manager will send an immediate data poll to retrieve the + * pending frame. * */ - void HandleReceivedFrame(Mac::Frame &aFrame); + void CheckFramePending(Mac::Frame &aFrame); /** - * This method informs the data poll manager that the device's timeout value is changed. + * This method asks the data poll manager to recalculate the poll period. * - * The timeout is used to determine the default data poll period. + * This is mainly used to inform the poll manager that a parameter impacting the poll period (e.g., the child's + * timeout value which is used to determine the default data poll period) is modified. * */ - void HandleTimeoutChanged(void); + void RecalculatePollPeriod(void); /** - * This method sets/clears the attach mode on data poll period manager. + * This method sets/clears the attach mode on data poll manager. * - * When attach mode is enabled, the data poll manager will send data polls at a faster period determined by - * configuration option `OPENTHREAD_CONFIG_ATTACH_DATA_POLL_PERIOD`. + * When attach mode is enabled, the data poll manager will send data polls at a faster rate determined by + * poll period configuration option `OPENTHREAD_CONFIG_ATTACH_DATA_POLL_PERIOD`. * * @param[in] aMode The mode value. * @@ -175,27 +181,31 @@ public: void SetAttachMode(bool aMode); /** - * This method informs the data poll manager that a response is expected from the parent/sender. + * This method asks data poll manager to send the next given number of polls at a faster rate (poll period defined + * by `kFastPollPeriod`). This is used by OpenThread stack when it expects a response from the parent/sender. + * + * If @p aNumFastPolls is zero the default value specified by `kDefaultFastPolls` is used instead. The number of + * fast polls is clipped by maximum value specified by `kMaxFastPolls`. + * + * @param[in] aNumFastPolls If non-zero, number of fast polls to send, if zero, default value is used instead. * - * Data poll manager will transmit data polls more frequently (up to some fixed number of polls). */ - void HandleResponseExpected(void); + void SendFastPolls(uint8_t aNumFastPolls); private: enum // Poll period under different conditions (in milliseconds). { - kAttachDataPollPeriod = OPENTHREAD_CONFIG_ATTACH_DATA_POLL_PERIOD, - kRetxPollPeriod = 500, - kNoBufferRetxPollPeriod = 200, - kResponseExpectedPeriod = 250, - kMinPollPeriod = 10, + kAttachDataPollPeriod = OPENTHREAD_CONFIG_ATTACH_DATA_POLL_PERIOD, ///< Poll period during attach. + kRetxPollPeriod = 500, ///< Poll retx period due to tx failure. + kNoBufferRetxPollPeriod = 200, ///< Poll retx due to no buffer space. + kFastPollPeriod = 188, ///< Period used for fast polls. + kMinPollPeriod = 10, ///< Minimum allowed poll period. }; enum { kQuickPollsAfterTimeout = 5, ///< Maximum number of quick data poll tx in case of back-to-back poll timeouts. kMaxPollRetxAttempts = 5, ///< Maximum number of retransmit attempts of data poll (mac data request). - kQuickPollsForResponse = 8, ///< Number of quick data poll transmissions when a response is expected. }; enum PollPeriodSelector @@ -213,13 +223,13 @@ private: uint32_t mExternalPollPeriod; uint32_t mPollPeriod; - bool mEnabled: 1; //< Indicates if data polling is enabled/started. - bool mAttachMode: 1; //< Indicates if in attach mode (to use attach poll period). - bool mRetxMode: 1; //< Indicates if last poll tx failed at mac/radio layer(poll retx mode). - bool mNoBufferRetxMode: 1; //< Indicates if last poll tx failed due to insufficient buffer. + bool mEnabled: 1; //< Indicates whether data polling is enabled/started. + bool mAttachMode: 1; //< Indicates whether in attach mode (to use attach poll period). + bool mRetxMode: 1; //< Indicates whether last poll tx failed at mac/radio layer (poll retx mode). + bool mNoBufferRetxMode: 1; //< Indicates whether last poll tx failed due to insufficient buffer. uint8_t mPollTimeoutCounter: 4; //< Poll timeouts counter (0 to `kQuickPollsAfterTimout`). uint8_t mPollTxFailureCounter: 4; //< Poll tx failure counter (0 to `kMaxPollRetxAttempts`). - uint8_t mResponseExpectedPolls: 4; //< # of remaining quick polls when "response expected". + uint8_t mRemainingFastPolls: 4; //< Number of remaining fast polls when in transient fast polling mode. }; /** diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index e087b04d6..b5a12a084 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -1588,7 +1588,7 @@ void MeshForwarder::HandleReceivedFrame(Mac::Frame &aFrame) payload = aFrame.GetPayload(); payloadLength = aFrame.GetPayloadLength(); - mDataPollManager.HandleReceivedFrame(aFrame); + mDataPollManager.CheckFramePending(aFrame); switch (aFrame.GetType()) { diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index a50d655c2..15935dd6e 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -601,7 +601,7 @@ ThreadError Mle::SetTimeout(uint32_t aTimeout) mTimeout = aTimeout; - mNetif.GetMeshForwarder().GetDataPollManager().HandleTimeoutChanged(); + mNetif.GetMeshForwarder().GetDataPollManager().RecalculatePollPeriod(); if (mDeviceState == kDeviceStateChild) { @@ -1608,7 +1608,7 @@ ThreadError Mle::SendDataRequest(const Ip6::Address &aDestination, const uint8_t if ((mDeviceMode & ModeTlv::kModeRxOnWhenIdle) == 0) { - mNetif.GetMeshForwarder().GetDataPollManager().HandleResponseExpected(); + mNetif.GetMeshForwarder().GetDataPollManager().SendFastPolls(DataPollManager::kDefaultFastPolls); } }