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, 60)
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 * Is the setup initialized?
108 static int initialized;
111 * Peers that have been connected
113 static int peers_in_tunnel;
116 * Peers that have responded
118 static int peers_responded;
121 * Number of payload packes sent
123 static int data_sent;
126 * Number of payload packets received
128 static int data_received;
131 * Number of payload packed explicitly (app level) acknowledged
141 * Total number of peers in the test.
143 static unsigned long long num_peers;
146 * Global configuration file
148 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
151 * Total number of currently running peers.
153 static unsigned long long peers_running;
156 * Total number of connections in the whole network.
158 static unsigned int total_connections;
161 * The currently running peer group.
163 static struct GNUNET_TESTING_PeerGroup *pg;
166 * File to report results to.
168 static struct GNUNET_DISK_FileHandle *output_file;
171 * File to log connection info, statistics to.
173 static struct GNUNET_DISK_FileHandle *data_file;
178 static struct GNUNET_TIME_Relative wait_time;
181 * Task called to disconnect peers.
183 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
186 * Task To perform tests
188 static GNUNET_SCHEDULER_TaskIdentifier test_task;
191 * Task called to shutdown test.
193 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
196 * Filename of the file containing the topology.
198 static char *topology_file;
201 * Testbed handle for the root peer
203 static struct GNUNET_TESTING_Daemon *d1;
206 * Testbed handle for the first leaf peer
208 static struct GNUNET_TESTING_Daemon *d2;
211 * Testbed handle for the second leaf peer
213 static struct GNUNET_TESTING_Daemon *d3;
216 * Mesh handle for the root peer
218 static struct GNUNET_MESH_Handle *h1;
221 * Mesh handle for the first leaf peer
223 static struct GNUNET_MESH_Handle *h2;
226 * Mesh handle for the second leaf peer
228 static struct GNUNET_MESH_Handle *h3;
231 * Tunnel handle for the root peer
233 static struct GNUNET_MESH_Tunnel *t;
236 * Tunnel handle for the first leaf peer
238 static struct GNUNET_MESH_Tunnel *incoming_t;
241 * Tunnel handle for the second leaf peer
243 static struct GNUNET_MESH_Tunnel *incoming_t2;
246 * Time we started the data transmission (after tunnel has been established
249 static struct GNUNET_TIME_Absolute start_time;
253 * Show the results of the test (banwidth acheived) and log them to GAUGER
258 static struct GNUNET_TIME_Absolute end_time;
259 static struct GNUNET_TIME_Relative total_time;
261 end_time = GNUNET_TIME_absolute_get();
262 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
263 FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name);
264 FPRINTF (stderr, "Test time %llu ms\n",
265 (unsigned long long) total_time.rel_value);
266 FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
267 4 * TOTAL_PACKETS * 1.0 / total_time.rel_value); // 4bytes * ms
268 FPRINTF (stderr, "Test throughput: %f packets/s\n\n",
269 TOTAL_PACKETS * 1000.0 / total_time.rel_value); // packets * ms
270 GAUGER ("MESH", test_name,
271 TOTAL_PACKETS * 1000.0 / total_time.rel_value,
277 * Check whether peers successfully shut down.
279 * @param cls Closure (unused).
280 * @param emsg Error message.
283 shutdown_callback (void *cls, const char *emsg)
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
289 "Shutdown of peers failed!\n");
296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
297 "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)
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
318 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
320 GNUNET_SCHEDULER_cancel (disconnect_task);
321 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
326 GNUNET_MESH_disconnect (h1);
331 GNUNET_MESH_disconnect (h2);
334 if (test == MULTICAST && NULL != h3)
336 GNUNET_MESH_disconnect (h3);
340 if (data_file != NULL)
341 GNUNET_DISK_file_close (data_file);
342 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
347 * Disconnect from mesh services af all peers, call shutdown.
349 * @param cls Closure (unused).
350 * @param tc Task Context.
353 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "disconnecting mesh service of peers\n");
357 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
360 GNUNET_MESH_tunnel_destroy(t);
363 if (NULL != incoming_t)
365 GNUNET_MESH_tunnel_destroy(incoming_t);
368 if (NULL != incoming_t2)
370 GNUNET_MESH_tunnel_destroy(incoming_t2);
373 GNUNET_MESH_disconnect (h1);
374 GNUNET_MESH_disconnect (h2);
376 if (test == MULTICAST)
378 GNUNET_MESH_disconnect (h3);
381 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
383 GNUNET_SCHEDULER_cancel (shutdown_handle);
384 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
390 * Transmit ready callback.
392 * @param cls Closure (peer #).
393 * @param size Size of the tranmist buffer.
394 * @param buf Pointer to the beginning of the buffer.
396 * @return Number of bytes written to buf.
399 tmt_rdy (void *cls, size_t size, void *buf);
403 * Task to schedule a new data transmission.
405 * @param cls Closure (peer #).
406 * @param tc Task Context.
409 data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
411 struct GNUNET_MESH_TransmitHandle *th;
412 struct GNUNET_MESH_Tunnel *tunnel;
413 struct GNUNET_PeerIdentity *destination;
415 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
419 if (GNUNET_YES == test_backwards)
422 destination = &d1->id;
427 destination = &d2->id;
429 th = GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
430 GNUNET_TIME_UNIT_FOREVER_REL,
432 sizeof (struct GNUNET_MessageHeader),
433 &tmt_rdy, (void *) 1L);
436 unsigned long i = (unsigned long) cls;
438 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retransmission\n");
441 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " in 1 ms\n");
442 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
443 &data_task, (void *)1UL);
448 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "in %u ms\n", i);
449 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
450 GNUNET_TIME_UNIT_MILLISECONDS,
452 &data_task, (void *)i);
459 * Transmit ready callback
461 * @param cls Closure.
462 * @param size Size of the buffer we have.
463 * @param buf Buffer to copy data to.
466 tmt_rdy (void *cls, size_t size, void *buf)
468 struct GNUNET_MessageHeader *msg = buf;
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 " tmt_rdy called\n");
472 if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf)
474 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
475 msg->type = htons ((long) cls);
476 if (SPEED == test && GNUNET_YES == initialized)
479 if (data_sent < TOTAL_PACKETS)
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 " Scheduling %d packet\n", data_sent);
483 GNUNET_SCHEDULER_add_now(&data_task, NULL);
486 return sizeof (struct GNUNET_MessageHeader);
491 * Function is called whenever a message is received.
493 * @param cls closure (set from GNUNET_MESH_connect)
494 * @param tunnel connection to the other end
495 * @param tunnel_ctx place to store local state associated with the tunnel
496 * @param sender who sent the message
497 * @param message the actual message
498 * @param atsi performance data for the connection
499 * @return GNUNET_OK to keep the connection open,
500 * GNUNET_SYSERR to close it (signal serious error)
503 data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
504 const struct GNUNET_PeerIdentity *sender,
505 const struct GNUNET_MessageHeader *message,
506 const struct GNUNET_ATS_Information *atsi)
508 long client = (long) cls;
509 long expected_target_client;
515 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n");
516 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
518 if (test == MULTICAST && peers_responded < 2)
523 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
524 "Leaf client %li got a message.\n",
526 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
534 if (SPEED == test && GNUNET_YES == test_backwards)
536 expected_target_client = 1L;
540 expected_target_client = 2L;
543 if (GNUNET_NO == initialized)
545 initialized = GNUNET_YES;
546 start_time = GNUNET_TIME_absolute_get ();
549 GNUNET_assert (2L == client);
550 GNUNET_SCHEDULER_add_now (&data_task, NULL);
555 if (client == expected_target_client) // Normally 2 or 3
558 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
559 " received data %u\n", data_received);
560 if (SPEED != test || (ok_goal - 2) == ok)
562 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
563 GNUNET_TIME_UNIT_FOREVER_REL, sender,
564 sizeof (struct GNUNET_MessageHeader),
565 &tmt_rdy, (void *) 1L);
569 if (data_received < TOTAL_PACKETS)
575 if (test == SPEED_ACK || test == SPEED)
578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
579 " received ack %u\n", data_ack);
580 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
581 GNUNET_TIME_UNIT_FOREVER_REL, sender,
582 sizeof (struct GNUNET_MessageHeader),
583 &tmt_rdy, (void *) 1L);
584 if (data_ack < TOTAL_PACKETS && SPEED != test)
586 if (ok == 2 && SPEED == test)
590 GNUNET_MESH_tunnel_destroy (t);
594 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
596 GNUNET_SCHEDULER_cancel (disconnect_task);
598 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
607 * Handlers, for diverse services
609 static struct GNUNET_MESH_MessageHandler handlers[] = {
610 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
616 * Method called whenever another peer has added us to a tunnel
617 * the other peer initiated.
620 * @param tunnel new handle to the tunnel
621 * @param initiator peer that started the tunnel
622 * @param atsi performance information for the tunnel
623 * @return initial tunnel context for the tunnel
624 * (can be NULL -- that's not an error)
627 incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
628 const struct GNUNET_PeerIdentity *initiator,
629 const struct GNUNET_ATS_Information *atsi)
631 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
632 "Incoming tunnel from %s to peer %d\n",
633 GNUNET_i2s (initiator), (long) cls);
635 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
636 if ((long) cls == 2L)
638 else if ((long) cls == 3L)
639 incoming_t2 = tunnel;
642 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
643 "Incoming tunnel for unknown client %lu\n", (long) cls);
646 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
648 GNUNET_SCHEDULER_cancel (disconnect_task);
650 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
657 * Function called whenever an inbound tunnel is destroyed. Should clean up
658 * any associated state.
660 * @param cls closure (set from GNUNET_MESH_connect)
661 * @param tunnel connection to the other end (henceforth invalid)
662 * @param tunnel_ctx place where local state associated
663 * with the tunnel is stored
666 tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
671 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
672 "Incoming tunnel disconnected at peer %d\n",
685 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
686 "Unknown peer! %d\n", i);
687 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
689 if (peers_in_tunnel > 0)
692 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
694 GNUNET_SCHEDULER_cancel (disconnect_task);
695 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
703 * Method called whenever a tunnel falls apart.
706 * @param peer peer identity the tunnel stopped working with
709 dh (void *cls, const struct GNUNET_PeerIdentity *peer)
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
712 "peer %s disconnected\n",
719 * Method called whenever a peer connects to a tunnel.
722 * @param peer peer identity the tunnel was created to, NULL on timeout
723 * @param atsi performance data for the connection
726 ch (void *cls, const struct GNUNET_PeerIdentity *peer,
727 const struct GNUNET_ATS_Information *atsi)
729 struct GNUNET_PeerIdentity *dest;
731 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
732 "peer %s connected\n", GNUNET_i2s (peer));
734 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
738 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
743 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
749 // incoming_t is NULL unless we send a relevant data packet
754 if (peers_in_tunnel < 2)
761 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
763 GNUNET_SCHEDULER_cancel (disconnect_task);
765 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
767 "Sending data initializer...\n");
772 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
773 GNUNET_TIME_UNIT_FOREVER_REL, dest,
774 sizeof (struct GNUNET_MessageHeader),
775 &tmt_rdy, (void *) 1L);
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "Disconnect already run?\n");
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
791 * Testcase continues when the root receives confirmation of connected peers,
792 * on callback funtion ch.
794 * @param cls Closure (unsued).
795 * @param tc Task Context.
798 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
802 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
804 if (test == MULTICAST)
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
808 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
812 "schedule timeout in SHORT_TIME\n");
813 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
815 GNUNET_SCHEDULER_cancel (disconnect_task);
817 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
823 * connect_mesh_service: connect to the mesh service of one of the peers
825 * @param cls Closure (unsued).
826 * @param tc Task Context.
829 connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
831 GNUNET_MESH_ApplicationType app;
833 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
837 "connect_mesh_service\n");
839 d2 = GNUNET_TESTING_daemon_get (pg, num_peers - 1);
840 if (test == MULTICAST)
842 d3 = GNUNET_TESTING_daemon_get (pg, num_peers - 2);
844 app = (GNUNET_MESH_ApplicationType) 0;
847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
848 "connecting to mesh service of peer %s\n",
849 GNUNET_i2s (&d1->id));
850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
851 "connecting to mesh service of peer %s\n",
852 GNUNET_i2s (&d2->id));
853 if (test == MULTICAST)
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "connecting to mesh service of peer %s\n",
857 GNUNET_i2s (&d3->id));
860 h1 = GNUNET_MESH_connect (d1->cfg, (void *) 1L, NULL, &tunnel_cleaner,
862 h2 = GNUNET_MESH_connect (d2->cfg, (void *) 2L, &incoming_tunnel,
863 &tunnel_cleaner, handlers, &app);
864 if (test == MULTICAST)
866 h3 = GNUNET_MESH_connect (d3->cfg, (void *) 3L, &incoming_tunnel,
867 &tunnel_cleaner, handlers, &app);
869 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
870 if (SPEED_MIN == test)
872 GNUNET_MESH_tunnel_speed_min(t);
875 if (SPEED_NOBUF == test)
877 GNUNET_MESH_tunnel_buffer(t, GNUNET_NO);
882 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
883 (GNUNET_TIME_UNIT_SECONDS, 1), &do_test,
890 * peergroup_ready: start test when all peers are connected
893 * @param emsg error message
896 peergroup_ready (void *cls, const char *emsg)
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
905 "Peergroup callback called with error, aborting test!\n");
906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
907 "Error from testing: `%s'\n", emsg);
909 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
914 "************************************************************\n");
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916 "Peer Group started successfully!\n");
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
918 "Have %u connections\n",
922 if (data_file != NULL)
925 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
927 GNUNET_DISK_file_write (data_file, buf, buf_len);
930 peers_running = GNUNET_TESTING_daemons_running (pg);
931 for (i = 0; i < num_peers; i++)
933 GNUNET_PEER_Id peer_id;
935 d1 = GNUNET_TESTING_daemon_get (pg, i);
936 peer_id = GNUNET_PEER_intern (&d1->id);
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n",
938 peer_id, GNUNET_i2s (&d1->id));
940 d1 = GNUNET_TESTING_daemon_get (pg, 0);
941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
942 "Peer looking: %s\n",
943 GNUNET_i2s (&d1->id));
945 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
947 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
953 * Function that will be called whenever two daemons are connected by
954 * the testing library.
957 * @param first peer id for first daemon
958 * @param second peer id for the second daemon
959 * @param distance distance between the connected peers
960 * @param first_cfg config for the first daemon
961 * @param second_cfg config for the second daemon
962 * @param first_daemon handle for the first daemon
963 * @param second_daemon handle for the second daemon
964 * @param emsg error message (NULL on success)
967 connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
968 const struct GNUNET_PeerIdentity *second, uint32_t distance,
969 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
970 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
971 struct GNUNET_TESTING_Daemon *first_daemon,
972 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
981 "Problem with new connection (%s)\n",
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (first));
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (second));
991 * run: load configuration options and schedule test to run (start peergroup)
995 * @param cfgfile configuration file name (can be NULL)
996 * @param cfg configuration handle
999 run (void *cls, char *const *args, const char *cfgfile,
1000 const struct GNUNET_CONFIGURATION_Handle *cfg)
1003 struct GNUNET_TESTING_Host *hosts;
1004 char *data_filename;
1007 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
1009 GNUNET_log_setup ("test_mesh_small",
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1019 "Starting daemons.\n");
1020 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing_old",
1021 "use_progressbars", "YES");
1025 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing_old",
1026 "num_peers", &num_peers))
1028 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1029 "Option TESTING:NUM_PEERS is required!\n");
1034 GNUNET_CONFIGURATION_get_value_time (testing_cfg, "test_mesh_small",
1035 "WAIT_TIME", &wait_time))
1037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1038 "Option test_mesh_small:wait_time is required!\n");
1043 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing_old",
1044 "topology_output_file",
1047 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1048 "Option test_mesh_small:topology_output_file is required!\n");
1053 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
1058 GNUNET_DISK_file_open (data_filename,
1059 GNUNET_DISK_OPEN_READWRITE |
1060 GNUNET_DISK_OPEN_CREATE,
1061 GNUNET_DISK_PERM_USER_READ |
1062 GNUNET_DISK_PERM_USER_WRITE);
1063 if (data_file == NULL)
1065 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1067 GNUNET_free (data_filename);
1072 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
1073 "output_file", &temp_str))
1076 GNUNET_DISK_file_open (temp_str,
1077 GNUNET_DISK_OPEN_READWRITE |
1078 GNUNET_DISK_OPEN_CREATE,
1079 GNUNET_DISK_PERM_USER_READ |
1080 GNUNET_DISK_PERM_USER_WRITE);
1081 if (output_file == NULL)
1082 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1085 GNUNET_free_non_null (temp_str);
1087 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
1089 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
1090 &connect_cb, &peergroup_ready, NULL,
1092 GNUNET_assert (pg != NULL);
1094 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1095 &shutdown_task, NULL);
1101 * test_mesh_small command line options
1103 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1104 {'V', "verbose", NULL,
1105 gettext_noop ("be verbose (print progress information)"),
1106 0, &GNUNET_GETOPT_set_one, &verbose},
1107 GNUNET_GETOPT_OPTION_END
1115 main (int argc, char *argv[])
1120 "test_mesh_small.conf",
1127 int argc2 = (sizeof (argv2) / sizeof (char *)) - 1;
1129 initialized = GNUNET_NO;
1131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n");
1132 if (strstr (argv[0], "test_mesh_small_unicast") != NULL)
1134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNICAST\n");
1136 test_name = "unicast";
1139 else if (strstr (argv[0], "test_mesh_small_multicast") != NULL)
1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MULTICAST\n");
1143 test_name = "multicast";
1146 else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
1148 /* Each peer is supposed to generate the following callbacks:
1149 * 1 incoming tunnel (@dest)
1150 * 1 connected peer (@orig)
1151 * TOTAL_PACKETS received data packet (@dest)
1152 * TOTAL_PACKETS received data packet (@orig)
1153 * 1 received tunnel destroy (@dest)
1154 * _________________________________
1155 * 5 x ok expected per peer
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1159 test_name = "speed ack";
1160 ok_goal = TOTAL_PACKETS * 2 + 3;
1161 argv2 [3] = NULL; // remove -L DEBUG
1166 else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
1168 /* Each peer is supposed to generate the following callbacks:
1169 * 1 incoming tunnel (@dest)
1170 * 1 connected peer (@orig)
1171 * TOTAL_PACKETS received data packet (@dest)
1172 * 1 received data packet (@orig)
1173 * 1 received tunnel destroy (@dest)
1174 * _________________________________
1176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1177 ok_goal = TOTAL_PACKETS + 4;
1178 if (strstr (argv[0], "_min") != NULL)
1181 test_name = "speed min";
1183 else if (strstr (argv[0], "_nobuf") != NULL)
1186 test_name = "speed nobuf";
1191 test_name = "speed";
1196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1201 if (strstr (argv[0], "backwards") != NULL)
1205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1206 test_backwards = GNUNET_YES;
1207 ok_goal++; // need one root->leaf packet to initialize tunnel
1208 aux = malloc (32); // "leaked"
1209 sprintf (aux, "backwards %s", test_name);
1213 GNUNET_PROGRAM_run (argc2, argv2,
1215 gettext_noop ("Test mesh in a small network."), options,
1218 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
1222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1223 "FAILED! (%d/%d)\n", ok, ok_goal);
1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1230 /* end of test_mesh_small.c */