diff --git a/tests/nexus/platform/nexus_core.cpp b/tests/nexus/platform/nexus_core.cpp index f5de1e2df..99d5fbb3d 100644 --- a/tests/nexus/platform/nexus_core.cpp +++ b/tests/nexus/platform/nexus_core.cpp @@ -667,48 +667,22 @@ void Core::ProcessInfraIf(Node &aNode) Node *Core::FindNodeByAddress(const Ip6::Address &aAddress) { - Node *matchedNode = FindNodeByThreadAddress(aAddress); - - if (matchedNode == nullptr) - { - matchedNode = FindNodeByInfraIfAddress(aAddress); - } - - return matchedNode; + return mNodes.FindMatching(aAddress, Node::kAnyNetifAddress); } -bool Core::IsThreadAddress(const Ip6::Address &aAddress) { return FindNodeByThreadAddress(aAddress) != nullptr; } +bool Core::IsThreadAddress(const Ip6::Address &aAddress) +{ + return mNodes.ContainsMatching(aAddress, Node::kThreadNetifAddress); +} Node *Core::FindNodeByThreadAddress(const Ip6::Address &aAddress) { - Node *matchedNode = nullptr; - - for (Node &node : mNodes) - { - if (node.Get().HasUnicastAddress(aAddress)) - { - matchedNode = &node; - break; - } - } - - return matchedNode; + return mNodes.FindMatching(aAddress, Node::kThreadNetifAddress); } Node *Core::FindNodeByInfraIfAddress(const Ip6::Address &aAddress) { - Node *matchedNode = nullptr; - - for (Node &node : mNodes) - { - if (node.mInfraIf.HasAddress(aAddress)) - { - matchedNode = &node; - break; - } - } - - return matchedNode; + return mNodes.FindMatching(aAddress, Node::kInfraNetifAddress); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/tests/nexus/platform/nexus_node.cpp b/tests/nexus/platform/nexus_node.cpp index 1fe7a1451..a4eb8fa1f 100644 --- a/tests/nexus/platform/nexus_node.cpp +++ b/tests/nexus/platform/nexus_node.cpp @@ -229,5 +229,27 @@ const Ip6::Address &Node::FindGlobalAddress(void) return *matchedAddress; } +bool Node::Matches(const Ip6::Address &aAddress, AddressNetif aNetif) const +{ + bool matches = false; + + switch (aNetif) + { + case kThreadNetifAddress: + matches = Get().HasUnicastAddress(aAddress); + break; + + case kInfraNetifAddress: + matches = mInfraIf.HasAddress(aAddress); + break; + + case kAnyNetifAddress: + matches = Get().HasUnicastAddress(aAddress) || mInfraIf.HasAddress(aAddress); + break; + } + + return matches; +} + } // namespace Nexus } // namespace ot diff --git a/tests/nexus/platform/nexus_node.hpp b/tests/nexus/platform/nexus_node.hpp index 2959150ba..4b8b25ad3 100644 --- a/tests/nexus/platform/nexus_node.hpp +++ b/tests/nexus/platform/nexus_node.hpp @@ -120,13 +120,23 @@ public: */ const Ip6::Address &FindGlobalAddress(void); + enum AddressNetif : uint8_t + { + kThreadNetifAddress, + kInfraNetifAddress, + kAnyNetifAddress, + }; + + bool Matches(const Ip6::Address &aAddress, AddressNetif aNetif) const; + void SetName(const char *aName) { mName.Clear().Append("%s", aName); } void SetName(const char *aPrefix, uint16_t aIndex); const char *GetName(void) const { return mName.AsCString(); } //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template Type &Get(void) { return Instance::Get(); } + template Type &Get(void) { return Instance::Get(); } + template const Type &Get(void) const { return AsConst(AsNonConst(this)->Get()); } Instance &GetInstance(void) { return *this; }