[link-metrics] refactor link metrics module (#8966)

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.
This commit is contained in:
Li Cao
2023-05-04 20:58:06 -07:00
committed by GitHub
parent 9affbabc53
commit 612f21e776
11 changed files with 690 additions and 642 deletions
+16 -17
View File
@@ -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"
@@ -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
@@ -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,
@@ -81,13 +80,13 @@ 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,
@@ -95,10 +94,10 @@ otError otLinkMetricsSendLinkProbe(otInstance *aInstance,
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
+5 -2
View File
@@ -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)
+12 -4
View File
@@ -563,8 +563,12 @@ private:
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
@@ -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)
+5 -3
View File
@@ -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
@@ -2304,7 +2306,7 @@ exit:
}
#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;
@@ -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)
File diff suppressed because it is too large Load Diff
+155 -129
View File
@@ -71,16 +71,18 @@ namespace LinkMetrics {
* @{
*/
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
/**
* This class implements Thread Link Metrics query and management.
* This class implements the Thread Link Metrics Initiator.
*
* The Initiator makes queries, configures Link Metrics probing at the Subject and generates reports of the results.
*
*/
class LinkMetrics : public InstanceLocator, private NonCopyable
class Initiator : public InstanceLocator, private NonCopyable
{
friend class ot::Neighbor;
friend class ot::UnitTester;
public:
// Initiator callbacks
typedef otLinkMetricsReportCallback ReportCallback;
typedef otLinkMetricsMgmtResponseCallback MgmtResponseCallback;
typedef otLinkMetricsEnhAckProbingIeReportCallback EnhAckProbingIeReportCallback;
@@ -97,12 +99,12 @@ public:
};
/**
* This constructor initializes an instance of the LinkMetrics class.
* This constructor initializes an instance of the Initiator class.
*
* @param[in] aInstance A reference to the OpenThread interface.
*
*/
explicit LinkMetrics(Instance &aInstance);
explicit Initiator(Instance &aInstance);
/**
* This method sends an MLE Data Request containing Link Metrics Query TLV to query Link Metrics data.
@@ -121,7 +123,38 @@ public:
*/
Error Query(const Ip6::Address &aDestination, uint8_t aSeriesId, const Metrics *aMetrics);
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
/**
* This method appends MLE Link Metrics Query TLV to a given message.
*
* @param[in] aMessage The message to append to.
* @param[in] aInfo The link metrics query info to use to prepare the message.
*
* @retval kErrorNone Successfully appended the TLV to the message.
* @retval kErrorNoBufs Insufficient buffers available to append the TLV.
*
*/
Error AppendLinkMetricsQueryTlv(Message &aMessage, const QueryInfo &aInfo);
/**
* This method registers a callback to handle Link Metrics report received.
*
* @param[in] aCallback A pointer to a function that is called when a Link Metrics report is received.
* @param[in] aContext A pointer to application-specific context.
*
*/
void SetReportCallback(ReportCallback aCallback, void *aContext) { mReportCallback.Set(aCallback, aContext); }
/**
* This method handles the received Link Metrics report contained in @p aMessage.
*
* @param[in] aMessage A reference to the message.
* @param[in] aOffset The offset in bytes where the metrics report sub-TLVs start.
* @param[in] aLength The length of the metrics report sub-TLVs in bytes.
* @param[in] aAddress A reference to the source address of the message.
*
*/
void HandleReport(const Message &aMessage, uint16_t aOffset, uint16_t aLength, const Ip6::Address &aAddress);
/**
* This method sends an MLE Link Metrics Management Request to configure/clear a Forward Tracking Series.
*
@@ -141,6 +174,18 @@ public:
const SeriesFlags &aSeriesFlags,
const Metrics *aMetrics);
/**
* This method registers a callback to handle Link Metrics Management Response received.
*
* @param[in] aCallback A pointer to a function that is called when a Link Metrics Management Response is received.
* @param[in] aContext A pointer to application-specific context.
*
*/
void SetMgmtResponseCallback(MgmtResponseCallback aCallback, void *aContext)
{
mMgmtResponseCallback.Set(aCallback, aContext);
}
/**
* This method sends an MLE Link Metrics Management Request to configure/clear a Enhanced-ACK Based Probing.
*
@@ -161,48 +206,16 @@ public:
const Metrics *aMetrics);
/**
* This method sends an MLE Link Probe message.
* This method registers a callback to handle Link Metrics when Enh-ACK Probing IE is received.
*
* @param[in] aDestination A reference to the IPv6 address of the destination.
* @param[in] aSeriesId The Series ID which the Probe message targets at.
* @param[in] aLength The length of the data payload in Link Probe TLV, [0, 64].
*
* @retval kErrorNone Successfully sent a Link Probe message.
* @retval kErrorNoBufs Insufficient buffers to generate the MLE Link Probe message.
* @retval kErrorInvalidArgs @p aSeriesId or @p aLength is not within the valid range.
* @retval kErrorUnknownNeighbor @p aDestination is not link-local or the neighbor is not found.
* @param[in] aCallback A pointer to a function that is called when Enh-ACK Probing IE is received is received.
* @param[in] aContext A pointer to application-specific context.
*
*/
Error SendLinkProbe(const Ip6::Address &aDestination, uint8_t aSeriesId, uint8_t aLength);
#endif
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
/**
* This method appends a Link Metrics Report to a message according to the Link Metrics query.
*
* @param[out] aMessage A reference to the message to append report.
* @param[in] aRequestMessage A reference to the message of the Data Request.
* @param[in] aNeighbor A reference to the neighbor who queries the report.
*
* @retval kErrorNone Successfully appended the Thread Discovery TLV.
* @retval kErrorParse Cannot parse query sub TLV successfully.
* @retval kErrorInvalidArgs QueryId is invalid or any Type ID is invalid.
*
*/
Error AppendReport(Message &aMessage, const Message &aRequestMessage, Neighbor &aNeighbor);
#endif
/**
* This method handles the received Link Metrics Management Request contained in @p aMessage and return a status.
*
* @param[in] aMessage A reference to the message that contains the Link Metrics Management Request.
* @param[in] aNeighbor A reference to the neighbor who sends the request.
* @param[out] aStatus A reference to the status which indicates the handling result.
*
* @retval kErrorNone Successfully handled the Link Metrics Management Request.
* @retval kErrorParse Cannot parse sub-TLVs from @p aMessage successfully.
*
*/
Error HandleManagementRequest(const Message &aMessage, Neighbor &aNeighbor, Status &aStatus);
void SetEnhAckProbingCallback(EnhAckProbingIeReportCallback aCallback, void *aContext)
{
mEnhAckProbingIeReportCallback.Set(aCallback, aContext);
}
/**
* This method handles the received Link Metrics Management Response contained in @p aMessage.
@@ -217,15 +230,89 @@ public:
Error HandleManagementResponse(const Message &aMessage, const Ip6::Address &aAddress);
/**
* This method handles the received Link Metrics report contained in @p aMessage.
* This method sends an MLE Link Probe message.
*
* @param[in] aMessage A reference to the message.
* @param[in] aOffset The offset in bytes where the metrics report sub-TLVs start.
* @param[in] aLength The length of the metrics report sub-TLVs in bytes.
* @param[in] aAddress A reference to the source address of the message.
* @param[in] aDestination A reference to the IPv6 address of the destination.
* @param[in] aSeriesId The Series ID which the Probe message targets at.
* @param[in] aLength The length of the data payload in Link Probe TLV, [0, 64].
*
* @retval kErrorNone Successfully sent a Link Probe message.
* @retval kErrorNoBufs Insufficient buffers to generate the MLE Link Probe message.
* @retval kErrorInvalidArgs @p aSeriesId or @p aLength is not within the valid range.
* @retval kErrorUnknownNeighbor @p aDestination is not link-local or the neighbor is not found.
*
*/
void HandleReport(const Message &aMessage, uint16_t aOffset, uint16_t aLength, const Ip6::Address &aAddress);
Error SendLinkProbe(const Ip6::Address &aDestination, uint8_t aSeriesId, uint8_t aLength);
/**
* This method processes received Enh-ACK Probing IE data.
*
* @param[in] aData A pointer to buffer containing the Enh-ACK Probing IE data.
* @param[in] aLength The length of @p aData.
* @param[in] aNeighbor The neighbor from which the Enh-ACK Probing IE was received.
*
*/
void ProcessEnhAckIeData(const uint8_t *aData, uint8_t aLength, const Neighbor &aNeighbor);
private:
static constexpr uint8_t kLinkProbeMaxLen = 64; // Max length of data payload in Link Probe TLV.
Error FindNeighbor(const Ip6::Address &aDestination, Neighbor *&aNeighbor);
Callback<ReportCallback> mReportCallback;
Callback<MgmtResponseCallback> mMgmtResponseCallback;
Callback<EnhAckProbingIeReportCallback> mEnhAckProbingIeReportCallback;
};
#endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
/**
* This class implements the Thread Link Metrics Subject.
*
* The Subject reponds queries with reports, handles Link Metrics Management Requests and Link Probe Messages.
*
*/
class Subject : public InstanceLocator, private NonCopyable
{
public:
typedef otLinkMetricsEnhAckProbingIeReportCallback EnhAckProbingIeReportCallback;
/**
* This constructor initializes an instance of the Subject class.
*
* @param[in] aInstance A reference to the OpenThread interface.
*
*/
explicit Subject(Instance &aInstance);
/**
* This method appends a Link Metrics Report to a message according to the Link Metrics query.
*
* @param[out] aMessage A reference to the message to append report.
* @param[in] aRequestMessage A reference to the message of the Data Request.
* @param[in] aNeighbor A reference to the neighbor who queries the report.
*
* @retval kErrorNone Successfully appended the Thread Discovery TLV.
* @retval kErrorParse Cannot parse query sub TLV successfully.
* @retval kErrorInvalidArgs QueryId is invalid or any Type ID is invalid.
*
*/
Error AppendReport(Message &aMessage, const Message &aRequestMessage, Neighbor &aNeighbor);
/**
* This method handles the received Link Metrics Management Request contained in @p aMessage and return a status.
*
* @param[in] aMessage A reference to the message that contains the Link Metrics Management Request.
* @param[in] aNeighbor A reference to the neighbor who sends the request.
* @param[out] aStatus A reference to the status which indicates the handling result.
*
* @retval kErrorNone Successfully handled the Link Metrics Management Request.
* @retval kErrorParse Cannot parse sub-TLVs from @p aMessage successfully.
*
*/
Error HandleManagementRequest(const Message &aMessage, Neighbor &aNeighbor, Status &aStatus);
/**
* This method handles the Link Probe contained in @p aMessage.
@@ -240,100 +327,39 @@ public:
Error HandleLinkProbe(const Message &aMessage, uint8_t &aSeriesId);
/**
* This method registers a callback to handle Link Metrics report received.
* This method frees a SeriesInfo entry that was allocated from the Subject object.
*
* @param[in] aCallback A pointer to a function that is called when a Link Metrics report is received.
* @param[in] aContext A pointer to application-specific context.
* @param[in] aSeries A reference to the SeriesInfo to free.
*
*/
void SetReportCallback(ReportCallback aCallback, void *aContext) { mReportCallback.Set(aCallback, aContext); }
/**
* This method registers a callback to handle Link Metrics Management Response received.
*
* @param[in] aCallback A pointer to a function that is called when a Link Metrics Management Response is received.
* @param[in] aContext A pointer to application-specific context.
*
*/
void SetMgmtResponseCallback(MgmtResponseCallback aCallback, void *aContext)
{
mMgmtResponseCallback.Set(aCallback, aContext);
}
/**
* This method registers a callback to handle Link Metrics when Enh-ACK Probing IE is received.
*
* @param[in] aCallback A pointer to a function that is called when Enh-ACK Probing IE is received is received.
* @param[in] aContext A pointer to application-specific context.
*
*/
void SetEnhAckProbingCallback(EnhAckProbingIeReportCallback aCallback, void *aContext)
{
mEnhAckProbingIeReportCallback.Set(aCallback, aContext);
}
/**
* This method processes received Enh-ACK Probing IE data.
*
* @param[in] aData A pointer to buffer containing the Enh-ACK Probing IE data.
* @param[in] aLength The length of @p aData.
* @param[in] aNeighbor The neighbor from which the Enh-ACK Probing IE was received.
*
*/
void ProcessEnhAckIeData(const uint8_t *aData, uint8_t aLength, const Neighbor &aNeighbor);
/**
* This method appends MLE Link Metrics Query TLV to a given message.
*
* @param[in] aMessage The message to append to.
* @param[in] aInfo The link metrics query info to use to prepare the message.
*
* @retval kErrorNone Successfully appended the TLV to the message.
* @retval kErrorNoBufs Insufficient buffers available to append the TLV.
*
*/
Error AppendLinkMetricsQueryTlv(Message &aMessage, const QueryInfo &aInfo);
void Free(SeriesInfo &aSeriesInfo);
private:
// Max number of SeriesInfo that could be allocated by the pool.
static constexpr uint16_t kMaxSeriesSupported = OPENTHREAD_CONFIG_MLE_LINK_METRICS_MAX_SERIES_SUPPORTED;
static constexpr uint8_t kQueryIdSingleProbe = 0; // This query ID represents Single Probe.
static constexpr uint8_t kSeriesIdAllSeries = 255; // This series ID represents all series.
static constexpr uint8_t kLinkProbeMaxLen = 64; // Max length of data payload in Link Probe TLV.
// Constants for scaling Link Margin and RSSI to raw value
static constexpr uint8_t kMaxLinkMargin = 130;
static constexpr int32_t kMinRssi = -130;
static constexpr int32_t kMaxRssi = 0;
Status ConfigureForwardTrackingSeries(uint8_t aSeriesId,
uint8_t aSeriesFlags,
const Metrics &aMetrics,
Neighbor &aNeighbor);
Status ConfigureEnhAckProbing(uint8_t aEnhAckFlags, const Metrics &aMetrics, Neighbor &aNeighbor);
Error FindNeighbor(const Ip6::Address &aDestination, Neighbor *&aNeighbor) const;
static Error ReadTypeIdsFromMessage(const Message &aMessage,
uint16_t aStartOffset,
uint16_t aEndOffset,
Metrics &aMetrics);
static Error AppendReportSubTlvToMessage(Message &aMessage, const MetricsValues &aValues);
static uint8_t ScaleLinkMarginToRawValue(uint8_t aLinkMargin);
static uint8_t ScaleRawValueToLinkMargin(uint8_t aRawValue);
static uint8_t ScaleRssiToRawValue(int8_t aRssi);
static int8_t ScaleRawValueToRssi(uint8_t aRawValue);
Callback<ReportCallback> mReportCallback;
Callback<MgmtResponseCallback> mMgmtResponseCallback;
Callback<EnhAckProbingIeReportCallback> mEnhAckProbingIeReportCallback;
Status ConfigureForwardTrackingSeries(uint8_t aSeriesId,
uint8_t aSeriesFlags,
const Metrics &aMetrics,
Neighbor &aNeighbor);
Status ConfigureEnhAckProbing(uint8_t aEnhAckFlags, const Metrics &aMetrics, Neighbor &aNeighbor);
Pool<SeriesInfo, kMaxSeriesSupported> mSeriesInfoPool;
};
#endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
uint8_t ScaleLinkMarginToRawValue(uint8_t aLinkMargin);
uint8_t ScaleRawValueToLinkMargin(uint8_t aRawValue);
uint8_t ScaleRssiToRawValue(int8_t aRssi);
int8_t ScaleRawValueToRssi(uint8_t aRawValue);
/**
* @}
*/
+15 -15
View File
@@ -1857,20 +1857,20 @@ Error Mle::SendDataRequestAfterDelay(const Ip6::Address &aDestination, uint16_t
return SendDataRequest(aDestination, kTlvs, mRequestRouteTlv ? 2 : 1, aDelay);
}
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
Error Mle::SendDataRequestForLinkMetricsReport(const Ip6::Address &aDestination,
const LinkMetrics::LinkMetrics::QueryInfo &aQueryInfo)
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
Error Mle::SendDataRequestForLinkMetricsReport(const Ip6::Address &aDestination,
const LinkMetrics::Initiator::QueryInfo &aQueryInfo)
{
static const uint8_t kTlvs[] = {Tlv::kLinkMetricsReport};
return SendDataRequest(aDestination, kTlvs, sizeof(kTlvs), /* aDelay */ 0, &aQueryInfo);
}
Error Mle::SendDataRequest(const Ip6::Address &aDestination,
const uint8_t *aTlvs,
uint8_t aTlvsLength,
uint16_t aDelay,
const LinkMetrics::LinkMetrics::QueryInfo *aQueryInfo)
Error Mle::SendDataRequest(const Ip6::Address &aDestination,
const uint8_t *aTlvs,
uint8_t aTlvsLength,
uint16_t aDelay,
const LinkMetrics::Initiator::QueryInfo *aQueryInfo)
#else
Error Mle::SendDataRequest(const Ip6::Address &aDestination, const uint8_t *aTlvs, uint8_t aTlvsLength, uint16_t aDelay)
#endif
@@ -1883,10 +1883,10 @@ Error Mle::SendDataRequest(const Ip6::Address &aDestination, const uint8_t *aTlv
VerifyOrExit((message = NewMleMessage(kCommandDataRequest)) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->AppendTlvRequestTlv(aTlvs, aTlvsLength));
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
if (aQueryInfo != nullptr)
{
SuccessOrExit(error = Get<LinkMetrics::LinkMetrics>().AppendLinkMetricsQueryTlv(*message, *aQueryInfo));
SuccessOrExit(error = Get<LinkMetrics::Initiator>().AppendLinkMetricsQueryTlv(*message, *aQueryInfo));
}
#endif
@@ -2840,8 +2840,8 @@ void Mle::HandleDataResponse(RxInfo &aRxInfo)
if (Tlv::FindTlvValueOffset(aRxInfo.mMessage, Tlv::kLinkMetricsReport, offset, length) == kErrorNone)
{
Get<LinkMetrics::LinkMetrics>().HandleReport(aRxInfo.mMessage, offset, length,
aRxInfo.mMessageInfo.GetPeerAddr());
Get<LinkMetrics::Initiator>().HandleReport(aRxInfo.mMessage, offset, length,
aRxInfo.mMessageInfo.GetPeerAddr());
}
}
#endif
@@ -3779,7 +3779,7 @@ void Mle::HandleLinkMetricsManagementRequest(RxInfo &aRxInfo)
VerifyOrExit(aRxInfo.mNeighbor != nullptr, error = kErrorInvalidState);
SuccessOrExit(
error = Get<LinkMetrics::LinkMetrics>().HandleManagementRequest(aRxInfo.mMessage, *aRxInfo.mNeighbor, status));
error = Get<LinkMetrics::Subject>().HandleManagementRequest(aRxInfo.mMessage, *aRxInfo.mNeighbor, status));
error = SendLinkMetricsManagementResponse(aRxInfo.mMessageInfo.GetPeerAddr(), status);
@@ -3801,7 +3801,7 @@ void Mle::HandleLinkMetricsManagementResponse(RxInfo &aRxInfo)
VerifyOrExit(aRxInfo.mNeighbor != nullptr, error = kErrorInvalidState);
error =
Get<LinkMetrics::LinkMetrics>().HandleManagementResponse(aRxInfo.mMessage, aRxInfo.mMessageInfo.GetPeerAddr());
Get<LinkMetrics::Initiator>().HandleManagementResponse(aRxInfo.mMessage, aRxInfo.mMessageInfo.GetPeerAddr());
aRxInfo.mClass = RxInfo::kPeerMessage;
@@ -3818,7 +3818,7 @@ void Mle::HandleLinkProbe(RxInfo &aRxInfo)
Log(kMessageReceive, kTypeLinkProbe, aRxInfo.mMessageInfo.GetPeerAddr());
SuccessOrExit(error = Get<LinkMetrics::LinkMetrics>().HandleLinkProbe(aRxInfo.mMessage, seriesId));
SuccessOrExit(error = Get<LinkMetrics::Subject>().HandleLinkProbe(aRxInfo.mMessage, seriesId));
aRxInfo.mNeighbor->AggregateLinkMetrics(seriesId, LinkMetrics::SeriesInfo::kSeriesTypeLinkProbe,
aRxInfo.mMessage.GetAverageLqi(), aRxInfo.mMessage.GetAverageRss());
+12 -14
View File
@@ -103,8 +103,8 @@ class Mle : public InstanceLocator, private NonCopyable
friend class DiscoverScanner;
friend class ot::Notifier;
friend class ot::SupervisionListener;
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
friend class ot::LinkMetrics::LinkMetrics;
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
friend class ot::LinkMetrics::Initiator;
#endif
public:
@@ -1536,7 +1536,7 @@ protected:
*/
Error SendDataRequest(const Ip6::Address &aDestination);
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
/**
* This method generates an MLE Data Request message which request Link Metrics Report TLV.
*
@@ -1547,8 +1547,8 @@ protected:
* @retval kErrorNoBufs Insufficient buffers to generate the MLE Data Request message.
*
*/
Error SendDataRequestForLinkMetricsReport(const Ip6::Address &aDestination,
const LinkMetrics::LinkMetrics::QueryInfo &aQueryInfo);
Error SendDataRequestForLinkMetricsReport(const Ip6::Address &aDestination,
const LinkMetrics::Initiator::QueryInfo &aQueryInfo);
#endif
/**
@@ -1976,12 +1976,12 @@ private:
Error SendChildUpdateRequest(ChildUpdateRequestMode aMode);
Error SendDataRequestAfterDelay(const Ip6::Address &aDestination, uint16_t aDelay);
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
Error SendDataRequest(const Ip6::Address &aDestination,
const uint8_t *aTlvs,
uint8_t aTlvsLength,
uint16_t aDelay,
const LinkMetrics::LinkMetrics::QueryInfo *aQueryInfo = nullptr);
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
Error SendDataRequest(const Ip6::Address &aDestination,
const uint8_t *aTlvs,
uint8_t aTlvsLength,
uint16_t aDelay,
const LinkMetrics::Initiator::QueryInfo *aQueryInfo = nullptr);
#else
Error SendDataRequest(const Ip6::Address &aDestination, const uint8_t *aTlvs, uint8_t aTlvsLength, uint16_t aDelay);
#endif
@@ -2003,12 +2003,10 @@ private:
void HandleAnnounce(RxInfo &aRxInfo);
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
void HandleLinkMetricsManagementRequest(RxInfo &aRxInfo);
void HandleLinkProbe(RxInfo &aRxInfo);
#endif
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
void HandleLinkMetricsManagementResponse(RxInfo &aRxInfo);
#endif
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
void HandleLinkProbe(RxInfo &aRxInfo);
#endif
Error HandleLeaderData(RxInfo &aRxInfo);
void ProcessAnnounce(void);
+1 -1
View File
@@ -3167,7 +3167,7 @@ void MleRouter::SendDataResponse(const Ip6::Address &aDestination,
OT_ASSERT(aRequestMessage != nullptr);
neighbor = mNeighborTable.FindNeighbor(aDestination);
VerifyOrExit(neighbor != nullptr, error = kErrorInvalidState);
SuccessOrExit(error = Get<LinkMetrics::LinkMetrics>().AppendReport(*message, *aRequestMessage, *neighbor));
SuccessOrExit(error = Get<LinkMetrics::Subject>().AppendReport(*message, *aRequestMessage, *neighbor));
break;
#endif
}
+1 -1
View File
@@ -208,7 +208,7 @@ void Neighbor::RemoveAllForwardTrackingSeriesInfo(void)
while (!mLinkMetricsSeriesInfoList.IsEmpty())
{
LinkMetrics::SeriesInfo *seriesInfo = mLinkMetricsSeriesInfoList.Pop();
Get<LinkMetrics::LinkMetrics>().mSeriesInfoPool.Free(*seriesInfo);
Get<LinkMetrics::Subject>().Free(*seriesInfo);
}
}
#endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
+10 -10
View File
@@ -494,13 +494,13 @@ public:
printf("\nLinkMargin : %-3u -> Scaled : %.1f (rounded:%u)", linkMargin, scaled, scaledAsU8);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleLinkMarginToRawValue(linkMargin) == scaledAsU8);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleRawValueToLinkMargin(scaledAsU8) == linkMargin);
VerifyOrQuit(LinkMetrics::ScaleLinkMarginToRawValue(linkMargin) == scaledAsU8);
VerifyOrQuit(LinkMetrics::ScaleRawValueToLinkMargin(scaledAsU8) == linkMargin);
}
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleLinkMarginToRawValue(131) == 255);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleLinkMarginToRawValue(150) == 255);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleLinkMarginToRawValue(255) == 255);
VerifyOrQuit(LinkMetrics::ScaleLinkMarginToRawValue(131) == 255);
VerifyOrQuit(LinkMetrics::ScaleLinkMarginToRawValue(150) == 255);
VerifyOrQuit(LinkMetrics::ScaleLinkMarginToRawValue(255) == 255);
// Test RSSI scaling from [-130, 0] -> [0, 255]
@@ -511,13 +511,13 @@ public:
printf("\nRSSI : %-3d -> Scaled :%.1f (rounded:%u)", rssi, scaled, scaledAsU8);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleRssiToRawValue(rssi) == scaledAsU8);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleRawValueToRssi(scaledAsU8) == rssi);
VerifyOrQuit(LinkMetrics::ScaleRssiToRawValue(rssi) == scaledAsU8);
VerifyOrQuit(LinkMetrics::ScaleRawValueToRssi(scaledAsU8) == rssi);
}
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleRssiToRawValue(1) == 255);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleRssiToRawValue(10) == 255);
VerifyOrQuit(LinkMetrics::LinkMetrics::ScaleRssiToRawValue(127) == 255);
VerifyOrQuit(LinkMetrics::ScaleRssiToRawValue(1) == 255);
VerifyOrQuit(LinkMetrics::ScaleRssiToRawValue(10) == 255);
VerifyOrQuit(LinkMetrics::ScaleRssiToRawValue(127) == 255);
}
};