X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fblackbox%2Fcommon%2Fcommon_handlers.c;h=e728f4383684176f9b8fe409eb4b6d5252c63652;hb=f342cb44b25cd61eed17897575015be4aae1dd17;hp=d6ef7756933ad179d73f7c54d753090bc03080b1;hpb=de40dd736a1b048e5e0f856184f832fa4db184d3;p=meshlink diff --git a/test/blackbox/common/common_handlers.c b/test/blackbox/common/common_handlers.c index d6ef7756..e728f438 100644 --- a/test/blackbox/common/common_handlers.c +++ b/test/blackbox/common/common_handlers.c @@ -17,6 +17,11 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#ifdef NDEBUG +#undef NDEBUG +#endif + #include #include #include @@ -33,31 +38,36 @@ #include "test_step.h" #include "common_handlers.h" -#define GET_IP_FAMILY AF_INET - char *lxc_bridge = NULL; black_box_state_t *state_ptr = NULL; bool meta_conn_status[10]; -bool node_reachable_status[10]; bool test_running; -void mesh_close_signal_handler(int a) { - test_running = false; +static int meshlink_get_node_in_container(const char *name) { + int i; - exit(EXIT_SUCCESS); + for(i = 0; i < state_ptr->num_nodes; i++) { + if(!strcasecmp(state_ptr->node_names[i], name)) { + return i; + break; + } + } + + return -1; } -void mesh_stop_start_signal_handler(int a) { - /* Stop the Mesh if it is running, otherwise start it again */ - (mesh_started) ? execute_stop() : execute_start(); +void mesh_close_signal_handler(int signum) { + (void)signum; + test_running = false; + + exit(EXIT_SUCCESS); } void setup_signals(void) { test_running = true; signal(SIGTERM, mesh_close_signal_handler); - signal(SIGINT, mesh_stop_start_signal_handler); } /* Return the IP Address of the Interface 'if_name' @@ -78,8 +88,8 @@ char *get_ip(const char *if_name) { family = ifa->ifa_addr->sa_family; - if(family == GET_IP_FAMILY && !strcmp(ifa->ifa_name, if_name)) { - assert(!getnameinfo(ifa->ifa_addr, (family == GET_IP_FAMILY) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)); + if(family == AF_INET && !strcmp(ifa->ifa_name, if_name)) { + assert(!getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)); break; } } @@ -105,8 +115,8 @@ char *get_netmask(const char *if_name) { family = ifa->ifa_addr->sa_family; - if(family == GET_IP_FAMILY && !strcmp(ifa->ifa_name, if_name)) { - assert(!getnameinfo(ifa->ifa_netmask, (family == GET_IP_FAMILY) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)); + if(family == AF_INET && !strcmp(ifa->ifa_name, if_name)) { + assert(!getnameinfo(ifa->ifa_netmask, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)); break; } } @@ -145,60 +155,35 @@ void start_nw_intf(const char *if_name) { void meshlink_callback_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - int i; - (void)mesh; fprintf(stderr, "Node %s became %s\n", node->name, (reachable) ? "reachable" : "unreachable"); - - if(state_ptr) - for(i = 0; i < state_ptr->num_nodes; i++) - if(strcmp(node->name, state_ptr->node_names[i]) == 0) { - node_reachable_status[i] = reachable; - } } void meshlink_callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - int i; - char connection_match_msg[100]; (void)mesh; (void)level; fprintf(stderr, "meshlink>> %s\n", text); - if(state_ptr && (strstr(text, "Connection") || strstr(text, "connection"))) { - for(i = 0; i < state_ptr->num_nodes; i++) { - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection with %s", state_ptr->node_names[i]) >= 0); - - if(strstr(text, connection_match_msg) && strstr(text, "activated")) { - meta_conn_status[i] = true; - continue; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Already connected to %s", state_ptr->node_names[i]) >= 0); - - if(strstr(text, connection_match_msg)) { - meta_conn_status[i] = true; - continue; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection closed by %s", state_ptr->node_names[i]) >= 0); - - if(strstr(text, connection_match_msg)) { - meta_conn_status[i] = false; - continue; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Closing connection with %s", state_ptr->node_names[i]) >= 0); - - if(strstr(text, connection_match_msg)) { - meta_conn_status[i] = false; - continue; - } + if(state_ptr) { + bool status; + char name[100]; + + if(sscanf(text, "Connection with %s activated", name) == 1) { + status = true; + } else if(sscanf(text, "Already connected to %s", name) == 1) { + status = true; + } else if(sscanf(text, "Connection closed by %s", name) == 1) { + status = false; + } else if(sscanf(text, "Closing connection with %s", name) == 1) { + status = false; + } else { + return; } + + int i = meshlink_get_node_in_container(name); + assert(i != -1); + meta_conn_status[i] = status; } }