diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 35bfea80a..3f5ec0de3 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1490,6 +1490,23 @@ const char *Ip6::IpProtoToString(uint8_t aIpProto) return Stringify::Lookup(aIpProto, kIpProtoTable, "Unknown"); } +const char *Ip6::EcnToString(Ecn aEcn) +{ + static const char *const kEcnStrings[] = { + "no", // (0) kEcnNotCapable + "e1", // (1) kEcnCapable1 (ECT1) + "e0", // (2) kEcnCapable0 (ECT0) + "ce", // (3) kEcnMarked (Congestion Encountered) + }; + + static_assert(0 == kEcnNotCapable, "kEcnNotCapable value is incorrect"); + static_assert(1 == kEcnCapable1, "kEcnCapable1 value is incorrect"); + static_assert(2 == kEcnCapable0, "kEcnCapable0 value is incorrect"); + static_assert(3 == kEcnMarked, "kEcnMarked value is incorrect"); + + return kEcnStrings[aEcn]; +} + // LCOV_EXCL_STOP } // namespace Ip6 diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 950460922..0855e1327 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -43,6 +43,7 @@ #include "common/encoding.hpp" #include "common/locator.hpp" +#include "common/log.hpp" #include "common/message.hpp" #include "common/non_copyable.hpp" #include "common/time_ticker.hpp" @@ -297,6 +298,16 @@ public: */ static const char *IpProtoToString(uint8_t aIpProto); + /** + * This static method converts an IP header ECN value to a string. + * + * @param[in] aEcn The 2-bit ECN value. + * + * @returns The string representation of @p aEcn. + * + */ + static const char *EcnToString(Ecn aEcn); + private: static constexpr uint8_t kDefaultHopLimit = OPENTHREAD_CONFIG_IP6_HOP_LIMIT_DEFAULT; static constexpr uint8_t kIp6ReassemblyTimeout = OPENTHREAD_CONFIG_IP6_REASSEMBLY_TIMEOUT; diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index efc36516e..4567afdbb 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -1786,9 +1786,9 @@ void MeshForwarder::LogIp6Message(MessageAction aAction, radioString = aMessage.IsRadioTypeSet() ? RadioTypeToString(aMessage.GetRadioType()) : "all"; #endif - LogAt(aLogLevel, "%s IPv6 %s msg, len:%d, chksum:%04x%s%s, sec:%s%s%s, prio:%s%s%s%s%s", + LogAt(aLogLevel, "%s IPv6 %s msg, len:%d, chksum:%04x, ecn:%s%s%s, sec:%s%s%s, prio:%s%s%s%s%s", MessageActionToString(aAction, aError), Ip6::Ip6::IpProtoToString(ip6Header.GetNextHeader()), - aMessage.GetLength(), checksum, + aMessage.GetLength(), checksum, Ip6::Ip6::EcnToString(ip6Header.GetEcn()), (aMacAddress == nullptr) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"), (aMacAddress == nullptr) ? "" : aMacAddress->ToString().AsCString(), ToYesNo(aMessage.IsLinkSecurityEnabled()), diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index fb3df525e..dcc25e90a 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -1162,8 +1162,9 @@ void MeshForwarder::LogMeshIpHeader(const Message & aMessage, SuccessOrExit(DecompressIp6UdpTcpHeader(aMessage, aOffset, aMeshSource, aMeshDest, ip6Header, checksum, sourcePort, destPort)); - LogAt(aLogLevel, " IPv6 %s msg, chksum:%04x, prio:%s", Ip6::Ip6::IpProtoToString(ip6Header.GetNextHeader()), - checksum, MessagePriorityToString(aMessage)); + LogAt(aLogLevel, " IPv6 %s msg, chksum:%04x, ecn:%s, prio:%s", + Ip6::Ip6::IpProtoToString(ip6Header.GetNextHeader()), checksum, Ip6::Ip6::EcnToString(ip6Header.GetEcn()), + MessagePriorityToString(aMessage)); LogIp6SourceDestAddresses(ip6Header, sourcePort, destPort, aLogLevel);