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

handling global attributes per cluster #1142

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

paulr34
Copy link
Collaborator

@paulr34 paulr34 commented Sep 17, 2023

handling global attributes per cluster

#543

@paulr34
Copy link
Collaborator Author

paulr34 commented Sep 17, 2023

@tecimovic @bzbarsky-apple @brdandu proof of concept for changing global attributes on a per cluster basis. I am aware that I need to clean it up but It works.

src-electron/db/query-config.js Outdated Show resolved Hide resolved
src-electron/db/query-config.js Outdated Show resolved Hide resolved
@paulr34 paulr34 marked this pull request as ready for review September 19, 2023 20:36
@paulr34 paulr34 force-pushed the globalAttributeHandling branch from 71f91b8 to 2a22341 Compare September 19, 2023 21:53
@paulr34
Copy link
Collaborator Author

paulr34 commented Sep 19, 2023

ready for review.

Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

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

Just tested, and this does not seem to fix #543 in any of the contexts I looked at:

  1. We are still ending up with accessor codegen for global attributes when we should not.
  2. We are not getting the relevant attributes flagged as external in endpoint_config.h
  3. zap convert is not marking them external in the .zap file.

@paulr34
Copy link
Collaborator Author

paulr34 commented Sep 20, 2023

Just tested, and this does not seem to fix #543 in any of the contexts I looked at:

  1. We are still ending up with accessor codegen for global attributes when we should not.

  2. We are not getting the relevant attributes flagged as external in endpoint_config.h

  3. zap convert is not marking them external in the .zap file.

Thank you. I will work on those cases tomorrow.

@paulr34 paulr34 force-pushed the globalAttributeHandling branch from 098292d to 2a22341 Compare September 20, 2023 12:23
@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2023

Codecov Report

Merging #1142 (a73c55a) into master (bc2ca3c) will increase coverage by 0.08%.
The diff coverage is 96.49%.

@@            Coverage Diff             @@
##           master    #1142      +/-   ##
==========================================
+ Coverage   65.16%   65.25%   +0.08%     
==========================================
  Files         170      171       +1     
  Lines       18232    18284      +52     
  Branches     3927     3936       +9     
==========================================
+ Hits        11881    11931      +50     
- Misses       6351     6353       +2     
Files Coverage Δ
src-electron/db/query-cluster.js 92.85% <100.00%> (+1.19%) ⬆️
src-electron/db/query-config.js 80.67% <100.00%> (-0.06%) ⬇️
src-electron/db/query-impexp.js 98.13% <100.00%> (+0.07%) ⬆️
src-electron/db/query-package.js 88.94% <100.00%> (+0.21%) ⬆️
src-electron/importexport/import-json.js 82.45% <ø> (ø)
src-electron/zcl/zcl-loader-silabs.js 94.43% <ø> (-0.01%) ⬇️
src-electron/upgrade/upgrade.js 95.00% <95.00%> (ø)

package-lock.json Outdated Show resolved Hide resolved
src-electron/db/query-attribute.js Outdated Show resolved Hide resolved
src-electron/db/query-cluster.js Show resolved Hide resolved
src-electron/db/query-config.js Outdated Show resolved Hide resolved
src-electron/db/query-impexp.js Show resolved Hide resolved
src-electron/db/query-impexp.js Outdated Show resolved Hide resolved
const fs = require('fs')
const fsp = fs.promises

async function selectClusterName(db, clusterRef) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you need this move this to query-cluster.js

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

originally I had it there but will probably just do what you suggested above, thanks

src-electron/db/query-upgrade.js Outdated Show resolved Hide resolved
return attributeName[0].NAME
}

