Skip to content

Commit

Permalink
[api] enable DIAG_GET query function into commissioner
Browse files Browse the repository at this point in the history
This PR adds DIAG_GET query command into the commissioner module,
allowing users to query one or more diagnostic TLVs from a peer Thread
device by setting the device's mesh local address than TLV mask bits
flag.

Test:

config set pskc 445f2b5ca6f2a93a55ce570a70efeecb
[done]
start 192.168.9.2 49154
[done]
diag query ipaddr fdce:bb1d:37f6:6978:0:ff:fe00:cc00
Peer Address: fd74:95e3:6ec:feee:0:ff:fe00:ac00
Content: {
    "Ipv6 Addresses": [
        "fd74:95e3:06ec:feee:0000:00ff:fe00:fc36",
        "fd74:95e3:06ec:feee:0000:00ff:fe00:fc11",
        "fd74:95e3:06ec:feee:0000:00ff:fe00:fc10",
        "fd74:95e3:06ec:feee:0000:00ff:fe00:fc38",
        "fd11:0022:0000:0000:99e7:cece:d50d:ae6b",
        "fd74:95e3:06ec:feee:0000:00ff:fe00:fc00",
        "fd74:95e3:06ec:feee:0000:00ff:fe00:ac00",
        "fd74:95e3:06ec:feee:6142:033d:b087:2845",
        "fe80:0000:0000:0000:9cbb:e247:df46:9e70"
    ]
}
[done]
  • Loading branch information
ZhangLe2016 committed Sep 30, 2024
1 parent 87bdb35 commit 53fcc9d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 28 deletions.
1 change: 1 addition & 0 deletions include/commissioner/commissioner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class CommissionerHandler
*/
virtual void OnDiagGetAnswerMessage(const std::string &aDestAddress, const NetDiagTlvs &aDiagAnsMsg)
{
(void)aDestAddress;
(void)aDiagAnsMsg;
}

Expand Down
82 changes: 59 additions & 23 deletions src/app/cli/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2612,9 +2612,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
tlvs.mPresentFlags = flags;
value = NetDiagTlvsToJson(tlvs);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() + "\nContent: " + NetDiagTlvsToJson(it->second);
}
}
}

Expand All @@ -2625,9 +2629,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
tlvs.mPresentFlags = flags;
value = NetDiagTlvsToJson(tlvs);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() + "\nContent: " + NetDiagTlvsToJson(it->second);
}
}
}
if (CaseInsensitiveEqual(aExpr[2], "mode"))
Expand All @@ -2637,9 +2645,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
tlvs.mPresentFlags = flags;
value = ModeToJson(tlvs.mMode);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() + "\nContent: " + ModeToJson(it->second.mMode);
}
}
}
if (CaseInsensitiveEqual(aExpr[2], "route64"))
Expand All @@ -2649,9 +2661,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
tlvs.mPresentFlags = flags;
value = Route64ToJson(tlvs.mRoute64);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() + "\nContent: " + Route64ToJson(it->second.mRoute64);
}
}
}
if (CaseInsensitiveEqual(aExpr[2], "leaderdata"))
Expand All @@ -2661,9 +2677,14 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
tlvs.mPresentFlags = flags;
value = LeaderDataToJson(tlvs.mLeaderData);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() +
"\nContent: " + LeaderDataToJson(it->second.mLeaderData);
}
}
}
if (CaseInsensitiveEqual(aExpr[2], "eui64"))
Expand All @@ -2673,9 +2694,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
tlvs.mPresentFlags = flags;
value = NetDiagTlvsToJson(tlvs);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() + "\nContent: " + NetDiagTlvsToJson(it->second);
}
}
}
if (CaseInsensitiveEqual(aExpr[2], "ipaddr"))
Expand All @@ -2685,8 +2710,14 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
value = Ipv6AddressToJson(tlvs.mIpv6Addresses);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() +
"\nContent: " + Ipv6AddressToJson(it->second.mIpv6Addresses);
}
}
}
if (CaseInsensitiveEqual(aExpr[2], "childtable"))
Expand All @@ -2696,9 +2727,14 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner
{
SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
tlvs = aCommissioner->GetNetDiagTlvs();
tlvs.mPresentFlags = flags;
value = ChildTableToJson(tlvs.mChildTable);
tlvs.mPresentFlags = flags;
DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs();
for (std::map<Address, NetDiagTlvs>::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end();
++it)
{
value = "Peer Address: " + (it->first).ToString() +
"\nContent: " + ChildTableToJson(it->second.mChildTable);
}
}
}
exit:
Expand Down
10 changes: 7 additions & 3 deletions src/app/commissioner_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,12 +1401,16 @@ Error CommissionerApp::CommandDiagGetQuery(const std::string &aAddr, uint64_t aD

void CommissionerApp::OnDiagGetAnswerMessage(const std::string &aDestAddress, const NetDiagTlvs &aDiagAnsMsg)
{
mNetDiagTlvs = aDiagAnsMsg;
Address addr;

SuccessOrDie(addr.Set(aDestAddress));

mDiagAnsDataMap[addr] = aDiagAnsMsg;
}

NetDiagTlvs CommissionerApp::GetNetDiagTlvs() const
DiagAnsDataMap CommissionerApp::GetNetDiagTlvs() const
{
return mNetDiagTlvs;
return mDiagAnsDataMap;
}

} // namespace commissioner
Expand Down
6 changes: 4 additions & 2 deletions src/app/commissioner_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct EnergyReport
};
using EnergyReportMap = std::map<Address, EnergyReport>;

using DiagAnsDataMap = std::map<Address, NetDiagTlvs>;

/**
* @brief Enumeration of Joiner Type for steering.
*
Expand Down Expand Up @@ -280,7 +282,7 @@ class CommissionerApp : public CommissionerHandler
MOCKABLE const EnergyReportMap &GetAllEnergyReports() const;

const std::string &GetDomainName() const;
NetDiagTlvs GetNetDiagTlvs() const;
DiagAnsDataMap GetNetDiagTlvs() const;

protected:
CommissionerApp() = default;
Expand Down Expand Up @@ -331,7 +333,7 @@ class CommissionerApp : public CommissionerHandler
PendingOperationalDataset mPendingDataset;
CommissionerDataset mCommDataset;
BbrDataset mBbrDataset;
NetDiagTlvs mNetDiagTlvs;
DiagAnsDataMap mDiagAnsDataMap;
};

Error CommissionerAppCreate(std::shared_ptr<CommissionerApp> &aCommApp, const Config &aConfig);
Expand Down

0 comments on commit 53fcc9d

Please sign in to comment.