aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_address_switch.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2015-01-08 14:12:56 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2015-01-08 14:12:56 +0000
commitef10ce23530f6cc3339c74fdb9ddb5298b50e8ca (patch)
treef1c5d41ab4e46aeba625240ca874ec3eed3f8156 /src/transport/test_transport_address_switch.c
parent64a9e7ce193ae9fd9fc64c65298adf3e711440c2 (diff)
downloadgnunet-ef10ce23530f6cc3339c74fdb9ddb5298b50e8ca.tar.gz
gnunet-ef10ce23530f6cc3339c74fdb9ddb5298b50e8ca.zip
fixed and improved test for address switching
Diffstat (limited to 'src/transport/test_transport_address_switch.c')
-rw-r--r--src/transport/test_transport_address_switch.c200
1 files changed, 88 insertions, 112 deletions
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c
index 10815c7ab..b5e42352e 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -22,7 +22,7 @@
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
23 * 23 *
24 * This test case tests if peers can successfully switch address when connected 24 * This test case tests if peers can successfully switch address when connected
25 * connected 25 * connected by monitoring statistic values
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_transport_service.h" 28#include "gnunet_transport_service.h"
@@ -43,16 +43,14 @@ struct TestMessage
43GNUNET_NETWORK_STRUCT_END 43GNUNET_NETWORK_STRUCT_END
44 44
45/** 45/**
46 * Note that this value must not significantly exceed 46 * Message type for test messages
47 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
48 * messages may be dropped even for a reliable transport.
49 */ 47 */
50#define TOTAL_MSGS (4096 * 2) 48#define MTYPE 12345
51 49
52/** 50/**
53 * Message type for test messages 51 * Message size for test messages
54 */ 52 */
55#define MTYPE 12345 53#define MSIZE 2048
56 54
57/** 55/**
58 * Testcase timeout 56 * Testcase timeout
@@ -67,11 +65,19 @@ GNUNET_NETWORK_STRUCT_END
67#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 65#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
68#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 66#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
69 67
70static struct GNUNET_SCHEDULER_Task * die_task; 68/**
69 * Timeout task to send messages
70 */
71static struct GNUNET_SCHEDULER_Task *die_task;
72
71 73
72static struct GNUNET_SCHEDULER_Task * delayed_end_task; 74static struct GNUNET_SCHEDULER_Task *delayed_end_task;
75
76/**
77 * Measurement task to send messages
78 */
79static struct GNUNET_SCHEDULER_Task *measure_task;
73 80
74static struct GNUNET_SCHEDULER_Task * measure_task;
75 81
76struct PeerContext *p1; 82struct PeerContext *p1;
77char *cfg_file_p1; 83char *cfg_file_p1;
@@ -87,32 +93,40 @@ struct PeerContext *receiver;
87 93
88struct GNUNET_TRANSPORT_TransmitHandle *th; 94struct GNUNET_TRANSPORT_TransmitHandle *th;
89 95
90static int test_connected;
91static int res;
92
93struct GNUNET_TRANSPORT_TESTING_handle *tth; 96struct GNUNET_TRANSPORT_TESTING_handle *tth;
94 97
95static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; 98static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
96 99
100static int test_connected;
101
102static int res;
103
104
105/**
106 * Statistics about peer 1
107 */
108static unsigned int p1_addresses_avail;
97static unsigned int p1_switch_attempts; 109static unsigned int p1_switch_attempts;
98static unsigned int p1_switch_success; 110static unsigned int p1_switch_success;
99static unsigned int p1_switch_fail; 111static unsigned int p1_switch_fail;
100static unsigned int p1_addresses_avail;
101 112
113
114/**
115 * Statistics about peer 2
116 */
102static unsigned int p2_switch_attempts; 117static unsigned int p2_switch_attempts;
103static unsigned int p2_switch_success; 118static unsigned int p2_switch_success;
104static unsigned int p2_switch_fail; 119static unsigned int p2_switch_fail;
105static unsigned int p2_addresses_avail; 120static unsigned int p2_addresses_avail;
106 121
107static unsigned long long bytes_sent_total; 122/**
108static unsigned long long bytes_recv_total; 123 * Transmission statistics
124 */
109 125
126/* Amount of data transfered since last switch attempt */
110static unsigned long long bytes_sent_after_switch; 127static unsigned long long bytes_sent_after_switch;
111static unsigned long long bytes_recv_after_switch; 128static unsigned long long bytes_recv_after_switch;
112 129
113static struct GNUNET_TIME_Absolute start_time;
114static struct GNUNET_TIME_Absolute start_time;
115
116/* 130/*
117 * END Testcase specific declarations 131 * END Testcase specific declarations
118 */ 132 */
@@ -132,18 +146,17 @@ stat_start_attempt_cb (void *cls, const char *subsystem, const char *name,
132 if (cls == p1) 146 if (cls == p1)
133 { 147 {
134 p1_switch_attempts++; 148 p1_switch_attempts++;
135 FPRINTF (stderr, "Peer 1 tries to switch."); 149 FPRINTF (stderr, "(1:s)");
136 } 150 }
137 else if (cls == p2) 151 else if (cls == p2)
138 { 152 {
139 p2_switch_attempts++; 153 p2_switch_attempts++;
140 FPRINTF (stderr, "Peer 2 tries to switch."); 154 FPRINTF (stderr, "(2:s)");
141 } 155 }
142 else
143 return GNUNET_OK;
144 156
145 if (NULL == delayed_end_task) 157 bytes_recv_after_switch = 0;
146 delayed_end_task = GNUNET_SCHEDULER_add_delayed (DELAY, &end, NULL ); 158 bytes_sent_after_switch = 0;
159
147 return GNUNET_OK; 160 return GNUNET_OK;
148} 161}
149 162
@@ -155,12 +168,12 @@ stat_success_attempt_cb (void *cls, const char *subsystem, const char *name,
155 if (cls == p1) 168 if (cls == p1)
156 { 169 {
157 p1_switch_success++; 170 p1_switch_success++;
158 FPRINTF (stderr, "Peer 1 switched successfully."); 171 FPRINTF (stderr, "(1:+)");
159 } 172 }
160 if (cls == p2) 173 if (cls == p2)
161 { 174 {
162 p2_switch_success++; 175 p2_switch_success++;
163 FPRINTF (stderr, "Peer 2 switched successfully."); 176 FPRINTF (stderr, "(2:+)");
164 } 177 }
165 178
166 return GNUNET_OK; 179 return GNUNET_OK;
@@ -177,12 +190,12 @@ stat_fail_attempt_cb (void *cls, const char *subsystem, const char *name,
177 if (cls == p1) 190 if (cls == p1)
178 { 191 {
179 p1_switch_fail++; 192 p1_switch_fail++;
180 FPRINTF (stderr, "Peer 1 failed to switch."); 193 FPRINTF (stderr, "(1:-)");
181 } 194 }
182 if (cls == p2) 195 if (cls == p2)
183 { 196 {
184 p2_switch_fail++; 197 p2_switch_fail++;
185 FPRINTF (stderr, "Peer 2 failed to switch."); 198 FPRINTF (stderr, "(2:-)");
186 } 199 }
187 200
188 return GNUNET_OK; 201 return GNUNET_OK;
@@ -270,24 +283,16 @@ clean_up ()
270 p2_stat = NULL; 283 p2_stat = NULL;
271 } 284 }
272 285
273 if (die_task != NULL )
274 {
275 GNUNET_SCHEDULER_cancel (die_task);
276 die_task = NULL;
277 }
278
279 if (th != NULL ) 286 if (th != NULL )
280 { 287 {
281 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 288 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
282 th = NULL; 289 th = NULL;
283 } 290 }
284
285 if (cc != NULL ) 291 if (cc != NULL )
286 { 292 {
287 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); 293 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
288 cc = NULL; 294 cc = NULL;
289 } 295 }
290
291 if (p1 != NULL ) 296 if (p1 != NULL )
292 { 297 {
293 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 298 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
@@ -320,7 +325,7 @@ end ()
320 result ++; 325 result ++;
321 } 326 }
322 } 327 }
323 else 328 else if (p1_addresses_avail > 1)
324 { 329 {
325 FPRINTF (stderr, "Peer 1 had %u addresses available, but did not try to switch\n", 330 FPRINTF (stderr, "Peer 1 had %u addresses available, but did not try to switch\n",
326 p1_addresses_avail); 331 p1_addresses_avail);
@@ -335,7 +340,7 @@ end ()
335 result ++; 340 result ++;
336 } 341 }
337 } 342 }
338 else 343 else if (p2_addresses_avail > 1)
339 { 344 {
340 FPRINTF (stderr, "Peer 2 had %u addresses available, but did not try to switch\n", 345 FPRINTF (stderr, "Peer 2 had %u addresses available, but did not try to switch\n",
341 p2_addresses_avail); 346 p2_addresses_avail);
@@ -368,11 +373,6 @@ end_badly ()
368 die_task = NULL; 373 die_task = NULL;
369 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 374 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
370 375
371 FPRINTF (stderr, "Peer 1 had %u addresses available, but did not try to switch\n",
372 p1_addresses_avail);
373 FPRINTF (stderr, "Peer 2 had %u addresses available, but did not try to switch\n",
374 p2_addresses_avail);
375
376 if (test_connected == GNUNET_YES) 376 if (test_connected == GNUNET_YES)
377 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n"); 377 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n");
378 else 378 else
@@ -384,15 +384,6 @@ end_badly ()
384} 384}
385 385
386 386
387static unsigned int
388get_size (unsigned int iter)
389{
390 unsigned int ret;
391 ret = (iter * iter * iter);
392 return sizeof(struct TestMessage) + (ret % 60000);
393}
394
395
396static void 387static void
397notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 388notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
398 const struct GNUNET_MessageHeader *message) 389 const struct GNUNET_MessageHeader *message)
@@ -410,9 +401,19 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
410 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps, 401 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps,
411 ntohl (hdr->num), ntohs (message->size), GNUNET_i2s (peer)); 402 ntohl (hdr->num), ntohs (message->size), GNUNET_i2s (peer));
412 403
413 bytes_recv_total += ntohs(hdr->header.size); 404 if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) &&
414 if ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) 405 (p1_switch_attempts == p1_switch_fail + p1_switch_success) &&
415 bytes_recv_after_switch += ntohs(hdr->header.size); 406 (p2_switch_attempts == p2_switch_fail + p2_switch_success) )
407 {
408 bytes_recv_after_switch += ntohs(hdr->header.size);
409 if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0))
410 {
411 /* A peer switched addresses and sent and received data after the
412 * switch operations */
413 end ();
414 }
415 }
416
416 417
417 GNUNET_free(ps); 418 GNUNET_free(ps);
418} 419}
@@ -421,10 +422,8 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
421static size_t 422static size_t
422notify_ready (void *cls, size_t size, void *buf) 423notify_ready (void *cls, size_t size, void *buf)
423{ 424{
424 static int n;
425 char *cbuf = buf; 425 char *cbuf = buf;
426 struct TestMessage hdr; 426 struct TestMessage hdr;
427 unsigned int s;
428 unsigned int ret; 427 unsigned int ret;
429 428
430 th = NULL; 429 th = NULL;
@@ -439,61 +438,37 @@ notify_ready (void *cls, size_t size, void *buf)
439 return 0; 438 return 0;
440 } 439 }
441 440
442 ret = 0; 441 GNUNET_assert(size >= MSIZE);
443 s = get_size (n);
444 GNUNET_assert(size >= s);
445 GNUNET_assert(buf != NULL); 442 GNUNET_assert(buf != NULL);
446 cbuf = buf; 443 cbuf = buf;
447 do
448 {
449 hdr.header.size = htons (s);
450 hdr.header.type = htons (MTYPE);
451 hdr.num = htonl (n);
452 memcpy (&cbuf[ret], &hdr, sizeof(struct TestMessage));
453 ret += sizeof(struct TestMessage);
454 memset (&cbuf[ret], n, s - sizeof(struct TestMessage));
455 ret += s - sizeof(struct TestMessage);
456#if VERBOSE
457 if (n % 5000 == 0)
458 {
459#endif
460 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
461 444
462 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 445 hdr.header.size = htons (MSIZE);
463 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", 446 hdr.header.type = htons (MTYPE);
464 n, s, sender->no, GNUNET_i2s (&sender->id), receiver->no, receiver_s); 447 hdr.num = htonl (0);
465 GNUNET_free(receiver_s); 448 memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage));
466#if 0 449 ret += sizeof(struct TestMessage);
467 } 450 memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage));
468#endif 451 ret = MSIZE;
469 n++;
470 s = get_size (n);
471 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
472 break; /* sometimes pack buffer full, sometimes not */
473 }
474 while (size - ret >= s);
475 if (n < TOTAL_MSGS)
476 {
477 if (th == NULL )
478 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s,
479 TIMEOUT_TRANSMIT, &notify_ready, NULL );
480 }
481 if (n % 5000 == 0)
482 {
483 452
484 } 453#if VERBOSE
485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 454 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
486 "Returning total message block of size %u\n", ret); 455 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
456 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
457 n, s, sender->no, GNUNET_i2s (&sender->id), receiver->no, receiver_s);
458 GNUNET_free(receiver_s);
459#endif
487 460
488 bytes_sent_total += ret; 461 if (th == NULL )
489 if ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) 462 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, MSIZE,
490 bytes_sent_after_switch += ret; 463 TIMEOUT_TRANSMIT, &notify_ready, NULL );
491 464
492 if (n == TOTAL_MSGS) 465 if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) &&
466 (p1_switch_attempts == p1_switch_fail + p1_switch_success) &&
467 (p2_switch_attempts == p2_switch_fail + p2_switch_success) )
493 { 468 {
494 FPRINTF (stderr, "%s", "\n"); 469 bytes_sent_after_switch += ret;
495 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n");
496 } 470 }
471
497 return ret; 472 return ret;
498} 473}
499 474
@@ -523,19 +498,16 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
523static void 498static void
524sendtask () 499sendtask ()
525{ 500{
526 start_time = GNUNET_TIME_absolute_get (); 501 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, MSIZE,
527 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0),
528 TIMEOUT_TRANSMIT, &notify_ready, NULL ); 502 TIMEOUT_TRANSMIT, &notify_ready, NULL );
529} 503}
530 504
531 505
532static void 506static void
533measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 507progress_indicator (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
534{ 508{
535 static int counter; 509 static int counter;
536
537 measure_task = NULL; 510 measure_task = NULL;
538
539 counter++; 511 counter++;
540 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) 512 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
541 { 513 {
@@ -545,7 +517,7 @@ measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
545 { 517 {
546 FPRINTF (stderr, "%s", "."); 518 FPRINTF (stderr, "%s", ".");
547 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 519 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
548 &measure, NULL ); 520 &progress_indicator, NULL );
549 } 521 }
550} 522}
551 523
@@ -562,8 +534,10 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
562 cc = NULL; 534 cc = NULL;
563 test_connected = GNUNET_YES; 535 test_connected = GNUNET_YES;
564 536
537 FPRINTF (stderr, "(i:s/+/-) \t i == peer 1/2, s/+/- : switch attempt/switch ok/switch fail\n");
538
565 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 539 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
566 &measure, NULL ); 540 &progress_indicator, NULL );
567 GNUNET_SCHEDULER_add_now (&sendtask, NULL ); 541 GNUNET_SCHEDULER_add_now (&sendtask, NULL );
568} 542}
569 543
@@ -614,6 +588,7 @@ run (void *cls, char * const *args, const char *cfgfile,
614 return; 588 return;
615 } 589 }
616 590
591 /* Start to watch statistics for peer 1 */
617 p1_stat = GNUNET_STATISTICS_create ("transport", p1->cfg); 592 p1_stat = GNUNET_STATISTICS_create ("transport", p1->cfg);
618 GNUNET_STATISTICS_watch (p1_stat, "transport", 593 GNUNET_STATISTICS_watch (p1_stat, "transport",
619 "# Attempts to switch addresses", 594 "# Attempts to switch addresses",
@@ -634,6 +609,7 @@ run (void *cls, char * const *args, const char *cfgfile,
634 "# transport addresses", 609 "# transport addresses",
635 stat_addresses_available, p1); 610 stat_addresses_available, p1);
636 611
612 /* Start to watch statistics for peer 2 */
637 p2_stat = GNUNET_STATISTICS_create ("transport", p2->cfg); 613 p2_stat = GNUNET_STATISTICS_create ("transport", p2->cfg);
638 GNUNET_STATISTICS_watch (p2_stat, "transport", 614 GNUNET_STATISTICS_watch (p2_stat, "transport",
639 "# Attempts to switch addresses", 615 "# Attempts to switch addresses",