Author: marek Date: 2010-05-21 06:43:57 +0200 (Fri, 21 May 2010) New Revision: 1664
Modified: branches/batctl-0.2.x/Makefile branches/batctl-0.2.x/ping.c Log: batctl: Correct mdev calculation in ping subcommand
Fixes the calculation of the mean absolute deviation (mdev) of the roundtrip times. mdev was previously calculated by computing the difference of maximum and minimum round trip times.
The calculation is now done using the same formula as in the iputils ping program.
Signed-off-by: Daniel Seither post@tiwoc.de Acked-by: Sven Eckelmann sven.eckelmann@gmx.de
Modified: branches/batctl-0.2.x/Makefile =================================================================== --- branches/batctl-0.2.x/Makefile 2010-05-21 04:17:54 UTC (rev 1663) +++ branches/batctl-0.2.x/Makefile 2010-05-21 04:43:57 UTC (rev 1664) @@ -28,7 +28,7 @@ CC = gcc CFLAGS += -pedantic -Wall -W -g3 -std=gnu99 -Os -fno-strict-aliasing EXTRA_CFLAGS = -DREVISION_VERSION=$(REVISION_VERSION) -LDFLAGS += +LDFLAGS += -lm
SBINDIR = $(INSTALL_PREFIX)/usr/sbin
Modified: branches/batctl-0.2.x/ping.c =================================================================== --- branches/batctl-0.2.x/ping.c 2010-05-21 04:17:54 UTC (rev 1663) +++ branches/batctl-0.2.x/ping.c 2010-05-21 04:43:57 UTC (rev 1664) @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: * * Andreas Langer a.langer@q-dsl.de, Marek Lindner lindner_marek@yahoo.de @@ -29,6 +29,7 @@ #include <signal.h> #include <fcntl.h> #include <string.h> +#include <math.h>
#include "main.h" #include "ping.h" @@ -75,7 +76,7 @@ unsigned int seq_counter = 0, packets_out = 0, packets_in = 0, packets_loss; char *dst_string, *mac_string; double time_delta; - float min = 0.0, max = 0.0, avg = 0.0; + float min = 0.0, max = 0.0, avg = 0.0, mdev = 0.0;
while ((optchar = getopt(argc, argv, "hc:i:t:")) != -1) { switch (optchar) { @@ -213,6 +214,7 @@ if (time_delta > max) max = time_delta; avg += time_delta; + mdev += time_delta * time_delta; packets_in++; break; case DESTINATION_UNREACHABLE: @@ -242,11 +244,24 @@ else packets_loss = ((packets_out - packets_in) * 100) / packets_out;
+ if (packets_in) { + avg /= packets_in; + mdev /= packets_in; + mdev = mdev - avg * avg; + if (mdev > 0.0) + mdev = sqrt(mdev); + else + mdev = 0.0; + } else { + avg = 0.0; + mdev = 0.0; + } + printf("--- %s ping statistics ---\n", dst_string); printf("%u packets transmitted, %u received, %u%% packet loss\n", packets_out, packets_in, packets_loss); printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f/%.3f ms\n", - min, (packets_in ? (avg / packets_in) : 0.000), max, (max - min)); + min, avg, max, mdev);
ret = EXIT_SUCCESS;