Skip to content

Commit

Permalink
[tmf] add UriToString() for logging (#8930)
Browse files Browse the repository at this point in the history
This commit adds a helper function `UriToString<Uri>()` to convert
a given `Uri` enumeration value to a human-readable string. This is
used for logging.
  • Loading branch information
abtink authored Apr 6, 2023
1 parent cbdabbc commit adde085
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/core/meshcop/announce_begin_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Error AnnounceBeginClient::SendRequest(uint32_t aChannelMask,

SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo));

LogInfo("sent announce begin query");
LogInfo("Sent %s", UriToString<kUriAnnounceBegin>());

exit:
FreeMessageOnError(message, error);
Expand Down
28 changes: 14 additions & 14 deletions src/core/meshcop/commissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ Error Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8_t
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo,
Commissioner::HandleMgmtCommissionerGetResponse, this));

LogInfo("sent MGMT_COMMISSIONER_GET.req to leader");
LogInfo("Sent %s to leader", UriToString<kUriCommissionerGet>());

exit:
FreeMessageOnError(message, error);
Expand All @@ -718,7 +718,7 @@ void Commissioner::HandleMgmtCommissionerGetResponse(Coap::Message *aMe
OT_UNUSED_VARIABLE(aMessageInfo);

VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged);
LogInfo("received MGMT_COMMISSIONER_GET response");
LogInfo("Received %s response", UriToString<kUriCommissionerGet>());

exit:
return;
Expand Down Expand Up @@ -764,7 +764,7 @@ Error Commissioner::SendMgmtCommissionerSetRequest(const Dataset &aDataset, cons
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo,
Commissioner::HandleMgmtCommissionerSetResponse, this));

LogInfo("sent MGMT_COMMISSIONER_SET.req to leader");
LogInfo("Sent %s to leader", UriToString<kUriCommissionerSet>());

exit:
FreeMessageOnError(message, error);
Expand All @@ -787,7 +787,7 @@ void Commissioner::HandleMgmtCommissionerSetResponse(Coap::Message *aMe
OT_UNUSED_VARIABLE(aMessageInfo);

VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged);
LogInfo("received MGMT_COMMISSIONER_SET response");
LogInfo("Received %s response", UriToString<kUriCommissionerSet>());

exit:
return;
Expand All @@ -813,7 +813,7 @@ Error Commissioner::SendPetition(void)
SuccessOrExit(
error = Get<Tmf::Agent>().SendMessage(*message, messageInfo, Commissioner::HandleLeaderPetitionResponse, this));

LogInfo("sent petition");
LogInfo("Sent %s", UriToString<kUriLeaderPetition>());

exit:
FreeMessageOnError(message, error);
Expand Down Expand Up @@ -842,7 +842,7 @@ void Commissioner::HandleLeaderPetitionResponse(Coap::Message *aMessage
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged,
retransmit = (mState == kStatePetition));

LogInfo("received Leader Petition response");
LogInfo("Received %s response", UriToString<kUriLeaderPetition>());

SuccessOrExit(Tlv::Find<StateTlv>(*aMessage, state));
VerifyOrExit(state == StateTlv::kAccept, IgnoreError(Stop(kDoNotSendKeepAlive)));
Expand Down Expand Up @@ -900,7 +900,7 @@ void Commissioner::SendKeepAlive(uint16_t aSessionId)
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo,
Commissioner::HandleLeaderKeepAliveResponse, this));

LogInfo("sent keep alive");
LogInfo("Sent %s", UriToString<kUriLeaderKeepAlive>());

exit:
FreeMessageOnError(message, error);
Expand Down Expand Up @@ -928,7 +928,7 @@ void Commissioner::HandleLeaderKeepAliveResponse(Coap::Message *aMessag
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged,
IgnoreError(Stop(kDoNotSendKeepAlive)));

LogInfo("received Leader keep-alive response");
LogInfo("Received %s response", UriToString<kUriLeaderKeepAlive>());

SuccessOrExit(Tlv::Find<StateTlv>(*aMessage, state));
VerifyOrExit(state == StateTlv::kAccept, IgnoreError(Stop(kDoNotSendKeepAlive)));
Expand Down Expand Up @@ -985,7 +985,7 @@ template <> void Commissioner::HandleTmf<kUriRelayRx>(Coap::Message &aMessage, c
{
if (mJoinerIid != joinerIid)
{
LogNote("Ignore Relay Receive (%s, 0x%04x), session in progress with (%s, 0x%04x)",
LogNote("Ignore %s (%s, 0x%04x), session in progress with (%s, 0x%04x)", UriToString<kUriRelayRx>(),
joinerIid.ToString().AsCString(), joinerRloc, mJoinerIid.ToString().AsCString(), mJoinerRloc);

ExitNow();
Expand All @@ -995,7 +995,7 @@ template <> void Commissioner::HandleTmf<kUriRelayRx>(Coap::Message &aMessage, c
mJoinerPort = joinerPort;
mJoinerRloc = joinerRloc;

LogInfo("Received Relay Receive (%s, 0x%04x)", mJoinerIid.ToString().AsCString(), mJoinerRloc);
LogInfo("Received %s (%s, 0x%04x)", UriToString<kUriRelayRx>(), mJoinerIid.ToString().AsCString(), mJoinerRloc);

aMessage.SetOffset(offset);
SuccessOrExit(error = aMessage.SetLength(offset + length));
Expand Down Expand Up @@ -1026,11 +1026,11 @@ void Commissioner::HandleTmf<kUriDatasetChanged>(Coap::Message &aMessage, const
VerifyOrExit(mState == kStateActive);
VerifyOrExit(aMessage.IsConfirmablePostRequest());

LogInfo("received dataset changed");
LogInfo("Received %s", UriToString<kUriDatasetChanged>());

SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMessage, aMessageInfo));

LogInfo("sent dataset changed acknowledgment");
LogInfo("Sent %s ack", UriToString<kUriDatasetChanged>());

exit:
return;
Expand All @@ -1046,7 +1046,7 @@ void Commissioner::HandleTmf<kUriJoinerFinalize>(Coap::Message &aMessage, const

VerifyOrExit(mState == kStateActive);

LogInfo("received joiner finalize");
LogInfo("Received %s", UriToString<kUriJoinerFinalize>());

switch (Tlv::Find<ProvisioningUrlTlv>(aMessage, provisioningUrl))
{
Expand Down Expand Up @@ -1116,7 +1116,7 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Message &aRequest, State
RemoveJoiner(*mActiveJoiner, kRemoveJoinerDelay);
}

LogInfo("sent joiner finalize response");
LogInfo("Sent %s response", UriToString<kUriJoinerFinalize>());

exit:
FreeMessageOnError(message, error);
Expand Down
6 changes: 3 additions & 3 deletions src/core/meshcop/energy_scan_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Error EnergyScanClient::SendQuery(uint32_t aChannelMas
messageInfo.SetSockAddrToRlocPeerAddrTo(aAddress);
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo));

LogInfo("sent query");
LogInfo("Sent %s", UriToString<kUriEnergyScan>());

mCallback.Set(aCallback, aContext);

Expand All @@ -108,7 +108,7 @@ void EnergyScanClient::HandleTmf<kUriEnergyReport>(Coap::Message &aMessage, cons

VerifyOrExit(aMessage.IsConfirmablePostRequest());

LogInfo("received report");
LogInfo("Received %s", UriToString<kUriEnergyReport>());

VerifyOrExit((mask = MeshCoP::ChannelMaskTlv::GetChannelMask(aMessage)) != 0);

Expand All @@ -118,7 +118,7 @@ void EnergyScanClient::HandleTmf<kUriEnergyReport>(Coap::Message &aMessage, cons

SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMessage, aMessageInfo));

LogInfo("sent report response");
LogInfo("Sent %s ack", UriToString<kUriEnergyReport>());

exit:
return;
Expand Down
8 changes: 4 additions & 4 deletions src/core/meshcop/joiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void Joiner::SendJoinerFinalize(void)
SuccessOrExit(Get<Tmf::SecureAgent>().SendMessage(*mFinalizeMessage, Joiner::HandleJoinerFinalizeResponse, this));
mFinalizeMessage = nullptr;

LogInfo("Joiner sent finalize");
LogInfo("Sent %s", UriToString<kUriJoinerFinalize>());

exit:
return;
Expand Down Expand Up @@ -517,7 +517,7 @@ void Joiner::HandleJoinerFinalizeResponse(Coap::Message *aMessage, const Ip6::Me
SetState(kStateEntrust);
mTimer.Start(kReponseTimeout);

LogInfo("Joiner received finalize response %d", state);
LogInfo("Received %s %d", UriToString<kUriJoinerFinalize>(), state);

#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
LogCertMessage("[THCI] direction=recv | type=JOIN_FIN.rsp |", *aMessage);
Expand All @@ -535,7 +535,7 @@ template <> void Joiner::HandleTmf<kUriJoinerEntrust>(Coap::Message &aMessage, c

VerifyOrExit(mState == kStateEntrust && aMessage.IsConfirmablePostRequest(), error = kErrorDrop);

LogInfo("Joiner received entrust");
LogInfo("Received %s", UriToString<kUriJoinerEntrust>());
LogCert("[THCI] direction=recv | type=JOIN_ENT.ntf");

datasetInfo.Clear();
Expand Down Expand Up @@ -574,7 +574,7 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Message &aRequest, const Ip6:

SetState(kStateJoined);

LogInfo("Joiner sent entrust response");
LogInfo("Sent %s response", UriToString<kUriJoinerEntrust>());
LogCert("[THCI] direction=send | type=JOIN_ENT.rsp");

exit:
Expand Down
9 changes: 4 additions & 5 deletions src/core/meshcop/joiner_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a

SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo));

LogInfo("Sent relay rx");
LogInfo("Sent %s", UriToString<kUriRelayRx>());

exit:
FreeMessageOnError(message, error);
Expand All @@ -177,7 +177,7 @@ template <> void JoinerRouter::HandleTmf<kUriRelayTx>(Coap::Message &aMessage, c

VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = kErrorDrop);

LogInfo("Received relay transmit");
LogInfo("Received %s", UriToString<kUriRelayTx>());

SuccessOrExit(error = Tlv::Find<JoinerUdpPortTlv>(aMessage, joinerPort));
SuccessOrExit(error = Tlv::Find<JoinerIidTlv>(aMessage, joinerIid));
Expand Down Expand Up @@ -273,11 +273,10 @@ Error JoinerRouter::SendJoinerEntrust(const Ip6::MessageInfo &aMessageInfo)

IgnoreError(Get<Tmf::Agent>().AbortTransaction(&JoinerRouter::HandleJoinerEntrustResponse, this));

LogInfo("Sending JOIN_ENT.ntf");
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, aMessageInfo,
&JoinerRouter::HandleJoinerEntrustResponse, this));

LogInfo("Sent joiner entrust length = %d", message->GetLength());
LogInfo("Sent %s (len= %d)", UriToString<kUriJoinerEntrust>(), message->GetLength());
LogCert("[THCI] direction=send | type=JOIN_ENT.ntf");

exit:
Expand Down Expand Up @@ -382,7 +381,7 @@ void JoinerRouter::HandleJoinerEntrustResponse(Coap::Message *aMessage,

VerifyOrExit(aMessage->GetCode() == Coap::kCodeChanged);

LogInfo("Receive joiner entrust response");
LogInfo("Receive %s response", UriToString<kUriJoinerEntrust>());
LogCert("[THCI] direction=recv | type=JOIN_ENT.rsp");

exit:
Expand Down
10 changes: 5 additions & 5 deletions src/core/meshcop/meshcop_leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ template <> void Leader::HandleTmf<kUriLeaderPetition>(Coap::Message &aMessage,
CommissionerIdTlv commissionerId;
StateTlv::State state = StateTlv::kReject;

LogInfo("received petition");
LogInfo("Received %s", UriToString<kUriLeaderPetition>());

VerifyOrExit(Get<Mle::MleRouter>().IsRoutingLocator(aMessageInfo.GetPeerAddr()));
SuccessOrExit(Tlv::FindTlv(aMessage, commissionerId));
Expand Down Expand Up @@ -136,7 +136,7 @@ void Leader::SendPetitionResponse(const Coap::Message &aRequest,

SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, aMessageInfo));

LogInfo("sent petition response");
LogInfo("Sent %s response", UriToString<kUriLeaderPetition>());

exit:
FreeMessageOnError(message, error);
Expand All @@ -150,7 +150,7 @@ template <> void Leader::HandleTmf<kUriLeaderKeepAlive>(Coap::Message &aMessage,
BorderAgentLocatorTlv *borderAgentLocator;
StateTlv::State responseState;

LogInfo("received keep alive");
LogInfo("Received %s", UriToString<kUriLeaderKeepAlive>());

SuccessOrExit(Tlv::Find<StateTlv>(aMessage, state));

Expand Down Expand Up @@ -202,7 +202,7 @@ void Leader::SendKeepAliveResponse(const Coap::Message &aRequest,

SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, aMessageInfo));

LogInfo("sent keep alive response");
LogInfo("Sent %s response", UriToString<kUriLeaderKeepAlive>());

exit:
FreeMessageOnError(message, error);
Expand All @@ -221,7 +221,7 @@ void Leader::SendDatasetChanged(const Ip6::Address &aAddress)
messageInfo.SetSockAddrToRlocPeerAddrTo(aAddress);
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo));

LogInfo("sent dataset changed");
LogInfo("Sent %s", UriToString<kUriDatasetChanged>());

exit:
FreeMessageOnError(message, error);
Expand Down
6 changes: 3 additions & 3 deletions src/core/meshcop/panid_query_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Error PanIdQueryClient::SendQuery(uint16_t aPanId,
messageInfo.SetSockAddrToRlocPeerAddrTo(aAddress);
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo));

LogInfo("sent panid query");
LogInfo("Sent %s", UriToString<kUriPanIdQuery>());

mCallback.Set(aCallback, aContext);

Expand All @@ -102,7 +102,7 @@ void PanIdQueryClient::HandleTmf<kUriPanIdConflict>(Coap::Message &aMessage, con

VerifyOrExit(aMessage.IsConfirmablePostRequest());

LogInfo("received panid conflict");
LogInfo("Received %s", UriToString<kUriPanIdConflict>());

SuccessOrExit(Tlv::Find<MeshCoP::PanIdTlv>(aMessage, panId));

Expand All @@ -112,7 +112,7 @@ void PanIdQueryClient::HandleTmf<kUriPanIdConflict>(Coap::Message &aMessage, con

SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMessage, aMessageInfo));

LogInfo("sent panid query conflict response");
LogInfo("Sent %s response", UriToString<kUriPanIdConflict>());

exit:
return;
Expand Down
Loading

0 comments on commit adde085

Please sign in to comment.