2 This file is part of GNUnet.
3 Copyright (C) 2011, 2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file cadet/test_cadet.c
23 * @author Christian Grothoff
24 * @brief Test for the cadet service using mq API.
28 #include "cadet_test_lib.h"
29 #include "gnunet_cadet_service.h"
30 #include "gnunet_statistics_service.h"
35 * Ugly workaround to unify data handlers on incoming and outgoing channels.
37 struct CadetTestChannelWrapper
42 struct GNUNET_CADET_Channel *ch;
46 * How many messages to send by default.
48 #define TOTAL_PACKETS 500 /* Cannot exceed 64k! */
51 * How long until we give up on connecting the peers?
53 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
56 * Time to wait by default for stuff that should be rather fast.
58 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
61 * How fast do we send messages?
63 #define SEND_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 10)
66 * DIFFERENT TESTS TO RUN
78 * Which test are we running?
83 * String with test name
85 static char *test_name;
88 * Flag to send traffic leaf->root in speed tests to test BCK_ACK logic.
90 static int test_backwards = GNUNET_NO;
93 * How many packets to send.
95 static unsigned int total_packets;
98 * Time to wait for fast operations.
100 static struct GNUNET_TIME_Relative short_time;
103 * How many events have happened
108 * Number of events expected to conclude the test successfully.
113 * Size of each test packet's payload
115 static size_t size_payload = sizeof (uint32_t);
118 * Operation to get peer ids.
120 static struct GNUNET_TESTBED_Operation *t_op[2];
125 static struct GNUNET_PeerIdentity *p_id[2];
130 static struct GNUNET_HashCode port;
135 static unsigned int p_ids;
138 * Is the setup initialized?
140 static int initialized;
143 * Number of payload packes sent.
145 static int data_sent;
148 * Number of payload packets received.
150 static int data_received;
153 * Number of payload packed acknowledgements sent.
158 * Number of payload packed explicitly (app level) acknowledged.
160 static int ack_received;
163 * Total number of peers asked to run.
165 static unsigned long long peers_requested;
168 * Number of currently running peers (should be same as @c peers_requested).
170 static unsigned long long peers_running;
173 * Test context (to shut down).
175 struct GNUNET_CADET_TEST_Context *test_ctx;
178 * Task called to disconnect peers.
180 static struct GNUNET_SCHEDULER_Task *disconnect_task;
183 * Task called to reconnect peers.
185 static struct GNUNET_SCHEDULER_Task *reconnect_task;
188 * Task To perform tests
190 static struct GNUNET_SCHEDULER_Task *test_task;
193 * Task runnining #send_next_msg().
195 static struct GNUNET_SCHEDULER_Task *send_next_msg_task;
198 * Cadet handle for the root peer
200 static struct GNUNET_CADET_Handle *h1;
203 * Cadet handle for the first leaf peer
205 static struct GNUNET_CADET_Handle *h2;
208 * Channel handle for the root peer
210 static struct GNUNET_CADET_Channel *outgoing_ch;
213 * Channel handle for the dest peer
215 static struct GNUNET_CADET_Channel *incoming_ch;
218 * Time we started the data transmission (after channel has been established
221 static struct GNUNET_TIME_Absolute start_time;
226 static struct GNUNET_TESTBED_Peer **testbed_peers;
229 * Statistics operation handle.
231 static struct GNUNET_TESTBED_Operation *stats_op;
236 static unsigned int ka_sent;
239 * Keepalives received.
241 static unsigned int ka_received;
244 * How many messages were dropped by CADET because of full buffers?
246 static unsigned int msg_dropped;
249 /******************************************************************************/
252 /******************************************************************************/
256 * Get the channel considered as the "target" or "receiver", depending on
257 * the test type and size.
259 * @return Channel handle of the target client, either 0 (for backward tests)
260 * or the last peer in the line (for other tests).
262 static struct GNUNET_CADET_Channel *
263 get_target_channel ()
265 if (SPEED == test && GNUNET_YES == test_backwards)
273 * Show the results of the test (banwidth acheived) and log them to GAUGER
278 static struct GNUNET_TIME_Absolute end_time;
279 static struct GNUNET_TIME_Relative total_time;
281 end_time = GNUNET_TIME_absolute_get ();
282 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
284 "\nResults of test \"%s\"\n",
288 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
290 "Test bandwidth: %f kb/s\n",
291 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
293 "Test throughput: %f packets/s\n\n",
294 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
297 total_packets * 1000.0 / (total_time.rel_value_us / 1000),
303 * Disconnect from cadet services af all peers, call shutdown.
305 * @param cls Closure (line number from which termination was requested).
306 * @param tc Task Context.
309 disconnect_cadet_peers (void *cls)
311 long line = (long) cls;
313 disconnect_task = NULL;
314 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
315 "disconnecting cadet service of peers, called from line %ld\n",
317 for (unsigned int i = 0; i < 2; i++)
319 GNUNET_TESTBED_operation_done (t_op[i]);
321 if (NULL != outgoing_ch)
323 GNUNET_CADET_channel_destroy (outgoing_ch);
326 if (NULL != incoming_ch)
328 GNUNET_CADET_channel_destroy (incoming_ch);
331 GNUNET_CADET_TEST_cleanup (test_ctx);
332 GNUNET_SCHEDULER_shutdown ();
337 * Shut down peergroup, clean up.
339 * @param cls Closure (unused).
340 * @param tc Task Context.
343 shutdown_task (void *cls)
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
347 if (NULL != send_next_msg_task)
349 GNUNET_SCHEDULER_cancel (send_next_msg_task);
350 send_next_msg_task = NULL;
352 if (NULL != test_task)
354 GNUNET_SCHEDULER_cancel (test_task);
357 if (NULL != disconnect_task)
359 GNUNET_SCHEDULER_cancel (disconnect_task);
361 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
368 * Stats callback. Finish the stats testbed operation and when all stats have
369 * been iterated, shutdown the test.
371 * @param cls Closure (line number from which termination was requested).
372 * @param op the operation that has been finished
373 * @param emsg error message in case the operation has failed; will be NULL if
374 * operation has executed successfully.
377 stats_cont (void *cls,
378 struct GNUNET_TESTBED_Operation *op,
381 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
382 "KA sent: %u, KA received: %u\n",
385 if ((KEEPALIVE == test || REOPEN == test) &&
386 ((ka_sent < 2) || (ka_sent > ka_received + 1)))
391 GNUNET_TESTBED_operation_done (stats_op);
393 if (NULL != disconnect_task)
394 GNUNET_SCHEDULER_cancel (disconnect_task);
395 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
401 * Process statistic values.
403 * @param cls closure (line number, unused)
404 * @param peer the peer the statistic belong to
405 * @param subsystem name of subsystem that created the statistic
406 * @param name the name of the datum
407 * @param value the current value
408 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
409 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
412 stats_iterator (void *cls,
413 const struct GNUNET_TESTBED_Peer *peer,
414 const char *subsystem,
419 static const char *s_sent = "# keepalives sent";
420 static const char *s_recv = "# keepalives received";
421 static const char *rdrops = "# messages dropped due to full buffer";
422 static const char *cdrops = "# messages dropped due to slow client";
425 i = GNUNET_TESTBED_get_index (peer);
426 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i,
427 subsystem, name, (unsigned long long) value);
428 if (0 == strncmp (s_sent, name, strlen (s_sent)) && 0 == i)
430 if (0 == strncmp (s_recv, name, strlen (s_recv)) && peers_requested - 1 == i)
432 if (0 == strncmp (rdrops, name, strlen (rdrops)))
433 msg_dropped += value;
434 if (0 == strncmp (cdrops, name, strlen (cdrops)))
435 msg_dropped += value;
442 * Task to gather all statistics.
444 * @param cls Closure (line from which the task was scheduled).
447 gather_stats_and_exit (void *cls)
451 disconnect_task = NULL;
452 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
453 "gathering statistics from line %ld\n",
455 if (NULL != outgoing_ch)
457 GNUNET_CADET_channel_destroy (outgoing_ch);
460 stats_op = GNUNET_TESTBED_get_statistics (peers_running,
471 * Send a message on the channel with the appropriate size and payload.
473 * Update the appropriate *_sent counter.
475 * @param channel Channel to send the message on.
478 send_test_message (struct GNUNET_CADET_Channel *channel);
481 * Check if payload is sane (size contains payload).
483 * @param cls should match #ch
484 * @param message The actual message.
485 * @return #GNUNET_OK to keep the channel open,
486 * #GNUNET_SYSERR to close it (signal serious error).
489 check_data (void *cls,
490 const struct GNUNET_MessageHeader *message);
493 * Function is called whenever a message is received.
495 * @param cls closure (set from GNUNET_CADET_connect(), peer number)
496 * @param message the actual message
499 handle_data (void *cls,
500 const struct GNUNET_MessageHeader *message);
503 * Function called whenever an MQ-channel is destroyed, even if the destruction
504 * was requested by #GNUNET_CADET_channel_destroy.
505 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
507 * It should clean up any associated state, including cancelling any pending
508 * transmission on this channel.
510 * @param cls Channel closure (channel wrapper).
511 * @param channel Connection to the other end (henceforth invalid).
514 disconnect_handler (void *cls,
515 const struct GNUNET_CADET_Channel *channel);
519 * Task to reconnect to other peer.
521 * @param cls Closure (line from which the task was scheduled).
524 reconnect_op (void *cls)
526 struct GNUNET_MQ_MessageHandler handlers[] = {
527 GNUNET_MQ_hd_var_size (data,
528 GNUNET_MESSAGE_TYPE_DUMMY,
529 struct GNUNET_MessageHeader,
531 GNUNET_MQ_handler_end ()
534 struct CadetTestChannelWrapper *ch;
535 enum GNUNET_CADET_ChannelOption flags;
537 reconnect_task = NULL;
538 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
539 "reconnecting from line %ld\n",
541 if (NULL != outgoing_ch)
543 GNUNET_CADET_channel_destroy (outgoing_ch);
546 flags = GNUNET_CADET_OPTION_DEFAULT;
547 ch = GNUNET_new (struct CadetTestChannelWrapper);
548 outgoing_ch = GNUNET_CADET_channel_create (h1,
556 ch->ch = outgoing_ch;
557 send_test_message (outgoing_ch);
561 * Function called whenever an MQ-channel is destroyed, even if the destruction
562 * was requested by #GNUNET_CADET_channel_destroy.
563 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
565 * It should clean up any associated state, including cancelling any pending
566 * transmission on this channel.
568 * @param cls Channel closure (channel wrapper).
569 * @param channel Connection to the other end (henceforth invalid).
572 disconnect_handler (void *cls,
573 const struct GNUNET_CADET_Channel *channel)
575 struct CadetTestChannelWrapper *ch_w = cls;
577 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
578 "Channel disconnected at %d\n",
580 GNUNET_assert (ch_w->ch == channel);
581 if (channel == incoming_ch)
586 else if (outgoing_ch == channel)
588 if (P2P_SIGNAL == test)
595 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
596 "Unknown channel! %p\n",
598 if (NULL != disconnect_task && REOPEN != test)
600 GNUNET_SCHEDULER_cancel (disconnect_task);
602 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
605 else if (NULL != reconnect_task && REOPEN == test)
607 GNUNET_SCHEDULER_cancel (reconnect_task);
609 GNUNET_SCHEDULER_add_now (&reconnect_op,
617 * Abort test: schedule disconnect and shutdown immediately
619 * @param line Line in the code the abort is requested from (__LINE__).
622 abort_test (long line)
624 if (NULL != disconnect_task)
626 GNUNET_SCHEDULER_cancel (disconnect_task);
627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
628 "Aborting test from %ld\n",
631 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
638 * Send a message on the channel with the appropriate size and payload.
640 * Update the appropriate *_sent counter.
642 * @param channel Channel to send the message on.
645 send_test_message (struct GNUNET_CADET_Channel *channel)
647 struct GNUNET_MQ_Envelope *env;
648 struct GNUNET_MessageHeader *msg;
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Sending test message on channel %p\n",
657 if (GNUNET_NO == initialized)
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n");
662 if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer
665 else if (SPEED == test || SPEED_ACK == test)
667 if (get_target_channel() == channel)
672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
673 "Sending ACK %u [%d bytes]\n",
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
682 "Sending DATA %u [%d bytes]\n",
686 else if (FORWARD == test)
690 else if (P2P_SIGNAL == test)
694 else if (REOPEN == test)
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Sending DATA %u [%d bytes]\n",
706 env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY);
708 data = (uint32_t *) &msg[1];
709 *data = htonl (payload);
710 GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env);
715 * Task to request a new data transmission in a SPEED test, without waiting
716 * for previous messages to be sent/arrrive.
718 * @param cls Closure (unused).
721 send_next_msg (void *cls)
723 struct GNUNET_CADET_Channel *channel;
725 send_next_msg_task = NULL;
726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
727 "Sending next message: %d\n",
730 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch;
731 GNUNET_assert (NULL != channel);
732 GNUNET_assert (SPEED == test);
733 send_test_message (channel);
734 if (data_sent < total_packets)
736 /* SPEED test: Send all messages as soon as possible */
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Scheduling message %d\n",
741 GNUNET_SCHEDULER_add_delayed (SEND_INTERVAL,
749 * Every few messages cancel the timeout task and re-schedule it again, to
750 * avoid timing out when traffic keeps coming.
752 * @param line Code line number to log if a timeout occurs.
755 reschedule_timeout_task (long line)
759 if (NULL != disconnect_task)
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
762 "reschedule timeout every 10 messages\n");
763 GNUNET_SCHEDULER_cancel (disconnect_task);
764 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
765 &gather_stats_and_exit,
773 * Check if payload is sane (size contains payload).
775 * @param cls should match #ch
776 * @param message The actual message.
777 * @return #GNUNET_OK to keep the channel open,
778 * #GNUNET_SYSERR to close it (signal serious error).
781 check_data (void *cls,
782 const struct GNUNET_MessageHeader *message)
784 return GNUNET_OK; /* all is well-formed */
789 * Function is called whenever a message is received.
791 * @param cls closure (set from GNUNET_CADET_connect(), peer number)
792 * @param message the actual message
795 handle_data (void *cls,
796 const struct GNUNET_MessageHeader *message)
798 struct CadetTestChannelWrapper *ch = cls;
799 struct GNUNET_CADET_Channel *channel = ch->ch;
805 GNUNET_CADET_receive_done (channel);
806 counter = get_target_channel () == channel ? &data_received : &ack_received;
808 reschedule_timeout_task ((long) __LINE__);
810 if (channel == outgoing_ch)
812 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
813 "Root client got a message.\n");
815 else if (channel == incoming_ch)
817 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
818 "Leaf client got a message.\n");
822 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
823 "Unknown channel %p.\n",
828 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
832 data = (uint32_t *) &message[1];
833 payload = ntohl (*data);
834 if (payload == *counter)
836 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
837 " payload as expected: %u\n",
842 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
843 " payload %u, expected: %u\n",
847 if (GNUNET_NO == initialized)
849 initialized = GNUNET_YES;
850 start_time = GNUNET_TIME_absolute_get ();
853 GNUNET_assert (incoming_ch == channel);
854 send_next_msg_task = GNUNET_SCHEDULER_add_now (&send_next_msg,
861 if (get_target_channel () == channel) /* Got "data" */
863 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received);
864 if (SPEED != test || (ok_goal - 2) == ok)
867 send_test_message (channel);
872 if (data_received < total_packets)
878 if (SPEED_ACK == test || SPEED == test)
880 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
882 send_test_message (channel);
883 if (ack_received < total_packets && SPEED != test)
885 if (ok == 2 && SPEED == test)
889 if (test == P2P_SIGNAL)
891 GNUNET_CADET_channel_destroy (incoming_ch);
896 GNUNET_CADET_channel_destroy (outgoing_ch);
904 * Method called whenever a peer connects to a port in MQ-based CADET.
906 * @param cls Closure from #GNUNET_CADET_open_port (peer # as long).
907 * @param channel New handle to the channel.
908 * @param source Peer that started this channel.
909 * @return Closure for the incoming @a channel. It's given to:
910 * - The #GNUNET_CADET_DisconnectEventHandler (given to
911 * #GNUNET_CADET_open_port) when the channel dies.
912 * - Each the #GNUNET_MQ_MessageCallback handlers for each message
913 * received on the @a channel.
916 connect_handler (void *cls,
917 struct GNUNET_CADET_Channel *channel,
918 const struct GNUNET_PeerIdentity *source)
920 struct CadetTestChannelWrapper *ch;
921 long peer = (long) cls;
923 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
924 "Incoming channel from %s to %ld: %p\n",
929 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
932 if (peer == peers_requested - 1)
934 if (NULL != incoming_ch)
936 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
937 "Duplicate incoming channel for client %lu\n",
941 incoming_ch = channel;
945 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
946 "Incoming channel for unexpected peer #%lu\n",
950 if (NULL != disconnect_task && REOPEN != test)
952 GNUNET_SCHEDULER_cancel (disconnect_task);
953 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
954 &gather_stats_and_exit,
957 else if ((NULL != disconnect_task) && (REOPEN == test))
959 GNUNET_SCHEDULER_cancel (disconnect_task);
960 disconnect_task = GNUNET_SCHEDULER_add_delayed (
961 GNUNET_TIME_relative_multiply (short_time, 2),
962 &gather_stats_and_exit,
966 if ((NULL != reconnect_task) && (REOPEN == test))
968 GNUNET_SCHEDULER_cancel (reconnect_task);
969 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
974 /* TODO: cannot return channel as-is, in order to unify the data handlers */
975 ch = GNUNET_new (struct CadetTestChannelWrapper);
983 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
985 * Testcase continues when the root receives confirmation of connected peers,
986 * on callback function ch.
988 * @param cls Closure (unused).
991 start_test (void *cls)
993 struct GNUNET_MQ_MessageHandler handlers[] = {
994 GNUNET_MQ_hd_var_size (data,
995 GNUNET_MESSAGE_TYPE_DUMMY,
996 struct GNUNET_MessageHeader,
998 GNUNET_MQ_handler_end ()
1000 struct CadetTestChannelWrapper *ch;
1001 enum GNUNET_CADET_ChannelOption flags;
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
1005 if (NULL != disconnect_task)
1007 GNUNET_SCHEDULER_cancel (disconnect_task);
1008 disconnect_task = NULL;
1011 flags = GNUNET_CADET_OPTION_DEFAULT;
1012 if (SPEED_REL == test)
1015 flags |= GNUNET_CADET_OPTION_RELIABLE;
1018 ch = GNUNET_new (struct CadetTestChannelWrapper);
1019 outgoing_ch = GNUNET_CADET_channel_create (h1,
1025 &disconnect_handler,
1028 ch->ch = outgoing_ch;
1030 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1031 &gather_stats_and_exit,
1033 if (KEEPALIVE == test)
1034 return; /* Don't send any data. */
1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1041 "Sending data initializer on channel %p...\n",
1043 send_test_message (outgoing_ch);
1046 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1049 GNUNET_SCHEDULER_cancel (disconnect_task);
1050 disconnect_task = GNUNET_SCHEDULER_add_delayed (
1051 GNUNET_TIME_relative_multiply (short_time, 2),
1052 &gather_stats_and_exit,
1060 * Callback to be called when the requested peer information is available
1062 * @param cls the closure from GNUNET_TESTBED_peer_get_information()
1063 * @param op the operation this callback corresponds to
1064 * @param pinfo the result; will be NULL if the operation has failed
1065 * @param emsg error message if the operation has failed;
1066 * NULL if the operation is successfull
1070 struct GNUNET_TESTBED_Operation *op,
1071 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1074 long i = (long) cls;
1076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1077 "ID callback for %ld\n",
1079 if ( (NULL == pinfo) ||
1082 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1085 abort_test (__LINE__);
1088 p_id[i] = pinfo->result.id;
1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1091 GNUNET_i2s (p_id[i]));
1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1096 "Got all IDs, starting test\n");
1097 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
1102 * test main: start test when all peers are connected
1104 * @param cls Closure.
1105 * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end.
1106 * @param num_peers Number of peers that are running.
1107 * @param peers Array of peers.
1108 * @param cadets Handle to each of the CADETs of the peers.
1112 struct GNUNET_CADET_TEST_Context *ctx,
1113 unsigned int num_peers,
1114 struct GNUNET_TESTBED_Peer **peers,
1115 struct GNUNET_CADET_Handle **cadets)
1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
1120 peers_running = num_peers;
1121 GNUNET_assert (peers_running == peers_requested);
1122 testbed_peers = peers;
1124 h2 = cadets[num_peers - 1];
1125 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1126 &disconnect_cadet_peers,
1128 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1130 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
1131 GNUNET_TESTBED_PIT_IDENTITY,
1134 t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1],
1135 GNUNET_TESTBED_PIT_IDENTITY,
1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
1146 main (int argc, char *argv[])
1148 static const struct GNUNET_HashCode *ports[2];
1149 struct GNUNET_MQ_MessageHandler handlers[] = {
1150 GNUNET_MQ_hd_var_size (data,
1151 GNUNET_MESSAGE_TYPE_DUMMY,
1152 struct GNUNET_MessageHeader,
1154 GNUNET_MQ_handler_end ()
1156 const char *config_file;
1157 char port_id[] = "test port";
1158 struct GNUNET_GETOPT_CommandLineOption options[] = {
1159 GNUNET_GETOPT_option_relative_time ('t',
1162 gettext_noop ("set short timeout"),
1164 GNUNET_GETOPT_option_uint ('m',
1167 gettext_noop ("set number of messages to send"),
1170 GNUNET_GETOPT_OPTION_END
1174 initialized = GNUNET_NO;
1175 GNUNET_log_setup ("test", "DEBUG", NULL);
1177 total_packets = TOTAL_PACKETS;
1178 short_time = SHORT_TIME;
1179 if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv))
1181 FPRINTF (stderr, "test failed: problem with CLI parameters\n");
1185 config_file = "test_cadet.conf";
1186 GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port);
1188 /* Find out requested size */
1189 if (strstr (argv[0], "_2_") != NULL)
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DIRECT CONNECTIONs\n");
1192 peers_requested = 2;
1194 else if (strstr (argv[0], "_5_") != NULL)
1196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n");
1197 peers_requested = 5;
1199 else if (strstr (argv[0], "_6_") != NULL)
1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "6 PEER LINE\n");
1202 peers_requested = 6;
1206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n");
1207 peers_requested = 2;
1210 /* Find out requested test */
1211 if (strstr (argv[0], "_forward") != NULL)
1213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n");
1215 test_name = "unicast";
1218 else if (strstr (argv[0], "_signal") != NULL)
1220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n");
1222 test_name = "signal";
1225 else if (strstr (argv[0], "_speed_ack") != NULL)
1227 /* Test is supposed to generate the following callbacks:
1228 * 1 incoming channel (@dest)
1229 * total_packets received data packet (@dest)
1230 * total_packets received data packet (@orig)
1231 * 1 received channel destroy (@dest)
1233 ok_goal = total_packets * 2 + 2;
1234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1236 test_name = "speed ack";
1238 else if (strstr (argv[0], "_speed") != NULL)
1240 /* Test is supposed to generate the following callbacks:
1241 * 1 incoming channel (@dest)
1242 * 1 initial packet (@dest)
1243 * total_packets received data packet (@dest)
1244 * 1 received data packet (@orig)
1245 * 1 received channel destroy (@dest)
1247 ok_goal = total_packets + 4;
1248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1249 if (strstr (argv[0], "_reliable") != NULL)
1252 test_name = "speed reliable";
1253 config_file = "test_cadet_drop.conf";
1258 test_name = "speed";
1261 else if (strstr (argv[0], "_keepalive") != NULL)
1264 /* Test is supposed to generate the following callbacks:
1265 * 1 incoming channel (@dest)
1267 * 1 received channel destroy (@dest)
1271 else if (strstr (argv[0], "_reopen") != NULL)
1274 test_name = "reopen";
1275 ///* Test is supposed to generate the following callbacks:
1276 // * 1 incoming channel (@dest)
1278 // * 1 received channel destroy (@dest)
1284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1289 if (strstr (argv[0], "backwards") != NULL)
1291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1292 test_backwards = GNUNET_YES;
1293 GNUNET_asprintf (&test_name, "backwards %s", test_name);
1299 GNUNET_CADET_TEST_ruN ("test_cadet_small",
1303 NULL, /* tmain cls */
1306 &disconnect_handler,
1309 if (NULL != strstr (argv[0], "_reliable"))
1310 msg_dropped = 0; /* dropped should be retransmitted */
1312 if (ok_goal > ok - msg_dropped)
1314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FAILED! (%d/%d)\n", ok, ok_goal);
1317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1321 /* end of test_cadet.c */