mirror of
https://github.com/espressif/openthread.git
synced 2026-08-02 00:57:47 +00:00
[mle] add OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE (#9387)
This commit adds a build configuration flag for the feature to set and get device properties, which are then used to calculate the local leader weight on a device. The feature is enabled by default on Thread 1.3.1 or later. The new configuration flag allows OpenThread project integrators to enable this feature on earlier versions if desired.
This commit is contained in:
@@ -189,6 +189,7 @@ ot_option(OT_CSL_AUTO_SYNC OPENTHREAD_CONFIG_MAC_CSL_AUTO_SYNC_ENABLE "data poll
|
||||
ot_option(OT_CSL_DEBUG OPENTHREAD_CONFIG_MAC_CSL_DEBUG_ENABLE "csl debug")
|
||||
ot_option(OT_CSL_RECEIVER OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE "csl receiver")
|
||||
ot_option(OT_DATASET_UPDATER OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE "dataset updater")
|
||||
ot_option(OT_DEVICE_PROP_LEADER_WEIGHT OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE "device prop for leader weight")
|
||||
ot_option(OT_DHCP6_CLIENT OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE "DHCP6 client")
|
||||
ot_option(OT_DHCP6_SERVER OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE "DHCP6 server")
|
||||
ot_option(OT_DIAGNOSTIC OPENTHREAD_CONFIG_DIAG_ENABLE "diagnostic")
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
#define OPENTHREAD_CONFIG_MAC_FILTER_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MESH_DIAG_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLR_ENABLE 1
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
#define OPENTHREAD_CONFIG_MAC_FILTER_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MESH_DIAG_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLR_ENABLE 1
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
#define OPENTHREAD_CONFIG_MAC_FILTER_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MESH_DIAG_ENABLE 0
|
||||
#define OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE 0
|
||||
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 0
|
||||
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1
|
||||
#define OPENTHREAD_CONFIG_MLR_ENABLE 1
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (354)
|
||||
#define OPENTHREAD_API_VERSION (355)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -237,7 +237,7 @@ typedef struct otDeviceProperties
|
||||
/**
|
||||
* Get the current device properties.
|
||||
*
|
||||
* Requires `OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1`.
|
||||
* Requires `OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE`.
|
||||
*
|
||||
* @returns The device properties `otDeviceProperties`.
|
||||
*
|
||||
@@ -247,7 +247,7 @@ const otDeviceProperties *otThreadGetDeviceProperties(otInstance *aInstance);
|
||||
/**
|
||||
* Set the device properties which are then used to determine and set the Leader Weight.
|
||||
*
|
||||
* Requires `OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1`.
|
||||
* Requires `OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE`.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aDeviceProperties The device properties.
|
||||
|
||||
+3
-3
@@ -3523,7 +3523,7 @@ template <> otError Interpreter::Process<Cmd("leaderweight")>(Arg aArgs[])
|
||||
return ProcessGetSet(aArgs, otThreadGetLocalLeaderWeight, otThreadSetLocalLeaderWeight);
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
template <> otError Interpreter::Process<Cmd("deviceprops")>(Arg aArgs[])
|
||||
{
|
||||
static const char *const kPowerSupplyStrings[4] = {
|
||||
@@ -3622,7 +3622,7 @@ template <> otError Interpreter::Process<Cmd("deviceprops")>(Arg aArgs[])
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif // #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#endif // OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
@@ -8203,7 +8203,7 @@ otError Interpreter::ProcessCommand(Arg aArgs[])
|
||||
#endif
|
||||
CmdEntry("detach"),
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
CmdEntry("deviceprops"),
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
|
||||
@@ -79,7 +79,7 @@ otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId)
|
||||
return AsCoreType(aInstance).Get<Mle::MleRouter>().SetPreferredRouterId(aRouterId);
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
const otDeviceProperties *otThreadGetDeviceProperties(otInstance *aInstance)
|
||||
{
|
||||
return &AsCoreType(aInstance).Get<Mle::MleRouter>().GetDeviceProperties();
|
||||
|
||||
@@ -88,6 +88,20 @@
|
||||
#define OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER (OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
*
|
||||
* Define as 1 to enable feature to set device properties which are used for calculating the local leader weight on a
|
||||
* device.
|
||||
*
|
||||
* It is enabled by default on Thread Version 1.3.1 or later.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE \
|
||||
(OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MLE_DEFAULT_LEADER_WEIGHT_ADJUSTMENT
|
||||
*
|
||||
|
||||
@@ -95,7 +95,7 @@ MleRouter::MleRouter(Instance &aInstance)
|
||||
{
|
||||
mDeviceMode.Set(mDeviceMode.Get() | DeviceMode::kModeFullThreadDevice | DeviceMode::kModeFullNetworkData);
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
mLeaderWeight = mDeviceProperties.CalculateLeaderWeight();
|
||||
#else
|
||||
mLeaderWeight = kDefaultLeaderWeight;
|
||||
@@ -212,7 +212,7 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
void MleRouter::SetDeviceProperties(const DeviceProperties &aDeviceProperties)
|
||||
{
|
||||
mDeviceProperties = aDeviceProperties;
|
||||
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
*/
|
||||
Error BecomeLeader(void);
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
/**
|
||||
* Gets the device properties which are used to determine the Leader Weight.
|
||||
*
|
||||
@@ -705,7 +705,7 @@ private:
|
||||
|
||||
TrickleTimer mAdvertiseTrickleTimer;
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
DeviceProperties mDeviceProperties;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ DeviceMode::InfoString DeviceMode::ToString(void) const
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// DeviceProperties
|
||||
|
||||
#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
|
||||
DeviceProperties::DeviceProperties(void)
|
||||
{
|
||||
@@ -135,7 +135,7 @@ uint8_t DeviceProperties::CalculateLeaderWeight(void) const
|
||||
return weight;
|
||||
}
|
||||
|
||||
#endif // #if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#endif // #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// RouterIdSet
|
||||
|
||||
@@ -287,7 +287,7 @@ private:
|
||||
uint8_t mMode;
|
||||
};
|
||||
|
||||
#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
/**
|
||||
* Represents device properties.
|
||||
*
|
||||
@@ -346,7 +346,7 @@ private:
|
||||
static_assert(kDefaultAdjustment <= kMaxAdjustment, "Invalid default weight adjustment");
|
||||
};
|
||||
|
||||
#endif // #if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#endif // #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
|
||||
/**
|
||||
* Represents the Thread Leader Data.
|
||||
@@ -706,7 +706,7 @@ const char *RoleToString(DeviceRole aRole);
|
||||
|
||||
DefineCoreType(otLeaderData, Mle::LeaderData);
|
||||
DefineMapEnum(otDeviceRole, Mle::DeviceRole);
|
||||
#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
DefineCoreType(otDeviceProperties, Mle::DeviceProperties);
|
||||
DefineMapEnum(otPowerSupply, Mle::DeviceProperties::PowerSupply);
|
||||
#endif
|
||||
|
||||
@@ -95,6 +95,8 @@
|
||||
|
||||
#define OPENTHREAD_CONFIG_TMF_SNOOP_CACHE_ENTRY_TIMEOUT 3
|
||||
|
||||
#define OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_MLE_MAX_CHILDREN 32
|
||||
|
||||
#define OPENTHREAD_CONFIG_MLE_CHILD_TIMEOUT_DEFAULT 120
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
|
||||
void TestDefaultDeviceProperties(void)
|
||||
{
|
||||
@@ -170,13 +170,13 @@ void TestLeaderWeightCalculation(void)
|
||||
printf("TestLeaderWeightCalculation passed\n");
|
||||
}
|
||||
|
||||
#endif // #if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#endif // #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3_1)
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
|
||||
ot::TestDefaultDeviceProperties();
|
||||
ot::TestLeaderWeightCalculation();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user