Skip to content

Commit 3049137

Browse files
tehampsonpull[bot]
authored andcommitted
Add ability for chip-repl to grab MaxPathsPerInvoke of remote node (#30880)
* Add ability for chip-repl to grab MaxPathsPerInvoke of remote node * Fix CI * Address PR comments * Restyle * Address PR comments * Address PR comments
1 parent c2d6fce commit 3049137

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from .clusters.CHIPClusters import ChipClusters
5454
from .crypto import p256keypair
5555
from .exceptions import UnknownAttribute, UnknownCommand
56-
from .interaction_model import InteractionModelError
56+
from .interaction_model import InteractionModelError, SessionParameters, SessionParametersStruct
5757
from .interaction_model import delegate as im
5858
from .native import PyChipError
5959

@@ -809,6 +809,36 @@ def ComputeRoundTripTimeout(self, nodeid, upperLayerProcessingTimeoutMs: int = 0
809809
device.deviceProxy, upperLayerProcessingTimeoutMs))
810810
return res
811811

812+
def GetRemoteSessionParameters(self, nodeid) -> typing.Optional[SessionParameters]:
813+
''' Returns the SessionParameters of reported by the remote node associated with `nodeid`.
814+
If there is some error in getting SessionParameters None is returned.
815+
816+
This will result in a session being established if one wasn't already established.
817+
'''
818+
819+
# First creating the struct to make building the ByteArray to be sent to CFFI easier.
820+
sessionParametersStruct = SessionParametersStruct.parse(b'\x00' * SessionParametersStruct.sizeof())
821+
sessionParametersByteArray = SessionParametersStruct.build(sessionParametersStruct)
822+
device = self.GetConnectedDeviceSync(nodeid)
823+
res = self._ChipStack.Call(lambda: self._dmLib.pychip_DeviceProxy_GetRemoteSessionParameters(
824+
device.deviceProxy, ctypes.c_char_p(sessionParametersByteArray)))
825+
826+
# 0 is CHIP_NO_ERROR
827+
if res != 0:
828+
return None
829+
830+
sessionParametersStruct = SessionParametersStruct.parse(sessionParametersByteArray)
831+
return SessionParameters(
832+
sessionIdleInterval=sessionParametersStruct.SessionIdleInterval if sessionParametersStruct.SessionIdleInterval != 0 else None,
833+
sessionActiveInterval=sessionParametersStruct.SessionActiveInterval if sessionParametersStruct.SessionActiveInterval != 0 else None,
834+
sessionActiveThreshold=sessionParametersStruct.SessionActiveThreshold if sessionParametersStruct.SessionActiveThreshold != 0 else None,
835+
dataModelRevision=sessionParametersStruct.DataModelRevision if sessionParametersStruct.DataModelRevision != 0 else None,
836+
interactionModelRevision=sessionParametersStruct.InteractionModelRevision if sessionParametersStruct.InteractionModelRevision != 0 else None,
837+
specficiationVersion=sessionParametersStruct.SpecificationVersion if sessionParametersStruct.SpecificationVersion != 0 else None,
838+
maxPathsPerInvoke=sessionParametersStruct.MaxPathsPerInvoke)
839+
840+
return res
841+
812842
async def TestOnlySendCommandTimedRequestFlagWithNoTimedInvoke(self, nodeid: int, endpoint: int,
813843
payload: ClusterObjects.ClusterCommand, responseType=None):
814844
'''

src/controller/python/chip/interaction_model/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
from chip.exceptions import ChipStackException
2828

29-
from .delegate import AttributePath, AttributePathIBstruct, DataVersionFilterIBstruct, EventPath, EventPathIBstruct
29+
from .delegate import (AttributePath, AttributePathIBstruct, DataVersionFilterIBstruct, EventPath, EventPathIBstruct,
30+
SessionParameters, SessionParametersStruct)
3031

3132
__all__ = ["AttributePath", "AttributePathIBstruct", "DataVersionFilterIBstruct",
32-
"EventPath", "EventPathIBstruct", "Status", "InteractionModelError"]
33+
"EventPath", "EventPathIBstruct", "InteractionModelError",
34+
"SessionParameters", "SessionParametersStruct", "Status"]
3335

3436

3537
# defined src/controller/python/chip/interaction_model/Delegate.h

src/controller/python/chip/interaction_model/delegate.py

+21
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
"DataVersion" / Int32ul,
7070
)
7171

72+
SessionParametersStruct = Struct(
73+
"SessionIdleInterval" / Int32ul,
74+
"SessionActiveInterval" / Int32ul,
75+
"SessionActiveThreshold" / Int16ul,
76+
"DataModelRevision" / Int16ul,
77+
"InteractionModelRevision" / Int16ul,
78+
"SpecificationVersion" / Int32ul,
79+
"MaxPathsPerInvoke" / Int16ul,
80+
)
81+
7282

7383
@dataclass
7484
class AttributePath:
@@ -107,6 +117,17 @@ class AttributeWriteResult:
107117
status: int
108118

109119

120+
@dataclass
121+
class SessionParameters:
122+
sessionIdleInterval: typing.Optional[int]
123+
sessionActiveInterval: typing.Optional[int]
124+
sessionActiveThreshold: typing.Optional[int]
125+
dataModelRevision: typing.Optional[int]
126+
interactionModelRevision: typing.Optional[int]
127+
specficiationVersion: typing.Optional[int]
128+
maxPathsPerInvoke: int
129+
130+
110131
# typedef void (*PythonInteractionModelDelegate_OnCommandResponseStatusCodeReceivedFunct)(uint64_t commandSenderPtr,
111132
# void * commandStatusBuf);
112133
# typedef void (*PythonInteractionModelDelegate_OnCommandResponseProtocolErrorFunct)(uint64_t commandSenderPtr,

src/controller/python/chip/utils/DeviceProxyUtils.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@
3333

3434
using namespace chip;
3535

36+
namespace python {
37+
38+
struct __attribute__((packed)) SessionParametersStruct
39+
{
40+
uint32_t sessionIdleInterval = 0;
41+
uint32_t sessionActiveInterval = 0;
42+
uint16_t sessionActiveThreshold = 0;
43+
uint16_t dataModelRevision = 0;
44+
uint16_t interactionModelRevision = 0;
45+
uint32_t specificationVersion = 0;
46+
uint16_t maxPathsPerInvoke = 0;
47+
};
48+
49+
} // namespace python
50+
3651
extern "C" {
3752

3853
/**
@@ -59,4 +74,31 @@ uint32_t pychip_DeviceProxy_ComputeRoundTripTimeout(DeviceProxy * device, uint32
5974
->ComputeRoundTripTimeout(System::Clock::Milliseconds32(upperLayerProcessingTimeoutMs))
6075
.count();
6176
}
77+
78+
/**
79+
* @brief This gets the Session Parameters reported by remote node.
80+
*
81+
* A valid DeviceProxy pointer with a valid established session is required for this method.
82+
*/
83+
PyChipError pychip_DeviceProxy_GetRemoteSessionParameters(DeviceProxy * device, void * sessionParametersStructPointer)
84+
{
85+
VerifyOrReturnError(device != nullptr || sessionParametersStructPointer, ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT));
86+
87+
auto * deviceProxy = static_cast<DeviceProxy *>(device);
88+
VerifyOrReturnError(deviceProxy->GetSecureSession().HasValue(), ToPyChipError(CHIP_ERROR_INCORRECT_STATE));
89+
90+
auto remoteSessionParameters = deviceProxy->GetSecureSession().Value()->GetRemoteSessionParameters();
91+
auto remoteMrpConfig = remoteSessionParameters.GetMRPConfig();
92+
93+
python::SessionParametersStruct * sessionParam = static_cast<python::SessionParametersStruct *>(sessionParametersStructPointer);
94+
95+
sessionParam->sessionIdleInterval = remoteMrpConfig.mIdleRetransTimeout.count();
96+
sessionParam->sessionActiveInterval = remoteMrpConfig.mActiveRetransTimeout.count();
97+
sessionParam->sessionActiveThreshold = remoteMrpConfig.mActiveThresholdTime.count();
98+
sessionParam->dataModelRevision = remoteSessionParameters.GetDataModelRevision().ValueOr(0);
99+
sessionParam->interactionModelRevision = remoteSessionParameters.GetInteractionModelRevision().ValueOr(0);
100+
sessionParam->specificationVersion = remoteSessionParameters.GetSpecificationVersion().ValueOr(0);
101+
sessionParam->maxPathsPerInvoke = remoteSessionParameters.GetMaxPathsPerInvoke();
102+
return ToPyChipError(CHIP_NO_ERROR);
103+
}
62104
}

0 commit comments

Comments
 (0)