From 0b6e5fd555025837cc404424884a725ce02c70f9 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Wed, 24 Nov 2021 02:33:30 +0800 Subject: [PATCH] Group MRP parameters (#12069) --- .../esp32/main/OTARequesterImpl.cpp | 5 +- examples/ota-requestor-app/linux/main.cpp | 5 +- src/app/CASESessionManager.cpp | 4 +- src/app/DeviceProxy.h | 11 +-- src/app/OperationalDeviceProxy.cpp | 13 ++-- src/app/OperationalDeviceProxy.h | 5 +- src/app/server/Dnssd.cpp | 21 +++--- src/channel/ChannelContext.cpp | 4 +- src/controller/CHIPDeviceController.cpp | 8 +-- src/controller/CommissioneeDeviceProxy.cpp | 9 ++- src/controller/CommissioneeDeviceProxy.h | 7 +- src/lib/core/Optional.h | 15 +++- src/lib/dnssd/Advertiser.h | 14 ++-- src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp | 70 ++++++++++--------- src/lib/dnssd/BUILD.gn | 1 + src/lib/dnssd/Discovery_ImplPlatform.cpp | 61 ++++++++-------- src/lib/dnssd/Resolver.h | 46 +++++------- src/lib/dnssd/TxtFields.cpp | 11 +-- .../minimal_mdns/tests/TestAdvertiser.cpp | 10 +-- src/lib/dnssd/platform/tests/TestPlatform.cpp | 26 +++---- src/lib/dnssd/tests/TestTxtFields.cpp | 16 ++--- src/lib/shell/commands/Ota.cpp | 3 +- src/messaging/BUILD.gn | 9 ++- src/messaging/ExchangeContext.cpp | 8 ++- src/messaging/ExchangeContext.h | 5 +- src/messaging/ExchangeMgr.cpp | 12 +--- src/messaging/ReliableMessageContext.cpp | 3 +- src/messaging/ReliableMessageContext.h | 3 +- .../ReliableMessageProtocolConfig.cpp | 37 ++++++++++ src/messaging/ReliableMessageProtocolConfig.h | 15 ++-- src/messaging/tests/MessagingContext.cpp | 6 +- src/transport/PairingSession.h | 10 +++ src/transport/SecureSession.h | 22 ++---- src/transport/SecureSessionTable.h | 6 +- src/transport/SessionHandle.cpp | 30 +++++--- src/transport/SessionHandle.h | 3 +- src/transport/SessionManager.cpp | 7 +- src/transport/SessionManager.h | 7 +- src/transport/UnauthenticatedSessionTable.h | 32 ++++----- src/transport/tests/TestPeerConnections.cpp | 20 +++--- 40 files changed, 319 insertions(+), 281 deletions(-) create mode 100644 src/messaging/ReliableMessageProtocolConfig.cpp diff --git a/examples/ota-requestor-app/esp32/main/OTARequesterImpl.cpp b/examples/ota-requestor-app/esp32/main/OTARequesterImpl.cpp index 8c523855e5573a..d9edae659fc9e7 100644 --- a/examples/ota-requestor-app/esp32/main/OTARequesterImpl.cpp +++ b/examples/ota-requestor-app/esp32/main/OTARequesterImpl.cpp @@ -302,10 +302,7 @@ void ConnectToProvider(const char * ipAddress, uint32_t nodeId) IPAddress ipAddr; IPAddress::FromString(ipAddress, ipAddr); PeerAddress addr = PeerAddress::UDP(ipAddr, CHIP_PORT); - uint32_t idleInterval; - uint32_t activeInterval; - operationalDeviceProxy->GetMRPIntervals(idleInterval, activeInterval); - operationalDeviceProxy->UpdateDeviceData(addr, idleInterval, activeInterval); + operationalDeviceProxy->UpdateDeviceData(addr, operationalDeviceProxy->GetMRPConfig()); } CHIP_ERROR err = operationalDeviceProxy->Connect(&onConnectedCallback, &onConnectionFailureCallback); diff --git a/examples/ota-requestor-app/linux/main.cpp b/examples/ota-requestor-app/linux/main.cpp index 1a83052fa6ab46..5d390b5d888f31 100644 --- a/examples/ota-requestor-app/linux/main.cpp +++ b/examples/ota-requestor-app/linux/main.cpp @@ -286,10 +286,7 @@ void SendQueryImageCommand(chip::NodeId peerNodeId = providerNodeId, chip::Fabri IPAddress ipAddr; IPAddress::FromString(ipAddress, ipAddr); PeerAddress addr = PeerAddress::UDP(ipAddr, CHIP_PORT); - uint32_t idleInterval; - uint32_t activeInterval; - operationalDeviceProxy->GetMRPIntervals(idleInterval, activeInterval); - operationalDeviceProxy->UpdateDeviceData(addr, idleInterval, activeInterval); + operationalDeviceProxy->UpdateDeviceData(addr, operationalDeviceProxy->GetMRPConfig()); CHIP_ERROR err = operationalDeviceProxy->Connect(&mOnConnectedCallback, &mOnConnectionFailureCallback); if (err != CHIP_NO_ERROR) diff --git a/src/app/CASESessionManager.cpp b/src/app/CASESessionManager.cpp index a4d3d982f3698f..b14542272e3414 100644 --- a/src/app/CASESessionManager.cpp +++ b/src/app/CASESessionManager.cpp @@ -85,9 +85,7 @@ void CASESessionManager::OnNodeIdResolved(const Dnssd::ResolvedNodeData & nodeDa VerifyOrReturn(session != nullptr, ChipLogDetail(Controller, "OnNodeIdResolved was called for a device with no active sessions, ignoring it.")); - LogErrorOnFailure(session->UpdateDeviceData( - session->ToPeerAddress(nodeData), nodeData.GetMrpRetryIntervalIdle().ValueOr(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL), - nodeData.GetMrpRetryIntervalActive().ValueOr(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL))); + LogErrorOnFailure(session->UpdateDeviceData(session->ToPeerAddress(nodeData), nodeData.GetMRPConfig())); } void CASESessionManager::OnNodeIdResolutionFailed(const PeerId & peer, CHIP_ERROR error) diff --git a/src/app/DeviceProxy.h b/src/app/DeviceProxy.h index 87e2e1e8c6650b..c09b1705d95e33 100644 --- a/src/app/DeviceProxy.h +++ b/src/app/DeviceProxy.h @@ -81,13 +81,7 @@ class DLL_EXPORT DeviceProxy virtual bool IsActive() const { return true; } - uint32_t GetMRPIdleInterval() const { return mMrpIdleInterval; } - uint32_t GetMRPActiveInterval() const { return mMrpActiveInterval; } - void GetMRPIntervals(uint32_t & idleInterval, uint32_t & activeInterval) const - { - idleInterval = mMrpIdleInterval; - activeInterval = mMrpActiveInterval; - } + const ReliableMessageProtocolConfig & GetMRPConfig() const { return mMRPConfig; } protected: virtual bool IsSecureConnected() const = 0; @@ -96,8 +90,7 @@ class DLL_EXPORT DeviceProxy app::CHIPDeviceCallbacksMgr & mCallbacksMgr = app::CHIPDeviceCallbacksMgr::GetInstance(); - uint32_t mMrpIdleInterval = CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL; - uint32_t mMrpActiveInterval = CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL; + ReliableMessageProtocolConfig mMRPConfig = gDefaultMRPConfig; }; } // namespace chip diff --git a/src/app/OperationalDeviceProxy.cpp b/src/app/OperationalDeviceProxy.cpp index bf78d8b014c9a2..015a0a95233694 100644 --- a/src/app/OperationalDeviceProxy.cpp +++ b/src/app/OperationalDeviceProxy.cpp @@ -86,16 +86,15 @@ CHIP_ERROR OperationalDeviceProxy::Connect(Callback::Callback return err; } -CHIP_ERROR OperationalDeviceProxy::UpdateDeviceData(const Transport::PeerAddress & addr, uint32_t mrpIdleInterval, - uint32_t mrpActiveInterval) +CHIP_ERROR OperationalDeviceProxy::UpdateDeviceData(const Transport::PeerAddress & addr, + const ReliableMessageProtocolConfig & config) { VerifyOrReturnLogError(mState != State::Uninitialized, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; mDeviceAddress = addr; - mMrpIdleInterval = mrpIdleInterval; - mMrpActiveInterval = mrpActiveInterval; + mMRPConfig = config; if (mState == State::NeedsAddress) { @@ -121,7 +120,7 @@ CHIP_ERROR OperationalDeviceProxy::UpdateDeviceData(const Transport::PeerAddress if (secureSession != nullptr) { secureSession->SetPeerAddress(addr); - secureSession->SetMRPIntervals(mrpIdleInterval, mrpActiveInterval); + secureSession->SetMRPConfig(mMRPConfig); } } @@ -144,11 +143,9 @@ CHIP_ERROR OperationalDeviceProxy::EstablishConnection() { // Create a UnauthenticatedSession for CASE pairing. // Don't use mSecureSession here, because mSecureSession is for encrypted communication. - Optional session = mInitParams.sessionManager->CreateUnauthenticatedSession(mDeviceAddress); + Optional session = mInitParams.sessionManager->CreateUnauthenticatedSession(mDeviceAddress, mMRPConfig); VerifyOrReturnError(session.HasValue(), CHIP_ERROR_NO_MEMORY); - session.Value().GetUnauthenticatedSession()->SetMRPIntervals(mMrpIdleInterval, mMrpActiveInterval); - Messaging::ExchangeContext * exchange = mInitParams.exchangeMgr->NewContext(session.Value(), &mCASESession); VerifyOrReturnError(exchange != nullptr, CHIP_ERROR_INTERNAL); diff --git a/src/app/OperationalDeviceProxy.h b/src/app/OperationalDeviceProxy.h index a98b96d6f515ef..ee2496ec614a4b 100644 --- a/src/app/OperationalDeviceProxy.h +++ b/src/app/OperationalDeviceProxy.h @@ -119,8 +119,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, SessionReleaseDele { mDeviceAddress = ToPeerAddress(nodeResolutionData); - mMrpIdleInterval = nodeResolutionData.GetMrpRetryIntervalIdle().ValueOr(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL); - mMrpActiveInterval = nodeResolutionData.GetMrpRetryIntervalActive().ValueOr(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); + mMRPConfig = nodeResolutionData.GetMRPConfig(); if (mState == State::NeedsAddress) { @@ -141,7 +140,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, SessionReleaseDele * Since the device settings might have been moved from RAM to the persistent storage, the function * will load the device settings first, before making the changes. */ - CHIP_ERROR UpdateDeviceData(const Transport::PeerAddress & addr, uint32_t mrpIdleInterval, uint32_t mrpActiveInterval); + CHIP_ERROR UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config); PeerId GetPeerId() const { return mPeerId; } diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index 76f236847527ed..a9c1c6b78d006a 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -258,15 +258,13 @@ CHIP_ERROR DnssdServer::AdvertiseOperational() MutableByteSpan mac(macBuffer); chip::DeviceLayer::ConfigurationMgr().GetPrimaryMACAddress(mac); - const auto advertiseParameters = - chip::Dnssd::OperationalAdvertisingParameters() - .SetPeerId(fabricInfo.GetPeerId()) - .SetMac(mac) - .SetPort(GetSecuredPort()) - .SetMRPRetryIntervals(Optional(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL), - Optional(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL)) - .SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)) - .EnableIpV4(true); + const auto advertiseParameters = chip::Dnssd::OperationalAdvertisingParameters() + .SetPeerId(fabricInfo.GetPeerId()) + .SetMac(mac) + .SetPort(GetSecuredPort()) + .SetMRPConfig(gDefaultMRPConfig) + .SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)) + .EnableIpV4(true); auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance(); @@ -343,10 +341,7 @@ CHIP_ERROR DnssdServer::Advertise(bool commissionableNode, chip::Dnssd::Commissi advertiseParameters.SetRotatingId(chip::Optional::Value(rotatingDeviceIdHexBuffer)); #endif - advertiseParameters - .SetMRPRetryIntervals(Optional(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL), - Optional(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL)) - .SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)); + advertiseParameters.SetMRPConfig(gDefaultMRPConfig).SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)); if (mode != chip::Dnssd::CommissioningMode::kEnabledEnhanced) { diff --git a/src/channel/ChannelContext.cpp b/src/channel/ChannelContext.cpp index e6a88ecfb926ce..3e34a095cfc9a0 100644 --- a/src/channel/ChannelContext.cpp +++ b/src/channel/ChannelContext.cpp @@ -263,7 +263,7 @@ void ChannelContext::EnterCasePairingState() Transport::PeerAddress addr; addr.SetTransportType(Transport::Type::kUdp).SetIPAddress(prepare.mAddress); - auto session = mExchangeManager->GetSessionManager()->CreateUnauthenticatedSession(addr); + auto session = mExchangeManager->GetSessionManager()->CreateUnauthenticatedSession(addr, gDefaultMRPConfig); if (!session.HasValue()) { ExitCasePairingState(); @@ -271,8 +271,6 @@ void ChannelContext::EnterCasePairingState() EnterFailedState(CHIP_ERROR_NO_MEMORY); return; } - session.Value().GetUnauthenticatedSession()->SetMRPIntervals(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL, - CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); ExchangeContext * ctxt = mExchangeManager->NewContext(session.Value(), prepare.mCasePairingSession); VerifyOrReturn(ctxt != nullptr); diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 985f1f27de2049..e1be7c1d92116e 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -694,7 +694,6 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParam CHIP_ERROR err = CHIP_NO_ERROR; CommissioneeDeviceProxy * device = nullptr; Transport::PeerAddress peerAddress = Transport::PeerAddress::UDP(Inet::IPAddress::Any); - uint32_t mrpIdleInterval, mrpActiveInterval; Messaging::ExchangeContext * exchangeCtxt = nullptr; Optional session; @@ -789,12 +788,9 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParam } } #endif - session = mSystemState->SessionMgr()->CreateUnauthenticatedSession(params.GetPeerAddress()); - VerifyOrExit(session.HasValue(), err = CHIP_ERROR_NO_MEMORY); - // TODO: In some cases like PASE over IP, CRA and CRI values from commissionable node service should be used - device->GetMRPIntervals(mrpIdleInterval, mrpActiveInterval); - session.Value().GetUnauthenticatedSession()->SetMRPIntervals(mrpIdleInterval, mrpActiveInterval); + session = mSystemState->SessionMgr()->CreateUnauthenticatedSession(params.GetPeerAddress(), device->GetMRPConfig()); + VerifyOrExit(session.HasValue(), err = CHIP_ERROR_NO_MEMORY); exchangeCtxt = mSystemState->ExchangeMgr()->NewContext(session.Value(), &device->GetPairing()); VerifyOrExit(exchangeCtxt != nullptr, err = CHIP_ERROR_INTERNAL); diff --git a/src/controller/CommissioneeDeviceProxy.cpp b/src/controller/CommissioneeDeviceProxy.cpp index 02394d64090137..89cb5c08322772 100644 --- a/src/controller/CommissioneeDeviceProxy.cpp +++ b/src/controller/CommissioneeDeviceProxy.cpp @@ -112,15 +112,14 @@ CHIP_ERROR CommissioneeDeviceProxy::CloseSession() return CHIP_NO_ERROR; } -CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddress & addr, uint32_t mrpIdleInterval, - uint32_t mrpActiveInterval) +CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddress & addr, + const ReliableMessageProtocolConfig & config) { bool didLoad; mDeviceAddress = addr; - mMrpIdleInterval = mrpIdleInterval; - mMrpActiveInterval = mrpActiveInterval; + mMRPConfig = config; ReturnErrorOnFailure(LoadSecureSessionParametersIfNeeded(didLoad)); @@ -135,7 +134,7 @@ CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddres Transport::SecureSession * secureSession = mSessionManager->GetSecureSession(mSecureSession.Value()); secureSession->SetPeerAddress(addr); - secureSession->SetMRPIntervals(mrpIdleInterval, mrpActiveInterval); + secureSession->SetMRPConfig(config); return CHIP_NO_ERROR; } diff --git a/src/controller/CommissioneeDeviceProxy.h b/src/controller/CommissioneeDeviceProxy.h index e4a62c0d82cd68..b092224e0c9a8d 100644 --- a/src/controller/CommissioneeDeviceProxy.h +++ b/src/controller/CommissioneeDeviceProxy.h @@ -188,13 +188,12 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegat * Since the device settings might have been moved from RAM to the persistent storage, the function * will load the device settings first, before making the changes. * - * @param[in] addr Address of the device to be set. - * @param[in] mrpIdleInterval MRP idle retransmission interval of the device to be set. - * @param[in] mrpActiveInterval MRP active retransmision interval of the device to be set. + * @param[in] addr Address of the device to be set. + * @param[in] config MRP parameters * * @return CHIP_NO_ERROR if the data has been updated, an error code otherwise. */ - CHIP_ERROR UpdateDeviceData(const Transport::PeerAddress & addr, uint32_t mrpIdleInterval, uint32_t mrpActiveInterval); + CHIP_ERROR UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config); /** * @brief * Return whether the current device object is actively associated with a paired CHIP diff --git a/src/lib/core/Optional.h b/src/lib/core/Optional.h index c94edfb0d7fa30..cd1fa9cf2a2cf2 100644 --- a/src/lib/core/Optional.h +++ b/src/lib/core/Optional.h @@ -157,7 +157,14 @@ class Optional } /** Gets the current value of the optional. Valid IFF `HasValue`. */ - const T & Value() const + T & Value() & + { + VerifyOrDie(HasValue()); + return mValue.mData; + } + + /** Gets the current value of the optional. Valid IFF `HasValue`. */ + const T & Value() const & { VerifyOrDie(HasValue()); return mValue.mData; @@ -196,6 +203,12 @@ class Optional } mValue; }; +template +constexpr Optional> MakeOptional(T && value) +{ + return Optional>(InPlace, std::forward(value)); +} + template constexpr Optional MakeOptional(Args &&... args) { diff --git a/src/lib/dnssd/Advertiser.h b/src/lib/dnssd/Advertiser.h index 2f385c557a1ffe..59047049b8cff3 100644 --- a/src/lib/dnssd/Advertiser.h +++ b/src/lib/dnssd/Advertiser.h @@ -81,17 +81,12 @@ class BaseAdvertisingParams const chip::ByteSpan GetMac() const { return chip::ByteSpan(mMacStorage, mMacLength); } // Common Flags - Derived & SetMRPRetryIntervals(Optional intervalIdle, Optional intervalActive) + Derived & SetMRPConfig(const ReliableMessageProtocolConfig & config) { - mMrpRetryIntervalIdle = intervalIdle; - mMrpRetryIntervalActive = intervalActive; + mMRPConfig.SetValue(config); return *reinterpret_cast(this); } - void GetMRPRetryIntervals(Optional & intervalIdle, Optional & intervalActive) const - { - intervalIdle = mMrpRetryIntervalIdle; - intervalActive = mMrpRetryIntervalActive; - } + const Optional & GetMRPConfig() const { return mMRPConfig; } Derived & SetTcpSupported(Optional tcpSupported) { mTcpSupported = tcpSupported; @@ -104,8 +99,7 @@ class BaseAdvertisingParams bool mEnableIPv4 = true; uint8_t mMacStorage[kMaxMacSize] = {}; size_t mMacLength = 0; - Optional mMrpRetryIntervalIdle; - Optional mMrpRetryIntervalActive; + Optional mMRPConfig; Optional mTcpSupported; }; diff --git a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp index 74f94afc211948..9dfa7ed332915f 100644 --- a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp @@ -157,8 +157,7 @@ class AdvertiserMinMdns : public ServiceAdvertiser, CHIP_ERROR AddCommonTxtEntries(const BaseAdvertisingParams & params, CommonTxtEntryStorage & storage, char ** txtFields, size_t & numTxtFields) { - Optional mrpRetryIntervalIdle, mrpRetryIntervalActive; - params.GetMRPRetryIntervals(mrpRetryIntervalIdle, mrpRetryIntervalActive); + auto optionalMrp = params.GetMRPConfig(); // TODO: Issue #5833 - MRP retry intervals should be updated on the poll period value change or device type change. #if CHIP_DEVICE_CONFIG_ENABLE_SED chip::DeviceLayer::ConnectivityManager::SEDPollingConfig sedPollingConfig; @@ -166,44 +165,51 @@ class AdvertiserMinMdns : public ServiceAdvertiser, ReturnErrorOnFailure(chip::DeviceLayer::ConnectivityMgr().GetSEDPollingConfig(sedPollingConfig)); // Increment default MRP retry intervals by SED poll period to be on the safe side // and avoid unnecessary retransmissions. - if (mrpRetryIntervalIdle.HasValue()) + if (optionalMrp.HasValue()) { - mrpRetryIntervalIdle.SetValue(mrpRetryIntervalIdle.Value() + sedPollingConfig.SlowPollingIntervalMS); - } - if (mrpRetryIntervalActive.HasValue()) - { - mrpRetryIntervalActive.SetValue(mrpRetryIntervalActive.Value() + sedPollingConfig.FastPollingIntervalMS); + auto mrp = optionalMrp.Value(); + optionalMrp.SetValue(ReliableMessageProtocolConfig( + mrp.mIdleRetransTimeoutTick + + (sedPollingConfig.SlowPollingIntervalMS >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT), + mrp.mActiveRetransTimeoutTick + + (sedPollingConfig.FastPollingIntervalMS >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT))); } #endif - if (mrpRetryIntervalIdle.HasValue()) + if (optionalMrp.HasValue()) { - if (mrpRetryIntervalIdle.Value() > kMaxRetryInterval) + auto mrp = optionalMrp.Value(); { - ChipLogProgress(Discovery, - "MRP retry interval idle value exceeds allowed range of 1 hour, using maximum available"); - mrpRetryIntervalIdle.SetValue(kMaxRetryInterval); + if ((mrp.mIdleRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT) > kMaxRetryInterval) + { + ChipLogProgress(Discovery, + "MRP retry interval idle value exceeds allowed range of 1 hour, using maximum available"); + mrp.mIdleRetransTimeoutTick = kMaxRetryInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; + } + size_t writtenCharactersNumber = + snprintf(storage.mrpRetryIntervalIdleBuf, sizeof(storage.mrpRetryIntervalIdleBuf), "CRI=%" PRIu32, + mrp.mIdleRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT); + VerifyOrReturnError((writtenCharactersNumber > 0) && + (writtenCharactersNumber < sizeof(storage.mrpRetryIntervalIdleBuf)), + CHIP_ERROR_INVALID_STRING_LENGTH); + + txtFields[numTxtFields++] = storage.mrpRetryIntervalIdleBuf; } - size_t writtenCharactersNumber = snprintf(storage.mrpRetryIntervalIdleBuf, sizeof(storage.mrpRetryIntervalIdleBuf), - "CRI=%" PRIu32, mrpRetryIntervalIdle.Value()); - VerifyOrReturnError((writtenCharactersNumber > 0) && - (writtenCharactersNumber < sizeof(storage.mrpRetryIntervalIdleBuf)), - CHIP_ERROR_INVALID_STRING_LENGTH); - txtFields[numTxtFields++] = storage.mrpRetryIntervalIdleBuf; - } - if (mrpRetryIntervalActive.HasValue()) - { - if (mrpRetryIntervalActive.Value() > kMaxRetryInterval) + { - ChipLogProgress(Discovery, - "MRP retry interval active value exceeds allowed range of 1 hour, using maximum available"); - mrpRetryIntervalActive.SetValue(kMaxRetryInterval); + if ((mrp.mActiveRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT) > kMaxRetryInterval) + { + ChipLogProgress(Discovery, + "MRP retry interval active value exceeds allowed range of 1 hour, using maximum available"); + mrp.mActiveRetransTimeoutTick = kMaxRetryInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; + } + size_t writtenCharactersNumber = + snprintf(storage.mrpRetryIntervalActiveBuf, sizeof(storage.mrpRetryIntervalActiveBuf), "CRA=%" PRIu32, + mrp.mActiveRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT); + VerifyOrReturnError((writtenCharactersNumber > 0) && + (writtenCharactersNumber < sizeof(storage.mrpRetryIntervalActiveBuf)), + CHIP_ERROR_INVALID_STRING_LENGTH); + txtFields[numTxtFields++] = storage.mrpRetryIntervalActiveBuf; } - size_t writtenCharactersNumber = snprintf(storage.mrpRetryIntervalActiveBuf, sizeof(storage.mrpRetryIntervalActiveBuf), - "CRA=%" PRIu32, mrpRetryIntervalActive.Value()); - VerifyOrReturnError((writtenCharactersNumber > 0) && - (writtenCharactersNumber < sizeof(storage.mrpRetryIntervalActiveBuf)), - CHIP_ERROR_INVALID_STRING_LENGTH); - txtFields[numTxtFields++] = storage.mrpRetryIntervalActiveBuf; } if (params.GetTcpSupported().HasValue()) { diff --git a/src/lib/dnssd/BUILD.gn b/src/lib/dnssd/BUILD.gn index 90fb0bdd31c08a..4ad5559c9d455d 100644 --- a/src/lib/dnssd/BUILD.gn +++ b/src/lib/dnssd/BUILD.gn @@ -26,6 +26,7 @@ static_library("dnssd") { "${chip_root}/src/crypto", "${chip_root}/src/lib/core", "${chip_root}/src/lib/support", + "${chip_root}/src/messaging:messaging_mrp_config", ] sources = [ diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index c021e3d7ef7841..c6f55c85dc6777 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -128,8 +128,7 @@ CHIP_ERROR AddCommonTxtElements(const BaseAdvertisingParams & params, c char (&mrpRetryActiveStorage)[N_active], char (&tcpSupportedStorage)[N_tcp], TextEntry txtEntryStorage[], size_t & txtEntryIdx) { - Optional mrpRetryIntervalIdle, mrpRetryIntervalActive; - params.GetMRPRetryIntervals(mrpRetryIntervalIdle, mrpRetryIntervalActive); + auto optionalMrp = params.GetMRPConfig(); // TODO: Issue #5833 - MRP retry intervals should be updated on the poll period value // change or device type change. @@ -141,40 +140,46 @@ CHIP_ERROR AddCommonTxtElements(const BaseAdvertisingParams & params, c ReturnErrorOnFailure(chip::DeviceLayer::ConnectivityMgr().GetSEDPollingConfig(sedPollingConfig)); // Increment default MRP retry intervals by SED poll period to be on the safe side // and avoid unnecessary retransmissions. - if (mrpRetryIntervalIdle.HasValue()) + if (optionalMrp.HasValue()) { - mrpRetryIntervalIdle.SetValue(mrpRetryIntervalIdle.Value() + sedPollingConfig.SlowPollingIntervalMS); - } - if (mrpRetryIntervalActive.HasValue()) - { - mrpRetryIntervalActive.SetValue(mrpRetryIntervalActive.Value() + sedPollingConfig.FastPollingIntervalMS); + auto mrp = optionalMrp.Value(); + optionalMrp.SetValue(ReliableMessageProtocolConfig( + mrp.mIdleRetransTimeoutTick + (sedPollingConfig.SlowPollingIntervalMS >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT), + mrp.mActiveRetransTimeoutTick + + (sedPollingConfig.FastPollingIntervalMS >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT))); } #endif - if (mrpRetryIntervalIdle.HasValue()) + if (optionalMrp.HasValue()) { - if (mrpRetryIntervalIdle.Value() > kMaxRetryInterval) + auto mrp = optionalMrp.Value(); { - ChipLogProgress(Discovery, "MRP retry interval idle value exceeds allowed range of 1 hour, using maximum available"); - mrpRetryIntervalIdle.SetValue(kMaxRetryInterval); + if ((mrp.mIdleRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT) > kMaxRetryInterval) + { + ChipLogProgress(Discovery, + "MRP retry interval idle value exceeds allowed range of 1 hour, using maximum available"); + mrp.mIdleRetransTimeoutTick = kMaxRetryInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; + } + size_t writtenCharactersNumber = snprintf(mrpRetryIdleStorage, sizeof(mrpRetryIdleStorage), "%" PRIu32, + mrp.mIdleRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT); + VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber <= kTxtRetryIntervalIdleMaxLength), + CHIP_ERROR_INVALID_STRING_LENGTH); + txtEntryStorage[txtEntryIdx++] = { "CRI", Uint8::from_const_char(mrpRetryIdleStorage), strlen(mrpRetryIdleStorage) }; } - size_t writtenCharactersNumber = - snprintf(mrpRetryIdleStorage, sizeof(mrpRetryIdleStorage), "%" PRIu32, mrpRetryIntervalIdle.Value()); - VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber <= kTxtRetryIntervalIdleMaxLength), - CHIP_ERROR_INVALID_STRING_LENGTH); - txtEntryStorage[txtEntryIdx++] = { "CRI", Uint8::from_const_char(mrpRetryIdleStorage), strlen(mrpRetryIdleStorage) }; - } - if (mrpRetryIntervalActive.HasValue()) - { - if (mrpRetryIntervalActive.Value() > kMaxRetryInterval) + { - ChipLogProgress(Discovery, "MRP retry interval active value exceeds allowed range of 1 hour, using maximum available"); - mrpRetryIntervalActive.SetValue(kMaxRetryInterval); + if ((mrp.mActiveRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT) > kMaxRetryInterval) + { + ChipLogProgress(Discovery, + "MRP retry interval active value exceeds allowed range of 1 hour, using maximum available"); + mrp.mActiveRetransTimeoutTick = kMaxRetryInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; + } + size_t writtenCharactersNumber = snprintf(mrpRetryActiveStorage, sizeof(mrpRetryActiveStorage), "%" PRIu32, + mrp.mActiveRetransTimeoutTick << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT); + VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber <= kTxtRetryIntervalActiveMaxLength), + CHIP_ERROR_INVALID_STRING_LENGTH); + txtEntryStorage[txtEntryIdx++] = { "CRA", Uint8::from_const_char(mrpRetryActiveStorage), + strlen(mrpRetryActiveStorage) }; } - size_t writtenCharactersNumber = - snprintf(mrpRetryActiveStorage, sizeof(mrpRetryActiveStorage), "%" PRIu32, mrpRetryIntervalActive.Value()); - VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber <= kTxtRetryIntervalActiveMaxLength), - CHIP_ERROR_INVALID_STRING_LENGTH); - txtEntryStorage[txtEntryIdx++] = { "CRA", Uint8::from_const_char(mrpRetryActiveStorage), strlen(mrpRetryActiveStorage) }; } if (params.GetTcpSupported().HasValue()) { diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index 91d99445070148..d44c55b9a6fc1b 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -29,12 +29,11 @@ #include #include #include +#include namespace chip { namespace Dnssd { -constexpr uint32_t kUndefinedRetryInterval = std::numeric_limits::max(); - struct ResolvedNodeData { // TODO: use pool to allow dynamic @@ -55,17 +54,17 @@ struct ResolvedNodeData #endif // CHIP_PROGRESS_LOGGING } - Optional GetMrpRetryIntervalIdle() const + ReliableMessageProtocolConfig GetMRPConfig() const { - return mMrpRetryIntervalIdle != kUndefinedRetryInterval ? Optional{ mMrpRetryIntervalIdle } - : Optional{}; - } - - Optional GetMrpRetryIntervalActive() const - { - return mMrpRetryIntervalActive != kUndefinedRetryInterval ? Optional{ mMrpRetryIntervalActive } - : Optional{}; + return ReliableMessageProtocolConfig(GetMrpRetryIntervalIdle().ValueOr(gDefaultMRPConfig.mIdleRetransTimeoutTick + << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT) >> + CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, + GetMrpRetryIntervalActive().ValueOr(gDefaultMRPConfig.mActiveRetransTimeoutTick + << CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT) >> + CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT); } + Optional GetMrpRetryIntervalIdle() const { return mMrpRetryIntervalIdle; } + Optional GetMrpRetryIntervalActive() const { return mMrpRetryIntervalActive; } PeerId mPeerId; size_t mNumIPs = 0; @@ -74,8 +73,8 @@ struct ResolvedNodeData uint16_t mPort = 0; char mHostName[kHostNameMaxLength + 1] = {}; bool mSupportsTcp = false; - uint32_t mMrpRetryIntervalIdle = kUndefinedRetryInterval; - uint32_t mMrpRetryIntervalActive = kUndefinedRetryInterval; + Optional mMrpRetryIntervalIdle; + Optional mMrpRetryIntervalActive; System::Clock::Timestamp mExpiryTime; }; @@ -101,8 +100,8 @@ struct DiscoveredNodeData uint16_t pairingHint; char pairingInstruction[kMaxPairingInstructionLen + 1]; bool supportsTcp; - uint32_t mrpRetryIntervalIdle; - uint32_t mrpRetryIntervalActive; + Optional mrpRetryIntervalIdle; + Optional mrpRetryIntervalActive; uint16_t port; int numIPs; Inet::InterfaceId interfaceId[kMaxIPAddresses]; @@ -123,8 +122,8 @@ struct DiscoveredNodeData memset(pairingInstruction, 0, sizeof(pairingInstruction)); pairingHint = 0; supportsTcp = false; - mrpRetryIntervalIdle = kUndefinedRetryInterval; - mrpRetryIntervalActive = kUndefinedRetryInterval; + mrpRetryIntervalIdle = NullOptional; + mrpRetryIntervalActive = NullOptional; numIPs = 0; port = 0; for (int i = 0; i < kMaxIPAddresses; ++i) @@ -136,17 +135,8 @@ struct DiscoveredNodeData bool IsHost(const char * host) const { return strcmp(host, hostName) == 0; } bool IsInstanceName(const char * instance) const { return strcmp(instance, instanceName) == 0; } bool IsValid() const { return !IsHost("") && ipAddress[0] != chip::Inet::IPAddress::Any; } - - Optional GetMrpRetryIntervalIdle() const - { - return mrpRetryIntervalIdle != kUndefinedRetryInterval ? Optional{ mrpRetryIntervalIdle } : Optional{}; - } - - Optional GetMrpRetryIntervalActive() const - { - return mrpRetryIntervalActive != kUndefinedRetryInterval ? Optional{ mrpRetryIntervalActive } - : Optional{}; - } + Optional GetMrpRetryIntervalIdle() const { return mrpRetryIntervalIdle; } + Optional GetMrpRetryIntervalActive() const { return mrpRetryIntervalActive; } void LogDetail() const { diff --git a/src/lib/dnssd/TxtFields.cpp b/src/lib/dnssd/TxtFields.cpp index 59abac1e1fa8b4..3cf23a2d300c62 100644 --- a/src/lib/dnssd/TxtFields.cpp +++ b/src/lib/dnssd/TxtFields.cpp @@ -171,14 +171,15 @@ void GetPairingInstruction(const ByteSpan & value, char * pairingInstruction) Platform::CopyString(pairingInstruction, kMaxPairingInstructionLen + 1, value); } -uint32_t GetRetryInterval(const ByteSpan & value) +Optional GetRetryInterval(const ByteSpan & value) { - const auto retryInterval = MakeU32FromAsciiDecimal(value, kUndefinedRetryInterval); + const auto undefined = std::numeric_limits::max(); + const auto retryInterval = MakeU32FromAsciiDecimal(value, undefined); - if (retryInterval != kUndefinedRetryInterval && retryInterval <= kMaxRetryInterval) - return retryInterval; + if (retryInterval != undefined && retryInterval <= kMaxRetryInterval) + return MakeOptional(retryInterval); - return kUndefinedRetryInterval; + return NullOptional; } TxtFieldKey GetTxtFieldKey(const ByteSpan & key) diff --git a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp index 9565c090c4c58f..efc12cee33f1ca 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp @@ -78,7 +78,8 @@ OperationalAdvertisingParameters operationalParams1 = .SetPort(CHIP_PORT) .EnableIpV4(true) .SetTcpSupported(chip::Optional(false)) - .SetMRPRetryIntervals(chip::Optional(32), chip::Optional(33)); + .SetMRPConfig(ReliableMessageProtocolConfig(64 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, + 128 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT)); OperationalAdvertisingParameters operationalParams2 = OperationalAdvertisingParameters().SetPeerId(kPeerId2).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true); OperationalAdvertisingParameters operationalParams3 = @@ -89,7 +90,7 @@ OperationalAdvertisingParameters operationalParams5 = OperationalAdvertisingParameters().SetPeerId(kPeerId5).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true); OperationalAdvertisingParameters operationalParams6 = OperationalAdvertisingParameters().SetPeerId(kPeerId6).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true); -const QNamePart txtOperational1Parts[] = { "CRI=32", "CRA=33", "T=0" }; +const QNamePart txtOperational1Parts[] = { "CRI=64", "CRA=128", "T=0" }; PtrResourceRecord ptrOperationalService = PtrResourceRecord(kDnsSdQueryName, kMatterOperationalQueryName); PtrResourceRecord ptrOperational1 = PtrResourceRecord(kMatterOperationalQueryName, kInstanceName1); SrvResourceRecord srvOperational1 = SrvResourceRecord(kInstanceName1, kHostnameName, CHIP_PORT); @@ -178,8 +179,9 @@ CommissionAdvertisingParameters commissionableNodeParamsLargeEnhanced = .SetProductId(chip::Optional(897)) .SetRotatingId(chip::Optional("id_that_spins")) .SetTcpSupported(chip::Optional(true)) - .SetMRPRetryIntervals(chip::Optional(3600000), - chip::Optional(3600005)); // 3600005 is more than the max so should be adjusted down + // 3600005 is more than the max so should be adjusted down + .SetMRPConfig(ReliableMessageProtocolConfig(3600000 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, + 3600064 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT)); QNamePart txtCommissionableNodeParamsLargeEnhancedParts[] = { "D=22", "VP=555+897", "CM=2", "DT=25", "DN=testy-test", "RI=id_that_spins", "PI=Pair me", "PH=3", "CRA=3600000", "CRI=3600000", "T=1" }; diff --git a/src/lib/dnssd/platform/tests/TestPlatform.cpp b/src/lib/dnssd/platform/tests/TestPlatform.cpp index bb65565d37a150..acbde364d97ae5 100644 --- a/src/lib/dnssd/platform/tests/TestPlatform.cpp +++ b/src/lib/dnssd/platform/tests/TestPlatform.cpp @@ -46,21 +46,23 @@ test::ExpectedCall operationalCall1 = test::ExpectedCall() .SetInstanceName("BEEFBEEFF00DF00D-1111222233334444") .SetHostName(host) .AddSubtype("_IBEEFBEEFF00DF00D"); -OperationalAdvertisingParameters operationalParams2 = OperationalAdvertisingParameters() - .SetPeerId(kPeerId2) - .SetMac(ByteSpan(kMac)) - .SetPort(CHIP_PORT) - .EnableIpV4(true) - .SetMRPRetryIntervals(Optional(32), Optional(33)) - .SetTcpSupported(Optional(true)); +OperationalAdvertisingParameters operationalParams2 = + OperationalAdvertisingParameters() + .SetPeerId(kPeerId2) + .SetMac(ByteSpan(kMac)) + .SetPort(CHIP_PORT) + .EnableIpV4(true) + .SetMRPConfig(ReliableMessageProtocolConfig(64 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, + 128 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT)) + .SetTcpSupported(Optional(true)); test::ExpectedCall operationalCall2 = test::ExpectedCall() .SetProtocol(DnssdServiceProtocol::kDnssdProtocolTcp) .SetServiceName("_matter") .SetInstanceName("5555666677778888-1212343456567878") .SetHostName(host) .AddSubtype("_I5555666677778888") - .AddTxt("CRI", "32") - .AddTxt("CRA", "33") + .AddTxt("CRI", "64") + .AddTxt("CRA", "128") .AddTxt("T", "1"); CommissionAdvertisingParameters commissionableNodeParamsSmall = @@ -94,9 +96,9 @@ CommissionAdvertisingParameters commissionableNodeParamsLargeBasic = .SetProductId(chip::Optional(897)) .SetRotatingId(chip::Optional("id_that_spins")) .SetTcpSupported(chip::Optional(true)) - .SetMRPRetryIntervals( - chip::Optional(3600000), - chip::Optional(3600005)); // 3600005 is over the max, so this should be adjusted by the platform + // 3600005 is over the max, so this should be adjusted by the platform + .SetMRPConfig(ReliableMessageProtocolConfig(3600000 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, + 3600064 >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT)); test::ExpectedCall commissionableLargeBasic = test::ExpectedCall() .SetProtocol(DnssdServiceProtocol::kDnssdProtocolUdp) diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index 68140d4b3f9a55..aa3a28d9b78b3d 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -281,9 +281,8 @@ bool NodeDataIsEmpty(const DiscoveredNodeData & node) { if (node.longDiscriminator != 0 || node.vendorId != 0 || node.productId != 0 || node.commissioningMode != 0 || - node.deviceType != 0 || node.rotatingIdLen != 0 || node.pairingHint != 0 || - node.mrpRetryIntervalIdle != kUndefinedRetryInterval || node.mrpRetryIntervalActive != kUndefinedRetryInterval || - node.supportsTcp) + node.deviceType != 0 || node.rotatingIdLen != 0 || node.pairingHint != 0 || node.mrpRetryIntervalIdle.HasValue() || + node.mrpRetryIntervalActive.HasValue() || node.supportsTcp) { return false; } @@ -381,28 +380,27 @@ void TestFillDiscoveredNodeDataFromTxt(nlTestSuite * inSuite, void * inContext) bool NodeDataIsEmpty(const ResolvedNodeData & nodeData) { return nodeData.mPeerId == PeerId{} && nodeData.mNumIPs == 0 && nodeData.mPort == 0 && - nodeData.mMrpRetryIntervalIdle == kUndefinedRetryInterval && nodeData.mMrpRetryIntervalActive == kUndefinedRetryInterval && - !nodeData.mSupportsTcp; + !nodeData.mMrpRetryIntervalIdle.HasValue() && !nodeData.mMrpRetryIntervalActive.HasValue() && !nodeData.mSupportsTcp; } void ResetRetryIntervalIdle(DiscoveredNodeData & nodeData) { - nodeData.mrpRetryIntervalIdle = kUndefinedRetryInterval; + nodeData.mrpRetryIntervalIdle.ClearValue(); } void ResetRetryIntervalIdle(ResolvedNodeData & nodeData) { - nodeData.mMrpRetryIntervalIdle = kUndefinedRetryInterval; + nodeData.mMrpRetryIntervalIdle.ClearValue(); } void ResetRetryIntervalActive(DiscoveredNodeData & nodeData) { - nodeData.mrpRetryIntervalActive = kUndefinedRetryInterval; + nodeData.mrpRetryIntervalActive.ClearValue(); } void ResetRetryIntervalActive(ResolvedNodeData & nodeData) { - nodeData.mMrpRetryIntervalActive = kUndefinedRetryInterval; + nodeData.mMrpRetryIntervalActive.ClearValue(); } // Test CRI diff --git a/src/lib/shell/commands/Ota.cpp b/src/lib/shell/commands/Ota.cpp index 4d0ed87dd3443d..d6fa03951b3c08 100644 --- a/src/lib/shell/commands/Ota.cpp +++ b/src/lib/shell/commands/Ota.cpp @@ -287,8 +287,7 @@ void ConnectDeviceAsync(intptr_t) OperationalDeviceProxy * deviceProxy = sOtaContext.deviceProxy; VerifyOrReturn(deviceProxy != nullptr); - deviceProxy->UpdateDeviceData(sOtaContext.providerAddress, deviceProxy->GetMRPIdleInterval(), - deviceProxy->GetMRPActiveInterval()); + deviceProxy->UpdateDeviceData(sOtaContext.providerAddress, deviceProxy->GetMRPConfig()); deviceProxy->Connect(&successCallback, &failureCallback); } diff --git a/src/messaging/BUILD.gn b/src/messaging/BUILD.gn index b96b98b823dbeb..5e596b615ac596 100644 --- a/src/messaging/BUILD.gn +++ b/src/messaging/BUILD.gn @@ -27,6 +27,12 @@ if (chip_case_retry_delta != "") { ] } +source_set("messaging_mrp_config") { + sources = [ "ReliableMessageProtocolConfig.h" ] + + public_deps = [ "${chip_root}/src/system" ] +} + static_library("messaging") { output_name = "libMessagingLayer" @@ -47,12 +53,13 @@ static_library("messaging") { "ReliableMessageContext.h", "ReliableMessageMgr.cpp", "ReliableMessageMgr.h", - "ReliableMessageProtocolConfig.h", + "ReliableMessageProtocolConfig.cpp", ] cflags = [ "-Wconversion" ] public_deps = [ + ":messaging_mrp_config", "${chip_root}/src/crypto", "${chip_root}/src/inet", "${chip_root}/src/lib/core", diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index b7ca10169f56dc..de7760bd8c813e 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -200,7 +200,7 @@ void ExchangeContext::DoClose(bool clearRetransTable) // needs to clear the MRP retransmission table immediately. if (clearRetransTable) { - mExchangeMgr->GetReliableMessageMgr()->ClearRetransTable(static_cast(this)); + mExchangeMgr->GetReliableMessageMgr()->ClearRetransTable(this); } // Cancel the response timer. @@ -539,5 +539,11 @@ System::Clock::Milliseconds32 ExchangeContext::GetAckTimeout() } return timeout; } + +const ReliableMessageProtocolConfig & ExchangeContext::GetMRPConfig() const +{ + return GetSessionHandle().GetMRPConfig(GetExchangeMgr()->GetSessionManager()); +} + } // namespace Messaging } // namespace chip diff --git a/src/messaging/ExchangeContext.h b/src/messaging/ExchangeContext.h index 0b5e18e4f69475..d7570ed14f8e07 100644 --- a/src/messaging/ExchangeContext.h +++ b/src/messaging/ExchangeContext.h @@ -151,7 +151,7 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, public Referen ExchangeMessageDispatch * GetMessageDispatch() { return mDispatch; } - SessionHandle GetSessionHandle() { return mSession.Value(); } + SessionHandle GetSessionHandle() const { return mSession.Value(); } bool HasSessionHandle() const { return mSession.HasValue(); } uint16_t GetExchangeId() const { return mExchangeId; } @@ -166,6 +166,7 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, public Referen void SetResponseTimeout(Timeout timeout); + // TODO: move following 5 functions into SessionHandle once we can access session vars w/o using a SessionManager /* * Get the overall acknowledge timeout period for the underneath transport(MRP+UDP/TCP) */ @@ -174,6 +175,8 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, public Referen bool IsUDPTransport(); bool IsTCPTransport(); bool IsBLETransport(); + // Helper function for easily accessing MRP config + const ReliableMessageProtocolConfig & GetMRPConfig() const; private: Timeout mResponseTimeout{ 0 }; // Maximum time to wait for response (in milliseconds); 0 disables response timeout. diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index a8f986b5ab50b7..e0b53dd6e17d30 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -119,17 +119,7 @@ CHIP_ERROR ExchangeManager::Shutdown() ExchangeContext * ExchangeManager::NewContext(SessionHandle session, ExchangeDelegate * delegate) { ExchangeContext * context = mContextPool.CreateObject(this, mNextExchangeId++, session, true, delegate); - - uint32_t mrpIdleInterval = CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL; - uint32_t mrpActiveInterval = CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL; - - session.GetMRPIntervals(GetSessionManager(), mrpIdleInterval, mrpActiveInterval); - - ReliableMessageProtocolConfig mrpConfig; - mrpConfig.mIdleRetransTimeoutTick = mrpIdleInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; - mrpConfig.mActiveRetransTimeoutTick = mrpActiveInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; - context->GetReliableMessageContext()->SetConfig(mrpConfig); - + context->GetReliableMessageContext()->SetConfig(session.GetMRPConfig(GetSessionManager())); return context; } diff --git a/src/messaging/ReliableMessageContext.cpp b/src/messaging/ReliableMessageContext.cpp index 9fa465aabda2d6..baabb4acc4ef20 100644 --- a/src/messaging/ReliableMessageContext.cpp +++ b/src/messaging/ReliableMessageContext.cpp @@ -39,8 +39,7 @@ namespace chip { namespace Messaging { -ReliableMessageContext::ReliableMessageContext() : - mConfig(gDefaultReliableMessageProtocolConfig), mNextAckTimeTick(0), mPendingPeerAckMessageCounter(0) +ReliableMessageContext::ReliableMessageContext() : mConfig(gDefaultMRPConfig), mNextAckTimeTick(0), mPendingPeerAckMessageCounter(0) {} bool ReliableMessageContext::AutoRequestAck() const diff --git a/src/messaging/ReliableMessageContext.h b/src/messaging/ReliableMessageContext.h index 4ced8884e02ce2..2869724d1d1f6a 100644 --- a/src/messaging/ReliableMessageContext.h +++ b/src/messaging/ReliableMessageContext.h @@ -26,12 +26,11 @@ #include #include -#include - #include #include #include #include +#include #include #include diff --git a/src/messaging/ReliableMessageProtocolConfig.cpp b/src/messaging/ReliableMessageProtocolConfig.cpp new file mode 100644 index 00000000000000..e373b0c4f3dff5 --- /dev/null +++ b/src/messaging/ReliableMessageProtocolConfig.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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 the configuration parameters that are required + * for the CHIP Reliable Messaging Protocol. + * + */ + +#include + +#include + +namespace chip { + +using namespace System::Clock::Literals; + +const ReliableMessageProtocolConfig + gDefaultMRPConfig(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, + CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT); + +} // namespace chip diff --git a/src/messaging/ReliableMessageProtocolConfig.h b/src/messaging/ReliableMessageProtocolConfig.h index fda12268157077..d2bb05ffe20a84 100644 --- a/src/messaging/ReliableMessageProtocolConfig.h +++ b/src/messaging/ReliableMessageProtocolConfig.h @@ -27,8 +27,9 @@ #include +#include + namespace chip { -namespace Messaging { /** * @def CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT @@ -118,16 +119,14 @@ namespace Messaging { */ struct ReliableMessageProtocolConfig { + ReliableMessageProtocolConfig(uint32_t idleInterval, uint32_t activeInterval) : + mIdleRetransTimeoutTick(idleInterval), mActiveRetransTimeoutTick(activeInterval) + {} + uint32_t mIdleRetransTimeoutTick; /**< Configurable timeout in msec for retransmission of the first sent message. */ uint32_t mActiveRetransTimeoutTick; /**< Configurable timeout in msec for retransmission of all subsequent messages. */ }; -const ReliableMessageProtocolConfig gDefaultReliableMessageProtocolConfig = { - CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, - CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT -}; - -// clang-format on +extern const ReliableMessageProtocolConfig gDefaultMRPConfig; -} // namespace Messaging } // namespace chip diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp index fa09f93cefcd4a..5e9743556bedd1 100644 --- a/src/messaging/tests/MessagingContext.cpp +++ b/src/messaging/tests/MessagingContext.cpp @@ -72,12 +72,14 @@ SessionHandle MessagingContext::GetSessionBobToFriends() Messaging::ExchangeContext * MessagingContext::NewUnauthenticatedExchangeToAlice(Messaging::ExchangeDelegate * delegate) { - return mExchangeManager.NewContext(mSessionManager.CreateUnauthenticatedSession(mAliceAddress).Value(), delegate); + return mExchangeManager.NewContext(mSessionManager.CreateUnauthenticatedSession(mAliceAddress, gDefaultMRPConfig).Value(), + delegate); } Messaging::ExchangeContext * MessagingContext::NewUnauthenticatedExchangeToBob(Messaging::ExchangeDelegate * delegate) { - return mExchangeManager.NewContext(mSessionManager.CreateUnauthenticatedSession(mBobAddress).Value(), delegate); + return mExchangeManager.NewContext(mSessionManager.CreateUnauthenticatedSession(mBobAddress, gDefaultMRPConfig).Value(), + delegate); } Messaging::ExchangeContext * MessagingContext::NewExchangeToAlice(Messaging::ExchangeDelegate * delegate) diff --git a/src/transport/PairingSession.h b/src/transport/PairingSession.h index cf99a76f719492..b1da8ea1a13609 100644 --- a/src/transport/PairingSession.h +++ b/src/transport/PairingSession.h @@ -83,6 +83,16 @@ class DLL_EXPORT PairingSession return LocalSessionMessageCounter::kInitialValue; } + /** + * @brief + * Get the value of peer session counter which is synced during session establishment + */ + virtual const ReliableMessageProtocolConfig & GetMRPConfig() const + { + // TODO(#6652): This is a stub implementation, should be replaced by the real one when CASE and PASE is completed + return gDefaultMRPConfig; + } + virtual const char * GetI2RSessionInfo() const = 0; virtual const char * GetR2ISessionInfo() const = 0; diff --git a/src/transport/SecureSession.h b/src/transport/SecureSession.h index 9c8ed346d957db..733f1a9ded6bcd 100644 --- a/src/transport/SecureSession.h +++ b/src/transport/SecureSession.h @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include #include @@ -50,9 +51,9 @@ class SecureSession { public: SecureSession(uint16_t localSessionId, NodeId peerNodeId, uint16_t peerSessionId, FabricIndex fabric, - System::Clock::Timestamp currentTime) : + const ReliableMessageProtocolConfig & config, System::Clock::Timestamp currentTime) : mPeerNodeId(peerNodeId), - mLocalSessionId(localSessionId), mPeerSessionId(peerSessionId), mFabric(fabric) + mLocalSessionId(localSessionId), mPeerSessionId(peerSessionId), mFabric(fabric), mMRPConfig(config) { SetLastActivityTime(currentTime); } @@ -68,17 +69,9 @@ class SecureSession NodeId GetPeerNodeId() const { return mPeerNodeId; } - void GetMRPIntervals(uint32_t & idleInterval, uint32_t & activeInterval) - { - idleInterval = mMRPIdleInterval; - activeInterval = mMRPActiveInterval; - } + void SetMRPConfig(const ReliableMessageProtocolConfig & config) { mMRPConfig = config; } - void SetMRPIntervals(uint32_t idleInterval, uint32_t activeInterval) - { - mMRPIdleInterval = idleInterval; - mMRPActiveInterval = activeInterval; - } + const ReliableMessageProtocolConfig & GetMRPConfig() const { return mMRPConfig; } uint16_t GetLocalSessionId() const { return mLocalSessionId; } uint16_t GetPeerSessionId() const { return mPeerSessionId; } @@ -110,9 +103,8 @@ class SecureSession const FabricIndex mFabric; PeerAddress mPeerAddress; - System::Clock::Timestamp mLastActivityTime = System::Clock::kZero; - uint32_t mMRPIdleInterval = 0; - uint32_t mMRPActiveInterval = 0; + System::Clock::Timestamp mLastActivityTime; + ReliableMessageProtocolConfig mMRPConfig; CryptoContext mCryptoContext; SessionMessageCounter mSessionMessageCounter; }; diff --git a/src/transport/SecureSessionTable.h b/src/transport/SecureSessionTable.h index d2745aa013aa2e..85a709bc81b027 100644 --- a/src/transport/SecureSessionTable.h +++ b/src/transport/SecureSessionTable.h @@ -55,9 +55,11 @@ class SecureSessionTable * has been reached (with CHIP_ERROR_NO_MEMORY). */ CHECK_RETURN_VALUE - SecureSession * CreateNewSecureSession(uint16_t localSessionId, NodeId peerNodeId, uint16_t peerSessionId, FabricIndex fabric) + SecureSession * CreateNewSecureSession(uint16_t localSessionId, NodeId peerNodeId, uint16_t peerSessionId, FabricIndex fabric, + const ReliableMessageProtocolConfig & config) { - return mEntries.CreateObject(localSessionId, peerNodeId, peerSessionId, fabric, mTimeSource.GetMonotonicTimestamp()); + return mEntries.CreateObject(localSessionId, peerNodeId, peerSessionId, fabric, config, + mTimeSource.GetMonotonicTimestamp()); } void ReleaseSession(SecureSession * session) { mEntries.ReleaseObject(session); } diff --git a/src/transport/SessionHandle.cpp b/src/transport/SessionHandle.cpp index 9865eb8d71321f..ea71f603b32e29 100644 --- a/src/transport/SessionHandle.cpp +++ b/src/transport/SessionHandle.cpp @@ -39,23 +39,37 @@ const PeerAddress * SessionHandle::GetPeerAddress(SessionManager * sessionManage return &GetUnauthenticatedSession()->GetPeerAddress(); } -CHIP_ERROR SessionHandle::GetMRPIntervals(SessionManager * sessionManager, uint32_t & mrpIdleInterval, uint32_t & mrpActiveInterval) +const ReliableMessageProtocolConfig & SessionHandle::GetMRPConfig(SessionManager * sessionManager) const { if (IsSecure()) { SecureSession * secureSession = sessionManager->GetSecureSession(*this); if (secureSession == nullptr) { - return CHIP_ERROR_INVALID_ARGUMENT; + return gDefaultMRPConfig; } - secureSession->GetMRPIntervals(mrpIdleInterval, mrpActiveInterval); - - return CHIP_NO_ERROR; + return secureSession->GetMRPConfig(); } + else + { + return GetUnauthenticatedSession()->GetMRPConfig(); + } +} - GetUnauthenticatedSession()->GetMRPIntervals(mrpIdleInterval, mrpActiveInterval); - - return CHIP_NO_ERROR; +void SessionHandle::SetMRPConfig(SessionManager * sessionManager, const ReliableMessageProtocolConfig & config) +{ + if (IsSecure()) + { + SecureSession * secureSession = sessionManager->GetSecureSession(*this); + if (secureSession != nullptr) + { + secureSession->SetMRPConfig(config); + } + } + else + { + return GetUnauthenticatedSession()->SetMRPConfig(config); + } } } // namespace chip diff --git a/src/transport/SessionHandle.h b/src/transport/SessionHandle.h index f65a3b2a88908e..d0186cc16941db 100644 --- a/src/transport/SessionHandle.h +++ b/src/transport/SessionHandle.h @@ -84,7 +84,8 @@ class SessionHandle // torn down, at the very least. const Transport::PeerAddress * GetPeerAddress(SessionManager * sessionManager) const; - CHIP_ERROR GetMRPIntervals(SessionManager * sessionManager, uint32_t & mrpIdleInterval, uint32_t & mrpActiveInterval); + const ReliableMessageProtocolConfig & GetMRPConfig(SessionManager * sessionManager) const; + void SetMRPConfig(SessionManager * sessionManager, const ReliableMessageProtocolConfig & config); Transport::UnauthenticatedSessionHandle GetUnauthenticatedSession() const { return mUnauthenticatedSessionHandle.Value(); } diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index 5688d6eef84bcb..8d6bc02a86352a 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -289,7 +289,7 @@ CHIP_ERROR SessionManager::NewPairing(const Optional & p ChipLogDetail(Inet, "New secure session created for device 0x" ChipLogFormatX64 ", key %d!!", ChipLogValueX64(peerNodeId), peerSessionId); - session = mSecureSessions.CreateNewSecureSession(localSessionId, peerNodeId, peerSessionId, fabric); + session = mSecureSessions.CreateNewSecureSession(localSessionId, peerNodeId, peerSessionId, fabric, pairing->GetMRPConfig()); ReturnErrorCodeIf(session == nullptr, CHIP_ERROR_NO_MEMORY); if (peerAddr.HasValue() && peerAddr.Value().GetIPAddress() != Inet::IPAddress::Any) @@ -307,8 +307,6 @@ CHIP_ERROR SessionManager::NewPairing(const Optional & p return CHIP_ERROR_INVALID_ARGUMENT; } - session->SetMRPIntervals(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); - ReturnErrorOnFailure(pairing->DeriveSecureSession(session->GetCryptoContext(), direction)); session->GetSessionMessageCounter().GetPeerMessageCounter().SetCounter(pairing->GetPeerCounter()); @@ -363,7 +361,8 @@ void SessionManager::OnMessageReceived(const PeerAddress & peerAddress, System:: void SessionManager::MessageDispatch(const PacketHeader & packetHeader, const Transport::PeerAddress & peerAddress, System::PacketBufferHandle && msg) { - Optional optionalSession = mUnauthenticatedSessions.FindOrAllocateEntry(peerAddress); + Optional optionalSession = + mUnauthenticatedSessions.FindOrAllocateEntry(peerAddress, gDefaultMRPConfig); if (!optionalSession.HasValue()) { ChipLogError(Inet, "UnauthenticatedSession exhausted"); diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index 490ac37e6715a6..7112542593c784 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -248,9 +249,11 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate */ void OnMessageReceived(const Transport::PeerAddress & source, System::PacketBufferHandle && msgBuf) override; - Optional CreateUnauthenticatedSession(const Transport::PeerAddress & peerAddress) + Optional CreateUnauthenticatedSession(const Transport::PeerAddress & peerAddress, + const ReliableMessageProtocolConfig & config) { - Optional session = mUnauthenticatedSessions.FindOrAllocateEntry(peerAddress); + Optional session = + mUnauthenticatedSessions.FindOrAllocateEntry(peerAddress, config); return session.HasValue() ? MakeOptional(session.Value()) : NullOptional; } diff --git a/src/transport/UnauthenticatedSessionTable.h b/src/transport/UnauthenticatedSessionTable.h index b121edd29b8f61..c265d43fe249e7 100644 --- a/src/transport/UnauthenticatedSessionTable.h +++ b/src/transport/UnauthenticatedSessionTable.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,9 @@ class UnauthenticatedSessionDeleter class UnauthenticatedSession : public ReferenceCounted { public: - UnauthenticatedSession(const PeerAddress & address) : mPeerAddress(address) {} + UnauthenticatedSession(const PeerAddress & address, const ReliableMessageProtocolConfig & config) : + mPeerAddress(address), mMRPConfig(config) + {} UnauthenticatedSession(const UnauthenticatedSession &) = delete; UnauthenticatedSession & operator=(const UnauthenticatedSession &) = delete; @@ -59,17 +62,9 @@ class UnauthenticatedSession : public ReferenceCounted FindOrAllocateEntry(const PeerAddress & address) + Optional FindOrAllocateEntry(const PeerAddress & address, + const ReliableMessageProtocolConfig & config) { UnauthenticatedSession * result = FindEntry(address); if (result != nullptr) return MakeOptional(*result); - CHIP_ERROR err = AllocEntry(address, result); + CHIP_ERROR err = AllocEntry(address, config, result); if (err == CHIP_NO_ERROR) { return MakeOptional(*result); @@ -134,9 +129,10 @@ class UnauthenticatedSessionTable * CHIP_ERROR_NO_MEMORY). */ CHECK_RETURN_VALUE - CHIP_ERROR AllocEntry(const PeerAddress & address, UnauthenticatedSession *& entry) + CHIP_ERROR AllocEntry(const PeerAddress & address, const ReliableMessageProtocolConfig & config, + UnauthenticatedSession *& entry) { - entry = mEntries.CreateObject(address); + entry = mEntries.CreateObject(address, config); if (entry != nullptr) return CHIP_NO_ERROR; @@ -146,7 +142,7 @@ class UnauthenticatedSessionTable return CHIP_ERROR_NO_MEMORY; } - mEntries.ResetObject(entry, address); + mEntries.ResetObject(entry, address, config); return CHIP_NO_ERROR; } diff --git a/src/transport/tests/TestPeerConnections.cpp b/src/transport/tests/TestPeerConnections.cpp index f9a4f6ec2f0195..d8e3203be482e4 100644 --- a/src/transport/tests/TestPeerConnections.cpp +++ b/src/transport/tests/TestPeerConnections.cpp @@ -59,17 +59,17 @@ void TestBasicFunctionality(nlTestSuite * inSuite, void * inContext) connections.GetTimeSource().SetMonotonicTimestamp(100_ms64); // Node ID 1, peer key 1, local key 2 - statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); // Node ID 2, peer key 3, local key 4 - statePtr = connections.CreateNewSecureSession(4, kPeer2NodeId, 3, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(4, kPeer2NodeId, 3, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); NL_TEST_ASSERT(inSuite, statePtr->GetPeerNodeId() == kPeer2NodeId); NL_TEST_ASSERT(inSuite, statePtr->GetLastActivityTime() == 100_ms64); // Insufficient space for new connections. Object is max size 2 - statePtr = connections.CreateNewSecureSession(6, kPeer3NodeId, 5, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(6, kPeer3NodeId, 5, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr == nullptr); } @@ -79,14 +79,14 @@ void TestFindByKeyId(nlTestSuite * inSuite, void * inContext) SecureSessionTable<2, Time::Source::kTest> connections; // Node ID 1, peer key 1, local key 2 - statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); NL_TEST_ASSERT(inSuite, !connections.FindSecureSessionByLocalKey(1)); NL_TEST_ASSERT(inSuite, connections.FindSecureSessionByLocalKey(2)); // Node ID 2, peer key 3, local key 4 - statePtr = connections.CreateNewSecureSession(4, kPeer2NodeId, 3, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(4, kPeer2NodeId, 3, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); NL_TEST_ASSERT(inSuite, !connections.FindSecureSessionByLocalKey(3)); @@ -109,19 +109,19 @@ void TestExpireConnections(nlTestSuite * inSuite, void * inContext) connections.GetTimeSource().SetMonotonicTimestamp(100_ms64); // Node ID 1, peer key 1, local key 2 - statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); statePtr->SetPeerAddress(kPeer1Addr); connections.GetTimeSource().SetMonotonicTimestamp(200_ms64); // Node ID 2, peer key 3, local key 4 - statePtr = connections.CreateNewSecureSession(4, kPeer2NodeId, 3, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(4, kPeer2NodeId, 3, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); statePtr->SetPeerAddress(kPeer2Addr); // cannot add before expiry connections.GetTimeSource().SetMonotonicTimestamp(300_ms64); - statePtr = connections.CreateNewSecureSession(6, kPeer3NodeId, 5, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(6, kPeer3NodeId, 5, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr == nullptr); // at time 300, this expires ip addr 1 @@ -138,7 +138,7 @@ void TestExpireConnections(nlTestSuite * inSuite, void * inContext) // now that the connections were expired, we can add peer3 connections.GetTimeSource().SetMonotonicTimestamp(300_ms64); // Node ID 3, peer key 5, local key 6 - statePtr = connections.CreateNewSecureSession(6, kPeer3NodeId, 5, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(6, kPeer3NodeId, 5, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); statePtr->SetPeerAddress(kPeer3Addr); @@ -169,7 +169,7 @@ void TestExpireConnections(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, !connections.FindSecureSessionByLocalKey(6)); // Node ID 1, peer key 1, local key 2 - statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */); + statePtr = connections.CreateNewSecureSession(2, kPeer1NodeId, 1, 0 /* fabricIndex */, gDefaultMRPConfig); NL_TEST_ASSERT(inSuite, statePtr != nullptr); NL_TEST_ASSERT(inSuite, connections.FindSecureSessionByLocalKey(2)); NL_TEST_ASSERT(inSuite, connections.FindSecureSessionByLocalKey(4));