Skip to content

Commit 89093da

Browse files
Make it possible to dynamically set the "sender boost" for MRP.
CHIP_CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST is a compile-time constant meant to capture the fact that we might be on a high-latency radio connection. But the same binary might be used on different types of hardware that have different MRP requirements. This change makes it possible to control the behavior CHIP_CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST is used for at run time, based on the actual hardware involved, not just at compile time. The new functionality is gated by the default-off CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG compiler flag, so only systems that really need it pay the cost for it.
1 parent d87e006 commit 89093da

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/messaging/ReliableMessageMgr.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ using namespace chip::System::Clock::Literals;
4747
namespace chip {
4848
namespace Messaging {
4949

50+
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
51+
Optional<System::Clock::Milliseconds64> ReliableMessageMgr::sAdditionalMRPBackoffTime;
52+
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
53+
5054
ReliableMessageMgr::RetransTableEntry::RetransTableEntry(ReliableMessageContext * rc) :
5155
ec(*rc->GetExchangeContext()), nextRetransTime(0), sendCount(0)
5256
{
@@ -263,7 +267,11 @@ System::Clock::Timestamp ReliableMessageMgr::GetBackoff(System::Clock::Timestamp
263267
mrpBackoffTime += ICDConfigurationData::GetInstance().GetFastPollingInterval();
264268
#endif
265269

270+
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
271+
mrpBackoffTime += sAdditionalMRPBackoffTime.ValueOr(CHIP_CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST);
272+
#else
266273
mrpBackoffTime += CHIP_CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST;
274+
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
267275

268276
return mrpBackoffTime;
269277
}

src/messaging/ReliableMessageMgr.h

+25
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <stdint.h>
2828

2929
#include <lib/core/CHIPError.h>
30+
#include <lib/core/Optional.h>
3031
#include <lib/support/BitFlags.h>
3132
#include <lib/support/Pool.h>
3233
#include <messaging/ExchangeContext.h>
@@ -205,6 +206,26 @@ class ReliableMessageMgr
205206
}
206207
#endif // CHIP_CONFIG_TEST
207208

209+
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
210+
/**
211+
* Set the value to add to the MRP backoff time we compute. This is meant to
212+
* account for high network latency on the sending side (us) that can't be
213+
* known to the message recipient and hence is not captured in the MRP
214+
* parameters the message recipient communicates to us.
215+
*
216+
* If set to NullOptional falls back to the compile-time
217+
* CHIP_CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST.
218+
*
219+
* This is a static, not a regular member, because API consumers may need to
220+
* set this before actually bringing up the stack and having access to a
221+
* ReliableMessageMgr.
222+
*/
223+
static void SetAdditionaMRPBackoffTime(const Optional<System::Clock::Milliseconds64> & additionalTime)
224+
{
225+
sAdditionalMRPBackoffTime = additionalTime;
226+
}
227+
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
228+
208229
private:
209230
/**
210231
* Calculates the next retransmission time for the entry
@@ -233,6 +254,10 @@ class ReliableMessageMgr
233254
ObjectPool<RetransTableEntry, CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE> mRetransTable;
234255

235256
SessionUpdateDelegate * mSessionUpdateDelegate = nullptr;
257+
258+
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
259+
static Optional<System::Clock::Milliseconds64> sAdditionalMRPBackoffTime;
260+
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
236261
};
237262

238263
} // namespace Messaging

0 commit comments

Comments
 (0)