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 * 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 (message type).
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 (message type).
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 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
517 GNUNET_SCHEDULER_cancel (disconnect_task);
519 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
527 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n");
528 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
530 if (test == MULTICAST && peers_responded < 2)
535 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
536 "Leaf client %li got a message.\n",
538 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
546 if (SPEED == test && GNUNET_YES == test_backwards)
548 expected_target_client = 1L;
552 expected_target_client = 2L;
555 if (GNUNET_NO == initialized)
557 initialized = GNUNET_YES;
558 start_time = GNUNET_TIME_absolute_get ();
561 GNUNET_assert (2L == client);
562 GNUNET_SCHEDULER_add_now (&data_task, NULL);
567 if (client == expected_target_client) // Normally 2 or 3
570 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
571 " received data %u\n", data_received);
572 if (SPEED != test || (ok_goal - 2) == ok)
574 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
575 GNUNET_TIME_UNIT_FOREVER_REL, sender,
576 sizeof (struct GNUNET_MessageHeader),
577 &tmt_rdy, (void *) 1L);
581 if (data_received < TOTAL_PACKETS)
587 if (test == SPEED_ACK || test == SPEED)
590 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
591 " received ack %u\n", data_ack);
592 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
593 GNUNET_TIME_UNIT_FOREVER_REL, sender,
594 sizeof (struct GNUNET_MessageHeader),
595 &tmt_rdy, (void *) 1L);
596 if (data_ack < TOTAL_PACKETS && SPEED != test)
598 if (ok == 2 && SPEED == test)
602 GNUNET_MESH_tunnel_destroy (t);
606 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
608 GNUNET_SCHEDULER_cancel (disconnect_task);
610 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
619 * Handlers, for diverse services
621 static struct GNUNET_MESH_MessageHandler handlers[] = {
622 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
628 * Method called whenever another peer has added us to a tunnel
629 * the other peer initiated.
632 * @param tunnel new handle to the tunnel
633 * @param initiator peer that started the tunnel
634 * @param atsi performance information for the tunnel
635 * @return initial tunnel context for the tunnel
636 * (can be NULL -- that's not an error)
639 incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
640 const struct GNUNET_PeerIdentity *initiator,
641 const struct GNUNET_ATS_Information *atsi)
643 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
644 "Incoming tunnel from %s to peer %d\n",
645 GNUNET_i2s (initiator), (long) cls);
647 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
648 if ((long) cls == 2L)
650 else if ((long) cls == 3L)
651 incoming_t2 = tunnel;
654 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
655 "Incoming tunnel for unknown client %lu\n", (long) cls);
658 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
660 GNUNET_SCHEDULER_cancel (disconnect_task);
662 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
669 * Function called whenever an inbound tunnel is destroyed. Should clean up
670 * any associated state.
672 * @param cls closure (set from GNUNET_MESH_connect)
673 * @param tunnel connection to the other end (henceforth invalid)
674 * @param tunnel_ctx place where local state associated
675 * with the tunnel is stored
678 tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
683 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
684 "Incoming tunnel disconnected at peer %d\n",
697 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
698 "Unknown peer! %d\n", i);
699 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
701 if (peers_in_tunnel > 0)
704 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
706 GNUNET_SCHEDULER_cancel (disconnect_task);
707 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
715 * Method called whenever a tunnel falls apart.
718 * @param peer peer identity the tunnel stopped working with
721 dh (void *cls, const struct GNUNET_PeerIdentity *peer)
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "peer %s disconnected\n",
731 * Method called whenever a peer connects to a tunnel.
734 * @param peer peer identity the tunnel was created to, NULL on timeout
735 * @param atsi performance data for the connection
738 ch (void *cls, const struct GNUNET_PeerIdentity *peer,
739 const struct GNUNET_ATS_Information *atsi)
741 struct GNUNET_PeerIdentity *dest;
743 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
744 "peer %s connected\n", GNUNET_i2s (peer));
746 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
750 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
755 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
761 // incoming_t is NULL unless we send a relevant data packet
766 if (peers_in_tunnel < 2)
774 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
776 GNUNET_SCHEDULER_cancel (disconnect_task);
778 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "Sending data initializer...\n");
785 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
786 GNUNET_TIME_UNIT_FOREVER_REL, dest,
787 sizeof (struct GNUNET_MessageHeader),
788 &tmt_rdy, (void *) 1L);
792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
793 "Disconnect already run?\n");
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
802 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
804 * Testcase continues when the root receives confirmation of connected peers,
805 * on callback funtion ch.
807 * @param cls Closure (unsued).
808 * @param tc Task Context.
811 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
815 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
817 if (test == MULTICAST)
819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
821 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
825 "schedule timeout in SHORT_TIME\n");
826 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
828 GNUNET_SCHEDULER_cancel (disconnect_task);
830 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
836 * connect_mesh_service: connect to the mesh service of one of the peers
838 * @param cls Closure (unsued).
839 * @param tc Task Context.
842 connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
844 GNUNET_MESH_ApplicationType app;
846 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
850 "connect_mesh_service\n");
852 d2 = GNUNET_TESTING_daemon_get (pg, num_peers - 1);
853 if (test == MULTICAST)
855 d3 = GNUNET_TESTING_daemon_get (pg, num_peers - 2);
857 app = (GNUNET_MESH_ApplicationType) 0;
860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
861 "connecting to mesh service of peer %s\n",
862 GNUNET_i2s (&d1->id));
863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
864 "connecting to mesh service of peer %s\n",
865 GNUNET_i2s (&d2->id));
866 if (test == MULTICAST)
868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
869 "connecting to mesh service of peer %s\n",
870 GNUNET_i2s (&d3->id));
873 h1 = GNUNET_MESH_connect (d1->cfg, (void *) 1L, NULL, &tunnel_cleaner,
875 h2 = GNUNET_MESH_connect (d2->cfg, (void *) 2L, &incoming_tunnel,
876 &tunnel_cleaner, handlers, &app);
877 if (test == MULTICAST)
879 h3 = GNUNET_MESH_connect (d3->cfg, (void *) 3L, &incoming_tunnel,
880 &tunnel_cleaner, handlers, &app);
882 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
883 if (SPEED_MIN == test)
885 GNUNET_MESH_tunnel_speed_min(t);
888 if (SPEED_NOBUF == test)
890 GNUNET_MESH_tunnel_buffer(t, GNUNET_NO);
895 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
896 (GNUNET_TIME_UNIT_SECONDS, 1), &do_test,
903 * peergroup_ready: start test when all peers are connected
906 * @param emsg error message
909 peergroup_ready (void *cls, const char *emsg)
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
918 "Peergroup callback called with error, aborting test!\n");
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
920 "Error from testing: `%s'\n", emsg);
922 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
927 "************************************************************\n");
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
929 "Peer Group started successfully!\n");
930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
931 "Have %u connections\n",
935 if (data_file != NULL)
938 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
940 GNUNET_DISK_file_write (data_file, buf, buf_len);
943 peers_running = GNUNET_TESTING_daemons_running (pg);
944 for (i = 0; i < num_peers; i++)
946 GNUNET_PEER_Id peer_id;
948 d1 = GNUNET_TESTING_daemon_get (pg, i);
949 peer_id = GNUNET_PEER_intern (&d1->id);
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n",
951 peer_id, GNUNET_i2s (&d1->id));
953 d1 = GNUNET_TESTING_daemon_get (pg, 0);
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
955 "Peer looking: %s\n",
956 GNUNET_i2s (&d1->id));
958 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
960 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
966 * Function that will be called whenever two daemons are connected by
967 * the testing library.
970 * @param first peer id for first daemon
971 * @param second peer id for the second daemon
972 * @param distance distance between the connected peers
973 * @param first_cfg config for the first daemon
974 * @param second_cfg config for the second daemon
975 * @param first_daemon handle for the first daemon
976 * @param second_daemon handle for the second daemon
977 * @param emsg error message (NULL on success)
980 connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
981 const struct GNUNET_PeerIdentity *second, uint32_t distance,
982 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
983 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
984 struct GNUNET_TESTING_Daemon *first_daemon,
985 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
994 "Problem with new connection (%s)\n",
996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (first));
997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (%s)\n", GNUNET_i2s (second));
1004 * run: load configuration options and schedule test to run (start peergroup)
1006 * @param cls closure
1008 * @param cfgfile configuration file name (can be NULL)
1009 * @param cfg configuration handle
1012 run (void *cls, char *const *args, const char *cfgfile,
1013 const struct GNUNET_CONFIGURATION_Handle *cfg)
1016 struct GNUNET_TESTING_Host *hosts;
1017 char *data_filename;
1020 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
1022 GNUNET_log_setup ("test_mesh_small",
1031 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1032 "Starting daemons.\n");
1033 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing_old",
1034 "use_progressbars", "YES");
1038 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing_old",
1039 "num_peers", &num_peers))
1041 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1042 "Option TESTING:NUM_PEERS is required!\n");
1047 GNUNET_CONFIGURATION_get_value_time (testing_cfg, "test_mesh_small",
1048 "WAIT_TIME", &wait_time))
1050 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1051 "Option test_mesh_small:wait_time is required!\n");
1056 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing_old",
1057 "topology_output_file",
1060 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1061 "Option test_mesh_small:topology_output_file is required!\n");
1066 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
1071 GNUNET_DISK_file_open (data_filename,
1072 GNUNET_DISK_OPEN_READWRITE |
1073 GNUNET_DISK_OPEN_CREATE,
1074 GNUNET_DISK_PERM_USER_READ |
1075 GNUNET_DISK_PERM_USER_WRITE);
1076 if (data_file == NULL)
1078 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1080 GNUNET_free (data_filename);
1085 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
1086 "output_file", &temp_str))
1089 GNUNET_DISK_file_open (temp_str,
1090 GNUNET_DISK_OPEN_READWRITE |
1091 GNUNET_DISK_OPEN_CREATE,
1092 GNUNET_DISK_PERM_USER_READ |
1093 GNUNET_DISK_PERM_USER_WRITE);
1094 if (output_file == NULL)
1095 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
1098 GNUNET_free_non_null (temp_str);
1100 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
1102 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
1103 &connect_cb, &peergroup_ready, NULL,
1105 GNUNET_assert (pg != NULL);
1107 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1108 &shutdown_task, NULL);
1114 * test_mesh_small command line options
1116 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1117 {'V', "verbose", NULL,
1118 gettext_noop ("be verbose (print progress information)"),
1119 0, &GNUNET_GETOPT_set_one, &verbose},
1120 GNUNET_GETOPT_OPTION_END
1128 main (int argc, char *argv[])
1133 "test_mesh_small.conf",
1140 int argc2 = (sizeof (argv2) / sizeof (char *)) - 1;
1142 initialized = GNUNET_NO;
1144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n");
1145 if (strstr (argv[0], "test_mesh_small_unicast") != NULL)
1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNICAST\n");
1149 test_name = "unicast";
1152 else if (strstr (argv[0], "test_mesh_small_multicast") != NULL)
1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MULTICAST\n");
1156 test_name = "multicast";
1159 else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
1161 /* Each peer is supposed to generate the following callbacks:
1162 * 1 incoming tunnel (@dest)
1163 * 1 connected peer (@orig)
1164 * TOTAL_PACKETS received data packet (@dest)
1165 * TOTAL_PACKETS received data packet (@orig)
1166 * 1 received tunnel destroy (@dest)
1167 * _________________________________
1168 * 5 x ok expected per peer
1170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1172 test_name = "speed ack";
1173 ok_goal = TOTAL_PACKETS * 2 + 3;
1174 argv2 [3] = NULL; // remove -L DEBUG
1179 else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
1181 /* Each peer is supposed to generate the following callbacks:
1182 * 1 incoming tunnel (@dest)
1183 * 1 connected peer (@orig)
1184 * TOTAL_PACKETS received data packet (@dest)
1185 * 1 received data packet (@orig)
1186 * 1 received tunnel destroy (@dest)
1187 * _________________________________
1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1190 ok_goal = TOTAL_PACKETS + 4;
1191 if (strstr (argv[0], "_min") != NULL)
1194 test_name = "speed min";
1196 else if (strstr (argv[0], "_nobuf") != NULL)
1199 test_name = "speed nobuf";
1204 test_name = "speed";
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1214 if (strstr (argv[0], "backwards") != NULL)
1218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1219 test_backwards = GNUNET_YES;
1220 ok_goal++; // need one root->leaf packet to initialize tunnel
1221 aux = malloc (32); // "leaked"
1222 sprintf (aux, "backwards %s", test_name);
1226 GNUNET_PROGRAM_run (argc2, argv2,
1228 gettext_noop ("Test mesh in a small network."), options,
1231 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
1235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1236 "FAILED! (%d/%d)\n", ok, ok_goal);
1239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1243 /* end of test_mesh_small.c */