Skip to content

Commit

Permalink
Rename CRMP to MRP (Message Reliability Protocol) (#7351)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored Jun 3, 2021
1 parent a379f00 commit 43077a5
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 84 deletions.
18 changes: 9 additions & 9 deletions examples/shell/shell_common/cmd_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class PingArguments
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
mUsingTCP = false;
#endif
mUsingCRMP = true;
mEchoPort = CHIP_PORT;
mUsingMRP = true;
mEchoPort = CHIP_PORT;
}

uint64_t GetLastEchoTime() const { return mLastEchoTime; }
Expand Down Expand Up @@ -93,8 +93,8 @@ class PingArguments
void SetUsingTCP(bool value) { mUsingTCP = value; }
#endif

bool IsUsingCRMP() const { return mUsingCRMP; }
void SetUsingCRMP(bool value) { mUsingCRMP = value; }
bool IsUsingMRP() const { return mUsingMRP; }
void SetUsingMRP(bool value) { mUsingMRP = value; }

private:
// The last time a echo request was attempted to be sent.
Expand Down Expand Up @@ -125,7 +125,7 @@ class PingArguments
bool mUsingTCP;
#endif

bool mUsingCRMP;
bool mUsingMRP;
} gPingArguments;

Protocols::Echo::EchoClient gEchoClient;
Expand Down Expand Up @@ -156,7 +156,7 @@ CHIP_ERROR SendEchoRequest(streamer_t * stream)
payloadBuf = MessagePacketBuffer::NewWithData(requestData, size);
VerifyOrExit(!payloadBuf.IsNull(), err = CHIP_ERROR_NO_MEMORY);

if (gPingArguments.IsUsingCRMP())
if (gPingArguments.IsUsingMRP())
{
sendFlags.Set(Messaging::SendMessageFlags::kNone);
}
Expand Down Expand Up @@ -363,7 +363,7 @@ void PrintUsage(streamer_t * stream)
streamer_printf(stream, " -p <port> echo server port\n");
streamer_printf(stream, " -i <interval> ping interval time in seconds\n");
streamer_printf(stream, " -c <count> stop after <count> replies\n");
streamer_printf(stream, " -r <1|0> enable or disable CRMP\n");
streamer_printf(stream, " -r <1|0> enable or disable MRP\n");
streamer_printf(stream, " -s <size> payload size in bytes\n");
}

Expand Down Expand Up @@ -446,11 +446,11 @@ int cmd_ping(int argc, char ** argv)

if (arg == 0)
{
gPingArguments.SetUsingCRMP(false);
gPingArguments.SetUsingMRP(false);
}
else if (arg == 1)
{
gPingArguments.SetUsingCRMP(true);
gPingArguments.SetUsingMRP(true);
}
else
{
Expand Down
18 changes: 9 additions & 9 deletions examples/shell/shell_common/cmd_send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class SendArguments
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
mUsingTCP = false;
#endif
mUsingCRMP = true;
mPort = CHIP_PORT;
mUsingMRP = true;
mPort = CHIP_PORT;
}

uint64_t GetLastSendTime() const { return mLastSendTime; }
Expand All @@ -78,8 +78,8 @@ class SendArguments
void SetUsingTCP(bool value) { mUsingTCP = value; }
#endif

bool IsUsingCRMP() const { return mUsingCRMP; }
void SetUsingCRMP(bool value) { mUsingCRMP = value; }
bool IsUsingMRP() const { return mUsingMRP; }
void SetUsingMRP(bool value) { mUsingMRP = value; }

private:
// The last time a CHIP message was attempted to be sent.
Expand All @@ -94,7 +94,7 @@ class SendArguments
bool mUsingTCP;
#endif

bool mUsingCRMP;
bool mUsingMRP;
} gSendArguments;

class MockAppDelegate : public Messaging::ExchangeDelegate
Expand Down Expand Up @@ -155,7 +155,7 @@ CHIP_ERROR SendMessage(streamer_t * stream)
payloadBuf = MessagePacketBuffer::NewWithData(requestData, size);
VerifyOrExit(!payloadBuf.IsNull(), err = CHIP_ERROR_NO_MEMORY);

if (gSendArguments.IsUsingCRMP())
if (gSendArguments.IsUsingMRP())
{
sendFlags.Set(Messaging::SendMessageFlags::kNone);
}
Expand Down Expand Up @@ -316,7 +316,7 @@ void PrintUsage(streamer_t * stream)
streamer_printf(stream, " -P <protocol> protocol ID\n");
streamer_printf(stream, " -T <type> message type\n");
streamer_printf(stream, " -p <port> server port number\n");
streamer_printf(stream, " -r <1|0> enable or disable CRMP\n");
streamer_printf(stream, " -r <1|0> enable or disable MRP\n");
streamer_printf(stream, " -s <size> payload size in bytes\n");
}

Expand Down Expand Up @@ -399,11 +399,11 @@ int cmd_send(int argc, char ** argv)

if (arg == 0)
{
gSendArguments.SetUsingCRMP(false);
gSendArguments.SetUsingMRP(false);
}
else if (arg == 1)
{
gSendArguments.SetUsingCRMP(true);
gSendArguments.SetUsingMRP(true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/server/Mdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ CHIP_ERROR AdvertiseOperational()
.SetPeerId(PeerId().SetFabricId(fabricId).SetNodeId(GetCurrentNodeId()))
.SetMac(FillMAC(mac))
.SetPort(CHIP_PORT)
.SetCRMPRetryIntervals(CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL, CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL)
.SetMRPRetryIntervals(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL, CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL)
.EnableIpV4(true);

auto & mdnsAdvertiser = chip::Mdns::ServiceAdvertiser::Instance();
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ must create an ExchangeContext object before initiating a CHIP conversation.

After constructing a CHIP ExchangeContext, CHIP messages are sent and received
using the ChipMessageLayer class which sends the CHIP message over a chosen
transport (TCP, UDP, or CRMP).
transport (TCP, UDP, or MRP).

## Example Applications Walk Through

Expand Down
18 changes: 9 additions & 9 deletions src/lib/mdns/Advertiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class OperationalAdvertisingParameters : public BaseAdvertisingParams<Operationa
// Amount of mDNS text entries required for this advertising type
static constexpr uint8_t kNumAdvertisingTxtEntries = 2;
static constexpr uint8_t kTxtMaxKeySize = 3 + 1; // "CRI"/"CRA" as possible keys
static constexpr uint8_t kTxtMaxValueSize = 7 + 1; // Max for text representation of the 32-bit CRMP intervals
static constexpr uint8_t kTxtMaxValueSize = 7 + 1; // Max for text representation of the 32-bit MRP intervals

OperationalAdvertisingParameters & SetPeerId(const PeerId & peerId)
{
Expand All @@ -105,22 +105,22 @@ class OperationalAdvertisingParameters : public BaseAdvertisingParams<Operationa
}
PeerId GetPeerId() const { return mPeerId; }

OperationalAdvertisingParameters & SetCRMPRetryIntervals(uint32_t intervalIdle, uint32_t intervalActive)
OperationalAdvertisingParameters & SetMRPRetryIntervals(uint32_t intervalIdle, uint32_t intervalActive)
{
mCrmpRetryIntervalIdle = intervalIdle;
mCrmpRetryIntervalActive = intervalActive;
mMrpRetryIntervalIdle = intervalIdle;
mMrpRetryIntervalActive = intervalActive;
return *this;
}
void GetCRMPRetryIntervals(uint32_t & intervalIdle, uint32_t & intervalActive) const
void GetMRPRetryIntervals(uint32_t & intervalIdle, uint32_t & intervalActive) const
{
intervalIdle = mCrmpRetryIntervalIdle;
intervalActive = mCrmpRetryIntervalActive;
intervalIdle = mMrpRetryIntervalIdle;
intervalActive = mMrpRetryIntervalActive;
}

private:
PeerId mPeerId;
uint32_t mCrmpRetryIntervalIdle = 0;
uint32_t mCrmpRetryIntervalActive = 0;
uint32_t mMrpRetryIntervalIdle = 0;
uint32_t mMrpRetryIntervalActive = 0;
};

class CommissionAdvertisingParameters : public BaseAdvertisingParams<CommissionAdvertisingParameters>
Expand Down
55 changes: 27 additions & 28 deletions src/lib/mdns/Discovery_ImplPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,65 +336,64 @@ CHIP_ERROR DiscoveryImplPlatform::Advertise(const OperationalAdvertisingParamete
// TODO: That value should be defined in the ReliableMessageProtocolConfig.h,
// but for now it is not possible to access it from src/lib/mdns. It should be
// refactored after creating common DNS-SD layer.
constexpr uint32_t kMaxCRMPRetryInterval = 3600000;
// kMaxCRMPRetryInterval max value is 3600000, what gives 7 characters and newline
constexpr uint32_t kMaxMRPRetryInterval = 3600000;
// kMaxMRPRetryInterval max value is 3600000, what gives 7 characters and newline
// necessary to represent it in the text form.
constexpr uint8_t kMaxCRMPRetryBufferSize = 7 + 1;
char crmpRetryIntervalIdleBuf[kMaxCRMPRetryBufferSize];
char crmpRetryIntervalActiveBuf[kMaxCRMPRetryBufferSize];
TextEntry crmpRetryIntervalEntries[OperationalAdvertisingParameters::kNumAdvertisingTxtEntries];
constexpr uint8_t kMaxMRPRetryBufferSize = 7 + 1;
char mrpRetryIntervalIdleBuf[kMaxMRPRetryBufferSize];
char mrpRetryIntervalActiveBuf[kMaxMRPRetryBufferSize];
TextEntry mrpRetryIntervalEntries[OperationalAdvertisingParameters::kNumAdvertisingTxtEntries];
size_t textEntrySize = 0;
uint32_t crmpRetryIntervalIdle, crmpRetryIntervalActive;
uint32_t mrpRetryIntervalIdle, mrpRetryIntervalActive;
int writtenCharactersNumber;
params.GetCRMPRetryIntervals(crmpRetryIntervalIdle, crmpRetryIntervalActive);
params.GetMRPRetryIntervals(mrpRetryIntervalIdle, mrpRetryIntervalActive);

// TODO: Issue #5833 - CRMP retry intervals should be updated on the poll period value
// TODO: Issue #5833 - MRP retry intervals should be updated on the poll period value
// change or device type change.
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (chip::DeviceLayer::ConnectivityMgr().GetThreadDeviceType() ==
chip::DeviceLayer::ConnectivityManager::kThreadDeviceType_SleepyEndDevice)
{
uint32_t sedPollPeriod;
ReturnErrorOnFailure(chip::DeviceLayer::ThreadStackMgr().GetPollPeriod(sedPollPeriod));
// Increment default CRMP retry intervals by SED poll period to be on the safe side
// Increment default MRP retry intervals by SED poll period to be on the safe side
// and avoid unnecessary retransmissions.
crmpRetryIntervalIdle += sedPollPeriod;
crmpRetryIntervalActive += sedPollPeriod;
mrpRetryIntervalIdle += sedPollPeriod;
mrpRetryIntervalActive += sedPollPeriod;
}
#endif

if (crmpRetryIntervalIdle > kMaxCRMPRetryInterval)
if (mrpRetryIntervalIdle > kMaxMRPRetryInterval)
{
ChipLogProgress(Discovery, "CRMP retry interval idle value exceeds allowed range of 1 hour, using maximum available",
ChipLogProgress(Discovery, "MRP retry interval idle value exceeds allowed range of 1 hour, using maximum available",
chip::ErrorStr(error));
crmpRetryIntervalIdle = kMaxCRMPRetryInterval;
mrpRetryIntervalIdle = kMaxMRPRetryInterval;
}
writtenCharactersNumber =
snprintf(crmpRetryIntervalIdleBuf, sizeof(crmpRetryIntervalIdleBuf), "%" PRIu32, crmpRetryIntervalIdle);
VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < kMaxCRMPRetryBufferSize),
writtenCharactersNumber = snprintf(mrpRetryIntervalIdleBuf, sizeof(mrpRetryIntervalIdleBuf), "%" PRIu32, mrpRetryIntervalIdle);
VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < kMaxMRPRetryBufferSize),
CHIP_ERROR_INVALID_STRING_LENGTH);
crmpRetryIntervalEntries[textEntrySize++] = { "CRI", reinterpret_cast<const uint8_t *>(crmpRetryIntervalIdleBuf),
strlen(crmpRetryIntervalIdleBuf) };
mrpRetryIntervalEntries[textEntrySize++] = { "CRI", reinterpret_cast<const uint8_t *>(mrpRetryIntervalIdleBuf),
strlen(mrpRetryIntervalIdleBuf) };

if (crmpRetryIntervalActive > kMaxCRMPRetryInterval)
if (mrpRetryIntervalActive > kMaxMRPRetryInterval)
{
ChipLogProgress(Discovery, "CRMP retry interval active value exceeds allowed range of 1 hour, using maximum available",
ChipLogProgress(Discovery, "MRP retry interval active value exceeds allowed range of 1 hour, using maximum available",
chip::ErrorStr(error));
crmpRetryIntervalActive = kMaxCRMPRetryInterval;
mrpRetryIntervalActive = kMaxMRPRetryInterval;
}
writtenCharactersNumber =
snprintf(crmpRetryIntervalActiveBuf, sizeof(crmpRetryIntervalActiveBuf), "%" PRIu32, crmpRetryIntervalActive);
VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < kMaxCRMPRetryBufferSize),
snprintf(mrpRetryIntervalActiveBuf, sizeof(mrpRetryIntervalActiveBuf), "%" PRIu32, mrpRetryIntervalActive);
VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < kMaxMRPRetryBufferSize),
CHIP_ERROR_INVALID_STRING_LENGTH);
crmpRetryIntervalEntries[textEntrySize++] = { "CRA", reinterpret_cast<const uint8_t *>(crmpRetryIntervalActiveBuf),
strlen(crmpRetryIntervalActiveBuf) };
mrpRetryIntervalEntries[textEntrySize++] = { "CRA", reinterpret_cast<const uint8_t *>(mrpRetryIntervalActiveBuf),
strlen(mrpRetryIntervalActiveBuf) };

