aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-03-17 11:02:53 +0000
committerBart Polot <bart@net.in.tum.de>2014-03-17 11:02:53 +0000
commitd8824219557a50f5a7343b172b5727e3505402e6 (patch)
tree0369dc110f937620f2828ce91fd972904aec4038 /src
parentc5a4f1e2cefbb8736857da95dfccbd4cfd504d45 (diff)
downloadgnunet-d8824219557a50f5a7343b172b5727e3505402e6.tar.gz
gnunet-d8824219557a50f5a7343b172b5727e3505402e6.zip
- use explicit ping/pong messages with counter and timestamp
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-mesh-profiler.c144
1 files changed, 87 insertions, 57 deletions
diff --git a/src/mesh/gnunet-mesh-profiler.c b/src/mesh/gnunet-mesh-profiler.c
index 4b9ac1676..f1c099290 100644
--- a/src/mesh/gnunet-mesh-profiler.c
+++ b/src/mesh/gnunet-mesh-profiler.c
@@ -65,6 +65,30 @@
65 65
66static float rounds[] = {0.8, 0.7, 0.6, 0.5, 0.0}; 66static float rounds[] = {0.8, 0.7, 0.6, 0.5, 0.0};
67 67
68/**
69 * Message type for pings.
70 */
71struct MeshPingMessage
72{
73 /**
74 * Header. Type PING/PONG.
75 */
76 struct GNUNET_MessageHeader header;
77
78 /**
79 * Message number.
80 */
81 uint32_t counter;
82
83 /**
84 * Time the message was sent.
85 */
86 struct GNUNET_TIME_AbsoluteNBO timestamp;
87};
88
89/**
90 * Peer description.
91 */
68struct MeshPeer 92struct MeshPeer
69{ 93{
70 /** 94 /**
@@ -118,11 +142,6 @@ struct MeshPeer
118 * Task to do the next ping. 142 * Task to do the next ping.
119 */ 143 */
120 GNUNET_SCHEDULER_TaskIdentifier ping_task; 144 GNUNET_SCHEDULER_TaskIdentifier ping_task;
121
122 /**
123 * Time the last ping was sent.
124 */
125 struct GNUNET_TIME_Absolute timestamp;
126}; 145};
127 146
128/** 147/**
@@ -151,11 +170,6 @@ static int ok;
151static int ok_goal; 170static int ok_goal;
152 171
153/** 172/**
154 * Size of each test packet
155 */
156size_t size_payload = sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t);
157
158/**
159 * Operation to get peer ids. 173 * Operation to get peer ids.
160 */ 174 */
161struct MeshPeer peers[TOTAL_PEERS]; 175struct MeshPeer peers[TOTAL_PEERS];
@@ -486,7 +500,7 @@ next_rnd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
486 500
487 501
488/** 502/**
489 * Transmit ready callback. 503 * Transmit ping callback.
490 * 504 *
491 * @param cls Closure (peer for PING, NULL for PONG). 505 * @param cls Closure (peer for PING, NULL for PONG).
492 * @param size Size of the tranmist buffer. 506 * @param size Size of the tranmist buffer.
@@ -495,7 +509,34 @@ next_rnd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
495 * @return Number of bytes written to buf. 509 * @return Number of bytes written to buf.
496 */ 510 */
497static size_t 511static size_t
498tmt_rdy (void *cls, size_t size, void *buf); 512tmt_rdy_ping (void *cls, size_t size, void *buf);
513
514
515/**
516 * Transmit pong callback.
517 *
518 * @param cls Closure (copy of PING message, to be freed).
519 * @param size Size of the buffer we have.
520 * @param buf Buffer to copy data to.
521 */
522static size_t
523tmt_rdy_pong (void *cls, size_t size, void *buf)
524{
525 struct MeshPingMessage *ping = cls;
526 struct MeshPingMessage *pong;
527
528 if (0 == size || NULL == buf)
529 {
530 GNUNET_free (ping);
531 return 0;
532 }
533 pong = (struct MeshPingMessage *) buf;
534 memcpy (pong, ping, sizeof (*ping));
535 pong->header.type = htons (PONG);
536
537 GNUNET_free (ping);
538 return sizeof (*ping);
539}
499 540
500 541
501/** 542/**
@@ -512,16 +553,16 @@ ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
512 peer->ping_task = GNUNET_SCHEDULER_NO_TASK; 553 peer->ping_task = GNUNET_SCHEDULER_NO_TASK;
513 554
514 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0 555 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0
515 || GNUNET_YES == test_finished 556 || GNUNET_YES == test_finished)
516 || 0 != peer->timestamp.abs_value_us)
517 return; 557 return;
518 558
519 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u\n", 559 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n",
520 get_index (peer), get_index (peer->dest)); 560 get_index (peer), get_index (peer->dest), peer->data_sent);
521 561
522 GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO, 562 GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO,
523 GNUNET_TIME_UNIT_FOREVER_REL, 563 GNUNET_TIME_UNIT_FOREVER_REL,
524 size_payload, &tmt_rdy, peer); 564 sizeof (struct MeshPingMessage),
565 &tmt_rdy_ping, peer);
525} 566}
526 567
527/** 568/**
@@ -531,30 +572,34 @@ ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
531 * @param tc Task context. 572 * @param tc Task context.
532 */ 573 */
533static void 574static void
534pong (struct GNUNET_MESH_Channel *channel) 575pong (struct GNUNET_MESH_Channel *channel, const struct MeshPingMessage *ping)
535{ 576{
577 struct MeshPingMessage *copy;
578
579 copy = GNUNET_new (struct MeshPingMessage);
580 memcpy (copy, ping, sizeof (*ping));
536 GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO, 581 GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO,
537 GNUNET_TIME_UNIT_FOREVER_REL, 582 GNUNET_TIME_UNIT_FOREVER_REL,
538 size_payload, &tmt_rdy, NULL); 583 sizeof (struct MeshPingMessage),
584 &tmt_rdy_pong, copy);
539} 585}
540 586
541 587
542/** 588/**
543 * Transmit ready callback 589 * Transmit ping callback
544 * 590 *
545 * @param cls Closure (peer for PING, NULL for PONG). 591 * @param cls Closure (peer).
546 * @param size Size of the buffer we have. 592 * @param size Size of the buffer we have.
547 * @param buf Buffer to copy data to. 593 * @param buf Buffer to copy data to.
548 */ 594 */
549static size_t 595static size_t
550tmt_rdy (void *cls, size_t size, void *buf) 596tmt_rdy_ping (void *cls, size_t size, void *buf)
551{ 597{
552 struct MeshPeer *peer = (struct MeshPeer *) cls; 598 struct MeshPeer *peer = (struct MeshPeer *) cls;
553 struct GNUNET_MessageHeader *msg = buf; 599 struct MeshPingMessage *msg = buf;
554 uint32_t *data;
555 600
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n"); 601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
557 if (size < size_payload || NULL == buf) 602 if (size < sizeof (struct MeshPingMessage) || NULL == buf)
558 { 603 {
559 GNUNET_break (0); 604 GNUNET_break (0);
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -563,23 +608,15 @@ tmt_rdy (void *cls, size_t size, void *buf)
563 608
564 return 0; 609 return 0;
565 } 610 }
566 msg->size = htons (size); 611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending: msg %d\n", peer->data_sent);
567 if (NULL == peer) 612 msg->header.size = htons (size);
568 { 613 msg->header.type = htons (PING);
569 msg->type = htons (PONG); 614 msg->counter = htonl (peer->data_sent++);
570 return sizeof (*msg); 615 msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
571 }
572
573 msg->type = htons (PING);
574 data = (uint32_t *) &msg[1];
575 *data = htonl (peer->data_sent);
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: msg %d\n", peer->data_sent);
577 peer->data_sent++;
578 peer->timestamp = GNUNET_TIME_absolute_get ();
579 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD), 616 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
580 &ping, peer); 617 &ping, peer);
581 618
582 return size_payload; 619 return sizeof (struct MeshPingMessage);
583} 620}
584 621
585 622
@@ -603,7 +640,7 @@ ping_handler (void *cls, struct GNUNET_MESH_Channel *channel,
603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got PING\n", n); 640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got PING\n", n);
604 GNUNET_MESH_receive_done (channel); 641 GNUNET_MESH_receive_done (channel);
605 if (GNUNET_NO == test_finished) 642 if (GNUNET_NO == test_finished)
606 pong (channel); 643 pong (channel, (struct MeshPingMessage *) message);
607 644
608 return GNUNET_OK; 645 return GNUNET_OK;
609} 646}
@@ -626,27 +663,20 @@ pong_handler (void *cls, struct GNUNET_MESH_Channel *channel,
626{ 663{
627 long n = (long) cls; 664 long n = (long) cls;
628 struct MeshPeer *peer; 665 struct MeshPeer *peer;
666 struct MeshPingMessage *msg;
667 struct GNUNET_TIME_Absolute send_time;
629 struct GNUNET_TIME_Relative latency; 668 struct GNUNET_TIME_Relative latency;
630 669
631 GNUNET_MESH_receive_done (channel); 670 GNUNET_MESH_receive_done (channel);
632 peer = &peers[n]; 671 peer = &peers[n];
633 672
634 GNUNET_break (0 != peer->timestamp.abs_value_us); 673 msg = (struct MeshPingMessage *) message;
635 latency = GNUNET_TIME_absolute_get_duration (peer->timestamp);
636 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u latency: %s\n",
637 get_index (peer), get_index (peer->dest),
638 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
639 674
640 if (GNUNET_SCHEDULER_NO_TASK == peer->ping_task) 675 send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
641 { 676 latency = GNUNET_TIME_absolute_get_duration (send_time);
642 peer->timestamp = GNUNET_TIME_absolute_get (); 677 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
643 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (60 * 1000), 678 get_index (peer), get_index (peer->dest), ntohl (msg->counter),
644 &ping, peer); 679 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
645 }
646 else
647 {
648 peer->timestamp.abs_value_us = 0;
649 }
650 680
651 return GNUNET_OK; 681 return GNUNET_OK;
652} 682}
@@ -656,8 +686,8 @@ pong_handler (void *cls, struct GNUNET_MESH_Channel *channel,
656 * Handlers, for diverse services 686 * Handlers, for diverse services
657 */ 687 */
658static struct GNUNET_MESH_MessageHandler handlers[] = { 688static struct GNUNET_MESH_MessageHandler handlers[] = {
659 {&ping_handler, PING, sizeof (struct GNUNET_MessageHeader)}, 689 {&ping_handler, PING, sizeof (struct MeshPingMessage)},
660 {&pong_handler, PONG, sizeof (struct GNUNET_MessageHeader)}, 690 {&pong_handler, PONG, sizeof (struct MeshPingMessage)},
661 {NULL, 0, 0} 691 {NULL, 0, 0}
662}; 692};
663 693