@@ -89,11 +89,12 @@ send_packets(pcap_t *pcap, int cache_file_idx)
89
89
#if defined TCPREPLAY && defined TCPREPLAY_EDIT
90
90
struct pcap_pkthdr * pkthdr_ptr ;
91
91
#endif
92
- delta_t delta_ctx ;
93
92
COUNTER skip_length = 0 ;
94
93
COUNTER start_us ;
94
+ bool do_not_timestamp = options .speed .mode == SPEED_TOPSPEED ||
95
+ (options .speed .mode == SPEED_MBPSRATE && !options .speed .speed );
95
96
96
- init_delta_time ( & delta_ctx );
97
+ init_timestamp ( & end );
97
98
start_us = TIMEVAL_TO_MICROSEC (& begin );
98
99
99
100
/* register signals */
@@ -166,26 +167,46 @@ send_packets(pcap_t *pcap, int cache_file_idx)
166
167
* had to be special and use bpf_timeval.
167
168
* Only sleep if we're not in top speed mode (-t)
168
169
*/
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
+
171
187
if (options .sleep_mode == REPLAY_V325 ) {
172
188
do_sleep_325 ((struct timeval * )& pkthdr .ts , & last , pktlen , options .accurate , sp , packetnum );
173
189
} else {
174
190
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 );
176
192
177
193
/* mark the time when we send the last packet */
178
194
if (!skip_length )
179
- start_delta_time ( & delta_ctx );
195
+ get_packet_timestamp ( & end );
180
196
}
181
197
}
182
198
199
+ SEND_NOW :
183
200
dbgx (2 , "Sending packet #" COUNTER_SPEC , packetnum );
184
201
185
202
/* write packet out on network */
186
203
if (sendpacket (sp , pktdata , pktlen , & pkthdr ) < (int )pktlen )
187
204
warnx ("Unable to send packet: %s" , sendpacket_geterr (sp ));
188
205
206
+ /* mark the time when we send the last packet */
207
+ if (!do_not_timestamp && !skip_length )
208
+ get_packet_timestamp (& end );
209
+
189
210
/*
190
211
* track the time of the "last packet sent". Again, because of OpenBSD
191
212
* 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
238
259
packet_cache_t * cached_packet1 = NULL , * cached_packet2 = NULL ;
239
260
packet_cache_t * * prev_packet1 = NULL , * * prev_packet2 = NULL , * * prev_packet = NULL ;
240
261
struct pcap_pkthdr * pkthdr_ptr ;
241
- delta_t delta_ctx ;
242
262
COUNTER start_us ;
243
263
COUNTER skip_length = 0 ;
264
+ bool do_not_timestamp = options .speed .mode == SPEED_TOPSPEED ||
265
+ (options .speed .mode == SPEED_MBPSRATE && !options .speed .speed );
244
266
245
- init_delta_time ( & delta_ctx );
267
+ init_timestamp ( & end );
246
268
start_us = TIMEVAL_TO_MICROSEC (& begin );
247
269
248
270
/* register signals */
@@ -350,26 +372,42 @@ send_dual_packets(pcap_t *pcap1, int cache_file_idx1, pcap_t *pcap2, int cache_f
350
372
* had to be special and use bpf_timeval.
351
373
* Only sleep if we're not in top speed mode (-t)
352
374
*/
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
+
355
391
if (options .sleep_mode == REPLAY_V325 ) {
356
392
do_sleep_325 ((struct timeval * )& pkthdr_ptr -> ts , & last , pktlen , options .accurate , sp , packetnum );
357
393
} else {
358
394
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 );
360
396
361
- /* mark the time when we send the last packet */
362
- if (!skip_length )
363
- start_delta_time (& delta_ctx );
364
397
}
365
398
}
366
399
400
+ SEND_NOW :
367
401
dbgx (2 , "Sending packet #" COUNTER_SPEC , packetnum );
368
402
369
403
/* write packet out on network */
370
404
if (sendpacket (sp , pktdata , pktlen , pkthdr_ptr ) < (int )pktlen )
371
405
warnx ("Unable to send packet: %s" , sendpacket_geterr (sp ));
372
406
407
+ /* mark the time when we send the last packet */
408
+ if (!do_not_timestamp && !skip_length )
409
+ get_packet_timestamp (& end );
410
+
373
411
/*
374
412
* track the time of the "last packet sent". Again, because of OpenBSD
375
413
* we have to do a memcpy rather then assignment.
0 commit comments