Skip to content

Commit ce806cf

Browse files
committed
Removed sleep-accel option. Timestamp after packet sent which allows us to clean up several timestamp hacks.
1 parent 7513447 commit ce806cf

22 files changed

+112
-198
lines changed

autogen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if test -x "`which glibtoolize`" ; then
66
# Necessary under OS X
77
glibtoolize --copy --automake --force
88
else
9-
libtoolize --copy
9+
libtoolize --copy --force
1010
fi
1111
autoheader
1212
automake --add-missing --copy

docs/CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$Id$
22

33
??/??/2013 Version 3.5.0
4+
- Removed sleep-accel option (anneta #2)
45
- Enhance accuracy and performance of --mbps option (appneta #2)
56
- Add netmap injector (appneta #1)
67
- Add --sleepmode option to handle high precision timing (#421)

libopts/parse-duration.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ typedef enum {
5454
#define TIME_MAX 0x7FFFFFFF
5555

5656
/* Wrapper around strtoul that does not require a cast. */
57-
static unsigned long inline
57+
static inline unsigned long
5858
str_const_to_ul (cch_t * str, cch_t ** ppz, int base)
5959
{
6060
return strtoul (str, (char **)ppz, base);
6161
}
6262

6363
/* Wrapper around strtol that does not require a cast. */
64-
static long inline
64+
static inline long
6565
str_const_to_l (cch_t * str, cch_t ** ppz, int base)
6666
{
6767
return strtol (str, (char **)ppz, base);
@@ -70,7 +70,7 @@ str_const_to_l (cch_t * str, cch_t ** ppz, int base)
7070
/* Returns BASE + VAL * SCALE, interpreting BASE = BAD_TIME
7171
with errno set as an error situation, and returning BAD_TIME
7272
with errno set in an error situation. */
73-
static time_t inline
73+
static inline time_t
7474
scale_n_add (time_t base, time_t val, int scale)
7575
{
7676
if (base == BAD_TIME)

src/common/fakepoll.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "defines.h"
4040
#include "common.h"
4141

42+
#ifdef USE_FAKE_POLL
4243
/* prevents ISO C error */
4344
static void FAKEPOLL(int stop)
4445
{
@@ -48,7 +49,6 @@ static void FAKEPOLL(int stop)
4849

4950
}
5051

51-
#ifdef USE_FAKE_POLL
5252
#include <sys/types.h>
5353
#ifdef HAVE_UNISTD_H
5454
#include <unistd.h>

src/common/mac.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mac2hex(const char *mac, u_char *dst, int len)
8181
int
8282
dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len)
8383
{
84-
char *tok, *temp, *string;
84+
char *tok = NULL, *temp, *string;
8585
int ret = 0;
8686

8787
string = safe_strdup(dualmac);
@@ -121,7 +121,7 @@ dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len)
121121
tcpr_dir_t
122122
macinstring(const char *macstring, const u_char *mac)
123123
{
124-
char *tok, *tempstr, *ourstring;
124+
char *tok = NULL, *tempstr, *ourstring;
125125
u_char tempmac[6];
126126
int len = 6, ret = TCPR_DIR_S2C;
127127

src/common/sendpacket.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ extern volatile int didsig;
255255
int
256256
sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr *pkthdr)
257257
{
258-
int retcode, val;
258+
int retcode = 0, val;
259259
u_char buffer[10000]; /* 10K bytes, enough for jumbo frames + pkthdr */
260260
#ifdef HAVE_NETMAP
261261
struct netmap_ring *txring;
@@ -702,7 +702,7 @@ sendpacket_seterr(sendpacket_t *sp, const char *fmt, ...)
702702
}
703703

704704

705-
#if defined HAVE_PCAP_INJECT || defined HAVE_PCAP_SENDPACKET
705+
#if (defined HAVE_PCAP_INJECT || defined HAVE_PCAP_SENDPACKET) && ! defined INJECT_METHOD
706706
/**
707707
* Inner sendpacket_open() method for using libpcap
708708
*/
@@ -996,7 +996,7 @@ sendpacket_open_pf(const char *device, char *errbuf)
996996
struct sockaddr_ll sa;
997997
int n = 1, err;
998998
socklen_t errlen = sizeof(err);
999-
unsigned int mtu=1500;
999+
unsigned int UNUSED(mtu) = 1500;
10001000

10011001
assert(device);
10021002
assert(errbuf);

src/common/timer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void timesdiv(struct timespec *tvs, COUNTER div)
9898
}
9999

100100
void
101-
init_delta_time(delta_t *ctx)
101+
init_timestamp(timestamp_t *ctx)
102102
{
103103
#ifdef HAVE_ABSOLUTE_TIME
104104
SetZero(*ctx);

src/common/timer.h

+6-41
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,17 @@ void timesdiv(struct timespec *tvs, COUNTER div);
201201
} while(0)
202202

203203
#ifdef HAVE_ABSOLUTE_TIME
204-
typedef AbsoluteTime delta_t;
204+
typedef AbsoluteTime timestamp_t;
205205
#else
206-
typedef struct timeval delta_t;
206+
typedef struct timeval timestamp_t;
207207
#endif
208208

209209
/*
210-
* starts a timer so we can figure out how much time has passed
211-
* when we call get_delta_timer()
210+
* starts a timer so we can figure out how long we have
211+
* bee transmitting
212212
*/
213213
static inline void
214-
start_delta_time(delta_t *ctx)
214+
get_packet_timestamp(timestamp_t *ctx)
215215
{
216216
#ifdef HAVE_ABSOLUTE_TIME
217217
*ctx = UpTime();
@@ -220,42 +220,7 @@ start_delta_time(delta_t *ctx)
220220
#endif
221221
}
222222

223-
void init_delta_time(delta_t *ctx);
223+
void init_timestamp(timestamp_t *ctx);
224224

225-
/*
226-
* returns the amount of time that has passed since the
227-
* last time you called start_delta_time()
228-
*/
229-
static inline void
230-
get_delta_time(delta_t *ctx, struct timespec *ret)
231-
{
232-
/* OS X has absolute time */
233-
#ifdef HAVE_ABSOLUTE_TIME
234-
AbsoluteTime now, delta;
235-
Nanoseconds nano;
236-
237-
238-
if (! NonZero(*ctx)) {
239-
timesclear(ret);
240-
} else {
241-
now = UpTime();
242-
delta = SubAbsoluteFromAbsolute(now, *ctx);
243-
nano = AbsoluteToNanoseconds(delta);
244-
NANOSEC_TO_TIMESPEC(UnsignedWideToUInt64(nano) / 10, ret);
245-
}
246-
247-
/* Everyone else just uses gettimeofday */
248-
#else
249-
struct timeval now, delta;
250-
251-
if (!timerisset(ctx)) {
252-
timesclear(ret);
253-
} else {
254-
gettimeofday(&now, NULL);
255-
timersub(&now, ctx, &delta);
256-
TIMEVAL_TO_TIMESPEC(&delta, ret);
257-
}
258-
#endif
259-
}
260225

261226
#endif /* _TIMER_H_ */

src/common/utils.h

-10
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@
3838
#include "defines.h"
3939
#include "common.h"
4040

41-
#define max(a,b) \
42-
({ __typeof__ (a) _a = (a); \
43-
__typeof__ (b) _b = (b); \
44-
_a > _b ? _a : _b; })
45-
46-
#define min(a,b) \
47-
({ __typeof__ (a) _a = (a); \
48-
__typeof__ (b) _b = (b); \
49-
_a > _b ? _b : _a; })
50-
5141
int read_hexstring(const char *l2string, u_char *hex, const int hexlen);
5242
void packet_stats(struct timeval *begin, struct timeval *end,
5343
COUNTER bytes_sent, COUNTER pkts_sent, COUNTER failed);

src/defines.h.in

+24
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,28 @@ typedef u_int32_t uint32_t
285285
#define TIMESPEC_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_nsec / 1000)
286286
#define TIMESPEC_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_nsec))
287287

288+
/* help suppress some compiler warnings */
289+
#ifdef UNUSED
290+
#elif defined(__GNUC__)
291+
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
292+
#elif defined(__LCLINT__)
293+
# define UNUSED(x) /*@unused@*/ x
294+
#else
295+
# define UNUSED(x) x
296+
#endif
297+
298+
#ifndef max
299+
# define max(a,b) \
300+
({ __typeof__ (a) _a = (a); \
301+
__typeof__ (b) _b = (b); \
302+
_a > _b ? _a : _b; })
303+
#endif
304+
305+
#ifndef min
306+
# define min(a,b) \
307+
({ __typeof__ (a) _a = (a); \
308+
__typeof__ (b) _b = (b); \
309+
_a > _b ? _b : _a; })
310+
#endif
311+
288312
#endif /* DEFINES */

src/send_packets.c

+52-14
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ send_packets(pcap_t *pcap, int cache_file_idx)
8989
#if defined TCPREPLAY && defined TCPREPLAY_EDIT
9090
struct pcap_pkthdr *pkthdr_ptr;
9191
#endif
92-
delta_t delta_ctx;
9392
COUNTER skip_length = 0;
9493
COUNTER start_us;
94+
bool do_not_timestamp = options.speed.mode == SPEED_TOPSPEED ||
95+
(options.speed.mode == SPEED_MBPSRATE && !options.speed.speed);
9596

96-
init_delta_time(&delta_ctx);
97+
init_timestamp(&end);
9798
start_us = TIMEVAL_TO_MICROSEC(&begin);
9899

99100
/* register signals */
@@ -166,26 +167,46 @@ send_packets(pcap_t *pcap, int cache_file_idx)
166167
* had to be special and use bpf_timeval.
167168
* Only sleep if we're not in top speed mode (-t)
168169
*/
169-
if (options.speed.mode != SPEED_TOPSPEED &&
170-
!(options.speed.mode == SPEED_MBPSRATE && !options.speed.speed)) {
170+
171+
if (!do_not_timestamp) {
172+
/*
173+
* this accelerator improves performance by avoiding expensive
174+
* time stamps during periods where we have fallen behind in our
175+
* sending
176+
*/
177+
if (skip_length) {
178+
if ((COUNTER)pktlen < skip_length) {
179+
skip_length -= pktlen;
180+
goto SEND_NOW;
181+
}
182+
183+
get_packet_timestamp(&end);
184+
skip_length = 0;
185+
}
186+
171187
if (options.sleep_mode == REPLAY_V325) {
172188
do_sleep_325((struct timeval *)&pkthdr.ts, &last, pktlen, options.accurate, sp, packetnum);
173189
} else {
174190
do_sleep((struct timeval *)&pkthdr.ts, &last, pktlen, options.accurate, sp, packetnum,
175-
&delta_ctx, &start_us, &skip_length);
191+
&end, &start_us, &skip_length);
176192

177193
/* mark the time when we send the last packet */
178194
if (!skip_length)
179-
start_delta_time(&delta_ctx);
195+
get_packet_timestamp(&end);
180196
}
181197
}
182198

199+
SEND_NOW:
183200
dbgx(2, "Sending packet #" COUNTER_SPEC, packetnum);
184201

185202
/* write packet out on network */
186203
if (sendpacket(sp, pktdata, pktlen, &pkthdr) < (int)pktlen)
187204
warnx("Unable to send packet: %s", sendpacket_geterr(sp));
188205

206+
/* mark the time when we send the last packet */
207+
if (!do_not_timestamp && !skip_length)
208+
get_packet_timestamp(&end);
209+
189210
/*
190211
* track the time of the "last packet sent". Again, because of OpenBSD
191212
* we have to do a memcpy rather then assignment.
@@ -238,11 +259,12 @@ send_dual_packets(pcap_t *pcap1, int cache_file_idx1, pcap_t *pcap2, int cache_f
238259
packet_cache_t *cached_packet1 = NULL, *cached_packet2 = NULL;
239260
packet_cache_t **prev_packet1 = NULL, **prev_packet2 = NULL, **prev_packet = NULL;
240261
struct pcap_pkthdr *pkthdr_ptr;
241-
delta_t delta_ctx;
242262
COUNTER start_us;
243263
COUNTER skip_length = 0;
264+
bool do_not_timestamp = options.speed.mode == SPEED_TOPSPEED ||
265+
(options.speed.mode == SPEED_MBPSRATE && !options.speed.speed);
244266

245-
init_delta_time(&delta_ctx);
267+
init_timestamp(&end);
246268
start_us = TIMEVAL_TO_MICROSEC(&begin);
247269

248270
/* register signals */
@@ -350,26 +372,42 @@ send_dual_packets(pcap_t *pcap1, int cache_file_idx1, pcap_t *pcap2, int cache_f
350372
* had to be special and use bpf_timeval.
351373
* Only sleep if we're not in top speed mode (-t)
352374
*/
353-
if (options.speed.mode != SPEED_TOPSPEED &&
354-
!(options.speed.mode == SPEED_MBPSRATE && !options.speed.speed)) {
375+
if (!do_not_timestamp) {
376+
/*
377+
* this accelerator improves performance by avoiding expensive
378+
* time stamps during periods where we have fallen behind in our
379+
* sending
380+
*/
381+
if (skip_length) {
382+
if ((COUNTER)pktlen < skip_length) {
383+
skip_length -= pktlen;
384+
goto SEND_NOW;
385+
}
386+
387+
get_packet_timestamp(&end);
388+
skip_length = 0;
389+
}
390+
355391
if (options.sleep_mode == REPLAY_V325) {
356392
do_sleep_325((struct timeval *)&pkthdr_ptr->ts, &last, pktlen, options.accurate, sp, packetnum);
357393
} else {
358394
do_sleep((struct timeval *)&pkthdr_ptr->ts, &last, pktlen, options.accurate, sp, packetnum,
359-
&delta_ctx, &start_us, &skip_length);
395+
&end, &start_us, &skip_length);
360396

361-
/* mark the time when we send the last packet */
362-
if (!skip_length)
363-
start_delta_time(&delta_ctx);
364397
}
365398
}
366399

400+
SEND_NOW:
367401
dbgx(2, "Sending packet #" COUNTER_SPEC, packetnum);
368402

369403
/* write packet out on network */
370404
if (sendpacket(sp, pktdata, pktlen, pkthdr_ptr) < (int)pktlen)
371405
warnx("Unable to send packet: %s", sendpacket_geterr(sp));
372406

407+
/* mark the time when we send the last packet */
408+
if (!do_not_timestamp && !skip_length)
409+
get_packet_timestamp(&end);
410+
373411
/*
374412
* track the time of the "last packet sent". Again, because of OpenBSD
375413
* we have to do a memcpy rather then assignment.

0 commit comments

Comments
 (0)