Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ typedef struct {
struct timespec end_time;
struct timespec pkt_ts_delta;
struct timespec last_print;
struct timespec first_packet_time;
struct timespec first_packet_wall_time;
COUNTER flow_non_flow_packets;
COUNTER flows;
COUNTER flows_unique;
Expand Down
37 changes: 13 additions & 24 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ void
send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
{
struct timespec now, print_delta, last_pkt_ts;
bool first_packet = true;
tcpreplay_opt_t *options = ctx->options;
tcpreplay_stats_t *stats = &ctx->stats;
COUNTER packetnum = 0;
Expand Down Expand Up @@ -465,23 +466,25 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
skip_length = 0;
ctx->skip_packets = 0;

if (!top_speed) {
now_is_now = true;
get_current_time(&now);
}

if (options->speed.mode == speed_multiplier) {
if (!timesisset(&last_pkt_ts)) {
if (first_packet) {
TIMESPEC_SET(&stats->first_packet_time, &pkthdr_ts);
TIMESPEC_SET(&last_pkt_ts, &pkthdr_ts);
TIMESPEC_SET(&stats->first_packet_wall_time, &now);
first_packet = false;
} else if (timescmp(&pkthdr_ts, &last_pkt_ts, >)) {
struct timespec delta;

timessub(&pkthdr_ts, &last_pkt_ts, &delta);
timeradd_timespec(&stats->pkt_ts_delta, &delta, &stats->pkt_ts_delta);
TIMESPEC_SET(&last_pkt_ts, &pkthdr_ts);
timessub(&pkthdr_ts, &stats->first_packet_time, &stats->pkt_ts_delta);
timessub(&now, &stats->first_packet_wall_time, &stats->time_delta);
timesdiv_float(&stats->pkt_ts_delta, options->speed.multiplier);
}
}

if (!top_speed) {
now_is_now = true;
get_current_time(&now);
}

/*
* Only if the current packet is not late.
*
Expand All @@ -498,15 +501,6 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
TIMESPEC_TO_NANOSEC(&stats->start_time),
&skip_length);

/*
* Track the time of the "last packet sent".
*
* A number of 3rd party tools generate bad timestamps which go backwards
* in time. Hence, don't update the "last" unless pkthdr.ts > last
*/
if (timescmp(&stats->time_delta, &stats->pkt_ts_delta, <))
TIMESPEC_SET(&stats->time_delta, &stats->pkt_ts_delta);

/*
* we know how long to sleep between sends, now do it.
*/
Expand Down Expand Up @@ -807,8 +801,6 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
* A number of 3rd party tools generate bad timestamps which go backwards
* in time. Hence, don't update the "last" unless pkthdr_ptr->ts > last
*/
if (timescmp(&stats->time_delta, &stats->pkt_ts_delta, <))
TIMESPEC_SET(&stats->time_delta, &stats->pkt_ts_delta);

/*
* we know how long to sleep between sends, now do it.
Expand Down Expand Up @@ -1062,9 +1054,6 @@ calc_sleep_time(tcpreplay_t *ctx,
/* pkt_time_delta has increased, so handle normally */
timessub(pkt_ts_delta, time_delta, &nap_for);
TIMESPEC_SET(&ctx->nap, &nap_for);
dbgx(3, "original packet delta time: " TIMESPEC_FORMAT, ctx->nap.tv_sec, ctx->nap.tv_nsec);
timesdiv_float(&ctx->nap, options->speed.multiplier);
dbgx(3, "original packet delta/div: " TIMESPEC_FORMAT, ctx->nap.tv_sec, ctx->nap.tv_nsec);
}
break;

Expand Down