Commit Graph

28 Commits

Author SHA1 Message Date
Abtin Keshavarzian 5b2bcee271 [srp-client] enhance single service mode (#11634)
This commit enhances the `Srp::Client` "single service mode". This
mode is enabled when a prepared SRP update message exceeds the IPv6
MTU size. In this mode, the client registers its services one by one,
with each SRP update containing only a single service.

The implementation is simplified by changing the `mSingleServiceMode`
flag from a persistent member variable of the `Client` class to a
field within the `MsgInfo` struct, making its scope
message-specific.

State transitions are now correctly applied to host and service
entries when operating in single service mode. This, in turn, helps
ensure that SRP message transaction IDs are managed correctly: the
same ID is used for retries of an unchanged service, while a new ID
is used if the service information has changed.

Finally, a new test case, `TestSrpClientSingleServiceMode`, is added
to `test_srp_server` to cover this behavior and its associated retry
logic in detail.
2025-06-25 16:45:49 -07:00
Abtin Keshavarzian 3aab10a8fb [srp-client] update message ID assignment model (#11592)
This commit updates the SRP client message ID assignment model.
Message IDs are now selected randomly, ensuring they differ from the
last ID used. The same message ID is reused when a message is
retried.

This replaces the earlier design where all messages, including
retries, used sequential message IDs.

The unit test is also updated to validate the new behavior.
2025-06-24 12:10:45 -07:00
Abtin Keshavarzian b1ca77aae9 [srp-server] allow disabling "Fast Start Mode" via auto-enable (#11319)
This commit updates the `Srp::Server` so that Fast Start Mode can be
disabled by a call to `otSrpServerSetAutoEnableMode()`, in addition
to the existing method of calling `otSrpServerSetEnabled()`.

The `test_srp_server` unit test is updated to validate this new
behavior.
2025-03-04 15:18:37 -08:00
Abtin Keshavarzian babbccd4c6 [srp-server] introduce "fast start mode" feature (#11305)
This commit adds "Fast Start Mode" feature for SRP server. This
feature is designed for scenarios where a device, often a mobile
device, needs to act as a provisional SRP server (e.g., functioning
as a temporary Border Router). The SRP server function is enabled
only if no other Border Routers are already providing the SRP
service within the Thread network. A common use case is a mobile
device joining a Thread network where it may be the first, or only,
BR. Importantly, Fast Start Mode allows the device to quickly start
its SRP server functionality upon joining the network, allowing other
Thread devices to quickly connect and register their services without
the typical delays associated with standard Border Router
initialization and SRP server startup (using NetData Publisher).
2025-02-28 13:49:30 -08:00
Abtin Keshavarzian 6e0755bd1b [srp-server] add new otSrpServerAddressMode for faster start up (#11180)
This commit adds a new option in `otSrpServerAddressMode` as
`OT_SRP_SERVER_ADDRESS_MODE_UNICAST_FORCE_ADD`. This allows faster
SRP server start up by bypassing the Network Data publisher and
adding the "SRP/DNS unicast" entry directly to Network Data upon enabling
of the SRP server, regardless of how many other similar entries are
present.

This option is intended for testing and specific situations. A warning
is added to indicate that using this option will make the device
non-compliant with the Thread specification.

The unit test `test_srp_server` is updated with a new test case to
validate the new `AddressMode` and its related behavior.
2025-02-28 07:13:29 -08:00
Abtin Keshavarzian 7b72e97782 [srp-server] use kNetifThreadInternal for UDP socket (#10992)
This commit updates `Srp::Server` to associate its UDP socket with
`kNetifThreadInternal`, ensuring that received messages are from the
internal Thread network interface (i.e., from devices within the
Thread mesh).
2024-12-05 18:53:24 -08:00
Abtin Keshavarzian 473af53155 [udp] add kNetifThreadInternal which disallows platform UDP use (#10965)
This commit introduces `kNetifThreadInternal` as a network interface
option for UDP sockets. Unlike other options, this disallows the use
of platform UDP for the socket, indicating that the socket should use
the OpenThread internal Thread network interface only.

This model replaces the previous approach where `ShouldUsePlatformUdp()`
would check the socket port against a set of port numbers used by
different modules (such as MLE, TMF, Joiner Router, etc) to determine
whether platform UDP APIs should be used. With the new model, each
module decides whether to associate its socket with the
`kNetifThreadInternal`.

This is a more flexible and extensible model, ensuring that sockets
that should not use the platform do not waste resources (they will
not be created or opened/closed on the platform). This also help
avoid edge cases where platform UDP operations may unintentionally
fail when the platform socket is not actually needed.
2024-11-28 08:58:19 -08:00
Abtin Keshavarzian 65dd8bff66 [udp] update Socket::Open() to include NetifId (#10964)
This commit updates how the `NetifId` is set on a `Udp::Socket`. It is
now specified as a parameter in the `Open()` call instead of `Bind()`.

This change makes the socket more flexible by allowing the `NetifId`
to be known earlier (which can be used for future optimizations). It
also allows the desired `NetifId` to be set even when `Bind()` is not
explicitly called, such as when `Connect()` or `SendTo()` are used on
a socket that is not yet bound. Previously, `kNetifThread` was
assumed by default in these situations.

The public `otUdp` APIs are left unchanged to ensure backward
compatibility.
2024-11-26 11:18:53 -08:00
Abtin Keshavarzian 821f2415e0 [test] harden test_srp_server (#10486)
This commit updates `test_srp_server` to wait longer after the start
of the SRP client before performing the test steps. This makes the
test more robust against random jitter which may be applied by the
client when registering.
2024-07-08 15:44:53 -07:00
Abtin Keshavarzian d87be657c6 [srp-client] enhance selection of TX jitter based on trigger reason (#10357)
This commit improves the `Srp::Client` mechanism for applying random
jitter delays before sending update messages to the server. It now
supports different jitter ranges based on specific triggers. Since
trigger events are often network-wide, potentially causing
simultaneous SRP re-registration from many nodes, longer jitter
intervals are used to distribute the resulting SRP update
transmissions and avoid congestion.

The following triggers are covered:

- Server switch: Client switching to a new server while already
  connected to a discovered server. This occurs when a new server
  entry appears in Network Data which is preferred over the current
  selection.

- Server restart: Client was previously connected to a server that
  disappeared from Network Data. Later, the same or a new server is
  discovered in Network Data.

- SLAAC address add or remove: This is generally triggered by updates
  to SLAAC prefixes in Network Data (e.g., OMR prefix changes).

- First registration after attach:

  - If the device is attaching to an established Thread mesh
    (e.g., after a reboot or initial pairing), the Network Data it
    receives should already include a server entry, leading to a
    quick server selection after attach. If server selection occurs
    within a short window, a shorter TX jitter is used, allowing the
    device to register quickly and become discoverable.

  - If server discovery takes longer, a longer TX jitter is used. This
    situation can indicate a server/BR starting up or a network-wide
    restart of many nodes (e.g., due to a power outage).

This commit introduces `TxJitter` class to manage the requested TX
jitter based on a trigger reason. It tracks the time of the event
that triggered a longer jitter request. If the update message is sent
immediately after the trigger event, the requested maximum jitter is
applied. However, if the update message is sent later, the maximum
jitter is adjusted proportionally to the time elapsed since the
trigger event. If the elapsed time exceeds the requested maximum
jitter interval, the default short jitter is applied to avoid
unnecessary registration delay.
2024-07-02 08:52:28 -07:00
Abtin Keshavarzian 54afce92ab [udp] add template SocketIn class for easier socket usage (#10392)
This commit adds a new template `Udp::SocketIn<Owner, RxHandlerPtr>`,
which defines a UDP socket for use within a specified `Owner` class.
It includes a `HandleUdpReceive()` member method callback for
processing received messages. This model, similar to `TimerMilliIn`,
eliminates the need for each socket user to define boilerplate code
for providing a static member function that simply casts and calls
the member method. This is now handled by the template `SocketIn`
class. The `Udp::Socket::Open()` method is also modified to no longer
require the callback and context parameters.
2024-06-17 18:31:26 -07:00
Abtin Keshavarzian 3315c44bb3 [mle] rename mesh local address methods to use Rloc and Eid (#10385)
This commit renames the methods for retrieving mesh local addresses to
`GetMeshLocalRloc()` and `GetMeshLocalEid()` (from `GetMeshLocal16()`
and `GetMeshLocal64()`, respectively) to align with the terminology
used in the Thread specification. Member and local variables are also
renamed accordingly.
2024-06-14 10:06:25 -07:00
Abtin Keshavarzian 7ba7fb2eb6 [srp-client] use sequential message IDs & allow older response IDs (#10353)
This commit updates `Srp::Client` to use sequential message IDs,
replacing the previous model where message IDs were generated
randomly.

When processing responses from the server, older message IDs are
accepted as long as the corresponding older message was identical to
the latest one. This helps in situations where the server's response
may be delayed  (e.g., due to network congestion) and the client retry
mechanism is retransmitting the same update message.

This commit also adds a unit test `TestSrpClientDelayedResponse()`
to validate the new behavior.
2024-06-11 08:43:49 -07:00
Abtin Keshavarzian 485cb18ea4 [dataset] add ValidateTlvs(), helper methods, and unit test (#10111)
This commit enhances dataset handling:

- Adds `ValidateTlvs()` which parses and validates all known TLVs
  within the `Dataset` and checks for any duplicates.
- Introduces a set of `SetFrom()` methods for constructing a `Dataset`
  from various types of inputs, e.g., other `Dataset`, TLV sequences,
  `DatasetInfo` structures, bytes read from `Message`. Now they
  consistently clear the `Dataset` before setting it.
- Adds `WriteTlvsFrom()` to update a `Dataset` replacing/appending a
  set of TLVs.
- Adds `AppendTlvsFrom()` to append an already encoded sequence of
  TLVs without validating/checking the format.
- Renames `Get/SetSize()` to `Get/SetLength()` for consistency.
- Adds `test_dataset.cpp` unit test for basic `Dataset` validation.
2024-05-02 14:40:11 -07:00
Abtin Keshavarzian 23c0fc4d4b [test] define all unit tests in ot namespace (#9617)
This commit updates unit test modules to be defined under the `ot`
namespace. This aligns all the unit tests to follow the same
model, eliminating the need to use `ot::` prefix in unit test
code.
2023-11-19 18:40:20 -08:00
Abtin Keshavarzian 1528c8831d [core] define core/instance folder for instance modules (#9561)
This commit moves the `instance` module to a newly added folder
`core/instance` (from `core/common`.  Header file `extension.hpp`
and its example is also moved to the same folder.
2023-10-26 05:08:24 -07:00
Abtin Keshavarzian 8ea2031c74 [srp-server] ensure Host is freed when committing with zero key-lease (#9309)
This commit updates `CommitSrpUpdate()` to ensure that `aHost` is
freed when granted key lease is zero and host is fully removed.

This commit also updates unit test `test_srp_server` (which checks the
heap allocations by server) to cover the situations where client sends
an update to remove host and all its services with or without
clearing key-lease.
2023-07-22 08:18:27 -07:00
Jonathan Hui 3f4dcbc2ec [unit-test] properly configure operational dataset (#9203) 2023-06-26 17:18:24 -07:00
Abtin Keshavarzian 0cc1de7b5a [srp-server] allow service instance label with dot character (#9198)
This commit updates the `Srp::Server` class to correctly handle the
case where a service is registered with a dot character in its
service instance name. The first label in a service instance name is
intended as a user-friendly name and can contain dot characters
(it has fewer restrictions than other labels in a DNS name).

In particular, this commit contains the following changes:
- The `PtrRecords::ReadPtrName()` method is used in `Srp::Server` to
  read and validate the first label and the rest of the labels
  separately. This also validates the format of the parsed PTR
  record.
- The `Service::Description` class now remembers the instance label in
  addition to the full instance name. This allows the instance label
  to be easily retrieved.
- The `Dns::Name::ReadName()` method is updated to only verify that
  the labels after the first label do not contain any dot characters.
  This allows it to be used to read instance service names.
- The tests are updated to validate the behavior of the SRP server
  when the instance label contains a dot character.
2023-06-26 12:55:45 -07:00
Abtin Keshavarzian aa7ce0d4da [test] update unit test emulating radio (#9200)
This commit updates the unit tests that emulate the radio platform API
to define `otPlatRadioGetCaps()`, which returns the ACK_TIMEOUT and
CSMA capabilities. This is to avoid having CSMA being implemented by
the `SubMac`, which then uses the microsecond timer that is not
emulated in the unit test platform.

It also updates the `InitTest()` function to clear the radio platform
variable `sRadioTxOngoing`. This is to avoid the possible
(though unlikely) situation where an earlier test finishes in the
middle of a transmission, causing an extra `TxDone` event in the
following test.
2023-06-22 15:00:40 -07:00
Abtin Keshavarzian 84be135243 [srp] add support for short (4-bytes) lease option variant (#8879)
This commit updates SRP client and server to support short variant
format for Update Lease Option. The short variant includes the lease
interval only (4 bytes) vs the long variant which includes both lease
and key lease intervals (8 bytes). Client and server can parse and
process both formats in received messages. Client by default uses the
long variant. Server will also use the long variant in its response
unless the request message uses the short variant format, i.e., if
the client uses the short variant, the server will also respond using
the short variant. This behavior is required by the latest Update
Lease draft.

This commit also updates `test_srp_server` unit test, adding a new
test-case to validate the behavior of client and server when short
Update Lease Option is used. A new method (intended for testing and
and only available under `REFERENCE_DEVCIE` config) is added which
configures the client to use the short variant format changing the
default behavior.
2023-03-23 17:43:33 -07:00
Abtin Keshavarzian a0ff14c475 [test] update test_srp_server to clear the service instances (#8768)
This commit updates `PrepareService()` functions to `memset` the
`Service` instance to zero before populating its fields. This ensures
that all new properties (e.g., recently added `mLease`/`mKeyLease`)
are set to zero and use the corresponding default value.
2023-02-15 22:34:43 -08:00
Yang Sun 82e816b82f [mle] retransmit link request after router reset (#8704)
According to Thread 1.3.0 Section 4.7.1.3, router synchronization
after reset requires the multicast link request message to be
retransmitted until a response is received, or the maximum
transmission limit has been reached. If the router was a leader or had
more than 5 children prior to reset, it MUST be retransmitted as a
critical message. Each multicast retransmission of an MLE Message on a
TL1 or TL2 Link must be delayed by MLE_MULTICAST_RETRANSMISSION_DELAY
multiplied by a random value between 0.9 and 1.1 with a resolution of
at least 1 ms.

This commit implements the above requirement. With this requirement,
in the cases when a router is reset and there is no other router to
respond to the link request then it takes longer time for the router
to join thread network. Thus some test cases are modified to allow
longer router sync time in such cases.
2023-02-06 21:10:38 -08:00
Abtin Keshavarzian 99a615bec2 [clang-format] use AllowShortFunctionsOnASingleLine: All (#8502)
This commit updates `AllowShortFunctionsOnASingleLine` to `All`
from `InlineOnly`.
2022-12-08 09:34:05 -08:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian 4eb64510bf [test] update AdvanceTime() in unit tests to handle overflow (#8244) 2022-10-06 08:54:27 -07:00
Abtin Keshavarzian 32a17d8abe [test] update SRP unit test to prepare service entries in all cases (#8208) 2022-09-27 20:35:16 -07:00
Abtin Keshavarzian 5a627ba0fd [test] add unit test test_srp_server (#8163)
This commit adds a unit test for `Srp::Server` (which also covers
`Srp::Client`) building a foundation for writing tests covering edge
cases of SRP server and its interaction with platform "update handler"
callback and SRP client.

For example, the test validates behavior of SRP sever, when
"update handler" accepts, rejects, or ignores (waits for timeout)
the received SRP updates. The test also validates that all heap
allocated objects (used by  SRP sever) are properly freed under
different scenarios (validating that there is no heap object leak).
2022-09-21 11:06:23 -07:00