[mle] add RLOC16 related helper methods in Mle (#10440)

This commit introduces new helper methods in the `Mle` class:

- `HasRloc16()`: Checks if the device is using a given RLOC16.
- `MatchesRouterId()`: Checks if this device's RLOC16 matches a given
  Router ID.
- `HasMatchingRouterIdWith()`: Checks if this device's RLOC16 shares
  the same Router ID with a given RLOC16. This implies that the two
  devices are either directly related as parent and child or are
  children of the same parent within the Thread network.
- `ParentRloc16ForRloc16()` derives the router RLOC16 corresponding to
  the parent of a given (child) RLOC16.

These methods act as syntactic sugar, simplifying code and enhancing
readability.
This commit is contained in:
Abtin Keshavarzian
2024-06-27 12:54:07 -04:00
committed by GitHub
parent e10a92570f
commit a0ba929e39
12 changed files with 91 additions and 42 deletions
+2 -2
View File
@@ -81,7 +81,7 @@ otError otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aLeaderRloc)
{
Error error = kErrorNone;
VerifyOrExit(AsCoreType(aInstance).Get<Mle::Mle>().GetRloc16() != Mle::kInvalidRloc16, error = kErrorDetached);
VerifyOrExit(!AsCoreType(aInstance).Get<Mle::Mle>().HasRloc16(Mle::kInvalidRloc16), error = kErrorDetached);
AsCoreType(aInstance).Get<Mle::Mle>().GetLeaderRloc(AsCoreType(aLeaderRloc));
exit:
@@ -197,7 +197,7 @@ otError otThreadGetServiceAloc(otInstance *aInstance, uint8_t aServiceId, otIp6A
{
Error error = kErrorNone;
VerifyOrExit(AsCoreType(aInstance).Get<Mle::Mle>().GetRloc16() != Mle::kInvalidRloc16, error = kErrorDetached);
VerifyOrExit(!AsCoreType(aInstance).Get<Mle::Mle>().HasRloc16(Mle::kInvalidRloc16), error = kErrorDetached);
AsCoreType(aInstance).Get<Mle::Mle>().GetServiceAloc(aServiceId, AsCoreType(aServiceAloc));
exit: