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 * How many events have happened
78 static int peers_in_tunnel;
80 static int peers_responded;
84 static int data_received;
94 * Total number of peers in the test.
96 static unsigned long long num_peers;
99 * Global configuration file
101 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
104 * Total number of currently running peers.
106 static unsigned long long peers_running;
109 * Total number of connections in the whole network.
111 static unsigned int total_connections;
114 * The currently running peer group.
116 static struct GNUNET_TESTING_PeerGroup *pg;
119 * File to report results to.
121 static struct GNUNET_DISK_FileHandle *output_file;
124 * File to log connection info, statistics to.
126 static struct GNUNET_DISK_FileHandle *data_file;
131 static struct GNUNET_TIME_Relative wait_time;
134 * Task called to disconnect peers.
136 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
139 * Task To perform tests
141 static GNUNET_SCHEDULER_TaskIdentifier test_task;
144 * Task called to shutdown test.
146 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
148 static char *topology_file;
150 static struct GNUNET_TESTING_Daemon *d1;
152 static GNUNET_PEER_Id pid1;
154 static struct GNUNET_TESTING_Daemon *d2;
156 static struct GNUNET_TESTING_Daemon *d3;
158 static struct GNUNET_MESH_Handle *h1;
160 static struct GNUNET_MESH_Handle *h2;
162 static struct GNUNET_MESH_Handle *h3;
164 static struct GNUNET_MESH_Tunnel *t;
166 static struct GNUNET_MESH_Tunnel *incoming_t;
168 static struct GNUNET_MESH_Tunnel *incoming_t2;
170 static struct GNUNET_TIME_Absolute start_time;
172 static struct GNUNET_TIME_Absolute end_time;
174 static struct GNUNET_TIME_Relative total_time;
178 * Check whether peers successfully shut down.
181 shutdown_callback (void *cls, const char *emsg)
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Shutdown of peers failed!\n");
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "All peers successfully shut down!\n");
198 GNUNET_CONFIGURATION_destroy (testing_cfg);
203 * Shut down peergroup, clean up.
206 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
215 GNUNET_SCHEDULER_cancel (disconnect_task);
216 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
221 GNUNET_MESH_disconnect (h1);
226 GNUNET_MESH_disconnect (h2);
229 if (test == MULTICAST && NULL != h3)
231 GNUNET_MESH_disconnect (h3);
235 if (data_file != NULL)
236 GNUNET_DISK_file_close (data_file);
237 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
242 * Disconnect from mesh services af all peers, call shutdown.
245 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
248 "disconnecting mesh service of peers\n");
249 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
252 GNUNET_MESH_tunnel_destroy(t);
255 if (NULL != incoming_t)
257 GNUNET_MESH_tunnel_destroy(incoming_t);
260 if (NULL != incoming_t2)
262 GNUNET_MESH_tunnel_destroy(incoming_t2);
265 GNUNET_MESH_disconnect (h1);
266 GNUNET_MESH_disconnect (h2);
268 if (test == MULTICAST)
270 GNUNET_MESH_disconnect (h3);
273 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
275 GNUNET_SCHEDULER_cancel (shutdown_handle);
276 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
281 tmt_rdy (void *cls, size_t size, void *buf);
284 data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
286 struct GNUNET_MESH_TransmitHandle *th;
287 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
289 th = GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
290 GNUNET_TIME_UNIT_FOREVER_REL, &d2->id,
291 sizeof (struct GNUNET_MessageHeader),
292 &tmt_rdy, (void *) 1L);
295 unsigned long i = (unsigned long) cls;
297 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retransmission\n");
300 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " in 1 ms\n");
301 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
302 &data_task, (void *)1UL);
307 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "in %u ms\n", i);
308 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
309 GNUNET_TIME_UNIT_MILLISECONDS,
311 &data_task, (void *)i);
317 * Transmit ready callback
319 * @param cls Closure.
320 * @param size Size of the buffer we have.
321 * @param buf Buffer to copy data to.
324 tmt_rdy (void *cls, size_t size, void *buf)
326 struct GNUNET_MessageHeader *msg = buf;
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 " tmt_rdy called\n");
330 if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf)
332 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
333 msg->type = htons ((long) cls);
337 if (data_sent < 1000)
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 " Scheduling %d packet\n", data_sent);
341 GNUNET_SCHEDULER_add_now(&data_task, NULL);
344 return sizeof (struct GNUNET_MessageHeader);
349 * Function is called whenever a message is received.
351 * @param cls closure (set from GNUNET_MESH_connect)
352 * @param tunnel connection to the other end
353 * @param tunnel_ctx place to store local state associated with the tunnel
354 * @param sender who sent the message
355 * @param message the actual message
356 * @param atsi performance data for the connection
357 * @return GNUNET_OK to keep the connection open,
358 * GNUNET_SYSERR to close it (signal serious error)
361 data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
362 const struct GNUNET_PeerIdentity *sender,
363 const struct GNUNET_MessageHeader *message,
364 const struct GNUNET_ATS_Information *atsi)
366 long client = (long) cls;
371 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Origin client got a response!\n");
373 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
376 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
378 GNUNET_SCHEDULER_cancel (disconnect_task);
380 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
383 if (test == MULTICAST && peers_responded < 2)
385 if (test == SPEED_ACK || test == SPEED)
387 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
388 " received ack %u\n", data_ack);
389 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
390 GNUNET_TIME_UNIT_FOREVER_REL, sender,
391 sizeof (struct GNUNET_MessageHeader),
392 &tmt_rdy, (void *) 1L);
393 if (data_ack < 1000 && test != SPEED)
395 end_time = GNUNET_TIME_absolute_get();
396 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
397 FPRINTF (stderr, "\nTest time %llu ms\n",
398 (unsigned long long) total_time.rel_value);
399 FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
400 4 * 1000.0 / total_time.rel_value); // 4bytes * ms
401 FPRINTF (stderr, "Test throughput: %f packets/s\n\n",
402 1000.0 * 1000.0 / total_time.rel_value); // 1000 packets * ms
403 GAUGER ("MESH", "Tunnel 5 peers", 1000.0 * 1000.0 / total_time.rel_value,
406 GNUNET_assert (tunnel == t);
407 GNUNET_MESH_tunnel_destroy (t);
412 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
413 "Destination client %u got a message.\n",
416 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
417 if (SPEED != test || 1002 == ok)
419 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
420 GNUNET_TIME_UNIT_FOREVER_REL, sender,
421 sizeof (struct GNUNET_MessageHeader),
422 &tmt_rdy, (void *) 1L);
427 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
428 " received data %u\n", data_received);
429 if (data_received < 1000)
432 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
434 GNUNET_SCHEDULER_cancel (disconnect_task);
436 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
448 * Handlers, for diverse services
450 static struct GNUNET_MESH_MessageHandler handlers[] = {
451 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
457 * Method called whenever another peer has added us to a tunnel
458 * the other peer initiated.
461 * @param tunnel new handle to the tunnel
462 * @param initiator peer that started the tunnel
463 * @param atsi performance information for the tunnel
464 * @return initial tunnel context for the tunnel
465 * (can be NULL -- that's not an error)
468 incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
469 const struct GNUNET_PeerIdentity *initiator,
470 const struct GNUNET_ATS_Information *atsi)
472 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
473 "Incoming tunnel from %s to peer %d\n",
474 GNUNET_i2s (initiator), (long) cls);
476 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
477 if ((long) cls == 2L)
479 else if ((long) cls == 3L)
480 incoming_t2 = tunnel;
483 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
484 "Incoming tunnel for unknown client %lu\n", (long) cls);
486 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
488 GNUNET_SCHEDULER_cancel (disconnect_task);
490 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
496 * Function called whenever an inbound tunnel is destroyed. Should clean up
497 * any associated state.
499 * @param cls closure (set from GNUNET_MESH_connect)
500 * @param tunnel connection to the other end (henceforth invalid)
501 * @param tunnel_ctx place where local state associated
502 * with the tunnel is stored
505 tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
510 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
511 "Incoming tunnel disconnected at peer %d\n",
524 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
525 "Unknown peer! %d\n", i);
526 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
528 if (peers_in_tunnel > 0)
531 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
533 GNUNET_SCHEDULER_cancel (disconnect_task);
534 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
542 * Method called whenever a tunnel falls apart.
545 * @param peer peer identity the tunnel stopped working with
548 dh (void *cls, const struct GNUNET_PeerIdentity *peer)
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
551 "peer %s disconnected\n",
558 * Method called whenever a peer connects to a tunnel.
561 * @param peer peer identity the tunnel was created to, NULL on timeout
562 * @param atsi performance data for the connection
565 ch (void *cls, const struct GNUNET_PeerIdentity *peer,
566 const struct GNUNET_ATS_Information *atsi)
568 struct GNUNET_PeerIdentity *dest;
570 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
571 "peer %s connected\n", GNUNET_i2s (peer));
573 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
577 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
582 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
592 if (peers_in_tunnel < 2)
599 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
601 GNUNET_SCHEDULER_cancel (disconnect_task);
603 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
605 "Sending data...\n");
610 start_time = GNUNET_TIME_absolute_get();
611 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
612 GNUNET_TIME_UNIT_FOREVER_REL, dest,
613 sizeof (struct GNUNET_MessageHeader),
614 &tmt_rdy, (void *) 1L);
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
619 "Disconnect already run?\n");
620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
628 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
631 if (test == MULTICAST)
633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
635 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
638 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
640 "schedule timeout in SHORT_TIME\n");
641 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
643 GNUNET_SCHEDULER_cancel (disconnect_task);
645 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
651 * connect_mesh_service: connect to the mesh service of one of the peers
655 connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
657 GNUNET_MESH_ApplicationType app;
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
660 "connect_mesh_service\n");
662 d2 = GNUNET_TESTING_daemon_get (pg, 4);
663 if (test == MULTICAST)
665 d3 = GNUNET_TESTING_daemon_get (pg, 3);
667 app = (GNUNET_MESH_ApplicationType) 0;
670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
671 "connecting to mesh service of peer %s\n",
672 GNUNET_i2s (&d1->id));
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
674 "connecting to mesh service of peer %s\n",
675 GNUNET_i2s (&d2->id));
676 if (test == MULTICAST)
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
679 "connecting to mesh service of peer %s\n",
680 GNUNET_i2s (&d3->id));
683 h1 = GNUNET_MESH_connect (d1->cfg, (void *) 1L, NULL, &tunnel_cleaner,
685 h2 = GNUNET_MESH_connect (d2->cfg, (void *) 2L, &incoming_tunnel,
686 &tunnel_cleaner, handlers, &app);
687 if (test == MULTICAST)
689 h3 = GNUNET_MESH_connect (d3->cfg, (void *) 3L, &incoming_tunnel,
690 &tunnel_cleaner, handlers, &app);
692 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
693 if (SPEED_MIN == test)
695 GNUNET_MESH_tunnel_speed_min(t);
698 if (SPEED_NOBUF == test)
700 GNUNET_MESH_tunnel_buffer(t, GNUNET_NO);
705 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
706 (GNUNET_TIME_UNIT_SECONDS, 1), &do_test,
713 * peergroup_ready: start test when all peers are connected
715 * @param emsg error message
718 peergroup_ready (void *cls, const char *emsg)
726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
727 "Peergroup callback called with error, aborting test!\n");
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
729 "Error from testing: `%s'\n", emsg);
731 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "************************************************************\n");
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Peer Group started successfully!\n");
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
740 "Have %u connections\n",
744 if (data_file != NULL)
747 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
749 GNUNET_DISK_file_write (data_file, buf, buf_len);
752 peers_running = GNUNET_TESTING_daemons_running (pg);
753 for (i = 0; i < num_peers; i++)
755 GNUNET_PEER_Id peer_id;
757 d1 = GNUNET_TESTING_daemon_get (pg, i);
758 peer_id = GNUNET_PEER_intern (&d1->id);
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n",
760 peer_id, GNUNET_i2s (&d1->id));
762 d1 = GNUNET_TESTING_daemon_get (pg, 0);
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
764 "Peer looking: %s\n",
765 GNUNET_i2s (&d1->id));
766 pid1 = GNUNET_PEER_intern (&d1->id);
768 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
770 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
776 * Function that will be called whenever two daemons are connected by
777 * the testing library.
780 * @param first peer id for first daemon
781 * @param second peer id for the second daemon
782 * @param distance distance between the connected peers
783 * @param first_cfg config for the first daemon
784 * @param second_cfg config for the second daemon
785 * @param first_daemon handle for the first daemon
786 * @param second_daemon handle for the second daemon
787 * @param emsg error message (NULL on success)
790 connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
791 const struct GNUNET_PeerIdentity *second, uint32_t distance,
792 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
793 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
794 struct GNUNET_TESTING_Daemon *first_daemon,
795 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
804 "Problem with new connection (%s)\n",
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (first));
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (second));
814 * run: load configuration options and schedule test to run (start peergroup)
817 * @param cfgfile configuration file name (can be NULL)
818 * @param cfg configuration handle
821 run (void *cls, char *const *args, const char *cfgfile,
822 const struct GNUNET_CONFIGURATION_Handle *cfg)
825 struct GNUNET_TESTING_Host *hosts;
829 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
831 GNUNET_log_setup ("test_mesh_small",
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
841 "Starting daemons.\n");
842 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing_old",
843 "use_progressbars", "YES");
847 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing_old",
848 "num_peers", &num_peers))
850 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
851 "Option TESTING:NUM_PEERS is required!\n");
856 GNUNET_CONFIGURATION_get_value_time (testing_cfg, "test_mesh_small",
857 "WAIT_TIME", &wait_time))
859 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
860 "Option test_mesh_small:wait_time is required!\n");
865 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing_old",
866 "topology_output_file",
869 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
870 "Option test_mesh_small:topology_output_file is required!\n");
875 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
880 GNUNET_DISK_file_open (data_filename,
881 GNUNET_DISK_OPEN_READWRITE |
882 GNUNET_DISK_OPEN_CREATE,
883 GNUNET_DISK_PERM_USER_READ |
884 GNUNET_DISK_PERM_USER_WRITE);
885 if (data_file == NULL)
887 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
889 GNUNET_free (data_filename);
894 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
895 "output_file", &temp_str))
898 GNUNET_DISK_file_open (temp_str,
899 GNUNET_DISK_OPEN_READWRITE |
900 GNUNET_DISK_OPEN_CREATE,
901 GNUNET_DISK_PERM_USER_READ |
902 GNUNET_DISK_PERM_USER_WRITE);
903 if (output_file == NULL)
904 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
907 GNUNET_free_non_null (temp_str);
909 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
911 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
912 &connect_cb, &peergroup_ready, NULL,
914 GNUNET_assert (pg != NULL);
916 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
917 &shutdown_task, NULL);
923 * test_mesh_small command line options
925 static struct GNUNET_GETOPT_CommandLineOption options[] = {
926 {'V', "verbose", NULL,
927 gettext_noop ("be verbose (print progress information)"),
928 0, &GNUNET_GETOPT_set_one, &verbose},
929 GNUNET_GETOPT_OPTION_END
937 main (int argc, char *argv[])
942 "test_mesh_small.conf",
949 int argc2 = (sizeof (argv2) / sizeof (char *)) - 1;
951 /* Each peer is supposed to generate the following callbacks:
952 * 1 incoming tunnel (@dest)
953 * 1 connected peer (@orig)
954 * 1 received data packet (@dest)
955 * 1 received data packet (@orig)
956 * 1 received tunnel destroy (@dest)
957 * _________________________________
958 * 5 x ok expected per peer
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n");
963 if (strstr (argv[0], "test_mesh_small_unicast") != NULL)
965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNICAST\n");
969 else if (strstr (argv[0], "test_mesh_small_multicast") != NULL)
971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MULTICAST\n");
975 else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
977 /* Each peer is supposed to generate the following callbacks:
978 * 1 incoming tunnel (@dest)
979 * 1 connected peer (@orig)
980 * 1000 received data packet (@dest)
981 * 1000 received data packet (@orig)
982 * 1 received tunnel destroy (@dest)
983 * _________________________________
984 * 5 x ok expected per peer
986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
989 argv2 [3] = NULL; // remove -L DEBUG
994 else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
996 /* Each peer is supposed to generate the following callbacks:
997 * 1 incoming tunnel (@dest)
998 * 1 connected peer (@orig)
999 * 1000 received data packet (@dest)
1000 * 1received data packet (@orig)
1001 * 1 received tunnel destroy (@dest)
1002 * _________________________________
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1006 if (strstr (argv[0], "_min") != NULL)
1008 else if (strstr (argv[0], "_nobuf") != NULL)
1015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1020 GNUNET_PROGRAM_run (argc2, argv2,
1022 gettext_noop ("Test mesh in a small network."), options,
1025 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
1029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1030 "FAILED! (%d/%d)\n", ok, ok_goal);
1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1037 /* end of test_mesh_small.c */