diff options
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 230 |
1 files changed, 54 insertions, 176 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index e1ce4da18..24ad4b81e 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -46,38 +46,13 @@ | |||
46 | #define TOTAL_MSGS (1024 * 3 * FACTOR) | 46 | #define TOTAL_MSGS (1024 * 3 * FACTOR) |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Message type of test messages | ||
50 | */ | ||
51 | #define MTYPE 12345 | ||
52 | |||
53 | /** | ||
54 | * Testcase timeout | 49 | * Testcase timeout |
55 | */ | 50 | */ |
56 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90 * FACTOR) | 51 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR) |
57 | |||
58 | /** | ||
59 | * How long until we give up on transmitting the message? | ||
60 | */ | ||
61 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60 * FACTOR) | ||
62 | |||
63 | |||
64 | GNUNET_NETWORK_STRUCT_BEGIN | ||
65 | |||
66 | /** | ||
67 | * Struct for the test message | ||
68 | */ | ||
69 | struct TestMessage | ||
70 | { | ||
71 | struct GNUNET_MessageHeader header; | ||
72 | uint32_t num GNUNET_PACKED; | ||
73 | }; | ||
74 | GNUNET_NETWORK_STRUCT_END | ||
75 | 52 | ||
76 | 53 | ||
77 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 54 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
78 | 55 | ||
79 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
80 | |||
81 | /** | 56 | /** |
82 | * Total amount of bytes sent | 57 | * Total amount of bytes sent |
83 | */ | 58 | */ |
@@ -89,19 +64,9 @@ static unsigned long long total_bytes; | |||
89 | static struct GNUNET_TIME_Absolute start_time; | 64 | static struct GNUNET_TIME_Absolute start_time; |
90 | 65 | ||
91 | /** | 66 | /** |
92 | * No. of message currently scheduled to be send | ||
93 | */ | ||
94 | static int msg_scheduled; | ||
95 | |||
96 | /** | ||
97 | * No. of last message sent | ||
98 | */ | ||
99 | static int msg_sent; | ||
100 | |||
101 | /** | ||
102 | * No. of last message received | 67 | * No. of last message received |
103 | */ | 68 | */ |
104 | static int msg_recv; | 69 | static unsigned int msg_recv; |
105 | 70 | ||
106 | /** | 71 | /** |
107 | * Bitmap storing which messages were received | 72 | * Bitmap storing which messages were received |
@@ -109,20 +74,41 @@ static int msg_recv; | |||
109 | static char bitmap[TOTAL_MSGS / 8]; | 74 | static char bitmap[TOTAL_MSGS / 8]; |
110 | 75 | ||
111 | 76 | ||
112 | static unsigned int | 77 | /** |
78 | * Get the desired message size for message number @a iter. | ||
79 | */ | ||
80 | static size_t | ||
113 | get_size (unsigned int iter) | 81 | get_size (unsigned int iter) |
114 | { | 82 | { |
115 | unsigned int ret; | 83 | size_t ret; |
116 | 84 | ||
117 | ret = (iter * iter * iter); | 85 | ret = (iter * iter * iter); |
118 | |||
119 | #ifndef LINUX | 86 | #ifndef LINUX |
120 | /* FreeBSD/OSX etc. Unix DGRAMs do not work | 87 | /* FreeBSD/OSX etc. Unix DGRAMs do not work |
121 | * with large messages */ | 88 | * with large messages */ |
122 | if (0 == strcmp ("unix", test_plugin)) | 89 | if (0 == strcmp ("unix", test_plugin)) |
123 | return sizeof (struct TestMessage) + (ret % 1024); | 90 | ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024); |
124 | #endif | 91 | #endif |
125 | return sizeof (struct TestMessage) + (ret % 60000); | 92 | ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000); |
93 | return ret; | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Implementation of the callback for obtaining the | ||
99 | * size of messages for transmission. Counts the total | ||
100 | * number of bytes sent as a side-effect. | ||
101 | * | ||
102 | * @param cnt_down count down from `TOTAL_MSGS - 1` | ||
103 | * @return message size of the message | ||
104 | */ | ||
105 | static size_t | ||
106 | get_size_cnt (unsigned int cnt_down) | ||
107 | { | ||
108 | size_t ret = get_size (TOTAL_MSGS - 1 - cnt_down); | ||
109 | |||
110 | total_bytes += ret; | ||
111 | return ret; | ||
126 | } | 112 | } |
127 | 113 | ||
128 | 114 | ||
@@ -181,14 +167,8 @@ custom_shutdown (void *cls) | |||
181 | { | 167 | { |
182 | unsigned long long delta; | 168 | unsigned long long delta; |
183 | unsigned long long rate; | 169 | unsigned long long rate; |
184 | unsigned int i; | ||
185 | int ok; | 170 | int ok; |
186 | 171 | ||
187 | if (NULL != th) | ||
188 | { | ||
189 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
190 | th = NULL; | ||
191 | } | ||
192 | /* Calculcate statistics */ | 172 | /* Calculcate statistics */ |
193 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | 173 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
194 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); | 174 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); |
@@ -197,6 +177,7 @@ custom_shutdown (void *cls) | |||
197 | rate); | 177 | rate); |
198 | { | 178 | { |
199 | char *value_name; | 179 | char *value_name; |
180 | |||
200 | GNUNET_asprintf (&value_name, | 181 | GNUNET_asprintf (&value_name, |
201 | "unreliable_%s", | 182 | "unreliable_%s", |
202 | ccc->test_plugin); | 183 | ccc->test_plugin); |
@@ -208,7 +189,7 @@ custom_shutdown (void *cls) | |||
208 | } | 189 | } |
209 | 190 | ||
210 | ok = 0; | 191 | ok = 0; |
211 | for (i = 0; i < TOTAL_MSGS; i++) | 192 | for (unsigned int i = 0; i < TOTAL_MSGS; i++) |
212 | { | 193 | { |
213 | if (get_bit (bitmap, i) == 0) | 194 | if (get_bit (bitmap, i) == 0) |
214 | { | 195 | { |
@@ -230,14 +211,13 @@ notify_receive (void *cls, | |||
230 | const struct GNUNET_MessageHeader *message) | 211 | const struct GNUNET_MessageHeader *message) |
231 | { | 212 | { |
232 | static int n; | 213 | static int n; |
233 | |||
234 | unsigned int s; | 214 | unsigned int s; |
235 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 215 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
236 | const struct TestMessage *hdr; | 216 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr; |
237 | 217 | ||
238 | hdr = (const struct TestMessage *) message; | 218 | hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message; |
239 | 219 | ||
240 | if (MTYPE != ntohs (message->type)) | 220 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type)) |
241 | return; | 221 | return; |
242 | msg_recv = ntohl (hdr->num); | 222 | msg_recv = ntohl (hdr->num); |
243 | s = get_size (ntohl (hdr->num)); | 223 | s = get_size (ntohl (hdr->num)); |
@@ -255,19 +235,24 @@ notify_receive (void *cls, | |||
255 | return; | 235 | return; |
256 | } | 236 | } |
257 | 237 | ||
258 | memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage)); | 238 | memset (cbuf, |
259 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) | 239 | ntohl (hdr->num), |
240 | s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)); | ||
241 | if (0 != | ||
242 | memcmp (cbuf, | ||
243 | &hdr[1], | ||
244 | s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage))) | ||
260 | { | 245 | { |
261 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 246 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
262 | "Expected message %u with bits %u, but body did not match\n", | 247 | "Expected message %u with bits %u, but body did not match\n", |
263 | ntohl (hdr->num), | 248 | ntohl (hdr->num), |
264 | (unsigned char) n); | 249 | (unsigned char) ntohl (hdr->num)); |
265 | ccc->global_ret = GNUNET_SYSERR; | 250 | ccc->global_ret = GNUNET_SYSERR; |
266 | GNUNET_SCHEDULER_shutdown (); | 251 | GNUNET_SCHEDULER_shutdown (); |
267 | return; | 252 | return; |
268 | } | 253 | } |
269 | #if VERBOSE | 254 | #if VERBOSE |
270 | if (ntohl (hdr->num) % 5 == 0) | 255 | if (0 == ntohl (hdr->num) % 5) |
271 | { | 256 | { |
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Got message %u of size %u\n", | 258 | "Got message %u of size %u\n", |
@@ -290,141 +275,34 @@ notify_receive (void *cls, | |||
290 | if (n == TOTAL_MSGS) | 275 | if (n == TOTAL_MSGS) |
291 | { | 276 | { |
292 | /* end testcase with success */ | 277 | /* end testcase with success */ |
278 | ccc->global_ret = GNUNET_OK; | ||
293 | GNUNET_SCHEDULER_shutdown (); | 279 | GNUNET_SCHEDULER_shutdown (); |
294 | } | 280 | } |
295 | } | 281 | } |
296 | 282 | ||
297 | 283 | ||
298 | static size_t | ||
299 | notify_ready (void *cls, | ||
300 | size_t size, | ||
301 | void *buf) | ||
302 | { | ||
303 | static int n; | ||
304 | char *cbuf = buf; | ||
305 | struct TestMessage hdr; | ||
306 | unsigned int s; | ||
307 | unsigned int ret; | ||
308 | |||
309 | th = NULL; | ||
310 | if (NULL == buf) | ||
311 | { | ||
312 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
313 | "Timeout occurred while waiting for transmit_ready for msg %u of %u\n", | ||
314 | msg_scheduled, | ||
315 | TOTAL_MSGS); | ||
316 | GNUNET_SCHEDULER_shutdown (); | ||
317 | ccc->global_ret = 42; | ||
318 | return 0; | ||
319 | } | ||
320 | ret = 0; | ||
321 | s = get_size (n); | ||
322 | GNUNET_assert (size >= s); | ||
323 | GNUNET_assert (buf != NULL); | ||
324 | GNUNET_assert (n < TOTAL_MSGS); | ||
325 | cbuf = buf; | ||
326 | do | ||
327 | { | ||
328 | GNUNET_assert (n < TOTAL_MSGS); | ||
329 | hdr.header.size = htons (s); | ||
330 | hdr.header.type = htons (MTYPE); | ||
331 | hdr.num = htonl (n); | ||
332 | msg_sent = n; | ||
333 | GNUNET_memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | ||
334 | ret += sizeof (struct TestMessage); | ||
335 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | ||
336 | ret += s - sizeof (struct TestMessage); | ||
337 | |||
338 | #if VERBOSE | ||
339 | if (0 == n % 5000) | ||
340 | { | ||
341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
342 | "Sending message %u of size %u\n", | ||
343 | n, | ||
344 | s); | ||
345 | } | ||
346 | #endif | ||
347 | n++; | ||
348 | s = get_size (n); | ||
349 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | ||
350 | break; /* sometimes pack buffer full, sometimes not */ | ||
351 | } | ||
352 | while ((size - ret >= s) && (n < TOTAL_MSGS)); | ||
353 | if (n < TOTAL_MSGS) | ||
354 | { | ||
355 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
356 | &ccc->p[0]->id, | ||
357 | s, | ||
358 | TIMEOUT_TRANSMIT, | ||
359 | ¬ify_ready, | ||
360 | NULL); | ||
361 | msg_scheduled = n; | ||
362 | } | ||
363 | else | ||
364 | { | ||
365 | FPRINTF (stderr, | ||
366 | "%s", | ||
367 | "\n"); | ||
368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
369 | "All messages scheduled to be sent\n"); | ||
370 | } | ||
371 | if (0 == n % 5000) | ||
372 | { | ||
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
374 | "Returning total message block of size %u\n", | ||
375 | ret); | ||
376 | } | ||
377 | total_bytes += ret; | ||
378 | return ret; | ||
379 | } | ||
380 | |||
381 | |||
382 | static void | ||
383 | sendtask (void *cls) | ||
384 | { | ||
385 | start_time = GNUNET_TIME_absolute_get (); | ||
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
387 | "Starting to send %u messages\n", | ||
388 | TOTAL_MSGS); | ||
389 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
390 | &ccc->p[0]->id, | ||
391 | get_size (0), | ||
392 | TIMEOUT_TRANSMIT, | ||
393 | ¬ify_ready, | ||
394 | NULL); | ||
395 | } | ||
396 | |||
397 | |||
398 | static void | ||
399 | notify_disconnect (void *cls, | ||
400 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
401 | const struct GNUNET_PeerIdentity *other) | ||
402 | { | ||
403 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, | ||
404 | me, | ||
405 | other); | ||
406 | if (NULL != th) | ||
407 | { | ||
408 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
409 | th = NULL; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | |||
414 | int | 284 | int |
415 | main (int argc, char *argv[]) | 285 | main (int argc, char *argv[]) |
416 | { | 286 | { |
287 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | ||
288 | .num_messages = TOTAL_MSGS, | ||
289 | .get_size_cb = &get_size_cnt | ||
290 | }; | ||
417 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 291 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
418 | .connect_continuation = &sendtask, | 292 | .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send, |
293 | .connect_continuation_cls = &sc, | ||
419 | .config_file = "test_transport_api_data.conf", | 294 | .config_file = "test_transport_api_data.conf", |
420 | .rec = ¬ify_receive, | 295 | .rec = ¬ify_receive, |
421 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 296 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
422 | .nd = ¬ify_disconnect, | 297 | .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect, |
423 | .shutdown_task = &custom_shutdown, | 298 | .shutdown_task = &custom_shutdown, |
424 | .timeout = TIMEOUT | 299 | .timeout = TIMEOUT, |
300 | .global_ret = GNUNET_SYSERR | ||
425 | }; | 301 | }; |
426 | 302 | ||
427 | ccc = &my_ccc; | 303 | ccc = &my_ccc; |
304 | sc.ccc = ccc; | ||
305 | start_time = GNUNET_TIME_absolute_get (); | ||
428 | if (GNUNET_OK != | 306 | if (GNUNET_OK != |
429 | GNUNET_TRANSPORT_TESTING_main (2, | 307 | GNUNET_TRANSPORT_TESTING_main (2, |
430 | &GNUNET_TRANSPORT_TESTING_connect_check, | 308 | &GNUNET_TRANSPORT_TESTING_connect_check, |