async function queryMetaFile(db, packageId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use query-package#getPackageByPackageId instead and get rid of this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unfortunately that query does not retrieve the PATH which I need

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm are you sure: I see
const querySelectFromPackage =
SELECT
PACKAGE_ID,
PATH,
TYPE,
CRC,
VERSION,
CATEGORY,
DESCRIPTION
FROM PACKAGE ``

src-electron/db/query-upgrade.js Outdated Show resolved Hide resolved
@brdandu
Copy link
Collaborator

brdandu commented Sep 20, 2023

Also fix Zigbee Code generation Issue in the CI

* @returns An array of objects
*/

async function checkGlobals(db, attributeId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is way more generic than the documented behavior of the function. And how does the attributeId fit in with the documented behavior bit? It does not seem to be used below....

I suspect this function just needs to be renamed to reflect what it actually does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agree, will fix, thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

attributeId is used to get the associated package

* @returns A flag.
*/

async function checkStorage(
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps computeStorageOption?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sounds good to me, will fix, thanks

Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

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

@paulr34 Actually, there is one more thing still broken here. This template:

{{#zcl_clusters}}
{{#zcl_attributes_server}}
{{#unless (isStrEqual storagePolicy "attributeAccessInterface")}}

does not behave correctly, because for global attributes this query is not producing the right storagePolicy.....

@paulr34
Copy link
Collaborator Author

paulr34 commented Sep 21, 2023

@paulr34 Actually, there is one more thing still broken here. This template:


{{#zcl_clusters}}

{{#zcl_attributes_server}}

{{#unless (isStrEqual storagePolicy "attributeAccessInterface")}}

does not behave correctly, because for global attributes this query is not producing the right storagePolicy.....

Thank you for catching this. I'm on it.

@paulr34
Copy link
Collaborator Author

paulr34 commented Sep 21, 2023

@paulr34 Actually, there is one more thing still broken here. This template:

{{#zcl_clusters}}
{{#zcl_attributes_server}}
{{#unless (isStrEqual storagePolicy "attributeAccessInterface")}}

does not behave correctly, because for global attributes this query is not producing the right storagePolicy.....

    "Access Control": [
      "ClusterRevision",
      "SubjectsPerAccessControlEntry",
      "TargetsPerAccessControlEntry",
      "AccessControlEntriesPerFabric"
    ],
    "Administrator Commissioning": [
      "WindowStatus",
      "AdminFabricIndex",
      "AdminVendorId"
    ],
    "Basic Information": [
      "DataModelRevision",
      "VendorName",
      "VendorID",
      "ProductName",
      "ProductID",
      "Location",
      "HardwareVersion",
      "HardwareVersionString",
      "SoftwareVersion",
      "SoftwareVersionString",
      "ManufacturingDate",
      "PartNumber",
      "ProductURL",
      "ProductLabel",
      "SerialNumber",
      "UniqueID",
      "CapabilityMinima"
    ],
    "Descriptor": ["ClusterRevision"],
    "Ethernet Network Diagnostics": [
      "PHYRate",
      "FullDuplex",
      "CarrierDetect",
      "TimeSinceReset",
      "PacketRxCount",
      "PacketTxCount",
      "TxErrCount",
      "CollisionCount",
      "OverrunCount"
    ],
    "General Commissioning": [
      "RegulatoryConfig",
      "LocationCapability",
      "BasicCommissioningInfo",
      "SupportsConcurrentConnection"
    ],
    "General Diagnostics": [
      "NetworkInterfaces",
      "ActiveHardwareFaults",
      "ActiveRadioFaults",
      "ActiveNetworkFaults",
      "RebootCount",
      "UpTime",
      "TotalOperationalHours",
      "BootReason"
    ],
    "Group Key Management": [
      "ClusterRevision",
      "MaxGroupsPerFabric",
      "MaxGroupKeysPerFabric",
      "FeatureMap"
    ],
    "Operational Credentials": [
      "SupportedFabrics",
      "CommissionedFabrics",
      "CurrentFabricIndex"
    ],
    "Software Diagnostics": [
      "CurrentHeapFree",
      "CurrentHeapHighWatermark",
      "CurrentHeapUsed",
      "FeatureMap",
      "ThreadMetrics"
    ],
    "Unit Testing": [
      "struct_attr",
      "nullable_struct",
      "general_error_boolean",
      "cluster_error_boolean"
    ],
    "Thread Network Diagnostics": [
      "Channel",
      "RoutingRole",
      "NetworkName",
      "PanId",
      "ExtendedPanId",
      "MeshLocalPrefix",
      "OverrunCount",
      "PartitionId",
      "Weighting",
      "DataVersion",
      "StableDataVersion",
      "LeaderRouterId",
      "DetachedRoleCount",
      "ChildRoleCount",
      "RouterRoleCount",
      "LeaderRoleCount",
      "AttachAttemptCount",
      "PartitionIdChangeCount",
      "BetterPartitionAttachAttemptCount",
      "ParentChangeCount",
      "TxTotalCount",
      "TxUnicastCount",
      "TxBroadcastCount",
      "TxAckRequestedCount",
      "TxAckedCount",
      "TxNoAckRequestedCount",
      "TxDataCount",
      "TxDataPollCount",
      "TxBeaconCount",
      "TxBeaconRequestCount",
      "TxOtherCount",
      "TxRetryCount",
      "TxDirectMaxRetryExpiryCount",
      "TxIndirectMaxRetryExpiryCount",
      "TxErrCcaCount",
      "TxErrAbortCount",
      "TxErrBusyChannelCount",
      "RxTotalCount",
      "RxUnicastCount",
      "RxBroadcastCount",
      "RxDataCount",
      "RxDataPollCount",
      "RxBeaconCount",
      "RxBeaconRequestCount",
      "RxOtherCount",
      "RxAddressFilteredCount",
      "RxDestAddrFilteredCount",
      "RxDuplicatedCount",
      "RxErrNoFrameCount",
      "RxErrUnknownNeighborCount",
      "RxErrInvalidSrcAddrCount",
      "RxErrSecCount",
      "RxErrFcsCount",
      "RxErrOtherCount",
      "ActiveTimestamp",
      "PendingTimestamp",
      "Delay",
      "SecurityPolicy",
      "ChannelPage0Mask",
      "OperationalDatasetComponents"
    ],
    "WiFi Network Diagnostics": [
      "BSSID",
      "SecurityType",
      "WiFiVersion",
      "ChannelNumber",
      "RSSI",
      "BeaconLostCount",
      "BeaconRxCount",
      "PacketMulticastRxCount",
      "PacketMulticastTxCount",
      "PacketUnicastRxCount",
      "PacketUnicastTxCount",
      "CurrentMaxRate",
      "OverrunCount"
    ]
  },```

@paulr34
Copy link
Collaborator Author

paulr34 commented Sep 21, 2023

@paulr34 Actually, there is one more thing still broken here. This template:

{{#zcl_clusters}}
{{#zcl_attributes_server}}
{{#unless (isStrEqual storagePolicy "attributeAccessInterface")}}

does not behave correctly, because for global attributes this query is not producing the right storagePolicy.....

    "Access Control": [
      "ClusterRevision",
      "SubjectsPerAccessControlEntry",
      "TargetsPerAccessControlEntry",
      "AccessControlEntriesPerFabric"
    ],
    "Administrator Commissioning": [
      "WindowStatus",
      "AdminFabricIndex",
      "AdminVendorId"
    ],
    "Basic Information": [
      "DataModelRevision",
      "VendorName",
      "VendorID",
      "ProductName",
      "ProductID",
      "Location",
      "HardwareVersion",
      "HardwareVersionString",
      "SoftwareVersion",
      "SoftwareVersionString",
      "ManufacturingDate",
      "PartNumber",
      "ProductURL",
      "ProductLabel",
      "SerialNumber",
      "UniqueID",
      "CapabilityMinima"
    ],
    "Descriptor": ["ClusterRevision"],
    "Ethernet Network Diagnostics": [
      "PHYRate",
      "FullDuplex",
      "CarrierDetect",
      "TimeSinceReset",
      "PacketRxCount",
      "PacketTxCount",
      "TxErrCount",
      "CollisionCount",
      "OverrunCount"
    ],
    "General Commissioning": [
      "RegulatoryConfig",
      "LocationCapability",
      "BasicCommissioningInfo",
      "SupportsConcurrentConnection"
    ],
    "General Diagnostics": [
      "NetworkInterfaces",
      "ActiveHardwareFaults",
      "ActiveRadioFaults",
      "ActiveNetworkFaults",
      "RebootCount",
      "UpTime",
      "TotalOperationalHours",
      "BootReason"
    ],
    "Group Key Management": [
      "ClusterRevision",
      "MaxGroupsPerFabric",
      "MaxGroupKeysPerFabric",
      "FeatureMap"
    ],
    "Operational Credentials": [
      "SupportedFabrics",
      "CommissionedFabrics",
      "CurrentFabricIndex"
    ],
    "Software Diagnostics": [
      "CurrentHeapFree",
      "CurrentHeapHighWatermark",
      "CurrentHeapUsed",
      "FeatureMap",
      "ThreadMetrics"
    ],
    "Unit Testing": [
      "struct_attr",
      "nullable_struct",
      "general_error_boolean",
      "cluster_error_boolean"
    ],
    "Thread Network Diagnostics": [
      "Channel",
      "RoutingRole",
      "NetworkName",
      "PanId",
      "ExtendedPanId",
      "MeshLocalPrefix",
      "OverrunCount",
      "PartitionId",
      "Weighting",
      "DataVersion",
      "StableDataVersion",
      "LeaderRouterId",
      "DetachedRoleCount",
      "ChildRoleCount",
      "RouterRoleCount",
      "LeaderRoleCount",
      "AttachAttemptCount",
      "PartitionIdChangeCount",
      "BetterPartitionAttachAttemptCount",
      "ParentChangeCount",
      "TxTotalCount",
      "TxUnicastCount",
      "TxBroadcastCount",
      "TxAckRequestedCount",
      "TxAckedCount",
      "TxNoAckRequestedCount",
      "TxDataCount",
      "TxDataPollCount",
      "TxBeaconCount",
      "TxBeaconRequestCount",
      "TxOtherCount",
      "TxRetryCount",
      "TxDirectMaxRetryExpiryCount",
      "TxIndirectMaxRetryExpiryCount",
      "TxErrCcaCount",
      "TxErrAbortCount",
      "TxErrBusyChannelCount",
      "RxTotalCount",
      "RxUnicastCount",
      "RxBroadcastCount",
      "RxDataCount",
      "RxDataPollCount",
      "RxBeaconCount",
      "RxBeaconRequestCount",
      "RxOtherCount",
      "RxAddressFilteredCount",
      "RxDestAddrFilteredCount",
      "RxDuplicatedCount",
      "RxErrNoFrameCount",
      "RxErrUnknownNeighborCount",
      "RxErrInvalidSrcAddrCount",
      "RxErrSecCount",
      "RxErrFcsCount",
      "RxErrOtherCount",
      "ActiveTimestamp",
      "PendingTimestamp",
      "Delay",
      "SecurityPolicy",
      "ChannelPage0Mask",
      "OperationalDatasetComponents"
    ],
    "WiFi Network Diagnostics": [
      "BSSID",
      "SecurityType",
      "WiFiVersion",
      "ChannelNumber",
      "RSSI",
      "BeaconLostCount",
      "BeaconRxCount",
      "PacketMulticastRxCount",
      "PacketMulticastTxCount",
      "PacketUnicastRxCount",
      "PacketUnicastTxCount",
      "CurrentMaxRate",
      "OverrunCount"
    ]
  },```

@bzbarsky-apple is the above list correct? or out of date?

@paulr34 paulr34 force-pushed the globalAttributeHandling branch 2 times, most recently from e8b944b to 9f6b561 Compare September 26, 2023 22:49
if (forcedExternal.lists == true && attribute.type == 'array') {
storageOption = dbEnum.storageOption.external
}
if (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bzbarsky-apple this code which presumably changes global attributes to external if they are in the list seems to cause CI and codeine failures. Any idea what the failures mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

That code changes all attributes to be external if they are of array type. And that code is very much pre-existing, the right behavior, and not the problem here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay thank you

let zcl = await queryPackage.getMetaFile(db, pkgs)
let obj = await fsp.readFile(zcl)
let data = JSON.parse(obj)
let externals = data.attributeAccessInterfaceAttributes
Copy link
Contributor

Choose a reason for hiding this comment

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

Is attributeAccessInterfaceAttributes always present in the zcl meta file?
Optional Chaining (data?.fieldName) can be used here when it's not guaranteed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is attributeAccessInterfaceAttributes always present in the zcl meta file?

No.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea @jingteng25742 will fix, thanks

) {
let storageOption
let attributeName
if (!clusterName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you meant to test clusterName or clusterRef?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

clusterName

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe you are passing null values to the cluster name and then extracting the cluster name regardless. See let storageOption = await queryUpgrade.computeStorage( db, null,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I only retrieve clusterName if it is null

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if (!clusterName) {
clusterName = await queryCluster.selectClusterName(db, clusterRef)

Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

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

So this is a partial fix, in that it does not fix item 1 from #1142 (review), right?

staticAttribute.storagePolicy,
forcedExternal,
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess my architectural question is this: if we are doing the "getForcedExternalStorage" thing here, what is the point of having storagePolicy as a concept at all?

That is, why are we bothering to store a storage policy in the db?

All of this could really benefit from some architecture documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Going into this I had no idea what the history behind storagePolicy was. After debugging, I think we have to do getForcedExternalStorage here because it is the only way to reference the cluster.

Note, we are still using storage policy when creating endpoints from scratch. As in, when we have a "new Configuration". But point taken.

src-electron/db/query-impexp.js Outdated Show resolved Hide resolved
let zcl = await queryPackage.getMetaFile(db, pkgs)
let obj = await fsp.readFile(zcl)
let data = JSON.parse(obj)
let externals = data.attributeAccessInterfaceAttributes
Copy link
Contributor

Choose a reason for hiding this comment

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

Is attributeAccessInterfaceAttributes always present in the zcl meta file?

No.

src-electron/db/query-upgrade.js Outdated Show resolved Hide resolved
src-electron/db/query-upgrade.js Outdated Show resolved Hide resolved
@paulr34
Copy link
Collaborator Author

paulr34 commented Sep 28, 2023

So this is a partial fix, in that it does not fix item 1 from #1142 (review), right?

right

@paulr34 paulr34 force-pushed the globalAttributeHandling branch from f01d09b to 64a5de8 Compare September 28, 2023 17:37
src-electron/db/query-cluster.js Outdated Show resolved Hide resolved
src-electron/db/query-impexp.js Show resolved Hide resolved
src-electron/db/query-upgrade.js Outdated Show resolved Hide resolved
return attributeName[0].NAME
}

async function queryMetaFile(db, packageId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm are you sure: I see
const querySelectFromPackage =
SELECT
PACKAGE_ID,
PATH,
TYPE,
CRC,
VERSION,
CATEGORY,
DESCRIPTION
FROM PACKAGE ``

src-electron/db/query-package.js Outdated Show resolved Hide resolved
)
let storageOption = await queryUpgrade.computeStorage(
db,
null,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this null instead of the cluster name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because clusterName is not needed when upgrading a new configuration so I used it as a differentiator

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

never mind, you're right. will fix.

src-electron/db/query-impexp.js Outdated Show resolved Hide resolved
) {
let storageOption
let attributeName
if (!clusterName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe you are passing null values to the cluster name and then extracting the cluster name regardless. See let storageOption = await queryUpgrade.computeStorage( db, null,

test/gen-matter-4.test.js Show resolved Hide resolved
test/gen-matter-4.test.js Show resolved Hide resolved
src-electron/db/query-config.js Show resolved Hide resolved
src-electron/upgrade/upgrade.js Show resolved Hide resolved
src-electron/db/query-impexp.js Show resolved Hide resolved
src-electron/upgrade/upgrade.js Outdated Show resolved Hide resolved
@paulr34 paulr34 force-pushed the globalAttributeHandling branch 2 times, most recently from 8cb8ed6 to 5b65d3c Compare October 2, 2023 22:00
@paulr34 paulr34 force-pushed the globalAttributeHandling branch from a73c55a to 879713a Compare October 4, 2023 14:23
@paulr34 paulr34 force-pushed the globalAttributeHandling branch from 3905ebd to 98d91d4 Compare October 4, 2023 15:42
@brdandu brdandu merged commit 331ce9d into project-chip:master Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants