Skip to content

Commit

Permalink
[link-metrics] refactor link metrics module (#8966)
Browse files Browse the repository at this point in the history
This commit breaks Link Metrics Initiator and Subject into two classes
and fixes incorrect swtich guard. For example, code for Initiator was
guarded by macro of Subject.
  • Loading branch information
Irving-cl authored May 5, 2023
1 parent 9affbab commit 612f21e
Show file tree
Hide file tree
Showing 11 changed files with 544 additions and 496 deletions.
33 changes: 16 additions & 17 deletions src/core/api/link_metrics_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

#include "openthread-core-config.h"

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
#include <openthread/link_metrics.h>

#include "common/as_core_type.hpp"
Expand All @@ -49,10 +48,10 @@ otError otLinkMetricsQuery(otInstance *aInstance,
otLinkMetricsReportCallback aCallback,
void *aCallbackContext)
{
AsCoreType(aInstance).Get<LinkMetrics::LinkMetrics>().SetReportCallback(aCallback, aCallbackContext);
AsCoreType(aInstance).Get<LinkMetrics::Initiator>().SetReportCallback(aCallback, aCallbackContext);

return AsCoreType(aInstance).Get<LinkMetrics::LinkMetrics>().Query(AsCoreType(aDestination), aSeriesId,
AsCoreTypePtr(aLinkMetricsFlags));
return AsCoreType(aInstance).Get<LinkMetrics::Initiator>().Query(AsCoreType(aDestination), aSeriesId,
AsCoreTypePtr(aLinkMetricsFlags));
}

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
Expand All @@ -64,12 +63,12 @@ otError otLinkMetricsConfigForwardTrackingSeries(otInstance
otLinkMetricsMgmtResponseCallback aCallback,
void *aCallbackContext)
{
LinkMetrics::LinkMetrics &linkMetrics = AsCoreType(aInstance).Get<LinkMetrics::LinkMetrics>();
LinkMetrics::Initiator &initiator = AsCoreType(aInstance).Get<LinkMetrics::Initiator>();

linkMetrics.SetMgmtResponseCallback(aCallback, aCallbackContext);
initiator.SetMgmtResponseCallback(aCallback, aCallbackContext);

return linkMetrics.SendMgmtRequestForwardTrackingSeries(
AsCoreType(aDestination), aSeriesId, AsCoreType(&aSeriesFlags), AsCoreTypePtr(aLinkMetricsFlags));
return initiator.SendMgmtRequestForwardTrackingSeries(AsCoreType(aDestination), aSeriesId,
AsCoreType(&aSeriesFlags), AsCoreTypePtr(aLinkMetricsFlags));
}

otError otLinkMetricsConfigEnhAckProbing(otInstance *aInstance,
Expand All @@ -81,24 +80,24 @@ otError otLinkMetricsConfigEnhAckProbing(otInstance
otLinkMetricsEnhAckProbingIeReportCallback aEnhAckCallback,
void *aEnhAckCallbackContext)
{
LinkMetrics::LinkMetrics &linkMetrics = AsCoreType(aInstance).Get<LinkMetrics::LinkMetrics>();
LinkMetrics::Initiator &initiator = AsCoreType(aInstance).Get<LinkMetrics::Initiator>();

linkMetrics.SetMgmtResponseCallback(aCallback, aCallbackContext);
linkMetrics.SetEnhAckProbingCallback(aEnhAckCallback, aEnhAckCallbackContext);
initiator.SetMgmtResponseCallback(aCallback, aCallbackContext);
initiator.SetEnhAckProbingCallback(aEnhAckCallback, aEnhAckCallbackContext);

return linkMetrics.SendMgmtRequestEnhAckProbing(AsCoreType(aDestination), MapEnum(aEnhAckFlags),
AsCoreTypePtr(aLinkMetricsFlags));
return initiator.SendMgmtRequestEnhAckProbing(AsCoreType(aDestination), MapEnum(aEnhAckFlags),
AsCoreTypePtr(aLinkMetricsFlags));
}

otError otLinkMetricsSendLinkProbe(otInstance *aInstance,
const otIp6Address *aDestination,
uint8_t aSeriesId,
uint8_t aLength)
{
LinkMetrics::LinkMetrics &linkMetrics = AsCoreType(aInstance).Get<LinkMetrics::LinkMetrics>();
LinkMetrics::Initiator &initiator = AsCoreType(aInstance).Get<LinkMetrics::Initiator>();

return linkMetrics.SendLinkProbe(AsCoreType(aDestination), aSeriesId, aLength);
return initiator.SendLinkProbe(AsCoreType(aDestination), aSeriesId, aLength);
}
#endif

#endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
#endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
7 changes: 5 additions & 2 deletions src/core/common/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ Instance::Instance(void)
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
, mTimeSync(*this)
#endif
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
, mLinkMetrics(*this)
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
, mInitiator(*this)
#endif
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
, mSubject(*this)
#endif
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
, mApplicationCoap(*this)
Expand Down
16 changes: 12 additions & 4 deletions src/core/common/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,12 @@ class Instance : public otInstance, private NonCopyable
TimeSync mTimeSync;
#endif

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
LinkMetrics::LinkMetrics mLinkMetrics;
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
LinkMetrics::Initiator mInitiator;
#endif

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
LinkMetrics::Subject mSubject;
#endif

#if OPENTHREAD_CONFIG_COAP_API_ENABLE
Expand Down Expand Up @@ -930,8 +934,12 @@ template <> inline MlrManager &Instance::Get(void) { return mMlrManager; }
template <> inline DuaManager &Instance::Get(void) { return mDuaManager; }
#endif

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
template <> inline LinkMetrics::LinkMetrics &Instance::Get(void) { return mLinkMetrics; }
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
template <> inline LinkMetrics::Initiator &Instance::Get(void) { return mInitiator; }
#endif

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
template <> inline LinkMetrics::Subject &Instance::Get(void) { return mSubject; }
#endif

#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
Expand Down
8 changes: 5 additions & 3 deletions src/core/mac/mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,8 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
neighbor->AggregateLinkMetrics(/* aSeriesId */ 0, aAckFrame->GetType(), aAckFrame->GetLqi(),
aAckFrame->GetRssi());
#endif
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
ProcessEnhAckProbing(*aAckFrame, *neighbor);
#endif
#if OPENTHREAD_FTD
Expand Down Expand Up @@ -2304,7 +2306,7 @@ void Mac::ProcessCsl(const RxFrame &aFrame, const Address &aSrcAddr)
}
#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE

#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
void Mac::ProcessEnhAckProbing(const RxFrame &aFrame, const Neighbor &aNeighbor)
{
constexpr uint8_t kEnhAckProbingIeMaxLen = 2;
Expand All @@ -2320,11 +2322,11 @@ void Mac::ProcessEnhAckProbing(const RxFrame &aFrame, const Neighbor &aNeighbor)
dataLen = enhAckProbingIe->GetLength() - sizeof(VendorIeHeader);
VerifyOrExit(dataLen <= kEnhAckProbingIeMaxLen);

Get<LinkMetrics::LinkMetrics>().ProcessEnhAckIeData(data, dataLen, aNeighbor);
Get<LinkMetrics::Initiator>().ProcessEnhAckIeData(data, dataLen, aNeighbor);
exit:
return;
}
#endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
#endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE

#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE && OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
void Mac::SetRadioFilterEnabled(bool aFilterEnabled)
Expand Down
Loading

0 comments on commit 612f21e

Please sign in to comment.