mirror of
https://github.com/espressif/openthread.git
synced 2026-10-10 09:47:35 +00:00
[netdata] centralize service/server TLV logic in Service::Manager (#10624)
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 is contained in:
@@ -75,8 +75,7 @@ Error Leader::GetServiceId(uint8_t &aServiceId) const
|
|||||||
Error error = kErrorNone;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(HasPrimary(), error = kErrorNotFound);
|
VerifyOrExit(HasPrimary(), error = kErrorNotFound);
|
||||||
error = Get<NetworkData::Service::Manager>().GetServiceId<NetworkData::Service::BackboneRouter>(
|
error = Get<NetworkData::Service::Manager>().GetBackboneRouterServiceId(aServiceId);
|
||||||
/* aServerStable */ true, aServiceId);
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
|
|||||||
@@ -174,8 +174,7 @@ exit:
|
|||||||
|
|
||||||
Error Local::AddService(RegisterMode aMode)
|
Error Local::AddService(RegisterMode aMode)
|
||||||
{
|
{
|
||||||
Error error = kErrorInvalidState;
|
Error error = kErrorInvalidState;
|
||||||
NetworkData::Service::BackboneRouter::ServerData serverData;
|
|
||||||
|
|
||||||
VerifyOrExit(mState != kStateDisabled && Get<Mle::Mle>().IsAttached());
|
VerifyOrExit(mState != kStateDisabled && Get<Mle::Mle>().IsAttached());
|
||||||
|
|
||||||
@@ -189,11 +188,8 @@ Error Local::AddService(RegisterMode aMode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
serverData.SetSequenceNumber(mSequenceNumber);
|
SuccessOrExit(error = Get<NetworkData::Service::Manager>().AddBackboneRouterService(
|
||||||
serverData.SetReregistrationDelay(mReregistrationDelay);
|
mSequenceNumber, mReregistrationDelay, mMlrTimeout));
|
||||||
serverData.SetMlrTimeout(mMlrTimeout);
|
|
||||||
|
|
||||||
SuccessOrExit(error = Get<NetworkData::Service::Manager>().Add<NetworkData::Service::BackboneRouter>(serverData));
|
|
||||||
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||||
|
|
||||||
mIsServiceAdded = true;
|
mIsServiceAdded = true;
|
||||||
@@ -207,7 +203,7 @@ void Local::RemoveService(void)
|
|||||||
{
|
{
|
||||||
Error error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = Get<NetworkData::Service::Manager>().Remove<NetworkData::Service::BackboneRouter>());
|
SuccessOrExit(error = Get<NetworkData::Service::Manager>().RemoveBackboneRouterService());
|
||||||
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||||
mIsServiceAdded = false;
|
mIsServiceAdded = false;
|
||||||
|
|
||||||
|
|||||||
+15
-15
@@ -2244,11 +2244,11 @@ exit:
|
|||||||
|
|
||||||
void Client::ProcessAutoStart(void)
|
void Client::ProcessAutoStart(void)
|
||||||
{
|
{
|
||||||
Ip6::SockAddr serverSockAddr;
|
Ip6::SockAddr serverSockAddr;
|
||||||
DnsSrpAnycast::Info anycastInfo;
|
DnsSrpAnycastInfo anycastInfo;
|
||||||
DnsSrpUnicast::Info unicastInfo;
|
DnsSrpUnicastInfo unicastInfo;
|
||||||
AutoStart::State oldAutoStartState = mAutoStart.GetState();
|
AutoStart::State oldAutoStartState = mAutoStart.GetState();
|
||||||
bool shouldRestart = false;
|
bool shouldRestart = false;
|
||||||
|
|
||||||
// If auto start mode is enabled, we check the Network Data entries
|
// If auto start mode is enabled, we check the Network Data entries
|
||||||
// to discover and select the preferred SRP server to register with.
|
// to discover and select the preferred SRP server to register with.
|
||||||
@@ -2274,7 +2274,7 @@ void Client::ProcessAutoStart(void)
|
|||||||
|
|
||||||
serverSockAddr.Clear();
|
serverSockAddr.Clear();
|
||||||
|
|
||||||
if (SelectUnicastEntry(DnsSrpUnicast::kFromServiceData, unicastInfo) == kErrorNone)
|
if (SelectUnicastEntry(NetworkData::Service::kAddrInServiceData, unicastInfo) == kErrorNone)
|
||||||
{
|
{
|
||||||
mAutoStart.SetState(AutoStart::kSelectedUnicastPreferred);
|
mAutoStart.SetState(AutoStart::kSelectedUnicastPreferred);
|
||||||
serverSockAddr = unicastInfo.mSockAddr;
|
serverSockAddr = unicastInfo.mSockAddr;
|
||||||
@@ -2299,7 +2299,7 @@ void Client::ProcessAutoStart(void)
|
|||||||
|
|
||||||
mAutoStart.SetState(AutoStart::kSelectedAnycast);
|
mAutoStart.SetState(AutoStart::kSelectedAnycast);
|
||||||
}
|
}
|
||||||
else if (SelectUnicastEntry(DnsSrpUnicast::kFromServerData, unicastInfo) == kErrorNone)
|
else if (SelectUnicastEntry(NetworkData::Service::kAddrInServerData, unicastInfo) == kErrorNone)
|
||||||
{
|
{
|
||||||
mAutoStart.SetState(AutoStart::kSelectedUnicast);
|
mAutoStart.SetState(AutoStart::kSelectedUnicast);
|
||||||
serverSockAddr = unicastInfo.mSockAddr;
|
serverSockAddr = unicastInfo.mSockAddr;
|
||||||
@@ -2378,10 +2378,10 @@ exit:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error Client::SelectUnicastEntry(DnsSrpUnicast::Type aType, DnsSrpUnicast::Info &aInfo) const
|
Error Client::SelectUnicastEntry(DnsSrpUnicastType aType, DnsSrpUnicastInfo &aInfo) const
|
||||||
{
|
{
|
||||||
Error error = kErrorNotFound;
|
Error error = kErrorNotFound;
|
||||||
DnsSrpUnicast::Info unicastInfo;
|
DnsSrpUnicastInfo unicastInfo;
|
||||||
NetworkData::Service::Manager::Iterator iterator;
|
NetworkData::Service::Manager::Iterator iterator;
|
||||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_SAVE_SELECTED_SERVER_ENABLE
|
#if OPENTHREAD_CONFIG_SRP_CLIENT_SAVE_SELECTED_SERVER_ENABLE
|
||||||
Settings::SrpClientInfo savedInfo;
|
Settings::SrpClientInfo savedInfo;
|
||||||
@@ -2436,9 +2436,9 @@ void Client::SelectNextServer(bool aDisallowSwitchOnRegisteredHost)
|
|||||||
// restarts the client with the new server (keeping the retry wait
|
// restarts the client with the new server (keeping the retry wait
|
||||||
// interval as before).
|
// interval as before).
|
||||||
|
|
||||||
Ip6::SockAddr serverSockAddr;
|
Ip6::SockAddr serverSockAddr;
|
||||||
bool selectNext = false;
|
bool selectNext = false;
|
||||||
DnsSrpUnicast::Type type = DnsSrpUnicast::kFromServiceData;
|
DnsSrpUnicastType type = NetworkData::Service::kAddrInServiceData;
|
||||||
|
|
||||||
serverSockAddr.Clear();
|
serverSockAddr.Clear();
|
||||||
|
|
||||||
@@ -2450,11 +2450,11 @@ void Client::SelectNextServer(bool aDisallowSwitchOnRegisteredHost)
|
|||||||
switch (mAutoStart.GetState())
|
switch (mAutoStart.GetState())
|
||||||
{
|
{
|
||||||
case AutoStart::kSelectedUnicastPreferred:
|
case AutoStart::kSelectedUnicastPreferred:
|
||||||
type = DnsSrpUnicast::kFromServiceData;
|
type = NetworkData::Service::kAddrInServiceData;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AutoStart::kSelectedUnicast:
|
case AutoStart::kSelectedUnicast:
|
||||||
type = DnsSrpUnicast::kFromServerData;
|
type = NetworkData::Service::kAddrInServerData;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AutoStart::kSelectedAnycast:
|
case AutoStart::kSelectedAnycast:
|
||||||
@@ -2477,7 +2477,7 @@ void Client::SelectNextServer(bool aDisallowSwitchOnRegisteredHost)
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
DnsSrpUnicast::Info unicastInfo;
|
DnsSrpUnicastInfo unicastInfo;
|
||||||
NetworkData::Service::Manager::Iterator iterator;
|
NetworkData::Service::Manager::Iterator iterator;
|
||||||
|
|
||||||
while (Get<NetworkData::Service::Manager>().GetNextDnsSrpUnicastInfo(iterator, type, unicastInfo) == kErrorNone)
|
while (Get<NetworkData::Service::Manager>().GetNextDnsSrpUnicastInfo(iterator, type, unicastInfo) == kErrorNone)
|
||||||
|
|||||||
@@ -75,8 +75,9 @@ class Client : public InstanceLocator, private NonCopyable
|
|||||||
friend class ot::Notifier;
|
friend class ot::Notifier;
|
||||||
friend class ot::Ip6::Netif;
|
friend class ot::Ip6::Netif;
|
||||||
|
|
||||||
using DnsSrpUnicast = NetworkData::Service::DnsSrpUnicast;
|
using DnsSrpUnicastInfo = NetworkData::Service::DnsSrpUnicastInfo;
|
||||||
using DnsSrpAnycast = NetworkData::Service::DnsSrpAnycast;
|
using DnsSrpUnicastType = NetworkData::Service::DnsSrpUnicastType;
|
||||||
|
using DnsSrpAnycastInfo = NetworkData::Service::DnsSrpAnycastInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -1110,7 +1111,7 @@ private:
|
|||||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
#if OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
||||||
void ApplyAutoStartGuardOnAttach(void);
|
void ApplyAutoStartGuardOnAttach(void);
|
||||||
void ProcessAutoStart(void);
|
void ProcessAutoStart(void);
|
||||||
Error SelectUnicastEntry(DnsSrpUnicast::Type aType, DnsSrpUnicast::Info &aInfo) const;
|
Error SelectUnicastEntry(DnsSrpUnicastType aType, DnsSrpUnicastInfo &aInfo) const;
|
||||||
void HandleGuardTimer(void) {}
|
void HandleGuardTimer(void) {}
|
||||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_SWITCH_SERVER_ON_FAILURE
|
#if OPENTHREAD_CONFIG_SRP_CLIENT_SWITCH_SERVER_ON_FAILURE
|
||||||
void SelectNextServer(bool aDisallowSwitchOnRegisteredHost);
|
void SelectNextServer(bool aDisallowSwitchOnRegisteredHost);
|
||||||
|
|||||||
@@ -599,10 +599,10 @@ Error AddressResolver::ResolveUsingNetDataServices(const Ip6::Address &aEid, uin
|
|||||||
// service entries. Returns `kErrorNone` and updates `aRloc16`
|
// service entries. Returns `kErrorNone` and updates `aRloc16`
|
||||||
// if successful, otherwise returns `kErrorNotFound`.
|
// if successful, otherwise returns `kErrorNotFound`.
|
||||||
|
|
||||||
Error error = kErrorNotFound;
|
Error error = kErrorNotFound;
|
||||||
NetworkData::Service::Manager::Iterator iterator;
|
NetworkData::Service::Manager::Iterator iterator;
|
||||||
NetworkData::Service::DnsSrpUnicast::Info unicastInfo;
|
NetworkData::Service::DnsSrpUnicastInfo unicastInfo;
|
||||||
NetworkData::Service::DnsSrpUnicast::Type type = NetworkData::Service::DnsSrpUnicast::kFromServerData;
|
NetworkData::Service::DnsSrpUnicastType type = NetworkData::Service::kAddrInServerData;
|
||||||
|
|
||||||
VerifyOrExit(Get<Mle::Mle>().GetDeviceMode().GetNetworkDataType() == NetworkData::kFullSet);
|
VerifyOrExit(Get<Mle::Mle>().GetDeviceMode().GetNetworkDataType() == NetworkData::kFullSet);
|
||||||
|
|
||||||
|
|||||||
@@ -572,18 +572,17 @@ void Publisher::DnsSrpServiceEntry::Add(void)
|
|||||||
switch (GetType())
|
switch (GetType())
|
||||||
{
|
{
|
||||||
case kTypeAnycast:
|
case kTypeAnycast:
|
||||||
SuccessOrExit(Get<Service::Manager>().Add<Service::DnsSrpAnycast>(
|
SuccessOrExit(Get<Service::Manager>().AddDnsSrpAnycastService(mInfo.GetSequenceNumber()));
|
||||||
Service::DnsSrpAnycast::ServiceData(mInfo.GetSequenceNumber())));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kTypeUnicast:
|
case kTypeUnicast:
|
||||||
SuccessOrExit(Get<Service::Manager>().Add<Service::DnsSrpUnicast>(
|
SuccessOrExit(
|
||||||
Service::DnsSrpUnicast::ServiceData(mInfo.GetAddress(), mInfo.GetPort())));
|
Get<Service::Manager>().AddDnsSrpUnicastServiceWithAddrInServiceData(mInfo.GetAddress(), mInfo.GetPort()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kTypeUnicastMeshLocalEid:
|
case kTypeUnicastMeshLocalEid:
|
||||||
SuccessOrExit(Get<Service::Manager>().Add<Service::DnsSrpUnicast>(
|
SuccessOrExit(
|
||||||
Service::DnsSrpUnicast::ServerData(mInfo.GetAddress(), mInfo.GetPort())));
|
Get<Service::Manager>().AddDnsSrpUnicastServiceWithAddrInServerData(mInfo.GetAddress(), mInfo.GetPort()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,17 +603,16 @@ void Publisher::DnsSrpServiceEntry::Remove(State aNextState)
|
|||||||
switch (GetType())
|
switch (GetType())
|
||||||
{
|
{
|
||||||
case kTypeAnycast:
|
case kTypeAnycast:
|
||||||
SuccessOrExit(Get<Service::Manager>().Remove<Service::DnsSrpAnycast>(
|
SuccessOrExit(Get<Service::Manager>().RemoveDnsSrpAnycastService(mInfo.GetSequenceNumber()));
|
||||||
Service::DnsSrpAnycast::ServiceData(mInfo.GetSequenceNumber())));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kTypeUnicast:
|
case kTypeUnicast:
|
||||||
SuccessOrExit(Get<Service::Manager>().Remove<Service::DnsSrpUnicast>(
|
SuccessOrExit(Get<Service::Manager>().RemoveDnsSrpUnicastServiceWithAddrInServiceData(mInfo.GetAddress(),
|
||||||
Service::DnsSrpUnicast::ServiceData(mInfo.GetAddress(), mInfo.GetPort())));
|
mInfo.GetPort()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kTypeUnicastMeshLocalEid:
|
case kTypeUnicastMeshLocalEid:
|
||||||
SuccessOrExit(Get<Service::Manager>().Remove<Service::DnsSrpUnicast>());
|
SuccessOrExit(Get<Service::Manager>().RemoveDnsSrpUnicastServiceWithAddrInServerData());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,7 +656,7 @@ void Publisher::DnsSrpServiceEntry::Process(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kTypeUnicastMeshLocalEid:
|
case kTypeUnicastMeshLocalEid:
|
||||||
CountUnicastEntries(Service::DnsSrpUnicast::kFromServerData, numEntries, numPreferredEntries);
|
CountUnicastEntries(Service::kAddrInServerData, numEntries, numPreferredEntries);
|
||||||
desiredNumEntries = kDesiredNumUnicast;
|
desiredNumEntries = kDesiredNumUnicast;
|
||||||
|
|
||||||
if (HasAnyServiceDataUnicastEntry() || HasAnyAnycastEntry())
|
if (HasAnyServiceDataUnicastEntry() || HasAnyAnycastEntry())
|
||||||
@@ -675,7 +673,7 @@ void Publisher::DnsSrpServiceEntry::Process(void)
|
|||||||
|
|
||||||
case kTypeUnicast:
|
case kTypeUnicast:
|
||||||
desiredNumEntries = kDesiredNumUnicast;
|
desiredNumEntries = kDesiredNumUnicast;
|
||||||
CountUnicastEntries(Service::DnsSrpUnicast::kFromServiceData, numEntries, numPreferredEntries);
|
CountUnicastEntries(Service::kAddrInServiceData, numEntries, numPreferredEntries);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,8 +690,8 @@ void Publisher::DnsSrpServiceEntry::CountAnycastEntries(uint8_t &aNumEntries, ui
|
|||||||
// "sequence number" value). We prefer the entries associated with
|
// "sequence number" value). We prefer the entries associated with
|
||||||
// smaller RLCO16.
|
// smaller RLCO16.
|
||||||
|
|
||||||
Service::Manager::Iterator iterator;
|
Service::Manager::Iterator iterator;
|
||||||
Service::DnsSrpAnycast::Info anycastInfo;
|
Service::DnsSrpAnycastInfo anycastInfo;
|
||||||
|
|
||||||
while (Get<Service::Manager>().GetNextDnsSrpAnycastInfo(iterator, anycastInfo) == kErrorNone)
|
while (Get<Service::Manager>().GetNextDnsSrpAnycastInfo(iterator, anycastInfo) == kErrorNone)
|
||||||
{
|
{
|
||||||
@@ -711,20 +709,20 @@ void Publisher::DnsSrpServiceEntry::CountAnycastEntries(uint8_t &aNumEntries, ui
|
|||||||
|
|
||||||
bool Publisher::DnsSrpServiceEntry::HasAnyAnycastEntry(void) const
|
bool Publisher::DnsSrpServiceEntry::HasAnyAnycastEntry(void) const
|
||||||
{
|
{
|
||||||
Service::Manager::Iterator iterator;
|
Service::Manager::Iterator iterator;
|
||||||
Service::DnsSrpAnycast::Info anycastInfo;
|
Service::DnsSrpAnycastInfo anycastInfo;
|
||||||
|
|
||||||
return (Get<Service::Manager>().GetNextDnsSrpAnycastInfo(iterator, anycastInfo) == kErrorNone);
|
return (Get<Service::Manager>().GetNextDnsSrpAnycastInfo(iterator, anycastInfo) == kErrorNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Publisher::DnsSrpServiceEntry::CountUnicastEntries(Service::DnsSrpUnicast::Type aType,
|
void Publisher::DnsSrpServiceEntry::CountUnicastEntries(Service::DnsSrpUnicastType aType,
|
||||||
uint8_t &aNumEntries,
|
uint8_t &aNumEntries,
|
||||||
uint8_t &aNumPreferredEntries) const
|
uint8_t &aNumPreferredEntries) const
|
||||||
{
|
{
|
||||||
// Count the number of DNS/SRP unicast entries in the Network Data.
|
// Count the number of DNS/SRP unicast entries in the Network Data.
|
||||||
|
|
||||||
Service::Manager::Iterator iterator;
|
Service::Manager::Iterator iterator;
|
||||||
Service::DnsSrpUnicast::Info unicastInfo;
|
Service::DnsSrpUnicastInfo unicastInfo;
|
||||||
|
|
||||||
while (Get<Service::Manager>().GetNextDnsSrpUnicastInfo(iterator, aType, unicastInfo) == kErrorNone)
|
while (Get<Service::Manager>().GetNextDnsSrpUnicastInfo(iterator, aType, unicastInfo) == kErrorNone)
|
||||||
{
|
{
|
||||||
@@ -739,9 +737,9 @@ void Publisher::DnsSrpServiceEntry::CountUnicastEntries(Service::DnsSrpUnicast::
|
|||||||
|
|
||||||
bool Publisher::DnsSrpServiceEntry::HasAnyServiceDataUnicastEntry(void) const
|
bool Publisher::DnsSrpServiceEntry::HasAnyServiceDataUnicastEntry(void) const
|
||||||
{
|
{
|
||||||
Service::Manager::Iterator iterator;
|
Service::Manager::Iterator iterator;
|
||||||
Service::DnsSrpUnicast::Info unicastInfo;
|
Service::DnsSrpUnicastInfo unicastInfo;
|
||||||
Service::DnsSrpUnicast::Type type = Service::DnsSrpUnicast::kFromServiceData;
|
Service::DnsSrpUnicastType type = Service::kAddrInServiceData;
|
||||||
|
|
||||||
return (Get<Service::Manager>().GetNextDnsSrpUnicastInfo(iterator, type, unicastInfo) == kErrorNone);
|
return (Get<Service::Manager>().GetNextDnsSrpUnicastInfo(iterator, type, unicastInfo) == kErrorNone);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -439,9 +439,9 @@ private:
|
|||||||
void Process(void);
|
void Process(void);
|
||||||
void CountAnycastEntries(uint8_t &aNumEntries, uint8_t &aNumPreferredEntries) const;
|
void CountAnycastEntries(uint8_t &aNumEntries, uint8_t &aNumPreferredEntries) const;
|
||||||
bool HasAnyAnycastEntry(void) const;
|
bool HasAnyAnycastEntry(void) const;
|
||||||
void CountUnicastEntries(Service::DnsSrpUnicast::Type aType,
|
void CountUnicastEntries(Service::DnsSrpUnicastType aType,
|
||||||
uint8_t &aNumEntries,
|
uint8_t &aNumEntries,
|
||||||
uint8_t &aNumPreferredEntries) const;
|
uint8_t &aNumPreferredEntries) const;
|
||||||
bool HasAnyServiceDataUnicastEntry(void) const;
|
bool HasAnyServiceDataUnicastEntry(void) const;
|
||||||
|
|
||||||
Info mInfo;
|
Info mInfo;
|
||||||
|
|||||||
@@ -43,20 +43,10 @@ namespace ot {
|
|||||||
namespace NetworkData {
|
namespace NetworkData {
|
||||||
namespace Service {
|
namespace Service {
|
||||||
|
|
||||||
// Definitions of static const class member variables to allow ODR-use
|
|
||||||
// (One Definition Rule), e.g., to get address of `kServiceData`.
|
|
||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
|
||||||
const uint8_t BackboneRouter::kServiceData;
|
|
||||||
#endif
|
|
||||||
const uint8_t DnsSrpAnycast::kServiceData;
|
|
||||||
const uint8_t DnsSrpUnicast::kServiceData;
|
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||||
|
|
||||||
Error Manager::AddService(const void *aServiceData,
|
Error Manager::AddService(const void *aServiceData,
|
||||||
uint8_t aServiceDataLength,
|
uint8_t aServiceDataLength,
|
||||||
bool aServerStable,
|
|
||||||
const void *aServerData,
|
const void *aServerData,
|
||||||
uint8_t aServerDataLength)
|
uint8_t aServerDataLength)
|
||||||
{
|
{
|
||||||
@@ -66,7 +56,7 @@ Error Manager::AddService(const void *aServiceData,
|
|||||||
serviceData.Init(aServiceData, aServiceDataLength);
|
serviceData.Init(aServiceData, aServiceDataLength);
|
||||||
serverData.Init(aServerData, aServerDataLength);
|
serverData.Init(aServerData, aServerDataLength);
|
||||||
|
|
||||||
return Get<Local>().AddService(kThreadEnterpriseNumber, serviceData, aServerStable, serverData);
|
return Get<Local>().AddService(kThreadEnterpriseNumber, serviceData, /* aServerStable */ true, serverData);
|
||||||
}
|
}
|
||||||
|
|
||||||
Error Manager::RemoveService(const void *aServiceData, uint8_t aServiceDataLength)
|
Error Manager::RemoveService(const void *aServiceData, uint8_t aServiceDataLength)
|
||||||
@@ -80,28 +70,26 @@ Error Manager::RemoveService(const void *aServiceData, uint8_t aServiceDataLengt
|
|||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
#endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||||
|
|
||||||
Error Manager::GetServiceId(const void *aServiceData,
|
Error Manager::GetServiceId(uint8_t aServiceNumber, uint8_t &aServiceId) const
|
||||||
uint8_t aServiceDataLength,
|
|
||||||
bool aServerStable,
|
|
||||||
uint8_t &aServiceId) const
|
|
||||||
{
|
{
|
||||||
ServiceData serviceData;
|
ServiceData serviceData;
|
||||||
|
|
||||||
serviceData.Init(aServiceData, aServiceDataLength);
|
serviceData.InitFrom(aServiceNumber);
|
||||||
|
|
||||||
return Get<Leader>().GetServiceId(kThreadEnterpriseNumber, serviceData, aServerStable, aServiceId);
|
return Get<Leader>().GetServiceId(kThreadEnterpriseNumber, serviceData, /* aServerStable */ true, aServiceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||||
|
|
||||||
void Manager::GetBackboneRouterPrimary(ot::BackboneRouter::Config &aConfig) const
|
void Manager::GetBackboneRouterPrimary(ot::BackboneRouter::Config &aConfig) const
|
||||||
{
|
{
|
||||||
const ServerTlv *rvalServerTlv = nullptr;
|
const ServerTlv *rvalServerTlv = nullptr;
|
||||||
const BackboneRouter::ServerData *rvalServerData = nullptr;
|
const BbrServerData *rvalServerData = nullptr;
|
||||||
const ServiceTlv *serviceTlv = nullptr;
|
const ServiceTlv *serviceTlv = nullptr;
|
||||||
ServiceData serviceData;
|
uint8_t bbrServiceNumber = kBackboneRouterServiceNumber;
|
||||||
|
ServiceData serviceData;
|
||||||
|
|
||||||
serviceData.Init(&BackboneRouter::kServiceData, BackboneRouter::kServiceDataMinSize);
|
serviceData.InitFrom(bbrServiceNumber);
|
||||||
|
|
||||||
aConfig.mServer16 = Mle::kInvalidRloc16;
|
aConfig.mServer16 = Mle::kInvalidRloc16;
|
||||||
|
|
||||||
@@ -114,17 +102,17 @@ void Manager::GetBackboneRouterPrimary(ot::BackboneRouter::Config &aConfig) cons
|
|||||||
|
|
||||||
while (IterateToNextServer(iterator) == kErrorNone)
|
while (IterateToNextServer(iterator) == kErrorNone)
|
||||||
{
|
{
|
||||||
ServerData data;
|
ServerData data;
|
||||||
const BackboneRouter::ServerData *serverData;
|
const BbrServerData *serverData;
|
||||||
|
|
||||||
iterator.mServerSubTlv->GetServerData(data);
|
iterator.mServerSubTlv->GetServerData(data);
|
||||||
|
|
||||||
if (data.GetLength() < sizeof(BackboneRouter::ServerData))
|
if (data.GetLength() < sizeof(BbrServerData))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
serverData = reinterpret_cast<const BackboneRouter::ServerData *>(data.GetBytes());
|
serverData = reinterpret_cast<const BbrServerData *>(data.GetBytes());
|
||||||
|
|
||||||
if (rvalServerTlv == nullptr ||
|
if (rvalServerTlv == nullptr ||
|
||||||
IsBackboneRouterPreferredTo(*iterator.mServerSubTlv, *serverData, *rvalServerTlv, *rvalServerData))
|
IsBackboneRouterPreferredTo(*iterator.mServerSubTlv, *serverData, *rvalServerTlv, *rvalServerData))
|
||||||
@@ -146,10 +134,10 @@ exit:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::IsBackboneRouterPreferredTo(const ServerTlv &aServerTlv,
|
bool Manager::IsBackboneRouterPreferredTo(const ServerTlv &aServerTlv,
|
||||||
const BackboneRouter::ServerData &aServerData,
|
const BbrServerData &aServerData,
|
||||||
const ServerTlv &aOtherServerTlv,
|
const ServerTlv &aOtherServerTlv,
|
||||||
const BackboneRouter::ServerData &aOtherServerData) const
|
const BbrServerData &aOtherServerData) const
|
||||||
{
|
{
|
||||||
bool isPreferred;
|
bool isPreferred;
|
||||||
uint16_t leaderRloc16 = Get<Mle::MleRouter>().GetLeaderRloc16();
|
uint16_t leaderRloc16 = Get<Mle::MleRouter>().GetLeaderRloc16();
|
||||||
@@ -166,9 +154,10 @@ exit:
|
|||||||
|
|
||||||
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||||
|
|
||||||
Error Manager::GetNextDnsSrpAnycastInfo(Iterator &aIterator, DnsSrpAnycast::Info &aInfo) const
|
Error Manager::GetNextDnsSrpAnycastInfo(Iterator &aIterator, DnsSrpAnycastInfo &aInfo) const
|
||||||
{
|
{
|
||||||
Error error = kErrorNone;
|
Error error = kErrorNone;
|
||||||
|
uint8_t serviceNumber = kDnsSrpAnycastServiceNumber;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -180,10 +169,10 @@ Error Manager::GetNextDnsSrpAnycastInfo(Iterator &aIterator, DnsSrpAnycast::Info
|
|||||||
{
|
{
|
||||||
aIterator.mServiceTlv->GetServiceData(serviceData);
|
aIterator.mServiceTlv->GetServiceData(serviceData);
|
||||||
|
|
||||||
if (serviceData.GetLength() >= sizeof(DnsSrpAnycast::ServiceData))
|
if (serviceData.GetLength() >= sizeof(DnsSrpAnycastServiceData))
|
||||||
{
|
{
|
||||||
const DnsSrpAnycast::ServiceData *dnsServiceData =
|
const DnsSrpAnycastServiceData *dnsServiceData =
|
||||||
reinterpret_cast<const DnsSrpAnycast::ServiceData *>(serviceData.GetBytes());
|
reinterpret_cast<const DnsSrpAnycastServiceData *>(serviceData.GetBytes());
|
||||||
|
|
||||||
Get<Mle::Mle>().GetServiceAloc(aIterator.mServiceTlv->GetServiceId(), aInfo.mAnycastAddress);
|
Get<Mle::Mle>().GetServiceAloc(aIterator.mServiceTlv->GetServiceId(), aInfo.mAnycastAddress);
|
||||||
aInfo.mSequenceNumber = dnsServiceData->GetSequenceNumber();
|
aInfo.mSequenceNumber = dnsServiceData->GetSequenceNumber();
|
||||||
@@ -194,7 +183,7 @@ Error Manager::GetNextDnsSrpAnycastInfo(Iterator &aIterator, DnsSrpAnycast::Info
|
|||||||
|
|
||||||
// Find the next matching Service TLV.
|
// Find the next matching Service TLV.
|
||||||
|
|
||||||
serviceData.InitFrom(DnsSrpAnycast::kServiceData);
|
serviceData.InitFrom(serviceNumber);
|
||||||
aIterator.mServiceTlv =
|
aIterator.mServiceTlv =
|
||||||
Get<Leader>().FindNextThreadService(aIterator.mServiceTlv, serviceData, NetworkData::kServicePrefixMatch);
|
Get<Leader>().FindNextThreadService(aIterator.mServiceTlv, serviceData, NetworkData::kServicePrefixMatch);
|
||||||
aIterator.mServerSubTlv = nullptr;
|
aIterator.mServerSubTlv = nullptr;
|
||||||
@@ -210,12 +199,12 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error Manager::FindPreferredDnsSrpAnycastInfo(DnsSrpAnycast::Info &aInfo) const
|
Error Manager::FindPreferredDnsSrpAnycastInfo(DnsSrpAnycastInfo &aInfo) const
|
||||||
{
|
{
|
||||||
Error error = kErrorNotFound;
|
Error error = kErrorNotFound;
|
||||||
Iterator iterator;
|
Iterator iterator;
|
||||||
DnsSrpAnycast::Info info;
|
DnsSrpAnycastInfo info;
|
||||||
DnsSrpAnycast::Info maxNumericalSeqNumInfo;
|
DnsSrpAnycastInfo maxNumericalSeqNumInfo;
|
||||||
|
|
||||||
// Determine the entry with largest seq number in two ways:
|
// Determine the entry with largest seq number in two ways:
|
||||||
// `aInfo` will track the largest using serial number arithmetic
|
// `aInfo` will track the largest using serial number arithmetic
|
||||||
@@ -276,11 +265,10 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator,
|
Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator, DnsSrpUnicastType aType, DnsSrpUnicastInfo &aInfo) const
|
||||||
DnsSrpUnicast::Type aType,
|
|
||||||
DnsSrpUnicast::Info &aInfo) const
|
|
||||||
{
|
{
|
||||||
Error error = kErrorNone;
|
Error error = kErrorNone;
|
||||||
|
uint8_t serviceNumber = kDnsSrpUnicastServiceNumber;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -292,7 +280,7 @@ Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator,
|
|||||||
{
|
{
|
||||||
ServerData data;
|
ServerData data;
|
||||||
|
|
||||||
if (aType == DnsSrpUnicast::kFromServiceData)
|
if (aType == kAddrInServiceData)
|
||||||
{
|
{
|
||||||
const DnsSrpUnicast::ServiceData *dnsServiceData;
|
const DnsSrpUnicast::ServiceData *dnsServiceData;
|
||||||
|
|
||||||
@@ -312,7 +300,7 @@ Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator,
|
|||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
// `aType` is `kFromServerData`.
|
// `aType` is `kAddrInServerData`.
|
||||||
|
|
||||||
// Server sub-TLV can contain address and port info
|
// Server sub-TLV can contain address and port info
|
||||||
// (then we parse and return the info), or it can be
|
// (then we parse and return the info), or it can be
|
||||||
@@ -346,7 +334,7 @@ Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator,
|
|||||||
|
|
||||||
// Find the next matching Service TLV.
|
// Find the next matching Service TLV.
|
||||||
|
|
||||||
serviceData.InitFrom(DnsSrpUnicast::kServiceData);
|
serviceData.InitFrom(serviceNumber);
|
||||||
aIterator.mServiceTlv =
|
aIterator.mServiceTlv =
|
||||||
Get<Leader>().FindNextThreadService(aIterator.mServiceTlv, serviceData, NetworkData::kServicePrefixMatch);
|
Get<Leader>().FindNextThreadService(aIterator.mServiceTlv, serviceData, NetworkData::kServicePrefixMatch);
|
||||||
aIterator.mServerSubTlv = nullptr;
|
aIterator.mServerSubTlv = nullptr;
|
||||||
|
|||||||
@@ -52,316 +52,35 @@ namespace Service {
|
|||||||
|
|
||||||
const uint32_t kThreadEnterpriseNumber = ServiceTlv::kThreadEnterpriseNumber; ///< Thread enterprise number.
|
const uint32_t kThreadEnterpriseNumber = ServiceTlv::kThreadEnterpriseNumber; ///< Thread enterprise number.
|
||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements Thread Network Data "Backbone Router Service" server data generation and parsing.
|
* Represents information about an DNS/SRP server parsed from related Network Data service entries.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class BackboneRouter
|
struct DnsSrpAnycastInfo
|
||||||
{
|
{
|
||||||
public:
|
Ip6::Address mAnycastAddress; ///< The anycast address associated with the DNS/SRP servers.
|
||||||
/**
|
uint8_t mSequenceNumber; ///< Sequence number used to notify SRP client if they need to re-register.
|
||||||
* This constant variable represents the Backbone Router service data.
|
uint16_t mRloc16; ///< The RLOC16 of the entry.
|
||||||
*
|
|
||||||
* The service data contains only the service number (THREAD_SERVICE_DATA_BBR) as a single byte.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static const uint8_t kServiceData = 0x01;
|
|
||||||
static constexpr uint8_t kServiceDataMinSize = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the generation and parsing of "Backbone Router Service" server data.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
OT_TOOL_PACKED_BEGIN
|
|
||||||
class ServerData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Returns the length (in bytes) of server data.
|
|
||||||
*
|
|
||||||
* @returns The server data length in bytes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint8_t GetLength(void) const { return sizeof(ServerData); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sequence number of Backbone Router.
|
|
||||||
*
|
|
||||||
* @returns The sequence number of the Backbone Router.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint8_t GetSequenceNumber(void) const { return mSequenceNumber; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the sequence number of Backbone Router.
|
|
||||||
*
|
|
||||||
* @param[in] aSequenceNumber The sequence number of Backbone Router.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void SetSequenceNumber(uint8_t aSequenceNumber) { mSequenceNumber = aSequenceNumber; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Registration Delay (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
* @returns The BBR Registration Delay (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint16_t GetReregistrationDelay(void) const { return BigEndian::HostSwap16(mReregistrationDelay); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Registration Delay (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
* @param[in] aReregistrationDelay The Registration Delay (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void SetReregistrationDelay(uint16_t aReregistrationDelay)
|
|
||||||
{
|
|
||||||
mReregistrationDelay = BigEndian::HostSwap16(aReregistrationDelay);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the multicast listener report timeout (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
* @returns The multicast listener report timeout (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint32_t GetMlrTimeout(void) const { return BigEndian::HostSwap32(mMlrTimeout); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets multicast listener report timeout (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
* @param[in] aMlrTimeout The multicast listener report timeout (in seconds) of Backbone Router.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void SetMlrTimeout(uint32_t aMlrTimeout) { mMlrTimeout = BigEndian::HostSwap32(aMlrTimeout); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t mSequenceNumber;
|
|
||||||
uint16_t mReregistrationDelay;
|
|
||||||
uint32_t mMlrTimeout;
|
|
||||||
} OT_TOOL_PACKED_END;
|
|
||||||
|
|
||||||
BackboneRouter(void) = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements Thread Network Data "DNS/SRP Service Anycast Address" generation and parsing.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class DnsSrpAnycast
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static constexpr uint8_t kServiceNumber = 0x5c; ///< The service number of a `DnsSrpAnycast` entry.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constant variable represents the short version of service data.
|
|
||||||
*
|
|
||||||
* The short version of service data contains only service number as a single byte.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static const uint8_t kServiceData = kServiceNumber;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents information about an DNS/SRP server parsed from related Network Data service entries.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
struct Info
|
|
||||||
{
|
|
||||||
Ip6::Address mAnycastAddress; ///< The anycast address associated with the DNS/SRP servers.
|
|
||||||
uint8_t mSequenceNumber; ///< Sequence number used to notify SRP client if they need to re-register.
|
|
||||||
uint16_t mRloc16; ///< The RLOC16 of the entry.
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the "DNS/SRP Service (Anycast)" service data.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
OT_TOOL_PACKED_BEGIN
|
|
||||||
class ServiceData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Initializes the `ServiceData` object.
|
|
||||||
*
|
|
||||||
* @param[in] aSequenceNumber The sequence number of "DNS/SRP server" service.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
explicit ServiceData(uint8_t aSequenceNumber)
|
|
||||||
: mServiceNumber(kServiceNumber)
|
|
||||||
, mSequenceNumber(aSequenceNumber)
|
|
||||||
{
|
|
||||||
OT_UNUSED_VARIABLE(mServiceNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the length (in bytes) of service data.
|
|
||||||
*
|
|
||||||
* @returns The data length in bytes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint8_t GetLength(void) const { return sizeof(ServiceData); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sequence number.
|
|
||||||
*
|
|
||||||
* @returns The sequence number.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint8_t GetSequenceNumber(void) const { return mSequenceNumber; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t mServiceNumber;
|
|
||||||
uint8_t mSequenceNumber;
|
|
||||||
} OT_TOOL_PACKED_END;
|
|
||||||
|
|
||||||
DnsSrpAnycast(void) = delete;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements Thread Network Data DNS/SRP Service (Unicast Address) generation and parsing.
|
* Represents the `DnsSrpUnicast` entry type.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DnsSrpUnicast
|
enum DnsSrpUnicastType : uint8_t
|
||||||
{
|
{
|
||||||
public:
|
kAddrInServiceData, ///< Socket address is from service data.
|
||||||
static constexpr uint8_t kServiceNumber = 0x5d; ///< The service number of `DnsSrpUnicast` entry.
|
kAddrInServerData, ///< Socket address is from server data.
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constant variable represents the short version of service data.
|
* Represents information about an DNS/SRP server parsed from related Network Data service entries.
|
||||||
*
|
*
|
||||||
* The short version of service data contains only service number as a single byte.
|
*/
|
||||||
*
|
struct DnsSrpUnicastInfo
|
||||||
*/
|
{
|
||||||
static const uint8_t kServiceData = kServiceNumber;
|
Ip6::SockAddr mSockAddr; ///< The socket address (IPv6 address and port) of the DNS/SRP server.
|
||||||
|
uint16_t mRloc16; ///< The BR RLOC16 adding the entry.
|
||||||
/**
|
|
||||||
* Represents the `DnsSrpUnicast` entry type.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
enum Type : uint8_t
|
|
||||||
{
|
|
||||||
kFromServiceData, ///< Socket address is from service data.
|
|
||||||
kFromServerData, ///< Socket address is from server data.
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents information about an DNS/SRP server parsed from related Network Data service entries.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
struct Info
|
|
||||||
{
|
|
||||||
Ip6::SockAddr mSockAddr; ///< The socket address (IPv6 address and port) of the DNS/SRP server.
|
|
||||||
uint16_t mRloc16; ///< The BR RLOC16 adding the entry.
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents long version of "DNS/SRP Service (Unicast)" service data.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
OT_TOOL_PACKED_BEGIN
|
|
||||||
class ServiceData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Initializes the `ServiceData` object.
|
|
||||||
*
|
|
||||||
* @param[in] aAddress The IPv6 address of DNS/SRP server.
|
|
||||||
* @param[in] aPort The port number of DNS/SRP server.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
explicit ServiceData(const Ip6::Address &aAddress, uint16_t aPort)
|
|
||||||
: mServiceNumber(kServiceNumber)
|
|
||||||
, mAddress(aAddress)
|
|
||||||
, mPort(BigEndian::HostSwap16(aPort))
|
|
||||||
{
|
|
||||||
OT_UNUSED_VARIABLE(mServiceNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the length (in bytes) of service data.
|
|
||||||
*
|
|
||||||
* @returns The data length in bytes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint8_t GetLength(void) const { return sizeof(ServiceData); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the IPv6 address.
|
|
||||||
*
|
|
||||||
* @returns The IPv6 address
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const Ip6::Address &GetAddress(void) const { return mAddress; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the port number.
|
|
||||||
*
|
|
||||||
* @returns The port number.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint16_t GetPort(void) const { return BigEndian::HostSwap16(mPort); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t mServiceNumber;
|
|
||||||
Ip6::Address mAddress;
|
|
||||||
uint16_t mPort;
|
|
||||||
} OT_TOOL_PACKED_END;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents long version of "DNS/SRP Service (Unicast)" server data.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
OT_TOOL_PACKED_BEGIN
|
|
||||||
class ServerData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Initializes the `ServerData` object.
|
|
||||||
*
|
|
||||||
* @param[in] aAddress The IPv6 address of DNS/SRP server.
|
|
||||||
* @param[in] aPort The port number of DNS/SRP server.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ServerData(const Ip6::Address &aAddress, uint16_t aPort)
|
|
||||||
: mAddress(aAddress)
|
|
||||||
, mPort(BigEndian::HostSwap16(aPort))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the length (in bytes) of server data.
|
|
||||||
*
|
|
||||||
* @returns The data length in bytes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint8_t GetLength(void) const { return sizeof(ServerData); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the IPv6 address.
|
|
||||||
*
|
|
||||||
* @returns The IPv6 address
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const Ip6::Address &GetAddress(void) const { return mAddress; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the port number.
|
|
||||||
*
|
|
||||||
* @returns The port number.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
uint16_t GetPort(void) const { return BigEndian::HostSwap16(mPort); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ip6::Address mAddress;
|
|
||||||
uint16_t mPort;
|
|
||||||
} OT_TOOL_PACKED_END;
|
|
||||||
|
|
||||||
DnsSrpUnicast(void) = delete;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -418,122 +137,117 @@ public:
|
|||||||
|
|
||||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||||
/**
|
/**
|
||||||
* Adds a Thread Service entry to the local Thread Network Data.
|
* Adds a DNS/SRP Anycast Service entry to the local Thread Network Data.
|
||||||
*
|
*
|
||||||
* This version of `Add<ServiceType>()` is intended for use with a `ServiceType` that has a constant service data
|
* @param[in] aSequenceNumber The anycast sequence number.
|
||||||
* format with a non-empty and potentially non-const server data format (provided as input parameter).
|
|
||||||
*
|
|
||||||
* The template type `ServiceType` has the following requirements:
|
|
||||||
* - It MUST have a constant variable `ServiceType::kServiceData` specifying the service data.
|
|
||||||
* - It MUST define nested type `ServiceType::ServerData` representing the server data (and its format).
|
|
||||||
* - The `ServiceType::ServerData` MUST provide `GetLength()` method returning the length of server data.
|
|
||||||
*
|
|
||||||
* @tparam ServiceType The service type to be added.
|
|
||||||
*
|
|
||||||
* @param[in] aServerData The server data.
|
|
||||||
* @param[in] aServerStable The Stable flag value for Server TLV.
|
|
||||||
*
|
*
|
||||||
* @retval kErrorNone Successfully added the Service entry.
|
* @retval kErrorNone Successfully added the Service entry.
|
||||||
* @retval kErrorNoBufs Insufficient space to add the Service entry.
|
* @retval kErrorNoBufs Insufficient space to add the Service entry.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename ServiceType>
|
Error AddDnsSrpAnycastService(uint8_t aSequenceNumber)
|
||||||
Error Add(const typename ServiceType::ServerData &aServerData, bool aServerStable = true)
|
|
||||||
{
|
{
|
||||||
return AddService(&ServiceType::kServiceData, sizeof(ServiceType::kServiceData), aServerStable, &aServerData,
|
return AddService(DnsSrpAnycastServiceData(aSequenceNumber));
|
||||||
aServerData.GetLength());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a Thread Service entry to the local Thread Network Data.
|
* Removes a DNS/SRP Anycast Service entry from local Thread Network Data.
|
||||||
*
|
*
|
||||||
* This version of `Add<ServiceType>()` is intended for use with a `ServiceType` that has a non-const service data
|
* @param[in] aSequenceNumber The anycast sequence number.
|
||||||
* format (provided as input parameter) with an empty server data.
|
|
||||||
*
|
*
|
||||||
* The template type `ServiceType` has the following requirements:
|
* @retval kErrorNone Successfully removed the Service entry.
|
||||||
* - It MUST define nested type `ServiceType::ServiceData` representing the service data (and its format).
|
* @retval kErrorNotFound Could not find the Service entry.
|
||||||
* - The `ServiceType::ServiceData` MUST provide `GetLength()` method returning the length of service data.
|
|
||||||
*
|
*
|
||||||
* @tparam ServiceType The service type to be added.
|
*/
|
||||||
|
Error RemoveDnsSrpAnycastService(uint8_t aSequenceNumber)
|
||||||
|
{
|
||||||
|
return RemoveService(DnsSrpAnycastServiceData(aSequenceNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a DNS/SRP Unicast Service entry with address in Service Data to the local Thread Network Data.
|
||||||
*
|
*
|
||||||
* @param[in] aServiceData The service data.
|
* @param[in] aAddress The unicast address.
|
||||||
* @param[in] aServerStable The Stable flag value for Server TLV.
|
* @param[in] aPort The port number.
|
||||||
*
|
*
|
||||||
* @retval kErrorNone Successfully added the Service entry.
|
* @retval kErrorNone Successfully added the Service entry.
|
||||||
* @retval kErrorNoBufs Insufficient space to add the Service entry.
|
* @retval kErrorNoBufs Insufficient space to add the Service entry.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename ServiceType>
|
Error AddDnsSrpUnicastServiceWithAddrInServiceData(const Ip6::Address &aAddress, uint16_t aPort)
|
||||||
Error Add(const typename ServiceType::ServiceData &aServiceData, bool aServerStable = true)
|
|
||||||
{
|
{
|
||||||
return AddService(&aServiceData, aServiceData.GetLength(), aServerStable, nullptr, 0);
|
return AddService(DnsSrpUnicast::ServiceData(aAddress, aPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a Thread Service entry from the local Thread Network Data.
|
* Removes a DNS/SRP Unicast Service entry with address in Service Data from the local Thread Network Data.
|
||||||
*
|
*
|
||||||
* This version of `Remove<SeviceType>()` is intended for use with a `ServiceType` that has a constant service data
|
* @param[in] aAddress The unicast address.
|
||||||
* format.
|
* @param[in] aPort The port number.
|
||||||
*
|
|
||||||
* The template type `ServiceType` has the following requirements:
|
|
||||||
* - It MUST have a constant variable `ServiceType::kServiceData` specifying the service data.
|
|
||||||
*
|
|
||||||
* @tparam ServiceType The service type to be removed.
|
|
||||||
*
|
*
|
||||||
* @retval kErrorNone Successfully removed the Service entry.
|
* @retval kErrorNone Successfully removed the Service entry.
|
||||||
* @retval kErrorNotFound Could not find the Service entry.
|
* @retval kErrorNotFound Could not find the Service entry.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename ServiceType> Error Remove(void)
|
Error RemoveDnsSrpUnicastServiceWithAddrInServiceData(const Ip6::Address &aAddress, uint16_t aPort)
|
||||||
{
|
{
|
||||||
return RemoveService(&ServiceType::kServiceData, sizeof(ServiceType::kServiceData));
|
return RemoveService(DnsSrpUnicast::ServiceData(aAddress, aPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a Thread Service entry from the local Thread Network Data.
|
* Adds a DNS/SRP Unicast Service entry with address in Server Data to the local Thread Network Data.
|
||||||
*
|
*
|
||||||
* This version of `Remove<ServiceType>()` is intended for use with a `ServiceType` that has a non-const service
|
* @param[in] aAddress The unicast address.
|
||||||
* data format (provided as input parameter).
|
* @param[in] aPort The port number.
|
||||||
*
|
*
|
||||||
* The template type `ServiceType` has the following requirements:
|
* @retval kErrorNone Successfully added the Service entry.
|
||||||
* - It MUST define nested type `ServiceType::ServiceData` representing the service data (and its format).
|
* @retval kErrorNoBufs Insufficient space to add the Service entry.
|
||||||
* - The `ServiceType::ServiceData` MUST provide `GetLength()` method returning the length of service data.
|
|
||||||
*
|
*
|
||||||
* @tparam ServiceType The service type to be removed.
|
*/
|
||||||
*
|
Error AddDnsSrpUnicastServiceWithAddrInServerData(const Ip6::Address &aAddress, uint16_t aPort)
|
||||||
* @param[in] aServiceData The service data.
|
{
|
||||||
|
return AddService(kDnsSrpUnicastServiceNumber, DnsSrpUnicast::ServerData(aAddress, aPort));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a DNS/SRP Unicast Service entry with address in Server Data from the local Thread Network Data.
|
||||||
*
|
*
|
||||||
* @retval kErrorNone Successfully removed the Service entry.
|
* @retval kErrorNone Successfully removed the Service entry.
|
||||||
* @retval kErrorNotFound Could not find the Service entry.
|
* @retval kErrorNotFound Could not find the Service entry.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename ServiceType> Error Remove(const typename ServiceType::ServiceData &aServiceData)
|
Error RemoveDnsSrpUnicastServiceWithAddrInServerData(void) { return RemoveService(kDnsSrpUnicastServiceNumber); }
|
||||||
|
|
||||||
|
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||||
|
/**
|
||||||
|
* Adds a Backbone Router Service entry to the local Thread Network Data.
|
||||||
|
*
|
||||||
|
* @param[in] aSequenceNumber The sequence number of Backbone Router.
|
||||||
|
* @param[in] aReregistrationDelay The Registration Delay (in seconds) of Backbone Router.
|
||||||
|
* @param[in] aMlrTimeout The multicast listener report timeout (in seconds) of Backbone Router.
|
||||||
|
*
|
||||||
|
* @retval kErrorNone Successfully added the Service entry.
|
||||||
|
* @retval kErrorNoBufs Insufficient space to add the Service entry.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Error AddBackboneRouterService(uint8_t aSequenceNumber, uint16_t aReregistrationDelay, uint32_t aMlrTimeout)
|
||||||
{
|
{
|
||||||
return RemoveService(&aServiceData, aServiceData.GetLength());
|
return AddService(kBackboneRouterServiceNumber,
|
||||||
|
BbrServerData(aSequenceNumber, aReregistrationDelay, aMlrTimeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the Backbone Router Service entry from the local Thread Network Data.
|
||||||
|
*
|
||||||
|
* @retval kErrorNone Successfully removed the Service entry.
|
||||||
|
* @retval kErrorNotFound Could not find the Service entry.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Error RemoveBackboneRouterService(void) { return RemoveService(kBackboneRouterServiceNumber); }
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
#endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Service ID for the specified service from Thread Network Data.
|
|
||||||
*
|
|
||||||
* The template type `ServiceType` has the following requirements:
|
|
||||||
* - It MUST have a constant `ServiceType::kServiceNumber` specifying the service number.
|
|
||||||
*
|
|
||||||
* @tparam ServiceType The service type to be added.
|
|
||||||
*
|
|
||||||
* @param[in] aServerStable The Stable flag value for Server TLV
|
|
||||||
* @param[out] aServiceId A reference where to put the Service ID.
|
|
||||||
*
|
|
||||||
* @retval kErrorNone Successfully got the Service ID.
|
|
||||||
* @retval kErrorNotFound The specified service was not found.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template <typename ServiceType> Error GetServiceId(bool aServerStable, uint8_t &aServiceId) const
|
|
||||||
{
|
|
||||||
return GetServiceId(&ServiceType::kServiceData, sizeof(ServiceType::kServiceData), aServerStable, aServiceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||||
/**
|
/**
|
||||||
* Gets the Primary Backbone Router (PBBR) in the Thread Network Data.
|
* Gets the Primary Backbone Router (PBBR) in the Thread Network Data.
|
||||||
@@ -542,6 +256,20 @@ public:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void GetBackboneRouterPrimary(ot::BackboneRouter::Config &aConfig) const;
|
void GetBackboneRouterPrimary(ot::BackboneRouter::Config &aConfig) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Service ID of Backbone Router service from Thread Network Data.
|
||||||
|
*
|
||||||
|
* @param[out] aServiceId A reference where to put the Service ID.
|
||||||
|
*
|
||||||
|
* @retval kErrorNone Successfully got the Service ID.
|
||||||
|
* @retval kErrorNotFound The specified service was not found.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Error GetBackboneRouterServiceId(uint8_t &aServiceId) const
|
||||||
|
{
|
||||||
|
return GetServiceId(kBackboneRouterServiceNumber, aServiceId);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -551,13 +279,13 @@ public:
|
|||||||
* method).
|
* method).
|
||||||
*
|
*
|
||||||
* @param[in,out] aIterator A reference to an iterator.
|
* @param[in,out] aIterator A reference to an iterator.
|
||||||
* @param[out] aInfo A reference to `DnsSrpAnycast::Info` to return the info.
|
* @param[out] aInfo A reference to `DnsSrpAnycastInfo` to return the info.
|
||||||
*
|
*
|
||||||
* @retval kErrorNone Successfully got the next info. @p aInfo and @p aIterator are updated.
|
* @retval kErrorNone Successfully got the next info. @p aInfo and @p aIterator are updated.
|
||||||
* @retval kErrorNotFound No more matching entries in the Network Data.
|
* @retval kErrorNotFound No more matching entries in the Network Data.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Error GetNextDnsSrpAnycastInfo(Iterator &aIterator, DnsSrpAnycast::Info &aInfo) const;
|
Error GetNextDnsSrpAnycastInfo(Iterator &aIterator, DnsSrpAnycastInfo &aInfo) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the preferred DNS/SRP info among all the Thread Network Data "DNS/SRP Service Anycast Address"
|
* Finds the preferred DNS/SRP info among all the Thread Network Data "DNS/SRP Service Anycast Address"
|
||||||
@@ -566,13 +294,13 @@ public:
|
|||||||
* The preferred entry is determined based on the sequence number value where a larger value (in the sense
|
* The preferred entry is determined based on the sequence number value where a larger value (in the sense
|
||||||
* specified by Serial Number Arithmetic logic in RFC-1982) is considered more recent and therefore preferred.
|
* specified by Serial Number Arithmetic logic in RFC-1982) is considered more recent and therefore preferred.
|
||||||
*
|
*
|
||||||
* @param[out] aInfo A reference to `DnsSrpAnycast::Info` to return the info.
|
* @param[out] aInfo A reference to `DnsSrpAnycastInfo` to return the info.
|
||||||
*
|
*
|
||||||
* @retval kErrorNone Successfully found the preferred info. @p aInfo is updated.
|
* @retval kErrorNone Successfully found the preferred info. @p aInfo is updated.
|
||||||
* @retval kErrorNotFound No "DNS/SRP Service Anycast" entry in Network Data.
|
* @retval kErrorNotFound No "DNS/SRP Service Anycast" entry in Network Data.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Error FindPreferredDnsSrpAnycastInfo(DnsSrpAnycast::Info &aInfo) const;
|
Error FindPreferredDnsSrpAnycastInfo(DnsSrpAnycastInfo &aInfo) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the next DNS/SRP info from the Thread Network Data "DNS/SRP Service Unicast Address" entries.
|
* Gets the next DNS/SRP info from the Thread Network Data "DNS/SRP Service Unicast Address" entries.
|
||||||
@@ -581,36 +309,139 @@ public:
|
|||||||
* method).
|
* method).
|
||||||
*
|
*
|
||||||
* @param[in,out] aIterator A reference to an iterator.
|
* @param[in,out] aIterator A reference to an iterator.
|
||||||
* @param[in] aType The entry type, `kFromServiceData` (preferred) or `kFromServerData` (non-preferred).
|
* @param[in] aType The entry type, `kAddrInServiceData` or `kAddrInServerData`
|
||||||
* @param[out] aInfo A reference to `DnsSrpUnicast::Info` to return the info.
|
* @param[out] aInfo A reference to `DnsSrpUnicastInfo` to return the info.
|
||||||
*
|
*
|
||||||
* @retval kErrorNone Successfully got the next info. @p aInfo and @p aIterator are updated.
|
* @retval kErrorNone Successfully got the next info. @p aInfo and @p aIterator are updated.
|
||||||
* @retval kErrorNotFound No more matching entries in the Network Data.
|
* @retval kErrorNotFound No more matching entries in the Network Data.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Error GetNextDnsSrpUnicastInfo(Iterator &aIterator, DnsSrpUnicast::Type aType, DnsSrpUnicast::Info &aInfo) const;
|
Error GetNextDnsSrpUnicastInfo(Iterator &aIterator, DnsSrpUnicastType aType, DnsSrpUnicastInfo &aInfo) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr uint8_t kBackboneRouterServiceNumber = 0x01;
|
||||||
|
static constexpr uint8_t kDnsSrpAnycastServiceNumber = 0x5c;
|
||||||
|
static constexpr uint8_t kDnsSrpUnicastServiceNumber = 0x5d;
|
||||||
|
|
||||||
|
OT_TOOL_PACKED_BEGIN
|
||||||
|
class DnsSrpAnycastServiceData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit DnsSrpAnycastServiceData(uint8_t aSequenceNumber)
|
||||||
|
: mServiceNumber(kDnsSrpAnycastServiceNumber)
|
||||||
|
, mSequenceNumber(aSequenceNumber)
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(mServiceNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t GetSequenceNumber(void) const { return mSequenceNumber; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t mServiceNumber;
|
||||||
|
uint8_t mSequenceNumber;
|
||||||
|
} OT_TOOL_PACKED_END;
|
||||||
|
|
||||||
|
class DnsSrpUnicast
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OT_TOOL_PACKED_BEGIN
|
||||||
|
struct ServiceData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ServiceData(const Ip6::Address &aAddress, uint16_t aPort)
|
||||||
|
: mServiceNumber(kDnsSrpUnicastServiceNumber)
|
||||||
|
, mAddress(aAddress)
|
||||||
|
, mPort(BigEndian::HostSwap16(aPort))
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(mServiceNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Ip6::Address &GetAddress(void) const { return mAddress; }
|
||||||
|
uint16_t GetPort(void) const { return BigEndian::HostSwap16(mPort); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t mServiceNumber;
|
||||||
|
Ip6::Address mAddress;
|
||||||
|
uint16_t mPort;
|
||||||
|
} OT_TOOL_PACKED_END;
|
||||||
|
|
||||||
|
OT_TOOL_PACKED_BEGIN
|
||||||
|
class ServerData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ServerData(const Ip6::Address &aAddress, uint16_t aPort)
|
||||||
|
: mAddress(aAddress)
|
||||||
|
, mPort(BigEndian::HostSwap16(aPort))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const Ip6::Address &GetAddress(void) const { return mAddress; }
|
||||||
|
uint16_t GetPort(void) const { return BigEndian::HostSwap16(mPort); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ip6::Address mAddress;
|
||||||
|
uint16_t mPort;
|
||||||
|
} OT_TOOL_PACKED_END;
|
||||||
|
|
||||||
|
DnsSrpUnicast(void) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||||
|
OT_TOOL_PACKED_BEGIN
|
||||||
|
class BbrServerData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BbrServerData(uint8_t aSequenceNumber, uint16_t aReregDelay, uint32_t aMlrTimeout)
|
||||||
|
: mSequenceNumber(aSequenceNumber)
|
||||||
|
, mReregDelay(BigEndian::HostSwap16(aReregDelay))
|
||||||
|
, mMlrTimeout(BigEndian::HostSwap32(aMlrTimeout))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t GetSequenceNumber(void) const { return mSequenceNumber; }
|
||||||
|
uint16_t GetReregistrationDelay(void) const { return BigEndian::HostSwap16(mReregDelay); }
|
||||||
|
uint32_t GetMlrTimeout(void) const { return BigEndian::HostSwap32(mMlrTimeout); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t mSequenceNumber;
|
||||||
|
uint16_t mReregDelay;
|
||||||
|
uint32_t mMlrTimeout;
|
||||||
|
} OT_TOOL_PACKED_END;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||||
|
template <typename ServiceDataType> Error AddService(const ServiceDataType &aServiceData)
|
||||||
|
{
|
||||||
|
return AddService(&aServiceData, sizeof(ServiceDataType), nullptr, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ServerDataType> Error AddService(uint8_t aServiceNumber, const ServerDataType &aServerData)
|
||||||
|
{
|
||||||
|
return AddService(&aServiceNumber, sizeof(uint8_t), &aServerData, sizeof(ServerDataType));
|
||||||
|
}
|
||||||
|
|
||||||
Error AddService(const void *aServiceData,
|
Error AddService(const void *aServiceData,
|
||||||
uint8_t aServiceDataLength,
|
uint8_t aServiceDataLength,
|
||||||
bool aServerStable,
|
const void *aServerData = nullptr,
|
||||||
const void *aServerData,
|
uint8_t aServerDataLength = 0);
|
||||||
uint8_t aServerDataLength);
|
|
||||||
|
template <typename ServiceDataType> Error RemoveService(const ServiceDataType &aServiceData)
|
||||||
|
{
|
||||||
|
return RemoveService(&aServiceData, sizeof(ServiceDataType));
|
||||||
|
}
|
||||||
|
|
||||||
|
Error RemoveService(uint8_t aServiceNumber) { return RemoveService(&aServiceNumber, sizeof(uint8_t)); }
|
||||||
Error RemoveService(const void *aServiceData, uint8_t aServiceDataLength);
|
Error RemoveService(const void *aServiceData, uint8_t aServiceDataLength);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Error GetServiceId(const void *aServiceData,
|
Error GetServiceId(uint8_t aServiceNumber, uint8_t &aServiceId) const;
|
||||||
uint8_t aServiceDataLength,
|
|
||||||
bool aServerStable,
|
|
||||||
uint8_t &aServiceId) const;
|
|
||||||
Error IterateToNextServer(Iterator &aIterator) const;
|
Error IterateToNextServer(Iterator &aIterator) const;
|
||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||||
bool IsBackboneRouterPreferredTo(const ServerTlv &aServerTlv,
|
bool IsBackboneRouterPreferredTo(const ServerTlv &aServerTlv,
|
||||||
const BackboneRouter::ServerData &aServerData,
|
const BbrServerData &aServerData,
|
||||||
const ServerTlv &aOtherServerTlv,
|
const ServerTlv &aOtherServerTlv,
|
||||||
const BackboneRouter::ServerData &aOtherServerData) const;
|
const BbrServerData &aOtherServerData) const;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -637,7 +637,7 @@ void TestNetworkDataDsnSrpServices(void)
|
|||||||
uint8_t mSequenceNumber;
|
uint8_t mSequenceNumber;
|
||||||
uint16_t mRloc16;
|
uint16_t mRloc16;
|
||||||
|
|
||||||
bool Matches(Service::DnsSrpAnycast::Info aInfo) const
|
bool Matches(Service::DnsSrpAnycastInfo aInfo) const
|
||||||
{
|
{
|
||||||
VerifyOrQuit(aInfo.mAnycastAddress.GetIid().IsAnycastServiceLocator());
|
VerifyOrQuit(aInfo.mAnycastAddress.GetIid().IsAnycastServiceLocator());
|
||||||
|
|
||||||
@@ -652,7 +652,7 @@ void TestNetworkDataDsnSrpServices(void)
|
|||||||
uint16_t mPort;
|
uint16_t mPort;
|
||||||
uint16_t mRloc16;
|
uint16_t mRloc16;
|
||||||
|
|
||||||
bool Matches(const Service::DnsSrpUnicast::Info &aInfo) const
|
bool Matches(const Service::DnsSrpUnicastInfo &aInfo) const
|
||||||
{
|
{
|
||||||
Ip6::SockAddr sockAddr;
|
Ip6::SockAddr sockAddr;
|
||||||
|
|
||||||
@@ -699,12 +699,12 @@ void TestNetworkDataDsnSrpServices(void)
|
|||||||
|
|
||||||
const uint8_t kPreferredAnycastEntryIndex = 2;
|
const uint8_t kPreferredAnycastEntryIndex = 2;
|
||||||
|
|
||||||
Service::Manager &manager = instance->Get<Service::Manager>();
|
Service::Manager &manager = instance->Get<Service::Manager>();
|
||||||
Service::Manager::Iterator iterator;
|
Service::Manager::Iterator iterator;
|
||||||
Service::DnsSrpAnycast::Info anycastInfo;
|
Service::DnsSrpAnycastInfo anycastInfo;
|
||||||
Service::DnsSrpUnicast::Info unicastInfo;
|
Service::DnsSrpUnicastInfo unicastInfo;
|
||||||
Service::DnsSrpUnicast::Type type;
|
Service::DnsSrpUnicastType type;
|
||||||
Rlocs rlocs;
|
Rlocs rlocs;
|
||||||
|
|
||||||
reinterpret_cast<TestLeader &>(instance->Get<Leader>()).Populate(kNetworkData, sizeof(kNetworkData));
|
reinterpret_cast<TestLeader &>(instance->Get<Leader>()).Populate(kNetworkData, sizeof(kNetworkData));
|
||||||
|
|
||||||
@@ -756,7 +756,7 @@ void TestNetworkDataDsnSrpServices(void)
|
|||||||
printf("\nDNS/SRP Unicast Service entries (server data)\n");
|
printf("\nDNS/SRP Unicast Service entries (server data)\n");
|
||||||
|
|
||||||
iterator.Clear();
|
iterator.Clear();
|
||||||
type = Service::DnsSrpUnicast::kFromServerData;
|
type = Service::kAddrInServerData;
|
||||||
|
|
||||||
for (const UnicastEntry &entry : kUnicastEntriesFromServerData)
|
for (const UnicastEntry &entry : kUnicastEntriesFromServerData)
|
||||||
{
|
{
|
||||||
@@ -774,7 +774,7 @@ void TestNetworkDataDsnSrpServices(void)
|
|||||||
printf("\nDNS/SRP Unicast Service entries (service data)\n");
|
printf("\nDNS/SRP Unicast Service entries (service data)\n");
|
||||||
|
|
||||||
iterator.Clear();
|
iterator.Clear();
|
||||||
type = Service::DnsSrpUnicast::kFromServiceData;
|
type = Service::kAddrInServiceData;
|
||||||
|
|
||||||
for (const UnicastEntry &entry : kUnicastEntriesFromServiceData)
|
for (const UnicastEntry &entry : kUnicastEntriesFromServiceData)
|
||||||
{
|
{
|
||||||
@@ -947,8 +947,8 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
|
|||||||
|
|
||||||
for (const TestInfo &test : kTests)
|
for (const TestInfo &test : kTests)
|
||||||
{
|
{
|
||||||
Service::Manager::Iterator iterator;
|
Service::Manager::Iterator iterator;
|
||||||
Service::DnsSrpAnycast::Info anycastInfo;
|
Service::DnsSrpAnycastInfo anycastInfo;
|
||||||
|
|
||||||
reinterpret_cast<TestLeader &>(instance->Get<Leader>()).Populate(test.mNetworkData, test.mNetworkDataLength);
|
reinterpret_cast<TestLeader &>(instance->Get<Leader>()).Populate(test.mNetworkData, test.mNetworkDataLength);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user