summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2012-07-06 15:36:39 +0000
committeremaste <emaste@FreeBSD.org>2012-07-06 15:36:39 +0000
commit5d3526c6d6e7abcfdad055b9663b6e242ed32f08 (patch)
treed96a6a8191b3edb6d919c6b2160730018e6b8bf0
parent700f0808eb9f3440636f5f9fe412321893a1c342 (diff)
downloadFreeBSD-src-5d3526c6d6e7abcfdad055b9663b6e242ed32f08.zip
FreeBSD-src-5d3526c6d6e7abcfdad055b9663b6e242ed32f08.tar.gz
Also report tx bandwidth with Ethernet overhead
-rw-r--r--tools/tools/netmap/pkt-gen.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/tools/tools/netmap/pkt-gen.c b/tools/tools/netmap/pkt-gen.c
index 8d2fe7d..7540cb8 100644
--- a/tools/tools/netmap/pkt-gen.c
+++ b/tools/tools/netmap/pkt-gen.c
@@ -653,27 +653,41 @@ quit:
return (NULL);
}
+static char *
+scaled_val(double val)
+{
+ static char buf[64];
+ const char *units[] = {"", "K", "M", "G"};
+ int i = 0;
+
+ while (val >= 1000 && i < 3) {
+ val /= 1000;
+ i++;
+ }
+ snprintf(buf, sizeof(buf), "%.2f%s", val, units[i]);
+ return (buf);
+}
+
static void
tx_output(uint64_t sent, int size, double delta)
{
- double amount = 8.0 * (1.0 * size * sent) / delta;
+ uint64_t bytes_sent = sent * size;
+ double bw = 8.0 * bytes_sent / delta;
double pps = sent / delta;
- char units[4] = { '\0', 'K', 'M', 'G' };
- int aunit = 0, punit = 0;
-
- while (amount >= 1000) {
- amount /= 1000;
- aunit += 1;
- }
- while (pps >= 1000) {
- pps /= 1000;
- punit += 1;
- }
+ /*
+ * Assume Ethernet overhead of 24 bytes per packet excluding header:
+ * FCS 4 bytes
+ * Preamble 8 bytes
+ * IFG 12 bytes
+ */
+ double bw_with_overhead = 8.0 * (bytes_sent + sent * 24) / delta;
printf("Sent %" PRIu64 " packets, %d bytes each, in %.2f seconds.\n",
sent, size, delta);
- printf("Speed: %.2f%cpps. Bandwidth: %.2f%cbps.\n",
- pps, units[punit], amount, units[aunit]);
+ printf("Speed: %spps. ", scaled_val(pps));
+ printf("Bandwidth: %sbps ", scaled_val(bw));
+ printf("(%sbps with overhead).\n", scaled_val(bw_with_overhead));
+
}
OpenPOWER on IntegriCloud