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 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.
16 * @file cadet/gnunet-cadet-profiler.c
18 * @brief Profiler for cadet experiments.
22 #include "cadet_test_lib.h"
23 #include "gnunet_cadet_service.h"
24 #include "gnunet_statistics_service.h"
32 * Paximum ping period in milliseconds. Real period = rand (0, PING_PERIOD)
34 #define PING_PERIOD 500
37 * How long until we give up on connecting the peers?
39 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
42 * Time to wait for stuff that should be rather fast
44 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
47 * Total number of rounds.
49 #define number_rounds sizeof(rounds)/sizeof(rounds[0])
52 * Ratio of peers active. First round always is 1.0.
54 static float rounds[] = {0.8, 0.6, 0.8, 0.5, 0.3, 0.8, 0.0};
57 * Message type for pings.
59 struct CadetPingMessage
62 * Header. Type PING/PONG.
64 struct GNUNET_MessageHeader header;
72 * Time the message was sent.
74 struct GNUNET_TIME_AbsoluteNBO timestamp;
79 uint32_t round_number;
88 * Testbed Operation (to get peer id, etc).
90 struct GNUNET_TESTBED_Operation *op;
95 struct GNUNET_PeerIdentity id;
98 * Cadet handle for the root peer
100 struct GNUNET_CADET_Handle *cadet;
103 * Channel handle for the root peer
105 struct GNUNET_CADET_Channel *ch;
108 * Channel handle for the dest peer
110 struct GNUNET_CADET_Channel *incoming_ch;
113 * Channel handle for a warmup channel.
115 struct GNUNET_CADET_Channel *warmup_ch;
118 * Number of payload packes sent
123 * Number of payload packets received
133 * Destinaton to ping.
135 struct CadetPeer *dest;
138 * Incoming channel for pings.
140 struct CadetPeer *incoming;
143 * Task to do the next ping.
145 struct GNUNET_SCHEDULER_Task *ping_task;
148 * NTR operation for the next ping.
150 struct GNUNET_CADET_TransmitHandle *ping_ntr;
152 float mean[number_rounds];
153 float var[number_rounds];
154 unsigned int pongs[number_rounds];
155 unsigned int pings[number_rounds];
160 * Duration of each round.
162 static struct GNUNET_TIME_Relative round_time;
165 * GNUNET_PeerIdentity -> CadetPeer
167 static struct GNUNET_CONTAINER_MultiPeerMap *ids;
170 * Testbed peer handles.
172 static struct GNUNET_TESTBED_Peer **testbed_handles;
175 * Testbed Operation (to get stats).
177 static struct GNUNET_TESTBED_Operation *stats_op;
180 * Operation to get peer ids.
182 static struct CadetPeer *peers;
187 static unsigned int p_ids;
190 * Total number of peers.
192 static unsigned long long peers_total;
195 * Number of currently running peers.
197 static unsigned long long peers_running;
200 * Number of peers doing pings.
202 static unsigned long long peers_pinging;
205 * Test context (to shut down).
207 static struct GNUNET_CADET_TEST_Context *test_ctx;
210 * Task called to disconnect peers, before shutdown.
212 static struct GNUNET_SCHEDULER_Task *disconnect_task;
215 * Task to perform tests
217 static struct GNUNET_SCHEDULER_Task *test_task;
222 static unsigned int current_round;
225 * Do preconnect? (Each peer creates a tunnel to one other peer).
227 static int do_warmup;
232 static unsigned int peers_warmup;
235 * Flag to notify callbacks not to generate any new traffic anymore.
237 static int test_finished;
240 * Task running each round of the benchmark.
242 static struct GNUNET_SCHEDULER_Task *round_task;
246 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
248 * Testcase continues when the root receives confirmation of connected peers,
249 * on callback funtion ch.
251 * @param cls Closure (unsued).
254 start_test (void *cls);
258 * Calculate a random delay.
260 * @param max Exclusive maximum, in ms.
262 * @return A time between 0 a max-1 ms.
264 static struct GNUNET_TIME_Relative
265 delay_ms_rnd (unsigned int max)
269 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
270 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
275 * Get the index of a peer in the peers array.
277 * @param peer Peer whose index to get.
279 * @return Index of peer in peers.
282 get_index (struct CadetPeer *peer)
289 * Show the results of the test (banwidth acheived) and log them to GAUGER
294 struct CadetPeer *peer;
298 for (i = 0; i < number_rounds; i++)
300 for (j = 0; j < peers_pinging; j++)
304 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
305 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
306 peer->pings[i], peer->pongs[i]);
313 * Disconnect from cadet services af all peers, call shutdown.
315 * @param cls Closure (unused).
318 disconnect_cadet_peers (void *cls)
320 long line = (long) cls;
323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
324 "disconnecting cadet service, called from line %ld\n",
326 disconnect_task = NULL;
327 for (i = 0; i < peers_total; i++)
329 if (NULL != peers[i].op)
330 GNUNET_TESTBED_operation_done (peers[i].op);
332 if (peers[i].up != GNUNET_YES)
335 if (NULL != peers[i].ch)
337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
338 "%u: channel %p\n", i, peers[i].ch);
339 GNUNET_CADET_channel_destroy (peers[i].ch);
341 if (NULL != peers[i].warmup_ch)
343 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
344 "%u: warmup channel %p\n",
345 i, peers[i].warmup_ch);
346 GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
348 if (NULL != peers[i].incoming_ch)
350 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
351 "%u: incoming channel %p\n",
352 i, peers[i].incoming_ch);
353 GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
356 GNUNET_CADET_TEST_cleanup (test_ctx);
357 GNUNET_SCHEDULER_shutdown ();
362 * Shut down peergroup, clean up.
364 * @param cls Closure (unused).
367 shutdown_task (void *cls)
369 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
371 if (NULL != disconnect_task)
373 GNUNET_SCHEDULER_cancel (disconnect_task);
374 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
377 if (NULL != round_task)
379 GNUNET_SCHEDULER_cancel (round_task);
382 if (NULL != test_task)
384 GNUNET_SCHEDULER_cancel (test_task);
391 * Finish test normally: schedule disconnect and shutdown
393 * @param line Line in the code the abort is requested from (__LINE__).
396 abort_test (long line)
398 if (disconnect_task != NULL)
400 GNUNET_SCHEDULER_cancel (disconnect_task);
401 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
407 * Stats callback. Finish the stats testbed operation and when all stats have
408 * been iterated, shutdown the test.
411 * @param op the operation that has been finished
412 * @param emsg error message in case the operation has failed; will be NULL if
413 * operation has executed successfully.
416 stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
418 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
419 GNUNET_TESTBED_operation_done (stats_op);
421 if (NULL != disconnect_task)
422 GNUNET_SCHEDULER_cancel (disconnect_task);
423 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
430 * Process statistic values.
433 * @param peer the peer the statistic belong to
434 * @param subsystem name of subsystem that created the statistic
435 * @param name the name of the datum
436 * @param value the current value
437 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
438 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
441 stats_iterator (void *cls,
442 const struct GNUNET_TESTBED_Peer *peer,
443 const char *subsystem,
450 i = GNUNET_TESTBED_get_index (peer);
451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
452 " STATS %u - %s [%s]: %llu\n",
454 (unsigned long long) value);
461 * Task check that keepalives were sent and received.
463 * @param cls Closure (NULL).
466 collect_stats (void *cls)
468 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
469 "Start collecting statistics...\n");
470 stats_op = GNUNET_TESTBED_get_statistics (peers_total,
479 * @brief Finish profiler normally. Signal finish and start collecting stats.
481 * @param cls Closure (unused).
484 finish_profiler (void *cls)
486 test_finished = GNUNET_YES;
488 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
493 * Set the total number of running peers.
495 * @param target Desired number of running peers.
498 adjust_running_peers (unsigned int target)
500 struct GNUNET_TESTBED_Operation *op;
506 GNUNET_assert (target <= peers_total);
508 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
509 if (target > peers_running)
511 delta = target - peers_running;
516 delta = peers_running - target;
520 for (i = 0; i < delta; i++)
523 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
524 peers_total - peers_pinging);
526 } while (peers[r].up == run || NULL != peers[r].incoming);
527 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
528 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
530 if (NULL != peers[r].ping_task)
532 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
533 peers[r].ping_task = NULL;
535 if (NULL != peers[r].ping_ntr)
537 GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
538 peers[r].ping_ntr = NULL;
542 if (NULL != peers[r].ch)
543 GNUNET_CADET_channel_destroy (peers[r].ch);
545 if (NULL != peers[r].dest)
547 if (NULL != peers[r].dest->incoming_ch)
548 GNUNET_CADET_channel_destroy (peers[r].dest->incoming_ch);
549 peers[r].dest->incoming_ch = NULL;
552 op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
553 "cadet", NULL, NULL, run);
554 GNUNET_break (NULL != op);
555 peers_running += run ? 1 : -1;
556 GNUNET_assert (peers_running > 0);
562 * @brief Move to next round.
564 * @param cls Closure (round #).
569 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
572 if (0.0 == rounds[current_round])
574 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
575 GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
578 adjust_running_peers (rounds[current_round] * peers_total);
581 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
588 * Transmit ping callback.
590 * @param cls Closure (peer for PING, NULL for PONG).
591 * @param size Size of the tranmist buffer.
592 * @param buf Pointer to the beginning of the buffer.
594 * @return Number of bytes written to buf.
597 tmt_rdy_ping (void *cls, size_t size, void *buf);
601 * Transmit pong callback.
603 * @param cls Closure (copy of PING message, to be freed).
604 * @param size Size of the buffer we have.
605 * @param buf Buffer to copy data to.
608 tmt_rdy_pong (void *cls, size_t size, void *buf)
610 struct CadetPingMessage *ping = cls;
611 struct CadetPingMessage *pong;
613 if (0 == size || NULL == buf)
618 pong = (struct CadetPingMessage *) buf;
619 GNUNET_memcpy (pong, ping, sizeof (*ping));
620 pong->header.type = htons (PONG);
623 return sizeof (*ping);
628 * @brief Send a ping to destination
630 * @param cls Closure (peer).
635 struct CadetPeer *peer = cls;
637 peer->ping_task = NULL;
638 if (GNUNET_YES == test_finished)
640 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
643 get_index (peer->dest),
645 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
646 GNUNET_TIME_UNIT_FOREVER_REL,
647 sizeof (struct CadetPingMessage),
648 &tmt_rdy_ping, peer);
652 * @brief Reply with a pong to origin.
654 * @param cls Closure (peer).
655 * @param tc Task context.
658 pong (struct GNUNET_CADET_Channel *channel,
659 const struct CadetPingMessage *ping)
661 struct CadetPingMessage *copy;
663 copy = GNUNET_new (struct CadetPingMessage);
665 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
666 GNUNET_TIME_UNIT_FOREVER_REL,
667 sizeof (struct CadetPingMessage),
668 &tmt_rdy_pong, copy);
673 * Transmit ping callback
675 * @param cls Closure (peer).
676 * @param size Size of the buffer we have.
677 * @param buf Buffer to copy data to.
680 tmt_rdy_ping (void *cls, size_t size, void *buf)
682 struct CadetPeer *peer = cls;
683 struct CadetPingMessage *msg = buf;
685 peer->ping_ntr = NULL;
686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
687 "tmt_rdy called, filling buffer\n");
688 if (size < sizeof (struct CadetPingMessage) || NULL == buf)
690 GNUNET_break (GNUNET_YES == test_finished);
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
692 "size %u, buf %p, data_sent %u, data_received %u\n",
696 peer->data_received);
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 msg->header.size = htons (size);
704 msg->header.type = htons (PING);
705 msg->counter = htonl (peer->data_sent++);
706 msg->round_number = htonl (current_round);
707 msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
708 peer->pings[current_round]++;
709 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
712 return sizeof (struct CadetPingMessage);
717 * Function is called whenever a PING message is received.
719 * @param cls closure (peer #, set from GNUNET_CADET_connect)
720 * @param channel connection to the other end
721 * @param channel_ctx place to store local state associated with the channel
722 * @param message the actual message
723 * @return GNUNET_OK to keep the connection open,
724 * GNUNET_SYSERR to close it (signal serious error)
727 ping_handler (void *cls, struct GNUNET_CADET_Channel *channel,
729 const struct GNUNET_MessageHeader *message)
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 GNUNET_CADET_receive_done (channel);
737 if (GNUNET_NO == test_finished)
738 pong (channel, (struct CadetPingMessage *) message);
745 * Function is called whenever a PONG message is received.
747 * @param cls closure (peer #, set from GNUNET_CADET_connect)
748 * @param channel connection to the other end
749 * @param channel_ctx place to store local state associated with the channel
750 * @param message the actual message
751 * @return GNUNET_OK to keep the connection open,
752 * GNUNET_SYSERR to close it (signal serious error)
755 pong_handler (void *cls, struct GNUNET_CADET_Channel *channel,
757 const struct GNUNET_MessageHeader *message)
760 struct CadetPeer *peer;
761 struct CadetPingMessage *msg;
762 struct GNUNET_TIME_Absolute send_time;
763 struct GNUNET_TIME_Relative latency;
764 unsigned int r /* Ping round */;
767 GNUNET_CADET_receive_done (channel);
770 msg = (struct CadetPingMessage *) message;
772 send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
773 latency = GNUNET_TIME_absolute_get_duration (send_time);
774 r = ntohl (msg->round_number);
775 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
777 get_index (peer->dest),
778 (uint32_t) ntohl (msg->counter),
779 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
781 /* Online variance calculation */
783 delta = latency.rel_value_us - peer->mean[r];
784 peer->mean[r] = peer->mean[r] + delta/peer->pongs[r];
785 peer->var[r] += delta * (latency.rel_value_us - peer->mean[r]);
792 * Handlers, for diverse services
794 static struct GNUNET_CADET_MessageHandler handlers[] = {
795 {&ping_handler, PING, sizeof (struct CadetPingMessage)},
796 {&pong_handler, PONG, sizeof (struct CadetPingMessage)},
802 * Method called whenever another peer has added us to a channel
803 * the other peer initiated.
805 * @param cls Closure.
806 * @param channel New handle to the channel.
807 * @param initiator Peer that started the channel.
808 * @param port Port this channel is connected to.
809 * @param options channel option flags
810 * @return Initial channel context for the channel
811 * (can be NULL -- that's not an error).
814 incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
815 const struct GNUNET_PeerIdentity *initiator,
816 const struct GNUNET_HashCode *port,
817 enum GNUNET_CADET_ChannelOption options)
820 struct CadetPeer *peer;
822 peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
823 GNUNET_assert (NULL != peer);
824 if (NULL == peers[n].incoming)
826 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
827 "WARMUP %3u: %u <= %u\n",
832 if (peers_warmup < peers_total)
834 if (NULL != test_task)
836 GNUNET_SCHEDULER_cancel (test_task);
837 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
842 GNUNET_assert (peer == peers[n].incoming);
843 GNUNET_assert (peer->dest == &peers[n]);
844 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
849 peers[n].incoming_ch = channel;
855 * Function called whenever an inbound channel is destroyed. Should clean up
856 * any associated state.
858 * @param cls closure (set from GNUNET_CADET_connect)
859 * @param channel connection to the other end (henceforth invalid)
860 * @param channel_ctx place where local state associated
861 * with the channel is stored
864 channel_cleaner (void *cls,
865 const struct GNUNET_CADET_Channel *channel,
869 struct CadetPeer *peer = &peers[n];
871 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
872 "Channel %p disconnected at peer %ld\n", channel, n);
873 if (peer->ch == channel)
879 * Select a random peer that has no incoming channel
881 * @param peer ID of the peer connecting. NULL if irrelevant (warmup).
883 * @return Random peer not yet connected to.
885 static struct CadetPeer *
886 select_random_peer (struct CadetPeer *peer)
892 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
893 } while (NULL != peers[r].incoming);
894 peers[r].incoming = peer;
900 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
902 * Testcase continues when the root receives confirmation of connected peers,
903 * on callback funtion ch.
905 * @param cls Closure (unsued).
908 start_test (void *cls)
910 enum GNUNET_CADET_ChannelOption flags;
914 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
916 flags = GNUNET_CADET_OPTION_DEFAULT;
917 for (i = 0; i < peers_pinging; i++)
919 peers[i].dest = select_random_peer (&peers[i]);
920 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
923 if (NULL == peers[i].ch)
925 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
926 GNUNET_CADET_TEST_cleanup (test_ctx);
929 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
932 get_index (peers[i].dest),
934 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
937 peers_running = peers_total;
938 if (NULL != disconnect_task)
939 GNUNET_SCHEDULER_cancel (disconnect_task);
941 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(round_time,
943 &disconnect_cadet_peers,
945 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
952 * Do warmup: create some channels to spread information about the topology.
957 struct CadetPeer *peer;
960 for (i = 0; i < peers_total; i++)
962 peer = select_random_peer (NULL);
963 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n",
964 i, get_index (peer));
966 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
967 GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT);
968 if (NULL == peers[i].warmup_ch)
970 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
971 GNUNET_CADET_TEST_cleanup (test_ctx);
979 * Callback to be called when the requested peer information is available
981 * @param cls the closure from GNUNET_TESTBED_peer_get_information()
982 * @param op the operation this callback corresponds to
983 * @param pinfo the result; will be NULL if the operation has failed
984 * @param emsg error message if the operation has failed;
985 * NULL if the operation is successfull
988 peer_id_cb (void *cls,
989 struct GNUNET_TESTBED_Operation *op,
990 const struct GNUNET_TESTBED_PeerInformation *pinfo,
995 if (NULL == pinfo || NULL != emsg)
997 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
998 abort_test (__LINE__);
1001 peers[n].id = *(pinfo->result.id);
1002 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1005 GNUNET_i2s (&peers[n].id));
1006 GNUNET_break (GNUNET_OK ==
1007 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
1008 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1010 GNUNET_TESTBED_operation_done (peers[n].op);
1014 if (p_ids < peers_total)
1016 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
1019 struct GNUNET_TIME_Relative delay;
1022 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1024 test_task = GNUNET_SCHEDULER_add_delayed (delay, &start_test, NULL);
1025 return; /* start_test from incoming_channel */
1027 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n");
1028 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1034 * test main: start test when all peers are connected
1036 * @param cls Closure.
1037 * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end.
1038 * @param num_peers Number of peers that are running.
1039 * @param testbed_peers Array of peers.
1040 * @param cadetes Handle to each of the CADETs of the peers.
1044 struct GNUNET_CADET_TEST_Context *ctx,
1045 unsigned int num_peers,
1046 struct GNUNET_TESTBED_Peer **testbed_peers,
1047 struct GNUNET_CADET_Handle **cadetes)
1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1054 GNUNET_assert (peers_total == num_peers);
1055 peers_running = num_peers;
1056 testbed_handles = testbed_peers;
1057 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
1058 &disconnect_cadet_peers,
1060 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1061 for (i = 0; i < peers_total; i++)
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1064 "requesting id %ld\n",
1066 peers[i].up = GNUNET_YES;
1067 peers[i].cadet = cadetes[i];
1069 GNUNET_TESTBED_peer_get_information (testbed_handles[i],
1070 GNUNET_TESTBED_PIT_IDENTITY,
1071 &peer_id_cb, (void *) i);
1073 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "requested peer ids\n");
1074 /* Continues from pi_cb -> do_test */
1079 * Main: start profiler.
1082 main (int argc, char *argv[])
1084 static const struct GNUNET_HashCode *ports[2];
1085 const char *config_file;
1087 config_file = ".profiler.conf";
1092 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
1095 "example: %s 30s 16 1 Y\n",
1101 GNUNET_STRINGS_fancy_time_to_relative (argv[1],
1105 "%s is not a valid time\n",
1110 peers_total = atoll (argv[2]);
1111 if (2 > peers_total)
1114 "%s peers is not valid (> 2)\n",
1118 peers = GNUNET_new_array (peers_total,
1120 peers_pinging = atoll (argv[3]);
1122 if (peers_total < 2 * peers_pinging)
1124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1125 "not enough peers, total should be > 2 * peers_pinging\n");
1129 do_warmup = (5 > argc || argv[4][0] != 'N');
1131 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
1133 GNUNET_assert (NULL != ids);
1135 test_finished = GNUNET_NO;
1136 ports[0] = GC_u2h (1);
1138 GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
1139 &tmain, NULL, /* tmain cls */
1140 &incoming_channel, &channel_cleaner,
1142 GNUNET_free (peers);
1147 /* end of gnunet-cadet-profiler.c */