Skip to content

Commit 9a511de

Browse files
committed
[MRP] Log target retransmission time for a given session/exchange
1 parent 2396bb4 commit 9a511de

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

src/messaging/ReliableMessageMgr.cpp

+50-13
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,18 @@ void ReliableMessageMgr::ExecuteActions()
129129

130130
VerifyOrDie(!entry->retainedBuf.IsNull());
131131

132+
// Don't check whether the session in the exchange is valid, because when the session is released, the retrans entry is
133+
// cleared inside ExchangeContext::OnSessionReleased, so the session must be valid if the entry exists.
134+
auto session = entry->ec->GetSessionHandle();
132135
uint8_t sendCount = entry->sendCount;
133-
#if CHIP_ERROR_LOGGING || CHIP_DETAIL_LOGGING
136+
#if CHIP_ERROR_LOGGING || CHIP_PROGRESS_LOGGING
134137
uint32_t messageCounter = entry->retainedBuf.GetMessageCounter();
138+
auto fabricIndex = session->GetFabricIndex();
139+
auto destination = kUndefinedNodeId;
140+
if (session->IsSecureSession())
141+
{
142+
destination = session->AsSecureSession()->GetPeerNodeId();
143+
}
135144
#endif // CHIP_ERROR_LOGGING || CHIP_DETAIL_LOGGING
136145

137146
if (sendCount == CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS)
@@ -140,13 +149,11 @@ void ReliableMessageMgr::ExecuteActions()
140149
ExchangeHandle ec(entry->ec);
141150

142151
ChipLogError(ExchangeManager,
143-
"Failed to Send CHIP MessageCounter:" ChipLogFormatMessageCounter " on exchange " ChipLogFormatExchange
144-
" sendCount: %u max retries: %d",
145-
messageCounter, ChipLogValueExchange(&ec.Get()), sendCount, CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS);
146-
147-
// Don't check whether the session in the exchange is valid, because when the session is released, the retrans entry is
148-
// cleared inside ExchangeContext::OnSessionReleased, so the session must be valid if the entry exists.
149-
SessionHandle session = ec->GetSessionHandle();
152+
"<<%d [E:" ChipLogFormatExchange " S:%u M:" ChipLogFormatMessageCounter
153+
"] (%s) Msg Retransmission to %u:" ChipLogFormatX64 " failure (max retries:%d)",
154+
sendCount + 1, ChipLogValueExchange(&entry->ec.Get()), session->SessionIdForLogging(), messageCounter,
155+
Transport::GetSessionTypeString(session), fabricIndex, ChipLogValueX64(destination),
156+
CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS);
150157

151158
// If the exchange is expecting a response, it will handle sending
152159
// this notification once it detects that it has not gotten a
@@ -167,10 +174,12 @@ void ReliableMessageMgr::ExecuteActions()
167174
}
168175

169176
entry->sendCount++;
177+
170178
ChipLogProgress(ExchangeManager,
171-
"Retransmitting MessageCounter:" ChipLogFormatMessageCounter " on exchange " ChipLogFormatExchange
172-
" Send Cnt %d",
173-
messageCounter, ChipLogValueExchange(&entry->ec.Get()), entry->sendCount);
179+
"<<%d [E:" ChipLogFormatExchange " S:%u M:" ChipLogFormatMessageCounter
180+
"] (%s) Msg Retransmission to %u:" ChipLogFormatX64,
181+
entry->sendCount, ChipLogValueExchange(&entry->ec.Get()), session->SessionIdForLogging(), messageCounter,
182+
Transport::GetSessionTypeString(session), fabricIndex, ChipLogValueX64(destination));
174183
MATTER_LOG_METRIC(Tracing::kMetricDeviceRMPRetryCount, entry->sendCount);
175184

176185
CalculateNextRetransTime(*entry);
@@ -467,22 +476,50 @@ void ReliableMessageMgr::SetAdditionalMRPBackoffTime(const Optional<System::Cloc
467476
void ReliableMessageMgr::CalculateNextRetransTime(RetransTableEntry & entry)
468477
{
469478
System::Clock::Timeout baseTimeout = System::Clock::Timeout(0);
479+
const auto sessionHandle = entry.ec->GetSessionHandle();
470480

471481
// Check if we have received at least one application-level message
472482
if (entry.ec->HasReceivedAtLeastOneMessage())
473483
{
474484
// If we have received at least one message, assume peer is active and use ActiveRetransTimeout
475-
baseTimeout = entry.ec->GetSessionHandle()->GetRemoteMRPConfig().mActiveRetransTimeout;
485+
baseTimeout = sessionHandle->GetRemoteMRPConfig().mActiveRetransTimeout;
476486
}
477487
else
478488
{
479489
// If we haven't received at least one message
480490
// Choose active/idle timeout from PeerActiveMode of session per 4.11.2.1. Retransmissions.
481-
baseTimeout = entry.ec->GetSessionHandle()->GetMRPBaseTimeout();
491+
baseTimeout = sessionHandle->GetMRPBaseTimeout();
482492
}
483493

484494
System::Clock::Timeout backoff = ReliableMessageMgr::GetBackoff(baseTimeout, entry.sendCount);
485495
entry.nextRetransTime = System::SystemClock().GetMonotonicTimestamp() + backoff;
496+
497+
#if CHIP_PROGRESS_LOGGING
498+
const auto config = sessionHandle->GetRemoteMRPConfig();
499+
uint32_t messageCounter = entry.retainedBuf.GetMessageCounter();
500+
auto fabricIndex = sessionHandle->GetFabricIndex();
501+
auto destination = kUndefinedNodeId;
502+
bool peerIsActive = false;
503+
504+
if (sessionHandle->IsSecureSession())
505+
{
506+
peerIsActive = sessionHandle->AsSecureSession()->IsPeerActive();
507+
destination = sessionHandle->AsSecureSession()->GetPeerNodeId();
508+
}
509+
else if (sessionHandle->IsUnauthenticatedSession())
510+
{
511+
peerIsActive = sessionHandle->AsUnauthenticatedSession()->IsPeerActive();
512+
}
513+
514+
ChipLogProgress(ExchangeManager,
515+
"??%d [E:" ChipLogFormatExchange " S:%u M:" ChipLogFormatMessageCounter
516+
"] (%s) Msg Retransmission to %u:" ChipLogFormatX64 " in %" PRIu16 "ms [State:%s II:%" PRIu32 " AI:%" PRIu32
517+
" AT:%" PRIu16 "]",
518+
entry.sendCount + 1, ChipLogValueExchange(&entry.ec.Get()), sessionHandle->SessionIdForLogging(),
519+
messageCounter, Transport::GetSessionTypeString(sessionHandle), fabricIndex, ChipLogValueX64(destination),
520+
backoff.count(), peerIsActive ? "Active" : "Idle", config.mIdleRetransTimeout.count(),
521+
config.mActiveRetransTimeout.count(), config.mActiveThresholdTime.count());
522+
#endif // CHIP_PROGRESS_LOGGING
486523
}
487524

488525
#if CHIP_CONFIG_TEST

0 commit comments

Comments
 (0)