Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
35057e8
Start of IM and cluster changes
zaid-google Nov 14, 2025
ad97e98
Add session manager unit test
zaid-google Dec 2, 2025
ed31119
Restyled by whitespace
restyled-commits Dec 2, 2025
9773474
Restyled by clang-format
restyled-commits Dec 2, 2025
3505bc0
Address comments from review
zaid-google Dec 2, 2025
af3828b
Restyled by whitespace
restyled-commits Dec 2, 2025
dc2e76d
Restyled by clang-format
restyled-commits Dec 2, 2025
858a85b
Add failure message
zaid-google Dec 2, 2025
5f77101
Restyled by clang-format
restyled-commits Dec 2, 2025
3498550
Merge branch 'master' into tcr_device_load
zaid-google Dec 2, 2025
87d92e1
Add provider for cluster context
zaid-google Dec 3, 2025
b3a7622
Restyled by whitespace
restyled-commits Dec 3, 2025
788962a
Restyled by clang-format
restyled-commits Dec 3, 2025
861cf88
Merge branch 'master' into tcr_device_load
zaid-google Dec 3, 2025
8e40b05
Address review comments
zaid-google Dec 4, 2025
71e0d34
Create DeviceLoadStatusProvider and address comments
zaid-google Dec 4, 2025
db0454c
Add the file for the delegate
zaid-google Dec 4, 2025
1aaf29b
Restyled by whitespace
restyled-commits Dec 4, 2025
22321d6
Restyled by clang-format
restyled-commits Dec 4, 2025
425ec8f
Edit BUILD files
zaid-google Dec 4, 2025
7c29a55
Restyled by gn
restyled-commits Dec 4, 2025
13c8cb6
Merge branch 'master' into tcr_device_load
zaid-google Dec 5, 2025
3ce5548
Create struct for subscription stats
zaid-google Dec 5, 2025
4f5a7cb
Make unused param unnamed
zaid-google Dec 5, 2025
1218f16
Restyled by clang-format
restyled-commits Dec 5, 2025
cc8dbec
Fix layered dependency
zaid-google Dec 5, 2025
5c2447a
Restyled by whitespace
restyled-commits Dec 5, 2025
4432d67
Restyled by clang-format
restyled-commits Dec 5, 2025
b924706
Move function definitions to cpp file
zaid-google Dec 5, 2025
264d024
Restyled by clang-format
restyled-commits Dec 5, 2025
0ecc91d
Merge branch 'master' into tcr_device_load
zaid-google Dec 5, 2025
9a0cb42
Merge branch 'master' into tcr_device_load
zaid-google Dec 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/InteractionModelEngine.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
#include <platform/CHIPDeviceLayer.h>
Expand Down Expand Up @@ -68,7 +69,8 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr
mAdministratorCommissioningCluster.Create(endpointId, BitFlags<AdministratorCommissioning::Feature>{});
ReturnErrorOnFailure(provider.AddCluster(mAdministratorCommissioningCluster.Registration()));

mGeneralDiagnosticsCluster.Create(GeneralDiagnosticsCluster::OptionalAttributeSet{}, BitFlags<GeneralDiagnostics::Feature>{});
mGeneralDiagnosticsCluster.Create(GeneralDiagnosticsCluster::OptionalAttributeSet{}, BitFlags<GeneralDiagnostics::Feature>{},
InteractionModelEngine::GetInstance());
ReturnErrorOnFailure(provider.AddCluster(mGeneralDiagnosticsCluster.Registration()));

