[border-agent] add API to enable/disable Border Agent service (#11458)

This commit adds a new API to allow the Border Agent service to be
enabled or disabled. By default, the Border Agent service is enabled
when the `OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE` feature is used.
This new API allows the user to explicitly control its state. This
can be useful in scenarios such as:
- The user code wishes to delay the start of the Border Agent service
  (and its mDNS advertisement of the `_meshcop._udp` service on the
  infrastructure link). This allows time to prepare or determine
  vendor-specific TXT data entries for inclusion.
- Unit tests or test scripts might disable the Border Agent service to
  prevent it from interfering with specific test steps. For example,
  tests validating mDNS or DNS-SD functionality may disable the
  Border Agent to prevent its registration of the MeshCoP service.

This commit also adds a corresponding CLI command for the new API and
updates `test_border_agent` to validate this functionality.
This commit is contained in:
Abtin Keshavarzian
2025-04-30 07:38:07 -07:00
committed by GitHub
parent 9e9522aaac
commit d56222a8db
8 changed files with 187 additions and 31 deletions
+12
View File
@@ -85,6 +85,18 @@ void TestBorderAgent(void)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Check Border Agent initial state");
VerifyOrQuit(node0.Get<BorderAgent>().IsEnabled());
VerifyOrQuit(node0.Get<BorderAgent>().IsRunning());
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Check disabling and re-enabling of Border Agent");
node0.Get<BorderAgent>().SetEnabled(false);
VerifyOrQuit(!node0.Get<BorderAgent>().IsEnabled());
VerifyOrQuit(!node0.Get<BorderAgent>().IsRunning());
node0.Get<BorderAgent>().SetEnabled(true);
VerifyOrQuit(node0.Get<BorderAgent>().IsEnabled());
VerifyOrQuit(node0.Get<BorderAgent>().IsRunning());
SuccessOrQuit(node0.Get<Ip6::Filter>().AddUnsecurePort(node0.Get<BorderAgent>().GetUdpPort()));