From 1ebc0c57ed3f0f1c78e381c1df4e312564831e29 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 26 Jan 2012 11:28:14 +0100 Subject: [PATCH] Different port for autocal. orders and hello Differentiate the port on which the autocalibration hello messages are sent to the aggregator by the listeners, and the one on which the autocalibration orders are sent by the aggregator to the listeners. This will allow to run a listener and an aggregator on the same machine with autocalibration enabled. Both in the listener and the aggregator, the option -a (autocalibration port) has been replaced by the options -O (autocalibration order port) and -H (autocalibration hello port). In the listener, the option -H was previously used to set the hello delay; this is now the role of the -T option. --- libowlps/owlps.h | 6 ++- owlps-aggregator/owlps-aggregator.h | 2 +- owlps-aggregator/owlps-aggregatord.c | 36 +++++++++----- owlps-listener/owlps-listener.h | 26 ++++++---- owlps-listener/owlps-listenerd.c | 72 ++++++++++++++++++---------- 5 files changed, 94 insertions(+), 48 deletions(-) diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 1c90790..285ad72 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -27,8 +27,10 @@ extern "C" { // Port on which aggregator and positioning server communicate: #define OWL_DEFAULT_AGGREGATION_PORT 9902 // Port on which the aggregator listens for hello messages from the -// listeners, and the listeners listen for orders from the aggregator: -#define OWL_DEFAULT_AUTOCALIBRATION_PORT 9904 +// listeners: +#define OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT 9903 +// Port on which the listeners listen for orders from the aggregator: +#define OWL_DEFAULT_AUTOCALIBRATION_ORDER_PORT 9904 // Port on which the mobile listens for its position: #define OWL_DEFAULT_RESULT_PORT 9910 diff --git a/owlps-aggregator/owlps-aggregator.h b/owlps-aggregator/owlps-aggregator.h index 31639fa..55161e6 100644 --- a/owlps-aggregator/owlps-aggregator.h +++ b/owlps-aggregator/owlps-aggregator.h @@ -9,7 +9,7 @@ /* Arguments & program configuration */ -#define OPTIONS "a:Ac:C:Df:hi:k:K:l:o:p:qt:vV" // getopt string +#define OPTIONS "Ac:C:Df:hH:i:k:K:l:o:O:p:qt:vV" // getopt string #define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-aggregator.conf" #define DEFAULT_AGGREGATE_TIMEOUT 1500 // milliseconds #define DEFAULT_KEEP_TIMEOUT 3000 // milliseconds diff --git a/owlps-aggregator/owlps-aggregatord.c b/owlps-aggregator/owlps-aggregatord.c index 1c62dd5..d310512 100644 --- a/owlps-aggregator/owlps-aggregatord.c +++ b/owlps-aggregator/owlps-aggregatord.c @@ -229,9 +229,13 @@ int parse_config_file(int argc, char **argv) // Autocalibration activated? CFG_BOOL("autocalibration", cfg_false, CFGF_NONE), - // Port on which autocalibration data are exchanged: - CFG_INT("autocalibration_port", OWL_DEFAULT_AUTOCALIBRATION_PORT, - CFGF_NONE), + // Port on which autocalibration orders are sent to the listeners: + CFG_INT("autocalibration_order_port", + OWL_DEFAULT_AUTOCALIBRATION_ORDER_PORT, CFGF_NONE), + // Port on which autocalibration hello are received from the + // listeners: + CFG_INT("autocalibration_hello_port", + OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT, CFGF_NONE), // Time we keep APs in the list (in seconds): CFG_INT("ap_keep_timeout", DEFAULT_AP_KEEP_TIMEOUT, CFGF_NONE), // Time between two checks of the AP list (in milliseconds): @@ -308,10 +312,6 @@ int parse_command_line(int argc, char **argv) case 'A' : cfg_setbool(cfg, "autocalibration", cfg_true) ; break ; - case 'a' : - cfg_setint(cfg, "autocalibration_port", - strtol(optarg, NULL, 0)) ; - break ; case 'c' : cfg_setint(cfg, "check_interval", strtol(optarg, NULL, 0)) ; break ; @@ -323,6 +323,10 @@ int parse_command_line(int argc, char **argv) break ; case 'f' : // Config file break ; // (already parsed) + case 'H' : + cfg_setint(cfg, "autocalibration_hello_port", + strtol(optarg, NULL, 0)) ; + break ; case 'i' : cfg_setstr(cfg, "positioner_ip", optarg) ; break ; @@ -338,6 +342,10 @@ int parse_command_line(int argc, char **argv) case 'o' : cfg_setstr(cfg, "output_file", optarg) ; break ; + case 'O' : + cfg_setint(cfg, "autocalibration_order_port", + strtol(optarg, NULL, 0)) ; + break ; case 'p' : cfg_setint(cfg, "positioner_port", strtol(optarg, NULL, 0)) ; break ; @@ -921,7 +929,7 @@ void* listen_for_aps(void *NULL_value) listen_sockfd = owl_create_udp_listening_socket(cfg_getint(cfg, - "autocalibration_port")) ; + "autocalibration_hello_port")) ; if (listen_sockfd < 0) { perror("Error! Cannot create UDP listening socket from the" @@ -1191,7 +1199,8 @@ void order_send(ap_list *ap) sockfd = owl_create_udp_trx_socket(ap->ip_addr, - cfg_getint(cfg, "autocalibration_port"), + cfg_getint(cfg, + "autocalibration_order_port"), &serv, &client) ; message.order = AUTOCALIBRATION_ORDER_SEND ; @@ -1380,8 +1389,10 @@ void print_usage() "Autocalibration options:\n" "\t-A\t\t\tEnable autocalibration (default: disabled).\n" - "\t-a port\t\t\tPort on which autocalibration data" - " are exchanged\n\t\t\t\twith the listeners (default: %d).\n" + "\t-O port\t\t\tPort on which autocalibration orders are" + " sent to\n\t\t\t\tthe listeners (default: %d).\n" + "\t-H port\t\t\tPort on which autocalibration hello are" + " received\n\t\t\t\tfrom the listeners (default: %d).\n" "\t-K ap_keep_timeout\tInactive APs are kept during" " 'ap_keep_timeout'\n\t\t\t\tseconds (default: %d s).\n" "\t-C ap_check_interval\tTime (in milliseconds) between two" @@ -1397,7 +1408,8 @@ void print_usage() DEFAULT_AGGREGATE_TIMEOUT, DEFAULT_KEEP_TIMEOUT, DEFAULT_CHECK_INTERVAL, - OWL_DEFAULT_AUTOCALIBRATION_PORT, + OWL_DEFAULT_AUTOCALIBRATION_ORDER_PORT, + OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT, DEFAULT_AP_KEEP_TIMEOUT, DEFAULT_AP_CHECK_INTERVAL ) ; diff --git a/owlps-listener/owlps-listener.h b/owlps-listener/owlps-listener.h index 84588a3..5505267 100644 --- a/owlps-listener/owlps-listener.h +++ b/owlps-listener/owlps-listener.h @@ -62,7 +62,7 @@ /* Arguments & program configuration */ -#define OPTIONS "a:ADf:hH:i:I:Kl:m:n:p:P:qr:t:vVw:" // getopt string +#define OPTIONS "ADf:hH:i:I:Kl:m:n:O:p:P:qr:t:T:vVw:" // getopt string #define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf" enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ; #define DEFAULT_AUTOCALIBRATION_HELLO_DELAY 120 // seconds @@ -257,10 +257,14 @@ void print_version(void) ; (cfg_setint(cfg, "autocalibration_request_port", (PORT))) #define GET_AUTOCALIBRATION_REQUEST_PORT() \ (cfg_getint(cfg, "autocalibration_request_port")) -#define SET_AUTOCALIBRATION_PORT(PORT) \ - (cfg_setint(cfg, "autocalibration_port", (PORT))) -#define GET_AUTOCALIBRATION_PORT() \ - (cfg_getint(cfg, "autocalibration_port")) +#define SET_AUTOCALIBRATION_ORDER_PORT(PORT) \ + (cfg_setint(cfg, "autocalibration_order_port", (PORT))) +#define GET_AUTOCALIBRATION_ORDER_PORT() \ + (cfg_getint(cfg, "autocalibration_order_port")) +#define SET_AUTOCALIBRATION_HELLO_PORT(PORT) \ + (cfg_setint(cfg, "autocalibration_hello_port", (PORT))) +#define GET_AUTOCALIBRATION_HELLO_PORT() \ + (cfg_getint(cfg, "autocalibration_hello_port")) #define SET_AUTOCALIBRATION_HELLO_DELAY(DELAY) \ (cfg_setint(cfg, "autocalibration_hello_delay", (DELAY))) #define GET_AUTOCALIBRATION_HELLO_DELAY() \ @@ -348,10 +352,14 @@ void print_version(void) ; (options.autocalibration_request_port = (PORT)) #define GET_AUTOCALIBRATION_REQUEST_PORT() \ (options.autocalibration_request_port) -#define SET_AUTOCALIBRATION_PORT(PORT) \ - (options.autocalibration_port = (PORT)) -#define GET_AUTOCALIBRATION_PORT() \ - (options.autocalibration_port) +#define SET_AUTOCALIBRATION_ORDER_PORT(PORT) \ + (options.autocalibration_order_port = (PORT)) +#define GET_AUTOCALIBRATION_ORDER_PORT() \ + (options.autocalibration_order_port) +#define SET_AUTOCALIBRATION_HELLO_PORT(PORT) \ + (options.autocalibration_hello_port = (PORT)) +#define GET_AUTOCALIBRATION_HELLO_PORT() \ + (options.autocalibration_hello_port) #define SET_AUTOCALIBRATION_HELLO_DELAY(DELAY) \ (options.autocalibration_hello_delay = (DELAY)) #define GET_AUTOCALIBRATION_HELLO_DELAY() \ diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index 9bc2445..8a18504 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -74,7 +74,8 @@ struct { owl_bool autocalibration ; char autocalibration_ip[INET_ADDRSTRLEN] ; uint_fast16_t autocalibration_request_port ; - uint_fast16_t autocalibration_port ; + uint_fast16_t autocalibration_order_port ; + uint_fast16_t autocalibration_hello_port ; uint_fast32_t autocalibration_hello_delay ; uint_fast32_t autocalibration_delay ; uint_fast16_t autocalibration_nb_packets ; @@ -99,7 +100,8 @@ struct { owl_false, "", 0, - OWL_DEFAULT_AUTOCALIBRATION_PORT, + OWL_DEFAULT_AUTOCALIBRATION_ORDER_PORT, + OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT, DEFAULT_AUTOCALIBRATION_HELLO_DELAY, DEFAULT_AUTOCALIBRATION_DELAY, DEFAULT_AUTOCALIBRATION_NBPKT, @@ -330,9 +332,12 @@ int parse_config_file(int argc, char **argv) // Port on which autocalibration requests are sent (default: 0, // but will be set to listening_port in the config check): CFG_INT("autocalibration_request_port", 0, CFGF_NONE), - // Port on which autocalibration data are exchanged: - CFG_INT("autocalibration_port", OWL_DEFAULT_AUTOCALIBRATION_PORT, - CFGF_NONE), + // Port on which autocalibration orders are received: + CFG_INT("autocalibration_order_port", + OWL_DEFAULT_AUTOCALIBRATION_ORDER_PORT, CFGF_NONE), + // Port on which autocalibration hello are sent: + CFG_INT("autocalibration_hello_port", + OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT, CFGF_NONE), // Delay between two hello messages: CFG_INT("autocalibration_hello_delay", DEFAULT_AUTOCALIBRATION_HELLO_DELAY, @@ -461,11 +466,6 @@ int parse_main_options(int argc, char **argv) " is not available and will be ignored. All other" " autocalibration-related options will also be" " ignored.\n") ; -#endif // USE_PTHREAD - break ; - case 'a' : -#ifdef USE_PTHREAD - SET_AUTOCALIBRATION_PORT(strtol(optarg, NULL, 0)) ; #endif // USE_PTHREAD break ; case 'D' : @@ -475,7 +475,7 @@ int parse_main_options(int argc, char **argv) break ; // (already parsed) case 'H' : #ifdef USE_PTHREAD - SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ; + SET_AUTOCALIBRATION_HELLO_PORT(strtol(optarg, NULL, 0)) ; #endif // USE_PTHREAD break ; case 'i' : @@ -504,6 +504,11 @@ int parse_main_options(int argc, char **argv) case 'n' : #ifdef USE_PTHREAD SET_AUTOCALIBRATION_NBPKT(strtol(optarg, NULL, 0)) ; +#endif // USE_PTHREAD + break ; + case 'O' : +#ifdef USE_PTHREAD + SET_AUTOCALIBRATION_ORDER_PORT(strtol(optarg, NULL, 0)) ; #endif // USE_PTHREAD break ; case 'p' : @@ -523,6 +528,11 @@ int parse_main_options(int argc, char **argv) case 't' : #ifdef USE_PTHREAD SET_AUTOCALIBRATION_DELAY(strtol(optarg, NULL, 0)) ; +#endif // USE_PTHREAD + break ; + case 'T' : +#ifdef USE_PTHREAD + SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ; #endif // USE_PTHREAD break ; case 'v' : @@ -652,13 +662,21 @@ int check_configuration() " failing back to the default value.\n") ; SET_AUTOCALIBRATION_REQUEST_PORT(GET_LISTENING_PORT()) ; } - if (GET_AUTOCALIBRATION_PORT() < 1 || - GET_AUTOCALIBRATION_PORT() > 65535) + if (GET_AUTOCALIBRATION_ORDER_PORT() < 1 || + GET_AUTOCALIBRATION_ORDER_PORT() > 65535) { if (VERBOSE_WARNING) - fprintf(stderr, "Warning! Bad autocalibration_port:" + fprintf(stderr, "Warning! Bad autocalibration_order_port:" " failing back to the default value.\n") ; - SET_AUTOCALIBRATION_PORT(OWL_DEFAULT_AUTOCALIBRATION_PORT) ; + SET_AUTOCALIBRATION_ORDER_PORT(OWL_DEFAULT_AUTOCALIBRATION_ORDER_PORT) ; + } + if (GET_AUTOCALIBRATION_HELLO_PORT() < 1 || + GET_AUTOCALIBRATION_HELLO_PORT() > 65535) + { + if (VERBOSE_WARNING) + fprintf(stderr, "Warning! Bad autocalibration_hello_port:" + " failing back to the default value.\n") ; + SET_AUTOCALIBRATION_HELLO_PORT(OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT) ; } } #endif // USE_PTHREAD @@ -688,7 +706,8 @@ void print_configuration() "autocalibration = %s\n" "autocalibration_ip = \"%s\"\n" "autocalibration_request_port = %"PRIuFAST16"\n" - "autocalibration_port = %"PRIuFAST16"\n" + "autocalibration_order_port = %"PRIuFAST16"\n" + "autocalibration_hello_port = %"PRIuFAST16"\n" "autocalibration_hello_delay = %"PRIuFAST32"\n" "autocalibration_delay = %"PRIuFAST32"\n" "autocalibration_nb_packets = %"PRIuFAST16"\n" @@ -712,7 +731,8 @@ void print_configuration() OWL_BOOL_TO_STRING(GET_AUTOCALIBRATION()), GET_AUTOCALIBRATION_IP(), GET_AUTOCALIBRATION_REQUEST_PORT(), - GET_AUTOCALIBRATION_PORT(), + GET_AUTOCALIBRATION_ORDER_PORT(), + GET_AUTOCALIBRATION_HELLO_PORT(), GET_AUTOCALIBRATION_HELLO_DELAY(), GET_AUTOCALIBRATION_DELAY(), GET_AUTOCALIBRATION_NBPKT(), @@ -1291,7 +1311,8 @@ void* autocalibrate_hello(void *NULL_value) send_sockfd = owl_create_trx_socket(GET_AGGREGATION_IP(), - GET_AUTOCALIBRATION_PORT(), &serv, NULL) ; + GET_AUTOCALIBRATION_HELLO_PORT(), + &serv, NULL) ; pthread_cleanup_push(&owl_close_fd, &send_sockfd) ; memcpy(&message.ap_mac_addr_bytes, my_mac_bytes, ETHER_ADDR_LEN) ; @@ -1331,7 +1352,7 @@ void* autocalibrate(void *NULL_value) // Socket to receive orders from the aggregator listen_sockfd = - owl_create_udp_listening_socket(GET_AUTOCALIBRATION_PORT()) ; + owl_create_udp_listening_socket(GET_AUTOCALIBRATION_ORDER_PORT()) ; if (listen_sockfd < 0) { perror("Error! Cannot create UDP listening socket from the" @@ -1530,10 +1551,12 @@ void print_usage() " requests\n\t\t\t\t(default: aggregation_ip).\n" "\t-P autocalib_req_port\tPort on which autocalibration" " requests are sent\n\t\t\t\t(default: listening_port).\n" - "\t-a autocalib_port\tPort on which autocalibration data (hello" - " &\n\t\t\t\torders) are exchanged with the aggregation" - "\n\t\t\t\tserver (default: %d).\n" - "\t-H hello_delay\t\tTime between each hello message sent to" + "\t-O order_port\t\tPort on which autocalibration orders are" + "\n\t\t\t\treceived from the aggregation server (default:" + "\n\t\t\t\t%d).\n" + "\t-H hello_port\t\tPort on which hello messages are sent to" + " the\n\t\t\t\taggregation server (default: %d).\n" + "\t-T hello_delay\t\tTime between each hello message sent to" " the\n\t\t\t\taggregation server, in seconds (default:" " %d s).\n" "\t-t delay\t\tTime between each autocalibration" @@ -1556,7 +1579,8 @@ void print_usage() DEFAULT_CONFIG_FILE, OWL_DEFAULT_REQUEST_PORT, OWL_DEFAULT_LISTENER_PORT, - OWL_DEFAULT_AUTOCALIBRATION_PORT, + OWL_DEFAULT_AUTOCALIBRATION_ORDER_PORT, + OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT, DEFAULT_AUTOCALIBRATION_HELLO_DELAY, DEFAULT_AUTOCALIBRATION_DELAY, DEFAULT_AUTOCALIBRATION_NBPKT