diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-22 12:34:02 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-22 12:34:02 +0000 |
commit | d53e0ea2ab53023ab080c35f0eb074bef0c65024 (patch) | |
tree | 6575254ccdacf53d4059444eabe5978b150989e2 /src/transport | |
parent | 843c9594e270b312af68c8f9ba9e1fc9fa6cb490 (diff) | |
download | gnunet-d53e0ea2ab53023ab080c35f0eb074bef0c65024.tar.gz gnunet-d53e0ea2ab53023ab080c35f0eb074bef0c65024.zip |
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/test_quota_compliance.c | 168 |
1 files changed, 158 insertions, 10 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 4d312e5f2..c53f4d424 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -47,7 +47,7 @@ | |||
47 | */ | 47 | */ |
48 | #define TOTAL_MSGS (10000 * 2) | 48 | #define TOTAL_MSGS (10000 * 2) |
49 | 49 | ||
50 | #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) | 50 | #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
51 | #define MEASUREMENT_MSG_SIZE 1024 | 51 | #define MEASUREMENT_MSG_SIZE 1024 |
52 | #define MEASUREMENT_MSG_SIZE_BIG 32768 | 52 | #define MEASUREMENT_MSG_SIZE_BIG 32768 |
53 | 53 | ||
@@ -57,7 +57,7 @@ | |||
57 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200) | 57 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200) |
58 | 58 | ||
59 | 59 | ||
60 | #define MTYPE 12345 | 60 | #define MTYPE 11111 |
61 | 61 | ||
62 | struct PeerContext | 62 | struct PeerContext |
63 | { | 63 | { |
@@ -86,6 +86,7 @@ static unsigned long long current_quota_p2; | |||
86 | static struct GNUNET_TIME_Absolute start_time; | 86 | static struct GNUNET_TIME_Absolute start_time; |
87 | 87 | ||
88 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 88 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
89 | static GNUNET_SCHEDULER_TaskIdentifier measurement_task; | ||
89 | 90 | ||
90 | static int msg_scheduled; | 91 | static int msg_scheduled; |
91 | static int msg_sent; | 92 | static int msg_sent; |
@@ -153,7 +154,6 @@ end_badly (void *cls, | |||
153 | ok = 1; | 154 | ok = 1; |
154 | } | 155 | } |
155 | 156 | ||
156 | |||
157 | struct TestMessage | 157 | struct TestMessage |
158 | { | 158 | { |
159 | struct GNUNET_MessageHeader header; | 159 | struct GNUNET_MessageHeader header; |
@@ -175,8 +175,7 @@ get_size (unsigned int iter) | |||
175 | static unsigned int | 175 | static unsigned int |
176 | get_size_new (unsigned int iter) | 176 | get_size_new (unsigned int iter) |
177 | { | 177 | { |
178 | unsigned int ret = 1024; | 178 | return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage); |
179 | return ret; | ||
180 | } | 179 | } |
181 | 180 | ||
182 | static void | 181 | static void |
@@ -254,6 +253,86 @@ notify_receive (void *cls, | |||
254 | end (); | 253 | end (); |
255 | } | 254 | } |
256 | 255 | ||
256 | static void | ||
257 | notify_receive_new (void *cls, | ||
258 | const struct GNUNET_PeerIdentity *peer, | ||
259 | const struct GNUNET_MessageHeader *message, | ||
260 | struct GNUNET_TIME_Relative latency, | ||
261 | uint32_t distance) | ||
262 | { | ||
263 | static int n; | ||
264 | unsigned int s; | ||
265 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | ||
266 | const struct TestMessage *hdr; | ||
267 | |||
268 | hdr = (const struct TestMessage*) message; | ||
269 | s = get_size_new (n); | ||
270 | if (MTYPE != ntohs (message->type)) | ||
271 | return; | ||
272 | msg_recv_expected = n; | ||
273 | msg_recv = ntohl(hdr->num); | ||
274 | /* | ||
275 | if (ntohs (message->size) != s) | ||
276 | { | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
278 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
279 | n, s, | ||
280 | ntohs (message->size), | ||
281 | ntohl (hdr->num)); | ||
282 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
283 | die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
284 | return; | ||
285 | } | ||
286 | |||
287 | if (ntohl (hdr->num) != n) | ||
288 | { | ||
289 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
290 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
291 | n, s, | ||
292 | ntohs (message->size), | ||
293 | ntohl (hdr->num)); | ||
294 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
295 | die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
296 | return; | ||
297 | } | ||
298 | */ | ||
299 | /* | ||
300 | memset (cbuf, n, s - sizeof (struct TestMessage)); | ||
301 | if (0 != memcmp (cbuf, | ||
302 | &hdr[1], | ||
303 | s - sizeof (struct TestMessage))) | ||
304 | { | ||
305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
306 | "Expected message %u with bits %u, but body did not match\n", | ||
307 | n, (unsigned char) n); | ||
308 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
309 | die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
310 | return; | ||
311 | } | ||
312 | */ | ||
313 | #if VERBOSE | ||
314 | if (ntohl(hdr->num) % 5000 == 0) | ||
315 | { | ||
316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
317 | "Got message %u of size %u\n", | ||
318 | ntohl (hdr->num), | ||
319 | ntohs (message->size)); | ||
320 | } | ||
321 | #endif | ||
322 | n++; | ||
323 | if (0 == (n % (TOTAL_MSGS/100))) | ||
324 | { | ||
325 | fprintf (stderr, "."); | ||
326 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
327 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | ||
328 | TIMEOUT, | ||
329 | &end_badly, | ||
330 | NULL); | ||
331 | } | ||
332 | /* | ||
333 | if (n == TOTAL_MSGS) | ||
334 | end ();*/ | ||
335 | } | ||
257 | 336 | ||
258 | static size_t | 337 | static size_t |
259 | notify_ready (void *cls, size_t size, void *buf) | 338 | notify_ready (void *cls, size_t size, void *buf) |
@@ -319,6 +398,71 @@ notify_ready (void *cls, size_t size, void *buf) | |||
319 | return ret; | 398 | return ret; |
320 | } | 399 | } |
321 | 400 | ||
401 | static size_t | ||
402 | notify_ready_new (void *cls, size_t size, void *buf) | ||
403 | { | ||
404 | static int n; | ||
405 | char *cbuf = buf; | ||
406 | struct TestMessage hdr; | ||
407 | unsigned int s; | ||
408 | unsigned int ret; | ||
409 | |||
410 | if (buf == NULL) | ||
411 | { | ||
412 | GNUNET_break (0); | ||
413 | ok = 42; | ||
414 | return 0; | ||
415 | } | ||
416 | ret = 0; | ||
417 | s = get_size_new (n); | ||
418 | GNUNET_assert (size >= s); | ||
419 | GNUNET_assert (buf != NULL); | ||
420 | cbuf = buf; | ||
421 | do | ||
422 | { | ||
423 | hdr.header.size = htons (s); | ||
424 | hdr.header.type = htons (MTYPE); | ||
425 | hdr.num = htonl (n); | ||
426 | msg_sent = n; | ||
427 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | ||
428 | ret += sizeof (struct TestMessage); | ||
429 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | ||
430 | ret += s - sizeof (struct TestMessage); | ||
431 | #if VERBOSE | ||
432 | if (n % 5000 == 0) | ||
433 | { | ||
434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
435 | "Sending message %u\n",n); | ||
436 | } | ||
437 | #endif | ||
438 | n++; | ||
439 | s = get_size_new (n); | ||
440 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | ||
441 | break; /* sometimes pack buffer full, sometimes not */ | ||
442 | } | ||
443 | while (size - ret >= s); | ||
444 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | ||
445 | &p1.id, | ||
446 | s, 0, TIMEOUT, | ||
447 | ¬ify_ready_new, | ||
448 | NULL); | ||
449 | msg_scheduled = n; | ||
450 | total_bytes += ret; | ||
451 | return ret; | ||
452 | } | ||
453 | |||
454 | static void | ||
455 | stop_measurement (void *cls, | ||
456 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
457 | { | ||
458 | |||
459 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
460 | "END OF MEASUREMENT %u bytes sent \n ", total_bytes); | ||
461 | |||
462 | end(); | ||
463 | } | ||
464 | |||
465 | |||
322 | static void measure () | 466 | static void measure () |
323 | { | 467 | { |
324 | #if VERBOSE | 468 | #if VERBOSE |
@@ -328,7 +472,7 @@ static void measure () | |||
328 | GNUNET_TRANSPORT_set_quota (p1.th, | 472 | GNUNET_TRANSPORT_set_quota (p1.th, |
329 | &p2.id, | 473 | &p2.id, |
330 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), | 474 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), |
331 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), | 475 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), |
332 | GNUNET_TIME_UNIT_FOREVER_REL, | 476 | GNUNET_TIME_UNIT_FOREVER_REL, |
333 | NULL, NULL); | 477 | NULL, NULL); |
334 | GNUNET_TRANSPORT_set_quota (p2.th, | 478 | GNUNET_TRANSPORT_set_quota (p2.th, |
@@ -339,11 +483,15 @@ static void measure () | |||
339 | NULL, NULL); | 483 | NULL, NULL); |
340 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 484 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
341 | &p1.id, | 485 | &p1.id, |
342 | get_size (0), 0, TIMEOUT, | 486 | get_size_new (0), 0, TIMEOUT, |
343 | ¬ify_ready, | 487 | ¬ify_ready_new, |
344 | NULL); | 488 | NULL); |
489 | measurement_task = GNUNET_SCHEDULER_add_delayed (sched, | ||
490 | MEASUREMENT_INTERVALL, | ||
491 | &stop_measurement, | ||
492 | NULL); | ||
493 | total_bytes = 0; | ||
345 | start_time = GNUNET_TIME_absolute_get (); | 494 | start_time = GNUNET_TIME_absolute_get (); |
346 | |||
347 | } | 495 | } |
348 | 496 | ||
349 | static void | 497 | static void |
@@ -399,7 +547,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
399 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 547 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
400 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL, | 548 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL, |
401 | p, | 549 | p, |
402 | ¬ify_receive, | 550 | ¬ify_receive_new, |
403 | ¬ify_connect, | 551 | ¬ify_connect, |
404 | ¬ify_disconnect); | 552 | ¬ify_disconnect); |
405 | GNUNET_assert (p->th != NULL); | 553 | GNUNET_assert (p->th != NULL); |