From e40947eb6fd3bce378290444fcaff4702f69e182 Mon Sep 17 00:00:00 2001 From: Adam Eliot Date: Tue, 22 Nov 2016 08:41:27 -0800 Subject: [PATCH] Add separate counters for unicast and broadcast (#994) * Added tx counts for unicast vs broadcast packets * Added counters for Rx broadcast vs unicast packets --- include/openthread-types.h | 4 +++ src/cli/README.md | 14 ++++++---- src/cli/cli.cpp | 4 +++ src/core/mac/mac.cpp | 52 +++++++++++++++++++++++++++++++++++--- src/core/mac/mac.hpp | 2 +- src/ncp/ncp_base.cpp | 21 +++++++++++++++ src/ncp/spinel.h | 18 +++++++++++++ 7 files changed, 105 insertions(+), 10 deletions(-) diff --git a/include/openthread-types.h b/include/openthread-types.h index 49c27c840..5476aa125 100644 --- a/include/openthread-types.h +++ b/include/openthread-types.h @@ -832,6 +832,8 @@ typedef struct otLeaderData typedef struct otMacCounters { uint32_t mTxTotal; ///< The total number of transmissions. + uint32_t mTxUnicast; ///< The total number of unicast transmissions. + uint32_t mTxBroadcast; ///< The total number of broadcast transmissions. uint32_t mTxAckRequested; ///< The number of transmissions with ack request. uint32_t mTxAcked; ///< The number of transmissions that were acked. uint32_t mTxNoAckRequested; ///< The number of transmissions without ack request. @@ -843,6 +845,8 @@ typedef struct otMacCounters uint32_t mTxRetry; ///< The number of retransmission times. uint32_t mTxErrCca; ///< The number of CCA failure times. uint32_t mRxTotal; ///< The total number of received packets. + uint32_t mRxUnicast; ///< The total number of unicast packets received. + uint32_t mRxBroadcast; ///< The total number of broadcast packets received. uint32_t mRxData; ///< The number of received data. uint32_t mRxDataPoll; ///< The number of received data poll. uint32_t mRxBeacon; ///< The number of received beacon. diff --git a/src/cli/README.md b/src/cli/README.md index 085dc4caa..df61d5db0 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -353,9 +353,11 @@ Get the counter value. ```bash >counter mac TxTotal: 10 - TxAckRequested: 4 - TxAcked: 4 - TxNoAckRequested: 6 + TxUnicast: 3 + TxBroadcast: 7 + TxAckRequested: 3 + TxAcked: 3 + TxNoAckRequested: 7 TxData: 10 TxDataPoll: 0 TxBeacon: 0 @@ -363,8 +365,10 @@ TxTotal: 10 TxOther: 0 TxRetry: 0 TxErrCca: 0 -RxTotal: 11 - RxData: 11 +RxTotal: 2 + RxUnicast: 1 + RxBroadcast: 1 + RxData: 2 RxDataPoll: 0 RxBeacon: 0 RxBeaconRequest: 0 diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index efbba8ec3..1df6d57d2 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -517,6 +517,8 @@ void Interpreter::ProcessCounters(int argc, char *argv[]) { const otMacCounters *counters = otGetMacCounters(mInstance); sServer->OutputFormat("TxTotal: %d\r\n", counters->mTxTotal); + sServer->OutputFormat(" TxUnicast: %d\r\n", counters->mTxUnicast); + sServer->OutputFormat(" TxBroadcast: %d\r\n", counters->mTxBroadcast); sServer->OutputFormat(" TxAckRequested: %d\r\n", counters->mTxAckRequested); sServer->OutputFormat(" TxAcked: %d\r\n", counters->mTxAcked); sServer->OutputFormat(" TxNoAckRequested: %d\r\n", counters->mTxNoAckRequested); @@ -528,6 +530,8 @@ void Interpreter::ProcessCounters(int argc, char *argv[]) sServer->OutputFormat(" TxRetry: %d\r\n", counters->mTxRetry); sServer->OutputFormat(" TxErrCca: %d\r\n", counters->mTxErrCca); sServer->OutputFormat("RxTotal: %d\r\n", counters->mRxTotal); + sServer->OutputFormat(" RxUnicast: %d\r\n", counters->mRxUnicast); + sServer->OutputFormat(" RxBroadcast: %d\r\n", counters->mRxBroadcast); sServer->OutputFormat(" RxData: %d\r\n", counters->mRxData); sServer->OutputFormat(" RxDataPoll: %d\r\n", counters->mRxDataPoll); sServer->OutputFormat(" RxBeacon: %d\r\n", counters->mRxBeacon); diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 89cad3d7a..9ff50c94e 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -782,7 +782,7 @@ exit: if (error != kThreadError_None) { - TransmitDoneTask(false, kThreadError_Abort); + TransmitDoneTask(mTxFrame, false, kThreadError_Abort); } } @@ -790,17 +790,33 @@ extern "C" void otPlatRadioTransmitDone(otInstance *aInstance, RadioPacket *aPac ThreadError aError) { otLogFuncEntryMsg("%!otError!, aRxPending=%u", aError, aRxPending ? 1 : 0); - (void)aPacket; - aInstance->mThreadNetif.GetMac().TransmitDoneTask(aRxPending, aError); + + aInstance->mThreadNetif.GetMac().TransmitDoneTask(aPacket, aRxPending, aError); otLogFuncExit(); } -void Mac::TransmitDoneTask(bool aRxPending, ThreadError aError) +void Mac::TransmitDoneTask(RadioPacket *aPacket, bool aRxPending, ThreadError aError) { mMacTimer.Stop(); mCounters.mTxTotal++; + Frame *packet = static_cast(aPacket); + Address addr; + packet->GetDstAddr(addr); + + if (addr.mShortAddress == kShortAddrBroadcast) + { + // Broadcast packet + mCounters.mTxBroadcast++; + } + else + { + // Unicast packet + mCounters.mTxUnicast++; + } + + if (!RadioSupportsRetriesAndCsmaBackoff() && aError == kThreadError_ChannelAccessFailure && mCsmaAttempts < kMaxCSMABackoffs) @@ -846,6 +862,8 @@ void Mac::HandleMacTimer(void *aContext) void Mac::HandleMacTimer(void) { + Address addr; + switch (mState) { case kStateActiveScan: @@ -876,6 +894,20 @@ void Mac::HandleMacTimer(void) otLogDebgMac("ack timer fired"); otPlatRadioReceive(mNetif.GetInstance(), mChannel); mCounters.mTxTotal++; + + mTxFrame->GetDstAddr(addr); + + if (addr.mShortAddress == kShortAddrBroadcast) + { + // Broadcast packet + mCounters.mTxBroadcast++; + } + else + { + // Unicast Packet + mCounters.mTxUnicast++; + } + SentFrame(kThreadError_NoAck); break; @@ -1239,6 +1271,18 @@ void Mac::ReceiveDoneTask(Frame *aFrame, ThreadError aError) break; } + // Increment coutners + if (dstaddr.mShortAddress == kShortAddrBroadcast) + { + // Broadcast packet + mCounters.mRxBroadcast++; + } + else + { + // Unicast packet + mCounters.mRxUnicast++; + } + // Security Processing SuccessOrExit(error = ProcessReceiveSecurity(*aFrame, srcaddr, neighbor)); diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 389b6a6ff..feeb9f85d 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -449,7 +449,7 @@ public: * was aborted for other reasons. * */ - void TransmitDoneTask(bool aRxPending, ThreadError aError); + void TransmitDoneTask(RadioPacket *aPacket, bool aRxPending, ThreadError aError); /** * This method returns if an active scan is in progress. diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 91904c97a..38c799103 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -181,6 +181,8 @@ const NcpBase::GetPropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = { SPINEL_PROP_CNTR_TX_PKT_BEACON_REQ, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_TX_PKT_OTHER, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_TX_PKT_RETRY, &NcpBase::GetPropertyHandler_MAC_CNTR }, + { SPINEL_PROP_CNTR_TX_PKT_UNICAST, &NcpBase::GetPropertyHandler_NCP_CNTR }, + { SPINEL_PROP_CNTR_TX_PKT_BROADCAST, &NcpBase::GetPropertyHandler_NCP_CNTR }, { SPINEL_PROP_CNTR_TX_ERR_CCA, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_RX_PKT_TOTAL, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_RX_PKT_DATA, &NcpBase::GetPropertyHandler_MAC_CNTR }, @@ -190,6 +192,8 @@ const NcpBase::GetPropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = { SPINEL_PROP_CNTR_RX_PKT_OTHER, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_RX_PKT_FILT_WL, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_RX_PKT_FILT_DA, &NcpBase::GetPropertyHandler_MAC_CNTR }, + { SPINEL_PROP_CNTR_RX_PKT_UNICAST, &NcpBase::GetPropertyHandler_NCP_CNTR }, + { SPINEL_PROP_CNTR_RX_PKT_BROADCAST, &NcpBase::GetPropertyHandler_NCP_CNTR }, { SPINEL_PROP_CNTR_RX_ERR_EMPTY, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_RX_ERR_UKWN_NBR, &NcpBase::GetPropertyHandler_MAC_CNTR }, { SPINEL_PROP_CNTR_RX_ERR_NVLD_SADDR, &NcpBase::GetPropertyHandler_MAC_CNTR }, @@ -2535,6 +2539,14 @@ ThreadError NcpBase::GetPropertyHandler_MAC_CNTR(uint8_t header, spinel_prop_key value = macCounters->mTxErrCca; break; + case SPINEL_PROP_CNTR_TX_PKT_UNICAST: + value = macCounters->mTxUnicast; + break; + + case SPINEL_PROP_CNTR_TX_PKT_BROADCAST: + value = macCounters->mTxBroadcast; + break; + case SPINEL_PROP_CNTR_RX_PKT_TOTAL: value = macCounters->mRxTotal; break; @@ -2571,6 +2583,14 @@ ThreadError NcpBase::GetPropertyHandler_MAC_CNTR(uint8_t header, spinel_prop_key value = macCounters->mRxDuplicated; break; + case SPINEL_PROP_CNTR_RX_PKT_UNICAST: + value = macCounters->mRxUnicast; + break; + + case SPINEL_PROP_CNTR_RX_PKT_BROADCAST: + value = macCounters->mRxBroadcast; + break; + case SPINEL_PROP_CNTR_RX_ERR_EMPTY: value = macCounters->mRxErrNoFrame; break; @@ -2595,6 +2615,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_CNTR(uint8_t header, spinel_prop_key value = macCounters->mRxErrOther; break; + default: errorCode = SendLastStatus(header, SPINEL_STATUS_INTERNAL_ERROR); goto bail; diff --git a/src/ncp/spinel.h b/src/ncp/spinel.h index 9657f8f36..b3eb1cb9b 100644 --- a/src/ncp/spinel.h +++ b/src/ncp/spinel.h @@ -734,6 +734,14 @@ typedef enum /** Format: `L` (Read-only) */ SPINEL_PROP_CNTR_TX_ERR_CCA = SPINEL_PROP_CNTR__BEGIN + 11, + /// The number of unicast packets transmitted. + /** Format: `L` (Read-only) */ + SPINEL_PROP_CNTR_TX_PKT_UNICAST = SPINEL_PROP_CNTR__BEGIN + 12, + + /// The number of broadcast packets transmitted. + /** Format: `L` (Read-only) */ + SPINEL_PROP_CNTR_TX_PKT_BROADCAST = SPINEL_PROP_CNTR__BEGIN + 13, + /// The total number of received packets. /** Format: `L` (Read-only) */ SPINEL_PROP_CNTR_RX_PKT_TOTAL = SPINEL_PROP_CNTR__BEGIN + 100, @@ -794,6 +802,14 @@ typedef enum /** Format: `L` (Read-only) */ SPINEL_PROP_CNTR_RX_PKT_DUP = SPINEL_PROP_CNTR__BEGIN + 114, + /// The number of unicast packets recived. + /** Format: `L` (Read-only) */ + SPINEL_PROP_CNTR_RX_PKT_UNICAST = SPINEL_PROP_CNTR__BEGIN + 115, + + /// The number of broadcast packets recived. + /** Format: `L` (Read-only) */ + SPINEL_PROP_CNTR_RX_PKT_BROADCAST = SPINEL_PROP_CNTR__BEGIN + 116, + /// The total number of secure transmitted IP messages. /** Format: `L` (Read-only) */ SPINEL_PROP_CNTR_TX_IP_SEC_TOTAL = SPINEL_PROP_CNTR__BEGIN + 200, @@ -830,6 +846,8 @@ typedef enum /** Format: `L` (Read-only) */ SPINEL_PROP_CNTR_RX_SPINEL_ERR = SPINEL_PROP_CNTR__BEGIN + 302, + + /// The message buffer counter info /** Format: `T(SSSSSSSSSSSSSSSS)` (Read-only) * `T(`