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 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/>.
19 * @file cadet/gnunet-cadet-profiler.c
21 * @brief Profiler for cadet experiments.
25 #include "cadet_test_lib.h"
26 #include "gnunet_cadet_service.h"
27 #include "gnunet_statistics_service.h"
35 * Paximum ping period in milliseconds. Real period = rand (0, PING_PERIOD)
37 #define PING_PERIOD 500
40 * How long until we give up on connecting the peers?
42 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
45 * Time to wait for stuff that should be rather fast
47 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
50 * Total number of rounds.
52 #define number_rounds sizeof(rounds)/sizeof(rounds[0])
55 * Ratio of peers active. First round always is 1.0.
57 static float rounds[] = {0.8, 0.6, 0.8, 0.5, 0.3, 0.8, 0.0};
60 * Message type for pings.
62 struct CadetPingMessage
65 * Header. Type PING/PONG.
67 struct GNUNET_MessageHeader header;
75 * Time the message was sent.
77 struct GNUNET_TIME_AbsoluteNBO timestamp;
82 uint32_t round_number;
91 * Testbed Operation (to get peer id, etc).
93 struct GNUNET_TESTBED_Operation *op;
98 struct GNUNET_PeerIdentity id;
101 * Cadet handle for the root peer
103 struct GNUNET_CADET_Handle *cadet;
106 * Channel handle for the root peer
108 struct GNUNET_CADET_Channel *ch;
111 * Channel handle for the dest peer
113 struct GNUNET_CADET_Channel *incoming_ch;
116 * Channel handle for a warmup channel.
118 struct GNUNET_CADET_Channel *warmup_ch;
121 * Number of payload packes sent
126 * Number of payload packets received
136 * Destinaton to ping.
138 struct CadetPeer *dest;
141 * Incoming channel for pings.
143 struct CadetPeer *incoming;
146 * Task to do the next ping.
148 struct GNUNET_SCHEDULER_Task *ping_task;
151 * NTR operation for the next ping.
153 struct GNUNET_CADET_TransmitHandle *ping_ntr;
155 float mean[number_rounds];
156 float var[number_rounds];
157 unsigned int pongs[number_rounds];
158 unsigned int pings[number_rounds];
163 * Duration of each round.
165 static struct GNUNET_TIME_Relative round_time;
168 * GNUNET_PeerIdentity -> CadetPeer
170 static struct GNUNET_CONTAINER_MultiPeerMap *ids;
173 * Testbed peer handles.
175 static struct GNUNET_TESTBED_Peer **testbed_handles;
178 * Testbed Operation (to get stats).
180 static struct GNUNET_TESTBED_Operation *stats_op;
183 * Operation to get peer ids.
185 static struct CadetPeer *peers;
190 static unsigned int p_ids;
193 * Total number of peers.
195 static unsigned long long peers_total;
198 * Number of currently running peers.
200 static unsigned long long peers_running;
203 * Number of peers doing pings.
205 static unsigned long long peers_pinging;
208 * Test context (to shut down).
210 static struct GNUNET_CADET_TEST_Context *test_ctx;
213 * Task called to disconnect peers, before shutdown.
215 static struct GNUNET_SCHEDULER_Task *disconnect_task;
218 * Task to perform tests
220 static struct GNUNET_SCHEDULER_Task *test_task;
225 static unsigned int current_round;
228 * Do preconnect? (Each peer creates a tunnel to one other peer).
230 static int do_warmup;
235 static unsigned int peers_warmup;
238 * Flag to notify callbacks not to generate any new traffic anymore.
240 static int test_finished;
243 * Task running each round of the benchmark.
245 static struct GNUNET_SCHEDULER_Task *round_task;
249 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
251 * Testcase continues when the root receives confirmation of connected peers,
252 * on callback funtion ch.
254 * @param cls Closure (unsued).
257 start_test (void *cls);
261 * Calculate a random delay.
263 * @param max Exclusive maximum, in ms.
265 * @return A time between 0 a max-1 ms.
267 static struct GNUNET_TIME_Relative
268 delay_ms_rnd (unsigned int max)
272 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
273 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
278 * Get the index of a peer in the peers array.
280 * @param peer Peer whose index to get.
282 * @return Index of peer in peers.
285 get_index (struct CadetPeer *peer)
292 * Show the results of the test (banwidth acheived) and log them to GAUGER
297 struct CadetPeer *peer;
301 for (i = 0; i < number_rounds; i++)
303 for (j = 0; j < peers_pinging; j++)
307 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
308 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
309 peer->pings[i], peer->pongs[i]);
316 * Disconnect from cadet services af all peers, call shutdown.
318 * @param cls Closure (unused).
321 disconnect_cadet_peers (void *cls)
323 long line = (long) cls;
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327 "disconnecting cadet service, called from line %ld\n",
329 disconnect_task = NULL;
330 for (i = 0; i < peers_total; i++)
332 if (NULL != peers[i].op)
333 GNUNET_TESTBED_operation_done (peers[i].op);
335 if (peers[i].up != GNUNET_YES)
338 if (NULL != peers[i].ch)
340 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
341 "%u: channel %p\n", i, peers[i].ch);
342 GNUNET_CADET_channel_destroy (peers[i].ch);
344 if (NULL != peers[i].warmup_ch)
346 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
347 "%u: warmup channel %p\n",
348 i, peers[i].warmup_ch);
349 GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
351 if (NULL != peers[i].incoming_ch)
353 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
354 "%u: incoming channel %p\n",
355 i, peers[i].incoming_ch);
356 GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
359 GNUNET_CADET_TEST_cleanup (test_ctx);
360 GNUNET_SCHEDULER_shutdown ();
365 * Shut down peergroup, clean up.
367 * @param cls Closure (unused).
370 shutdown_task (void *cls)
372 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
374 if (NULL != disconnect_task)
376 GNUNET_SCHEDULER_cancel (disconnect_task);
377 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
380 if (NULL != round_task)
382 GNUNET_SCHEDULER_cancel (round_task);
385 if (NULL != test_task)
387 GNUNET_SCHEDULER_cancel (test_task);
394 * Finish test normally: schedule disconnect and shutdown
396 * @param line Line in the code the abort is requested from (__LINE__).
399 abort_test (long line)
401 if (disconnect_task != NULL)
403 GNUNET_SCHEDULER_cancel (disconnect_task);
404 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
410 * Stats callback. Finish the stats testbed operation and when all stats have
411 * been iterated, shutdown the test.
414 * @param op the operation that has been finished
415 * @param emsg error message in case the operation has failed; will be NULL if
416 * operation has executed successfully.
419 stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
421 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
422 GNUNET_TESTBED_operation_done (stats_op);
424 if (NULL != disconnect_task)
425 GNUNET_SCHEDULER_cancel (disconnect_task);
426 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
433 * Process statistic values.
436 * @param peer the peer the statistic belong to
437 * @param subsystem name of subsystem that created the statistic
438 * @param name the name of the datum
439 * @param value the current value
440 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
441 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
444 stats_iterator (void *cls,
445 const struct GNUNET_TESTBED_Peer *peer,
446 const char *subsystem,
453 i = GNUNET_TESTBED_get_index (peer);
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
455 " STATS %u - %s [%s]: %llu\n",
457 (unsigned long long) value);
464 * Task check that keepalives were sent and received.
466 * @param cls Closure (NULL).
469 collect_stats (void *cls)
471 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
472 "Start collecting statistics...\n");
473 stats_op = GNUNET_TESTBED_get_statistics (peers_total,
482 * @brief Finish profiler normally. Signal finish and start collecting stats.
484 * @param cls Closure (unused).
487 finish_profiler (void *cls)
489 test_finished = GNUNET_YES;
491 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
496 * Set the total number of running peers.
498 * @param target Desired number of running peers.
501 adjust_running_peers (unsigned int target)
503 struct GNUNET_TESTBED_Operation *op;
509 GNUNET_assert (target <= peers_total);
511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
512 if (target > peers_running)
514 delta = target - peers_running;
519 delta = peers_running - target;
523 for (i = 0; i < delta; i++)
526 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
527 peers_total - peers_pinging);
529 } while (peers[r].up == run || NULL != peers[r].incoming);
530 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
531 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
533 if (NULL != peers[r].ping_task)
535 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
536 peers[r].ping_task = NULL;
538 if (NULL != peers[r].ping_ntr)
540 GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
541 peers[r].ping_ntr = NULL;
545 if (NULL != peers[r].ch)
546 GNUNET_CADET_channel_destroy (peers[r].ch);
548 if (NULL != peers[r].dest)
550 if (NULL != peers[r].dest->incoming_ch)
551 GNUNET_CADET_channel_destroy (peers[r].dest->incoming_ch);
552 peers[r].dest->incoming_ch = NULL;
555 op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
556 "cadet", NULL, NULL, run);
557 GNUNET_break (NULL != op);
558 peers_running += run ? 1 : -1;
559 GNUNET_assert (peers_running > 0);
565 * @brief Move to next round.
567 * @param cls Closure (round #).
572 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
575 if (0.0 == rounds[current_round])
577 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
578 GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
581 adjust_running_peers (rounds[current_round] * peers_total);
584 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
591 * Transmit ping callback.
593 * @param cls Closure (peer for PING, NULL for PONG).
594 * @param size Size of the tranmist buffer.
595 * @param buf Pointer to the beginning of the buffer.
597 * @return Number of bytes written to buf.
600 tmt_rdy_ping (void *cls, size_t size, void *buf);
604 * Transmit pong callback.
606 * @param cls Closure (copy of PING message, to be freed).
607 * @param size Size of the buffer we have.
608 * @param buf Buffer to copy data to.
611 tmt_rdy_pong (void *cls, size_t size, void *buf)
613 struct CadetPingMessage *ping = cls;
614 struct CadetPingMessage *pong;
616 if (0 == size || NULL == buf)
621 pong = (struct CadetPingMessage *) buf;
622 GNUNET_memcpy (pong, ping, sizeof (*ping));
623 pong->header.type = htons (PONG);
626 return sizeof (*ping);
631 * @brief Send a ping to destination
633 * @param cls Closure (peer).
638 struct CadetPeer *peer = cls;
640 peer->ping_task = NULL;
641 if (GNUNET_YES == test_finished)
643 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
646 get_index (peer->dest),
648 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
649 GNUNET_TIME_UNIT_FOREVER_REL,
650 sizeof (struct CadetPingMessage),
651 &tmt_rdy_ping, peer);
655 * @brief Reply with a pong to origin.
657 * @param cls Closure (peer).
658 * @param tc Task context.
661 pong (struct GNUNET_CADET_Channel *channel,
662 const struct CadetPingMessage *ping)
664 struct CadetPingMessage *copy;
666 copy = GNUNET_new (struct CadetPingMessage);
668 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
669 GNUNET_TIME_UNIT_FOREVER_REL,
670 sizeof (struct CadetPingMessage),
671 &tmt_rdy_pong, copy);
676 * Transmit ping callback
678 * @param cls Closure (peer).
679 * @param size Size of the buffer we have.
680 * @param buf Buffer to copy data to.
683 tmt_rdy_ping (void *cls, size_t size, void *buf)
685 struct CadetPeer *peer = cls;
686 struct CadetPingMessage *msg = buf;
688 peer->ping_ntr = NULL;
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
690 "tmt_rdy called, filling buffer\n");
691 if (size < sizeof (struct CadetPingMessage) || NULL == buf)
693 GNUNET_break (GNUNET_YES == test_finished);
694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "size %u, buf %p, data_sent %u, data_received %u\n",
699 peer->data_received);
703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
706 msg->header.size = htons (size);
707 msg->header.type = htons (PING);
708 msg->counter = htonl (peer->data_sent++);
709 msg->round_number = htonl (current_round);
710 msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
711 peer->pings[current_round]++;
712 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
715 return sizeof (struct CadetPingMessage);
720 * Function is called whenever a PING message is received.
722 * @param cls closure (peer #, set from GNUNET_CADET_connect)
723 * @param channel connection to the other end
724 * @param channel_ctx place to store local state associated with the channel
725 * @param message the actual message
726 * @return GNUNET_OK to keep the connection open,
727 * GNUNET_SYSERR to close it (signal serious error)
730 ping_handler (void *cls, struct GNUNET_CADET_Channel *channel,
732 const struct GNUNET_MessageHeader *message)
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
739 GNUNET_CADET_receive_done (channel);
740 if (GNUNET_NO == test_finished)
741 pong (channel, (struct CadetPingMessage *) message);
748 * Function is called whenever a PONG message is received.
750 * @param cls closure (peer #, set from GNUNET_CADET_connect)
751 * @param channel connection to the other end
752 * @param channel_ctx place to store local state associated with the channel
753 * @param message the actual message
754 * @return GNUNET_OK to keep the connection open,
755 * GNUNET_SYSERR to close it (signal serious error)
758 pong_handler (void *cls, struct GNUNET_CADET_Channel *channel,
760 const struct GNUNET_MessageHeader *message)
763 struct CadetPeer *peer;
764 struct CadetPingMessage *msg;
765 struct GNUNET_TIME_Absolute send_time;
766 struct GNUNET_TIME_Relative latency;
767 unsigned int r /* Ping round */;
770 GNUNET_CADET_receive_done (channel);
773 msg = (struct CadetPingMessage *) message;
775 send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
776 latency = GNUNET_TIME_absolute_get_duration (send_time);
777 r = ntohl (msg->round_number);
778 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
780 get_index (peer->dest),
781 (uint32_t) ntohl (msg->counter),
782 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
784 /* Online variance calculation */
786 delta = latency.rel_value_us - peer->mean[r];
787 peer->mean[r] = peer->mean[r] + delta/peer->pongs[r];
788 peer->var[r] += delta * (latency.rel_value_us - peer->mean[r]);
795 * Handlers, for diverse services
797 static struct GNUNET_CADET_MessageHandler handlers[] = {
798 {&ping_handler, PING, sizeof (struct CadetPingMessage)},
799 {&pong_handler, PONG, sizeof (struct CadetPingMessage)},
805 * Method called whenever another peer has added us to a channel
806 * the other peer initiated.
808 * @param cls Closure.
809 * @param channel New handle to the channel.
810 * @param initiator Peer that started the channel.
811 * @param port Port this channel is connected to.
812 * @param options channel option flags
813 * @return Initial channel context for the channel
814 * (can be NULL -- that's not an error).
817 incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
818 const struct GNUNET_PeerIdentity *initiator,
819 const struct GNUNET_HashCode *port,
820 enum GNUNET_CADET_ChannelOption options)
823 struct CadetPeer *peer;
825 peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
826 GNUNET_assert (NULL != peer);
827 if (NULL == peers[n].incoming)
829 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
830 "WARMUP %3u: %u <= %u\n",
835 if (peers_warmup < peers_total)
837 if (NULL != test_task)
839 GNUNET_SCHEDULER_cancel (test_task);
840 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
845 GNUNET_assert (peer == peers[n].incoming);
846 GNUNET_assert (peer->dest == &peers[n]);
847 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
852 peers[n].incoming_ch = channel;
858 * Function called whenever an inbound channel is destroyed. Should clean up
859 * any associated state.
861 * @param cls closure (set from GNUNET_CADET_connect)
862 * @param channel connection to the other end (henceforth invalid)
863 * @param channel_ctx place where local state associated
864 * with the channel is stored
867 channel_cleaner (void *cls,
868 const struct GNUNET_CADET_Channel *channel,
872 struct CadetPeer *peer = &peers[n];
874 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
875 "Channel %p disconnected at peer %ld\n", channel, n);
876 if (peer->ch == channel)
882 * Select a random peer that has no incoming channel
884 * @param peer ID of the peer connecting. NULL if irrelevant (warmup).
886 * @return Random peer not yet connected to.
888 static struct CadetPeer *
889 select_random_peer (struct CadetPeer *peer)
895 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
896 } while (NULL != peers[r].incoming);
897 peers[r].incoming = peer;
903 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
905 * Testcase continues when the root receives confirmation of connected peers,
906 * on callback funtion ch.
908 * @param cls Closure (unsued).
911 start_test (void *cls)
913 enum GNUNET_CADET_ChannelOption flags;
917 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
919 flags = GNUNET_CADET_OPTION_DEFAULT;
920 for (i = 0; i < peers_pinging; i++)
922 peers[i].dest = select_random_peer (&peers[i]);
923 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
926 if (NULL == peers[i].ch)
928 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
929 GNUNET_CADET_TEST_cleanup (test_ctx);
932 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
935 get_index (peers[i].dest),
937 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
940 peers_running = peers_total;
941 if (NULL != disconnect_task)
942 GNUNET_SCHEDULER_cancel (disconnect_task);
944 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(round_time,
946 &disconnect_cadet_peers,
948 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
955 * Do warmup: create some channels to spread information about the topology.
960 struct CadetPeer *peer;
963 for (i = 0; i < peers_total; i++)
965 peer = select_random_peer (NULL);
966 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n",
967 i, get_index (peer));
969 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
970 GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT);
971 if (NULL == peers[i].warmup_ch)
973 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
974 GNUNET_CADET_TEST_cleanup (test_ctx);
982 * Callback to be called when the requested peer information is available
984 * @param cls the closure from GNUNET_TESTBED_peer_get_information()
985 * @param op the operation this callback corresponds to
986 * @param pinfo the result; will be NULL if the operation has failed
987 * @param emsg error message if the operation has failed;
988 * NULL if the operation is successfull
991 peer_id_cb (void *cls,
992 struct GNUNET_TESTBED_Operation *op,
993 const struct GNUNET_TESTBED_PeerInformation *pinfo,
998 if (NULL == pinfo || NULL != emsg)
1000 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
1001 abort_test (__LINE__);
1004 peers[n].id = *(pinfo->result.id);
1005 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1008 GNUNET_i2s (&peers[n].id));
1009 GNUNET_break (GNUNET_OK ==
1010 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
1011 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1013 GNUNET_TESTBED_operation_done (peers[n].op);
1017 if (p_ids < peers_total)
1019 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
1022 struct GNUNET_TIME_Relative delay;
1025 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1027 test_task = GNUNET_SCHEDULER_add_delayed (delay, &start_test, NULL);
1028 return; /* start_test from incoming_channel */
1030 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n");
1031 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1037 * test main: start test when all peers are connected
1039 * @param cls Closure.
1040 * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end.
1041 * @param num_peers Number of peers that are running.
1042 * @param testbed_peers Array of peers.
1043 * @param cadetes Handle to each of the CADETs of the peers.
1047 struct GNUNET_CADET_TEST_Context *ctx,
1048 unsigned int num_peers,
1049 struct GNUNET_TESTBED_Peer **testbed_peers,
1050 struct GNUNET_CADET_Handle **cadetes)
1054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1057 GNUNET_assert (peers_total == num_peers);
1058 peers_running = num_peers;
1059 testbed_handles = testbed_peers;
1060 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
1061 &disconnect_cadet_peers,
1063 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1064 for (i = 0; i < peers_total; i++)
1066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1067 "requesting id %ld\n",
1069 peers[i].up = GNUNET_YES;
1070 peers[i].cadet = cadetes[i];
1072 GNUNET_TESTBED_peer_get_information (testbed_handles[i],
1073 GNUNET_TESTBED_PIT_IDENTITY,
1074 &peer_id_cb, (void *) i);
1076 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "requested peer ids\n");
1077 /* Continues from pi_cb -> do_test */
1082 * Main: start profiler.
1085 main (int argc, char *argv[])
1087 static const struct GNUNET_HashCode *ports[2];
1088 const char *config_file;
1090 config_file = ".profiler.conf";
1095 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
1098 "example: %s 30s 16 1 Y\n",
1104 GNUNET_STRINGS_fancy_time_to_relative (argv[1],
1108 "%s is not a valid time\n",
1113 peers_total = atoll (argv[2]);
1114 if (2 > peers_total)
1117 "%s peers is not valid (> 2)\n",
1121 peers = GNUNET_new_array (peers_total,
1123 peers_pinging = atoll (argv[3]);
1125 if (peers_total < 2 * peers_pinging)
1127 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1128 "not enough peers, total should be > 2 * peers_pinging\n");
1132 do_warmup = (5 > argc || argv[4][0] != 'N');
1134 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
1136 GNUNET_assert (NULL != ids);
1138 test_finished = GNUNET_NO;
1139 ports[0] = GC_u2h (1);
1141 GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
1142 &tmain, NULL, /* tmain cls */
1143 &incoming_channel, &channel_cleaner,
1145 GNUNET_free (peers);
1150 /* end of gnunet-cadet-profiler.c */