public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Daniel Seither <post@tiwoc.de>
To: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n@lists.open-mesh.org>
Subject: [B.A.T.M.A.N.] [PATCH] batctl: Correct mdev calculation in ping subcommand
Date: Thu, 20 May 2010 17:58:00 +0200	[thread overview]
Message-ID: <4BF55C08.7010704@tiwoc.de> (raw)

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>
---
Index: ping.c
===================================================================
--- ping.c	(revision 1659)
+++ ping.c	(working copy)
@@ -76,7 +76,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 +260,7 @@
 			if (time_delta > max)
 				max = time_delta;
 			avg += time_delta;
+			mdev += time_delta * time_delta;
 			packets_in++;
 			break;
 		case DESTINATION_UNREACHABLE:
@@ -289,11 +290,20 @@
 	else
 		packets_loss = ((packets_out - packets_in) * 100) / packets_out;

+	if (packets_in) {
+		avg /= packets_in;
+		mdev /= packets_in;
+		mdev = sqrt(mdev - avg * avg);
+	} 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;


             reply	other threads:[~2010-05-20 15:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-20 15:58 Daniel Seither [this message]
2010-05-20 16:10 ` [B.A.T.M.A.N.] [PATCH] batctl: Correct mdev calculation in ping subcommand Daniel Seither

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BF55C08.7010704@tiwoc.de \
    --to=post@tiwoc.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox