#define PING 1
#define PONG 2
-/**
- * How many peers to run
- */
-#define TOTAL_PEERS 10
/**
* How many peers do pinging
*/
-#define PING_PEERS 1
-
+#define PING_PEERS 3
/**
* Duration of each round.
/**
* Paximum ping period in milliseconds. Real period = rand (0, PING_PERIOD)
*/
-#define PING_PERIOD 2000
+#define PING_PERIOD 1000
/**
* How long until we give up on connecting the peers?
*/
#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+/**
+ * Total number of rounds.
+ */
+#define number_rounds sizeof(rounds)/sizeof(rounds[0])
+
+/**
+ * Ratio of peers active. First round always is 1.0.
+ */
static float rounds[] = {0.8, 0.7, 0.6, 0.5, 0.0};
/**
* Time the message was sent.
*/
struct GNUNET_TIME_AbsoluteNBO timestamp;
+
+ /**
+ * Round number.
+ */
+ uint32_t round_number;
};
/**
*/
int data_received;
+ /**
+ * Is peer up?
+ */
int up;
/**
* Task to do the next ping.
*/
GNUNET_SCHEDULER_TaskIdentifier ping_task;
+
+ float mean[number_rounds];
+ float var[number_rounds];
+ unsigned int pongs[number_rounds];
+ unsigned int pings[number_rounds];
+
};
/**
*/
static struct GNUNET_TESTBED_Operation *stats_op;
-/**
- * How many events have happened
- */
-static int ok;
-
-/**
- * Number of events expected to conclude the test successfully.
- */
-static int ok_goal;
-
/**
* Operation to get peer ids.
*/
-struct MeshPeer peers[TOTAL_PEERS];
+struct MeshPeer *peers;
/**
* Peer ids counter.
static unsigned int p_ids;
/**
- * Total number of currently running peers.
+ * Total number of peers.
+ */
+static unsigned long long peers_total;
+
+/**
+ * Number of currently running peers.
*/
static unsigned long long peers_running;
*/
static GNUNET_SCHEDULER_TaskIdentifier test_task;
+/**
+ * Round number.
+ */
+static unsigned int current_round;
/**
* Flag to notify callbacks not to generate any new traffic anymore.
static void
show_end_data (void)
{
+ struct MeshPeer *peer;
+ unsigned int i;
+ unsigned int j;
+
+ for (i = 0; i < number_rounds; i++)
+ {
+ for (j = 0; j < PING_PEERS; j++)
+ {
+ peer = &peers[j];
+ FPRINTF (stdout,
+ "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
+ i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
+ peer->pings[i], peer->pongs[i]);
+ }
+ }
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"disconnecting mesh service, called from line %ld\n", line);
disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- for (i = 0; i < TOTAL_PEERS; i++)
+ for (i = 0; i < peers_total; i++)
{
if (NULL != peers[i].op)
GNUNET_TESTBED_operation_done (peers[i].op);
return;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
- stats_op = GNUNET_TESTBED_get_statistics (TOTAL_PEERS, testbed_handles,
+ stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
NULL, NULL,
stats_iterator, stats_cont, NULL);
}
unsigned int i;
unsigned int r;
- GNUNET_assert (target <= TOTAL_PEERS);
+ GNUNET_assert (target <= peers_total);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
if (target > peers_running)
{
do {
r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- TOTAL_PEERS - PING_PEERS);
+ peers_total - PING_PEERS);
r += PING_PEERS;
} while (peers[r].up == run || NULL != peers[r].incoming);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
static void
next_rnd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- long round = (long) cls;
-
if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", round);
- if (0.0 == rounds[round])
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
+ if (0.0 == rounds[current_round])
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
return;
}
- adjust_running_peers (rounds[round] * TOTAL_PEERS);
+ adjust_running_peers (rounds[current_round] * peers_total);
+ current_round++;
- GNUNET_SCHEDULER_add_delayed (ROUND_TIME, &next_rnd, (void *) (round + 1));
+ GNUNET_SCHEDULER_add_delayed (ROUND_TIME, &next_rnd, NULL);
}
msg->header.size = htons (size);
msg->header.type = htons (PING);
msg->counter = htonl (peer->data_sent++);
+ msg->round_number = htonl (current_round);
msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
+ peer->pings[current_round]++;
peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
&ping, peer);
struct MeshPingMessage *msg;
struct GNUNET_TIME_Absolute send_time;
struct GNUNET_TIME_Relative latency;
+ unsigned int r /* Ping round */;
+ float delta;
GNUNET_MESH_receive_done (channel);
peer = &peers[n];
send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
latency = GNUNET_TIME_absolute_get_duration (send_time);
+ r = ntohl (msg->round_number);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
get_index (peer), get_index (peer->dest), ntohl (msg->counter),
GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
+ /* Online variance calculation */
+ peer->pongs[r]++;
+ delta = latency.rel_value_us - peer->mean[r];
+ peer->mean[r] = peer->mean[r] + delta/peer->pongs[r];
+ peer->var[r] += delta * (latency.rel_value_us - peer->mean[r]);
+
return GNUNET_OK;
}
do
{
- r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TOTAL_PEERS);
+ r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
} while (NULL != peers[r].incoming);
peers[r].incoming = peer;
peers[i].ch = GNUNET_MESH_channel_create (peers[i].mesh, NULL,
&peers[i].dest->id,
1, flags);
+ if (NULL == peers[i].ch)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u => %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]);
}
- peers_running = TOTAL_PEERS;
+ peers_running = peers_total;
+ if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(ROUND_TIME,
+ number_rounds + 1),
+ &disconnect_mesh_peers,
+ (void *) __LINE__);
GNUNET_SCHEDULER_add_delayed (ROUND_TIME, &next_rnd, NULL);
}
peers[n].op = NULL;
p_ids++;
- if (p_ids < TOTAL_PEERS)
+ if (p_ids < peers_total)
return;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
unsigned long i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
- ok = 0;
test_ctx = ctx;
- GNUNET_assert (TOTAL_PEERS > 2 * PING_PEERS);
- GNUNET_assert (TOTAL_PEERS == num_peers);
+ GNUNET_assert (peers_total > 2 * PING_PEERS);
+ GNUNET_assert (peers_total == num_peers);
peers_running = num_peers;
testbed_handles = testbed_peers;
disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
(void *) __LINE__);
shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task, NULL);
- for (i = 0; i < TOTAL_PEERS; i++)
+ for (i = 0; i < peers_total; i++)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
peers[i].up = GNUNET_YES;
static uint32_t ports[2];
const char *config_file;
- config_file = "test_mesh.conf";
+ config_file = ".profiler.conf";
+
+ if (2 > argc)
+ {
+ fprintf (stderr, "usage: %s PEERS\n", argv[0]);
+ return 1;
+ }
+ peers_total = atoll (argv[1]);
+ if (2 > peers_total)
+ {
+ fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]);
+ return 1;
+ }
- ids = GNUNET_CONTAINER_multipeermap_create (2 * TOTAL_PEERS, GNUNET_YES);
+ ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES);
GNUNET_assert (NULL != ids);
p_ids = 0;
test_finished = GNUNET_NO;
ports[0] = 1;
ports[1] = 0;
- GNUNET_MESH_TEST_run ("mesh-profiler", config_file, TOTAL_PEERS,
+ GNUNET_MESH_TEST_run ("mesh-profiler", config_file, peers_total,
&tmain, NULL, /* tmain cls */
&incoming_channel, &channel_cleaner,
handlers, ports);
- if (ok_goal > ok)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "FAILED! (%d/%d)\n", ok, ok_goal);
- return 1;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
return 0;
}