[Client] Change -F option's behaviour

In flood mode, the delay is now counted from the beginning of the
transmission of a request, instead of after the end of the transmission.
The old behaviour is still supported by adding a '+' before the delay
duration on the command line.
This commit is contained in:
Matteo Cypriani 2013-09-20 12:34:11 -04:00
parent 9ca63f0858
commit e58d158286
3 changed files with 62 additions and 21 deletions

View File

@ -139,14 +139,6 @@ Work to do in OwlPS
= Client =
- "Metronome" option to send a request precisely every X milliseconds.
Get the current time right before and right after transmitting a
request, and sleep for (X - elapsed(before, after)).
Should we replace the default behaviour? Or -F 1000 would be the new
behaviour, whereas -F +1000 would be the old behaviour?
- Log sent requests?
- Qt version of the client

View File

@ -23,7 +23,7 @@ June 2013
**owlps-client** [ **-v** | **-q** ] **-i** //dest_ip// [ **-p** //dest_port// ] [ **-I** //iface// ]
[ **-t** //delay// ] [ **-n** //nb_packets// ] [ **-s** //packet_size// ]
[ **-F** [ //delay// ] [ **-N** //nb_requests// ] [ **-D** ] ] [ **-l** [ //port// ] ]
[ **-F** [ //[+]delay// ] [ **-N** //nb_requests// ] [ **-D** ] ] [ **-l** [ //port// ] ]
**owlps-client** [ **-v** | **-q** ] **-i** dest_ip [ **-p** //dest_port// ] [ **-I** //iface// ]
[ **-t** //delay// ] [ **-n** //nb_packets// ] [ **-s** //packet_size// ]
@ -75,9 +75,16 @@ owlps-aggregatord.t2t) to create a manual calibration database.
Name of the network interface used to transmit the request (e.g.
“eth2”). If this option is absent, the interface is selected
automatically. You must be root to use this option.
: **-F** [ //delay// ]
: **-F** [ //[+]delay// ]
“Flood mode”: loop indefinitely, sending a new request every //delay//
milliseconds (default: 1000 ms).
milliseconds (default: 1000 ms). If //delay// is smaller than the
transmission time of a request (cf. **-n** and **-t** options), it is
ignored and the next request is transmitted right away. If //delay//
is prefixed with a //+// sign, it is cumulative to the transmission
time, i.e. it is the delay between the end of a request's transmission
and the start of the next request's transmission; by default,
//delay// is the time between the start of the transmissions of both
requests.
: **-N** //nb_requests//
With -F, stop after //nb_requests// requests transmitted instead of
looping indefinitely.

View File

@ -84,6 +84,7 @@ struct {
uint_fast16_t nb_pkt ; // Number of packets to send
uint_fast16_t pkt_size ; // Size of the packet to send
int_fast32_t flood_delay ; // Time between two request transmissions
bool add_flood_delay ; // Add the delay to the transmission time?
uint_fast16_t nb_requests ; // Number of requests to send
uint_fast16_t listening_port ;
// Calibration data:
@ -101,6 +102,7 @@ struct {
0, // nb_pkt
0, // pkt_size
-1, // flood_delay
false, // add_flood_delay
0, // nb_requests
0, // listening_port
0, 0, 0, 0 // Calibration data
@ -125,6 +127,7 @@ int main(int argc, char *argv[])
int ret = 0 ;
// Number of requests we still have to transmit:
uint_fast16_t nb_requests_left = 1 ;
owl_timestamp start_time ; // Time of the transmission's start
owl_run = true ;
@ -149,12 +152,42 @@ int main(int argc, char *argv[])
create_socket() ;
/* Transmit the first request */
if (! options.add_flood_delay)
owl_timestamp_now(&start_time) ;
send_request() ;
if (options.nb_requests)
nb_requests_left = options.nb_requests - 1 ;
/* Transmit the next requests, if any */
while (owl_run && options.flood_delay >= 0 && nb_requests_left > 0)
{
owl_msleep(options.flood_delay) ;
uint_fast32_t trx_time, sleep_time ;
owl_timestamp now ;
if (options.add_flood_delay)
owl_msleep(options.flood_delay) ;
else
{
owl_timestamp_now(&now) ;
trx_time = owl_time_elapsed_ms(&start_time, &now) ;
printf("Transmission time was %"PRIuFAST32" ms", trx_time) ;
// Sleep only if the sleep delay is greater than the
// transmission time
if (trx_time < (uint_fast32_t) options.flood_delay)
{
sleep_time = options.flood_delay - trx_time ;
printf(", sleeping for %"PRIuFAST32" ms...\n", sleep_time) ;
owl_msleep(sleep_time) ;
}
else
printf(" > %"PRIdFAST32" ms, no sleeping required.\n",
options.flood_delay) ;
owl_timestamp_now(&start_time) ;
}
if (owl_run) // owl_run can have been set to false during the sleep
{
send_request() ;
@ -204,8 +237,12 @@ void parse_main_options(int argc, char **argv)
* (like -F <delay>), so we have to test separately.
*/
if (optarg) // We got an option like -F<delay>, it's OK
options.flood_delay = strtoul(optarg, NULL, 0) ;
else // We got -F alone or -F <port>
{
options.flood_delay = strtoul(optarg, NULL, 0) ;
if (optarg[0] == '+')
options.add_flood_delay = true ;
}
else // We got -F alone or -F <delay>
{
/* If we are at the end of the string, or the next optind
* is an option, we have the option without argument */
@ -215,8 +252,9 @@ void parse_main_options(int argc, char **argv)
else
{
// Take the optind value:
options.flood_delay =
strtoul(argv[optind], NULL, 0) ;
options.flood_delay = strtoul(argv[optind], NULL, 0) ;
if (argv[optind][0] == '+')
options.add_flood_delay = true ;
++optind ;
}
}
@ -438,6 +476,7 @@ void print_configuration()
"\tNumber of packets: %"PRIuFAST16"\n"
"\tPacket size: %"PRIuFAST16"\n"
"\tFlood delay (ms): %"PRIdFAST32"\n"
"\tCumulative flood delay: %s\n"
"\tNumber of requests: %"PRIuFAST16"\n"
"\tListening port: %"PRIuFAST16"\n"
"\tDirection: %"PRIu8"\n"
@ -454,6 +493,7 @@ void print_configuration()
options.nb_pkt,
options.pkt_size,
options.flood_delay,
OWL_BOOL_TO_STRING(options.add_flood_delay),
options.nb_requests,
options.listening_port,
options.direction,
@ -497,7 +537,7 @@ void make_packet()
if (is_calibration_request) // Calibration packet
{
if (options.verbose)
printf("Preparing calibration request packet...\n") ;
printf("\nPreparing calibration request packet...\n") ;
packet_size =
sizeof(uint8_t) * 2 + sizeof(owl_timestamp) + sizeof(float) * 3 +
@ -517,7 +557,7 @@ void make_packet()
else // Standard packet
{
if (options.verbose)
printf("Preparing request packet...\n") ;
printf("\nPreparing request packet...\n") ;
packet_size =
sizeof(uint8_t) + sizeof(owl_timestamp) + sizeof(uint16_t) * 2 ;
@ -676,7 +716,7 @@ void print_usage()
"\n\t"
" [-n nb_packets]"
" [-s packet_size]"
" [-F [delay] [-N nb_requests] [-D]]"
" [-F [[+]delay] [-N nb_requests] [-D]]"
"\n\t"
" [-l [port]]\n"
"Calibration request:\n"
@ -689,7 +729,7 @@ void print_usage()
"\n\t"
" [-n nb_packets]"
" [-s packet_size]"
" [-F [delay] [-N nb_requests] [-D]]"
" [-F [[+]delay] [-N nb_requests] [-D]]"
"\n\t"
" direction x y z\n"
@ -721,7 +761,9 @@ void print_usage()
" to\n\t\t\tuse this option.\n"
"\t-F [delay]\t\"Flood mode\": loop indefinitely, sending a"
" new request\n\t\t\tevery <delay> milliseconds (default:"
" %d ms).\n"
" %d ms). If\n\t\t\t<delay> starts with a +, it is the time"
" between two\n\t\t\trequests instead of the time between the"
" start of the\n\t\t\ttransmission of two requests.\n"
"\t-N nb_requests\tWith -F, stop after <nb_requests> requests"
" transmitted\n\t\t\tinstead of looping indefinitely.\n"
"\t-D\t\tDaemon mode. Useful only in flood mode.\n"