mirror of
https://github.com/espressif/openthread.git
synced 2026-09-01 06:49:54 +00:00
[trel] ignore mDNS service removal for peer table update (#11692)
This commit modifies TREL to disregard mDNS (DNS-SD) service removal events when updating the peer table. Since mDNS peer removal signals can be unreliable, this change prevents such signals from causing a peer's removal. Instead, a peer entry is retained as long as TREL packets and acks are successfully exchanged, moving towards the goal of eliminating TREL's dependency on mDNS for peer discovery and tracking. This commit also introduces a new mechanism to track the last interaction time with each peer. This information is used to evict the least recently used entry when the peer table gets full and to remove inactive peers after a long expiration period (7.5 min) passes. The `test_trel` Nexus test is updated to validate these new behaviors.
This commit is contained in:
@@ -127,7 +127,7 @@ Error Interface::Send(Packet &aPacket, bool aIsDiscovery)
|
||||
Header::AckMode originalAckMode = aPacket.GetHeader().GetAckMode();
|
||||
Neighbor *neighbor;
|
||||
|
||||
if (!peer.IsStateValid())
|
||||
if (!peer.HasValidSockAddr())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -156,8 +156,10 @@ Error Interface::Send(Packet &aPacket, bool aIsDiscovery)
|
||||
case Header::kTypeUnicast:
|
||||
case Header::kTypeAck:
|
||||
peerEntry = Get<PeerTable>().FindMatching(aPacket.GetHeader().GetDestination());
|
||||
VerifyOrExit((peerEntry != nullptr) && peerEntry->IsStateValid(), error = kErrorAbort);
|
||||
otPlatTrelSend(&GetInstance(), aPacket.GetBuffer(), aPacket.GetLength(), &peerEntry->mSockAddr);
|
||||
VerifyOrExit(peerEntry != nullptr, error = kErrorAbort);
|
||||
VerifyOrExit(peerEntry->HasValidSockAddr(), error = kErrorAbort);
|
||||
peerEntry->UpdateLastInteractionTime();
|
||||
otPlatTrelSend(&GetInstance(), aPacket.GetBuffer(), aPacket.GetLength(), &peerEntry->GetSockAddr());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -347,6 +347,11 @@ void Link::ProcessReceivedPacket(Packet &aPacket, const Ip6::SockAddr &aSockAddr
|
||||
mRxPacketSenderAddr = aSockAddr;
|
||||
mRxPacketPeer = Get<PeerTable>().FindMatching(aPacket.GetHeader().GetSource());
|
||||
|
||||
if (mRxPacketPeer != nullptr)
|
||||
{
|
||||
mRxPacketPeer->UpdateLastInteractionTime();
|
||||
}
|
||||
|
||||
if (type != Header::kTypeBroadcast)
|
||||
{
|
||||
VerifyOrExit(aPacket.GetHeader().GetDestination() == Get<Mac::Mac>().GetExtAddress());
|
||||
|
||||
+109
-45
@@ -51,6 +51,7 @@ void Peer::Init(Instance &aInstance)
|
||||
AsCoreType(&mExtAddress).Clear();
|
||||
AsCoreType(&mExtPanId).Clear();
|
||||
AsCoreType(&mSockAddr).Clear();
|
||||
UpdateLastInteractionTime();
|
||||
|
||||
#if OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
mPort = 0;
|
||||
@@ -59,9 +60,9 @@ void Peer::Init(Instance &aInstance)
|
||||
mResolvingHost = false;
|
||||
mTxtDataValidated = false;
|
||||
mSockAddrUpdatedBasedOnRx = false;
|
||||
mState = kStateResolving;
|
||||
mDnssdState = kDnssdResolving;
|
||||
#else
|
||||
mState = kStateValid;
|
||||
mDnssdState = kDnssdResolved;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -79,6 +80,25 @@ void Peer::Free(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void Peer::SetDnssdState(DnssdState aState)
|
||||
{
|
||||
VerifyOrExit(mDnssdState != aState);
|
||||
|
||||
mDnssdState = aState;
|
||||
|
||||
if (mDnssdState == kDnssdRemoved)
|
||||
{
|
||||
uint32_t delay = DetermineExpirationDelay(Get<Uptime>().GetUptimeInSeconds());
|
||||
|
||||
Get<PeerTable>().mTimer.FireAtIfEarlier(TimerMilli::GetNow() + Time::SecToMsec(delay));
|
||||
|
||||
SignalPeerRemoval();
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Peer::UpdateSockAddrBasedOnRx(const Ip6::SockAddr &aSockAddr)
|
||||
{
|
||||
VerifyOrExit(GetSockAddr() != aSockAddr);
|
||||
@@ -93,23 +113,40 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Peer::ScheduleToRemoveAfter(uint32_t aDelay)
|
||||
void Peer::UpdateLastInteractionTime(void) { mLastInteractionTime = Get<Uptime>().GetUptimeInSeconds(); }
|
||||
|
||||
uint32_t Peer::DetermineSecondsSinceLastInteraction(void) const
|
||||
{
|
||||
VerifyOrExit(!IsStateRemoving());
|
||||
return Get<Uptime>().GetUptimeInSeconds() - mLastInteractionTime;
|
||||
}
|
||||
|
||||
mRemoveTime = TimerMilli::GetNow() + aDelay;
|
||||
uint32_t Peer::DetermineExpirationDelay(uint32_t aUptimeNow) const
|
||||
{
|
||||
// Determines the remaining expiration delay (in seconds) relative
|
||||
// to the current time of `aUptimeNow`.
|
||||
//
|
||||
// If the peer is in the `kDnssdRemoved` state, expiration is
|
||||
// calculated as `kExpirationDelay` seconds after
|
||||
// `mLastInteractionTime`. Returns the seconds remaining until
|
||||
// this expiration time or zero if already expired.
|
||||
//
|
||||
// If the peer is not in the `kDnssdRemoved` state, returns
|
||||
// `uint32_t` max value, indicating that the peer is not
|
||||
// considered as expired.
|
||||
|
||||
Log(kRemoving);
|
||||
LogInfo(" after %lu msec", ToUlong(aDelay));
|
||||
uint32_t delay = NumericLimits<uint32_t>::kMax;
|
||||
uint32_t expireTime;
|
||||
|
||||
SetState(kStateRemoving);
|
||||
VerifyOrExit(mDnssdState == kDnssdRemoved);
|
||||
|
||||
Get<PeerTable>().mTimer.FireAtIfEarlier(mRemoveTime);
|
||||
expireTime = mLastInteractionTime + kExpirationDelay;
|
||||
|
||||
SignalPeerRemoval();
|
||||
VerifyOrExit(expireTime > aUptimeNow, delay = 0);
|
||||
|
||||
delay = expireTime - aUptimeNow;
|
||||
|
||||
exit:
|
||||
return;
|
||||
return delay;
|
||||
}
|
||||
|
||||
void Peer::SetExtAddress(const Mac::ExtAddress &aExtAddress)
|
||||
@@ -154,6 +191,11 @@ exit:
|
||||
return matches;
|
||||
}
|
||||
|
||||
bool Peer::Matches(const ExpireChecker &aChecker) const
|
||||
{
|
||||
return (mDnssdState == kDnssdRemoved) && (aChecker.mUptimeNow >= mLastInteractionTime + kExpirationDelay);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
|
||||
void Peer::SignalPeerRemoval(void)
|
||||
@@ -194,26 +236,26 @@ bool Peer::NameMatch(const Heap::String &aHeapString, const char *aName)
|
||||
return !aHeapString.IsNull() && StringMatch(aHeapString.AsCString(), aName, kStringCaseInsensitiveMatch);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
|
||||
#if OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
|
||||
const char *Peer::StateToString(State aState)
|
||||
const char *Peer::DnssdStateToString(DnssdState aState)
|
||||
{
|
||||
static const char *const kStateStrings[] = {
|
||||
"valid", // (0) kStateValid
|
||||
"removing", // (1) kStateRemoving
|
||||
"resolving", // (2) kStateResolving
|
||||
"resolved", // (0) kDnssdResolved
|
||||
"removed", // (1) kDnssdRemoved
|
||||
"resolving", // (2) kDnssdResolving
|
||||
};
|
||||
|
||||
struct EnumCheck
|
||||
{
|
||||
InitEnumValidatorCounter();
|
||||
ValidateNextEnum(kStateValid);
|
||||
ValidateNextEnum(kStateRemoving);
|
||||
ValidateNextEnum(kStateResolving);
|
||||
ValidateNextEnum(kDnssdResolved);
|
||||
ValidateNextEnum(kDnssdRemoved);
|
||||
ValidateNextEnum(kDnssdResolving);
|
||||
};
|
||||
|
||||
return kStateStrings[aState];
|
||||
@@ -221,8 +263,8 @@ const char *Peer::StateToString(State aState)
|
||||
|
||||
void Peer::Log(Action aAction) const
|
||||
{
|
||||
LogInfo("%s peer %s, state:%s", ActionToString(aAction),
|
||||
mServiceName.IsNull() ? "(null)" : mServiceName.AsCString(), StateToString(mState));
|
||||
LogInfo("%s peer %s, dnssd-state:%s", ActionToString(aAction),
|
||||
mServiceName.IsNull() ? "(null)" : mServiceName.AsCString(), DnssdStateToString(mDnssdState));
|
||||
|
||||
if (!mHostName.IsNull())
|
||||
{
|
||||
@@ -263,9 +305,8 @@ const char *Peer::ActionToString(Action aAction)
|
||||
"Added", // (0) kAdded
|
||||
"Re-added", // (1) kReAdded,
|
||||
"Updated", // (2) kUpdated
|
||||
"Removing", // (3) kRemoving
|
||||
"Deleted", // (4) kDeleted
|
||||
"Evicting", // (5) kEvicting
|
||||
"Deleted", // (3) kDeleted
|
||||
"Evicting", // (4) kEvicting
|
||||
};
|
||||
|
||||
struct EnumCheck
|
||||
@@ -274,7 +315,6 @@ const char *Peer::ActionToString(Action aAction)
|
||||
ValidateNextEnum(kAdded);
|
||||
ValidateNextEnum(kReAdded);
|
||||
ValidateNextEnum(kUpdated);
|
||||
ValidateNextEnum(kRemoving);
|
||||
ValidateNextEnum(kDeleted);
|
||||
ValidateNextEnum(kEvicting);
|
||||
};
|
||||
@@ -357,22 +397,46 @@ Error PeerTable::EvictPeer(void)
|
||||
Error error = kErrorNotFound;
|
||||
OwnedPtr<Peer> peerToEvict;
|
||||
|
||||
// We first try to evict a peer already scheduled to be removed.
|
||||
// Then try to evict a peer belonging to a different PAN. If not
|
||||
// found, we evict a non-neighbor peer.
|
||||
|
||||
peerToEvict = RemoveMatching(Peer::kStateRemoving);
|
||||
|
||||
if (peerToEvict == nullptr)
|
||||
{
|
||||
peerToEvict = RemoveMatching(Peer::OtherExtPanIdMatcher(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
|
||||
}
|
||||
peerToEvict = RemoveMatching(Peer::OtherExtPanIdMatcher(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
|
||||
|
||||
if (peerToEvict == nullptr)
|
||||
{
|
||||
peerToEvict = RemoveMatching(Peer::NonNeighborMatcher(Get<NeighborTable>()));
|
||||
}
|
||||
|
||||
if (peerToEvict == nullptr)
|
||||
{
|
||||
// Find the peer in the 'kDnssdRemoved' state that has been
|
||||
// inactive (no send/receive interaction) for the longest duration.
|
||||
|
||||
uint32_t uptimeNow = Get<Uptime>().GetUptimeInSeconds();
|
||||
uint32_t longestInactiveTime = 0;
|
||||
const Peer *selectedPeer = nullptr;
|
||||
|
||||
for (const Peer &peer : *this)
|
||||
{
|
||||
uint32_t inactiveTime;
|
||||
|
||||
if (peer.GetDnssdState() != Peer::kDnssdRemoved)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inactiveTime = uptimeNow - peer.mLastInteractionTime;
|
||||
|
||||
if (inactiveTime > longestInactiveTime)
|
||||
{
|
||||
longestInactiveTime = inactiveTime;
|
||||
selectedPeer = &peer;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedPeer != nullptr)
|
||||
{
|
||||
peerToEvict = RemoveMatching(*selectedPeer);
|
||||
}
|
||||
}
|
||||
|
||||
VerifyOrExit(peerToEvict != nullptr);
|
||||
|
||||
peerToEvict->Log(Peer::kEvicting);
|
||||
@@ -384,20 +448,20 @@ exit:
|
||||
|
||||
void PeerTable::HandleTimer(void)
|
||||
{
|
||||
TimeMilli now = TimerMilli::GetNow();
|
||||
NextFireTime nextFireTime(now);
|
||||
uint32_t uptimeNow = Get<Uptime>().GetUptimeInSeconds();
|
||||
uint32_t delay = NumericLimits<uint32_t>::kMax;
|
||||
|
||||
RemoveAndFreeAllMatching(Peer::ExpireChecker(now));
|
||||
RemoveAndFreeAllMatching(Peer::ExpireChecker(uptimeNow));
|
||||
|
||||
for (const Peer &peer : *this)
|
||||
{
|
||||
if (peer.IsStateRemoving())
|
||||
{
|
||||
nextFireTime.UpdateIfEarlier(peer.mRemoveTime);
|
||||
}
|
||||
delay = Min(delay, peer.DetermineExpirationDelay(uptimeNow));
|
||||
}
|
||||
|
||||
mTimer.FireAtIfEarlier(nextFireTime);
|
||||
if (delay < NumericLimits<uint32_t>::kMax)
|
||||
{
|
||||
mTimer.Start(Time::SecToMsec(delay));
|
||||
}
|
||||
}
|
||||
|
||||
const Peer *PeerTable::GetNextPeer(PeerIterator &aIterator) const
|
||||
@@ -406,7 +470,7 @@ const Peer *PeerTable::GetNextPeer(PeerIterator &aIterator) const
|
||||
|
||||
VerifyOrExit(entry != nullptr);
|
||||
|
||||
while (!entry->IsStateValid())
|
||||
while (entry->GetDnssdState() == Peer::kDnssdResolving)
|
||||
{
|
||||
entry = entry->GetNext();
|
||||
VerifyOrExit(entry != nullptr);
|
||||
@@ -424,7 +488,7 @@ uint16_t PeerTable::GetNumberOfPeers(void) const
|
||||
|
||||
for (const Peer &peer : *this)
|
||||
{
|
||||
if (peer.IsStateValid())
|
||||
if (peer.GetDnssdState() != Peer::kDnssdResolving)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -87,12 +87,21 @@ class Peer : public InstanceLocatorInit,
|
||||
|
||||
public:
|
||||
/**
|
||||
* Indicates whether the `Peer` is in valid state.
|
||||
*
|
||||
* @returns TRUE If the `peer` is in valid state.
|
||||
* @returns FALSE If the `Peer` is not in valid state (e.g., still being resolved or scheduled for removal).
|
||||
* Represents the DNS-SD (mDNS) service discovery state of the peer.
|
||||
*/
|
||||
bool IsStateValid(void) const { return mState == kStateValid; }
|
||||
enum DnssdState : uint8_t
|
||||
{
|
||||
kDnssdResolved, ///< Peer is resolved on DNS-SD (mDNS), i.e., service and host resolution are done.
|
||||
kDnssdRemoved, ///< DNS-SD (mDNS) has notified that the peer service registration is removed or timed out.
|
||||
kDnssdResolving, ///< Ongoing service/host resolution for the peer service or host name.
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the current DNS-SD service discovery state of the peer.
|
||||
*
|
||||
* @returns The DNS-SD state.
|
||||
*/
|
||||
DnssdState GetDnssdState(void) const { return mDnssdState; }
|
||||
|
||||
/**
|
||||
* Returns the Extended MAC Address of the discovered TREL peer.
|
||||
@@ -115,6 +124,17 @@ public:
|
||||
*/
|
||||
const Ip6::SockAddr &GetSockAddr(void) const { return AsCoreType(&mSockAddr); }
|
||||
|
||||
/**
|
||||
* Indicates whether or not the IPv6 socket address associated with the TREL peer is valid.
|
||||
*
|
||||
* During peer discovery (mDNS service and host resolution), the peer address may not yet be known and can be
|
||||
* invalid (i.e., set to the unspecified IPv6 address `::`).
|
||||
*
|
||||
* @retval TRUE If the peer socket address is valid.
|
||||
* @retval FALSE If the peer socket address is not valid.
|
||||
*/
|
||||
bool HasValidSockAddr(void) const { return !GetSockAddr().GetAddress().IsUnspecified(); }
|
||||
|
||||
/**
|
||||
* Updates the IPv6 socket address of the discovered TREL peer based on a received message from peer.
|
||||
*
|
||||
@@ -122,6 +142,20 @@ public:
|
||||
*/
|
||||
void UpdateSockAddrBasedOnRx(const Ip6::SockAddr &aSockAddr);
|
||||
|
||||
/**
|
||||
* Updates the last interaction time (rx or tx) of the TREL peer to now.
|
||||
*
|
||||
* This is called after sending (unicast/ack TREL packet excluding a broadcast tx) or receiving from the peer.
|
||||
*/
|
||||
void UpdateLastInteractionTime(void);
|
||||
|
||||
/**
|
||||
* Determine number of seconds since last interaction with the TREL peer.
|
||||
*
|
||||
* @returns Duration (in seconds) since last interaction with the peer.
|
||||
*/
|
||||
uint32_t DetermineSecondsSinceLastInteraction(void) const;
|
||||
|
||||
#if OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
|
||||
/**
|
||||
@@ -150,19 +184,13 @@ public:
|
||||
#endif // OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
|
||||
private:
|
||||
enum State : uint8_t
|
||||
{
|
||||
kStateValid,
|
||||
kStateRemoving,
|
||||
kStateResolving,
|
||||
};
|
||||
static constexpr uint32_t kExpirationDelay = 450; // (in second) - 7.5 minutes
|
||||
|
||||
enum Action : uint8_t
|
||||
{
|
||||
kAdded, // Added a new peer.
|
||||
kReAdded, // Re-added a peer (discovered again) that was scheduled for removal.
|
||||
kReAdded, // Re-added a peer (discovered again) after DNSSD removal.
|
||||
kUpdated, // Updated an existing peer.
|
||||
kRemoving, // Scheduling a peer to be removed after delay.
|
||||
kDeleted, // Fully removing and deleting the peer from the table.
|
||||
kEvicting, // Evicting the peer to make space for new one.
|
||||
};
|
||||
@@ -187,14 +215,14 @@ private:
|
||||
NeighborTable &mNeighborTable;
|
||||
};
|
||||
|
||||
struct ExpireChecker // Matches if the peer is in `kStateRemoving` and already expired.
|
||||
struct ExpireChecker // Matches if the peer is in `kDnssdRemoved` and already expired.
|
||||
{
|
||||
explicit ExpireChecker(TimeMilli aNow)
|
||||
: mNow(aNow)
|
||||
explicit ExpireChecker(uint32_t aUptimeNow)
|
||||
: mUptimeNow(aUptimeNow)
|
||||
{
|
||||
}
|
||||
|
||||
TimeMilli mNow;
|
||||
uint32_t mUptimeNow;
|
||||
};
|
||||
|
||||
#if OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
@@ -227,22 +255,19 @@ private:
|
||||
|
||||
#endif
|
||||
|
||||
void Init(Instance &aInstance);
|
||||
void Free(void);
|
||||
void SetState(State aState) { mState = aState; }
|
||||
bool IsStateRemoving(void) const { return mState == kStateRemoving; }
|
||||
bool IsStateResolving(void) const { return mState == kStateResolving; }
|
||||
void SetExtAddress(const Mac::ExtAddress &aExtAddress);
|
||||
void SetExtPanId(const MeshCoP::ExtendedPanId &aExtPanId) { mExtPanId = aExtPanId; }
|
||||
void SetSockAddr(const Ip6::SockAddr &aSockAddr) { mSockAddr = aSockAddr; }
|
||||
void ScheduleToRemoveAfter(uint32_t aDelay);
|
||||
bool Matches(const Mac::ExtAddress &aExtAddress) const;
|
||||
bool Matches(const Ip6::SockAddr &aSockAddr) const { return GetSockAddr() == aSockAddr; }
|
||||
bool Matches(State aState) const { return mState == aState; }
|
||||
bool Matches(const Peer &aPeer) const { return this == &aPeer; }
|
||||
bool Matches(const OtherExtPanIdMatcher &aMatcher) const { return GetExtPanId() != aMatcher.mExtPanId; }
|
||||
bool Matches(const NonNeighborMatcher &aMatcher) const;
|
||||
bool Matches(const ExpireChecker &aChecker) const { return IsStateRemoving() && (aChecker.mNow >= mRemoveTime); }
|
||||
void Init(Instance &aInstance);
|
||||
void Free(void);
|
||||
void SetDnssdState(DnssdState aState);
|
||||
void SetExtAddress(const Mac::ExtAddress &aExtAddress);
|
||||
void SetExtPanId(const MeshCoP::ExtendedPanId &aExtPanId) { mExtPanId = aExtPanId; }
|
||||
void SetSockAddr(const Ip6::SockAddr &aSockAddr) { mSockAddr = aSockAddr; }
|
||||
bool Matches(const Mac::ExtAddress &aExtAddress) const;
|
||||
bool Matches(const Ip6::SockAddr &aSockAddr) const { return GetSockAddr() == aSockAddr; }
|
||||
bool Matches(const Peer &aPeer) const { return this == &aPeer; }
|
||||
bool Matches(const OtherExtPanIdMatcher &aMatcher) const { return GetExtPanId() != aMatcher.mExtPanId; }
|
||||
bool Matches(const NonNeighborMatcher &aMatcher) const;
|
||||
bool Matches(const ExpireChecker &aChecker) const;
|
||||
uint32_t DetermineExpirationDelay(uint32_t aUptimeNow) const;
|
||||
|
||||
#if OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
void SetPort(uint16_t aPort);
|
||||
@@ -258,14 +283,14 @@ private:
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
void Log(Action aAction) const;
|
||||
static const char *ActionToString(Action aAction);
|
||||
static const char *StateToString(State aState);
|
||||
static const char *DnssdStateToString(DnssdState aState);
|
||||
#else
|
||||
void Log(Action) const {}
|
||||
#endif
|
||||
|
||||
Peer *mNext;
|
||||
State mState;
|
||||
TimeMilli mRemoveTime;
|
||||
Peer *mNext;
|
||||
DnssdState mDnssdState;
|
||||
uint32_t mLastInteractionTime;
|
||||
#if OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
|
||||
bool mExtAddressSet : 1;
|
||||
bool mResolvingService : 1;
|
||||
|
||||
@@ -184,7 +184,8 @@ void PeerDiscoverer::HandleDiscoveredPeerInfo(const PeerInfo &aInfo)
|
||||
{
|
||||
peer = Get<PeerTable>().FindMatching(txtInfo.mExtAddress);
|
||||
VerifyOrExit(peer != nullptr);
|
||||
peer->ScheduleToRemoveAfter(kRemoveDelay);
|
||||
peer->SetDnssdState(Peer::kDnssdRemoved);
|
||||
peer->Log(Peer::kUpdated);
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
@@ -215,7 +216,7 @@ void PeerDiscoverer::HandleDiscoveredPeerInfo(const PeerInfo &aInfo)
|
||||
peer->SetExtAddress(txtInfo.mExtAddress);
|
||||
action = Peer::kAdded;
|
||||
}
|
||||
else if (!peer->IsStateValid())
|
||||
else if (peer->GetDnssdState() == Peer::kDnssdRemoved)
|
||||
{
|
||||
action = Peer::kReAdded;
|
||||
}
|
||||
@@ -225,7 +226,7 @@ void PeerDiscoverer::HandleDiscoveredPeerInfo(const PeerInfo &aInfo)
|
||||
action = Peer::kUpdated;
|
||||
}
|
||||
|
||||
peer->SetState(Peer::kStateValid);
|
||||
peer->SetDnssdState(Peer::kDnssdResolved);
|
||||
peer->SetExtPanId(txtInfo.mExtPanId);
|
||||
peer->SetSockAddr(aInfo.GetSockAddr());
|
||||
|
||||
@@ -341,7 +342,8 @@ void PeerDiscoverer::HandleBrowseResult(const Dnssd::BrowseResult &aResult)
|
||||
// Previously discovered service is now removed.
|
||||
|
||||
VerifyOrExit(peer != nullptr);
|
||||
peer->ScheduleToRemoveAfter(kRemoveDelay);
|
||||
peer->SetDnssdState(Peer::kDnssdRemoved);
|
||||
peer->Log(Peer::kUpdated);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -360,7 +362,7 @@ void PeerDiscoverer::HandleBrowseResult(const Dnssd::BrowseResult &aResult)
|
||||
action = Peer::kReAdded;
|
||||
}
|
||||
|
||||
peer->SetState(Peer::kStateResolving);
|
||||
peer->SetDnssdState(Peer::kDnssdResolving);
|
||||
peer->Log(action);
|
||||
|
||||
StartServiceResolvers(*peer);
|
||||
@@ -473,7 +475,7 @@ void PeerDiscoverer::ProcessPeerTxtData(const Dnssd::TxtResult &aResult, Peer &a
|
||||
if (txtInfo.mExtAddress == Get<Mac::Mac>().GetExtAddress())
|
||||
{
|
||||
LogInfo("Peer %s is this device itself", aPeer.mServiceName.AsCString());
|
||||
aPeer.ScheduleToRemoveAfter(0);
|
||||
Get<PeerTable>().RemoveMatching(aPeer);
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
@@ -608,7 +610,7 @@ void PeerDiscoverer::HandleAddressResult(const Dnssd::AddressResult &aResult)
|
||||
|
||||
for (Peer &peer : Get<PeerTable>())
|
||||
{
|
||||
if (peer.IsStateRemoving())
|
||||
if (peer.GetDnssdState() == Peer::kDnssdRemoved)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -696,13 +698,13 @@ exit:
|
||||
|
||||
void PeerDiscoverer::UpdatePeerState(Peer &aPeer)
|
||||
{
|
||||
VerifyOrExit(aPeer.IsStateResolving());
|
||||
VerifyOrExit(aPeer.GetDnssdState() == Peer::kDnssdResolving);
|
||||
VerifyOrExit(aPeer.mResolvingService && aPeer.mResolvingHost);
|
||||
VerifyOrExit(aPeer.mTxtDataValidated);
|
||||
VerifyOrExit(aPeer.mPort != 0);
|
||||
VerifyOrExit(aPeer.mHostAddresses.GetLength() > 0);
|
||||
|
||||
aPeer.SetState(Peer::kStateValid);
|
||||
aPeer.SetDnssdState(Peer::kDnssdResolved);
|
||||
aPeer.Log(Peer::kUpdated);
|
||||
|
||||
exit:
|
||||
|
||||
@@ -119,8 +119,6 @@ public:
|
||||
#endif
|
||||
|
||||
private:
|
||||
static constexpr uint32_t kRemoveDelay = 7 * Time::kOneSecondInMsec;
|
||||
|
||||
enum State : uint8_t
|
||||
{
|
||||
kStateStopped, // Stopped.
|
||||
|
||||
+54
-19
@@ -41,6 +41,10 @@ namespace Nexus {
|
||||
static constexpr uint32_t kInfraIfIndex = 1;
|
||||
static constexpr uint16_t kMaxTxtDataSize = 128;
|
||||
|
||||
static constexpr ot::Trel::Peer::DnssdState kDnssdResolved = ot::Trel::Peer::kDnssdResolved;
|
||||
static constexpr ot::Trel::Peer::DnssdState kDnssdRemoved = ot::Trel::Peer::kDnssdRemoved;
|
||||
static constexpr ot::Trel::Peer::DnssdState kDnssdResolving = ot::Trel::Peer::kDnssdResolving;
|
||||
|
||||
void TestTrelBasic(void)
|
||||
{
|
||||
// Validate basic operations, forming a network and
|
||||
@@ -120,7 +124,7 @@ void TestTrelBasic(void)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
VerifyOrQuit(peer.IsStateValid());
|
||||
VerifyOrQuit(peer.GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
|
||||
VerifyOrQuit(peer.GetExtPanId() == node.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
|
||||
for (Node &otherNode : nexus.GetNodes())
|
||||
@@ -169,6 +173,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
|
||||
Node &node1 = nexus.CreateNode();
|
||||
Node &node2 = nexus.CreateNode();
|
||||
const ot::Trel::Peer *peer;
|
||||
uint32_t inactiveDuration;
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("TestTrelDelayedMdnsStartAndPeerRemovalDelay()");
|
||||
@@ -213,7 +218,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(peer->IsStateValid());
|
||||
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
|
||||
VerifyOrQuit(peer->GetServiceName() != nullptr);
|
||||
@@ -231,7 +236,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
|
||||
peer = node2.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(peer->IsStateValid());
|
||||
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node1.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node1.Get<Mac::Mac>().GetExtAddress());
|
||||
VerifyOrQuit(peer->GetServiceName() != nullptr);
|
||||
@@ -255,11 +260,10 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Log("Validate that `PeerTable` is properly updated on `node1`");
|
||||
|
||||
// Check peer on `node1` is still present but not longer `IsStateValid()`.
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(!peer->IsStateValid());
|
||||
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdRemoved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
|
||||
VerifyOrQuit(peer->GetServiceName() != nullptr);
|
||||
@@ -284,7 +288,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(peer->IsStateValid());
|
||||
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
|
||||
VerifyOrQuit(peer->GetServiceName() != nullptr);
|
||||
@@ -302,7 +306,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
|
||||
peer = node2.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(peer->IsStateValid());
|
||||
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node1.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node1.Get<Mac::Mac>().GetExtAddress());
|
||||
VerifyOrQuit(peer->GetServiceName() != nullptr);
|
||||
@@ -315,17 +319,48 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
|
||||
VerifyOrQuit(peer->GetHostAddresses().GetLength() == 1);
|
||||
VerifyOrQuit(peer->GetHostAddresses()[0] == node1.mMdns.mIfAddresses[0]);
|
||||
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
inactiveDuration = peer->DetermineSecondsSinceLastInteraction();
|
||||
VerifyOrQuit(inactiveDuration > 0);
|
||||
Log("- peer has been inactive for %lu seconds", ToUlong(inactiveDuration));
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Log("Disable TREL Interface (and `PeerDiscoverer`) on `node2` again");
|
||||
Log("Disable TREL Interface (and `PeerDiscoverer`) on `node2` again and signal its removal on mDNS");
|
||||
|
||||
node2.Get<ot::Trel::Interface>().Disable();
|
||||
VerifyOrQuit(node2.Get<ot::Trel::PeerTable>().IsEmpty());
|
||||
|
||||
Log("Wait for long enough for the `node2` peer to be fully deleted on `node1`");
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Log("Check that peer entry for `node2` is properly switched to `kDnssdRemoved` state");
|
||||
|
||||
nexus.AdvanceTime(15 * 1000);
|
||||
nexus.AdvanceTime(10 * 1000 + 500);
|
||||
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdRemoved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
|
||||
VerifyOrQuit(peer->GetSockAddr().GetAddress() == node2.mMdns.mIfAddresses[0]);
|
||||
|
||||
Log("Validate the `DetermineSecondsSinceLastInteraction()` is properly tracked");
|
||||
|
||||
VerifyOrQuit(peer->DetermineSecondsSinceLastInteraction() - inactiveDuration >= 10);
|
||||
|
||||
inactiveDuration = peer->DetermineSecondsSinceLastInteraction();
|
||||
VerifyOrQuit(inactiveDuration > 0);
|
||||
Log("- peer has been inactive for %lu seconds", ToUlong(inactiveDuration));
|
||||
|
||||
Log("Validate that peer is deleted from list after 450 second inactivity");
|
||||
|
||||
nexus.AdvanceTime((451 - inactiveDuration) * 1000);
|
||||
|
||||
VerifyOrQuit(node1.Get<ot::Trel::PeerTable>().IsEmpty());
|
||||
VerifyOrQuit(node2.Get<ot::Trel::PeerTable>().IsEmpty());
|
||||
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer == nullptr);
|
||||
}
|
||||
|
||||
void TestServiceNameConflict(void)
|
||||
@@ -395,7 +430,7 @@ void TestServiceNameConflict(void)
|
||||
|
||||
for (const ot::Trel::Peer &peer : node2.Get<ot::Trel::PeerTable>())
|
||||
{
|
||||
if (peer.IsStateValid())
|
||||
if (peer.GetDnssdState() == ot::Trel::Peer::kDnssdResolved)
|
||||
{
|
||||
VerifyOrQuit(peer.GetExtPanId() == node1.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer.GetExtAddress() == node1.Get<Mac::Mac>().GetExtAddress());
|
||||
@@ -470,7 +505,7 @@ void TestHostAddressChange(void)
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(peer->IsStateValid());
|
||||
VerifyOrQuit(peer->GetDnssdState() == kDnssdResolved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
|
||||
|
||||
@@ -511,7 +546,7 @@ void TestHostAddressChange(void)
|
||||
peer = node1.Get<ot::Trel::PeerTable>().GetHead();
|
||||
VerifyOrQuit(peer != nullptr);
|
||||
|
||||
VerifyOrQuit(peer->IsStateValid());
|
||||
VerifyOrQuit(peer->GetDnssdState() == kDnssdResolved);
|
||||
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
|
||||
|
||||
@@ -645,7 +680,7 @@ void TestMultiServiceSameHost(void)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
VerifyOrQuit(peer.IsStateValid());
|
||||
VerifyOrQuit(peer.GetDnssdState() == kDnssdResolved);
|
||||
VerifyOrQuit(peer.GetServiceName() != nullptr);
|
||||
VerifyOrQuit(peer.GetHostName() != nullptr);
|
||||
VerifyOrQuit(StringStartsWith(peer.GetHostName(), "ot"));
|
||||
@@ -677,13 +712,13 @@ void TestMultiServiceSameHost(void)
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Log("Validate peer table on `node`");
|
||||
|
||||
VerifyOrQuit(node.Get<ot::Trel::PeerTable>().GetNumberOfPeers() == 2);
|
||||
VerifyOrQuit(node.Get<ot::Trel::PeerTable>().GetNumberOfPeers() == 3);
|
||||
|
||||
for (const ot::Trel::Peer &peer : node.Get<ot::Trel::PeerTable>())
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
if (!peer.IsStateValid())
|
||||
if (peer.GetDnssdState() != kDnssdResolved)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -722,13 +757,13 @@ void TestMultiServiceSameHost(void)
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Log("Validate all peers get the updated list");
|
||||
|
||||
VerifyOrQuit(node.Get<ot::Trel::PeerTable>().GetNumberOfPeers() == 2);
|
||||
VerifyOrQuit(node.Get<ot::Trel::PeerTable>().GetNumberOfPeers() == 3);
|
||||
|
||||
for (const ot::Trel::Peer &peer : node.Get<ot::Trel::PeerTable>())
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
if (!peer.IsStateValid())
|
||||
if (peer.GetDnssdState() != kDnssdResolved)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user