aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-03-17 11:02:23 +0000
committerBart Polot <bart@net.in.tum.de>2014-03-17 11:02:23 +0000
commit81ed24969da3230870f5bbd4965f0202e55b1d0f (patch)
tree99bd066cb07a16d60eb886a9f50c381a97993cb1 /src
parent141f89d7b89449954cbd38b4930507fcdba5c607 (diff)
downloadgnunet-81ed24969da3230870f5bbd4965f0202e55b1d0f.tar.gz
gnunet-81ed24969da3230870f5bbd4965f0202e55b1d0f.zip
- nse-style round cycling
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-mesh-profiler.c105
1 files changed, 87 insertions, 18 deletions
diff --git a/src/mesh/gnunet-mesh-profiler.c b/src/mesh/gnunet-mesh-profiler.c
index c0c0bfe30..8d6984170 100644
--- a/src/mesh/gnunet-mesh-profiler.c
+++ b/src/mesh/gnunet-mesh-profiler.c
@@ -38,6 +38,16 @@
38#define TOTAL_PEERS 10 38#define TOTAL_PEERS 10
39 39
40/** 40/**
41 * Duration of each round.
42 */
43#define ROUND_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
44
45/**
46 * Paximum ping period in milliseconds. Real period = rand (0, PING_PERIOD)
47 */
48#define PING_PERIOD 2000
49
50/**
41 * How long until we give up on connecting the peers? 51 * How long until we give up on connecting the peers?
42 */ 52 */
43#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 53#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
@@ -47,6 +57,7 @@
47 */ 57 */
48#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 58#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
49 59
60static float rounds[] = {0.8, 0.7, 0.6, 0.5, 0.0};
50 61
51struct MeshPeer 62struct MeshPeer
52{ 63{
@@ -85,6 +96,8 @@ struct MeshPeer
85 */ 96 */
86 int data_received; 97 int data_received;
87 98
99 int up;
100
88 struct MeshPeer *dest; 101 struct MeshPeer *dest;
89 struct MeshPeer *incoming; 102 struct MeshPeer *incoming;
90 GNUNET_SCHEDULER_TaskIdentifier ping_task; 103 GNUNET_SCHEDULER_TaskIdentifier ping_task;
@@ -333,7 +346,7 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
333 346
334 347
335/** 348/**
336 * @brief Finish profiler normally. 349 * @brief Finish profiler normally. Signal finish and start collecting stats.
337 * 350 *
338 * @param cls Closure (unused). 351 * @param cls Closure (unused).
339 * @param tc Task context. 352 * @param tc Task context.
@@ -349,6 +362,71 @@ finish_profiler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
349 GNUNET_SCHEDULER_add_now (&collect_stats, NULL); 362 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
350} 363}
351 364
365/**
366 * Set the total number of running peers.
367 *
368 * @param target Desired number of running peers.
369 */
370static void
371adjust_running_peers (unsigned int target)
372{
373 struct GNUNET_TESTBED_Operation *op;
374 unsigned int delta;
375 unsigned int run;
376 unsigned int i;
377 unsigned int r;
378
379 GNUNET_assert (target <= TOTAL_PEERS);
380
381 if (target > peers_running)
382 {
383 delta = target - peers_running;
384 run = GNUNET_YES;
385 }
386 else
387 {
388 delta = peers_running - target;
389 run = GNUNET_NO;
390 }
391
392 for (i = 0; i < delta; i++)
393 {
394 do {
395 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TOTAL_PEERS);
396 } while (!run == peers[r].up);
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "St%s peer %\n",
398 run ? "arting" : "opping", GNUNET_i2s (&peers[r].id));
399 op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
400 "mesh", NULL, NULL, run);
401 GNUNET_break (NULL != op);
402 }
403}
404
405
406/**
407 * @brief Move to next round.
408 *
409 * @param cls Closure (round #).
410 * @param tc Task context.
411 */
412static void
413next_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
414{
415 long round = (long) cls;
416
417 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
418 return;
419
420 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", round);
421 if (0.0 == rounds[round])
422 {
423 GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
424 return;
425 }
426 adjust_running_peers (rounds[round] * TOTAL_PEERS);
427
428 GNUNET_SCHEDULER_add_delayed (ROUND_TIME, &next_round, (void *) (round + 1));
429}
352 430
353 431
354/** 432/**
@@ -418,7 +496,6 @@ tmt_rdy (void *cls, size_t size, void *buf)
418 struct MeshPeer *peer = (struct MeshPeer *) cls; 496 struct MeshPeer *peer = (struct MeshPeer *) cls;
419 struct GNUNET_MessageHeader *msg = buf; 497 struct GNUNET_MessageHeader *msg = buf;
420 uint32_t *data; 498 uint32_t *data;
421 unsigned int s;
422 499
423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n"); 500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
424 if (size < size_payload || NULL == buf) 501 if (size < size_payload || NULL == buf)
@@ -440,19 +517,10 @@ tmt_rdy (void *cls, size_t size, void *buf)
440 msg->type = htons (PING); 517 msg->type = htons (PING);
441 data = (uint32_t *) &msg[1]; 518 data = (uint32_t *) &msg[1];
442 *data = htonl (peer->data_sent); 519 *data = htonl (peer->data_sent);
443 if (0 == peer->data_sent) 520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: msg %d\n", peer->data_sent);
444 {
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: initializer\n");
446 s = 5;
447 }
448 else
449 {
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: msg %d\n", peer->data_sent);
451 s = 60;
452 }
453 peer->data_sent++; 521 peer->data_sent++;
454 peer->timestamp = GNUNET_TIME_absolute_get (); 522 peer->timestamp = GNUNET_TIME_absolute_get ();
455 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (s * 1000), 523 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
456 &ping, peer); 524 &ping, peer);
457 525
458 return size_payload; 526 return size_payload;
@@ -616,7 +684,7 @@ select_random_peer (struct MeshPeer *peer)
616} 684}
617 685
618/** 686/**
619 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES. 687 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
620 * 688 *
621 * Testcase continues when the root receives confirmation of connected peers, 689 * Testcase continues when the root receives confirmation of connected peers,
622 * on callback funtion ch. 690 * on callback funtion ch.
@@ -625,7 +693,7 @@ select_random_peer (struct MeshPeer *peer)
625 * @param tc Task Context. 693 * @param tc Task Context.
626 */ 694 */
627static void 695static void
628do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 696start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
629{ 697{
630 enum GNUNET_MESH_ChannelOption flags; 698 enum GNUNET_MESH_ChannelOption flags;
631 unsigned long i; 699 unsigned long i;
@@ -654,6 +722,8 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
654 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000), 722 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
655 &ping, &peers[i]); 723 &ping, &peers[i]);
656 } 724 }
725 peers_running = TOTAL_PEERS;
726 GNUNET_SCHEDULER_add_delayed (ROUND_TIME, &next_round, NULL);
657} 727}
658 728
659 729
@@ -691,7 +761,7 @@ peer_id_cb (void *cls,
691 return; 761 return;
692 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n"); 762 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
693 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 763 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
694 &do_test, NULL); 764 &start_test, NULL);
695} 765}
696 766
697/** 767/**
@@ -718,8 +788,6 @@ tmain (void *cls,
718 GNUNET_assert (TOTAL_PEERS == num_peers); 788 GNUNET_assert (TOTAL_PEERS == num_peers);
719 peers_running = num_peers; 789 peers_running = num_peers;
720 testbed_handles = testbed_peers; 790 testbed_handles = testbed_peers;
721 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
722 &finish_profiler, NULL);
723 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 791 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
724 &disconnect_mesh_peers, 792 &disconnect_mesh_peers,
725 (void *) __LINE__); 793 (void *) __LINE__);
@@ -728,6 +796,7 @@ tmain (void *cls,
728 for (i = 0; i < TOTAL_PEERS; i++) 796 for (i = 0; i < TOTAL_PEERS; i++)
729 { 797 {
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i); 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
799 peers[i].up = GNUNET_YES;
731 peers[i].mesh = meshes[i]; 800 peers[i].mesh = meshes[i];
732 peers[i].op = 801 peers[i].op =
733 GNUNET_TESTBED_peer_get_information (testbed_handles[i], 802 GNUNET_TESTBED_peer_get_information (testbed_handles[i],