From eb2c2dfb26003604ed503c34d8dc72f40c6abeda Mon Sep 17 00:00:00 2001 From: Rongli Sun Date: Fri, 6 Dec 2019 16:13:55 +0800 Subject: [PATCH] [cli] extend `ping` to allow hoplimit configuration (#4370) --- src/cli/README.md | 7 +++++-- src/cli/cli.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cli/README.md b/src/cli/README.md index bf10006d6..98b54a463 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -53,7 +53,7 @@ OpenThread test scripts use the CLI to execute test cases. * [panid](#panid) * [parent](#parent) * [parentpriority](#parentpriority) -* [ping](#ping-ipaddr-size-count-interval) +* [ping](#ping-ipaddr-size-count-interval-hoplimit) * [pollperiod](#pollperiod-pollperiod) * [prefix](#prefix-add-prefix-pvdcsr-prf) * [promiscuous](#promiscuous) @@ -937,17 +937,20 @@ Set the assigned parent priority value: 1, 0, -1 or -2. Done ``` -### ping \ [size] [count] [interval] +### ping \ [size] [count] [interval] [hoplimit] Send an ICMPv6 Echo Request. * size: The number of data bytes to be sent. * count: The number of ICMPv6 Echo Requests to be sent. * interval: The interval between two consecutive ICMPv6 Echo Requests in seconds. The value may have fractional form, for example `0.5`. +* hoplimit: The hoplimit of ICMPv6 Echo Request to be sent. ```bash > ping fdde:ad00:beef:0:558:f56b:d688:799 16 bytes from fdde:ad00:beef:0:558:f56b:d688:799: icmp_seq=1 hlim=64 time=28ms + +> ping ff05::1 100 1 1 1 ``` ### ping stop diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index c50cdfe2e..183dbc05e 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2033,6 +2033,7 @@ void Interpreter::ProcessPing(int argc, char *argv[]) VerifyOrExit(!mPingTimer.IsRunning(), error = OT_ERROR_BUSY); + mMessageInfo = Ip6::MessageInfo(); SuccessOrExit(error = mMessageInfo.GetPeerAddr().FromString(argv[0])); mLength = 8; @@ -2059,6 +2060,16 @@ void Interpreter::ProcessPing(int argc, char *argv[]) mInterval = interval; break; + case 4: + SuccessOrExit(error = ParseLong(argv[index], value)); + VerifyOrExit(0 <= value && value <= 255, error = OT_ERROR_INVALID_ARGS); + mMessageInfo.mHopLimit = static_cast(value); + if (value == 0) + { + mMessageInfo.mAllowZeroHopLimit = true; + } + break; + default: ExitNow(error = OT_ERROR_INVALID_ARGS); }