From f86ceb43ce89c5d045d73c27ea70ec5c46144977 Mon Sep 17 00:00:00 2001 From: arun-mahasenan <72365266+arun-mahasenan@users.noreply.github.com> Date: Mon, 12 Jul 2021 12:54:39 -0700 Subject: [PATCH] [cli] IPv6 counters (#6771) Add CLI command for IPv6 packet success and failures during transmission and reception. --- src/cli/README.md | 9 +++++++ src/cli/cli.cpp | 34 +++++++++++++++++++++++++++ tests/scripts/expect/cli-counters.exp | 7 ++++++ 3 files changed, 50 insertions(+) diff --git a/src/cli/README.md b/src/cli/README.md index 5946317f3..526417c5f 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -770,6 +770,7 @@ Get the supported counter names. ```bash > counters +ip mac mle Done @@ -824,6 +825,12 @@ Partition Id Changes: 1 Better Partition Attach Attempts: 0 Parent Changes: 0 Done +> counters ip +TxSuccess: 10 +TxFailed: 0 +RxSuccess: 5 +RxFailed: 0 +Done ``` ### counters \ reset @@ -835,6 +842,8 @@ Reset the counter value. Done > counters mle reset Done +> counters ip reset +Done ``` ### csl diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 0ee7eb60c..002def7af 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1117,6 +1117,7 @@ otError Interpreter::ProcessCounters(Arg aArgs[]) if (aArgs[0].IsEmpty()) { + OutputLine("ip"); OutputLine("mac"); OutputLine("mle"); } @@ -1228,6 +1229,39 @@ otError Interpreter::ProcessCounters(Arg aArgs[]) ExitNow(error = OT_ERROR_INVALID_ARGS); } } + else if (aArgs[0] == "ip") + { + if (aArgs[1].IsEmpty()) + { + struct IpCounterName + { + const uint32_t otIpCounters::*mValuePtr; + const char * mName; + }; + + static const IpCounterName kCounterNames[] = { + {&otIpCounters::mTxSuccess, "TxSuccess"}, + {&otIpCounters::mTxFailure, "TxFailed"}, + {&otIpCounters::mRxSuccess, "RxSuccess"}, + {&otIpCounters::mRxFailure, "RxFailed"}, + }; + + const otIpCounters *ipCounters = otThreadGetIp6Counters(mInstance); + + for (const IpCounterName &counter : kCounterNames) + { + OutputLine("%s: %d", counter.mName, ipCounters->*counter.mValuePtr); + } + } + else if ((aArgs[1] == "reset") && aArgs[2].IsEmpty()) + { + otThreadResetIp6Counters(mInstance); + } + else + { + ExitNow(error = OT_ERROR_INVALID_ARGS); + } + } else { ExitNow(error = OT_ERROR_INVALID_ARGS); diff --git a/tests/scripts/expect/cli-counters.exp b/tests/scripts/expect/cli-counters.exp index 359d3b45f..6c6f33e65 100755 --- a/tests/scripts/expect/cli-counters.exp +++ b/tests/scripts/expect/cli-counters.exp @@ -34,19 +34,26 @@ spawn_node 1 send "counters\n" expect "mac" expect "mle" +expect "ip" expect_line "Done" send "counters mac\n" expect_line "Done" send "counters mle\n" expect_line "Done" +send "counters ip\n" +expect_line "Done" send "counters mac reset\n" expect_line "Done" send "counters mle reset\n" expect_line "Done" +send "counters ip reset\n" +expect_line "Done" send "counters mac 1\n" expect "Error 7: InvalidArgs" send "counters mle 1\n" expect "Error 7: InvalidArgs" +send "counters ip 1\n" +expect "Error 7: InvalidArgs" send "counters other\n" expect "Error 7: InvalidArgs"