mirror of
https://github.com/espressif/openthread.git
synced 2026-08-22 02:19:52 +00:00
[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.
This commit is contained in:
@@ -1207,6 +1207,74 @@ void TestSrpClientDelayedResponse(void)
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
|
||||
void TestSrpServerAddressModeForceAdd(void)
|
||||
{
|
||||
Srp::Server *srpServer;
|
||||
Srp::Client *srpClient;
|
||||
uint16_t heapAllocations;
|
||||
|
||||
Log("--------------------------------------------------------------------------------------------");
|
||||
Log("TestSrpServerAddressModeForceAdd");
|
||||
|
||||
InitTest();
|
||||
|
||||
srpServer = &sInstance->Get<Srp::Server>();
|
||||
srpClient = &sInstance->Get<Srp::Client>();
|
||||
|
||||
heapAllocations = sHeapAllocatedPtrs.GetLength();
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Set address mode to `kAddressModeUnicastForceAdd`.
|
||||
|
||||
SuccessOrQuit(srpServer->SetAddressMode(Srp::Server::kAddressModeUnicastForceAdd));
|
||||
VerifyOrQuit(srpServer->GetAddressMode() == Srp::Server::kAddressModeUnicastForceAdd);
|
||||
|
||||
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateDisabled);
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Start SRP server, ensure it starts quickly.
|
||||
|
||||
srpServer->SetEnabled(true);
|
||||
VerifyOrQuit(srpServer->GetState() != Srp::Server::kStateDisabled);
|
||||
|
||||
AdvanceTime(0);
|
||||
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateRunning);
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Start SRP client and validate that it discovers server.
|
||||
|
||||
srpClient->SetCallback(HandleSrpClientCallback, sInstance);
|
||||
|
||||
srpClient->EnableAutoStartMode(nullptr, nullptr);
|
||||
VerifyOrQuit(srpClient->IsAutoStartModeEnabled());
|
||||
|
||||
AdvanceTime(2000);
|
||||
VerifyOrQuit(srpClient->IsRunning());
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Disable SRP server. Validate that the NetData entry is removed and
|
||||
// client detects this.
|
||||
|
||||
Log("Disabling SRP server");
|
||||
|
||||
srpServer->SetEnabled(false);
|
||||
AdvanceTime(1);
|
||||
|
||||
VerifyOrQuit(!srpClient->IsRunning());
|
||||
|
||||
VerifyOrQuit(heapAllocations == sHeapAllocatedPtrs.GetLength());
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Finalize OT instance and validate all heap allocations are freed.
|
||||
|
||||
Log("Finalizing OT instance");
|
||||
FinalizeTest();
|
||||
|
||||
VerifyOrQuit(sHeapAllocatedPtrs.IsEmpty());
|
||||
|
||||
Log("End of TestSrpServerAddressModeForceAdd");
|
||||
}
|
||||
|
||||
#endif // ENABLE_SRP_TEST
|
||||
|
||||
} // namespace ot
|
||||
@@ -1223,6 +1291,7 @@ int main(void)
|
||||
ot::TestUpdateLeaseShortVariant();
|
||||
ot::TestSrpClientDelayedResponse();
|
||||
#endif
|
||||
ot::TestSrpServerAddressModeForceAdd();
|
||||
|
||||
printf("All tests passed\n");
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user