[mesh-forwarder] update `LogMessage()` to include ECN from IPv6 header (#7562)

This commit adds a helper `Ip6::EncToString()` and updates logging of
messages in `MeshForwarder` to include the ECN field from IPv6
header.
This commit is contained in:
Abtin Keshavarzian 2022-04-07 13:09:05 -07:00 committed by GitHub
parent 5eb0537cf0
commit fe0258cbec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -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()),

View File

@ -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);