#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;
-static int meshlink_get_node_in_container(const char *name) {
- int i;
-
- for(i = 0; i < state_ptr->num_nodes; i++) {
- if(!strcasecmp(state_ptr->node_names[i], name)) {
- return i;
- break;
- }
- }
-
- return -1;
-}
-
void mesh_close_signal_handler(int a) {
test_running = false;
exit(EXIT_SUCCESS);
}
+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 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'
family = ifa->ifa_addr->sa_family;
- 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));
+ 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));
break;
}
}
family = ifa->ifa_addr->sa_family;
- 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));
+ 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));
break;
}
}
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) {
- 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;
- }
+ 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);
- int i = meshlink_get_node_in_container(name);
- assert(i != -1);
- meta_conn_status[i] = status;
+ 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;
+ }
+ }
}
}