Skip to content

Commit 95dfb9b

Browse files
committed
Adds DBus APIs to attempt a leader takeover operation as well as write method
to the LocalLeaderWeight property, in order to set the local leader weight
1 parent eeda311 commit 95dfb9b

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/dbus/common/constants.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#define OTBR_DBUS_DEACTIVATE_EPHEMERAL_KEY_MODE_METHOD "DeactivateEphemeralKeyMode"
7070
#define OTBR_DBUS_SCHEDULE_MIGRATION_METHOD "ScheduleMigration"
7171
#define OTBR_DBUS_HOST_POWER_STATE_METHOD "SetHostPowerState"
72+
#define OTBR_DBUS_TAKEOVER_LEADER_METHOD "TakeoverLeader"
7273

7374
#define OTBR_DBUS_PROPERTY_MESH_LOCAL_PREFIX "MeshLocalPrefix"
7475
#define OTBR_DBUS_PROPERTY_LINK_MODE "LinkMode"

src/dbus/server/dbus_thread_object_rcp.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ otbrError DBusThreadObjectRcp::Init(void)
173173
RegisterMethod(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_DEACTIVATE_EPHEMERAL_KEY_MODE_METHOD,
174174
std::bind(&DBusThreadObjectRcp::DeactivateEphemeralKeyModeHandler, this, _1));
175175
#endif
176+
RegisterMethod(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_TAKEOVER_LEADER_METHOD,
177+
std::bind(&DBusThreadObjectRcp::TakeoverLeaderHandler, this, _1));
176178
RegisterMethod(DBUS_INTERFACE_INTROSPECTABLE, DBUS_INTROSPECT_METHOD,
177179
std::bind(&DBusThreadObjectRcp::IntrospectHandler, this, _1));
178180

@@ -194,6 +196,8 @@ otbrError DBusThreadObjectRcp::Init(void)
194196
RegisterSetPropertyHandler(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_EPHEMERAL_KEY_ENABLED,
195197
std::bind(&DBusThreadObjectRcp::SetEphemeralKeyEnabled, this, _1));
196198
#endif
199+
RegisterSetPropertyHandler(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_LOCAL_LEADER_WEIGHT,
200+
std::bind(&DBusThreadObjectRcp::SetLocalLeaderWeightHandler, this, _1));
197201

198202
RegisterGetPropertyHandler(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_LINK_MODE,
199203
std::bind(&DBusThreadObjectRcp::GetLinkModeHandler, this, _1));
@@ -987,6 +991,19 @@ otError DBusThreadObjectRcp::GetLocalLeaderWeightHandler(DBusMessageIter &aIter)
987991
return error;
988992
}
989993

994+
otError DBusThreadObjectRcp::SetLocalLeaderWeightHandler(DBusMessageIter &aIter)
995+
{
996+
auto threadHelper = mHost.GetThreadHelper();
997+
otError error = OT_ERROR_NONE;
998+
uint8_t weight;
999+
1000+
VerifyOrExit(DBusMessageExtractFromVariant(&aIter, weight) == OTBR_ERROR_NONE, error = OT_ERROR_INVALID_ARGS);
1001+
otThreadSetLocalLeaderWeight(threadHelper->GetInstance(), weight);
1002+
1003+
exit:
1004+
return error;
1005+
}
1006+
9901007
otError DBusThreadObjectRcp::GetChannelMonitorSampleCountHandler(DBusMessageIter &aIter)
9911008
{
9921009
#if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE
@@ -1906,6 +1923,19 @@ void DBusThreadObjectRcp::LeaveNetworkHandler(DBusRequest &aRequest)
19061923
});
19071924
}
19081925

1926+
void DBusThreadObjectRcp::TakeoverLeaderHandler(DBusRequest &aRequest)
1927+
{
1928+
auto threadHelper = mHost.GetThreadHelper();
1929+
otError error = OT_ERROR_NONE;
1930+
otDeviceRole role = otThreadGetDeviceRole(threadHelper->GetInstance());
1931+
1932+
VerifyOrExit(role != OT_DEVICE_ROLE_DISABLED && role != OT_DEVICE_ROLE_DETACHED, error = OT_ERROR_INVALID_STATE);
1933+
SuccessOrExit(error = otThreadBecomeLeader(threadHelper->GetInstance()));
1934+
1935+
exit:
1936+
aRequest.ReplyOtResult(error);
1937+
}
1938+
19091939
#if OTBR_ENABLE_NAT64
19101940
void DBusThreadObjectRcp::SetNat64Enabled(DBusRequest &aRequest)
19111941
{

src/dbus/server/dbus_thread_object_rcp.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class DBusThreadObjectRcp : public DBusObject
112112
void ActivateEphemeralKeyModeHandler(DBusRequest &aRequest);
113113
void DeactivateEphemeralKeyModeHandler(DBusRequest &aRequest);
114114
#endif
115+
void TakeoverLeaderHandler(DBusRequest &aRequest);
115116

116117
void IntrospectHandler(DBusRequest &aRequest);
117118

@@ -126,6 +127,7 @@ class DBusThreadObjectRcp : public DBusObject
126127
#if OTBR_ENABLE_EPSKC
127128
otError SetEphemeralKeyEnabled(DBusMessageIter &aIter);
128129
#endif
130+
otError SetLocalLeaderWeightHandler(DBusMessageIter &aIter);
129131

130132
otError GetLinkModeHandler(DBusMessageIter &aIter);
131133
otError GetDeviceRoleHandler(DBusMessageIter &aIter);

src/dbus/server/introspect.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@
262262
<arg name="retain_active_session" type="b" direction="in"/>
263263
</method>
264264

265+
<!-- TakeoverLeader: Takeover as the current partition leader if possible. -->
266+
<method name="TakeoverLeader">
267+
</method>
268+
265269
<!-- MeshLocalPrefix: The /64 mesh-local prefix. -->
266270
<property name="MeshLocalPrefix" type="ay" access="readwrite">
267271
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
@@ -428,8 +432,8 @@
428432
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
429433
</property>
430434

431-
<!-- LocalLeaderWeight: The leader weight of the current node. -->
432-
<property name="LocalLeaderWeight" type="y" access="read">
435+
<!-- LocalLeaderWeight: Get or set the leader weight of the current node. -->
436+
<property name="LocalLeaderWeight" type="y" access="readwrite">
433437
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
434438
</property>
435439

0 commit comments

Comments
 (0)