2 node_sim.c -- Implementation of Node Simulation for Meshlink Testing
3 for meta connection test case 01 - re-connection of
4 two nodes when relay node goes down
5 Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "../common/common_handlers.h"
26 #include "../common/test_step.h"
27 #include "../common/mesh_event_handler.h"
29 static bool conn_status = false;
31 void callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level,
33 char connection_match_msg[100];
35 fprintf(stderr, "meshlink>> %s\n", text);
37 if(strstr(text, "Connection") || strstr(text, "connection")) {
38 assert(snprintf(connection_match_msg, sizeof(connection_match_msg),
39 "Connection with peer") >= 0);
41 if(strstr(text, connection_match_msg) && strstr(text, "activated")) {
46 assert(snprintf(connection_match_msg, sizeof(connection_match_msg),
47 "Already connected to peer") >= 0);
49 if(strstr(text, connection_match_msg)) {
54 assert(snprintf(connection_match_msg, sizeof(connection_match_msg),
55 "Connection closed by peer") >= 0);
57 if(strstr(text, connection_match_msg)) {
62 assert(snprintf(connection_match_msg, sizeof(connection_match_msg),
63 "Closing connection with peer") >= 0);
65 if(strstr(text, connection_match_msg)) {
74 int main(int argc, char *argv[]) {
79 if((argv[3]) && (argv[4])) {
80 client_id = atoi(argv[3]);
81 mesh_event_sock_connect(argv[4]);
84 execute_open(argv[1], argv[2]);
85 meshlink_set_log_cb(mesh_handle, MESHLINK_DEBUG, callback_logger);
88 execute_join(argv[5]);
92 mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0);
94 /* Connectivity of peer is checked using meshlink_get_node API */
100 fprintf(stderr, "Connected with Peer\n");
101 mesh_event_sock_send(client_id, META_CONN_SUCCESSFUL, NULL, 0);
104 fprintf(stderr, "Waiting 120 sec for peer to be re-connected\n");
106 for(i = 0; i < 120; i++) {
116 fprintf(stderr, "Re-connected with Peer\n");
117 mesh_event_sock_send(client_id, META_RECONN_SUCCESSFUL, NULL, 0);
119 fprintf(stderr, "Failed to reconnect with Peer\n");
120 mesh_event_sock_send(client_id, META_RECONN_FAILURE, NULL, 0);
124 meshlink_destroy(argv[1]);