Skip to content

Commit

Permalink
[SQUASH ME] shell: add more statistics to ping6
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 19, 2015
1 parent 1e761b9 commit 43e113f
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions sys/shell/commands/sc_icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void _set_payload(ng_icmpv6_echo_t *hdr, size_t payload_len)
}
}

void _handle_reply(ng_pktsnip_t *pkt, uint64_t time)
int _handle_reply(ng_pktsnip_t *pkt, uint64_t time)
{
ng_pktsnip_t *ipv6, *icmpv6;
ng_ipv6_hdr_t *ipv6_hdr;
Expand All @@ -73,28 +73,37 @@ void _handle_reply(ng_pktsnip_t *pkt, uint64_t time)

if ((ipv6 == NULL) || (icmpv6 == NULL)) {
puts("error: IPv6 header or ICMPv6 header not found in reply");
return;
return 0;
}

ipv6_hdr = ipv6->data;
icmpv6_hdr = icmpv6->data;

printf("%zu bytes from %s: id=%" PRIu16 " seq=%" PRIu16 " hop limit=%" PRIu8
"time = %" PRIu64 ".%03" PRIu64 " ms\n", icmpv6->size,
ng_ipv6_addr_to_str(ipv6_str, &(ipv6_hdr->src), sizeof(ipv6_str)),
byteorder_ntohs(icmpv6_hdr->id), byteorder_ntohs(icmpv6_hdr->seq),
ipv6_hdr->hl, time / MS_IN_USEC, time % MS_IN_USEC);
if ((icmpv6_hdr->id == id) && (icmpv6_hdr->seq == seq)) {
printf("%zu bytes from %s: id=%" PRIu16 " seq=%" PRIu16 " hop limit=%" PRIu8
"time = %" PRIu64 ".%03" PRIu64 " ms\n", icmpv6->size,
ng_ipv6_addr_to_str(ipv6_str, &(ipv6_hdr->src), sizeof(ipv6_str)),
byteorder_ntohs(icmpv6_hdr->id), byteorder_ntohs(icmpv6_hdr->seq),
ipv6_hdr->hl, time / MS_IN_USEC, time % MS_IN_USEC);
}
else {
puts("error: unexpected parameters");
return 0;
}

return 1;
}

void _icmpv6_ping(int argc, char **argv)
{
int n = 3;
int n = 3, success = 0;
size_t payload_len = 4;
char *addr_str;
ng_ipv6_addr_t addr;
ng_netreg_entry_t *ipv6_entry, my_entry = { NULL, NG_ICMPV6_ECHO_REP,
thread_getpid()
};
uint64_t min_rtt = UINT64_MAX, max_rtt = 0, sum_rtt = 0;

switch (argc) {
case 1:
Expand Down Expand Up @@ -164,16 +173,29 @@ void _icmpv6_ping(int argc, char **argv)
case NG_NETAPI_MSG_TYPE_RCV:
vtimer_now(&stop);
stop = timex_sub(stop, start);
_handle_reply((ng_pktsnip_t *)msg.content.ptr, timex_uint64(stop));
success += _handle_reply((ng_pktsnip_t *)msg.content.ptr,
timex_uint64(stop));

if (stop > max_rtt) {
max_rtt = stop;
}

if (stop < min_rtt) {
min_rtt = stop
}

sum_rtt += stop;

break;

default:
/* requeue wrong packets */
msg_send(&msg, thread_getpid());
break;
}
}
else {
puts("Timeout");
puts("ping timeout");
}

seq++;
Expand All @@ -184,7 +206,17 @@ void _icmpv6_ping(int argc, char **argv)

ng_netreg_unregister(NG_NETTYPE_ICMPV6, &my_entry);

return;
printf("--- %s ping statistics ---\n", addr_str);
printf("%d packets transmitted, %d received, %d%% packet loss, time %"
PRIu64 " ms\n", n, success, (success - n) / n, sum_rtt / MS_IN_USEC);
sum_rtt = sum_rtt / n; /* get average */
printf("rtt min/avg/max = "
"%" PRIu64 ".%03" PRIu64 "/"
"%" PRIu64 ".%03" PRIu64 "/"
"%" PRIu64 ".%03" PRIu64 " ms\n",
min_rtt / MS_IN_USEC, min_rtt % MS_IN_USEC,
sum_rtt / MS_IN_USEC, sum_rtt % MS_IN_USEC, /* sum is now avg, see above */
max_rtt / MS_IN_USEC, max_rtt % MS_IN_USEC);
}

#endif
Expand Down

0 comments on commit 43e113f

Please sign in to comment.