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 VERBOSE GNUNET_YES
33 #define REMOVE_DIR GNUNET_YES
37 struct MeshPeer *prev;
39 struct MeshPeer *next;
41 struct GNUNET_TESTING_Daemon *daemon;
43 struct GNUNET_MESH_Handle *mesh_handle;
48 * How long until we give up on connecting the peers?
50 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
53 * Time to wait for stuff that should be rather fast
55 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
58 * DIFFERENT TESTS TO RUN
69 * Which test are we running?
74 * Flag to send traffic leaf->root in speed tests to test BCK_ACK logic.
76 static int test_backwards = GNUNET_NO;
79 * How many events have happened
84 * Peers that have been connected
86 static int peers_in_tunnel;
89 * Peers that have responded
91 static int peers_responded;
94 * Number of payload packes sent
99 * Number of payload packets received
101 static int data_received;
104 * Number of payload packed explicitly (app/level) acknowledged
114 * Total number of peers in the test.
116 static unsigned long long num_peers;
119 * Global configuration file
121 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
124 * Total number of currently running peers.
126 static unsigned long long peers_running;
129 * Total number of connections in the whole network.
131 static unsigned int total_connections;
134 * The currently running peer group.
136 static struct GNUNET_TESTING_PeerGroup *pg;
139 * File to report results to.
141 static struct GNUNET_DISK_FileHandle *output_file;
144 * File to log connection info, statistics to.
146 static struct GNUNET_DISK_FileHandle *data_file;
151 static struct GNUNET_TIME_Relative wait_time;
154 * Task called to disconnect peers.
156 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
159 * Task To perform tests
161 static GNUNET_SCHEDULER_TaskIdentifier test_task;
164 * Task called to shutdown test.
166 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
168 static char *topology_file;
170 static struct GNUNET_TESTING_Daemon *d1;
172 static GNUNET_PEER_Id pid1;
174 static struct GNUNET_TESTING_Daemon *d2;
176 static struct GNUNET_TESTING_Daemon *d3;
178 static struct GNUNET_MESH_Handle *h1;
180 static struct GNUNET_MESH_Handle *h2;
182 static struct GNUNET_MESH_Handle *h3;
184 static struct GNUNET_MESH_Tunnel *t;
186 static struct GNUNET_MESH_Tunnel *incoming_t;
188 static struct GNUNET_MESH_Tunnel *incoming_t2;
190 static struct GNUNET_TIME_Absolute start_time;
192 static struct GNUNET_TIME_Absolute end_time;
194 static struct GNUNET_TIME_Relative total_time;
198 * Check whether peers successfully shut down.
201 shutdown_callback (void *cls, const char *emsg)
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Shutdown of peers failed!\n");
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "All peers successfully shut down!\n");
218 GNUNET_CONFIGURATION_destroy (testing_cfg);
223 * Shut down peergroup, clean up.
226 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
235 GNUNET_SCHEDULER_cancel (disconnect_task);
236 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
241 GNUNET_MESH_disconnect (h1);
246 GNUNET_MESH_disconnect (h2);
249 if (test == MULTICAST && NULL != h3)
251 GNUNET_MESH_disconnect (h3);
255 if (data_file != NULL)
256 GNUNET_DISK_file_close (data_file);
257 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
262 * Disconnect from mesh services af all peers, call shutdown.
265 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "disconnecting mesh service of peers\n");
269 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
272 GNUNET_MESH_tunnel_destroy(t);
275 if (NULL != incoming_t)
277 GNUNET_MESH_tunnel_destroy(incoming_t);
280 if (NULL != incoming_t2)
282 GNUNET_MESH_tunnel_destroy(incoming_t2);
285 GNUNET_MESH_disconnect (h1);
286 GNUNET_MESH_disconnect (h2);
288 if (test == MULTICAST)
290 GNUNET_MESH_disconnect (h3);
293 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
295 GNUNET_SCHEDULER_cancel (shutdown_handle);
296 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
301 tmt_rdy (void *cls, size_t size, void *buf);
304 data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
306 struct GNUNET_MESH_TransmitHandle *th;
307 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
309 th = GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
310 GNUNET_TIME_UNIT_FOREVER_REL, &d2->id,
311 sizeof (struct GNUNET_MessageHeader),
312 &tmt_rdy, (void *) 1L);
315 unsigned long i = (unsigned long) cls;
317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retransmission\n");
320 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " in 1 ms\n");
321 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
322 &data_task, (void *)1UL);
327 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "in %u ms\n", i);
328 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
329 GNUNET_TIME_UNIT_MILLISECONDS,
331 &data_task, (void *)i);
337 * Transmit ready callback
339 * @param cls Closure.
340 * @param size Size of the buffer we have.
341 * @param buf Buffer to copy data to.
344 tmt_rdy (void *cls, size_t size, void *buf)
346 struct GNUNET_MessageHeader *msg = buf;
348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
349 " tmt_rdy called\n");
350 if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf)
352 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
353 msg->type = htons ((long) cls);
357 if (data_sent < 1000)
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
360 " Scheduling %d packet\n", data_sent);
361 GNUNET_SCHEDULER_add_now(&data_task, NULL);
364 return sizeof (struct GNUNET_MessageHeader);
369 * Function is called whenever a message is received.
371 * @param cls closure (set from GNUNET_MESH_connect)
372 * @param tunnel connection to the other end
373 * @param tunnel_ctx place to store local state associated with the tunnel
374 * @param sender who sent the message
375 * @param message the actual message
376 * @param atsi performance data for the connection
377 * @return GNUNET_OK to keep the connection open,
378 * GNUNET_SYSERR to close it (signal serious error)
381 data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
382 const struct GNUNET_PeerIdentity *sender,
383 const struct GNUNET_MessageHeader *message,
384 const struct GNUNET_ATS_Information *atsi)
386 long client = (long) cls;
391 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Origin client got a response!\n");
393 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
396 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
398 GNUNET_SCHEDULER_cancel (disconnect_task);
400 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
403 if (test == MULTICAST && peers_responded < 2)
405 if (test == SPEED_ACK || test == SPEED)
407 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
408 " received ack %u\n", data_ack);
409 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
410 GNUNET_TIME_UNIT_FOREVER_REL, sender,
411 sizeof (struct GNUNET_MessageHeader),
412 &tmt_rdy, (void *) 1L);
413 if (data_ack < 1000 && test != SPEED)
415 end_time = GNUNET_TIME_absolute_get();
416 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
417 FPRINTF (stderr, "\nTest time %llu ms\n",
418 (unsigned long long) total_time.rel_value);
419 FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
420 4 * 1000.0 / total_time.rel_value); // 4bytes * ms
421 FPRINTF (stderr, "Test throughput: %f packets/s\n\n",
422 1000.0 * 1000.0 / total_time.rel_value); // 1000 packets * ms
423 GAUGER ("MESH", "Tunnel 5 peers", 1000.0 * 1000.0 / total_time.rel_value,
426 GNUNET_assert (tunnel == t);
427 GNUNET_MESH_tunnel_destroy (t);
432 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
433 "Destination client %u got a message.\n",
436 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
437 if (SPEED != test || 1002 == ok)
439 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
440 GNUNET_TIME_UNIT_FOREVER_REL, sender,
441 sizeof (struct GNUNET_MessageHeader),
442 &tmt_rdy, (void *) 1L);
447 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
448 " received data %u\n", data_received);
449 if (data_received < 1000)
452 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
454 GNUNET_SCHEDULER_cancel (disconnect_task);
456 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
468 * Handlers, for diverse services
470 static struct GNUNET_MESH_MessageHandler handlers[] = {
471 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
477 * Method called whenever another peer has added us to a tunnel
478 * the other peer initiated.
481 * @param tunnel new handle to the tunnel
482 * @param initiator peer that started the tunnel
483 * @param atsi performance information for the tunnel
484 * @return initial tunnel context for the tunnel
485 * (can be NULL -- that's not an error)
488 incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
489 const struct GNUNET_PeerIdentity *initiator,
490 const struct GNUNET_ATS_Information *atsi)
492 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
493 "Incoming tunnel from %s to peer %d\n",
494 GNUNET_i2s (initiator), (long) cls);
496 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
497 if ((long) cls == 2L)
499 else if ((long) cls == 3L)
500 incoming_t2 = tunnel;
503 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
504 "Incoming tunnel for unknown client %lu\n", (long) cls);
506 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
508 GNUNET_SCHEDULER_cancel (disconnect_task);
510 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
516 * Function called whenever an inbound tunnel is destroyed. Should clean up
517 * any associated state.
519 * @param cls closure (set from GNUNET_MESH_connect)
520 * @param tunnel connection to the other end (henceforth invalid)
521 * @param tunnel_ctx place where local state associated
522 * with the tunnel is stored
525 tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
530 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
531 "Incoming tunnel disconnected at peer %d\n",
544 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
545 "Unknown peer! %d\n", i);
546 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
548 if (peers_in_tunnel > 0)
551 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
553 GNUNET_SCHEDULER_cancel (disconnect_task);
554 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
562 * Method called whenever a tunnel falls apart.
565 * @param peer peer identity the tunnel stopped working with
568 dh (void *cls, const struct GNUNET_PeerIdentity *peer)
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
571 "peer %s disconnected\n",
578 * Method called whenever a peer connects to a tunnel.
581 * @param peer peer identity the tunnel was created to, NULL on timeout
582 * @param atsi performance data for the connection
585 ch (void *cls, const struct GNUNET_PeerIdentity *peer,
586 const struct GNUNET_ATS_Information *atsi)
588 struct GNUNET_PeerIdentity *dest;
590 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
591 "peer %s connected\n", GNUNET_i2s (peer));
593 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
597 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
602 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
612 if (peers_in_tunnel < 2)
619 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
621 GNUNET_SCHEDULER_cancel (disconnect_task);
623 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
625 "Sending data...\n");
630 start_time = GNUNET_TIME_absolute_get();
631 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
632 GNUNET_TIME_UNIT_FOREVER_REL, dest,
633 sizeof (struct GNUNET_MessageHeader),
634 &tmt_rdy, (void *) 1L);
638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
639 "Disconnect already run?\n");
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
651 if (test == MULTICAST)
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
655 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
658 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
660 "schedule timeout in SHORT_TIME\n");
661 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
663 GNUNET_SCHEDULER_cancel (disconnect_task);
665 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
671 * connect_mesh_service: connect to the mesh service of one of the peers
675 connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
677 GNUNET_MESH_ApplicationType app;
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "connect_mesh_service\n");
682 d2 = GNUNET_TESTING_daemon_get (pg, 4);
683 if (test == MULTICAST)
685 d3 = GNUNET_TESTING_daemon_get (pg, 3);
687 app = (GNUNET_MESH_ApplicationType) 0;
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "connecting to mesh service of peer %s\n",
692 GNUNET_i2s (&d1->id));
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
694 "connecting to mesh service of peer %s\n",
695 GNUNET_i2s (&d2->id));
696 if (test == MULTICAST)
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "connecting to mesh service of peer %s\n",
700 GNUNET_i2s (&d3->id));
703 h1 = GNUNET_MESH_connect (d1->cfg, (void *) 1L, NULL, &tunnel_cleaner,
705 h2 = GNUNET_MESH_connect (d2->cfg, (void *) 2L, &incoming_tunnel,
706 &tunnel_cleaner, handlers, &app);
707 if (test == MULTICAST)
709 h3 = GNUNET_MESH_connect (d3->cfg, (void *) 3L, &incoming_tunnel,
710 &tunnel_cleaner, handlers, &app);
712 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
713 if (SPEED_MIN == test)
715 GNUNET_MESH_tunnel_speed_min(t);
718 if (SPEED_NOBUF == test)
720 GNUNET_MESH_tunnel_buffer(t, GNUNET_NO);
725 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
726 (GNUNET_TIME_UNIT_SECONDS, 1), &do_test,
733 * peergroup_ready: start test when all peers are connected
735 * @param emsg error message
738 peergroup_ready (void *cls, const char *emsg)
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
747 "Peergroup callback called with error, aborting test!\n");
748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
749 "Error from testing: `%s'\n", emsg);
751 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 "************************************************************\n");
757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
758 "Peer Group started successfully!\n");
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
760 "Have %u connections\n",
764 if (data_file != NULL)
767 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
769 GNUNET_DISK_file_write (data_file, buf, buf_len);
772 peers_running = GNUNET_TESTING_daemons_running (pg);
773 for (i = 0; i < num_peers; i++)
775 GNUNET_PEER_Id peer_id;
777 d1 = GNUNET_TESTING_daemon_get (pg, i);
778 peer_id = GNUNET_PEER_intern (&d1->id);
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n",
780 peer_id, GNUNET_i2s (&d1->id));
782 d1 = GNUNET_TESTING_daemon_get (pg, 0);
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
784 "Peer looking: %s\n",
785 GNUNET_i2s (&d1->id));
786 pid1 = GNUNET_PEER_intern (&d1->id);
788 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
790 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
796 * Function that will be called whenever two daemons are connected by
797 * the testing library.
800 * @param first peer id for first daemon
801 * @param second peer id for the second daemon
802 * @param distance distance between the connected peers
803 * @param first_cfg config for the first daemon
804 * @param second_cfg config for the second daemon
805 * @param first_daemon handle for the first daemon
806 * @param second_daemon handle for the second daemon
807 * @param emsg error message (NULL on success)
810 connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
811 const struct GNUNET_PeerIdentity *second, uint32_t distance,
812 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
813 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
814 struct GNUNET_TESTING_Daemon *first_daemon,
815 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
824 "Problem with new connection (%s)\n",
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (first));
827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (second));
834 * run: load configuration options and schedule test to run (start peergroup)
837 * @param cfgfile configuration file name (can be NULL)
838 * @param cfg configuration handle
841 run (void *cls, char *const *args, const char *cfgfile,
842 const struct GNUNET_CONFIGURATION_Handle *cfg)
845 struct GNUNET_TESTING_Host *hosts;
849 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
851 GNUNET_log_setup ("test_mesh_small",
860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
861 "Starting daemons.\n");
862 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing_old",
863 "use_progressbars", "YES");
867 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing_old",
868 "num_peers", &num_peers))
870 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
871 "Option TESTING:NUM_PEERS is required!\n");
876 GNUNET_CONFIGURATION_get_value_time (testing_cfg, "test_mesh_small",
877 "WAIT_TIME", &wait_time))
879 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
880 "Option test_mesh_small:wait_time is required!\n");
885 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing_old",
886 "topology_output_file",
889 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
890 "Option test_mesh_small:topology_output_file is required!\n");
895 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
900 GNUNET_DISK_file_open (data_filename,
901 GNUNET_DISK_OPEN_READWRITE |
902 GNUNET_DISK_OPEN_CREATE,
903 GNUNET_DISK_PERM_USER_READ |
904 GNUNET_DISK_PERM_USER_WRITE);
905 if (data_file == NULL)
907 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
909 GNUNET_free (data_filename);
914 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
915 "output_file", &temp_str))
918 GNUNET_DISK_file_open (temp_str,
919 GNUNET_DISK_OPEN_READWRITE |
920 GNUNET_DISK_OPEN_CREATE,
921 GNUNET_DISK_PERM_USER_READ |
922 GNUNET_DISK_PERM_USER_WRITE);
923 if (output_file == NULL)
924 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
927 GNUNET_free_non_null (temp_str);
929 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
931 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
932 &connect_cb, &peergroup_ready, NULL,
934 GNUNET_assert (pg != NULL);
936 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
937 &shutdown_task, NULL);
943 * test_mesh_small command line options
945 static struct GNUNET_GETOPT_CommandLineOption options[] = {
946 {'V', "verbose", NULL,
947 gettext_noop ("be verbose (print progress information)"),
948 0, &GNUNET_GETOPT_set_one, &verbose},
949 GNUNET_GETOPT_OPTION_END
957 main (int argc, char *argv[])
962 "test_mesh_small.conf",
969 int argc2 = (sizeof (argv2) / sizeof (char *)) - 1;
971 /* Each peer is supposed to generate the following callbacks:
972 * 1 incoming tunnel (@dest)
973 * 1 connected peer (@orig)
974 * 1 received data packet (@dest)
975 * 1 received data packet (@orig)
976 * 1 received tunnel destroy (@dest)
977 * _________________________________
978 * 5 x ok expected per peer
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n");
983 if (strstr (argv[0], "test_mesh_small_unicast") != NULL)
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNICAST\n");
989 else if (strstr (argv[0], "test_mesh_small_multicast") != NULL)
991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MULTICAST\n");
995 else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
997 /* Each peer is supposed to generate the following callbacks:
998 * 1 incoming tunnel (@dest)
999 * 1 connected peer (@orig)
1000 * 1000 received data packet (@dest)
1001 * 1000 received data packet (@orig)
1002 * 1 received tunnel destroy (@dest)
1003 * _________________________________
1004 * 5 x ok expected per peer
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1009 argv2 [3] = NULL; // remove -L DEBUG
1014 else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
1016 /* Each peer is supposed to generate the following callbacks:
1017 * 1 incoming tunnel (@dest)
1018 * 1 connected peer (@orig)
1019 * 1000 received data packet (@dest)
1020 * 1received data packet (@orig)
1021 * 1 received tunnel destroy (@dest)
1022 * _________________________________
1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1026 if (strstr (argv[0], "_min") != NULL)
1028 else if (strstr (argv[0], "_nobuf") != NULL)
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1040 if (strstr (argv[0], "backwards") != NULL)
1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1043 test_backwards = GNUNET_YES;
1046 GNUNET_PROGRAM_run (argc2, argv2,
1048 gettext_noop ("Test mesh in a small network."), options,
1051 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
1055 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1056 "FAILED! (%d/%d)\n", ok, ok_goal);
1059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1063 /* end of test_mesh_small.c */