diff options
author | Bart Polot <bart@net.in.tum.de> | 2014-03-14 15:49:13 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2014-03-14 15:49:13 +0000 |
commit | 6c633f3957fa05a3ad7003892c04fb9923ad7e39 (patch) | |
tree | e503931460f28a0d39ca304a182f0c4728e0a042 /src | |
parent | e3b0d9da6051251e66c8795f96d33fc9a439decd (diff) | |
download | gnunet-6c633f3957fa05a3ad7003892c04fb9923ad7e39.tar.gz gnunet-6c633f3957fa05a3ad7003892c04fb9923ad7e39.zip |
- use global hashmap for IDs
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/mesh_profiler.c | 124 |
1 files changed, 34 insertions, 90 deletions
diff --git a/src/mesh/mesh_profiler.c b/src/mesh/mesh_profiler.c index 50745ceb7..418d087f4 100644 --- a/src/mesh/mesh_profiler.c +++ b/src/mesh/mesh_profiler.c | |||
@@ -94,6 +94,11 @@ struct MeshPeer | |||
94 | }; | 94 | }; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * GNUNET_PeerIdentity -> MeshPeer | ||
98 | */ | ||
99 | static struct GNUNET_CONTAINER_MultiPeerMap *ids; | ||
100 | |||
101 | /** | ||
97 | * Testbed peer handles. | 102 | * Testbed peer handles. |
98 | */ | 103 | */ |
99 | static struct GNUNET_TESTBED_Peer **testbed_handles; | 104 | static struct GNUNET_TESTBED_Peer **testbed_handles; |
@@ -129,11 +134,6 @@ struct MeshPeer peers[TOTAL_PEERS]; | |||
129 | static unsigned int p_ids; | 134 | static unsigned int p_ids; |
130 | 135 | ||
131 | /** | 136 | /** |
132 | * Is the setup initialized? | ||
133 | */ | ||
134 | static int initialized; | ||
135 | |||
136 | /** | ||
137 | * Total number of currently running peers. | 137 | * Total number of currently running peers. |
138 | */ | 138 | */ |
139 | static unsigned long long peers_running; | 139 | static unsigned long long peers_running; |
@@ -158,11 +158,6 @@ static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | |||
158 | */ | 158 | */ |
159 | static GNUNET_SCHEDULER_TaskIdentifier test_task; | 159 | static GNUNET_SCHEDULER_TaskIdentifier test_task; |
160 | 160 | ||
161 | /** | ||
162 | * Time we started the data transmission (after channel has been established | ||
163 | * and initilized). | ||
164 | */ | ||
165 | static struct GNUNET_TIME_Absolute start_time; | ||
166 | 161 | ||
167 | /** | 162 | /** |
168 | * Flag to notify callbacks not to generate any new traffic anymore. | 163 | * Flag to notify callbacks not to generate any new traffic anymore. |
@@ -206,18 +201,6 @@ get_index (struct MeshPeer *peer) | |||
206 | static void | 201 | static void |
207 | show_end_data (void) | 202 | show_end_data (void) |
208 | { | 203 | { |
209 | static struct GNUNET_TIME_Absolute end_time; | ||
210 | static struct GNUNET_TIME_Relative total_time; | ||
211 | |||
212 | end_time = GNUNET_TIME_absolute_get(); | ||
213 | total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); | ||
214 | FPRINTF (stderr, "Test time %s\n", | ||
215 | GNUNET_STRINGS_relative_time_to_string (total_time, | ||
216 | GNUNET_YES)); | ||
217 | FPRINTF (stderr, "Test bandwidth: %f kb/s\n", | ||
218 | 4 * TOTAL_PACKETS * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms | ||
219 | FPRINTF (stderr, "Test throughput: %f packets/s\n\n", | ||
220 | TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms | ||
221 | } | 204 | } |
222 | 205 | ||
223 | 206 | ||
@@ -327,7 +310,6 @@ stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer, | |||
327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u - %s [%s]: %llu\n", | 310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u - %s [%s]: %llu\n", |
328 | i, subsystem, name, value); | 311 | i, subsystem, name, value); |
329 | 312 | ||
330 | |||
331 | return GNUNET_OK; | 313 | return GNUNET_OK; |
332 | } | 314 | } |
333 | 315 | ||
@@ -385,33 +367,6 @@ tmt_rdy (void *cls, size_t size, void *buf); | |||
385 | 367 | ||
386 | 368 | ||
387 | /** | 369 | /** |
388 | * Task to schedule a new data transmission. | ||
389 | * | ||
390 | * @param cls Closure (peer). | ||
391 | * @param tc Task Context. | ||
392 | */ | ||
393 | static void | ||
394 | data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
395 | { | ||
396 | struct MeshPeer *peer = (struct MeshPeer *) cls; | ||
397 | struct GNUNET_MESH_TransmitHandle *th; | ||
398 | struct GNUNET_MESH_Channel *channel; | ||
399 | |||
400 | if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) | ||
401 | return; | ||
402 | |||
403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n"); | ||
404 | |||
405 | channel = peer->ch; | ||
406 | th = GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO, | ||
407 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
408 | size_payload, &tmt_rdy, peer); | ||
409 | if (NULL == th) | ||
410 | GNUNET_abort (); | ||
411 | } | ||
412 | |||
413 | |||
414 | /** | ||
415 | * @brief Send data to destination | 370 | * @brief Send data to destination |
416 | * | 371 | * |
417 | * @param cls Closure (peer). | 372 | * @param cls Closure (peer). |
@@ -448,6 +403,7 @@ tmt_rdy (void *cls, size_t size, void *buf) | |||
448 | struct MeshPeer *peer = (struct MeshPeer *) cls; | 403 | struct MeshPeer *peer = (struct MeshPeer *) cls; |
449 | struct GNUNET_MessageHeader *msg = buf; | 404 | struct GNUNET_MessageHeader *msg = buf; |
450 | uint32_t *data; | 405 | uint32_t *data; |
406 | unsigned int s; | ||
451 | 407 | ||
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n"); | 408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n"); |
453 | if (size < size_payload || NULL == buf) | 409 | if (size < size_payload || NULL == buf) |
@@ -464,26 +420,20 @@ tmt_rdy (void *cls, size_t size, void *buf) | |||
464 | msg->type = htons ((long) cls); | 420 | msg->type = htons ((long) cls); |
465 | data = (uint32_t *) &msg[1]; | 421 | data = (uint32_t *) &msg[1]; |
466 | *data = htonl (peer->data_sent); | 422 | *data = htonl (peer->data_sent); |
467 | if (GNUNET_NO == initialized) | 423 | if (0 == peer->data_sent) |
468 | { | 424 | { |
469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: initializer\n"); |
470 | "sending initializer\n"); | 426 | s = 5; |
471 | } | 427 | } |
472 | else | 428 | else |
473 | { | 429 | { |
474 | peer->data_sent++; | 430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: msg %d\n", peer->data_sent); |
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 431 | s = 60; |
476 | " Sent packet %d\n", peer->data_sent); | ||
477 | if (peer->data_sent < TOTAL_PACKETS) | ||
478 | { | ||
479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
480 | " Scheduling packet %d\n", peer->data_sent + 1); | ||
481 | GNUNET_SCHEDULER_add_now (&data_task, peer); | ||
482 | } | ||
483 | } | 432 | } |
433 | peer->data_sent++; | ||
484 | peer->timestamp = GNUNET_TIME_absolute_get (); | 434 | peer->timestamp = GNUNET_TIME_absolute_get (); |
485 | peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (60 * 1000), | 435 | peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (s * 1000), |
486 | &ping, peer); | 436 | &ping, peer); |
487 | 437 | ||
488 | return size_payload; | 438 | return size_payload; |
489 | } | 439 | } |
@@ -492,7 +442,7 @@ tmt_rdy (void *cls, size_t size, void *buf) | |||
492 | /** | 442 | /** |
493 | * Function is called whenever a message is received. | 443 | * Function is called whenever a message is received. |
494 | * | 444 | * |
495 | * @param cls closure (set from GNUNET_MESH_connect) | 445 | * @param cls closure (peer #, set from GNUNET_MESH_connect) |
496 | * @param channel connection to the other end | 446 | * @param channel connection to the other end |
497 | * @param channel_ctx place to store local state associated with the channel | 447 | * @param channel_ctx place to store local state associated with the channel |
498 | * @param message the actual message | 448 | * @param message the actual message |
@@ -504,28 +454,19 @@ data_callback (void *cls, struct GNUNET_MESH_Channel *channel, | |||
504 | void **channel_ctx, | 454 | void **channel_ctx, |
505 | const struct GNUNET_MessageHeader *message) | 455 | const struct GNUNET_MessageHeader *message) |
506 | { | 456 | { |
507 | // long n = (long) cls; | 457 | long n = (long) cls; |
458 | struct MeshPeer *peer; | ||
459 | struct GNUNET_TIME_Relative latency; | ||
508 | 460 | ||
509 | GNUNET_MESH_receive_done (channel); | 461 | GNUNET_MESH_receive_done (channel); |
462 | peer = &peers[n]; | ||
510 | 463 | ||
511 | 464 | GNUNET_assert (0 != peer->timestamp.abs_value_us); | |
512 | if (GNUNET_NO == initialized) | 465 | latency = GNUNET_TIME_absolute_get_duration (peer->incoming->timestamp); |
513 | { | 466 | FPRINTF (stderr, "%u -> %ld latency: %s\n", |
514 | initialized = GNUNET_YES; | 467 | get_index (peer->incoming), n, |
515 | start_time = GNUNET_TIME_absolute_get (); | 468 | GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO)); |
516 | GNUNET_SCHEDULER_add_now (&data_task, NULL); | 469 | peer->timestamp.abs_value_us = 0; |
517 | } | ||
518 | GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO, | ||
519 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
520 | size_payload, &tmt_rdy, (void *) 1L); | ||
521 | |||
522 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | ||
523 | { | ||
524 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
525 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | ||
526 | &disconnect_mesh_peers, | ||
527 | (void *) __LINE__); | ||
528 | } | ||
529 | 470 | ||
530 | return GNUNET_OK; | 471 | return GNUNET_OK; |
531 | } | 472 | } |
@@ -558,12 +499,11 @@ incoming_channel (void *cls, struct GNUNET_MESH_Channel *channel, | |||
558 | uint32_t port, enum GNUNET_MESH_ChannelOption options) | 499 | uint32_t port, enum GNUNET_MESH_ChannelOption options) |
559 | { | 500 | { |
560 | long n = (long) cls; | 501 | long n = (long) cls; |
502 | struct MeshPeer *peer; | ||
561 | 503 | ||
562 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 504 | peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator); |
563 | "Incoming channel from %s to peer %ld\n", | 505 | GNUNET_assert (NULL != peer); |
564 | GNUNET_i2s (initiator), n); | 506 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <= %u\n", n, get_index (peer)); |
565 | ok++; | ||
566 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | ||
567 | peers[n].incoming_ch = channel; | 507 | peers[n].incoming_ch = channel; |
568 | 508 | ||
569 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 509 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) |
@@ -673,6 +613,9 @@ peer_id_cb (void *cls, | |||
673 | peers[n].id = *(pinfo->result.id); | 613 | peers[n].id = *(pinfo->result.id); |
674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u id: %s\n", | 614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u id: %s\n", |
675 | n, GNUNET_i2s (&peers[n].id)); | 615 | n, GNUNET_i2s (&peers[n].id)); |
616 | GNUNET_break (GNUNET_OK == | ||
617 | GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n], | ||
618 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | ||
676 | p_ids++; | 619 | p_ids++; |
677 | if (p_ids < TOTAL_PEERS) | 620 | if (p_ids < TOTAL_PEERS) |
678 | return; | 621 | return; |
@@ -731,12 +674,13 @@ tmain (void *cls, | |||
731 | int | 674 | int |
732 | main (int argc, char *argv[]) | 675 | main (int argc, char *argv[]) |
733 | { | 676 | { |
734 | initialized = GNUNET_NO; | ||
735 | static uint32_t ports[2]; | 677 | static uint32_t ports[2]; |
736 | const char *config_file; | 678 | const char *config_file; |
737 | 679 | ||
738 | config_file = "test_mesh.conf"; | 680 | config_file = "test_mesh.conf"; |
739 | 681 | ||
682 | ids = GNUNET_CONTAINER_multipeermap_create (2 * TOTAL_PEERS, GNUNET_YES); | ||
683 | GNUNET_assert (NULL != ids); | ||
740 | p_ids = 0; | 684 | p_ids = 0; |
741 | test_finished = GNUNET_NO; | 685 | test_finished = GNUNET_NO; |
742 | ports[0] = 1; | 686 | ports[0] = 1; |