diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-02 12:48:00 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-02 12:48:00 +0000 |
commit | ef6a7d5caff982795f749f6ce7d4ea54eac96ab7 (patch) | |
tree | dcc01aa13fbb10c22accee31252c4e217380ae63 | |
parent | a835b3a78f988d45032449012954c8b4a4e8cd40 (diff) | |
download | gnunet-ef6a7d5caff982795f749f6ce7d4ea54eac96ab7.tar.gz gnunet-ef6a7d5caff982795f749f6ce7d4ea54eac96ab7.zip |
-rw-r--r-- | src/transport/test_quota_compliance.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 86357c540..7ea8c451f 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -42,12 +42,12 @@ | |||
42 | #define DEBUG_MEASUREMENT GNUNET_NO | 42 | #define DEBUG_MEASUREMENT GNUNET_NO |
43 | #define DEBUG_CONNECTIONS GNUNET_NO | 43 | #define DEBUG_CONNECTIONS GNUNET_NO |
44 | 44 | ||
45 | #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | 45 | #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) |
46 | #define MEASUREMENT_MSG_SIZE 1024 | 46 | #define MEASUREMENT_MSG_SIZE 1024 |
47 | #define MEASUREMENT_MSG_SIZE_BIG 32768 | 47 | #define MEASUREMENT_MSG_SIZE_BIG 32768 |
48 | #define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024 | 48 | #define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024 |
49 | #define MEASUREMENT_MIN_QUOTA 1024 * 1024 | 49 | #define MEASUREMENT_MIN_QUOTA 1024 |
50 | #define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 35) | 50 | #define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
51 | /** | 51 | /** |
52 | * Testcase timeout | 52 | * Testcase timeout |
53 | */ | 53 | */ |
@@ -128,7 +128,9 @@ static int measurement_running; | |||
128 | static int send_running; | 128 | static int send_running; |
129 | static int recv_running; | 129 | static int recv_running; |
130 | 130 | ||
131 | static unsigned long long total_bytes; | 131 | static unsigned long long total_bytes_sent; |
132 | static unsigned long long last_msg_sent; | ||
133 | static unsigned long long last_msg_recv; | ||
132 | static unsigned long long current_quota_p1; | 134 | static unsigned long long current_quota_p1; |
133 | static unsigned long long current_quota_p2; | 135 | static unsigned long long current_quota_p2; |
134 | 136 | ||
@@ -230,7 +232,7 @@ struct TestMessage | |||
230 | }; | 232 | }; |
231 | 233 | ||
232 | static unsigned int | 234 | static unsigned int |
233 | get_size (unsigned int iter) | 235 | get_size (void) |
234 | { | 236 | { |
235 | return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage); | 237 | return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage); |
236 | } | 238 | } |
@@ -242,16 +244,16 @@ notify_receive_new (void *cls, | |||
242 | struct GNUNET_TIME_Relative latency, | 244 | struct GNUNET_TIME_Relative latency, |
243 | uint32_t distance) | 245 | uint32_t distance) |
244 | { | 246 | { |
245 | static int n; | ||
246 | unsigned int s; | 247 | unsigned int s; |
247 | const struct TestMessage *hdr; | 248 | const struct TestMessage *hdr; |
248 | 249 | ||
249 | hdr = (const struct TestMessage*) message; | 250 | hdr = (const struct TestMessage*) message; |
250 | s = get_size (n); | 251 | s = get_size (); |
251 | if (measurement_running == GNUNET_NO) | 252 | if (measurement_running == GNUNET_NO) |
252 | return; | 253 | return; |
253 | if (MTYPE != ntohs (message->type)) | 254 | if (MTYPE != ntohs (message->type)) |
254 | return; | 255 | return; |
256 | |||
255 | #if DEBUG_MEASUREMENT | 257 | #if DEBUG_MEASUREMENT |
256 | if (ntohl(hdr->num) % 5000 == 0) | 258 | if (ntohl(hdr->num) % 5000 == 0) |
257 | { | 259 | { |
@@ -261,13 +263,16 @@ notify_receive_new (void *cls, | |||
261 | ntohs (message->size)); | 263 | ntohs (message->size)); |
262 | } | 264 | } |
263 | #endif | 265 | #endif |
264 | n++; | 266 | /* |
267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
268 | "Got message %u\n", | ||
269 | ntohl (hdr->num));*/ | ||
270 | last_msg_recv = ntohl (hdr->num); | ||
265 | } | 271 | } |
266 | 272 | ||
267 | static size_t | 273 | static size_t |
268 | notify_ready_new (void *cls, size_t size, void *buf) | 274 | notify_ready (void *cls, size_t size, void *buf) |
269 | { | 275 | { |
270 | static int n; | ||
271 | char *cbuf = buf; | 276 | char *cbuf = buf; |
272 | struct TestMessage hdr; | 277 | struct TestMessage hdr; |
273 | unsigned int s; | 278 | unsigned int s; |
@@ -293,18 +298,19 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
293 | 298 | ||
294 | send_running = GNUNET_YES; | 299 | send_running = GNUNET_YES; |
295 | ret = 0; | 300 | ret = 0; |
296 | s = get_size (n); | 301 | s = get_size (); |
297 | GNUNET_assert (size >= s); | 302 | GNUNET_assert (size >= s); |
298 | GNUNET_assert (buf != NULL); | 303 | GNUNET_assert (buf != NULL); |
304 | last_msg_sent++; | ||
299 | cbuf = buf; | 305 | cbuf = buf; |
300 | do | 306 | do |
301 | { | 307 | { |
302 | hdr.header.size = htons (s); | 308 | hdr.header.size = htons (s); |
303 | hdr.header.type = htons (MTYPE); | 309 | hdr.header.type = htons (MTYPE); |
304 | hdr.num = htonl (n); | 310 | hdr.num = htonl (last_msg_sent); |
305 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 311 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
306 | ret += sizeof (struct TestMessage); | 312 | ret += sizeof (struct TestMessage); |
307 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | 313 | memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage)); |
308 | ret += s - sizeof (struct TestMessage); | 314 | ret += s - sizeof (struct TestMessage); |
309 | #if DEBUG_MEASUREMENT | 315 | #if DEBUG_MEASUREMENT |
310 | if (n % 5000 == 0) | 316 | if (n % 5000 == 0) |
@@ -313,8 +319,11 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
313 | "Sending message %u\n",n); | 319 | "Sending message %u\n",n); |
314 | } | 320 | } |
315 | #endif | 321 | #endif |
316 | n++; | 322 | |
317 | s = get_size (n); | 323 | /* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
324 | "Sending message %u\n",last_msg_sent);*/ | ||
325 | |||
326 | s = get_size (); | ||
318 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 327 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
319 | break; /* sometimes pack buffer full, sometimes not */ | 328 | break; /* sometimes pack buffer full, sometimes not */ |
320 | } | 329 | } |
@@ -322,9 +331,9 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
322 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 331 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
323 | &p1.id, | 332 | &p1.id, |
324 | s, 0, SEND_TIMEOUT, | 333 | s, 0, SEND_TIMEOUT, |
325 | ¬ify_ready_new, | 334 | ¬ify_ready, |
326 | NULL); | 335 | NULL); |
327 | total_bytes += s; | 336 | total_bytes_sent += s; |
328 | return ret; | 337 | return ret; |
329 | } | 338 | } |
330 | 339 | ||
@@ -370,39 +379,38 @@ measurement_end (void *cls, | |||
370 | #if VERBOSE | 379 | #if VERBOSE |
371 | fprintf(stderr,"\n"); | 380 | fprintf(stderr,"\n"); |
372 | #endif | 381 | #endif |
373 | /* | 382 | |
374 | if (transmit_handle != NULL) | 383 | if (transmit_handle != NULL) |
375 | { | 384 | { |
376 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); | 385 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); |
377 | transmit_handle = NULL; | 386 | transmit_handle = NULL; |
378 | } | 387 | } |
379 | */ | ||
380 | 388 | ||
381 | if (current_quota_p1 < current_quota_p2) | 389 | if (current_quota_p1 < current_quota_p2) |
382 | quota_allowed = current_quota_p1; | 390 | quota_allowed = current_quota_p1; |
383 | else | 391 | else |
384 | quota_allowed = current_quota_p2; | 392 | quota_allowed = current_quota_p2; |
385 | 393 | ||
386 | if ((total_bytes/(duration.rel_value / 1000)) > (quota_allowed + (quota_allowed / 10))) | 394 | if ((total_bytes_sent/(duration.rel_value / 1000)) > (quota_allowed + (quota_allowed / 10))) |
387 | { | 395 | { |
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 396 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
389 | "\nQuota compliance failed: \n"\ | 397 | "\nQuota compliance failed: \n"\ |
390 | "Quota allowed: %10llu kB/s\n"\ | 398 | "Quota allowed: %10llu kB/s\n"\ |
391 | "Throughput : %10llu kB/s\n", (quota_allowed / (1024)), (total_bytes/(duration.rel_value / 1000)/1024)); | 399 | "Throughput : %10llu kB/s\n", (quota_allowed / (1024)), (total_bytes_sent/(duration.rel_value / 1000)/1024)); |
392 | ok = 1; | 400 | ok = 1; |
393 | /*end(); | 401 | end(); |
394 | return;*/ | 402 | return; |
395 | } | 403 | } |
396 | else | 404 | else |
397 | { | 405 | { |
398 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 406 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
399 | "\nQuota compliance ok: \n"\ | 407 | "\nQuota compliance ok: \n"\ |
400 | "Quota allowed: %10llu kB/s\n"\ | 408 | "Quota allowed: %10llu kB/s\n"\ |
401 | "Throughput : %10llu kB/s\n", (quota_allowed / (1024)) , (total_bytes/(duration.rel_value / 1000)/1024)); | 409 | "Throughput : %10llu kB/s\n", (quota_allowed / (1024)) , (total_bytes_sent/(duration.rel_value / 1000)/1024)); |
402 | ok = 0; | 410 | ok = 0; |
403 | } | 411 | } |
404 | 412 | ||
405 | if ((quota_allowed) > (2 *(total_bytes/(duration.rel_value / 1000)))) | 413 | if ((quota_allowed) > (2 *(total_bytes_sent/(duration.rel_value / 1000)))) |
406 | { | 414 | { |
407 | strike_counter++; | 415 | strike_counter++; |
408 | if (strike_counter == 2) | 416 | if (strike_counter == 2) |
@@ -488,7 +496,9 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | |||
488 | MEASUREMENT_INTERVALL, | 496 | MEASUREMENT_INTERVALL, |
489 | &measurement_end, | 497 | &measurement_end, |
490 | NULL); | 498 | NULL); |
491 | total_bytes = 0; | 499 | total_bytes_sent = 0; |
500 | last_msg_sent = 0; | ||
501 | last_msg_recv = 0; | ||
492 | measurement_running = GNUNET_YES; | 502 | measurement_running = GNUNET_YES; |
493 | start_time = GNUNET_TIME_absolute_get (); | 503 | start_time = GNUNET_TIME_absolute_get (); |
494 | 504 | ||
@@ -496,8 +506,8 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | |||
496 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); | 506 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); |
497 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 507 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
498 | &p1.id, | 508 | &p1.id, |
499 | get_size (0), 0, SEND_TIMEOUT, | 509 | get_size (), 0, SEND_TIMEOUT, |
500 | ¬ify_ready_new, | 510 | ¬ify_ready, |
501 | NULL); | 511 | NULL); |
502 | } | 512 | } |
503 | 513 | ||