2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file mesh/test_mesh_small.c
23 * @brief Test for the mesh service: retransmission of traffic.
27 #include "gnunet_testing_lib.h"
28 #include "gnunet_mesh_service.h"
32 #define REMOVE_DIR GNUNET_YES
36 struct MeshPeer *prev;
38 struct MeshPeer *next;
40 struct GNUNET_TESTING_Daemon *daemon;
42 struct GNUNET_MESH_Handle *mesh_handle;
46 * How namy messages to send
48 #define TOTAL_PACKETS 1000
51 * How long until we give up on connecting the peers?
53 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
56 * Time to wait for stuff that should be rather fast
58 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
61 * DIFFERENT TESTS TO RUN
72 * Which test are we running?
77 * String with test name
82 * Flag to send traffic leaf->root in speed tests to test BCK_ACK logic.
84 static int test_backwards = GNUNET_NO;
87 * How many events have happened
92 * Each peer is supposed to generate the following callbacks:
93 * 1 incoming tunnel (@dest)
94 * 1 connected peer (@orig)
95 * 1 received data packet (@dest)
96 * 1 received data packet (@orig)
97 * 1 received tunnel destroy (@dest)
98 * _________________________________
99 * 5 x ok expected per peer
105 * Size of each test packet
107 size_t size_payload = sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t);
110 * Is the setup initialized?
112 static int initialized;
115 * Peers that have been connected
117 static int peers_in_tunnel;
120 * Peers that have responded
122 static int peers_responded;
125 * Number of payload packes sent
127 static int data_sent;
130 * Number of payload packets received
132 static int data_received;
135 * Number of payload packed explicitly (app level) acknowledged
145 * Total number of peers in the test.
147 static unsigned long long num_peers;
150 * Global configuration file
152 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
155 * Total number of currently running peers.
157 static unsigned long long peers_running;
160 * Total number of connections in the whole network.
162 static unsigned int total_connections;
165 * The currently running peer group.
167 static struct GNUNET_TESTING_PeerGroup *pg;
170 * File to report results to.
172 static struct GNUNET_DISK_FileHandle *output_file;
175 * File to log connection info, statistics to.
177 static struct GNUNET_DISK_FileHandle *data_file;
182 static struct GNUNET_TIME_Relative wait_time;
185 * Task called to disconnect peers.
187 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
190 * Task To perform tests
192 static GNUNET_SCHEDULER_TaskIdentifier test_task;
195 * Task called to shutdown test.
197 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
200 * Filename of the file containing the topology.
202 static char *topology_file;
205 * Testbed handle for the root peer
207 static struct GNUNET_TESTING_Daemon *d1;
210 * Testbed handle for the first leaf peer
212 static struct GNUNET_TESTING_Daemon *d2;
215 * Testbed handle for the second leaf peer
217 static struct GNUNET_TESTING_Daemon *d3;
220 * Mesh handle for the root peer
222 static struct GNUNET_MESH_Handle *h1;
225 * Mesh handle for the first leaf peer
227 static struct GNUNET_MESH_Handle *h2;
230 * Mesh handle for the second leaf peer
232 static struct GNUNET_MESH_Handle *h3;
235 * Tunnel handle for the root peer
237 static struct GNUNET_MESH_Tunnel *t;
240 * Tunnel handle for the first leaf peer
242 static struct GNUNET_MESH_Tunnel *incoming_t;
245 * Tunnel handle for the second leaf peer
247 static struct GNUNET_MESH_Tunnel *incoming_t2;
250 * Time we started the data transmission (after tunnel has been established
253 static struct GNUNET_TIME_Absolute start_time;
257 * Show the results of the test (banwidth acheived) and log them to GAUGER
262 static struct GNUNET_TIME_Absolute end_time;
263 static struct GNUNET_TIME_Relative total_time;
265 end_time = GNUNET_TIME_absolute_get();
266 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
267 FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name);
268 FPRINTF (stderr, "Test time %llu ms\n",
269 (unsigned long long) total_time.rel_value);
270 FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
271 4 * TOTAL_PACKETS * 1.0 / total_time.rel_value); // 4bytes * ms
272 FPRINTF (stderr, "Test throughput: %f packets/s\n\n",
273 TOTAL_PACKETS * 1000.0 / total_time.rel_value); // packets * ms
274 GAUGER ("MESH", test_name,
275 TOTAL_PACKETS * 1000.0 / total_time.rel_value,
281 * Check whether peers successfully shut down.
283 * @param cls Closure (unused).
284 * @param emsg Error message.
287 shutdown_callback (void *cls, const char *emsg)
291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
292 "Shutdown of peers failed!\n");
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
298 "All peers successfully shut down!\n");
300 GNUNET_CONFIGURATION_destroy (testing_cfg);
305 * Shut down peergroup, clean up.
307 * @param cls Closure (unused).
308 * @param tc Task Context.
311 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
315 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
317 GNUNET_SCHEDULER_cancel (disconnect_task);
318 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
323 GNUNET_MESH_disconnect (h1);
328 GNUNET_MESH_disconnect (h2);
331 if (test == MULTICAST && NULL != h3)
333 GNUNET_MESH_disconnect (h3);
337 if (data_file != NULL)
338 GNUNET_DISK_file_close (data_file);
339 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
344 * Disconnect from mesh services af all peers, call shutdown.
346 * @param cls Closure (unused).
347 * @param tc Task Context.
350 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
353 "disconnecting mesh service of peers\n");
354 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
357 GNUNET_MESH_tunnel_destroy(t);
360 if (NULL != incoming_t)
362 GNUNET_MESH_tunnel_destroy(incoming_t);
365 if (NULL != incoming_t2)
367 GNUNET_MESH_tunnel_destroy(incoming_t2);
370 GNUNET_MESH_disconnect (h1);
371 GNUNET_MESH_disconnect (h2);
373 if (test == MULTICAST)
375 GNUNET_MESH_disconnect (h3);
378 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
380 GNUNET_SCHEDULER_cancel (shutdown_handle);
381 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
387 * Transmit ready callback.
389 * @param cls Closure (message type).
390 * @param size Size of the tranmist buffer.
391 * @param buf Pointer to the beginning of the buffer.
393 * @return Number of bytes written to buf.
396 tmt_rdy (void *cls, size_t size, void *buf);
400 * Task to schedule a new data transmission.
402 * @param cls Closure (peer #).
403 * @param tc Task Context.
406 data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
408 struct GNUNET_MESH_TransmitHandle *th;
409 struct GNUNET_MESH_Tunnel *tunnel;
410 struct GNUNET_PeerIdentity *destination;
412 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
416 if (GNUNET_YES == test_backwards)
419 destination = &d1->id;
424 destination = &d2->id;
426 th = GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
427 GNUNET_TIME_UNIT_FOREVER_REL,
430 &tmt_rdy, (void *) 1L);
433 unsigned long i = (unsigned long) cls;
435 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retransmission\n");
438 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " in 1 ms\n");
439 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
440 &data_task, (void *)1UL);
445 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "in %u ms\n", i);
446 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
447 GNUNET_TIME_UNIT_MILLISECONDS,
449 &data_task, (void *)i);
456 * Transmit ready callback
458 * @param cls Closure (message type).
459 * @param size Size of the buffer we have.
460 * @param buf Buffer to copy data to.
463 tmt_rdy (void *cls, size_t size, void *buf)
465 struct GNUNET_MessageHeader *msg = buf;
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 " tmt_rdy called\n");
470 if (size < size_payload || NULL == buf)
473 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
474 "size %u, buf %p, data_sent %u, data_received %u\n",
481 msg->size = htons (size);
482 msg->type = htons ((long) cls);
483 data = (uint32_t *) &msg[1];
484 *data = htonl (data_sent);
485 if (SPEED == test && GNUNET_YES == initialized)
488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 " Sent packet %d\n", data_sent);
490 if (data_sent < TOTAL_PACKETS)
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 " Scheduling packet %d\n", data_sent + 1);
494 GNUNET_SCHEDULER_add_now(&data_task, NULL);
502 * Function is called whenever a message is received.
504 * @param cls closure (set from GNUNET_MESH_connect)
505 * @param tunnel connection to the other end
506 * @param tunnel_ctx place to store local state associated with the tunnel
507 * @param sender who sent the message
508 * @param message the actual message
509 * @param atsi performance data for the connection
510 * @return GNUNET_OK to keep the connection open,
511 * GNUNET_SYSERR to close it (signal serious error)
514 data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
515 const struct GNUNET_PeerIdentity *sender,
516 const struct GNUNET_MessageHeader *message,
517 const struct GNUNET_ATS_Information *atsi)
519 long client = (long) cls;
520 long expected_target_client;
527 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
529 GNUNET_SCHEDULER_cancel (disconnect_task);
531 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
539 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n");
541 if (test == MULTICAST && peers_responded < 2)
546 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
547 "Leaf client %li got a message.\n",
555 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal);
556 data = (uint32_t *) &message[1];
557 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " payload: (%u)\n", ntohl (*data));
558 if (SPEED == test && GNUNET_YES == test_backwards)
560 expected_target_client = 1L;
564 expected_target_client = 2L;
567 if (GNUNET_NO == initialized)
569 initialized = GNUNET_YES;
570 start_time = GNUNET_TIME_absolute_get ();
573 GNUNET_assert (2L == client);
574 GNUNET_SCHEDULER_add_now (&data_task, NULL);
579 if (client == expected_target_client) // Normally 2 or 3
582 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
583 " received data %u\n", data_received);
584 if (SPEED != test || (ok_goal - 2) == ok)
586 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
587 GNUNET_TIME_UNIT_FOREVER_REL, sender,
589 &tmt_rdy, (void *) 1L);
594 if (data_received < TOTAL_PACKETS)
600 if (test == SPEED_ACK || test == SPEED)
603 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
604 " received ack %u\n", data_ack);
605 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
606 GNUNET_TIME_UNIT_FOREVER_REL, sender,
608 &tmt_rdy, (void *) 1L);
609 if (data_ack < TOTAL_PACKETS && SPEED != test)
611 if (ok == 2 && SPEED == test)
615 GNUNET_MESH_tunnel_destroy (t);
619 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
621 GNUNET_SCHEDULER_cancel (disconnect_task);
623 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
632 * Handlers, for diverse services
634 static struct GNUNET_MESH_MessageHandler handlers[] = {
635 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
641 * Method called whenever another peer has added us to a tunnel
642 * the other peer initiated.
645 * @param tunnel new handle to the tunnel
646 * @param initiator peer that started the tunnel
647 * @param atsi performance information for the tunnel
648 * @return initial tunnel context for the tunnel
649 * (can be NULL -- that's not an error)
652 incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
653 const struct GNUNET_PeerIdentity *initiator,
654 const struct GNUNET_ATS_Information *atsi)
656 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
657 "Incoming tunnel from %s to peer %d\n",
658 GNUNET_i2s (initiator), (long) cls);
660 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
661 if ((long) cls == 2L)
663 else if ((long) cls == 3L)
664 incoming_t2 = tunnel;
667 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
668 "Incoming tunnel for unknown client %lu\n", (long) cls);
671 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
673 GNUNET_SCHEDULER_cancel (disconnect_task);
675 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
682 * Function called whenever an inbound tunnel is destroyed. Should clean up
683 * any associated state.
685 * @param cls closure (set from GNUNET_MESH_connect)
686 * @param tunnel connection to the other end (henceforth invalid)
687 * @param tunnel_ctx place where local state associated
688 * with the tunnel is stored
691 tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
696 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
697 "Incoming tunnel disconnected at peer %d\n",
710 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
711 "Unknown peer! %d\n", i);
712 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
714 if (peers_in_tunnel > 0)
717 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
719 GNUNET_SCHEDULER_cancel (disconnect_task);
720 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
728 * Method called whenever a tunnel falls apart.
731 * @param peer peer identity the tunnel stopped working with
734 dh (void *cls, const struct GNUNET_PeerIdentity *peer)
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "peer %s disconnected\n",
744 * Method called whenever a peer connects to a tunnel.
747 * @param peer peer identity the tunnel was created to, NULL on timeout
748 * @param atsi performance data for the connection
751 ch (void *cls, const struct GNUNET_PeerIdentity *peer,
752 const struct GNUNET_ATS_Information *atsi)
754 struct GNUNET_PeerIdentity *dest;
756 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
757 "peer %s connected\n", GNUNET_i2s (peer));
759 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
763 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
768 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
774 // incoming_t is NULL unless we send a relevant data packet
779 if (peers_in_tunnel < 2)
787 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
789 GNUNET_SCHEDULER_cancel (disconnect_task);
791 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
793 "Sending data initializer...\n");
798 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
799 GNUNET_TIME_UNIT_FOREVER_REL, dest,
801 &tmt_rdy, (void *) 1L);
805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
806 "Disconnect already run?\n");
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
815 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
817 * Testcase continues when the root receives confirmation of connected peers,
818 * on callback funtion ch.
820 * @param cls Closure (unsued).
821 * @param tc Task Context.
824 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
828 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
830 if (test == MULTICAST)
832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
834 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
838 "schedule timeout in TIMEOUT\n");
839 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
841 GNUNET_SCHEDULER_cancel (disconnect_task);
843 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &disconnect_mesh_peers, NULL);
849 * connect_mesh_service: connect to the mesh service of one of the peers
851 * @param cls Closure (unsued).
852 * @param tc Task Context.
855 connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
857 GNUNET_MESH_ApplicationType app;
859 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
863 "connect_mesh_service\n");
865 d2 = GNUNET_TESTING_daemon_get (pg, num_peers - 1);
866 if (test == MULTICAST)
868 d3 = GNUNET_TESTING_daemon_get (pg, num_peers - 2);
870 app = (GNUNET_MESH_ApplicationType) 0;
872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
873 "connecting to mesh service of peer %s\n",
874 GNUNET_i2s (&d1->id));
875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
876 "connecting to mesh service of peer %s\n",
877 GNUNET_i2s (&d2->id));
878 if (test == MULTICAST)
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
881 "connecting to mesh service of peer %s\n",
882 GNUNET_i2s (&d3->id));
884 h1 = GNUNET_MESH_connect (d1->cfg, (void *) 1L, NULL, &tunnel_cleaner,
886 h2 = GNUNET_MESH_connect (d2->cfg, (void *) 2L, &incoming_tunnel,
887 &tunnel_cleaner, handlers, &app);
888 if (test == MULTICAST)
890 h3 = GNUNET_MESH_connect (d3->cfg, (void *) 3L, &incoming_tunnel,
891 &tunnel_cleaner, handlers, &app);
893 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
894 if (SPEED_MIN == test)
896 GNUNET_MESH_tunnel_speed_min(t);
899 if (SPEED_NOBUF == test)
901 GNUNET_MESH_tunnel_buffer(t, GNUNET_NO);
906 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
907 (GNUNET_TIME_UNIT_SECONDS, 1), &do_test,
914 * peergroup_ready: start test when all peers are connected
917 * @param emsg error message
920 peergroup_ready (void *cls, const char *emsg)
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
929 "Peergroup callback called with error, aborting test!\n");
930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
931 "Error from testing: `%s'\n", emsg);
933 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
937 "Peer Group started successfully with %u connections\n",
939 if (data_file != NULL)
942 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
944 GNUNET_DISK_file_write (data_file, buf, buf_len);
947 peers_running = GNUNET_TESTING_daemons_running (pg);
948 for (i = 0; i < num_peers; i++)
950 GNUNET_PEER_Id peer_id;
952 d1 = GNUNET_TESTING_daemon_get (pg, i);
953 peer_id = GNUNET_PEER_intern (&d1->id);
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n",
955 peer_id, GNUNET_i2s (&d1->id));
957 d1 = GNUNET_TESTING_daemon_get (pg, 0);
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
959 "Peer looking: %s\n",
960 GNUNET_i2s (&d1->id));
962 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
964 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
970 * Function that will be called whenever two daemons are connected by
971 * the testing library.
974 * @param first peer id for first daemon
975 * @param second peer id for the second daemon
976 * @param distance distance between the connected peers
977 * @param first_cfg config for the first daemon
978 * @param second_cfg config for the second daemon
979 * @param first_daemon handle for the first daemon
980 * @param second_daemon handle for the second daemon
981 * @param emsg error message (NULL on success)
984 connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
985 const struct GNUNET_PeerIdentity *second, uint32_t distance,
986 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
987 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
988 struct GNUNET_TESTING_Daemon *first_daemon,
989 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
998 "Problem with new connection (%s)\n",
1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (first));
1001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (second));
1008 * run: load configuration options and schedule test to run (start peergroup)
1010 * @param cls closure
1012 * @param cfgfile configuration file name (can be NULL)
1013 * @param cfg configuration handle
1016 run (void *cls, char *const *args, const char *cfgfile,
1017 const struct GNUNET_CONFIGURATION_Handle *cfg)
1020 struct GNUNET_TESTING_Host *hosts;
1021 char *data_filename;
1024 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
1026 GNUNET_log_setup ("test_mesh_small",
1030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1031 "Starting daemons.\n");
1033 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing_old",
1034 "num_peers", &num_peers))
1036 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1037 "Option TESTING:NUM_PEERS is required!\n");
1042 GNUNET_CONFIGURATION_get_value_time (testing_cfg, "test_mesh_small",
1043 "WAIT_TIME", &wait_time))
1045 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1046 "Option test_mesh_small:wait_time is required!\n");
1051 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing_old",
1052 "topology_output_file",
1055 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1056 "Option test_mesh_small:topology_output_file is required!\n");
1061 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
1066 GNUNET_DISK_file_open (data_filename,
1067 GNUNET_DISK_OPEN_READWRITE |
1068 GNUNET_DISK_OPEN_CREATE,
1069 GNUNET_DISK_PERM_USER_READ |
1070 GNUNET_DISK_PERM_USER_WRITE);
1071 if (data_file == NULL)
1073 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1075 GNUNET_free (data_filename);
1080 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
1081 "output_file", &temp_str))
1084 GNUNET_DISK_file_open (temp_str,
1085 GNUNET_DISK_OPEN_READWRITE |
1086 GNUNET_DISK_OPEN_CREATE,
1087 GNUNET_DISK_PERM_USER_READ |
1088 GNUNET_DISK_PERM_USER_WRITE);
1089 if (output_file == NULL)
1090 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1093 GNUNET_free_non_null (temp_str);
1095 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
1097 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
1098 &connect_cb, &peergroup_ready, NULL,
1100 GNUNET_assert (pg != NULL);
1102 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1103 &shutdown_task, NULL);
1109 * test_mesh_small command line options
1111 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1112 {'V', "verbose", NULL,
1113 gettext_noop ("be verbose (print progress information)"),
1114 0, &GNUNET_GETOPT_set_one, &verbose},
1115 GNUNET_GETOPT_OPTION_END
1123 main (int argc, char *argv[])
1128 "test_mesh_small.conf",
1131 int argc2 = (sizeof (argv2) / sizeof (char *)) - 1;
1133 initialized = GNUNET_NO;
1135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n");
1136 if (strstr (argv[0], "test_mesh_small_unicast") != NULL)
1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNICAST\n");
1140 test_name = "unicast";
1143 else if (strstr (argv[0], "test_mesh_small_multicast") != NULL)
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MULTICAST\n");
1147 test_name = "multicast";
1150 else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
1152 /* Each peer is supposed to generate the following callbacks:
1153 * 1 incoming tunnel (@dest)
1154 * 1 connected peer (@orig)
1155 * TOTAL_PACKETS received data packet (@dest)
1156 * TOTAL_PACKETS received data packet (@orig)
1157 * 1 received tunnel destroy (@dest)
1158 * _________________________________
1159 * 5 x ok expected per peer
1161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1163 test_name = "speed ack";
1164 ok_goal = TOTAL_PACKETS * 2 + 3;
1165 argv2 [3] = NULL; // remove -L DEBUG
1167 else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
1169 /* Each peer is supposed to generate the following callbacks:
1170 * 1 incoming tunnel (@dest)
1171 * 1 connected peer (@orig)
1172 * 1 initial packet (@dest)
1173 * TOTAL_PACKETS received data packet (@dest)
1174 * 1 received data packet (@orig)
1175 * 1 received tunnel destroy (@dest)
1176 * _________________________________
1178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1179 ok_goal = TOTAL_PACKETS + 5;
1180 if (strstr (argv[0], "_min") != NULL)
1183 test_name = "speed min";
1185 else if (strstr (argv[0], "_nobuf") != NULL)
1188 test_name = "speed nobuf";
1193 test_name = "speed";
1198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1203 if (strstr (argv[0], "backwards") != NULL)
1207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1208 test_backwards = GNUNET_YES;
1209 aux = malloc (32); // "leaked"
1210 sprintf (aux, "backwards %s", test_name);
1214 GNUNET_PROGRAM_run (argc2, argv2,
1216 gettext_noop ("Test mesh in a small network."), options,
1219 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
1223 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1224 "FAILED! (%d/%d)\n", ok, ok_goal);
1227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1231 /* end of test_mesh_small.c */