Skip to content

Commit 29a06c3

Browse files
Make it possible to dynamically set MRP parameters.
Right now MRP parameters have to be compile-time constants, except for ICDs. But in some cases the same binary might be used on different types of hardware that have different MRP requirements. This change makes it possible to set the MRP parameters at run time, based on the actual hardware involved, not just compile time. The new functionality is gated by a new default-off compiler flag, so only systems that really need it pay the cost for it.
1 parent 92d87e8 commit 29a06c3

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/messaging/ReliableMessageProtocolConfig.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,43 @@ void ClearLocalMRPConfigOverride()
5757
}
5858
#endif
5959

60+
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
61+
namespace {
62+
63+
// This is not a static member of ReliableMessageProtocolConfig because the free
64+
// function GetLocalMRPConfig() needs access to it.
65+
Optional<ReliableMessageProtocolConfig> sDynamicLocalMPRConfig;
66+
67+
} // anonymous namespace
68+
69+
bool ReliableMessageProtocolConfig::SetLocalMRPConfig(const Optional<ReliableMessageProtocolConfig> & localMRPConfig)
70+
{
71+
auto oldConfig = GetLocalMRPConfig();
72+
sDynamicLocalMPRConfig = localMRPConfig;
73+
return oldConfig != GetLocalMRPConfig();
74+
}
75+
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
76+
6077
ReliableMessageProtocolConfig GetDefaultMRPConfig()
6178
{
6279
// Default MRP intervals are defined in spec <4.12.8. Parameters and Constants>
6380
static constexpr const System::Clock::Milliseconds32 idleRetransTimeout = 500_ms32;
6481
static constexpr const System::Clock::Milliseconds32 activeRetransTimeout = 300_ms32;
6582
static constexpr const System::Clock::Milliseconds16 activeThresholdTime = 4000_ms16;
83+
static_assert(activeThresholdTime == kDefaultActiveTime, "Different active defaults?");
6684
return ReliableMessageProtocolConfig(idleRetransTimeout, activeRetransTimeout, activeThresholdTime);
6785
}
6886

6987
Optional<ReliableMessageProtocolConfig> GetLocalMRPConfig()
7088
{
7189
ReliableMessageProtocolConfig config(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL);
90+
91+
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
92+
if (sDynamicLocalMPRConfig.HasValue()) {
93+
config = sDynamicLocalMPRConfig.Value();
94+
}
95+
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
96+
7297
#if CHIP_CONFIG_ENABLE_ICD_SERVER
7398
// TODO ICD LIT shall not advertise the SII key
7499
// Increase local MRP retry intervals by ICD polling intervals. That is, intervals for

src/messaging/ReliableMessageProtocolConfig.h

+19
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,25 @@ struct ReliableMessageProtocolConfig
208208
return mIdleRetransTimeout == that.mIdleRetransTimeout && mActiveRetransTimeout == that.mActiveRetransTimeout &&
209209
mActiveThresholdTime == that.mActiveThresholdTime;
210210
}
211+
212+
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
213+
/**
214+
* Set the local MRP configuration for the node.
215+
*
216+
* Passing a "no value" optional resets to the compiled-in settings
217+
* (CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL and
218+
* CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL).
219+
*
220+
* Otherwise the value set via this function is used instead of the
221+
* compiled-in settings, but can still be overridden by ICD configuration
222+
* and other things that would override the compiled-in settings.
223+
*
224+
* @return whether the local MRP configuration actually changed as a result
225+
* of this call. If it did, callers may need to reset DNS-SD
226+
* advertising to advertise the updated values.
227+
*/
228+
static bool SetLocalMRPConfig(const Optional<ReliableMessageProtocolConfig> & localMRPConfig);
229+
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
211230
};
212231

213232
/// @brief The default MRP config. The value is defined by spec, and shall be same for all implementations,

src/platform/BUILD.gn

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
8080

8181
# Define the default number of ip addresses to discover
8282
chip_max_discovered_ip_addresses = 5
83+
84+
# Allows enabling dynamic setting of the local MRP configuration, for
85+
# devices with multiple radios that have different sleep behavior for
86+
# different radios.
87+
chip_device_config_enable_dynamic_mrp_config = false
8388
}
8489

8590
if (chip_stack_lock_tracking == "auto") {
@@ -131,6 +136,7 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
131136
"CHIP_DISABLE_PLATFORM_KVS=${chip_disable_platform_kvs}",
132137
"CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER=${chip_use_transitional_commissionable_data_provider}",
133138
"CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER=${chip_use_transitional_device_instance_info_provider}",
139+
"CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG=${chip_device_config_enable_dynamic_mrp_config}",
134140
]
135141

136142
if (chip_device_platform == "linux" || chip_device_platform == "darwin" ||

0 commit comments

Comments
 (0)