ReturnErrorOnFailure(SetupHostname(params.GetMac()));
ReturnErrorOnFailure(MakeInstanceName(service.mName, sizeof(service.mName), params.GetPeerId()));
strncpy(service.mType, kOperationalServiceName, sizeof(service.mType));
service.mProtocol = MdnsServiceProtocol::kMdnsProtocolTcp;
service.mPort = CHIP_PORT;
service.mTextEntries = crmpRetryIntervalEntries;
service.mTextEntries = mrpRetryIntervalEntries;
service.mTextEntrySize = textEntrySize;
service.mInterface = INET_NULL_INTERFACEID;
service.mAddressType = Inet::kIPAddressType_Any;
Expand Down
4 changes: 2 additions & 2 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void ExchangeContext::DoClose(bool clearRetransTable)
FlushAcks();

// In case the protocol wants a harder release of the EC right away, such as calling Abort(), exchange
// needs to clear the CRMP retransmission table immediately.
// needs to clear the MRP retransmission table immediately.
if (clearRetransTable)
{
mExchangeMgr->GetReliableMessageMgr()->ClearRetransTable(static_cast<ReliableMessageContext *>(this));
Expand Down Expand Up @@ -382,7 +382,7 @@ CHIP_ERROR ExchangeContext::HandleMessage(const PacketHeader & packetHeader, con
mDispatch->OnMessageReceived(payloadHeader, packetHeader.GetMessageId(), peerAddress, GetReliableMessageContext());
SuccessOrExit(err);

// The SecureChannel::StandaloneAck message type is only used for CRMP; do not pass such messages to the application layer.
// The SecureChannel::StandaloneAck message type is only used for MRP; do not pass such messages to the application layer.
if (payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::StandaloneAck))
{
ExitNow(err = CHIP_NO_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/ExchangeMessageDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CHIP_ERROR ExchangeMessageDispatch::SendMessage(SecureSessionHandle session, uin
}
else
{
// If the channel itself is providing reliability, let's not request CRMP acks
// If the channel itself is providing reliability, let's not request MRP acks
payloadHeader.SetNeedsAck(false);
ReturnErrorOnFailure(SendMessageImpl(session, payloadHeader, std::move(message), nullptr));
}
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/ExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const
mContextPool.ForEachActiveObject([&](auto * ec) {
if (ec->MatchExchange(session, packetHeader, payloadHeader))
{
// Found a matching exchange. Set flag for correct subsequent CRMP
// Found a matching exchange. Set flag for correct subsequent MRP
// retransmission timeout selection.
if (!ec->HasRcvdMsgFromPeer())
{
Expand Down
20 changes: 10 additions & 10 deletions src/messaging/ReliableMessageProtocolConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Messaging {
#endif // CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT

/**
* @def CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL
* @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL
*
* @brief
* Active retransmit interval, or time to wait before retransmission after
Expand All @@ -53,12 +53,12 @@ namespace Messaging {
* needs (e.g. sleeping period) using Service Discovery TXT record CRA key.
*
*/
#ifndef CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL
#define CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL (300)
#endif // CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL
#ifndef CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL
#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (300)
#endif // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL

/**
* @def CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL
* @def CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL
*
* @brief
* Initial retransmission interval, or time to wait before retransmission after first
Expand All @@ -67,9 +67,9 @@ namespace Messaging {
* This is the default value, that might be adjusted by end device depending on its
* needs (e.g. sleeping period) using Service Discovery TXT record CRI key.
*/
#ifndef CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL
#define CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL (5000)
#endif // CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL
#ifndef CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL
#define CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL (5000)
#endif // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL

/**
* @def CHIP_CONFIG_RMP_DEFAULT_ACK_TIMEOUT_TICK
Expand Down Expand Up @@ -121,8 +121,8 @@ struct ReliableMessageProtocolConfig
};

const ReliableMessageProtocolConfig gDefaultReliableMessageProtocolConfig = {
CHIP_CONFIG_RMP_DEFAULT_INITIAL_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT,
CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT
CHIP_CONFIG_MRP_DEFAULT_INITIAL_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
Expand Down
Loading

0 comments on commit 43077a5

Please sign in to comment.