From patchwork Fri May 21 07:48:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Seither X-Patchwork-Id: 119 Return-Path: Received: from devzero.de (devzero.de [85.214.76.202]) by open-mesh.net (Postfix) with ESMTP id 208861541FF for ; Fri, 21 May 2010 04:24:48 +0200 (CEST) Received: from [130.83.73.250] (x504.vpn.hrz.tu-darmstadt.de [130.83.73.250]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by devzero.de (Postfix) with ESMTPSA id 6E968954007 for ; Fri, 21 May 2010 07:48:34 +0000 (UTC) Message-ID: <4BF63AD1.2030105@tiwoc.de> Date: Fri, 21 May 2010 09:48:33 +0200 From: Daniel Seither User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: The list for a Better Approach To Mobile Ad-hoc Networking X-Enigmail-Version: 1.0.1 Subject: [B.A.T.M.A.N.] [PATCHv3] batctl: Correct mdev calculation in ping subcommand X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 May 2010 02:24:48 -0000 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 Acked-by: Sven Eckelmann Index: Makefile =================================================================== --- Makefile (revision 1659) +++ Makefile (working copy) @@ -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 Index: ping.c =================================================================== --- ping.c (revision 1659) +++ ping.c (working copy) @@ -29,6 +29,7 @@ #include #include #include +#include #include "main.h" #include "ping.h" @@ -76,7 +77,7 @@ unsigned int seq_counter = 0, packets_out = 0, packets_in = 0, packets_loss; char *dst_string, *mac_string, *rr_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; uint8_t last_rr_cur = 0, last_rr[BAT_RR_LEN][ETH_ALEN]; size_t packet_len; @@ -260,6 +261,7 @@ if (time_delta > max) max = time_delta; avg += time_delta; + mdev += time_delta * time_delta; packets_in++; break; case DESTINATION_UNREACHABLE: @@ -289,11 +291,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;