/*
This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file cadet/gnunet-cadet-profiler.c
/**
* Paximum ping period in milliseconds. Real period = rand (0, PING_PERIOD)
*/
-#define PING_PERIOD 1000
+#define PING_PERIOD 500
/**
* How long until we give up on connecting the peers?
/**
* Ratio of peers active. First round always is 1.0.
*/
-static float rounds[] = {0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.0};
+static float rounds[] = {0.8, 0.6, 0.8, 0.5, 0.3, 0.8, 0.0};
/**
* Message type for pings.
/**
* Task to do the next ping.
*/
- struct GNUNET_SCHEDULER_Task * ping_task;
+ struct GNUNET_SCHEDULER_Task *ping_task;
+
+ /**
+ * NTR operation for the next ping.
+ */
+ struct GNUNET_CADET_TransmitHandle *ping_ntr;
float mean[number_rounds];
float var[number_rounds];
/**
* Operation to get peer ids.
*/
-struct CadetPeer *peers;
+static struct CadetPeer *peers;
/**
* Peer ids counter.
*/
static struct GNUNET_CADET_TEST_Context *test_ctx;
-/**
- * Task called to shutdown test.
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
-
/**
* Task called to disconnect peers, before shutdown.
*/
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
/**
* Task to perform tests
*/
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
/**
* Round number.
*/
static int test_finished;
+/**
+ * Task running each round of the benchmark.
+ */
+static struct GNUNET_SCHEDULER_Task *round_task;
+
/**
* START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
* on callback funtion ch.
*
* @param cls Closure (unsued).
- * @param tc Task Context.
*/
static void
-start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+start_test (void *cls);
/**
}
-/**
- * Shut down peergroup, clean up.
- *
- * @param cls Closure (unused).
- * @param tc Task Context.
- */
-static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
- shutdown_handle = NULL;
-}
-
-
/**
* Disconnect from cadet services af all peers, call shutdown.
*
* @param cls Closure (unused).
- * @param tc Task Context.
*/
static void
-disconnect_cadet_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_cadet_peers (void *cls)
{
long line = (long) cls;
unsigned int i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting cadet service, called from line %ld\n", line);
+ "disconnecting cadet service, called from line %ld\n",
+ line);
disconnect_task = NULL;
for (i = 0; i < peers_total; i++)
{
if (NULL != peers[i].ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: channel %p\n", i, peers[i].ch);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: channel %p\n", i, peers[i].ch);
GNUNET_CADET_channel_destroy (peers[i].ch);
}
if (NULL != peers[i].warmup_ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: warmup channel %p\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: warmup channel %p\n",
i, peers[i].warmup_ch);
GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
}
if (NULL != peers[i].incoming_ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: incoming channel %p\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: incoming channel %p\n",
i, peers[i].incoming_ch);
GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
}
}
GNUNET_CADET_TEST_cleanup (test_ctx);
- if (NULL != shutdown_handle)
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Shut down peergroup, clean up.
+ *
+ * @param cls Closure (unused).
+ */
+static void
+shutdown_task (void *cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Ending test.\n");
+ if (NULL != disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) __LINE__);
+ }
+ if (NULL != round_task)
+ {
+ GNUNET_SCHEDULER_cancel (round_task);
+ round_task = NULL;
+ }
+ if (NULL != test_task)
{
- GNUNET_SCHEDULER_cancel (shutdown_handle);
+ GNUNET_SCHEDULER_cancel (test_task);
+ test_task = NULL;
}
- shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
* @param subsystem name of subsystem that created the statistic
* @param name the name of the datum
* @param value the current value
- * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
static int
-stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
- const char *subsystem, const char *name,
- uint64_t value, int is_persistent)
+stats_iterator (void *cls,
+ const struct GNUNET_TESTBED_Peer *peer,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
{
uint32_t i;
i = GNUNET_TESTBED_get_index (peer);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " STATS %u - %s [%s]: %llu\n",
- i, subsystem, name, value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " STATS %u - %s [%s]: %llu\n",
+ i, subsystem, name,
+ (unsigned long long) value);
return GNUNET_OK;
}
* Task check that keepalives were sent and received.
*
* @param cls Closure (NULL).
- * @param tc Task Context.
*/
static void
-collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+collect_stats (void *cls)
{
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
- stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Start collecting statistics...\n");
+ stats_op = GNUNET_TESTBED_get_statistics (peers_total,
+ testbed_handles,
NULL, NULL,
- stats_iterator, stats_cont, NULL);
+ &stats_iterator,
+ &stats_cont, NULL);
}
* @brief Finish profiler normally. Signal finish and start collecting stats.
*
* @param cls Closure (unused).
- * @param tc Task context.
*/
static void
-finish_profiler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+finish_profiler (void *cls)
{
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
test_finished = GNUNET_YES;
- show_end_data();
+ show_end_data ();
GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
}
+
/**
* Set the total number of running peers.
*
run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
if (NULL != peers[r].ping_task)
+ {
GNUNET_SCHEDULER_cancel (peers[r].ping_task);
- peers[r].ping_task = NULL;
-
+ peers[r].ping_task = NULL;
+ }
+ if (NULL != peers[r].ping_ntr)
+ {
+ GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
+ peers[r].ping_ntr = NULL;
+ }
peers[r].up = run;
if (NULL != peers[r].ch)
* @brief Move to next round.
*
* @param cls Closure (round #).
- * @param tc Task context.
*/
static void
-next_rnd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+next_rnd (void *cls)
{
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "ROUND %u\n",
+ current_round);
if (0.0 == rounds[current_round])
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
adjust_running_peers (rounds[current_round] * peers_total);
current_round++;
- GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
* @brief Send a ping to destination
*
* @param cls Closure (peer).
- * @param tc Task context.
*/
static void
-ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+ping (void *cls)
{
- struct CadetPeer *peer = (struct CadetPeer *) cls;
+ struct CadetPeer *peer = cls;
peer->ping_task = NULL;
-
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0
- || GNUNET_YES == test_finished)
+ if (GNUNET_YES == test_finished)
return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n",
- get_index (peer), get_index (peer->dest), peer->data_sent);
-
- GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
- GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof (struct CadetPingMessage),
- &tmt_rdy_ping, peer);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u -> %u (%u)\n",
+ get_index (peer),
+ get_index (peer->dest),
+ peer->data_sent);
+ peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof (struct CadetPingMessage),
+ &tmt_rdy_ping, peer);
}
/**
* @param tc Task context.
*/
static void
-pong (struct GNUNET_CADET_Channel *channel, const struct CadetPingMessage *ping)
+pong (struct GNUNET_CADET_Channel *channel,
+ const struct CadetPingMessage *ping)
{
struct CadetPingMessage *copy;
copy = GNUNET_new (struct CadetPingMessage);
- memcpy (copy, ping, sizeof (*ping));
+ *copy = *ping;
GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
sizeof (struct CadetPingMessage),
static size_t
tmt_rdy_ping (void *cls, size_t size, void *buf)
{
- struct CadetPeer *peer = (struct CadetPeer *) cls;
+ struct CadetPeer *peer = cls;
struct CadetPingMessage *msg = buf;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
+ peer->ping_ntr = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tmt_rdy called, filling buffer\n");
if (size < sizeof (struct CadetPingMessage) || NULL == buf)
{
GNUNET_break (GNUNET_YES == test_finished);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"size %u, buf %p, data_sent %u, data_received %u\n",
- size, buf, peer->data_sent, peer->data_received);
+ (unsigned int) size,
+ buf,
+ peer->data_sent,
+ peer->data_received);
return 0;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending: msg %d\n", peer->data_sent);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending: msg %d\n",
+ peer->data_sent);
msg->header.size = htons (size);
msg->header.type = htons (PING);
msg->counter = htonl (peer->data_sent++);
{
long n = (long) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got PING\n", n);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%u got PING\n",
+ (unsigned int) n);
GNUNET_CADET_receive_done (channel);
if (GNUNET_NO == test_finished)
pong (channel, (struct CadetPingMessage *) message);
GNUNET_assert (NULL != peer);
if (NULL == peers[n].incoming)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %3u: %u <= %u\n",
- peers_warmup, n, get_index (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "WARMUP %3u: %u <= %u\n",
+ peers_warmup,
+ (unsigned int) n,
+ get_index (peer));
peers_warmup++;
if (peers_warmup < peers_total)
return NULL;
}
GNUNET_assert (peer == peers[n].incoming);
GNUNET_assert (peer->dest == &peers[n]);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <= %u %p\n",
- n, get_index (peer), channel);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u <= %u %p\n",
+ (unsigned int) n,
+ get_index (peer),
+ channel);
peers[n].incoming_ch = channel;
return NULL;
* with the channel is stored
*/
static void
-channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
+channel_cleaner (void *cls,
+ const struct GNUNET_CADET_Channel *channel,
void *channel_ctx)
{
long n = (long) cls;
* on callback funtion ch.
*
* @param cls Closure (unsued).
- * @param tc Task Context.
*/
static void
-start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_test (void *cls)
{
enum GNUNET_CADET_ChannelOption flags;
unsigned long i;
test_task = NULL;
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
flags = GNUNET_CADET_OPTION_DEFAULT;
{
peers[i].dest = select_random_peer (&peers[i]);
peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
- &peers[i].dest->id,
- 1, flags);
+ &peers[i].dest->id,
+ 1, flags);
if (NULL == peers[i].ch)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
GNUNET_CADET_TEST_cleanup (test_ctx);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u => %u %p\n",
- i, get_index (peers[i].dest), peers[i].ch);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%lu => %u %p\n",
+ i,
+ get_index (peers[i].dest),
+ peers[i].ch);
peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
&ping, &peers[i]);
}
number_rounds + 1),
&disconnect_cadet_peers,
(void *) __LINE__);
- GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
}
}
+
/**
* Callback to be called when the requested peer information is available
*
*/
static void
peer_id_cb (void *cls,
- struct GNUNET_TESTBED_Operation *op,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
+ struct GNUNET_TESTBED_Operation *op,
+ const struct GNUNET_TESTBED_PeerInformation *pinfo,
+ const char *emsg)
{
long n = (long) cls;
return;
}
peers[n].id = *(pinfo->result.id);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, " %u id: %s\n",
- n, GNUNET_i2s (&peers[n].id));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%ld id: %s\n",
+ n,
+ GNUNET_i2s (&peers[n].id));
GNUNET_break (GNUNET_OK ==
GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
&start_test, NULL);
}
+
/**
* test main: start test when all peers are connected
*
{
unsigned long i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test main\n");
test_ctx = ctx;
GNUNET_assert (peers_total == num_peers);
peers_running = num_peers;
disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
&disconnect_cadet_peers,
(void *) __LINE__);
- shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
for (i = 0; i < peers_total; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "requesting id %ld\n",
+ i);
peers[i].up = GNUNET_YES;
peers[i].cadet = cadetes[i];
peers[i].op =
if (4 > argc)
{
- fprintf (stderr, "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", argv[0]);
- fprintf (stderr, "example: %s 30s 16 1 Y\n", argv[0]);
+ fprintf (stderr,
+ "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
+ argv[0]);
+ fprintf (stderr,
+ "example: %s 30s 16 1 Y\n",
+ argv[0]);
return 1;
}
- if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[1], &round_time))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_fancy_time_to_relative (argv[1],
+ &round_time))
{
- fprintf (stderr, "%s is not a valid time\n", argv[1]);
+ fprintf (stderr,
+ "%s is not a valid time\n",
+ argv[1]);
return 1;
}
peers_total = atoll (argv[2]);
if (2 > peers_total)
{
- fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]);
+ fprintf (stderr,
+ "%s peers is not valid (> 2)\n",
+ argv[1]);
return 1;
}
- peers = GNUNET_malloc (sizeof (struct CadetPeer) * peers_total);
-
+ peers = GNUNET_new_array (peers_total,
+ struct CadetPeer);
peers_pinging = atoll (argv[3]);
if (peers_total < 2 * peers_pinging)
do_warmup = (5 > argc || argv[4][0] != 'N');
- ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES);
+ ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
+ GNUNET_YES);
GNUNET_assert (NULL != ids);
p_ids = 0;
test_finished = GNUNET_NO;
}
/* end of gnunet-cadet-profiler.c */
-