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;
47 * How namy messages to send
49 #define TOTAL_PACKETS 1000
52 * How long until we give up on connecting the peers?
54 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
57 * Time to wait for stuff that should be rather fast
59 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
62 * DIFFERENT TESTS TO RUN
73 * Which test are we running?
78 * String with test name
83 * Flag to send traffic leaf->root in speed tests to test BCK_ACK logic.
85 static int test_backwards = GNUNET_NO;
88 * How many events have happened
93 * Each peer is supposed to generate the following callbacks:
94 * 1 incoming tunnel (@dest)
95 * 1 connected peer (@orig)
96 * 1 received data packet (@dest)
97 * 1 received data packet (@orig)
98 * 1 received tunnel destroy (@dest)
99 * _________________________________
100 * 5 x ok expected per peer
106 * Size of each test packet
108 size_t size_payload = sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t);
111 * Is the setup initialized?
113 static int initialized;
116 * Peers that have been connected
118 static int peers_in_tunnel;
121 * Peers that have responded
123 static int peers_responded;
126 * Number of payload packes sent
128 static int data_sent;
131 * Number of payload packets received
133 static int data_received;
136 * Number of payload packed explicitly (app level) acknowledged
146 * Total number of peers in the test.
148 static unsigned long long num_peers;
151 * Global configuration file
153 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
156 * Total number of currently running peers.
158 static unsigned long long peers_running;
161 * Total number of connections in the whole network.
163 static unsigned int total_connections;
166 * The currently running peer group.
168 static struct GNUNET_TESTING_PeerGroup *pg;
171 * File to report results to.
173 static struct GNUNET_DISK_FileHandle *output_file;
176 * File to log connection info, statistics to.
178 static struct GNUNET_DISK_FileHandle *data_file;
183 static struct GNUNET_TIME_Relative wait_time;
186 * Task called to disconnect peers.
188 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
191 * Task To perform tests
193 static GNUNET_SCHEDULER_TaskIdentifier test_task;
196 * Task called to shutdown test.
198 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
201 * Filename of the file containing the topology.
203 static char *topology_file;
206 * Testbed handle for the root peer
208 static struct GNUNET_TESTING_Daemon *d1;
211 * Testbed handle for the first leaf peer
213 static struct GNUNET_TESTING_Daemon *d2;
216 * Testbed handle for the second leaf peer
218 static struct GNUNET_TESTING_Daemon *d3;
221 * Mesh handle for the root peer
223 static struct GNUNET_MESH_Handle *h1;
226 * Mesh handle for the first leaf peer
228 static struct GNUNET_MESH_Handle *h2;
231 * Mesh handle for the second leaf peer
233 static struct GNUNET_MESH_Handle *h3;
236 * Tunnel handle for the root peer
238 static struct GNUNET_MESH_Tunnel *t;
241 * Tunnel handle for the first leaf peer
243 static struct GNUNET_MESH_Tunnel *incoming_t;
246 * Tunnel handle for the second leaf peer
248 static struct GNUNET_MESH_Tunnel *incoming_t2;
251 * Time we started the data transmission (after tunnel has been established
254 static struct GNUNET_TIME_Absolute start_time;
258 * Show the results of the test (banwidth acheived) and log them to GAUGER
263 static struct GNUNET_TIME_Absolute end_time;
264 static struct GNUNET_TIME_Relative total_time;
266 end_time = GNUNET_TIME_absolute_get();
267 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
268 FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name);
269 FPRINTF (stderr, "Test time %llu ms\n",
270 (unsigned long long) total_time.rel_value);
271 FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
272 4 * TOTAL_PACKETS * 1.0 / total_time.rel_value); // 4bytes * ms
273 FPRINTF (stderr, "Test throughput: %f packets/s\n\n",
274 TOTAL_PACKETS * 1000.0 / total_time.rel_value); // packets * ms
275 GAUGER ("MESH", test_name,
276 TOTAL_PACKETS * 1000.0 / total_time.rel_value,
282 * Check whether peers successfully shut down.
284 * @param cls Closure (unused).
285 * @param emsg Error message.
288 shutdown_callback (void *cls, const char *emsg)
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Shutdown of peers failed!\n");
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "All peers successfully shut down!\n");
305 GNUNET_CONFIGURATION_destroy (testing_cfg);
310 * Shut down peergroup, clean up.
312 * @param cls Closure (unused).
313 * @param tc Task Context.
316 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
325 GNUNET_SCHEDULER_cancel (disconnect_task);
326 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
331 GNUNET_MESH_disconnect (h1);
336 GNUNET_MESH_disconnect (h2);
339 if (test == MULTICAST && NULL != h3)
341 GNUNET_MESH_disconnect (h3);
345 if (data_file != NULL)
346 GNUNET_DISK_file_close (data_file);
347 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
352 * Disconnect from mesh services af all peers, call shutdown.
354 * @param cls Closure (unused).
355 * @param tc Task Context.
358 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
361 "disconnecting mesh service of peers\n");
362 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
365 GNUNET_MESH_tunnel_destroy(t);
368 if (NULL != incoming_t)
370 GNUNET_MESH_tunnel_destroy(incoming_t);
373 if (NULL != incoming_t2)
375 GNUNET_MESH_tunnel_destroy(incoming_t2);
378 GNUNET_MESH_disconnect (h1);
379 GNUNET_MESH_disconnect (h2);
381 if (test == MULTICAST)
383 GNUNET_MESH_disconnect (h3);
386 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
388 GNUNET_SCHEDULER_cancel (shutdown_handle);
389 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
395 * Transmit ready callback.
397 * @param cls Closure (message type).
398 * @param size Size of the tranmist buffer.
399 * @param buf Pointer to the beginning of the buffer.
401 * @return Number of bytes written to buf.
404 tmt_rdy (void *cls, size_t size, void *buf);
408 * Task to schedule a new data transmission.
410 * @param cls Closure (peer #).
411 * @param tc Task Context.
414 data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
416 struct GNUNET_MESH_TransmitHandle *th;
417 struct GNUNET_MESH_Tunnel *tunnel;
418 struct GNUNET_PeerIdentity *destination;
420 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
424 if (GNUNET_YES == test_backwards)
427 destination = &d1->id;
432 destination = &d2->id;
434 th = GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
435 GNUNET_TIME_UNIT_FOREVER_REL,
438 &tmt_rdy, (void *) 1L);
441 unsigned long i = (unsigned long) cls;
443 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retransmission\n");
446 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " in 1 ms\n");
447 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
448 &data_task, (void *)1UL);
453 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "in %u ms\n", i);
454 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
455 GNUNET_TIME_UNIT_MILLISECONDS,
457 &data_task, (void *)i);
464 * Transmit ready callback
466 * @param cls Closure (message type).
467 * @param size Size of the buffer we have.
468 * @param buf Buffer to copy data to.
471 tmt_rdy (void *cls, size_t size, void *buf)
473 struct GNUNET_MessageHeader *msg = buf;
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
477 " tmt_rdy called\n");
478 if (size < size_payload || NULL == buf)
481 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
482 "size %u, buf %p, data_sent %u, data_received %u\n",
489 msg->size = htons (size);
490 msg->type = htons ((long) cls);
491 data = (uint32_t *) &msg[1];
492 *data = htonl (data_sent);
493 if (SPEED == test && GNUNET_YES == initialized)
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 " Sent packet %d\n", data_sent);
498 if (data_sent < TOTAL_PACKETS)
500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
501 " Scheduling packet %d\n", data_sent + 1);
502 GNUNET_SCHEDULER_add_now(&data_task, NULL);
510 * Function is called whenever a message is received.
512 * @param cls closure (set from GNUNET_MESH_connect)
513 * @param tunnel connection to the other end
514 * @param tunnel_ctx place to store local state associated with the tunnel
515 * @param sender who sent the message
516 * @param message the actual message
517 * @param atsi performance data for the connection
518 * @return GNUNET_OK to keep the connection open,
519 * GNUNET_SYSERR to close it (signal serious error)
522 data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
523 const struct GNUNET_PeerIdentity *sender,
524 const struct GNUNET_MessageHeader *message,
525 const struct GNUNET_ATS_Information *atsi)
527 long client = (long) cls;
528 long expected_target_client;
535 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
537 GNUNET_SCHEDULER_cancel (disconnect_task);
539 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
547 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n");
549 if (test == MULTICAST && peers_responded < 2)
554 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
555 "Leaf client %li got a message.\n",
563 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal);
564 data = (uint32_t *) &message[1];
565 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " payload: (%u)\n", ntohl (*data));
566 if (SPEED == test && GNUNET_YES == test_backwards)
568 expected_target_client = 1L;
572 expected_target_client = 2L;
575 if (GNUNET_NO == initialized)
577 initialized = GNUNET_YES;
578 start_time = GNUNET_TIME_absolute_get ();
581 GNUNET_assert (2L == client);
582 GNUNET_SCHEDULER_add_now (&data_task, NULL);
587 if (client == expected_target_client) // Normally 2 or 3
590 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
591 " received data %u\n", data_received);
592 if (SPEED != test || (ok_goal - 2) == ok)
594 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
595 GNUNET_TIME_UNIT_FOREVER_REL, sender,
597 &tmt_rdy, (void *) 1L);
602 if (data_received < TOTAL_PACKETS)
608 if (test == SPEED_ACK || test == SPEED)
611 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
612 " received ack %u\n", data_ack);
613 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
614 GNUNET_TIME_UNIT_FOREVER_REL, sender,
616 &tmt_rdy, (void *) 1L);
617 if (data_ack < TOTAL_PACKETS && SPEED != test)
619 if (ok == 2 && SPEED == test)
623 GNUNET_MESH_tunnel_destroy (t);
627 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
629 GNUNET_SCHEDULER_cancel (disconnect_task);
631 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
640 * Handlers, for diverse services
642 static struct GNUNET_MESH_MessageHandler handlers[] = {
643 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
649 * Method called whenever another peer has added us to a tunnel
650 * the other peer initiated.
653 * @param tunnel new handle to the tunnel
654 * @param initiator peer that started the tunnel
655 * @param atsi performance information for the tunnel
656 * @return initial tunnel context for the tunnel
657 * (can be NULL -- that's not an error)
660 incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
661 const struct GNUNET_PeerIdentity *initiator,
662 const struct GNUNET_ATS_Information *atsi)
664 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
665 "Incoming tunnel from %s to peer %d\n",
666 GNUNET_i2s (initiator), (long) cls);
668 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
669 if ((long) cls == 2L)
671 else if ((long) cls == 3L)
672 incoming_t2 = tunnel;
675 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
676 "Incoming tunnel for unknown client %lu\n", (long) cls);
679 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
681 GNUNET_SCHEDULER_cancel (disconnect_task);
683 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
690 * Function called whenever an inbound tunnel is destroyed. Should clean up
691 * any associated state.
693 * @param cls closure (set from GNUNET_MESH_connect)
694 * @param tunnel connection to the other end (henceforth invalid)
695 * @param tunnel_ctx place where local state associated
696 * with the tunnel is stored
699 tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
704 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
705 "Incoming tunnel disconnected at peer %d\n",
718 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
719 "Unknown peer! %d\n", i);
720 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
722 if (peers_in_tunnel > 0)
725 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
727 GNUNET_SCHEDULER_cancel (disconnect_task);
728 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
736 * Method called whenever a tunnel falls apart.
739 * @param peer peer identity the tunnel stopped working with
742 dh (void *cls, const struct GNUNET_PeerIdentity *peer)
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "peer %s disconnected\n",
752 * Method called whenever a peer connects to a tunnel.
755 * @param peer peer identity the tunnel was created to, NULL on timeout
756 * @param atsi performance data for the connection
759 ch (void *cls, const struct GNUNET_PeerIdentity *peer,
760 const struct GNUNET_ATS_Information *atsi)
762 struct GNUNET_PeerIdentity *dest;
764 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
765 "peer %s connected\n", GNUNET_i2s (peer));
767 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
771 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
776 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
782 // incoming_t is NULL unless we send a relevant data packet
787 if (peers_in_tunnel < 2)
795 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
797 GNUNET_SCHEDULER_cancel (disconnect_task);
799 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
801 "Sending data initializer...\n");
806 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
807 GNUNET_TIME_UNIT_FOREVER_REL, dest,
809 &tmt_rdy, (void *) 1L);
813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
814 "Disconnect already run?\n");
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
823 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
825 * Testcase continues when the root receives confirmation of connected peers,
826 * on callback funtion ch.
828 * @param cls Closure (unsued).
829 * @param tc Task Context.
832 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
835 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
836 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
838 if (test == MULTICAST)
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
842 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
846 "schedule timeout in TIMEOUT\n");
847 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
849 GNUNET_SCHEDULER_cancel (disconnect_task);
851 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &disconnect_mesh_peers, NULL);
857 * connect_mesh_service: connect to the mesh service of one of the peers
859 * @param cls Closure (unsued).
860 * @param tc Task Context.
863 connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
865 GNUNET_MESH_ApplicationType app;
867 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
871 "connect_mesh_service\n");
873 d2 = GNUNET_TESTING_daemon_get (pg, num_peers - 1);
874 if (test == MULTICAST)
876 d3 = GNUNET_TESTING_daemon_get (pg, num_peers - 2);
878 app = (GNUNET_MESH_ApplicationType) 0;
881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
882 "connecting to mesh service of peer %s\n",
883 GNUNET_i2s (&d1->id));
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
885 "connecting to mesh service of peer %s\n",
886 GNUNET_i2s (&d2->id));
887 if (test == MULTICAST)
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 "connecting to mesh service of peer %s\n",
891 GNUNET_i2s (&d3->id));
894 h1 = GNUNET_MESH_connect (d1->cfg, (void *) 1L, NULL, &tunnel_cleaner,
896 h2 = GNUNET_MESH_connect (d2->cfg, (void *) 2L, &incoming_tunnel,
897 &tunnel_cleaner, handlers, &app);
898 if (test == MULTICAST)
900 h3 = GNUNET_MESH_connect (d3->cfg, (void *) 3L, &incoming_tunnel,
901 &tunnel_cleaner, handlers, &app);
903 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
904 if (SPEED_MIN == test)
906 GNUNET_MESH_tunnel_speed_min(t);
909 if (SPEED_NOBUF == test)
911 GNUNET_MESH_tunnel_buffer(t, GNUNET_NO);
916 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
917 (GNUNET_TIME_UNIT_SECONDS, 1), &do_test,
924 * peergroup_ready: start test when all peers are connected
927 * @param emsg error message
930 peergroup_ready (void *cls, const char *emsg)
938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939 "Peergroup callback called with error, aborting test!\n");
940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
941 "Error from testing: `%s'\n", emsg);
943 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
948 "************************************************************\n");
949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
950 "Peer Group started successfully!\n");
951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
952 "Have %u connections\n",
956 if (data_file != NULL)
959 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
961 GNUNET_DISK_file_write (data_file, buf, buf_len);
964 peers_running = GNUNET_TESTING_daemons_running (pg);
965 for (i = 0; i < num_peers; i++)
967 GNUNET_PEER_Id peer_id;
969 d1 = GNUNET_TESTING_daemon_get (pg, i);
970 peer_id = GNUNET_PEER_intern (&d1->id);
971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n",
972 peer_id, GNUNET_i2s (&d1->id));
974 d1 = GNUNET_TESTING_daemon_get (pg, 0);
975 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
976 "Peer looking: %s\n",
977 GNUNET_i2s (&d1->id));
979 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
981 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
987 * Function that will be called whenever two daemons are connected by
988 * the testing library.
991 * @param first peer id for first daemon
992 * @param second peer id for the second daemon
993 * @param distance distance between the connected peers
994 * @param first_cfg config for the first daemon
995 * @param second_cfg config for the second daemon
996 * @param first_daemon handle for the first daemon
997 * @param second_daemon handle for the second daemon
998 * @param emsg error message (NULL on success)
1001 connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1002 const struct GNUNET_PeerIdentity *second, uint32_t distance,
1003 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
1004 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
1005 struct GNUNET_TESTING_Daemon *first_daemon,
1006 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
1010 total_connections++;
1014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1015 "Problem with new connection (%s)\n",
1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (first));
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (second));
1025 * run: load configuration options and schedule test to run (start peergroup)
1027 * @param cls closure
1029 * @param cfgfile configuration file name (can be NULL)
1030 * @param cfg configuration handle
1033 run (void *cls, char *const *args, const char *cfgfile,
1034 const struct GNUNET_CONFIGURATION_Handle *cfg)
1037 struct GNUNET_TESTING_Host *hosts;
1038 char *data_filename;
1041 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
1043 GNUNET_log_setup ("test_mesh_small",
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 "Starting daemons.\n");
1054 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing_old",
1055 "use_progressbars", "YES");
1059 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing_old",
1060 "num_peers", &num_peers))
1062 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1063 "Option TESTING:NUM_PEERS is required!\n");
1068 GNUNET_CONFIGURATION_get_value_time (testing_cfg, "test_mesh_small",
1069 "WAIT_TIME", &wait_time))
1071 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1072 "Option test_mesh_small:wait_time is required!\n");
1077 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing_old",
1078 "topology_output_file",
1081 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1082 "Option test_mesh_small:topology_output_file is required!\n");
1087 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
1092 GNUNET_DISK_file_open (data_filename,
1093 GNUNET_DISK_OPEN_READWRITE |
1094 GNUNET_DISK_OPEN_CREATE,
1095 GNUNET_DISK_PERM_USER_READ |
1096 GNUNET_DISK_PERM_USER_WRITE);
1097 if (data_file == NULL)
1099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1101 GNUNET_free (data_filename);
1106 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
1107 "output_file", &temp_str))
1110 GNUNET_DISK_file_open (temp_str,
1111 GNUNET_DISK_OPEN_READWRITE |
1112 GNUNET_DISK_OPEN_CREATE,
1113 GNUNET_DISK_PERM_USER_READ |
1114 GNUNET_DISK_PERM_USER_WRITE);
1115 if (output_file == NULL)
1116 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1119 GNUNET_free_non_null (temp_str);
1121 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
1123 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
1124 &connect_cb, &peergroup_ready, NULL,
1126 GNUNET_assert (pg != NULL);
1128 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1129 &shutdown_task, NULL);
1135 * test_mesh_small command line options
1137 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1138 {'V', "verbose", NULL,
1139 gettext_noop ("be verbose (print progress information)"),
1140 0, &GNUNET_GETOPT_set_one, &verbose},
1141 GNUNET_GETOPT_OPTION_END
1149 main (int argc, char *argv[])
1154 "test_mesh_small.conf",
1161 int argc2 = (sizeof (argv2) / sizeof (char *)) - 1;
1163 initialized = GNUNET_NO;
1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n");
1166 if (strstr (argv[0], "test_mesh_small_unicast") != NULL)
1168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNICAST\n");
1170 test_name = "unicast";
1173 else if (strstr (argv[0], "test_mesh_small_multicast") != NULL)
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MULTICAST\n");
1177 test_name = "multicast";
1180 else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
1182 /* Each peer is supposed to generate the following callbacks:
1183 * 1 incoming tunnel (@dest)
1184 * 1 connected peer (@orig)
1185 * TOTAL_PACKETS received data packet (@dest)
1186 * TOTAL_PACKETS received data packet (@orig)
1187 * 1 received tunnel destroy (@dest)
1188 * _________________________________
1189 * 5 x ok expected per peer
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1193 test_name = "speed ack";
1194 ok_goal = TOTAL_PACKETS * 2 + 3;
1195 argv2 [3] = NULL; // remove -L DEBUG
1200 else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
1202 /* Each peer is supposed to generate the following callbacks:
1203 * 1 incoming tunnel (@dest)
1204 * 1 connected peer (@orig)
1205 * 1 initial packet (@dest)
1206 * TOTAL_PACKETS received data packet (@dest)
1207 * 1 received data packet (@orig)
1208 * 1 received tunnel destroy (@dest)
1209 * _________________________________
1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1212 ok_goal = TOTAL_PACKETS + 5;
1213 if (strstr (argv[0], "_min") != NULL)
1216 test_name = "speed min";
1218 else if (strstr (argv[0], "_nobuf") != NULL)
1221 test_name = "speed nobuf";
1226 test_name = "speed";
1231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1236 if (strstr (argv[0], "backwards") != NULL)
1240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1241 test_backwards = GNUNET_YES;
1242 aux = malloc (32); // "leaked"
1243 sprintf (aux, "backwards %s", test_name);
1247 GNUNET_PROGRAM_run (argc2, argv2,
1249 gettext_noop ("Test mesh in a small network."), options,
1252 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
1256 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1257 "FAILED! (%d/%d)\n", ok, ok_goal);
1260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1264 /* end of test_mesh_small.c */