Added ip level counters (#1892)

* Added ip level counters

* Fixed style issue

* Added const to function prototype

* Removed SPINEL_ from the property return strings

* Added descriptions for ipv6 counters and moved counter logic out of logging function

* Added public API to get the IPv6 counters

* Fixed build errors with bad call to otThreadGetIPv6Counters

* Changed otThreadGetIp6Counters to return a const *

* make pretty
This commit is contained in:
Adam Eliot
2017-06-14 20:58:15 -07:00
committed by Jonathan Hui
parent b205bf03ff
commit 8b4d468c3c
9 changed files with 175 additions and 32 deletions
+10
View File
@@ -533,6 +533,16 @@ OTAPI otError OTCALL otThreadSendDiagnosticGet(otInstance *aInstance, const otIp
OTAPI otError OTCALL otThreadSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination,
const uint8_t aTlvTypes[], uint8_t aCount);
/**
* Get the IPv6 counters.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns A pointer to the IPv6 counters.
*
*/
OTAPI const otIpCounters *OTCALL otThreadGetIp6Counters(otInstance *aInstance);
/**
* @}
*
+11
View File
@@ -921,6 +921,17 @@ typedef struct otMacCounters
uint32_t mRxErrOther; ///< The number of received packets with other error.
} otMacCounters;
/**
* This structure represents the IP level counters
*/
typedef struct otIpCounters
{
uint32_t mTxSuccess; ///< The number of IPv6 packets successfully transmitted.
uint32_t mRxSuccess; ///< The number of IPv6 packets successfully received.
uint32_t mTxFailure; ///< The number of IPv6 packets failed to transmit.
uint32_t mRxFailure; ///< The number of IPv6 packets failed to receive.
} otIpCounters;
/**
* This structure represents the message buffer information.
*/
+5
View File
@@ -491,3 +491,8 @@ bool otThreadIsDiscoverInProgress(otInstance *aInstance)
{
return aInstance->mThreadNetif.GetMle().IsDiscoverInProgress();
}
const otIpCounters *otThreadGetIp6Counters(otInstance *aInstance)
{
return &aInstance->mThreadNetif.GetMeshForwarder().GetCounters();
}
+26 -1
View File
@@ -89,6 +89,11 @@ MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif):
mNetif.GetMac().RegisterReceiver(mMacReceiver);
mMacSource.mLength = 0;
mMacDest.mLength = 0;
mIpCounters.mTxSuccess = 0;
mIpCounters.mRxSuccess = 0;
mIpCounters.mTxFailure = 0;
mIpCounters.mRxFailure = 0;
}
otInstance *MeshForwarder::GetInstance(void)
@@ -1607,6 +1612,15 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
if (mMessageNextOffset >= mSendMessage->GetLength())
{
LogIp6Message(kMessageTransmit, *mSendMessage, &macDest, aError);
if (aError == OT_ERROR_NONE)
{
mIpCounters.mTxSuccess++;
}
else
{
mIpCounters.mTxFailure++;
}
}
if (mSendMessage->GetDirectTransmission() == false && mSendMessage->IsChildPending() == false)
@@ -2017,6 +2031,7 @@ void MeshForwarder::ClearReassemblyList(void)
mReassemblyList.Dequeue(*message);
LogIp6Message(kMessageDrop, *message, NULL, OT_ERROR_NO_FRAME_RECEIVED);
mIpCounters.mRxFailure++;
message->Free();
}
@@ -2046,6 +2061,7 @@ void MeshForwarder::HandleReassemblyTimer()
mReassemblyList.Dequeue(*message);
LogIp6Message(kMessageDrop, *message, NULL, OT_ERROR_REASSEMBLY_TIMEOUT);
mIpCounters.mRxFailure++;
message->Free();
}
@@ -2117,6 +2133,7 @@ otError MeshForwarder::HandleDatagram(Message &aMessage, const ThreadMessageInfo
const Mac::Address &aMacSource)
{
LogIp6Message(kMessageReceive, aMessage, &aMacSource, OT_ERROR_NONE);
mIpCounters.mRxSuccess++;
return mNetif.GetIp6().HandleDatagram(aMessage, &mNetif, mNetif.GetInterfaceId(), &aMessageInfo, false);
}
@@ -2211,7 +2228,15 @@ void MeshForwarder::LogIp6Message(MessageAction aAction, const Message &aMessage
break;
case kMessageTransmit:
actionText = (aError == OT_ERROR_NONE) ? "Sent" : "Failed to send";
if (aError == OT_ERROR_NONE)
{
actionText = "Sent";
}
else
{
actionText = "Failed to send";
}
break;
case kMessagePrepareIndirect:
+42 -31
View File
@@ -218,6 +218,14 @@ public:
*/
SourceMatchController &GetSourceMatchController(void) { return mSourceMatchController; }
/**
* This method returns a reference to the IP level counters.
*
* @returns A reference to the IP level counters.
*
*/
const otIpCounters &GetCounters(void) const { return mIpCounters; }
private:
enum
{
@@ -298,46 +306,49 @@ private:
void LogIp6Message(MessageAction aAction, const Message &aMessage, const Mac::Address *aMacAddress,
otError aError);
ThreadNetif &mNetif;
Mac::Receiver mMacReceiver;
Mac::Sender mMacSender;
Timer mDiscoverTimer;
Timer mReassemblyTimer;
ThreadNetif &mNetif;
PriorityQueue mSendQueue;
MessageQueue mReassemblyList;
MessageQueue mResolvingQueue;
uint16_t mFragTag;
uint16_t mMessageNextOffset;
Mac::Receiver mMacReceiver;
Mac::Sender mMacSender;
Timer mDiscoverTimer;
Timer mReassemblyTimer;
uint32_t mSendMessageFrameCounter;
Message *mSendMessage;
bool mSendMessageIsARetransmission;
uint8_t mSendMessageMaxMacTxAttempts;
uint8_t mSendMessageKeyId;
uint8_t mSendMessageDataSequenceNumber;
uint8_t mStartChildIndex;
PriorityQueue mSendQueue;
MessageQueue mReassemblyList;
MessageQueue mResolvingQueue;
uint16_t mFragTag;
uint16_t mMessageNextOffset;
Mac::Address mMacSource;
Mac::Address mMacDest;
uint16_t mMeshSource;
uint16_t mMeshDest;
bool mAddMeshHeader;
uint32_t mSendMessageFrameCounter;
Message *mSendMessage;
bool mSendMessageIsARetransmission;
uint8_t mSendMessageMaxMacTxAttempts;
uint8_t mSendMessageKeyId;
uint8_t mSendMessageDataSequenceNumber;
uint8_t mStartChildIndex;
bool mSendBusy;
Mac::Address mMacSource;
Mac::Address mMacDest;
uint16_t mMeshSource;
uint16_t mMeshDest;
bool mAddMeshHeader;
Tasklet mScheduleTransmissionTask;
bool mEnabled;
bool mSendBusy;
uint32_t mScanChannels;
uint8_t mScanChannel;
uint8_t mRestoreChannel;
uint16_t mRestorePanId;
bool mScanning;
Tasklet mScheduleTransmissionTask;
bool mEnabled;
DataPollManager mDataPollManager;
uint32_t mScanChannels;
uint8_t mScanChannel;
uint8_t mRestoreChannel;
uint16_t mRestorePanId;
bool mScanning;
DataPollManager mDataPollManager;
SourceMatchController mSourceMatchController;
otIpCounters mIpCounters;
};
/**
+48
View File
@@ -266,6 +266,11 @@ const NcpBase::GetPropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] =
{ SPINEL_PROP_CNTR_RX_SPINEL_TOTAL, &NcpBase::GetPropertyHandler_NCP_CNTR },
{ SPINEL_PROP_CNTR_RX_SPINEL_ERR, &NcpBase::GetPropertyHandler_NCP_CNTR },
{ SPINEL_PROP_CNTR_IP_TX_SUCCESS, &NcpBase::GetPropertyHandler_IP_CNTR },
{ SPINEL_PROP_CNTR_IP_RX_SUCCESS, &NcpBase::GetPropertyHandler_IP_CNTR },
{ SPINEL_PROP_CNTR_IP_TX_FAILURE, &NcpBase::GetPropertyHandler_IP_CNTR },
{ SPINEL_PROP_CNTR_IP_RX_FAILURE, &NcpBase::GetPropertyHandler_IP_CNTR },
{ SPINEL_PROP_MSG_BUFFER_COUNTERS, &NcpBase::GetPropertyHandler_MSG_BUFFER_COUNTERS },
{ SPINEL_PROP_DEBUG_TEST_ASSERT, &NcpBase::GetPropertyHandler_DEBUG_TEST_ASSERT },
{ SPINEL_PROP_DEBUG_NCP_LOG_LEVEL, &NcpBase::GetPropertyHandler_DEBUG_NCP_LOG_LEVEL },
@@ -3793,6 +3798,49 @@ bail:
return errorCode;
}
otError NcpBase::GetPropertyHandler_IP_CNTR(uint8_t header, spinel_prop_key_t key)
{
uint32_t value;
otError errorCode = OT_ERROR_NONE;
const otIpCounters *counters = otThreadGetIp6Counters(mInstance);
switch (key)
{
case SPINEL_PROP_CNTR_IP_TX_SUCCESS:
value = counters->mTxSuccess;
break;
case SPINEL_PROP_CNTR_IP_RX_SUCCESS:
value = counters->mRxSuccess;
break;
case SPINEL_PROP_CNTR_IP_TX_FAILURE:
value = counters->mTxFailure;
break;
case SPINEL_PROP_CNTR_IP_RX_FAILURE:
value = counters->mRxFailure;
break;
default:
errorCode = SendLastStatus(header, SPINEL_STATUS_INTERNAL_ERROR);
goto bail;
break;
}
errorCode = SendPropertyUpdate(
header,
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT32_S,
value
);
bail:
return errorCode;
}
otError NcpBase::GetPropertyHandler_MSG_BUFFER_COUNTERS(uint8_t header, spinel_prop_key_t key)
{
otError errorCode = OT_ERROR_NONE;
+1
View File
@@ -403,6 +403,7 @@ private:
otError GetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(uint8_t header, spinel_prop_key_t key);
otError GetPropertyHandler_MAC_CNTR(uint8_t header, spinel_prop_key_t key);
otError GetPropertyHandler_NCP_CNTR(uint8_t header, spinel_prop_key_t key);
otError GetPropertyHandler_IP_CNTR(uint8_t header, spinel_prop_key_t key);
otError GetPropertyHandler_MSG_BUFFER_COUNTERS(uint8_t header, spinel_prop_key_t key);
#if OPENTHREAD_ENABLE_MAC_WHITELIST
otError GetPropertyHandler_MAC_WHITELIST(uint8_t header, spinel_prop_key_t key);
+16
View File
@@ -1531,6 +1531,22 @@ spinel_prop_key_to_cstr(spinel_prop_key_t prop_key)
ret = "PROP_CNTR_RX_SPINEL_OUT_OF_ORDER_TID";
break;
case SPINEL_PROP_CNTR_IP_TX_SUCCESS:
ret = "PROP_CNTR_IP_TX_SUCCESS";
break;
case SPINEL_PROP_CNTR_IP_RX_SUCCESS:
ret = "PROP_CNTR_IP_RX_SUCCESS";
break;
case SPINEL_PROP_CNTR_IP_TX_FAILURE:
ret = "PROP_CNTR_IP_TX_FAILURE";
break;
case SPINEL_PROP_CNTR_IP_RX_FAILURE:
ret = "PROP_CNTR_IP_RX_FAILURE";
break;
case SPINEL_PROP_MSG_BUFFER_COUNTERS:
ret = "PROP_MSG_BUFFER_COUNTERS";
break;
+16
View File
@@ -1206,6 +1206,22 @@ typedef enum
SPINEL_PROP_CNTR_RX_SPINEL_OUT_OF_ORDER_TID
= SPINEL_PROP_CNTR__BEGIN + 303,
/// The number of successful Tx IP packets
/** Format: `L` (Read-only) */
SPINEL_PROP_CNTR_IP_TX_SUCCESS = SPINEL_PROP_CNTR__BEGIN + 304,
/// The number of successful Rx IP packets
/** Format: `L` (Read-only) */
SPINEL_PROP_CNTR_IP_RX_SUCCESS = SPINEL_PROP_CNTR__BEGIN + 305,
/// The number of failed Tx IP packets
/** Format: `L` (Read-only) */
SPINEL_PROP_CNTR_IP_TX_FAILURE = SPINEL_PROP_CNTR__BEGIN + 306,
/// The number of failed Rx IP packets
/** Format: `L` (Read-only) */
SPINEL_PROP_CNTR_IP_RX_FAILURE = SPINEL_PROP_CNTR__BEGIN + 307,
/// The message buffer counter info
/** Format: `SSSSSSSSSSSSSSSS` (Read-only)
* `S`, (TotalBuffers) The number of buffers in the pool.