diff options
-rw-r--r-- | src/mesh/test_mesh_small.c | 171 |
1 files changed, 125 insertions, 46 deletions
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c index da32ee504..96f448461 100644 --- a/src/mesh/test_mesh_small.c +++ b/src/mesh/test_mesh_small.c | |||
@@ -43,6 +43,10 @@ struct MeshPeer | |||
43 | struct GNUNET_MESH_Handle *mesh_handle; | 43 | struct GNUNET_MESH_Handle *mesh_handle; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | /** | ||
47 | * How namy messages to send | ||
48 | */ | ||
49 | #define TOTAL_PACKETS 1000 | ||
46 | 50 | ||
47 | /** | 51 | /** |
48 | * How long until we give up on connecting the peers? | 52 | * How long until we give up on connecting the peers? |
@@ -80,6 +84,18 @@ static int test_backwards = GNUNET_NO; | |||
80 | */ | 84 | */ |
81 | static int ok; | 85 | static int ok; |
82 | 86 | ||
87 | /** | ||
88 | * Each peer is supposed to generate the following callbacks: | ||
89 | * 1 incoming tunnel (@dest) | ||
90 | * 1 connected peer (@orig) | ||
91 | * 1 received data packet (@dest) | ||
92 | * 1 received data packet (@orig) | ||
93 | * 1 received tunnel destroy (@dest) | ||
94 | * _________________________________ | ||
95 | * 5 x ok expected per peer | ||
96 | */ | ||
97 | int ok_goal; | ||
98 | |||
83 | /** | 99 | /** |
84 | * Peers that have been connected | 100 | * Peers that have been connected |
85 | */ | 101 | */ |
@@ -101,7 +117,7 @@ static int data_sent; | |||
101 | static int data_received; | 117 | static int data_received; |
102 | 118 | ||
103 | /** | 119 | /** |
104 | * Number of payload packed explicitly (app/level) acknowledged | 120 | * Number of payload packed explicitly (app level) acknowledged |
105 | */ | 121 | */ |
106 | static int data_ack; | 122 | static int data_ack; |
107 | 123 | ||
@@ -167,26 +183,53 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | |||
167 | 183 | ||
168 | static char *topology_file; | 184 | static char *topology_file; |
169 | 185 | ||
186 | /** | ||
187 | * Testbed handle for the root peer | ||
188 | */ | ||
170 | static struct GNUNET_TESTING_Daemon *d1; | 189 | static struct GNUNET_TESTING_Daemon *d1; |
171 | 190 | ||
172 | static GNUNET_PEER_Id pid1; | 191 | /** |
173 | 192 | * Testbed handle for the first leaf peer | |
193 | */ | ||
174 | static struct GNUNET_TESTING_Daemon *d2; | 194 | static struct GNUNET_TESTING_Daemon *d2; |
175 | 195 | ||
196 | /** | ||
197 | * Testbed handle for the second leaf peer | ||
198 | */ | ||
176 | static struct GNUNET_TESTING_Daemon *d3; | 199 | static struct GNUNET_TESTING_Daemon *d3; |
177 | 200 | ||
201 | /** | ||
202 | * Mesh handle for the root peer | ||
203 | */ | ||
178 | static struct GNUNET_MESH_Handle *h1; | 204 | static struct GNUNET_MESH_Handle *h1; |
179 | 205 | ||
206 | /** | ||
207 | * Mesh handle for the first leaf peer | ||
208 | */ | ||
180 | static struct GNUNET_MESH_Handle *h2; | 209 | static struct GNUNET_MESH_Handle *h2; |
181 | 210 | ||
211 | /** | ||
212 | * Mesh handle for the second leaf peer | ||
213 | */ | ||
182 | static struct GNUNET_MESH_Handle *h3; | 214 | static struct GNUNET_MESH_Handle *h3; |
183 | 215 | ||
216 | /** | ||
217 | * Tunnel handle for the root peer | ||
218 | */ | ||
184 | static struct GNUNET_MESH_Tunnel *t; | 219 | static struct GNUNET_MESH_Tunnel *t; |
185 | 220 | ||
221 | /** | ||
222 | * Tunnel handle for the first leaf peer | ||
223 | */ | ||
186 | static struct GNUNET_MESH_Tunnel *incoming_t; | 224 | static struct GNUNET_MESH_Tunnel *incoming_t; |
187 | 225 | ||
226 | /** | ||
227 | * Tunnel handle for the second leaf peer | ||
228 | */ | ||
188 | static struct GNUNET_MESH_Tunnel *incoming_t2; | 229 | static struct GNUNET_MESH_Tunnel *incoming_t2; |
189 | 230 | ||
231 | static GNUNET_PEER_Id pid1; | ||
232 | |||
190 | static struct GNUNET_TIME_Absolute start_time; | 233 | static struct GNUNET_TIME_Absolute start_time; |
191 | 234 | ||
192 | static struct GNUNET_TIME_Absolute end_time; | 235 | static struct GNUNET_TIME_Absolute end_time; |
@@ -304,12 +347,26 @@ static void | |||
304 | data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 347 | data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
305 | { | 348 | { |
306 | struct GNUNET_MESH_TransmitHandle *th; | 349 | struct GNUNET_MESH_TransmitHandle *th; |
350 | struct GNUNET_MESH_Tunnel *tunnel; | ||
351 | struct GNUNET_PeerIdentity *destination; | ||
352 | |||
307 | if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) | 353 | if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) |
308 | return; | 354 | return; |
309 | th = GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, | 355 | if (GNUNET_YES == test_backwards) |
310 | GNUNET_TIME_UNIT_FOREVER_REL, &d2->id, | 356 | { |
311 | sizeof (struct GNUNET_MessageHeader), | 357 | tunnel = incoming_t; |
312 | &tmt_rdy, (void *) 1L); | 358 | destination = &d1->id; |
359 | } | ||
360 | else | ||
361 | { | ||
362 | tunnel = t; | ||
363 | destination = &d2->id; | ||
364 | } | ||
365 | th = GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, | ||
366 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
367 | destination, | ||
368 | sizeof (struct GNUNET_MessageHeader), | ||
369 | &tmt_rdy, (void *) 1L); | ||
313 | if (NULL == th) | 370 | if (NULL == th) |
314 | { | 371 | { |
315 | unsigned long i = (unsigned long) cls; | 372 | unsigned long i = (unsigned long) cls; |
@@ -354,7 +411,7 @@ tmt_rdy (void *cls, size_t size, void *buf) | |||
354 | if (test == SPEED) | 411 | if (test == SPEED) |
355 | { | 412 | { |
356 | data_sent++; | 413 | data_sent++; |
357 | if (data_sent < 1000) | 414 | if (data_sent < TOTAL_PACKETS) |
358 | { | 415 | { |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
360 | " Scheduling %d packet\n", data_sent); | 417 | " Scheduling %d packet\n", data_sent); |
@@ -384,11 +441,27 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, | |||
384 | const struct GNUNET_ATS_Information *atsi) | 441 | const struct GNUNET_ATS_Information *atsi) |
385 | { | 442 | { |
386 | long client = (long) cls; | 443 | long client = (long) cls; |
444 | long expected_client; | ||
445 | struct GNUNET_MESH_Tunnel *tunnel_to_use; | ||
446 | struct GNUNET_PeerIdentity *dest_to_use; | ||
447 | |||
448 | if (GNUNET_YES == test_backwards) | ||
449 | { | ||
450 | expected_client = 1L; | ||
451 | dest_to_use = &d1->id; | ||
452 | tunnel_to_use = incoming_t; | ||
453 | } | ||
454 | else | ||
455 | { | ||
456 | expected_client = 0L; | ||
457 | dest_to_use = &d2->id; | ||
458 | tunnel_to_use = t; | ||
459 | } | ||
387 | 460 | ||
388 | switch (client) | 461 | switch (client) |
389 | { | 462 | { |
390 | case 1L: | 463 | case 1L: |
391 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Origin client got a response!\n"); | 464 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a response!\n"); |
392 | ok++; | 465 | ok++; |
393 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | 466 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); |
394 | peers_responded++; | 467 | peers_responded++; |
@@ -410,17 +483,18 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, | |||
410 | GNUNET_TIME_UNIT_FOREVER_REL, sender, | 483 | GNUNET_TIME_UNIT_FOREVER_REL, sender, |
411 | sizeof (struct GNUNET_MessageHeader), | 484 | sizeof (struct GNUNET_MessageHeader), |
412 | &tmt_rdy, (void *) 1L); | 485 | &tmt_rdy, (void *) 1L); |
413 | if (data_ack < 1000 && test != SPEED) | 486 | if (data_ack < TOTAL_PACKETS && test != SPEED) |
414 | return GNUNET_OK; | 487 | return GNUNET_OK; |
415 | end_time = GNUNET_TIME_absolute_get(); | 488 | end_time = GNUNET_TIME_absolute_get(); |
416 | total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); | 489 | total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); |
417 | FPRINTF (stderr, "\nTest time %llu ms\n", | 490 | FPRINTF (stderr, "\nTest time %llu ms\n", |
418 | (unsigned long long) total_time.rel_value); | 491 | (unsigned long long) total_time.rel_value); |
419 | FPRINTF (stderr, "Test bandwidth: %f kb/s\n", | 492 | FPRINTF (stderr, "Test bandwidth: %f kb/s\n", |
420 | 4 * 1000.0 / total_time.rel_value); // 4bytes * ms | 493 | 4 * TOTAL_PACKETS * 1.0 / total_time.rel_value); // 4bytes * ms |
421 | FPRINTF (stderr, "Test throughput: %f packets/s\n\n", | 494 | FPRINTF (stderr, "Test throughput: %f packets/s\n\n", |
422 | 1000.0 * 1000.0 / total_time.rel_value); // 1000 packets * ms | 495 | TOTAL_PACKETS * 1000.0 / total_time.rel_value); // packets * ms |
423 | GAUGER ("MESH", "Tunnel 5 peers", 1000.0 * 1000.0 / total_time.rel_value, | 496 | GAUGER ("MESH", "Tunnel 5 peers", |
497 | TOTAL_PACKETS * 1000.0 / total_time.rel_value, | ||
424 | "packets/s"); | 498 | "packets/s"); |
425 | } | 499 | } |
426 | GNUNET_assert (tunnel == t); | 500 | GNUNET_assert (tunnel == t); |
@@ -430,11 +504,11 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, | |||
430 | case 2L: | 504 | case 2L: |
431 | case 3L: | 505 | case 3L: |
432 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 506 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
433 | "Destination client %u got a message.\n", | 507 | "Leaf client %u got a message.\n", |
434 | client); | 508 | client); |
435 | ok++; | 509 | ok++; |
436 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | 510 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); |
437 | if (SPEED != test || 1002 == ok) | 511 | if (SPEED != test || (ok_goal - 2) == ok) |
438 | { | 512 | { |
439 | GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, | 513 | GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, |
440 | GNUNET_TIME_UNIT_FOREVER_REL, sender, | 514 | GNUNET_TIME_UNIT_FOREVER_REL, sender, |
@@ -446,7 +520,7 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, | |||
446 | data_received++; | 520 | data_received++; |
447 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 521 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
448 | " received data %u\n", data_received); | 522 | " received data %u\n", data_received); |
449 | if (data_received < 1000) | 523 | if (data_received < TOTAL_PACKETS) |
450 | return GNUNET_OK; | 524 | return GNUNET_OK; |
451 | } | 525 | } |
452 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 526 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) |
@@ -460,6 +534,10 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, | |||
460 | default: | 534 | default: |
461 | break; | 535 | break; |
462 | } | 536 | } |
537 | |||
538 | |||
539 | |||
540 | |||
463 | return GNUNET_OK; | 541 | return GNUNET_OK; |
464 | } | 542 | } |
465 | 543 | ||
@@ -586,6 +664,7 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
586 | const struct GNUNET_ATS_Information *atsi) | 664 | const struct GNUNET_ATS_Information *atsi) |
587 | { | 665 | { |
588 | struct GNUNET_PeerIdentity *dest; | 666 | struct GNUNET_PeerIdentity *dest; |
667 | struct GNUNET_MESH_Tunnel *tunnel; | ||
589 | 668 | ||
590 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 669 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
591 | "peer %s connected\n", GNUNET_i2s (peer)); | 670 | "peer %s connected\n", GNUNET_i2s (peer)); |
@@ -602,19 +681,30 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
602 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | 681 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); |
603 | switch (test) | 682 | switch (test) |
604 | { | 683 | { |
605 | case UNICAST: | 684 | case UNICAST: |
606 | case SPEED: | 685 | case SPEED: |
607 | case SPEED_ACK: | 686 | case SPEED_ACK: |
608 | dest = &d2->id; | 687 | if (GNUNET_YES == test_backwards) |
609 | break; | 688 | { |
610 | case MULTICAST: | 689 | dest = &d1->id; |
611 | peers_in_tunnel++; | 690 | tunnel = incoming_t; |
612 | if (peers_in_tunnel < 2) | 691 | } |
692 | else | ||
693 | { | ||
694 | dest = &d2->id; | ||
695 | tunnel = t; | ||
696 | } | ||
697 | break; | ||
698 | case MULTICAST: | ||
699 | peers_in_tunnel++; | ||
700 | if (peers_in_tunnel < 2) | ||
701 | return; | ||
702 | dest = NULL; | ||
703 | tunnel = t; | ||
704 | break; | ||
705 | default: | ||
706 | tunnel = t; | ||
613 | return; | 707 | return; |
614 | dest = NULL; | ||
615 | break; | ||
616 | default: | ||
617 | return; | ||
618 | } | 708 | } |
619 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 709 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) |
620 | { | 710 | { |
@@ -628,7 +718,7 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
628 | data_received = 0; | 718 | data_received = 0; |
629 | data_sent = 0; | 719 | data_sent = 0; |
630 | start_time = GNUNET_TIME_absolute_get(); | 720 | start_time = GNUNET_TIME_absolute_get(); |
631 | GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, | 721 | GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, |
632 | GNUNET_TIME_UNIT_FOREVER_REL, dest, | 722 | GNUNET_TIME_UNIT_FOREVER_REL, dest, |
633 | sizeof (struct GNUNET_MessageHeader), | 723 | sizeof (struct GNUNET_MessageHeader), |
634 | &tmt_rdy, (void *) 1L); | 724 | &tmt_rdy, (void *) 1L); |
@@ -968,17 +1058,6 @@ main (int argc, char *argv[]) | |||
968 | }; | 1058 | }; |
969 | int argc2 = (sizeof (argv2) / sizeof (char *)) - 1; | 1059 | int argc2 = (sizeof (argv2) / sizeof (char *)) - 1; |
970 | 1060 | ||
971 | /* Each peer is supposed to generate the following callbacks: | ||
972 | * 1 incoming tunnel (@dest) | ||
973 | * 1 connected peer (@orig) | ||
974 | * 1 received data packet (@dest) | ||
975 | * 1 received data packet (@orig) | ||
976 | * 1 received tunnel destroy (@dest) | ||
977 | * _________________________________ | ||
978 | * 5 x ok expected per peer | ||
979 | */ | ||
980 | int ok_goal; | ||
981 | |||
982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n"); | 1061 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n"); |
983 | if (strstr (argv[0], "test_mesh_small_unicast") != NULL) | 1062 | if (strstr (argv[0], "test_mesh_small_unicast") != NULL) |
984 | { | 1063 | { |
@@ -997,15 +1076,15 @@ main (int argc, char *argv[]) | |||
997 | /* Each peer is supposed to generate the following callbacks: | 1076 | /* Each peer is supposed to generate the following callbacks: |
998 | * 1 incoming tunnel (@dest) | 1077 | * 1 incoming tunnel (@dest) |
999 | * 1 connected peer (@orig) | 1078 | * 1 connected peer (@orig) |
1000 | * 1000 received data packet (@dest) | 1079 | * TOTAL_PACKETS received data packet (@dest) |
1001 | * 1000 received data packet (@orig) | 1080 | * TOTAL_PACKETS received data packet (@orig) |
1002 | * 1 received tunnel destroy (@dest) | 1081 | * 1 received tunnel destroy (@dest) |
1003 | * _________________________________ | 1082 | * _________________________________ |
1004 | * 5 x ok expected per peer | 1083 | * 5 x ok expected per peer |
1005 | */ | 1084 | */ |
1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); | 1085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); |
1007 | test = SPEED_ACK; | 1086 | test = SPEED_ACK; |
1008 | ok_goal = 2003; | 1087 | ok_goal = TOTAL_PACKETS * 2 + 3; |
1009 | argv2 [3] = NULL; // remove -L DEBUG | 1088 | argv2 [3] = NULL; // remove -L DEBUG |
1010 | #if VERBOSE | 1089 | #if VERBOSE |
1011 | argc2 -= 2; | 1090 | argc2 -= 2; |
@@ -1016,13 +1095,13 @@ main (int argc, char *argv[]) | |||
1016 | /* Each peer is supposed to generate the following callbacks: | 1095 | /* Each peer is supposed to generate the following callbacks: |
1017 | * 1 incoming tunnel (@dest) | 1096 | * 1 incoming tunnel (@dest) |
1018 | * 1 connected peer (@orig) | 1097 | * 1 connected peer (@orig) |
1019 | * 1000 received data packet (@dest) | 1098 | * TOTAL_PACKETS received data packet (@dest) |
1020 | * 1received data packet (@orig) | 1099 | * 1 received data packet (@orig) |
1021 | * 1 received tunnel destroy (@dest) | 1100 | * 1 received tunnel destroy (@dest) |
1022 | * _________________________________ | 1101 | * _________________________________ |
1023 | */ | 1102 | */ |
1024 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); | 1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); |
1025 | ok_goal = 1004; | 1104 | ok_goal = TOTAL_PACKETS + 4; |
1026 | if (strstr (argv[0], "_min") != NULL) | 1105 | if (strstr (argv[0], "_min") != NULL) |
1027 | test = SPEED_MIN; | 1106 | test = SPEED_MIN; |
1028 | else if (strstr (argv[0], "_nobuf") != NULL) | 1107 | else if (strstr (argv[0], "_nobuf") != NULL) |