mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
shell: sc_icmpv6_echo: provide delay option
This commit is contained in:
parent
d15f0990b3
commit
be9d8ca64b
@ -38,7 +38,11 @@ static char ipv6_str[NG_IPV6_ADDR_MAX_STR_LEN];
|
||||
|
||||
static void usage(char **argv)
|
||||
{
|
||||
printf("%s [<n>] <ipv6 addr> [<payload_len>]\n", argv[0]);
|
||||
printf("%s [<n>] <ipv6 addr> [<payload_len>] [<delay in ms>]\n", argv[0]);
|
||||
puts("defaults:");
|
||||
puts(" n = 3");
|
||||
puts(" payload_len = 4");
|
||||
puts(" delay = 1000");
|
||||
}
|
||||
|
||||
void _set_payload(ng_icmpv6_echo_t *hdr, size_t payload_len)
|
||||
@ -118,6 +122,7 @@ int _icmpv6_ping(int argc, char **argv)
|
||||
{
|
||||
int n = 3, success = 0, count;
|
||||
size_t payload_len = 4;
|
||||
timex_t delay = { 1, 0 };
|
||||
char *addr_str;
|
||||
ng_ipv6_addr_t addr;
|
||||
ng_netreg_entry_t *ipv6_entry, my_entry = { NULL, NG_ICMPV6_ECHO_REP,
|
||||
@ -125,8 +130,10 @@ int _icmpv6_ping(int argc, char **argv)
|
||||
};
|
||||
timex_t min_rtt = { UINT32_MAX, UINT32_MAX }, max_rtt = { 0, 0 };
|
||||
timex_t sum_rtt = { 0, 0 };
|
||||
timex_t start, stop;
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
case 1:
|
||||
usage(argv);
|
||||
return 1;
|
||||
@ -137,14 +144,41 @@ int _icmpv6_ping(int argc, char **argv)
|
||||
|
||||
case 3:
|
||||
n = atoi(argv[1]);
|
||||
addr_str = argv[2];
|
||||
if (n > 0) {
|
||||
addr_str = argv[2];
|
||||
}
|
||||
else {
|
||||
n = 3;
|
||||
addr_str = argv[1];
|
||||
payload_len = atoi(argv[2]);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
n = atoi(argv[1]);
|
||||
if (n > 0) {
|
||||
addr_str = argv[2];
|
||||
payload_len = atoi(argv[3]);
|
||||
}
|
||||
else {
|
||||
n = 3;
|
||||
addr_str = argv[1];
|
||||
payload_len = atoi(argv[2]);
|
||||
delay.seconds = 0;
|
||||
delay.microseconds = atoi(argv[3]) * 1000;
|
||||
timex_normalize(&delay);
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
default:
|
||||
n = atoi(argv[1]);
|
||||
addr_str = argv[2];
|
||||
payload_len = atoi(argv[3]);
|
||||
delay.seconds = 0;
|
||||
delay.microseconds = atoi(argv[4]) * 1000;
|
||||
timex_normalize(&delay);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -167,6 +201,8 @@ int _icmpv6_ping(int argc, char **argv)
|
||||
|
||||
count = n;
|
||||
|
||||
vtimer_now(&start);
|
||||
|
||||
while ((count--) > 0) {
|
||||
msg_t msg;
|
||||
ng_pktsnip_t *pkt;
|
||||
@ -224,10 +260,17 @@ int _icmpv6_ping(int argc, char **argv)
|
||||
else {
|
||||
puts("ping timeout");
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
vtimer_sleep(delay);
|
||||
}
|
||||
}
|
||||
|
||||
vtimer_now(&stop);
|
||||
|
||||
max_seq_expected = 0;
|
||||
id++;
|
||||
stop = timex_sub(stop, start);
|
||||
|
||||
ng_netreg_unregister(NG_NETTYPE_ICMPV6, &my_entry);
|
||||
|
||||
@ -237,8 +280,7 @@ int _icmpv6_ping(int argc, char **argv)
|
||||
timex_normalize(&sum_rtt);
|
||||
printf("%d packets transmitted, %d received, %d%% packet loss, time %"
|
||||
PRIu32 ".06%" PRIu32 " s\n", n, success,
|
||||
(100 - ((success * 100) / n)),
|
||||
sum_rtt.seconds, sum_rtt.microseconds);
|
||||
(100 - ((success * 100) / n)), stop.seconds, stop.microseconds);
|
||||
timex_t avg_rtt = timex_from_uint64(timex_uint64(sum_rtt) / n); /* get average */
|
||||
printf("rtt min/avg/max = "
|
||||
"%" PRIu32 ".%03" PRIu32 "/"
|
||||
|
Loading…
Reference in New Issue
Block a user