2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file mesh/gnunet-mesh-profiler.c
23 * @brief Profiler for mesh experiments.
27 #include "mesh_test_lib.h"
28 #include "gnunet_mesh_service.h"
29 #include "gnunet_statistics_service.h"
37 * Duration of each round.
39 #define ROUND_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
42 * Paximum ping period in milliseconds. Real period = rand (0, PING_PERIOD)
44 #define PING_PERIOD 1000
47 * How long until we give up on connecting the peers?
49 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
52 * Time to wait for stuff that should be rather fast
54 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
57 * Total number of rounds.
59 #define number_rounds sizeof(rounds)/sizeof(rounds[0])
62 * Ratio of peers active. First round always is 1.0.
64 static float rounds[] = {0.8, 0.6, 0.4, 0.2, 0.0};
67 * Message type for pings.
69 struct MeshPingMessage
72 * Header. Type PING/PONG.
74 struct GNUNET_MessageHeader header;
82 * Time the message was sent.
84 struct GNUNET_TIME_AbsoluteNBO timestamp;
89 uint32_t round_number;
98 * Testbed Operation (to get peer id, etc).
100 struct GNUNET_TESTBED_Operation *op;
105 struct GNUNET_PeerIdentity id;
108 * Mesh handle for the root peer
110 struct GNUNET_MESH_Handle *mesh;
113 * Channel handle for the root peer
115 struct GNUNET_MESH_Channel *ch;
118 * Channel handle for the dest peer
120 struct GNUNET_MESH_Channel *incoming_ch;
123 * Number of payload packes sent
128 * Number of payload packets received
138 * Destinaton to ping.
140 struct MeshPeer *dest;
143 * Incoming channel for pings.
145 struct MeshPeer *incoming;
148 * Task to do the next ping.
150 GNUNET_SCHEDULER_TaskIdentifier ping_task;
152 float mean[number_rounds];
153 float var[number_rounds];
154 unsigned int pongs[number_rounds];
155 unsigned int pings[number_rounds];
160 * GNUNET_PeerIdentity -> MeshPeer
162 static struct GNUNET_CONTAINER_MultiPeerMap *ids;
165 * Testbed peer handles.
167 static struct GNUNET_TESTBED_Peer **testbed_handles;
170 * Testbed Operation (to get stats).
172 static struct GNUNET_TESTBED_Operation *stats_op;
175 * Operation to get peer ids.
177 struct MeshPeer *peers;
182 static unsigned int p_ids;
185 * Total number of peers.
187 static unsigned long long peers_total;
190 * Number of currently running peers.
192 static unsigned long long peers_running;
195 * Number of peers doing pings.
197 static unsigned long long peers_pinging;
200 * Test context (to shut down).
202 static struct GNUNET_MESH_TEST_Context *test_ctx;
205 * Task called to shutdown test.
207 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
210 * Task called to disconnect peers, before shutdown.
212 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
215 * Task to perform tests
217 static GNUNET_SCHEDULER_TaskIdentifier test_task;
222 static unsigned int current_round;
225 * Flag to notify callbacks not to generate any new traffic anymore.
227 static int test_finished;
230 * Calculate a random delay.
232 * @param max Exclusive maximum, in ms.
234 * @return A time between 0 a max-1 ms.
236 static struct GNUNET_TIME_Relative
237 delay_ms_rnd (unsigned int max)
241 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
242 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
247 * Get the index of a peer in the peers array.
249 * @param peer Peer whose index to get.
251 * @return Index of peer in peers.
254 get_index (struct MeshPeer *peer)
261 * Show the results of the test (banwidth acheived) and log them to GAUGER
266 struct MeshPeer *peer;
270 for (i = 0; i < number_rounds; i++)
272 for (j = 0; j < peers_pinging; j++)
276 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
277 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
278 peer->pings[i], peer->pongs[i]);
285 * Shut down peergroup, clean up.
287 * @param cls Closure (unused).
288 * @param tc Task Context.
291 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
293 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
294 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
299 * Disconnect from mesh services af all peers, call shutdown.
301 * @param cls Closure (unused).
302 * @param tc Task Context.
305 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
307 long line = (long) cls;
310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
311 "disconnecting mesh service, called from line %ld\n", line);
312 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
313 for (i = 0; i < peers_total; i++)
315 if (NULL != peers[i].op)
316 GNUNET_TESTBED_operation_done (peers[i].op);
318 if (peers[i].up != GNUNET_YES)
321 if (NULL != peers[i].ch)
323 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: channel %p\n", i, peers[i].ch);
324 GNUNET_MESH_channel_destroy (peers[i].ch);
326 if (NULL != peers[i].incoming_ch)
328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: incoming channel %p\n",
329 i, peers[i].incoming_ch);
330 GNUNET_MESH_channel_destroy (peers[i].incoming_ch);
333 GNUNET_MESH_TEST_cleanup (test_ctx);
334 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
336 GNUNET_SCHEDULER_cancel (shutdown_handle);
338 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
343 * Finish test normally: schedule disconnect and shutdown
345 * @param line Line in the code the abort is requested from (__LINE__).
348 abort_test (long line)
350 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
352 GNUNET_SCHEDULER_cancel (disconnect_task);
353 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
359 * Stats callback. Finish the stats testbed operation and when all stats have
360 * been iterated, shutdown the test.
363 * @param op the operation that has been finished
364 * @param emsg error message in case the operation has failed; will be NULL if
365 * operation has executed successfully.
368 stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
370 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
371 GNUNET_TESTBED_operation_done (stats_op);
373 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
374 GNUNET_SCHEDULER_cancel (disconnect_task);
375 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
382 * Process statistic values.
385 * @param peer the peer the statistic belong to
386 * @param subsystem name of subsystem that created the statistic
387 * @param name the name of the datum
388 * @param value the current value
389 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
390 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
393 stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
394 const char *subsystem, const char *name,
395 uint64_t value, int is_persistent)
399 i = GNUNET_TESTBED_get_index (peer);
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " STATS %u - %s [%s]: %llu\n",
401 i, subsystem, name, value);
408 * Task check that keepalives were sent and received.
410 * @param cls Closure (NULL).
411 * @param tc Task Context.
414 collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
416 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
419 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
420 stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
422 stats_iterator, stats_cont, NULL);
427 * @brief Finish profiler normally. Signal finish and start collecting stats.
429 * @param cls Closure (unused).
430 * @param tc Task context.
433 finish_profiler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
435 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
438 test_finished = GNUNET_YES;
440 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
444 * Set the total number of running peers.
446 * @param target Desired number of running peers.
449 adjust_running_peers (unsigned int target)
451 struct GNUNET_TESTBED_Operation *op;
457 GNUNET_assert (target <= peers_total);
459 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
460 if (target > peers_running)
462 delta = target - peers_running;
467 delta = peers_running - target;
471 for (i = 0; i < delta; i++)
474 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
475 peers_total - peers_pinging);
477 } while (peers[r].up == run || NULL != peers[r].incoming);
478 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
479 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
481 if (GNUNET_SCHEDULER_NO_TASK != peers[r].ping_task)
482 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
483 peers[r].ping_task = GNUNET_SCHEDULER_NO_TASK;
487 if (NULL != peers[r].ch)
488 GNUNET_MESH_channel_destroy (peers[r].ch);
490 if (NULL != peers[r].dest)
492 if (NULL != peers[r].dest->incoming_ch)
493 GNUNET_MESH_channel_destroy (peers[r].dest->incoming_ch);
494 peers[r].dest->incoming_ch = NULL;
497 op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
498 "mesh", NULL, NULL, run);
499 GNUNET_break (NULL != op);
500 peers_running += run ? 1 : -1;
501 GNUNET_assert (peers_running > 0);
507 * @brief Move to next round.
509 * @param cls Closure (round #).
510 * @param tc Task context.
513 next_rnd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
515 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
518 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
519 if (0.0 == rounds[current_round])
521 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
522 GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
525 adjust_running_peers (rounds[current_round] * peers_total);
528 GNUNET_SCHEDULER_add_delayed (ROUND_TIME, &next_rnd, NULL);
533 * Transmit ping callback.
535 * @param cls Closure (peer for PING, NULL for PONG).
536 * @param size Size of the tranmist buffer.
537 * @param buf Pointer to the beginning of the buffer.
539 * @return Number of bytes written to buf.
542 tmt_rdy_ping (void *cls, size_t size, void *buf);
546 * Transmit pong callback.
548 * @param cls Closure (copy of PING message, to be freed).
549 * @param size Size of the buffer we have.
550 * @param buf Buffer to copy data to.
553 tmt_rdy_pong (void *cls, size_t size, void *buf)
555 struct MeshPingMessage *ping = cls;
556 struct MeshPingMessage *pong;
558 if (0 == size || NULL == buf)
563 pong = (struct MeshPingMessage *) buf;
564 memcpy (pong, ping, sizeof (*ping));
565 pong->header.type = htons (PONG);
568 return sizeof (*ping);
573 * @brief Send a ping to destination
575 * @param cls Closure (peer).
576 * @param tc Task context.
579 ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
581 struct MeshPeer *peer = (struct MeshPeer *) cls;
583 peer->ping_task = GNUNET_SCHEDULER_NO_TASK;
585 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0
586 || GNUNET_YES == test_finished)
589 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n",
590 get_index (peer), get_index (peer->dest), peer->data_sent);
592 GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO,
593 GNUNET_TIME_UNIT_FOREVER_REL,
594 sizeof (struct MeshPingMessage),
595 &tmt_rdy_ping, peer);
599 * @brief Reply with a pong to origin.
601 * @param cls Closure (peer).
602 * @param tc Task context.
605 pong (struct GNUNET_MESH_Channel *channel, const struct MeshPingMessage *ping)
607 struct MeshPingMessage *copy;
609 copy = GNUNET_new (struct MeshPingMessage);
610 memcpy (copy, ping, sizeof (*ping));
611 GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO,
612 GNUNET_TIME_UNIT_FOREVER_REL,
613 sizeof (struct MeshPingMessage),
614 &tmt_rdy_pong, copy);
619 * Transmit ping callback
621 * @param cls Closure (peer).
622 * @param size Size of the buffer we have.
623 * @param buf Buffer to copy data to.
626 tmt_rdy_ping (void *cls, size_t size, void *buf)
628 struct MeshPeer *peer = (struct MeshPeer *) cls;
629 struct MeshPingMessage *msg = buf;
631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
632 if (size < sizeof (struct MeshPingMessage) || NULL == buf)
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "size %u, buf %p, data_sent %u, data_received %u\n",
637 size, buf, peer->data_sent, peer->data_received);
641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending: msg %d\n", peer->data_sent);
642 msg->header.size = htons (size);
643 msg->header.type = htons (PING);
644 msg->counter = htonl (peer->data_sent++);
645 msg->round_number = htonl (current_round);
646 msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
647 peer->pings[current_round]++;
648 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
651 return sizeof (struct MeshPingMessage);
656 * Function is called whenever a PING message is received.
658 * @param cls closure (peer #, set from GNUNET_MESH_connect)
659 * @param channel connection to the other end
660 * @param channel_ctx place to store local state associated with the channel
661 * @param message the actual message
662 * @return GNUNET_OK to keep the connection open,
663 * GNUNET_SYSERR to close it (signal serious error)
666 ping_handler (void *cls, struct GNUNET_MESH_Channel *channel,
668 const struct GNUNET_MessageHeader *message)
672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got PING\n", n);
673 GNUNET_MESH_receive_done (channel);
674 if (GNUNET_NO == test_finished)
675 pong (channel, (struct MeshPingMessage *) message);
682 * Function is called whenever a PONG message is received.
684 * @param cls closure (peer #, set from GNUNET_MESH_connect)
685 * @param channel connection to the other end
686 * @param channel_ctx place to store local state associated with the channel
687 * @param message the actual message
688 * @return GNUNET_OK to keep the connection open,
689 * GNUNET_SYSERR to close it (signal serious error)
692 pong_handler (void *cls, struct GNUNET_MESH_Channel *channel,
694 const struct GNUNET_MessageHeader *message)
697 struct MeshPeer *peer;
698 struct MeshPingMessage *msg;
699 struct GNUNET_TIME_Absolute send_time;
700 struct GNUNET_TIME_Relative latency;
701 unsigned int r /* Ping round */;
704 GNUNET_MESH_receive_done (channel);
707 msg = (struct MeshPingMessage *) message;
709 send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
710 latency = GNUNET_TIME_absolute_get_duration (send_time);
711 r = ntohl (msg->round_number);
712 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
713 get_index (peer), get_index (peer->dest), ntohl (msg->counter),
714 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
716 /* Online variance calculation */
718 delta = latency.rel_value_us - peer->mean[r];
719 peer->mean[r] = peer->mean[r] + delta/peer->pongs[r];
720 peer->var[r] += delta * (latency.rel_value_us - peer->mean[r]);
727 * Handlers, for diverse services
729 static struct GNUNET_MESH_MessageHandler handlers[] = {
730 {&ping_handler, PING, sizeof (struct MeshPingMessage)},
731 {&pong_handler, PONG, sizeof (struct MeshPingMessage)},
737 * Method called whenever another peer has added us to a channel
738 * the other peer initiated.
740 * @param cls Closure.
741 * @param channel New handle to the channel.
742 * @param initiator Peer that started the channel.
743 * @param port Port this channel is connected to.
744 * @param options channel option flags
745 * @return Initial channel context for the channel
746 * (can be NULL -- that's not an error).
749 incoming_channel (void *cls, struct GNUNET_MESH_Channel *channel,
750 const struct GNUNET_PeerIdentity *initiator,
751 uint32_t port, enum GNUNET_MESH_ChannelOption options)
754 struct MeshPeer *peer;
756 peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
757 GNUNET_assert (NULL != peer);
758 GNUNET_assert (peer == peers[n].incoming);
759 GNUNET_assert (peer->dest == &peers[n]);
760 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <= %u %p\n",
761 n, get_index (peer), channel);
762 peers[n].incoming_ch = channel;
768 * Function called whenever an inbound channel is destroyed. Should clean up
769 * any associated state.
771 * @param cls closure (set from GNUNET_MESH_connect)
772 * @param channel connection to the other end (henceforth invalid)
773 * @param channel_ctx place where local state associated
774 * with the channel is stored
777 channel_cleaner (void *cls, const struct GNUNET_MESH_Channel *channel,
781 struct MeshPeer *peer = &peers[n];
783 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
784 "Channel %p disconnected at peer %ld\n", channel, n);
785 if (peer->ch == channel)
790 static struct MeshPeer *
791 select_random_peer (struct MeshPeer *peer)
797 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
798 } while (NULL != peers[r].incoming);
799 peers[r].incoming = peer;
805 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
807 * Testcase continues when the root receives confirmation of connected peers,
808 * on callback funtion ch.
810 * @param cls Closure (unsued).
811 * @param tc Task Context.
814 start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
816 enum GNUNET_MESH_ChannelOption flags;
819 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
822 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
824 flags = GNUNET_MESH_OPTION_DEFAULT;
825 for (i = 0; i < peers_pinging; i++)
828 peers[i].dest = select_random_peer (&peers[i]);
829 peers[i].ch = GNUNET_MESH_channel_create (peers[i].mesh, NULL,
832 if (NULL == peers[i].ch)
834 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
835 GNUNET_SCHEDULER_shutdown ();
838 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u => %u %p\n",
839 i, get_index (peers[i].dest), peers[i].ch);
840 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
843 peers_running = peers_total;
844 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
845 GNUNET_SCHEDULER_cancel (disconnect_task);
847 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(ROUND_TIME,
849 &disconnect_mesh_peers,
851 GNUNET_SCHEDULER_add_delayed (ROUND_TIME, &next_rnd, NULL);
856 * Callback to be called when the requested peer information is available
858 * @param cls the closure from GNUNET_TESTBED_peer_get_information()
859 * @param op the operation this callback corresponds to
860 * @param pinfo the result; will be NULL if the operation has failed
861 * @param emsg error message if the operation has failed;
862 * NULL if the operation is successfull
865 peer_id_cb (void *cls,
866 struct GNUNET_TESTBED_Operation *op,
867 const struct GNUNET_TESTBED_PeerInformation *pinfo,
872 if (NULL == pinfo || NULL != emsg)
874 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
875 abort_test (__LINE__);
878 peers[n].id = *(pinfo->result.id);
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " %u id: %s\n",
880 n, GNUNET_i2s (&peers[n].id));
881 GNUNET_break (GNUNET_OK ==
882 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
883 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
885 GNUNET_TESTBED_operation_done (peers[n].op);
889 if (p_ids < peers_total)
891 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
892 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
897 * test main: start test when all peers are connected
899 * @param cls Closure.
900 * @param ctx Argument to give to GNUNET_MESH_TEST_cleanup on test end.
901 * @param num_peers Number of peers that are running.
902 * @param testbed_peers Array of peers.
903 * @param meshes Handle to each of the MESHs of the peers.
907 struct GNUNET_MESH_TEST_Context *ctx,
908 unsigned int num_peers,
909 struct GNUNET_TESTBED_Peer **testbed_peers,
910 struct GNUNET_MESH_Handle **meshes)
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
916 if (peers_total < 2 * peers_pinging)
918 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
919 "not enough peers, total should be > 2 * peers_pinging\n");
920 GNUNET_MESH_TEST_cleanup (ctx);
923 GNUNET_assert (peers_total == num_peers);
924 peers_running = num_peers;
925 testbed_handles = testbed_peers;
926 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
927 &disconnect_mesh_peers,
929 shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
930 &shutdown_task, NULL);
931 for (i = 0; i < peers_total; i++)
933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
934 peers[i].up = GNUNET_YES;
935 peers[i].mesh = meshes[i];
937 GNUNET_TESTBED_peer_get_information (testbed_handles[i],
938 GNUNET_TESTBED_PIT_IDENTITY,
939 &peer_id_cb, (void *) i);
941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
942 /* Continues from pi_cb -> do_test */
947 * Main: start profiler.
950 main (int argc, char *argv[])
952 static uint32_t ports[2];
953 const char *config_file;
955 config_file = ".profiler.conf";
959 fprintf (stderr, "usage: %s PEERS PINGS\n", argv[0]);
962 peers_total = atoll (argv[1]);
965 fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]);
968 peers = GNUNET_malloc (sizeof (struct MeshPeer) * peers_total);
970 peers_pinging = atoll (argv[2]);
972 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES);
973 GNUNET_assert (NULL != ids);
975 test_finished = GNUNET_NO;
978 GNUNET_MESH_TEST_run ("mesh-profiler", config_file, peers_total,
979 &tmain, NULL, /* tmain cls */
980 &incoming_channel, &channel_cleaner,
987 /* end of gnunet-mesh-profiler.c */