aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_quota_compliance.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_quota_compliance.c')
-rw-r--r--src/transport/test_quota_compliance.c161
1 files changed, 87 insertions, 74 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 1c6bba0d5..7d28820cb 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -70,9 +70,9 @@ struct PeerContext *p1;
70 70
71struct PeerContext *p2; 71struct PeerContext *p2;
72 72
73struct PeerContext * sender; 73struct PeerContext *sender;
74 74
75struct PeerContext * receiver; 75struct PeerContext *receiver;
76 76
77struct GNUNET_TRANSPORT_TransmitHandle *th; 77struct GNUNET_TRANSPORT_TransmitHandle *th;
78 78
@@ -86,7 +86,7 @@ char *gen_cfg_p1;
86unsigned long long quota_in_p2; 86unsigned long long quota_in_p2;
87unsigned long long quota_out_p2; 87unsigned long long quota_out_p2;
88 88
89struct GNUNET_TRANSPORT_TESTING_handle * tth; 89struct GNUNET_TRANSPORT_TESTING_handle *tth;
90 90
91static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; 91static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
92 92
@@ -144,26 +144,28 @@ end ()
144 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 144 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
145 datarate = (total_bytes_sent * 1000) / delta; 145 datarate = (total_bytes_sent * 1000) / delta;
146 146
147 fprintf (stderr, "Throughput was %llu b/s\n", 147 fprintf (stderr, "Throughput was %llu b/s\n", datarate);
148 datarate);
149 148
150 test_failed = GNUNET_NO; 149 test_failed = GNUNET_NO;
151 if (datarate > quota_in_p2) 150 if (datarate > quota_in_p2)
152 { 151 {
153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
154 "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", datarate, quota_in_p2); 153 "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n",
154 datarate, quota_in_p2);
155 test_failed = GNUNET_YES; 155 test_failed = GNUNET_YES;
156 } 156 }
157 if (datarate > quota_out_p1) 157 if (datarate > quota_out_p1)
158 { 158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", datarate, quota_out_p1); 160 "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n",
161 datarate, quota_out_p1);
161 test_failed = GNUNET_YES; 162 test_failed = GNUNET_YES;
162 } 163 }
163 if (test_failed == GNUNET_NO) 164 if (test_failed == GNUNET_NO)
164 { 165 {
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
166 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", datarate, quota_out_p1, quota_in_p2); 167 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n",
168 datarate, quota_out_p1, quota_in_p2);
167 } 169 }
168 170
169 if (die_task != GNUNET_SCHEDULER_NO_TASK) 171 if (die_task != GNUNET_SCHEDULER_NO_TASK)
@@ -174,7 +176,7 @@ end ()
174 th = NULL; 176 th = NULL;
175 177
176 if (cc != NULL) 178 if (cc != NULL)
177 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 179 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
178 180
179 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 181 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
180 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 182 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
@@ -200,7 +202,7 @@ end_badly ()
200 th = NULL; 202 th = NULL;
201 203
202 if (cc != NULL) 204 if (cc != NULL)
203 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 205 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
204 206
205 if (p1 != NULL) 207 if (p1 != NULL)
206 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 208 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
@@ -224,8 +226,7 @@ get_size (unsigned int iter)
224static void 226static void
225notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 227notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
226 const struct GNUNET_MessageHeader *message, 228 const struct GNUNET_MessageHeader *message,
227 const struct GNUNET_ATS_Information *ats, 229 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
228 uint32_t ats_count)
229{ 230{
230 static int n; 231 static int n;
231 unsigned int s; 232 unsigned int s;
@@ -269,17 +270,19 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
269 if (die_task != GNUNET_SCHEDULER_NO_TASK) 270 if (die_task != GNUNET_SCHEDULER_NO_TASK)
270 GNUNET_SCHEDULER_cancel (die_task); 271 GNUNET_SCHEDULER_cancel (die_task);
271 test_failed = GNUNET_YES; 272 test_failed = GNUNET_YES;
272 die_task = GNUNET_SCHEDULER_add_now (&end_badly, 273 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
273 NULL);
274 return; 274 return;
275 } 275 }
276#if VERBOSE 276#if VERBOSE
277 if (ntohl (hdr->num) % 5000 == 0) 277 if (ntohl (hdr->num) % 5000 == 0)
278 { 278 {
279 struct PeerContext *p = cls; 279 struct PeerContext *p = cls;
280 char * ps = strdup(GNUNET_i2s(&p->id)); 280 char *ps = strdup (GNUNET_i2s (&p->id));
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 281
282 p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer)); 282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
284 p->no, ps, ntohl (hdr->num), ntohs (message->size),
285 GNUNET_i2s (peer));
283 GNUNET_free (ps); 286 GNUNET_free (ps);
284 } 287 }
285#endif 288#endif
@@ -300,7 +303,8 @@ notify_ready (void *cls, size_t size, void *buf)
300 if (buf == NULL) 303 if (buf == NULL)
301 { 304 {
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
303 "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS); 306 "Timeout occurred while waiting for transmit_ready for message %u of %u\n",
307 msg_scheduled, TOTAL_MSGS);
304 if (GNUNET_SCHEDULER_NO_TASK != die_task) 308 if (GNUNET_SCHEDULER_NO_TASK != die_task)
305 GNUNET_SCHEDULER_cancel (die_task); 309 GNUNET_SCHEDULER_cancel (die_task);
306 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 310 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
@@ -327,12 +331,12 @@ notify_ready (void *cls, size_t size, void *buf)
327 if (n % 5000 == 0) 331 if (n % 5000 == 0)
328 { 332 {
329 333
330 char * receiver_s = strdup(GNUNET_i2s (&receiver->id)); 334 char *receiver_s = strdup (GNUNET_i2s (&receiver->id));
335
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", 337 "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
333 n, 338 n, sender->no, GNUNET_i2s (&sender->id), receiver->no,
334 sender->no, 339 receiver_s);
335 GNUNET_i2s (&sender->id), receiver->no, receiver_s);
336 GNUNET_free (receiver_s); 340 GNUNET_free (receiver_s);
337 } 341 }
338#endif 342#endif
@@ -367,11 +371,11 @@ notify_ready (void *cls, size_t size, void *buf)
367 371
368static void 372static void
369notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 373notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
370 const struct GNUNET_ATS_Information *ats, 374 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
371 uint32_t ats_count)
372{ 375{
373 376
374 struct PeerContext *p = cls; 377 struct PeerContext *p = cls;
378
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n",
376 p->no, GNUNET_i2s (peer)); 380 p->no, GNUNET_i2s (peer));
377} 381}
@@ -381,8 +385,9 @@ static void
381notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 385notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
382{ 386{
383 struct PeerContext *p = cls; 387 struct PeerContext *p = cls;
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", 388
385 p->no, GNUNET_i2s (peer)); 389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no,
390 GNUNET_i2s (peer));
386 if (th != NULL) 391 if (th != NULL)
387 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 392 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
388 th = NULL; 393 th = NULL;
@@ -403,10 +408,11 @@ static void
403measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 408measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
404{ 409{
405 static int counter; 410 static int counter;
411
406 measure_task = GNUNET_SCHEDULER_NO_TASK; 412 measure_task = GNUNET_SCHEDULER_NO_TASK;
407 413
408 counter++; 414 counter++;
409 if ((DURATION.rel_value / 1000) < counter ) 415 if ((DURATION.rel_value / 1000) < counter)
410 { 416 {
411 fprintf (stderr, ".\n"); 417 fprintf (stderr, ".\n");
412 GNUNET_SCHEDULER_add_now (&end, NULL); 418 GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -414,7 +420,8 @@ measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
414 else 420 else
415 { 421 {
416 fprintf (stderr, "."); 422 fprintf (stderr, ".");
417 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); 423 measure_task =
424 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
418 } 425 }
419} 426}
420 427
@@ -423,28 +430,29 @@ static void
423testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 430testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
424{ 431{
425 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 432 char *p1_c = strdup (GNUNET_i2s (&p1->id));
433
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", 434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
427 p1->no, p1_c, 435 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
428 p2->no, GNUNET_i2s (&p2->id));
429 GNUNET_free (p1_c); 436 GNUNET_free (p1_c);
430 437
431 cc = NULL; 438 cc = NULL;
432 test_connected = GNUNET_YES; 439 test_connected = GNUNET_YES;
433 440
434 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); 441 measure_task =
442 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
435 GNUNET_SCHEDULER_add_now (&sendtask, NULL); 443 GNUNET_SCHEDULER_add_now (&sendtask, NULL);
436 444
437} 445}
438 446
439void start_cb (struct PeerContext * p, 447void
440 void *cls) 448start_cb (struct PeerContext *p, void *cls)
441{ 449{
442 static int started; 450 static int started;
451
443 started++; 452 started++;
444 453
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
446 p->no, 455 GNUNET_i2s (&p->id));
447 GNUNET_i2s (&p->id));
448 456
449 if (started != 2) 457 if (started != 2)
450 return; 458 return;
@@ -455,61 +463,66 @@ void start_cb (struct PeerContext * p,
455 receiver = p1; 463 receiver = p1;
456 464
457 char *sender_c = strdup (GNUNET_i2s (&sender->id)); 465 char *sender_c = strdup (GNUNET_i2s (&sender->id));
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to send from %u (%s) -> peer %u (%s)\n",
459 sender->no, sender_c,
460 receiver->no, GNUNET_i2s (&receiver->id));
461 466
462 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); 467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Test tries to send from %u (%s) -> peer %u (%s)\n", sender->no,
469 sender_c, receiver->no, GNUNET_i2s (&receiver->id));
470
471 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
472 NULL);
463 473
464} 474}
465 475
466static char * 476static char *
467generate_config (char * cfg_file, unsigned long long quota_in, unsigned long long quota_out) 477generate_config (char *cfg_file, unsigned long long quota_in,
478 unsigned long long quota_out)
468{ 479{
469 char * fname = NULL; 480 char *fname = NULL;
470 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create(); 481 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
482
471 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file)); 483 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file));
472 GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, cfg_file); 484 GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out,
473 GNUNET_CONFIGURATION_set_value_string(cfg, "PATHS", "DEFAULTCONFIG", fname); 485 cfg_file);
474 GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_OUT", quota_out); 486 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname);
475 GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_IN", quota_in); 487 GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_OUT",
476 GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_IN", quota_in); 488 quota_out);
477 GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_OUT", quota_out); 489 GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_IN",
478 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write(cfg, fname)); 490 quota_in);
479 GNUNET_CONFIGURATION_destroy(cfg); 491 GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_IN",
492 quota_in);
493 GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_OUT",
494 quota_out);
495 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname));
496 GNUNET_CONFIGURATION_destroy (cfg);
480 return fname; 497 return fname;
481} 498}
482 499
483static void 500static void
484run_measurement (unsigned long long p1_quota_in, unsigned long long p1_quota_out, 501run_measurement (unsigned long long p1_quota_in,
485 unsigned long long p2_quota_in, unsigned long long p2_quota_out) 502 unsigned long long p1_quota_out,
503 unsigned long long p2_quota_in,
504 unsigned long long p2_quota_out)
486{ 505{
487 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 506 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
488 507
489 /* setting ATS quota */ 508 /* setting ATS quota */
490 quota_out_p1 = p1_quota_out; 509 quota_out_p1 = p1_quota_out;
491 gen_cfg_p1 = generate_config(cfg_file_p1, p1_quota_in, p1_quota_out); 510 gen_cfg_p1 = generate_config (cfg_file_p1, p1_quota_in, p1_quota_out);
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
493 "Generated config file `%s'\n", 512 gen_cfg_p1);
494 gen_cfg_p1);
495 513
496 quota_in_p2 = p2_quota_in; 514 quota_in_p2 = p2_quota_in;
497 gen_cfg_p2 = generate_config(cfg_file_p2, p2_quota_in, p2_quota_out); 515 gen_cfg_p2 = generate_config (cfg_file_p2, p2_quota_in, p2_quota_out);
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
499 "Generated config file `%s'\n", 517 gen_cfg_p2);
500 gen_cfg_p2);
501 518
502 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, 519 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, &notify_receive,
503 &notify_receive,
504 &notify_connect, &notify_disconnect, 520 &notify_connect, &notify_disconnect,
505 &start_cb, 521 &start_cb, NULL);
506 NULL);
507 522
508 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, 523 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, &notify_receive,
509 &notify_receive,
510 &notify_connect, &notify_disconnect, 524 &notify_connect, &notify_disconnect,
511 &start_cb, 525 &start_cb, NULL);
512 NULL);
513 526
514 if ((p1 == NULL) || (p2 == NULL)) 527 if ((p1 == NULL) || (p2 == NULL))
515 { 528 {
@@ -530,19 +543,19 @@ run (void *cls, char *const *args, const char *cfgfile,
530 unsigned long long p2_quota_in = 10000; 543 unsigned long long p2_quota_in = 10000;
531 unsigned long long p2_quota_out = 10000; 544 unsigned long long p2_quota_out = 10000;
532 545
533 if (NULL != strstr (test_name,"asymmetric")) 546 if (NULL != strstr (test_name, "asymmetric"))
534 { 547 {
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
536 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", 549 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n",
537 p2_quota_in, p2_quota_out); 550 p2_quota_in, p2_quota_out);
538 p1_quota_out = 1024 * 1024 * 1024; 551 p1_quota_out = 1024 * 1024 * 1024;
539 p1_quota_in = 1024 * 1024 * 1024; 552 p1_quota_in = 1024 * 1024 * 1024;
540 } 553 }
541 else 554 else
542 { 555 {
543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
544 "Running symmetric test with (in/out) %llu/%llu b/s \n", 557 "Running symmetric test with (in/out) %llu/%llu b/s \n",
545 p2_quota_in, p2_quota_out); 558 p2_quota_in, p2_quota_out);
546 } 559 }
547 run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out); 560 run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out);
548} 561}