Skip to content

Commit

Permalink
Merge pull request #765 from appneta/Bug_#749_loop_inflates_packet_stats
Browse files Browse the repository at this point in the history
Bug #749 flow stats: avoid overstating flow packet count
  • Loading branch information
fklassen authored Dec 30, 2022
2 parents bd84388 + 611a574 commit 2db5b3c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ test/*1
COPYING
.vscode/
.idea/
build/
build*/
.run/
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- remove invalid assert in tree (#756)
- program exit after send error (#751)
- make libpcap version test more robust (#750)
- looping inflates some packet counters (#749)

08/28/2022 Version 4.4.2
- remove autogen.sh from distribution tarballs (#745)
Expand Down
42 changes: 23 additions & 19 deletions src/tcpreplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ static void flow_stats(const tcpreplay_t *ctx)
COUNTER flows_total = stats->flows;
COUNTER flows_unique = stats->flows_unique;
COUNTER flows_expired = stats->flows_expired;
COUNTER flow_packets;
COUNTER flow_non_flow_packets;
COUNTER flow_packets = stats->flow_packets;
COUNTER flow_non_flow_packets = stats->flow_non_flow_packets;
COUNTER flows_sec = 0;
u_int32_t flows_sec_100ths = 0;

Expand All @@ -239,28 +239,32 @@ static void flow_stats(const tcpreplay_t *ctx)
return;

/*
* When packets are read into cache, flows
* When packets are read into cache, flows
* are only counted in first iteration
* If flows are unique from one loop iteration
* to the next then multiply by the number of
* successful iterations.
*/
if (options->preload_pcap) {
if (ctx->options->unique_ip) {
flows_total *= ctx->last_unique_iteration;
flows_unique *= ctx->last_unique_iteration;
flows_expired *= ctx->last_unique_iteration;
#ifdef TCPREPLAY_EDIT
} else if (tcpedit->seed) {
flows_total *= ctx->iteration;
flows_unique *= ctx->iteration;
flows_expired *= ctx->iteration;
#endif
}
if (options->preload_pcap && ctx->last_unique_iteration) {
flows_total *= ctx->last_unique_iteration;
flows_unique *= ctx->last_unique_iteration;
flows_expired *= ctx->last_unique_iteration;
flow_packets *= ctx->last_unique_iteration;
flow_non_flow_packets *= ctx->last_unique_iteration;
} else {
/* adjust for --unique-ip-loops */
flow_packets = (flow_packets * (ctx->last_unique_iteration ?: ctx->iteration)) /
ctx->iteration;
}

flow_packets = stats->flow_packets * ctx->iteration;
flow_non_flow_packets = stats->flow_non_flow_packets * ctx->iteration;
#ifdef TCPREPLAY_EDIT
if (tcpedit->seed) {
flow_non_flow_packets *= ctx->iteration;
flows_total *= ctx->iteration;
flows_unique *= ctx->iteration;
flows_expired *= ctx->iteration;
}
#endif

if (diff_us) {
COUNTER flows_sec_X100;
Expand All @@ -271,11 +275,11 @@ static void flow_stats(const tcpreplay_t *ctx)
}

if (ctx->options->flow_expiry)
printf("Flows: " COUNTER_SPEC " flows, " COUNTER_SPEC " unique, "COUNTER_SPEC " expired, %llu.%02u fps, " COUNTER_SPEC " flow packets, " COUNTER_SPEC " non-flow\n",
printf("Flows: " COUNTER_SPEC " flows, " COUNTER_SPEC " unique, "COUNTER_SPEC " expired, %llu.%02u fps, " COUNTER_SPEC " unique flow packets, " COUNTER_SPEC " unique non-flow packets\n",
flows_total, flows_unique, flows_expired, flows_sec, flows_sec_100ths, flow_packets,
flow_non_flow_packets);
else
printf("Flows: " COUNTER_SPEC " flows, %llu.%02u fps, " COUNTER_SPEC " flow packets, " COUNTER_SPEC " non-flow\n",
printf("Flows: " COUNTER_SPEC " flows, %llu.%02u fps, " COUNTER_SPEC " unique flow packets, " COUNTER_SPEC " unique non-flow packets\n",
flows_total, flows_sec, flows_sec_100ths, flow_packets,
flow_non_flow_packets);
}
Expand Down

0 comments on commit 2db5b3c

Please sign in to comment.