Skip to content

Commit

Permalink
appneta#270 allow fractions for --pps (appneta#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen authored Feb 27, 2017
1 parent d689d14 commit 175f7ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
02/26/2017 Version 4.2.0beta1
- tcpcapinfo buffer overflow vulnerablily (#278)
- Update git-clone instructions by Kyle McDonald (#277)
- Allow fractions for --pps option (#270)
- Add protection against packet drift by Guillaume Scott (#268)
- Include Travis-CI build support by Ilya Shipitsin (#264) (#285)

Expand Down
9 changes: 6 additions & 3 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,10 +1170,13 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta,
*/
now_us = TIMSTAMP_TO_MICROSEC(sent_timestamp);
if (now_us) {
COUNTER pps = ctx->options->speed.speed * (ctx->options->speed.pps_multi > 0 ? ctx->options->speed.pps_multi : 1);;
COUNTER pph = ctx->options->speed.speed * (ctx->options->speed.pps_multi > 0 ? ctx->options->speed.pps_multi : (60 * 60));;
COUNTER pkts_sent = ctx->stats.pkts_sent;
/* packets * 1000000 divided by pps = microseconds */
COUNTER next_tx_us = (pkts_sent * 1000000) / pps;
/*
* packets * 1000000 divided by pps = microseconds
* packets per sec (pps) = packets per hour / (60 * 60)
*/
COUNTER next_tx_us = (pkts_sent * 1000000) * (60 * 60) / pph;
COUNTER tx_us = now_us - *start_us;
if (next_tx_us > tx_us)
NANOSEC_TO_TIMESPEC((next_tx_us - tx_us) * 1000, &ctx->nap);
Expand Down
3 changes: 2 additions & 1 deletion src/tcpreplay_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ tcpreplay_post_args(tcpreplay_t *ctx, int argc)
options->speed.mode = speed_topspeed;
options->speed.speed = 0;
} else if (HAVE_OPT(PPS)) {
n = atof(OPT_ARG(PPS));
options->speed.speed = (COUNTER)(n * 60.0 * 60.0); /* convert to packets per hour */
options->speed.mode = speed_packetrate;
options->speed.speed = (float)OPT_VALUE_PPS;
options->speed.pps_multi = OPT_VALUE_PPS_MULTI;
} else if (HAVE_OPT(ONEATATIME)) {
options->speed.mode = speed_oneatatime;
Expand Down
11 changes: 9 additions & 2 deletions src/tcpreplay_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,17 @@ flag = {
flags-cant = oneatatime;
flags-cant = topspeed;
value = p;
arg-type = number;
arg-type = string;
max = 1;
descrip = "Replay packets at a given packets/sec";
doc = "";
doc = <<- EOText
Specify a value to regulate the packet replay to a specific packet-per-second rate.
Examples:
@example
200 will replay traffic at 200 packets per second
0.25 will replay traffic at 15 packets per minute
@end example
EOText;
};

flag = {
Expand Down

0 comments on commit 175f7ed

Please sign in to comment.