2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file cadet/gnunet-cadet-profiler.c
23 * @brief Profiler for cadet experiments.
27 #include "cadet_test_lib.h"
28 #include "gnunet_cadet_service.h"
29 #include "gnunet_statistics_service.h"
37 * Paximum ping period in milliseconds. Real period = rand (0, PING_PERIOD)
39 #define PING_PERIOD 500
42 * How long until we give up on connecting the peers?
44 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
47 * Time to wait for stuff that should be rather fast
49 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
52 * Total number of rounds.
54 #define number_rounds sizeof(rounds)/sizeof(rounds[0])
57 * Ratio of peers active. First round always is 1.0.
59 static float rounds[] = {0.8, 0.6, 0.8, 0.5, 0.3, 0.8, 0.0};
62 * Message type for pings.
64 struct CadetPingMessage
67 * Header. Type PING/PONG.
69 struct GNUNET_MessageHeader header;
77 * Time the message was sent.
79 struct GNUNET_TIME_AbsoluteNBO timestamp;
84 uint32_t round_number;
93 * Testbed Operation (to get peer id, etc).
95 struct GNUNET_TESTBED_Operation *op;
100 struct GNUNET_PeerIdentity id;
103 * Cadet handle for the root peer
105 struct GNUNET_CADET_Handle *cadet;
108 * Channel handle for the root peer
110 struct GNUNET_CADET_Channel *ch;
113 * Channel handle for the dest peer
115 struct GNUNET_CADET_Channel *incoming_ch;
118 * Channel handle for a warmup channel.
120 struct GNUNET_CADET_Channel *warmup_ch;
123 * Number of payload packes sent
128 * Number of payload packets received
138 * Destinaton to ping.
140 struct CadetPeer *dest;
143 * Incoming channel for pings.
145 struct CadetPeer *incoming;
148 * Task to do the next ping.
150 struct GNUNET_SCHEDULER_Task *ping_task;
153 * NTR operation for the next ping.
155 struct GNUNET_CADET_TransmitHandle *ping_ntr;
157 float mean[number_rounds];
158 float var[number_rounds];
159 unsigned int pongs[number_rounds];
160 unsigned int pings[number_rounds];
165 * Duration of each round.
167 static struct GNUNET_TIME_Relative round_time;
170 * GNUNET_PeerIdentity -> CadetPeer
172 static struct GNUNET_CONTAINER_MultiPeerMap *ids;
175 * Testbed peer handles.
177 static struct GNUNET_TESTBED_Peer **testbed_handles;
180 * Testbed Operation (to get stats).
182 static struct GNUNET_TESTBED_Operation *stats_op;
185 * Operation to get peer ids.
187 static struct CadetPeer *peers;
192 static unsigned int p_ids;
195 * Total number of peers.
197 static unsigned long long peers_total;
200 * Number of currently running peers.
202 static unsigned long long peers_running;
205 * Number of peers doing pings.
207 static unsigned long long peers_pinging;
210 * Test context (to shut down).
212 static struct GNUNET_CADET_TEST_Context *test_ctx;
215 * Task called to disconnect peers, before shutdown.
217 static struct GNUNET_SCHEDULER_Task *disconnect_task;
220 * Task to perform tests
222 static struct GNUNET_SCHEDULER_Task *test_task;
227 static unsigned int current_round;
230 * Do preconnect? (Each peer creates a tunnel to one other peer).
232 static int do_warmup;
237 static unsigned int peers_warmup;
240 * Flag to notify callbacks not to generate any new traffic anymore.
242 static int test_finished;
245 * Task running each round of the benchmark.
247 static struct GNUNET_SCHEDULER_Task *round_task;
251 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
253 * Testcase continues when the root receives confirmation of connected peers,
254 * on callback funtion ch.
256 * @param cls Closure (unsued).
259 start_test (void *cls);
263 * Calculate a random delay.
265 * @param max Exclusive maximum, in ms.
267 * @return A time between 0 a max-1 ms.
269 static struct GNUNET_TIME_Relative
270 delay_ms_rnd (unsigned int max)
274 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
275 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
280 * Get the index of a peer in the peers array.
282 * @param peer Peer whose index to get.
284 * @return Index of peer in peers.
287 get_index (struct CadetPeer *peer)
294 * Show the results of the test (banwidth acheived) and log them to GAUGER
299 struct CadetPeer *peer;
303 for (i = 0; i < number_rounds; i++)
305 for (j = 0; j < peers_pinging; j++)
309 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
310 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
311 peer->pings[i], peer->pongs[i]);
318 * Disconnect from cadet services af all peers, call shutdown.
320 * @param cls Closure (unused).
323 disconnect_cadet_peers (void *cls)
325 long line = (long) cls;
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 "disconnecting cadet service, called from line %ld\n",
331 disconnect_task = NULL;
332 for (i = 0; i < peers_total; i++)
334 if (NULL != peers[i].op)
335 GNUNET_TESTBED_operation_done (peers[i].op);
337 if (peers[i].up != GNUNET_YES)
340 if (NULL != peers[i].ch)
342 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
343 "%u: channel %p\n", i, peers[i].ch);
344 GNUNET_CADET_channel_destroy (peers[i].ch);
346 if (NULL != peers[i].warmup_ch)
348 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 "%u: warmup channel %p\n",
350 i, peers[i].warmup_ch);
351 GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
353 if (NULL != peers[i].incoming_ch)
355 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
356 "%u: incoming channel %p\n",
357 i, peers[i].incoming_ch);
358 GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
361 GNUNET_CADET_TEST_cleanup (test_ctx);
362 GNUNET_SCHEDULER_shutdown ();
367 * Shut down peergroup, clean up.
369 * @param cls Closure (unused).
372 shutdown_task (void *cls)
374 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
376 if (NULL != disconnect_task)
378 GNUNET_SCHEDULER_cancel (disconnect_task);
379 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
382 if (NULL != round_task)
384 GNUNET_SCHEDULER_cancel (round_task);
387 if (NULL != test_task)
389 GNUNET_SCHEDULER_cancel (test_task);
396 * Finish test normally: schedule disconnect and shutdown
398 * @param line Line in the code the abort is requested from (__LINE__).
401 abort_test (long line)
403 if (disconnect_task != NULL)
405 GNUNET_SCHEDULER_cancel (disconnect_task);
406 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
412 * Stats callback. Finish the stats testbed operation and when all stats have
413 * been iterated, shutdown the test.
416 * @param op the operation that has been finished
417 * @param emsg error message in case the operation has failed; will be NULL if
418 * operation has executed successfully.
421 stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
423 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
424 GNUNET_TESTBED_operation_done (stats_op);
426 if (NULL != disconnect_task)
427 GNUNET_SCHEDULER_cancel (disconnect_task);
428 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
435 * Process statistic values.
438 * @param peer the peer the statistic belong to
439 * @param subsystem name of subsystem that created the statistic
440 * @param name the name of the datum
441 * @param value the current value
442 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
443 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
446 stats_iterator (void *cls,
447 const struct GNUNET_TESTBED_Peer *peer,
448 const char *subsystem,
455 i = GNUNET_TESTBED_get_index (peer);
456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
457 " STATS %u - %s [%s]: %llu\n",
459 (unsigned long long) value);
466 * Task check that keepalives were sent and received.
468 * @param cls Closure (NULL).
471 collect_stats (void *cls)
473 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
474 "Start collecting statistics...\n");
475 stats_op = GNUNET_TESTBED_get_statistics (peers_total,
484 * @brief Finish profiler normally. Signal finish and start collecting stats.
486 * @param cls Closure (unused).
489 finish_profiler (void *cls)
491 test_finished = GNUNET_YES;
493 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
498 * Set the total number of running peers.
500 * @param target Desired number of running peers.
503 adjust_running_peers (unsigned int target)
505 struct GNUNET_TESTBED_Operation *op;
511 GNUNET_assert (target <= peers_total);
513 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
514 if (target > peers_running)
516 delta = target - peers_running;
521 delta = peers_running - target;
525 for (i = 0; i < delta; i++)
528 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
529 peers_total - peers_pinging);
531 } while (peers[r].up == run || NULL != peers[r].incoming);
532 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
533 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
535 if (NULL != peers[r].ping_task)
537 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
538 peers[r].ping_task = NULL;
540 if (NULL != peers[r].ping_ntr)
542 GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
543 peers[r].ping_ntr = NULL;
547 if (NULL != peers[r].ch)
548 GNUNET_CADET_channel_destroy (peers[r].ch);
550 if (NULL != peers[r].dest)
552 if (NULL != peers[r].dest->incoming_ch)
553 GNUNET_CADET_channel_destroy (peers[r].dest->incoming_ch);
554 peers[r].dest->incoming_ch = NULL;
557 op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
558 "cadet", NULL, NULL, run);
559 GNUNET_break (NULL != op);
560 peers_running += run ? 1 : -1;
561 GNUNET_assert (peers_running > 0);
567 * @brief Move to next round.
569 * @param cls Closure (round #).
574 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
577 if (0.0 == rounds[current_round])
579 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
580 GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
583 adjust_running_peers (rounds[current_round] * peers_total);
586 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
593 * Transmit ping callback.
595 * @param cls Closure (peer for PING, NULL for PONG).
596 * @param size Size of the tranmist buffer.
597 * @param buf Pointer to the beginning of the buffer.
599 * @return Number of bytes written to buf.
602 tmt_rdy_ping (void *cls, size_t size, void *buf);
606 * Transmit pong callback.
608 * @param cls Closure (copy of PING message, to be freed).
609 * @param size Size of the buffer we have.
610 * @param buf Buffer to copy data to.
613 tmt_rdy_pong (void *cls, size_t size, void *buf)
615 struct CadetPingMessage *ping = cls;
616 struct CadetPingMessage *pong;
618 if (0 == size || NULL == buf)
623 pong = (struct CadetPingMessage *) buf;
624 GNUNET_memcpy (pong, ping, sizeof (*ping));
625 pong->header.type = htons (PONG);
628 return sizeof (*ping);
633 * @brief Send a ping to destination
635 * @param cls Closure (peer).
640 struct CadetPeer *peer = cls;
642 peer->ping_task = NULL;
643 if (GNUNET_YES == test_finished)
645 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
648 get_index (peer->dest),
650 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
651 GNUNET_TIME_UNIT_FOREVER_REL,
652 sizeof (struct CadetPingMessage),
653 &tmt_rdy_ping, peer);
657 * @brief Reply with a pong to origin.
659 * @param cls Closure (peer).
660 * @param tc Task context.
663 pong (struct GNUNET_CADET_Channel *channel,
664 const struct CadetPingMessage *ping)
666 struct CadetPingMessage *copy;
668 copy = GNUNET_new (struct CadetPingMessage);
670 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
671 GNUNET_TIME_UNIT_FOREVER_REL,
672 sizeof (struct CadetPingMessage),
673 &tmt_rdy_pong, copy);
678 * Transmit ping callback
680 * @param cls Closure (peer).
681 * @param size Size of the buffer we have.
682 * @param buf Buffer to copy data to.
685 tmt_rdy_ping (void *cls, size_t size, void *buf)
687 struct CadetPeer *peer = cls;
688 struct CadetPingMessage *msg = buf;
690 peer->ping_ntr = NULL;
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
692 "tmt_rdy called, filling buffer\n");
693 if (size < sizeof (struct CadetPingMessage) || NULL == buf)
695 GNUNET_break (GNUNET_YES == test_finished);
696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
697 "size %u, buf %p, data_sent %u, data_received %u\n",
701 peer->data_received);
705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708 msg->header.size = htons (size);
709 msg->header.type = htons (PING);
710 msg->counter = htonl (peer->data_sent++);
711 msg->round_number = htonl (current_round);
712 msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
713 peer->pings[current_round]++;
714 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
717 return sizeof (struct CadetPingMessage);
722 * Function is called whenever a PING message is received.
724 * @param cls closure (peer #, set from GNUNET_CADET_connect)
725 * @param channel connection to the other end
726 * @param channel_ctx place to store local state associated with the channel
727 * @param message the actual message
728 * @return GNUNET_OK to keep the connection open,
729 * GNUNET_SYSERR to close it (signal serious error)
732 ping_handler (void *cls, struct GNUNET_CADET_Channel *channel,
734 const struct GNUNET_MessageHeader *message)
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
741 GNUNET_CADET_receive_done (channel);
742 if (GNUNET_NO == test_finished)
743 pong (channel, (struct CadetPingMessage *) message);
750 * Function is called whenever a PONG message is received.
752 * @param cls closure (peer #, set from GNUNET_CADET_connect)
753 * @param channel connection to the other end
754 * @param channel_ctx place to store local state associated with the channel
755 * @param message the actual message
756 * @return GNUNET_OK to keep the connection open,
757 * GNUNET_SYSERR to close it (signal serious error)
760 pong_handler (void *cls, struct GNUNET_CADET_Channel *channel,
762 const struct GNUNET_MessageHeader *message)
765 struct CadetPeer *peer;
766 struct CadetPingMessage *msg;
767 struct GNUNET_TIME_Absolute send_time;
768 struct GNUNET_TIME_Relative latency;
769 unsigned int r /* Ping round */;
772 GNUNET_CADET_receive_done (channel);
775 msg = (struct CadetPingMessage *) message;
777 send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
778 latency = GNUNET_TIME_absolute_get_duration (send_time);
779 r = ntohl (msg->round_number);
780 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
782 get_index (peer->dest),
783 (uint32_t) ntohl (msg->counter),
784 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
786 /* Online variance calculation */
788 delta = latency.rel_value_us - peer->mean[r];
789 peer->mean[r] = peer->mean[r] + delta/peer->pongs[r];
790 peer->var[r] += delta * (latency.rel_value_us - peer->mean[r]);
797 * Handlers, for diverse services
799 static struct GNUNET_CADET_MessageHandler handlers[] = {
800 {&ping_handler, PING, sizeof (struct CadetPingMessage)},
801 {&pong_handler, PONG, sizeof (struct CadetPingMessage)},
807 * Method called whenever another peer has added us to a channel
808 * the other peer initiated.
810 * @param cls Closure.
811 * @param channel New handle to the channel.
812 * @param initiator Peer that started the channel.
813 * @param port Port this channel is connected to.
814 * @param options channel option flags
815 * @return Initial channel context for the channel
816 * (can be NULL -- that's not an error).
819 incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
820 const struct GNUNET_PeerIdentity *initiator,
821 const struct GNUNET_HashCode *port,
822 enum GNUNET_CADET_ChannelOption options)
825 struct CadetPeer *peer;
827 peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
828 GNUNET_assert (NULL != peer);
829 if (NULL == peers[n].incoming)
831 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
832 "WARMUP %3u: %u <= %u\n",
837 if (peers_warmup < peers_total)
839 if (NULL != test_task)
841 GNUNET_SCHEDULER_cancel (test_task);
842 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
847 GNUNET_assert (peer == peers[n].incoming);
848 GNUNET_assert (peer->dest == &peers[n]);
849 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
854 peers[n].incoming_ch = channel;
860 * Function called whenever an inbound channel is destroyed. Should clean up
861 * any associated state.
863 * @param cls closure (set from GNUNET_CADET_connect)
864 * @param channel connection to the other end (henceforth invalid)
865 * @param channel_ctx place where local state associated
866 * with the channel is stored
869 channel_cleaner (void *cls,
870 const struct GNUNET_CADET_Channel *channel,
874 struct CadetPeer *peer = &peers[n];
876 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
877 "Channel %p disconnected at peer %ld\n", channel, n);
878 if (peer->ch == channel)
884 * Select a random peer that has no incoming channel
886 * @param peer ID of the peer connecting. NULL if irrelevant (warmup).
888 * @return Random peer not yet connected to.
890 static struct CadetPeer *
891 select_random_peer (struct CadetPeer *peer)
897 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
898 } while (NULL != peers[r].incoming);
899 peers[r].incoming = peer;
905 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
907 * Testcase continues when the root receives confirmation of connected peers,
908 * on callback funtion ch.
910 * @param cls Closure (unsued).
913 start_test (void *cls)
915 enum GNUNET_CADET_ChannelOption flags;
919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
921 flags = GNUNET_CADET_OPTION_DEFAULT;
922 for (i = 0; i < peers_pinging; i++)
924 peers[i].dest = select_random_peer (&peers[i]);
925 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
928 if (NULL == peers[i].ch)
930 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
931 GNUNET_CADET_TEST_cleanup (test_ctx);
934 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
937 get_index (peers[i].dest),
939 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
942 peers_running = peers_total;
943 if (NULL != disconnect_task)
944 GNUNET_SCHEDULER_cancel (disconnect_task);
946 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(round_time,
948 &disconnect_cadet_peers,
950 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
957 * Do warmup: create some channels to spread information about the topology.
962 struct CadetPeer *peer;
965 for (i = 0; i < peers_total; i++)
967 peer = select_random_peer (NULL);
968 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n",
969 i, get_index (peer));
971 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
972 GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT);
973 if (NULL == peers[i].warmup_ch)
975 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
976 GNUNET_CADET_TEST_cleanup (test_ctx);
984 * Callback to be called when the requested peer information is available
986 * @param cls the closure from GNUNET_TESTBED_peer_get_information()
987 * @param op the operation this callback corresponds to
988 * @param pinfo the result; will be NULL if the operation has failed
989 * @param emsg error message if the operation has failed;
990 * NULL if the operation is successfull
993 peer_id_cb (void *cls,
994 struct GNUNET_TESTBED_Operation *op,
995 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1000 if (NULL == pinfo || NULL != emsg)
1002 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
1003 abort_test (__LINE__);
1006 peers[n].id = *(pinfo->result.id);
1007 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1010 GNUNET_i2s (&peers[n].id));
1011 GNUNET_break (GNUNET_OK ==
1012 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
1013 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1015 GNUNET_TESTBED_operation_done (peers[n].op);
1019 if (p_ids < peers_total)
1021 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
1024 struct GNUNET_TIME_Relative delay;
1027 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1029 test_task = GNUNET_SCHEDULER_add_delayed (delay, &start_test, NULL);
1030 return; /* start_test from incoming_channel */
1032 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n");
1033 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1039 * test main: start test when all peers are connected
1041 * @param cls Closure.
1042 * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end.
1043 * @param num_peers Number of peers that are running.
1044 * @param testbed_peers Array of peers.
1045 * @param cadetes Handle to each of the CADETs of the peers.
1049 struct GNUNET_CADET_TEST_Context *ctx,
1050 unsigned int num_peers,
1051 struct GNUNET_TESTBED_Peer **testbed_peers,
1052 struct GNUNET_CADET_Handle **cadetes)
1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1059 GNUNET_assert (peers_total == num_peers);
1060 peers_running = num_peers;
1061 testbed_handles = testbed_peers;
1062 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
1063 &disconnect_cadet_peers,
1065 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1066 for (i = 0; i < peers_total; i++)
1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1069 "requesting id %ld\n",
1071 peers[i].up = GNUNET_YES;
1072 peers[i].cadet = cadetes[i];
1074 GNUNET_TESTBED_peer_get_information (testbed_handles[i],
1075 GNUNET_TESTBED_PIT_IDENTITY,
1076 &peer_id_cb, (void *) i);
1078 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "requested peer ids\n");
1079 /* Continues from pi_cb -> do_test */
1084 * Main: start profiler.
1087 main (int argc, char *argv[])
1089 static const struct GNUNET_HashCode *ports[2];
1090 const char *config_file;
1092 config_file = ".profiler.conf";
1097 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
1100 "example: %s 30s 16 1 Y\n",
1106 GNUNET_STRINGS_fancy_time_to_relative (argv[1],
1110 "%s is not a valid time\n",
1115 peers_total = atoll (argv[2]);
1116 if (2 > peers_total)
1119 "%s peers is not valid (> 2)\n",
1123 peers = GNUNET_new_array (peers_total,
1125 peers_pinging = atoll (argv[3]);
1127 if (peers_total < 2 * peers_pinging)
1129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1130 "not enough peers, total should be > 2 * peers_pinging\n");
1134 do_warmup = (5 > argc || argv[4][0] != 'N');
1136 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
1138 GNUNET_assert (NULL != ids);
1140 test_finished = GNUNET_NO;
1141 ports[0] = GC_u2h (1);
1143 GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
1144 &tmain, NULL, /* tmain cls */
1145 &incoming_channel, &channel_cleaner,
1147 GNUNET_free (peers);
1152 /* end of gnunet-cadet-profiler.c */