Skip to contentSkip to conversation

batctl: Correct mdev calculation in ping subcommand

PATCH Superseded Daniel Seither 1 participant 2 messages May 20, 2010

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---

ping.c +12 -2
Index: ping.c
===================================================================
@@ -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;
 
#1 lore raw

Sorry, I sent the wrong version of the patch. I'll send a fixed patch in a minute...

- Daniel

Am 20.05.2010 17:58, schrieb Daniel Seither:

Quoted 9 lines

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.

---