mGroupKeyManagementCluster.Create();
Expand Down
3 changes: 3 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static_library("interaction-model") {
"CASESessionManager.h",
"CommandSender.cpp",
"CommandSender.h",
"DeviceLoadStatusProvider.h",
"DeviceProxy.cpp",
"DeviceProxy.h",
"InteractionModelDelegatePointers.cpp",
Expand All @@ -192,6 +193,7 @@ static_library("interaction-model") {
# fixing
"ReadPrepareParams.h",
"SubscriptionResumptionStorage.h",
"SubscriptionStats.h",
"TimedHandler.cpp",
"TimedHandler.h",
"TimedRequest.cpp",
Expand Down Expand Up @@ -236,6 +238,7 @@ static_library("interaction-model") {
"${chip_root}/src/protocols/interaction_model",
"${chip_root}/src/protocols/secure_channel",
"${chip_root}/src/system",
"${chip_root}/src/transport",
]

if (chip_enable_icd_server) {
Expand Down
41 changes: 41 additions & 0 deletions src/app/DeviceLoadStatusProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* 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.
*/
#pragma once

#include <cstdint>

#include <app/SubscriptionStats.h>
#include <lib/core/DataModelTypes.h>
#include <transport/MessageStats.h>
#include <utility>

namespace chip {
namespace app {

class DeviceLoadStatusProvider
{
public:
virtual ~DeviceLoadStatusProvider() = default;

virtual MessageStats GetMessageStats() = 0;

virtual SubscriptionStats GetSubscriptionStats(FabricIndex fabric) = 0;
};

} // namespace app
} // namespace chip
15 changes: 15 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,5 +2269,20 @@ void InteractionModelEngine::ResetNumSubscriptionsRetries()
}
}
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION

MessageStats InteractionModelEngine::GetMessageStats()
{
return GetExchangeManager()->GetSessionManager()->GetMessageStats();
}

SubscriptionStats InteractionModelEngine::GetSubscriptionStats(FabricIndex fabric)
{
return SubscriptionStats{ .numTotalSubscriptions = GetReportScheduler()->GetTotalSubscriptionsEstablished(),
.numCurrentSubscriptions =
static_cast<uint16_t>(GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe)),
.numCurrentSubscriptionsForFabric = static_cast<uint16_t>(
GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe, fabric)) };
}

} // namespace app
} // namespace chip
14 changes: 11 additions & 3 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@
#include <access/AccessControl.h>
#include <app/AppConfig.h>
#include <app/AttributePathParams.h>
#include <app/CASESessionManager.h>
#include <app/CommandHandlerImpl.h>
#include <app/CommandResponseSender.h>
#include <app/CommandSender.h>
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>
#include <app/ConcreteEventPath.h>
#include <app/DataVersionFilter.h>
#include <app/DeviceLoadStatusProvider.h>
#include <app/EventPathParams.h>
#include <app/MessageDef/AttributeReportIBs.h>
#include <app/MessageDef/ReportDataMessage.h>
#include <app/ReadClient.h>
#include <app/ReadHandler.h>
#include <app/StatusResponse.h>
#include <app/SubscriptionResumptionSessionEstablisher.h>
#include <app/SubscriptionStats.h>
#include <app/SubscriptionsInfoProvider.h>
#include <app/TimedHandler.h>
#include <app/WriteClient.h>
Expand All @@ -66,8 +69,7 @@
#include <protocols/Protocols.h>
#include <protocols/interaction_model/Constants.h>
#include <system/SystemPacketBuffer.h>

#include <app/CASESessionManager.h>
#include <transport/MessageStats.h>

#if CHIP_CONFIG_ENABLE_ICD_SERVER
#include <app/icd/server/ICDManager.h> // nogncheck
Expand All @@ -92,7 +94,8 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
public FabricTable::Delegate,
public SubscriptionsInfoProvider,
public TimedHandlerDelegate,
public WriteHandlerDelegate
public WriteHandlerDelegate,
public DeviceLoadStatusProvider
{
public:
/**
Expand Down Expand Up @@ -429,6 +432,11 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
// Returns the old data model provider value.
DataModel::Provider * SetDataModelProvider(DataModel::Provider * model);

// DeviceLoadStatusProvider functions implementation
MessageStats GetMessageStats() override;

SubscriptionStats GetSubscriptionStats(FabricIndex fabric) override;

private:
/* DataModel::ActionContext implementation */
Messaging::ExchangeContext * CurrentExchange() override { return mCurrentExchange; }
Expand Down
33 changes: 33 additions & 0 deletions src/app/SubscriptionStats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* 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.
*/
#pragma once

#include <cstdint>

namespace chip {
namespace app {

struct SubscriptionStats
{
uint32_t numTotalSubscriptions = 0;
uint16_t numCurrentSubscriptions = 0;
uint16_t numCurrentSubscriptionsForFabric = 0;
};

} // namespace app
} // namespace chip
1 change: 1 addition & 0 deletions src/app/clusters/general-diagnostics-server/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ source_set("general-diagnostics-server") {

public_deps = [
"${chip_root}/src/app:attribute-access",
"${chip_root}/src/app:interaction-model",
"${chip_root}/src/app:test-event-trigger",
"${chip_root}/src/app/data-model-provider:metadata",
"${chip_root}/src/app/server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

#include <app/InteractionModelEngine.h>
#include <app/clusters/general-diagnostics-server/CodegenIntegration.h>
#include <app/clusters/general-diagnostics-server/GeneralDiagnosticsCluster.h>
#include <app/static-cluster-config/GeneralDiagnostics.h>
Expand Down Expand Up @@ -50,6 +51,7 @@ class IntegrationDelegate : public CodegenClusterIntegration::Delegate
uint32_t optionalAttributeBits, uint32_t featureMap) override
{
GeneralDiagnosticsCluster::OptionalAttributeSet optionalAttributeSet(optionalAttributeBits);
InteractionModelEngine * interactionModel = InteractionModelEngine::GetInstance();

#if defined(ZCL_USING_TIME_SYNCHRONIZATION_CLUSTER_SERVER) || defined(GENERAL_DIAGNOSTICS_ENABLE_PAYLOAD_TEST_REQUEST_CMD)
const GeneralDiagnosticsFunctionsConfig functionsConfig
Expand All @@ -69,9 +71,9 @@ class IntegrationDelegate : public CodegenClusterIntegration::Delegate
.enablePayloadSnapshot = false,
#endif
};
gServer.Create(optionalAttributeSet, BitFlags<GeneralDiagnostics::Feature>(featureMap), functionsConfig);
gServer.Create(optionalAttributeSet, BitFlags<GeneralDiagnostics::Feature>(featureMap), interactionModel, functionsConfig);
#else
gServer.Create(optionalAttributeSet, BitFlags<GeneralDiagnostics::Feature>(featureMap));
gServer.Create(optionalAttributeSet, BitFlags<GeneralDiagnostics::Feature>(featureMap), interactionModel);
#endif
return gServer.Registration();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
*/

#include <app-common/zap-generated/cluster-objects.h>
#include <app/InteractionModelEngine.h>
#include <app/SubscriptionStats.h>
#include <app/clusters/general-diagnostics-server/GeneralDiagnosticsCluster.h>
#include <app/server-cluster/AttributeListBuilder.h>
#include <app/server-cluster/DefaultServerCluster.h>
#include <app/server/Server.h>
#include <clusters/GeneralDiagnostics/ClusterId.h>
#include <clusters/GeneralDiagnostics/Metadata.h>
#include <transport/MessageStats.h>

using namespace chip;
using namespace chip::app;
Expand Down Expand Up @@ -274,6 +277,21 @@ DataModel::ActionReturnStatus GeneralDiagnosticsCluster::ReadAttribute(const Dat
case GeneralDiagnostics::Attributes::TestEventTriggersEnabled::Id: {
bool isTestEventTriggersEnabled = IsTestEventTriggerEnabled();
return encoder.Encode(isTestEventTriggersEnabled);
}
case GeneralDiagnostics::Attributes::DeviceLoadStatus::Id: {
static_assert(CHIP_IM_MAX_NUM_SUBSCRIPTIONS <= UINT16_MAX,
"The maximum number of IM subscriptions is larger than expected (should fit within a 16 bit unsigned int)");
const SubscriptionStats subscriptionStats = mDeviceLoadStatusProvider->GetSubscriptionStats(encoder.AccessingFabricIndex());
const MessageStats messageStatistics = mDeviceLoadStatusProvider->GetMessageStats();

GeneralDiagnostics::Structs::DeviceLoadStruct::Type load = {
.currentSubscriptions = subscriptionStats.numCurrentSubscriptions,
.currentSubscriptionsForFabric = subscriptionStats.numCurrentSubscriptionsForFabric,
.totalSubscriptionsEstablished = subscriptionStats.numTotalSubscriptions,
.totalInteractionModelMessagesSent = messageStatistics.interactionModelMessagesSent,
.totalInteractionModelMessagesReceived = messageStatistics.interactionModelMessagesReceived,
};
return encoder.Encode(load);
}
// Note: Attribute ID 0x0009 was removed (#30002).

Expand Down Expand Up @@ -328,6 +346,11 @@ CHIP_ERROR GeneralDiagnosticsCluster::Attributes(const ConcreteClusterPath & pat
GeneralDiagnostics::Attributes::DeviceLoadStatus::kMetadataEntry,
};

if (mFeatureFlags.Has(GeneralDiagnostics::Feature::kDeviceLoad))
{
mOptionalAttributeSet.Set<GeneralDiagnostics::Attributes::DeviceLoadStatus::Id>();
}

return listBuilder.Append(Span(GeneralDiagnostics::Attributes::kMandatoryMetadata), Span(optionalAttributeEntries),
mOptionalAttributeSet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/DeviceLoadStatusProvider.h>
#include <app/server-cluster/DefaultServerCluster.h>
#include <app/server-cluster/OptionalAttributeSet.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -49,10 +50,11 @@ class GeneralDiagnosticsCluster : public DefaultServerCluster
// it will be forced as mandatory by the cluster constructor
>;

GeneralDiagnosticsCluster(OptionalAttributeSet optionalAttributeSet, BitFlags<GeneralDiagnostics::Feature> featureFlags) :
GeneralDiagnosticsCluster(OptionalAttributeSet optionalAttributeSet, BitFlags<GeneralDiagnostics::Feature> featureFlags,
DeviceLoadStatusProvider * deviceLoadStatusProvider) :
DefaultServerCluster({ kRootEndpointId, GeneralDiagnostics::Id }),
mOptionalAttributeSet(optionalAttributeSet.ForceSet<GeneralDiagnostics::Attributes::UpTime::Id>()),
mFeatureFlags(featureFlags)
mFeatureFlags(featureFlags), mDeviceLoadStatusProvider(deviceLoadStatusProvider)
{}

CHIP_ERROR Startup(ServerClusterContext & context) override;
Expand Down Expand Up @@ -126,15 +128,17 @@ class GeneralDiagnosticsCluster : public DefaultServerCluster
OptionalAttributeSet mOptionalAttributeSet;
CHIP_ERROR ReadNetworkInterfaces(AttributeValueEncoder & aEncoder);
BitFlags<GeneralDiagnostics::Feature> mFeatureFlags;
DeviceLoadStatusProvider * mDeviceLoadStatusProvider;
};

class GeneralDiagnosticsClusterFullConfigurable : public GeneralDiagnosticsCluster
{
public:
GeneralDiagnosticsClusterFullConfigurable(const GeneralDiagnosticsCluster::OptionalAttributeSet & optionalAttributeSet,
const BitFlags<GeneralDiagnostics::Feature> featureFlags,
DeviceLoadStatusProvider * deviceLoadStatusProvider,
const GeneralDiagnosticsFunctionsConfig & functionsConfig) :
GeneralDiagnosticsCluster(optionalAttributeSet, featureFlags),
GeneralDiagnosticsCluster(optionalAttributeSet, featureFlags, deviceLoadStatusProvider),
mFunctionConfig(functionsConfig)
{}

Expand Down
Loading
Loading