Skip to content

Commit

Permalink
appneta#239 add timestamp messages when using --stats (appneta#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen authored Feb 27, 2017
1 parent b6196bc commit 2298ae1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
- tcpcapinfo buffer overflow vulnerablily (#278)
- Update git-clone instructions by Kyle McDonald (#277)
- Allow fractions for --pps option (#270)
- Print per-loop stats with --stats=0 (#269)
- Add protection against packet drift by Guillaume Scott (#268)
- Include Travis-CI build support by Ilya Shipitsin (#264) (#285)
- First and last packet times in --stats output (#239)

11/19/2016 Version 4.1.2
- Fix compilation with musl C library (#260)
Expand Down
23 changes: 23 additions & 0 deletions src/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ packet_stats(const tcpreplay_stats_t *stats)
stats->failed);
}

/**
* fills a buffer with a string representing the given time
*
* @param when: the time that should be formatted
* @param buf: a buffer to write to
* @param len: length of the buffer
* @return: string containing date, or -1 on error
*/
int format_date_time(struct timeval *when, char *buf, size_t len)
{
struct tm *tm;
char tmp[64];

assert(len);

tm = localtime(&when->tv_sec);
if (!tm)
return -1;

strftime(tmp, sizeof tmp, "%Y-%m-%d %H:%M:%S.%%06u", tm);
return snprintf(buf, len, tmp, when->tv_usec);
}

/**
* reads a hexstring in the format of xx,xx,xx,xx spits it back into *hex
* up to hexlen bytes. Returns actual number of bytes returned. On error
Expand Down
1 change: 1 addition & 0 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ typedef struct {

int read_hexstring(const char *l2string, u_char *hex, const int hexlen);
void packet_stats(const tcpreplay_stats_t *stats);
int format_date_time(struct timeval *when, char *buf, size_t len);

/* our "safe" implimentations of functions which allocate memory */
#define safe_malloc(x) _our_safe_malloc(x, __FUNCTION__, __LINE__, __FILE__)
Expand Down
18 changes: 14 additions & 4 deletions src/tcpreplay_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ int
tcpreplay_replay(tcpreplay_t *ctx)
{
int rcode, loop, total_loops;
char buf[64];

assert(ctx);

Expand All @@ -1175,6 +1176,11 @@ tcpreplay_replay(tcpreplay_t *ctx)
return -1;
}

if (ctx->options->stats >= 0) {
if (format_date_time(&ctx->stats.start_time, buf, sizeof(buf)) > 0)
printf("Test start: %s ...\n", buf);
}

ctx->running = true;
total_loops = ctx->options->loop;
loop = 0;
Expand Down Expand Up @@ -1212,14 +1218,18 @@ tcpreplay_replay(tcpreplay_t *ctx)

#ifdef HAVE_QUICK_TX
/* flush any remaining netmap packets */
if (ctx->options->quick_tx)
if (ctx->options->quick_tx) {
quick_tx_wait_for_tx_complete(ctx->intf1->qtx_dev);
if (ctx->stats.bytes_sent >= 0)
gettimeofday(&ctx->stats.end_time, NULL);
}
#endif

if (ctx->stats.bytes_sent > 0) {
if (gettimeofday(&ctx->stats.end_time, NULL) < 0)
errx(-1, "gettimeofday() failed: %s", strerror(errno));
if (ctx->options->stats >= 0) {
if (format_date_time(&ctx->stats.end_time, buf, sizeof(buf)) > 0)
printf("Test complete: %s\n", buf);
}

return 0;
}

Expand Down

0 comments on commit 2298ae1

Please sign in to comment.