This change updates the `NetworkData` iteration methods to reduce
redundant code and simplify their use.
Previously, separate methods were defined to iterate over different
types of network data entries (e.g., `GetNextOnMeshPrefix()`,
`GetNextExternalRoute()`). This change unifies these into a single
template method, `NetworkData::GetNext<EntryType>()`. A similar
change is applied to unify the corresponding `Contains...()`
methods into a single template.
Since llvm-19, if we use package manager to install it, the minor
versions could be different. This commit standardizes the version on
linux to 19.1.7. This version is the same as the one installed by
homebrew.
This commit enhances the `NetworkData::Service::Iterator` class.
The `Iterator` is now a separate class from `Service::Manager`. It
provides `GetNextDnsSrpAnycastInfo()` & `GetNextDnsSrpUnicastInfo()`
methods, simplifying the code for iterating over these service
entries. The `Iterator` is also generalized to track a given
`NetworkData` instance, allowing it to iterate over service entries
on any `NetworkData` object, not just the Leader's.
This commit enhances `NetworkData` modules to skip invalid TLVs during
iteration or search operations. Specifically, `NetworkDataTlv::Find
()` and `NetworkData::Iterate()` are updated. These two methods are
the primary methods used by all other methods for parsing or
searching for TLVs.
Generally, the leader validates TLVs before registration using
`NetworkData::Leader::Validate()`. However, this change improves
robustness by allowing receivers to also handle possible malformed
Network Data.
This commit also updates the `test_network_data` unit test to cover
the new behavior of skipping invalid TLVs.
This commit adds a version field (`uint8_t`) to DNS/SRP Anycast and
Unicast Service entries in `NetworkData::Service::Manager`.
For Unicast entries, the version the version field is placed after
the existing fields, specifically after the IPv6 address and port number fields.
For Anycast entries it is added as the in server data as part of the
Server TLV.
When processing Network Data service entries, the version field is
optional and if absent, version number zero is assumed.
The `NetworkData::Publisher` now considers entries with the same or
higher version number when deciding whether to add or remove its own
entry, preferring those with a higher version.
In SRP client, when `AutoStart` mode is used and if there are multiple
Unicast, Service entries, the client prefers the one with larger
version number.
When selecting an anycast entry, the existing rules regarding sequence
numbers are still used. If multiple entries with the same sequence
number exist, the client will assume the minimum version number among
all such entries.
This commit also updates the `test_network_data` unit test, validating
the new format and related methods.
`test_netdata_publisher.py` is also updated to check service entries
with different version numbers.
This commit updates the `NetworkData::Service::Manager` class to
provide helper methods for adding and removing different service
types (DNS/SRP anycast or unicast services, backbone router
service).
With this change, the definitions of `ServiceData` and `ServerData`
formats for different service types are now `private` to the
`Service::Manager` class. This centralizes the logic for constructing
and parsing the service/server TLVs, making it easier to update and
add new fields to these formats in the future.
This commit updates `Service::Manager::GetNextDnsSrpAnycastInfo()` to
iterate over Server sub-TLVs and include the RLOC16 of each entry in
the returned `Info` structure. The unit test `test_network_data` is
updated accordingly. This change simplifies the `Publisher` method
used for counting existing anycast entries in the Network Data.
This commit updates `Service::Manager::GetNextDnsSrpUnicastInfo()` to
accept a `DnsSrpUnicast::Type`, indicating the desired entry type
(either `kFromServiceData` or `kFromServerData`). This simplifies the
code, which previously iterated over all types and performed type
checks. Additionally, this change simplifies the `Publisher` methods
used for counting existing DNS/SRP unicast entries of different
types.
This commit introduces `NetworkData::FindRlocs()` which returns the
list of RLCO16 of all border routers and servers in the Network Data
matching specified filter conditions. The `BorderRouterFilter` can be
used to filter the entry type. It can be set to `kAnyBrOrServer` to
include all BRs and servers, or `kBrProvidingExternalIpConn` to
restrict the list to BRs providing external IP connectivity. The new
`FindRlocs()` replaces `FindBorderRouters()` and `GetNextServer()`
methods and helps simplify the code. Unit test `test_network_data`
is updated to validate the new method.
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.
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.
This commit adds support for the Advertising PIO (AP) flag in Network
Data `ExternalRoute` entries. It also updates the `RoutingManager`
class to set the AP flag on its published Network Data route when the
local on-link prefix is included as PIO in emitted RA messages, which
is equivalent to when the local on-link prefix is being published,
advertised, or deprecated.
This commit also updates the `test_routing_manager` unit test to
validate the AP flag in the published route under different
scenarios.
This commit implements a new optimization in `AddressResolver`
allowing it to resolve on-mesh IPv6 addresses using info from Thread
Network Data DNS/SRP Service (Unicast Address) entries.
When determining EID-to-RLOC mapping in `Resolve()`, we first try to
match the EID against unicast addresses discovered from DNS/SRP
service entries. This is limited to entries where the address/port
info is encoded as part of server data. If a match is found the
associated RLOC16 of the BR which added the entry in Network Data
will be used (i.e., the `server16` field from Network data server
sub-TLV). This optimization is used on devices where MLE Mode
indicates they receive full Network Data and not the stable subset
(since stable subset will not provide RLOC16 info).
This commit adds a similar check in `UpdateSnoopedCacheEntry()` so
that the limited snoop cache entries are not unnecessarily used for
addresses which can be resolved using Network Data services.
This commit adds a new mechanism to allow border routers to request
router role upgrade.
A border router which provides IP connectivity (either adding an
external route prefix or an on-mesh prefix with default route flag)
and is acting as a REED is eligible to request a router role upgrade
by sending an "Address Solicit" request to leader with status reason
`BorderRouterRequest`. This reason is used when the number of active
routers in the Thread mesh is above the threshold, and only if the
number of existing eligible BRs (determined from the network data)
that are acting as router is less than two. This mechanism allows up
to two eligible border routers to request router role upgrade when
the number of routers is already above the threshold.
This commit also adds a new test-case `test_br_upgrade_router_role`
which validates the behavior of the new mechanism.
This commit enhances the selection algorithm for the preferred entry
when there are multiple "DNS/SRP Service Anycast" entries in the
Thread Network Data. The sequence number (which is `uint8_t`) is used
for selecting the preferred entry and the larger value is preferred.
The seq numbers are compared using "serial number arithmetic"
(RFC-1982) but if we have 3 or more entries the notion of a largest
seq number may not be well-defined under the "serial number
arithmetic" comparison (e.g., for `{10, 130, 250}` there is no
largest seq number since `130 > 10`, `250 > 130` and `10 > 250`). In
such a case the algorithm selects the entry with largest seq number
in normal sense.
This commit updates `FindPreferredDnsSrpAnycastInfo()` to implement
the new algorithm. It also updates `test_network_data` unit test to
add many test cases related to the selection algorithm.
This commit adds a new method in `NetworkData` to find the list of
RLOC16 of all border routers providing external IP connectivity. A
border router is considered to provide external IP connectivity if it
has added at least one external route entry, or an on-mesh prefix
with default-route and on-mesh flags set. It also adds a method to
count the number of border routers. The methods allow filtering based
on the border router device role, including devices in any role, or
in router role only, or in child role only. This commit also updates
`test_network_data` unit test to validate the behavior of the newly
added methods.
This commit updates `NetworkData::Service::DnsSrpUnicast` to indicate
`Origin` of the entry, whether the server IPv6 address and port
number is included as part of service data or server data. This will
be used by clients to prefer entries with the info in service data
(which coveys the infra-structure provided (authoritative) server)
over the ones in server data (which are used by Thread BRs).
This commit also updates the unit test `test_network_data` to validate
the new behavior.
This commit updates the `NetworkData` implementation to simplify it
and make it more flexible. It changes `NetworkData` class such that
it delegates providing the buffer space to store the TLVs to its
sub-classes (`Local`/`Leader`) or its users. This allow us to remove
many `static` methods that expect inputs of `(aTlvs, aTlvsLength)`
and instead the use the `NetworkData` methods directly. Basically,
the `NetworkData` class can now be considered as a wrapper over a
pointer to a buffer containing a sequence of TLVs which provides
methods to parse and process the TLVs. `NetworkData` class assumes
that the TLVs (buffer content) is immutable and we have a new class
`MutableNetworkData` which provides methods to update (add, remove,
or modify) the TLVs.
This commit adds new types `NetworkData::ServiceData/ServerData`
(which use the `ot::Data` class) which help simplify different
`NetworkData` methods dealing with Service and Server TLVs.
This commit simplifies the `NetworkData` class by removing the `mType`
Instead we add a new parameter in `SendServerDataNotification()` which
indicates whether to append the Network Data TLV to the message or
not (which was previously determined by `mType`).
This commit relaxes BBR dataset matching to only compare the first
byte of Service Data (i.e. 0x01).
This commit also requires all Service TLV searching methods to
explicitly specify aExactServiceDataMatch argument, helping to reduce
unconscious mistakes.
This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to
include the failed condition in the error message that is printed on
a failure (in addition to function name and line number where the
error happened). This commit also changes the second parameter
(`aMessage`) to in these macros to be optional.
This commit also updates unit tests to remove the second `aMessage`
string in cases where the failure can be inferred from the condition
itself.
This commit adds new network data service entry definitions to
indicate presence of DNS/SRP servers within the Thread mesh and
provide info about them. Two service TLV formats are added:
`NetworkData::Service::DnsSrpAnycast` indicates that DNS/SRP client on
a device can use the associated anycast address with this service TLV
to reach the DNS/SRP server. The use of anycast address ensures that
the messages are routed to the nearest node which has added such a
service entry in the network data. The service TLV data in this model
contains a one byte sequence number which is used to notify the SRP
clients if they need to re-register with the server(s) (e.g., due
server reset/reboot and/or loss of previous registrations).
`NetworkData::Service::DnsSrpUnicast` directly provides the IPv6
address and port info for a DNS/SRP server which can be included as
part of the service TLV data and/or the server TLV data. Using service
TLV data allows the info about a common infrastructure SRP/DNS server
to be added by multiple BRs. In the case of server TLV, the IPv6
address info can be optionally omitted (i.e. just a port number is
provided) which then causes the associated RLOC/ALOC address of the
node who added the service entry to be used as the server's IPv6
address.
This commit updates the `Srp::Client` to use the new service entries
to discover/select the SRP sever when auto-start mode is enabled. The
client prefers and uses a `DnsSrpAnycast` over `DnsSrpUnicast`
entries. The `Srp::Server` is also updated to publish its info as
`DnsSrpAnycast` entry (using mesh-local address).
This commit also updates the `test_network_data` unit test to cover
the behavior of newly methods which iterate and parse different
service entry formats.
This commit adds a new flag in `NetworkData::HasRouteEntry` to
indicate that an off-mesh route prefix in the Network Data is also a
NAT64 prefix. It updates the public `otExternalRouteConfig` structure
to include `mNat64` bit flag and adds support for it in the core
modules.
It also updates `test_network_data` unit test to cover the new flag
and also adds some smaller style changes in this test.
This commit updates the CLI modules to add support for the new
flag. It also adds smaller enhancements in CLI related to network
data, adding methods `NetworkData::OutputPreference()` and
`OutputIp6Prefix()` to output common info (shared between on-mesh
prefixes and off-mesh routes), also simplifying how the flags are
mapped to char array string (avoiding extra space char in the output
string).
This commit also updates spinel and NCP code to add support for the
new NAT64 flag.
This commit adds a new method in `NetworkData` class to find and
iterate over all Service TLVs that start with a given Service Data.
Unlike the existing `FindService()` method which searches for a
Service TLV with an exact match with the given Service Data, this
method performs a relaxed check allowing a matching Service TLV to
contain additional bytes after given data bytes to search for.
This commit also updates `test_network_data` unit test to add new
test to cover the behavior of newly added method.
This commit adds `Ip6::Prefix` class as a sub-class of `otIp6Prefix`
representing an IPv6 Prefix. Helper methods are provided in `Prefix`
and `Address` to perform prefix matching.
Different core modules such as `network-data`, `lowpan`, `dhcp6`,
`slaac`, and, `backbone-router` are updated to use the new `Prefix`
and its helper methods.
This commit also updates the unit test `test_ip6_address` to verify
behavior of `Prefix` and its helper methods.
This commit removes the extra `\n` at the end of error message strings
used in `VerifyOrQuit()` or `SuccessOrQuit()` macros in different unit
test modules. This help make the style (usage of macros) consistent
across all unit tests.
This commit contains t changes the methods in `NetworkData` class used
for iterating over on-mesh prefix, external router, etc (e.g.,
`GetNextOnMeshPrefix`()) to use reference input variables instead of
pointer type variables.
This commit changes `NetworkData` to use an enumeration `Type` to
specify whether a `NetworkData` instance represents local network
data or leader network data.
This commit makes the following changes: It defines the public
`otInstance` as an empty opaque structure which is used by all public
C OpenThread APIs. It defines a new class `ot::Instance` (inheriting
from `otInstance) which is then used in core source files. The
functionality related to the instance is also moved/added into the
newly added `Instance` class (as class/static or member methods).
This commit changes the model for OpenThread classes so that all
classes track/locate their owning/parent `otInstance` object (i.e.,
the owning `otInstance` object reference is expected to be passed as
an input argument in the object constructor). This replaces and
simplifies current model where some of classes track/locate the parent
`ThreadNetif`, `MeshForwarder`, or `Ip6` object references instead.
This helps harmonize the model across OpenThread source and also
simplify the `Locator` class implementation.
This commit updates the `otNetworkDataIterator` to also store the
sub-tlv offset (in addition to main prefix tlv offset and the entry
index). It also updates two methods `GetNextExternalRoute()` and
`GetNextOnMeshPrefix()`. This commit also adds network data unit
test module.