Skip to content

Commit

Permalink
[diag] handling some variable redefination issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangLe2016 committed Jan 9, 2025
1 parent 2e074c3 commit 5f187e7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 65 deletions.
30 changes: 15 additions & 15 deletions include/commissioner/network_diag_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ struct MacCounters
};

/**
* @brief Has Route
* @brief Has Route Entry
*/
struct HasRoute
struct HasRouteEntry
{
uint16_t mRloc16 = 0;
uint8_t mRouterPreference = 0;
bool mIsNat64 = false;
};

/**
* @brief Border Router
* @brief Border Router Entry
*/
struct BorderRouter
struct BorderRouterEntry
{
uint16_t mRloc16 = 0;
uint8_t mPrefixPreference = 0;
Expand All @@ -167,22 +167,22 @@ struct SixLowPanContext
/**
* @brief Prefix
*/
struct Prefix
struct PrefixEntry
{
uint8_t mDomainId = 0;
uint8_t mPrefixLength = 0;
ByteArray mPrefix;
std::vector<HasRoute> mHasRoutes;
std::vector<BorderRouter> mBorderRouters;
SixLowPanContext mSixLowPanContext;
uint8_t mDomainId = 0;
uint8_t mPrefixLength = 0;
ByteArray mPrefix;
std::vector<HasRouteEntry> mHasRouteList;
std::vector<BorderRouterEntry> mBorderRouterList;
SixLowPanContext mSixLowPanContext;
};

/**
* @brief Network Data
* @brief Network Data TLV
*/
struct NetworkData
struct NetworkDataTlv
{
std::vector<Prefix> mPrefixList;
std::vector<PrefixEntry> mPrefixList;
};

/**
Expand All @@ -204,7 +204,7 @@ struct NetDiagData
std::vector<std::string> mAddrs;
std::vector<ChildTableEntry> mChildTable;
std::vector<ChildIpv6AddrInfo> mChildIpv6AddrsInfoList;
NetworkData mNetworkData;
NetworkDataTlv mNetworkData;

/**
* Indicates which fields are included in the object.
Expand Down
47 changes: 23 additions & 24 deletions src/library/commissioner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2225,19 +2225,18 @@ Error internal::DecodeNetDiagData(NetDiagData &aNetDiagData, const ByteArray &aP
SuccessOrExit(error = DecodeNetworkData(diagData.mNetworkData, value));
diagData.mPresentFlags |= NetDiagData::kNetworkDataBit;
}

aNetDiagData = diagData;

exit:
return error;
}

Error internal::DecodeNetworkData(NetworkData &aNetworkData, const ByteArray &aBuf)
Error internal::DecodeNetworkData(NetworkDataTlv &aNetworkData, const ByteArray &aBuf)
{
Error error;
tlv::TlvSet tlvSet;
tlv::TlvList tlvList;
NetworkData networkData;
Error error;
tlv::TlvSet tlvSet;
tlv::TlvList tlvList;
NetworkDataTlv networkData;

SuccessOrExit(error =
tlv::GetTlvListByType(tlvList, aBuf, tlv::Type::kNetworkDataPrefix, tlv::Scope::kNetworkData));
Expand All @@ -2255,11 +2254,11 @@ Error internal::DecodeNetworkData(NetworkData &aNetworkData, const ByteArray &aB
return error;
}

Error internal::DecodePrefixList(std::vector<Prefix> &aPrefixList, const ByteArray &aBuf)
Error internal::DecodePrefixList(std::vector<PrefixEntry> &aPrefixList, const ByteArray &aBuf)
{
Error error;
size_t length = aBuf.size();
Prefix prefix;
PrefixEntry prefix;
uint8_t offset = 0;
ByteArray subTlv;
tlv::TlvList tlvList;
Expand Down Expand Up @@ -2290,15 +2289,15 @@ Error internal::DecodePrefixList(std::vector<Prefix> &aPrefixList, const ByteArr
if (auto hasRoute = tlvSet[tlv::Type::kNetworkDataHasRoute])
{
const ByteArray &value = hasRoute->GetValue();
SuccessOrExit(error = DecodeHasRoute(prefix.mHasRoutes, value));
SuccessOrExit(error = DecodeHasRoute(prefix.mHasRouteList, value));
}

// Get the BorderRouter
SuccessOrExit(error = tlv::GetTlvSet(tlvSet, subTlv, tlv::Scope::kNetworkData));
if (auto borderRouter = tlvSet[tlv::Type::kNetworkDataBorderRouter])
{
const ByteArray &value = borderRouter->GetValue();
SuccessOrExit(error = DecodeBorderRouter(prefix.mBorderRouters, value));
SuccessOrExit(error = DecodeBorderRouter(prefix.mBorderRouterList, value));
}

// Add the prefix to the list
Expand All @@ -2307,13 +2306,13 @@ Error internal::DecodePrefixList(std::vector<Prefix> &aPrefixList, const ByteArr
exit:
return error;
}
Error internal::DecodeHasRoute(std::vector<HasRoute> &aHasRoutes, const ByteArray &aBuf)
Error internal::DecodeHasRoute(std::vector<HasRouteEntry> &aHasRouteList, const ByteArray &aBuf)
{
Error error;
size_t length = aBuf.size();
HasRoute hasRoute;
uint8_t offset = 0;
tlv::TlvList tlvList;
Error error;
size_t length = aBuf.size();
HasRouteEntry hasRoute;
uint8_t offset = 0;
tlv::TlvList tlvList;

VerifyOrExit((length % kHasRouteBytes == 0), error = ERROR_BAD_FORMAT("incorrect size of HasRoute"));
while (offset < length)
Expand All @@ -2323,19 +2322,19 @@ Error internal::DecodeHasRoute(std::vector<HasRoute> &aHasRoutes, const ByteArra
hasRoute.mIsNat64 = (aBuf[offset] >> 5) & 0x01;
hasRoute.mRouterPreference = (aBuf[offset] >> 6) & 0x03;
offset += 1;
aHasRoutes.emplace_back(hasRoute);
aHasRouteList.emplace_back(hasRoute);
}
exit:
return error;
}

Error internal::DecodeBorderRouter(std::vector<BorderRouter> &aBorderRouters, const ByteArray &aBuf)
Error internal::DecodeBorderRouter(std::vector<BorderRouterEntry> &aBorderRouterList, const ByteArray &aBuf)
{
Error error;
size_t length = aBuf.size();
BorderRouter borderRouter;
uint8_t offset = 0;
tlv::TlvList tlvList;
Error error;
size_t length = aBuf.size();
BorderRouterEntry borderRouter;
uint8_t offset = 0;
tlv::TlvList tlvList;
VerifyOrExit((length % kBorderRouterBytes == 0), error = ERROR_BAD_FORMAT("incorrect size of BorderRouter"));
while (offset < length)
{
Expand All @@ -2352,7 +2351,7 @@ Error internal::DecodeBorderRouter(std::vector<BorderRouter> &aBorderRouters, co
borderRouter.mIsNdDns = (aBuf[offset] >> 7) & 0x01;
borderRouter.mIsDp = (aBuf[offset] >> 6) & 0x01;
offset += 1;
aBorderRouters.emplace_back(borderRouter);
aBorderRouterList.emplace_back(borderRouter);
}

exit:
Expand Down
10 changes: 5 additions & 5 deletions src/library/commissioner_impl_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ Error DecodeRoute64(Route64 &aRoute64, const ByteArray &aBuf);
void DecodeRouteDataEntry(RouteDataEntry &aRouteDataEntry, uint8_t aBuf);
ByteArray ExtractRouterIds(const ByteArray &aMask);

Error DecodeNetworkData(NetworkData &aNetworkData, const ByteArray &aBuf);
Error DecodePrefixList(std::vector<Prefix> &aPrefixList, const ByteArray &aBuf);
Error DecodePrefix(Prefix &aPrefix, const ByteArray &aBuf);
Error DecodeHasRoute(std::vector<HasRoute> &aHasRoutes, const ByteArray &aBuf);
Error DecodeBorderRouter(std::vector<BorderRouter> &aBorderRouters, const ByteArray &aBuf);
Error DecodeNetworkData(NetworkDataTlv &aNetworkData, const ByteArray &aBuf);
Error DecodePrefixList(std::vector<PrefixEntry> &aPrefixList, const ByteArray &aBuf);
Error DecodePrefix(PrefixEntry &aPrefix, const ByteArray &aBuf);
Error DecodeHasRoute(std::vector<HasRouteEntry> &aHasRouteList, const ByteArray &aBuf);
Error DecodeBorderRouter(std::vector<BorderRouterEntry> &aBorderRouterList, const ByteArray &aBuf);
Error DecodeContext(SixLowPanContext &aSixLowPanContext, const ByteArray &aBuf);

} // namespace internal
Expand Down
42 changes: 21 additions & 21 deletions src/library/commissioner_impl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,27 @@ TEST(CommissionerImplTest, ValidInput_DecodeNetDiagData)
EXPECT_EQ(diagData.mNetworkData.mPrefixList.size(), 3);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mDomainId, 0);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mPrefixLength, 1);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes.size(), 3);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[0].mRloc16, 58368);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[0].mRouterPreference, 0);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[0].mIsNat64, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[1].mRloc16, 33792);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[1].mRouterPreference, 0);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[1].mIsNat64, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[2].mRloc16, 39936);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[2].mRouterPreference, 0);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRoutes[2].mIsNat64, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters.size(), 1);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mRloc16, 58368);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mPrefixPreference, 3);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsPreferred, true);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsSlaac, true);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsDhcp, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsConfigure, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsDefaultRoute, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsOnMesh, true);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsNdDns, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouters[0].mIsDp, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList.size(), 3);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[0].mRloc16, 58368);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[0].mRouterPreference, 0);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[0].mIsNat64, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[1].mRloc16, 33792);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[1].mRouterPreference, 0);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[1].mIsNat64, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[2].mRloc16, 39936);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[2].mRouterPreference, 0);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[0].mHasRouteList[2].mIsNat64, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList.size(), 1);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mRloc16, 58368);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mPrefixPreference, 3);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsPreferred, true);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsSlaac, true);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsDhcp, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsConfigure, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsDefaultRoute, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsOnMesh, true);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsNdDns, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mBorderRouterList[0].mIsDp, false);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mSixLowPanContext.mIsCompress, true);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mSixLowPanContext.mContextId, 2);
EXPECT_EQ(diagData.mNetworkData.mPrefixList[1].mSixLowPanContext.mContextLength, 64);
Expand Down

0 comments on commit 5f187e7

Please sign in to comment.