Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding MRP analytics delegate #37439

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/messaging/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static_library("messaging") {
"ExchangeMgr.cpp",
"ExchangeMgr.h",
"Flags.h",
"ReliableMessageAnalyticsDelegate.h",
"ReliableMessageContext.cpp",
"ReliableMessageContext.h",
"ReliableMessageMgr.cpp",
Expand Down
56 changes: 56 additions & 0 deletions src/messaging/ReliableMessageAnalyticsDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file defines interface for objects interested in MRP events for analytics
*/

#pragma once

#include <lib/core/DataModelTypes.h>
#include <lib/core/NodeId.h>

namespace chip {
namespace Messaging {

class ReliableMessageAnalyticsDelegate
{
public:
virtual ~ReliableMessageAnalyticsDelegate() = default;
enum class EventType
{
kInitialSend,
kRetransmission,
kAcknowledged,
kFailed,
kUndefined, /* Should be last element in enum */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be the first element 🤷

};

struct TransmitEvent
{
NodeId nodeId = kUndefinedNodeId;
FabricIndex fabricIndex = kUndefinedFabricIndex;
EventType eventType = EventType::kUndefined;
uint32_t messageCounter = 0;
};

virtual void OnTransmitEvent(const TransmitEvent & event) = 0;
};

} // namespace Messaging
} // namespace chip
51 changes: 51 additions & 0 deletions src/messaging/ReliableMessageMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ void ReliableMessageMgr::ExecuteActions()
Transport::GetSessionTypeString(session), fabricIndex, ChipLogValueX64(destination),
CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS);

if (mAnalyticsDelegate)
{
ReliableMessageAnalyticsDelegate::TransmitEvent event = { .nodeId = destination,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO needs to move outside of CHIP_PROGRESS_LOGGING

.fabricIndex = fabricIndex,
.eventType =
ReliableMessageAnalyticsDelegate::EventType::kFailed,
.messageCounter = messageCounter };

mAnalyticsDelegate->OnTransmitEvent(event);
}

// If the exchange is expecting a response, it will handle sending
// this notification once it detects that it has not gotten a
// response. Otherwise, we need to do it.
Expand Down Expand Up @@ -295,6 +306,25 @@ bool ReliableMessageMgr::CheckAndRemRetransTable(ReliableMessageContext * rc, ui
mRetransTable.ForEachActiveObject([&](auto * entry) {
if (entry->ec->GetReliableMessageContext() == rc && entry->retainedBuf.GetMessageCounter() == ackMessageCounter)
{
if (mAnalyticsDelegate)
{
auto session = entry->ec->GetSessionHandle();
auto fabricIndex = session->GetFabricIndex();
auto destination = kUndefinedNodeId;
if (session->IsSecureSession())
{
destination = session->AsSecureSession()->GetPeerNodeId();
}
ReliableMessageAnalyticsDelegate::TransmitEvent event = {
.nodeId = destination,
.fabricIndex = fabricIndex,
.eventType = ReliableMessageAnalyticsDelegate::EventType::kAcknowledged,
.messageCounter = ackMessageCounter
};

mAnalyticsDelegate->OnTransmitEvent(event);
}

// Clear the entry from the retransmision table.
ClearRetransTable(*entry);

Expand Down Expand Up @@ -440,6 +470,11 @@ void ReliableMessageMgr::RegisterSessionUpdateDelegate(SessionUpdateDelegate * s
mSessionUpdateDelegate = sessionUpdateDelegate;
}

void ReliableMessageMgr::RegisterAnalyticsDelegate(ReliableMessageAnalyticsDelegate * analyticsDelegate)
{
mAnalyticsDelegate = analyticsDelegate;
}

CHIP_ERROR ReliableMessageMgr::MapSendError(CHIP_ERROR error, uint16_t exchangeId, bool isInitiator)
{
if (
Expand Down Expand Up @@ -511,6 +546,22 @@ void ReliableMessageMgr::CalculateNextRetransTime(RetransTableEntry & entry)
peerIsActive = sessionHandle->AsUnauthenticatedSession()->IsPeerActive();
}

// For initial send the packet has already been submitted to transport layer successfully.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do people feel about the location of this and how re-transmission has technically not taken place yet

// On re-transmits we do not know if transport layer is unable to retransmit for some
// reason, so saying we have sent re-transmit here is a little presumptuous.
if (mAnalyticsDelegate)
{
ReliableMessageAnalyticsDelegate::TransmitEvent event = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO needs to move outside of CHIP_PROGRESS_LOGGING

.nodeId = destination,
.fabricIndex = fabricIndex,
.eventType = entry.sendCount == 0 ? ReliableMessageAnalyticsDelegate::EventType::kInitialSend
: ReliableMessageAnalyticsDelegate::EventType::kRetransmission,
.messageCounter = messageCounter
};

mAnalyticsDelegate->OnTransmitEvent(event);
}

ChipLogProgress(ExchangeManager,
"??%d [E:" ChipLogFormatExchange " S:%u M:" ChipLogFormatMessageCounter
"] (%s) Msg Retransmission to %u:" ChipLogFormatX64 " in %" PRIu32 "ms [State:%s II:%" PRIu32 " AI:%" PRIu32
Expand Down
9 changes: 9 additions & 0 deletions src/messaging/ReliableMessageMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <lib/support/BitFlags.h>
#include <lib/support/Pool.h>
#include <messaging/ExchangeContext.h>
#include <messaging/ReliableMessageAnalyticsDelegate.h>
#include <messaging/ReliableMessageProtocolConfig.h>
#include <system/SystemLayer.h>
#include <system/SystemPacketBuffer.h>
Expand Down Expand Up @@ -185,6 +186,13 @@ class ReliableMessageMgr
*/
void RegisterSessionUpdateDelegate(SessionUpdateDelegate * sessionUpdateDelegate);

/**
* Registers a delegate interested in analytic information
*
* @param[in] analyticsDelegate - Pointer to delegate for reporting analytic
*/
void RegisterAnalyticsDelegate(ReliableMessageAnalyticsDelegate * analyticsDelegate);

/**
* Map a send error code to the error code we should actually use for
* success checks. This maps some error codes to CHIP_NO_ERROR as
Expand Down Expand Up @@ -249,6 +257,7 @@ class ReliableMessageMgr
ObjectPool<RetransTableEntry, CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE> mRetransTable;

SessionUpdateDelegate * mSessionUpdateDelegate = nullptr;
ReliableMessageAnalyticsDelegate * mAnalyticsDelegate = nullptr;

static System::Clock::Timeout sAdditionalMRPBackoffTime;
};
Expand Down
Loading
Loading