Skip to content

Commit

Permalink
Group MRP parameters (#12069)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost authored and pull[bot] committed Apr 27, 2022
1 parent b961bb0 commit 1082784
Show file tree
Hide file tree
Showing 40 changed files with 319 additions and 281 deletions.
5 changes: 1 addition & 4 deletions examples/ota-requestor-app/esp32/main/OTARequesterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/app/CASESessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions src/app/DeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
13 changes: 5 additions & 8 deletions src/app/OperationalDeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ CHIP_ERROR OperationalDeviceProxy::Connect(Callback::Callback<OnDeviceConnected>
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)
{
Expand All @@ -121,7 +120,7 @@ CHIP_ERROR OperationalDeviceProxy::UpdateDeviceData(const Transport::PeerAddress
if (secureSession != nullptr)
{
secureSession->SetPeerAddress(addr);
secureSession->SetMRPIntervals(mrpIdleInterval, mrpActiveInterval);
secureSession->SetMRPConfig(mMRPConfig);
}
}

Expand All @@ -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<SessionHandle> session = mInitParams.sessionManager->CreateUnauthenticatedSession(mDeviceAddress);
Optional<SessionHandle> 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);

Expand Down
5 changes: 2 additions & 3 deletions src/app/OperationalDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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; }

Expand Down
21 changes: 8 additions & 13 deletions src/app/server/Dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL),
Optional<uint32_t>(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL))
.SetTcpSupported(Optional<bool>(INET_CONFIG_ENABLE_TCP_ENDPOINT))
.EnableIpV4(true);
const auto advertiseParameters = chip::Dnssd::OperationalAdvertisingParameters()
.SetPeerId(fabricInfo.GetPeerId())
.SetMac(mac)
.SetPort(GetSecuredPort())
.SetMRPConfig(gDefaultMRPConfig)
.SetTcpSupported(Optional<bool>(INET_CONFIG_ENABLE_TCP_ENDPOINT))
.EnableIpV4(true);

auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance();

Expand Down Expand Up @@ -343,10 +341,7 @@ CHIP_ERROR DnssdServer::Advertise(bool commissionableNode, chip::Dnssd::Commissi
advertiseParameters.SetRotatingId(chip::Optional<const char *>::Value(rotatingDeviceIdHexBuffer));
#endif

advertiseParameters
.SetMRPRetryIntervals(Optional<uint32_t>(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL),
Optional<uint32_t>(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL))
.SetTcpSupported(Optional<bool>(INET_CONFIG_ENABLE_TCP_ENDPOINT));
advertiseParameters.SetMRPConfig(gDefaultMRPConfig).SetTcpSupported(Optional<bool>(INET_CONFIG_ENABLE_TCP_ENDPOINT));

if (mode != chip::Dnssd::CommissioningMode::kEnabledEnhanced)
{
Expand Down
4 changes: 1 addition & 3 deletions src/channel/ChannelContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,14 @@ 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();
ExitPreparingState();
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);
Expand Down
8 changes: 2 additions & 6 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionHandle> session;
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/controller/CommissioneeDeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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;
}
Expand Down
7 changes: 3 additions & 4 deletions src/controller/CommissioneeDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/lib/core/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,6 +203,12 @@ class Optional
} mValue;
};

template <class T>
constexpr Optional<std::decay_t<T>> MakeOptional(T && value)
{
return Optional<std::decay_t<T>>(InPlace, std::forward<T>(value));
}

template <class T, class... Args>
constexpr Optional<T> MakeOptional(Args &&... args)
{
Expand Down
14 changes: 4 additions & 10 deletions src/lib/dnssd/Advertiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,12 @@ class BaseAdvertisingParams
const chip::ByteSpan GetMac() const { return chip::ByteSpan(mMacStorage, mMacLength); }

// Common Flags
Derived & SetMRPRetryIntervals(Optional<uint32_t> intervalIdle, Optional<uint32_t> intervalActive)
Derived & SetMRPConfig(const ReliableMessageProtocolConfig & config)
{
mMrpRetryIntervalIdle = intervalIdle;
mMrpRetryIntervalActive = intervalActive;
mMRPConfig.SetValue(config);
return *reinterpret_cast<Derived *>(this);
}
void GetMRPRetryIntervals(Optional<uint32_t> & intervalIdle, Optional<uint32_t> & intervalActive) const
{
intervalIdle = mMrpRetryIntervalIdle;
intervalActive = mMrpRetryIntervalActive;
}
const Optional<ReliableMessageProtocolConfig> & GetMRPConfig() const { return mMRPConfig; }
Derived & SetTcpSupported(Optional<bool> tcpSupported)
{
mTcpSupported = tcpSupported;
Expand All @@ -104,8 +99,7 @@ class BaseAdvertisingParams
bool mEnableIPv4 = true;
uint8_t mMacStorage[kMaxMacSize] = {};
size_t mMacLength = 0;
Optional<uint32_t> mMrpRetryIntervalIdle;
Optional<uint32_t> mMrpRetryIntervalActive;
Optional<ReliableMessageProtocolConfig> mMRPConfig;
Optional<bool> mTcpSupported;
};

Expand Down
Loading

0 comments on commit 1082784

Please sign in to comment.