diff --git a/tests/nexus/platform/nexus_infra_if.cpp b/tests/nexus/platform/nexus_infra_if.cpp index 5f13f72e8..ea3c2dab1 100644 --- a/tests/nexus/platform/nexus_infra_if.cpp +++ b/tests/nexus/platform/nexus_infra_if.cpp @@ -293,21 +293,14 @@ void InfraIf::HandleRouterSolicitation(const Ip6::Address &aSrcAddress) } } -void InfraIf::SendIp6(const Ip6::Address &aSrcAddress, - const Ip6::Address &aDestAddress, - const uint8_t *aBuffer, - uint16_t aBufferLength) +void InfraIf::SendIp6(const Ip6::Header &aHeader, OwnedPtr aMessagePtr) { - Message *message = GetNode().Get().Allocate(Message::kTypeIp6); + VerifyOrQuit(aMessagePtr != nullptr); - VerifyOrQuit(message != nullptr); + Log("InfraIf::SendIp6 from %s to %s (len:%u)", aHeader.GetSource().ToString().AsCString(), + aHeader.GetDestination().ToString().AsCString(), aMessagePtr->GetLength()); - Log("InfraIf::SendIp6 from %s to %s (len:%u)", aSrcAddress.ToString().AsCString(), - aDestAddress.ToString().AsCString(), aBufferLength); - - SuccessOrQuit(message->AppendBytes(aBuffer, aBufferLength)); - - mPendingTxQueue.Enqueue(*message); + mPendingTxQueue.Enqueue(*aMessagePtr.Release()); } void InfraIf::SendEchoRequest(const Ip6::Address &aSrcAddress, diff --git a/tests/nexus/platform/nexus_infra_if.hpp b/tests/nexus/platform/nexus_infra_if.hpp index a05ce9185..5e620bdc4 100644 --- a/tests/nexus/platform/nexus_infra_if.hpp +++ b/tests/nexus/platform/nexus_infra_if.hpp @@ -64,10 +64,7 @@ public: const Ip6::Prefix *aRioPrefix); void StartRouterAdvertisement(const Ip6::Prefix &aPioPrefix, const Ip6::Prefix *aRioPrefix = nullptr); void StopRouterAdvertisement(void); - void SendIp6(const Ip6::Address &aSrcAddress, - const Ip6::Address &aDestAddress, - const uint8_t *aBuffer, - uint16_t aBufferLength); + void SendIp6(const Ip6::Header &aHeader, OwnedPtr aMessagePtr); void SendEchoRequest(const Ip6::Address &aSrcAddress, const Ip6::Address &aDestAddress, uint16_t aIdentifier, diff --git a/tests/nexus/platform/nexus_node.cpp b/tests/nexus/platform/nexus_node.cpp index a149c2443..1fe7a1451 100644 --- a/tests/nexus/platform/nexus_node.cpp +++ b/tests/nexus/platform/nexus_node.cpp @@ -142,46 +142,42 @@ void Node::SetName(const char *aPrefix, uint16_t aIndex) { mName.Clear().Append( void Node::HandleIp6Receive(otMessage *aMessage, void *aContext) { - static_cast(aContext)->HandleReceive(aMessage); + OwnedPtr messagePtr(AsCoreTypePtr(aMessage)); + + static_cast(aContext)->HandleIp6Receive(messagePtr.PassOwnership()); } -void Node::HandleReceive(otMessage *aMessage) +void Node::HandleIp6Receive(OwnedPtr aMessagePtr) { - uint16_t length = otMessageGetLength(aMessage); - uint8_t buffer[1500]; - Ip6::Header *header; + Ip6::Header header; - VerifyOrExit(length <= sizeof(buffer)); - VerifyOrQuit(otMessageRead(aMessage, 0, buffer, length) == length); - - VerifyOrExit(length >= sizeof(Ip6::Header)); - header = reinterpret_cast(buffer); + VerifyOrExit(aMessagePtr != nullptr); + SuccessOrExit(header.ParseFrom(*aMessagePtr)); // Forward packets to InfraIf if they are intended for the backbone. // We avoid forwarding link-local and realm-local scope packets. VerifyOrExit(mInfraIf.IsInitialized()); - VerifyOrExit(header->GetHopLimit() > 1); - header->SetHopLimit(header->GetHopLimit() - 1); + VerifyOrExit(header.GetHopLimit() > 1); + header.SetHopLimit(header.GetHopLimit() - 1); + aMessagePtr->Write(0, header); - VerifyOrExit(header->GetDestination().GetScope() > Ip6::Address::kRealmLocalScope); + VerifyOrExit(header.GetDestination().GetScope() > Ip6::Address::kRealmLocalScope); - if (header->GetDestination().IsMulticast()) + if (header.GetDestination().IsMulticast()) { VerifyOrExit(Get().IsPrimary()); } - VerifyOrExit(Get().IsOnMesh(header->GetSource())); + VerifyOrExit(!header.GetSource().IsLinkLocalUnicastOrMulticast()); + VerifyOrExit(!Get().IsMeshLocalAddress(header.GetSource())); + VerifyOrExit(Get().IsOnMesh(header.GetSource())); - // Only forward if source is NOT Link-Local and NOT Mesh-Local. - VerifyOrExit(!header->GetSource().IsLinkLocalUnicastOrMulticast()); - VerifyOrExit(!Get().IsMeshLocalAddress(header->GetSource())); - - mInfraIf.SendIp6(header->GetSource(), header->GetDestination(), buffer, length); + mInfraIf.SendIp6(header, aMessagePtr.PassOwnership()); exit: - otMessageFree(aMessage); + return; } #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE diff --git a/tests/nexus/platform/nexus_node.hpp b/tests/nexus/platform/nexus_node.hpp index cb3f0daac..2959150ba 100644 --- a/tests/nexus/platform/nexus_node.hpp +++ b/tests/nexus/platform/nexus_node.hpp @@ -135,7 +135,6 @@ public: static Node &From(otInstance *aInstance) { return static_cast(*aInstance); } static void HandleIp6Receive(otMessage *aMessage, void *aContext); - void HandleReceive(otMessage *aMessage); using Platform::mAlarmMicro; using Platform::mAlarmMilli; @@ -160,6 +159,8 @@ private: { } + void HandleIp6Receive(OwnedPtr aMessagePtr); + String<32> mName; };