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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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];
164 * Duration of each round.
166 static struct GNUNET_TIME_Relative round_time;
169 * GNUNET_PeerIdentity -> CadetPeer
171 static struct GNUNET_CONTAINER_MultiPeerMap *ids;
174 * Testbed peer handles.
176 static struct GNUNET_TESTBED_Peer **testbed_handles;
179 * Testbed Operation (to get stats).
181 static struct GNUNET_TESTBED_Operation *stats_op;
184 * Operation to get peer ids.
186 static struct CadetPeer *peers;
191 static unsigned int p_ids;
194 * Total number of peers.
196 static unsigned long long peers_total;
199 * Number of currently running peers.
201 static unsigned long long peers_running;
204 * Number of peers doing pings.
206 static unsigned long long peers_pinging;
209 * Test context (to shut down).
211 static struct GNUNET_CADET_TEST_Context *test_ctx;
214 * Task called to disconnect peers, before shutdown.
216 static struct GNUNET_SCHEDULER_Task *disconnect_task;
219 * Task to perform tests
221 static struct GNUNET_SCHEDULER_Task *test_task;
226 static unsigned int current_round;
229 * Do preconnect? (Each peer creates a tunnel to one other peer).
231 static int do_warmup;
236 static unsigned int peers_warmup;
239 * Flag to notify callbacks not to generate any new traffic anymore.
241 static int test_finished;
244 * Task running each round of the benchmark.
246 static struct GNUNET_SCHEDULER_Task *round_task;
250 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
252 * Testcase continues when the root receives confirmation of connected peers,
253 * on callback funtion ch.
255 * @param cls Closure (unsued).
258 start_test (void *cls);
262 * Calculate a random delay.
264 * @param max Exclusive maximum, in ms.
266 * @return A time between 0 a max-1 ms.
268 static struct GNUNET_TIME_Relative
269 delay_ms_rnd (unsigned int max)
273 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
274 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
279 * Get the index of a peer in the peers array.
281 * @param peer Peer whose index to get.
283 * @return Index of peer in peers.
286 get_index (struct CadetPeer *peer)
293 * Show the results of the test (banwidth acheived) and log them to GAUGER
298 struct CadetPeer *peer;
302 for (i = 0; i < number_rounds; i++)
304 for (j = 0; j < peers_pinging; j++)
308 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
309 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
310 peer->pings[i], peer->pongs[i]);
317 * Disconnect from cadet services af all peers, call shutdown.
319 * @param cls Closure (unused).
322 disconnect_cadet_peers (void *cls)
324 long line = (long) cls;
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
328 "disconnecting cadet service, called from line %ld\n",
330 disconnect_task = NULL;
331 for (i = 0; i < peers_total; i++)
333 if (NULL != peers[i].op)
334 GNUNET_TESTBED_operation_done (peers[i].op);
336 if (peers[i].up != GNUNET_YES)
339 if (NULL != peers[i].ch)
341 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
342 "%u: channel %p\n", i, peers[i].ch);
343 GNUNET_CADET_channel_destroy (peers[i].ch);
345 if (NULL != peers[i].warmup_ch)
347 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
348 "%u: warmup channel %p\n",
349 i, peers[i].warmup_ch);
350 GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
352 if (NULL != peers[i].incoming_ch)
354 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
355 "%u: incoming channel %p\n",
356 i, peers[i].incoming_ch);
357 GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
360 GNUNET_CADET_TEST_cleanup (test_ctx);
361 GNUNET_SCHEDULER_shutdown ();
366 * Shut down peergroup, clean up.
368 * @param cls Closure (unused).
371 shutdown_task (void *cls)
373 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
375 if (NULL != disconnect_task)
377 GNUNET_SCHEDULER_cancel (disconnect_task);
378 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
381 if (NULL != round_task)
383 GNUNET_SCHEDULER_cancel (round_task);
386 if (NULL != test_task)
388 GNUNET_SCHEDULER_cancel (test_task);
395 * Finish test normally: schedule disconnect and shutdown
397 * @param line Line in the code the abort is requested from (__LINE__).
400 abort_test (long line)
402 if (disconnect_task != NULL)
404 GNUNET_SCHEDULER_cancel (disconnect_task);
405 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,
434 * Process statistic values.
437 * @param peer the peer the statistic belong to
438 * @param subsystem name of subsystem that created the statistic
439 * @param name the name of the datum
440 * @param value the current value
441 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
442 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
445 stats_iterator (void *cls,
446 const struct GNUNET_TESTBED_Peer *peer,
447 const char *subsystem,
454 i = GNUNET_TESTBED_get_index (peer);
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 " STATS %u - %s [%s]: %llu\n",
458 (unsigned long long) value);
465 * Task check that keepalives were sent and received.
467 * @param cls Closure (NULL).
470 collect_stats (void *cls)
472 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
473 "Start collecting statistics...\n");
474 stats_op = GNUNET_TESTBED_get_statistics (peers_total,
483 * @brief Finish profiler normally. Signal finish and start collecting stats.
485 * @param cls Closure (unused).
488 finish_profiler (void *cls)
490 test_finished = GNUNET_YES;
492 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
497 * Set the total number of running peers.
499 * @param target Desired number of running peers.
502 adjust_running_peers (unsigned int target)
504 struct GNUNET_TESTBED_Operation *op;
510 GNUNET_assert (target <= peers_total);
512 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
513 if (target > peers_running)
515 delta = target - peers_running;
520 delta = peers_running - target;
524 for (i = 0; i < delta; i++)
528 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
529 peers_total - peers_pinging);
532 while (peers[r].up == run || NULL != peers[r].incoming);
533 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
534 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
536 if (NULL != peers[r].ping_task)
538 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
539 peers[r].ping_task = NULL;
541 if (NULL != peers[r].ping_ntr)
543 GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
544 peers[r].ping_ntr = NULL;
548 if (NULL != peers[r].ch)
549 GNUNET_CADET_channel_destroy (peers[r].ch);
551 if (NULL != peers[r].dest)
553 if (NULL != peers[r].dest->incoming_ch)
554 GNUNET_CADET_channel_destroy (peers[r].dest->incoming_ch);
555 peers[r].dest->incoming_ch = NULL;
558 op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
559 "cadet", NULL, NULL, run);
560 GNUNET_break (NULL != op);
561 peers_running += run ? 1 : -1;
562 GNUNET_assert (peers_running > 0);
568 * @brief Move to next round.
570 * @param cls Closure (round #).
575 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
578 if (0.0 == rounds[current_round])
580 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
581 GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
584 adjust_running_peers (rounds[current_round] * peers_total);
587 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
594 * Transmit ping callback.
596 * @param cls Closure (peer for PING, NULL for PONG).
597 * @param size Size of the tranmist buffer.
598 * @param buf Pointer to the beginning of the buffer.
600 * @return Number of bytes written to buf.
603 tmt_rdy_ping (void *cls, size_t size, void *buf);
607 * Transmit pong callback.
609 * @param cls Closure (copy of PING message, to be freed).
610 * @param size Size of the buffer we have.
611 * @param buf Buffer to copy data to.
614 tmt_rdy_pong (void *cls, size_t size, void *buf)
616 struct CadetPingMessage *ping = cls;
617 struct CadetPingMessage *pong;
619 if ((0 == size) || (NULL == buf))
624 pong = (struct CadetPingMessage *) buf;
625 GNUNET_memcpy (pong, ping, sizeof(*ping));
626 pong->header.type = htons (PONG);
629 return sizeof(*ping);
634 * @brief Send a ping to destination
636 * @param cls Closure (peer).
641 struct CadetPeer *peer = cls;
643 peer->ping_task = NULL;
644 if (GNUNET_YES == test_finished)
646 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
649 get_index (peer->dest),
651 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
652 GNUNET_TIME_UNIT_FOREVER_REL,
655 &tmt_rdy_ping, peer);
660 * @brief Reply with a pong to origin.
662 * @param cls Closure (peer).
663 * @param tc Task context.
666 pong (struct GNUNET_CADET_Channel *channel,
667 const struct CadetPingMessage *ping)
669 struct CadetPingMessage *copy;
671 copy = GNUNET_new (struct CadetPingMessage);
673 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
674 GNUNET_TIME_UNIT_FOREVER_REL,
675 sizeof(struct CadetPingMessage),
676 &tmt_rdy_pong, copy);
681 * Transmit ping callback
683 * @param cls Closure (peer).
684 * @param size Size of the buffer we have.
685 * @param buf Buffer to copy data to.
688 tmt_rdy_ping (void *cls, size_t size, void *buf)
690 struct CadetPeer *peer = cls;
691 struct CadetPingMessage *msg = buf;
693 peer->ping_ntr = NULL;
694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "tmt_rdy called, filling buffer\n");
696 if ((size < sizeof(struct CadetPingMessage)) || (NULL == buf))
698 GNUNET_break (GNUNET_YES == test_finished);
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "size %u, buf %p, data_sent %u, data_received %u\n",
704 peer->data_received);
708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
711 msg->header.size = htons (size);
712 msg->header.type = htons (PING);
713 msg->counter = htonl (peer->data_sent++);
714 msg->round_number = htonl (current_round);
715 msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
716 peer->pings[current_round]++;
717 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
720 return sizeof(struct CadetPingMessage);
725 * Function is called whenever a PING message is received.
727 * @param cls closure (peer #, set from GNUNET_CADET_connect)
728 * @param channel connection to the other end
729 * @param channel_ctx place to store local state associated with the channel
730 * @param message the actual message
731 * @return GNUNET_OK to keep the connection open,
732 * GNUNET_SYSERR to close it (signal serious error)
735 ping_handler (void *cls, struct GNUNET_CADET_Channel *channel,
737 const struct GNUNET_MessageHeader *message)
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
744 GNUNET_CADET_receive_done (channel);
745 if (GNUNET_NO == test_finished)
746 pong (channel, (struct CadetPingMessage *) message);
753 * Function is called whenever a PONG message is received.
755 * @param cls closure (peer #, set from GNUNET_CADET_connect)
756 * @param channel connection to the other end
757 * @param channel_ctx place to store local state associated with the channel
758 * @param message the actual message
759 * @return GNUNET_OK to keep the connection open,
760 * GNUNET_SYSERR to close it (signal serious error)
763 pong_handler (void *cls, struct GNUNET_CADET_Channel *channel,
765 const struct GNUNET_MessageHeader *message)
768 struct CadetPeer *peer;
769 struct CadetPingMessage *msg;
770 struct GNUNET_TIME_Absolute send_time;
771 struct GNUNET_TIME_Relative latency;
772 unsigned int r /* Ping round */;
775 GNUNET_CADET_receive_done (channel);
778 msg = (struct CadetPingMessage *) message;
780 send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
781 latency = GNUNET_TIME_absolute_get_duration (send_time);
782 r = ntohl (msg->round_number);
783 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
785 get_index (peer->dest),
786 (uint32_t) ntohl (msg->counter),
787 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
789 /* Online variance calculation */
791 delta = latency.rel_value_us - peer->mean[r];
792 peer->mean[r] = peer->mean[r] + delta / peer->pongs[r];
793 peer->var[r] += delta * (latency.rel_value_us - peer->mean[r]);
800 * Handlers, for diverse services
802 static struct GNUNET_CADET_MessageHandler handlers[] = {
803 { &ping_handler, PING, sizeof(struct CadetPingMessage) },
804 { &pong_handler, PONG, sizeof(struct CadetPingMessage) },
810 * Method called whenever another peer has added us to a channel
811 * the other peer initiated.
813 * @param cls Closure.
814 * @param channel New handle to the channel.
815 * @param initiator Peer that started the channel.
816 * @param port Port this channel is connected to.
817 * @param options channel option flags
818 * @return Initial channel context for the channel
819 * (can be NULL -- that's not an error).
822 incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
823 const struct GNUNET_PeerIdentity *initiator,
824 const struct GNUNET_HashCode *port,
825 enum GNUNET_CADET_ChannelOption options)
828 struct CadetPeer *peer;
830 peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
831 GNUNET_assert (NULL != peer);
832 if (NULL == peers[n].incoming)
834 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
835 "WARMUP %3u: %u <= %u\n",
840 if (peers_warmup < peers_total)
842 if (NULL != test_task)
844 GNUNET_SCHEDULER_cancel (test_task);
845 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
850 GNUNET_assert (peer == peers[n].incoming);
851 GNUNET_assert (peer->dest == &peers[n]);
852 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
857 peers[n].incoming_ch = channel;
864 * Function called whenever an inbound channel is destroyed. Should clean up
865 * any associated state.
867 * @param cls closure (set from GNUNET_CADET_connect)
868 * @param channel connection to the other end (henceforth invalid)
869 * @param channel_ctx place where local state associated
870 * with the channel is stored
873 channel_cleaner (void *cls,
874 const struct GNUNET_CADET_Channel *channel,
878 struct CadetPeer *peer = &peers[n];
880 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
881 "Channel %p disconnected at peer %ld\n", channel, n);
882 if (peer->ch == channel)
888 * Select a random peer that has no incoming channel
890 * @param peer ID of the peer connecting. NULL if irrelevant (warmup).
892 * @return Random peer not yet connected to.
894 static struct CadetPeer *
895 select_random_peer (struct CadetPeer *peer)
901 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
903 while (NULL != peers[r].incoming);
904 peers[r].incoming = peer;
911 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
913 * Testcase continues when the root receives confirmation of connected peers,
914 * on callback funtion ch.
916 * @param cls Closure (unsued).
919 start_test (void *cls)
924 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
927 for (i = 0; i < peers_pinging; i++)
929 peers[i].dest = select_random_peer (&peers[i]);
930 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
933 if (NULL == peers[i].ch)
935 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
936 GNUNET_CADET_TEST_cleanup (test_ctx);
939 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
942 get_index (peers[i].dest),
944 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
947 peers_running = peers_total;
948 if (NULL != disconnect_task)
949 GNUNET_SCHEDULER_cancel (disconnect_task);
951 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (round_time,
954 &disconnect_cadet_peers,
956 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
963 * Do warmup: create some channels to spread information about the topology.
968 struct CadetPeer *peer;
971 for (i = 0; i < peers_total; i++)
973 peer = select_random_peer (NULL);
974 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n",
975 i, get_index (peer));
977 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
979 if (NULL == peers[i].warmup_ch)
981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
982 GNUNET_CADET_TEST_cleanup (test_ctx);
990 * Callback to be called when the requested peer information is available
992 * @param cls the closure from GNUNET_TESTBED_peer_get_information()
993 * @param op the operation this callback corresponds to
994 * @param pinfo the result; will be NULL if the operation has failed
995 * @param emsg error message if the operation has failed;
996 * NULL if the operation is successfull
999 peer_id_cb (void *cls,
1000 struct GNUNET_TESTBED_Operation *op,
1001 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1004 long n = (long) cls;
1006 if ((NULL == pinfo) || (NULL != emsg))
1008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
1009 abort_test (__LINE__);
1012 peers[n].id = *(pinfo->result.id);
1013 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1016 GNUNET_i2s (&peers[n].id));
1017 GNUNET_break (GNUNET_OK ==
1018 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
1019 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1021 GNUNET_TESTBED_operation_done (peers[n].op);
1025 if (p_ids < peers_total)
1027 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
1030 struct GNUNET_TIME_Relative delay;
1033 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1035 test_task = GNUNET_SCHEDULER_add_delayed (delay, &start_test, NULL);
1036 return; /* start_test from incoming_channel */
1038 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n");
1039 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1045 * test main: start test when all peers are connected
1047 * @param cls Closure.
1048 * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end.
1049 * @param num_peers Number of peers that are running.
1050 * @param testbed_peers Array of peers.
1051 * @param cadetes Handle to each of the CADETs of the peers.
1055 struct GNUNET_CADET_TEST_Context *ctx,
1056 unsigned int num_peers,
1057 struct GNUNET_TESTBED_Peer **testbed_peers,
1058 struct GNUNET_CADET_Handle **cadetes)
1062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1065 GNUNET_assert (peers_total == num_peers);
1066 peers_running = num_peers;
1067 testbed_handles = testbed_peers;
1068 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
1069 &disconnect_cadet_peers,
1071 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1072 for (i = 0; i < peers_total; i++)
1074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1075 "requesting id %ld\n",
1077 peers[i].up = GNUNET_YES;
1078 peers[i].cadet = cadetes[i];
1080 GNUNET_TESTBED_peer_get_information (testbed_handles[i],
1081 GNUNET_TESTBED_PIT_IDENTITY,
1082 &peer_id_cb, (void *) i);
1084 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "requested peer ids\n");
1085 /* Continues from pi_cb -> do_test */
1090 * Main: start profiler.
1093 main (int argc, char *argv[])
1095 static const struct GNUNET_HashCode *ports[2];
1096 const char *config_file;
1098 config_file = ".profiler.conf";
1103 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
1106 "example: %s 30s 16 1 Y\n",
1112 GNUNET_STRINGS_fancy_time_to_relative (argv[1],
1116 "%s is not a valid time\n",
1121 peers_total = atoll (argv[2]);
1122 if (2 > peers_total)
1125 "%s peers is not valid (> 2)\n",
1129 peers = GNUNET_new_array (peers_total,
1131 peers_pinging = atoll (argv[3]);
1133 if (peers_total < 2 * peers_pinging)
1135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1136 "not enough peers, total should be > 2 * peers_pinging\n");
1140 do_warmup = (5 > argc || argv[4][0] != 'N');
1142 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
1144 GNUNET_assert (NULL != ids);
1146 test_finished = GNUNET_NO;
1147 ports[0] = GC_u2h (1);
1149 GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
1150 &tmain, NULL, /* tmain cls */
1151 &incoming_channel, &channel_cleaner,
1153 GNUNET_free (peers);
1159 /* end of gnunet-cadet-profiler.c */