summaryrefslogtreecommitdiff
path: root/src/ats/perf_ats_solver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/perf_ats_solver.c')
-rw-r--r--src/ats/perf_ats_solver.c1609
1 files changed, 830 insertions, 779 deletions
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c
index 6a4eadad7..5f10addaf 100644
--- a/src/ats/perf_ats_solver.c
+++ b/src/ats/perf_ats_solver.c
@@ -49,7 +49,8 @@ struct GNUNET_STATISTICS_Handle *GSA_stats;
49/** 49/**
50 * Handle for ATS address component 50 * Handle for ATS address component
51 */ 51 */
52struct PerfHandle { 52struct PerfHandle
53{
53 /** 54 /**
54 * Performance peers 55 * Performance peers
55 */ 56 */
@@ -164,7 +165,8 @@ struct PerfHandle {
164/** 165/**
165 * Data structure to store results for a single iteration 166 * Data structure to store results for a single iteration
166 */ 167 */
167struct Iteration { 168struct Iteration
169{
168 struct Result **results_array; 170 struct Result **results_array;
169 171
170 struct Result **update_results_array; 172 struct Result **update_results_array;
@@ -174,7 +176,8 @@ struct Iteration {
174/** 176/**
175 * Result for a solver calculcation 177 * Result for a solver calculcation
176 */ 178 */
177struct Result { 179struct Result
180{
178 /** 181 /**
179 * Previous element in the linked list 182 * Previous element in the linked list
180 */ 183 */
@@ -280,7 +283,8 @@ struct Result {
280/** 283/**
281 * Peer used for the benchmarking 284 * Peer used for the benchmarking
282 */ 285 */
283struct PerfPeer { 286struct PerfPeer
287{
284 /** 288 /**
285 * Peer identitity 289 * Peer identitity
286 */ 290 */
@@ -313,19 +317,19 @@ static int ret;
313 * Do shutdown 317 * Do shutdown
314 */ 318 */
315static void 319static void
316end_now(int res) 320end_now (int res)
317{ 321{
318 if (NULL != ph.stat) 322 if (NULL != ph.stat)
319 { 323 {
320 GNUNET_STATISTICS_destroy(ph.stat, GNUNET_NO); 324 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
321 ph.stat = NULL; 325 ph.stat = NULL;
322 } 326 }
323 327
324 GNUNET_free_non_null(ph.peers); 328 GNUNET_free_non_null (ph.peers);
325 GNUNET_free_non_null(ph.iterations_results); 329 GNUNET_free_non_null (ph.iterations_results);
326 330
327 GAS_normalization_stop(); 331 GAS_normalization_stop ();
328 GAS_preference_done(); 332 GAS_preference_done ();
329 ret = res; 333 ret = res;
330} 334}
331 335
@@ -336,12 +340,13 @@ end_now(int res)
336 * @param cp the number of the peer 340 * @param cp the number of the peer
337 */ 341 */
338static void 342static void
339perf_create_peer(int cp) 343perf_create_peer (int cp)
340{ 344{
341 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, 345 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
342 &ph.peers[cp].id, sizeof(struct GNUNET_PeerIdentity)); 346 &ph.peers[cp].id, sizeof(struct
343 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, 347 GNUNET_PeerIdentity));
344 GNUNET_i2s(&ph.peers[cp].id)); 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
349 GNUNET_i2s (&ph.peers[cp].id));
345} 350}
346 351
347 352
@@ -351,117 +356,118 @@ perf_create_peer(int cp)
351 * @param cur the address to update 356 * @param cur the address to update
352 */ 357 */
353static void 358static void
354perf_update_address(struct ATS_Address *cur) 359perf_update_address (struct ATS_Address *cur)
355{ 360{
356 int r_type; 361 int r_type;
357 int abs_val; 362 int abs_val;
358 double rel_val; 363 double rel_val;
359 364
360 r_type = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2); 365 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
361 switch (r_type) 366 switch (r_type)
362 { 367 {
363 case 0: 368 case 0:
364 abs_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 369 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
365 rel_val = (100 + (double)abs_val) / 100; 370 rel_val = (100 + (double) abs_val) / 100;
366 371
367 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 372 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
368 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", 373 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
369 GNUNET_i2s(&cur->peer), cur, 374 GNUNET_i2s (&cur->peer), cur,
370 "GNUNET_ATS_QUALITY_NET_DELAY", 375 "GNUNET_ATS_QUALITY_NET_DELAY",
371 abs_val, rel_val); 376 abs_val, rel_val);
372 ph.sf->s_address_update_property(ph.sf->cls, cur, 377 ph.sf->s_address_update_property (ph.sf->cls, cur,
373 GNUNET_ATS_QUALITY_NET_DELAY, 378 GNUNET_ATS_QUALITY_NET_DELAY,
374 abs_val, rel_val); 379 abs_val, rel_val);
375 break; 380 break;
376 381
377 case 1: 382 case 1:
378 abs_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10); 383 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
379 rel_val = (100 + (double)abs_val) / 100; 384 rel_val = (100 + (double) abs_val) / 100;
380 385
381 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 386 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
382 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", 387 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
383 GNUNET_i2s(&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", 388 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
384 abs_val, rel_val); 389 abs_val, rel_val);
385 ph.sf->s_address_update_property(ph.sf->cls, cur, 390 ph.sf->s_address_update_property (ph.sf->cls, cur,
386 GNUNET_ATS_QUALITY_NET_DISTANCE, 391 GNUNET_ATS_QUALITY_NET_DISTANCE,
387 abs_val, rel_val); 392 abs_val, rel_val);
388 break; 393 break;
389 394
390 default: 395 default:
391 break; 396 break;
392 } 397 }
393} 398}
394 399
395 400
396static void 401static void
397bandwidth_changed_cb(void *cls, 402bandwidth_changed_cb (void *cls,
398 struct ATS_Address *address) 403 struct ATS_Address *address)
399{ 404{
400 if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in)) 405 if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in))
401 return; 406 return;
402 407
403 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n", 409 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
405 GNUNET_i2s(&address->peer), 410 GNUNET_i2s (&address->peer),
406 address, 411 address,
407 address->assigned_bw_out, 412 address->assigned_bw_out,
408 address->assigned_bw_in); 413 address->assigned_bw_in);
409 if (GNUNET_YES == ph.bulk_running) 414 if (GNUNET_YES == ph.bulk_running)
410 GNUNET_break(0); 415 GNUNET_break (0);
411 return; 416 return;
412} 417}
413 418
414 419
415static const double * 420static const double *
416get_preferences_cb(void *cls, const struct GNUNET_PeerIdentity *id) 421get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
417{ 422{
418 return GAS_preference_get_by_peer(NULL, id); 423 return GAS_preference_get_by_peer (NULL, id);
419} 424}
420 425
421 426
422static void 427static void
423perf_address_initial_update(void *dead, 428perf_address_initial_update (void *dead,
424 struct GNUNET_CONTAINER_MultiPeerMap * addresses, 429 struct GNUNET_CONTAINER_MultiPeerMap *addresses,
425 struct ATS_Address *address) 430 struct ATS_Address *address)
426{ 431{
427 double delay; 432 double delay;
428 double distance; 433 double distance;
429 uint32_t random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 434 uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
430 435
431 delay = (100 + (double)random) / 100; 436 delay = (100 + (double) random) / 100;
432 ph.sf->s_address_update_property(ph.sf->cls, 437 ph.sf->s_address_update_property (ph.sf->cls,
433 address, GNUNET_ATS_QUALITY_NET_DELAY, 438 address, GNUNET_ATS_QUALITY_NET_DELAY,
434 100, delay); 439 100, delay);
435 440
436 random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 441 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
437 distance = (100 + (double)random) / 100; 442 distance = (100 + (double) random) / 100;
438 443
439 ph.sf->s_address_update_property(ph.sf->cls, address, 444 ph.sf->s_address_update_property (ph.sf->cls, address,
440 GNUNET_ATS_QUALITY_NET_DISTANCE, 445 GNUNET_ATS_QUALITY_NET_DISTANCE,
441 10, distance); 446 10, distance);
442 447
443 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 448 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
444 "Initial update address %p : %.2f %.2f\n", 449 "Initial update address %p : %.2f %.2f\n",
445 address, delay, distance); 450 address, delay, distance);
446} 451}
447 452
448 453
449struct DUA_Ctx { 454struct DUA_Ctx
455{
450 int r; 456 int r;
451 int c_cur_a; 457 int c_cur_a;
452}; 458};
453 459
454 460
455static int 461static int
456do_update_address(void *cls, 462do_update_address (void *cls,
457 const struct GNUNET_PeerIdentity *pid, 463 const struct GNUNET_PeerIdentity *pid,
458 void *value) 464 void *value)
459{ 465{
460 struct DUA_Ctx *ctx = cls; 466 struct DUA_Ctx *ctx = cls;
461 struct ATS_Address *addr = value; 467 struct ATS_Address *addr = value;
462 468
463 if (ctx->c_cur_a == ctx->r) 469 if (ctx->c_cur_a == ctx->r)
464 perf_update_address(addr); 470 perf_update_address (addr);
465 ctx->c_cur_a++; 471 ctx->c_cur_a++;
466 return GNUNET_OK; 472 return GNUNET_OK;
467} 473}
@@ -475,7 +481,8 @@ do_update_address(void *cls,
475 * @param percentage_peers the percentage of peers to update 481 * @param percentage_peers the percentage of peers to update
476 */ 482 */
477static void 483static void
478perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percentage_peers) 484perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int
485 percentage_peers)
479{ 486{
480 int c_peer; 487 int c_peer;
481 int c_select; 488 int c_select;
@@ -485,9 +492,9 @@ perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percent
485 unsigned int m[cp]; 492 unsigned int m[cp];
486 struct DUA_Ctx dua_ctx; 493 struct DUA_Ctx dua_ctx;
487 494
488 count = cp * ((double)percentage_peers / 100); 495 count = cp * ((double) percentage_peers / 100);
489 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 496 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
490 "Updating %u of %u peers \n", count, cp); 497 "Updating %u of %u peers \n", count, cp);
491 498
492 for (c_peer = 0; c_peer < cp; c_peer++) 499 for (c_peer = 0; c_peer < cp; c_peer++)
493 m[c_peer] = 0; 500 m[c_peer] = 0;
@@ -495,32 +502,32 @@ perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percent
495 c_select = 0; 502 c_select = 0;
496 503
497 while (c_select < count) 504 while (c_select < count)
505 {
506 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
507 if (0 == m[r])
498 { 508 {
499 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, cp); 509 m[r] = 1;
500 if (0 == m[r]) 510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
501 { 511 "Updating peer [%u] \n", r);
502 m[r] = 1; 512 c_select++;
503 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
504 "Updating peer [%u] \n", r);
505 c_select++;
506 }
507 } 513 }
514 }
508 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++) 515 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
516 {
517 if (1 == m[c_cur_p])
509 { 518 {
510 if (1 == m[c_cur_p]) 519 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
511 { 520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
512 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, ca); 521 "Updating peer [%u] address [%u]\n", c_cur_p, r);
513 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 522
514 "Updating peer [%u] address [%u]\n", c_cur_p, r); 523 dua_ctx.c_cur_a = 0;
515 524 dua_ctx.r = r;
516 dua_ctx.c_cur_a = 0; 525 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
517 dua_ctx.r = r; 526 &ph.peers[c_cur_p].id,
518 GNUNET_CONTAINER_multipeermap_get_multiple(ph.addresses, 527 &do_update_address,
519 &ph.peers[c_cur_p].id, 528 &dua_ctx);
520 &do_update_address,
521 &dua_ctx);
522 }
523 } 529 }
530 }
524} 531}
525 532
526/** 533/**
@@ -531,14 +538,14 @@ perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percent
531 * @return the address 538 * @return the address
532 */ 539 */
533static struct ATS_Address * 540static struct ATS_Address *
534perf_create_address(int cp, int ca) 541perf_create_address (int cp, int ca)
535{ 542{
536 struct ATS_Address *a; 543 struct ATS_Address *a;
537 544
538 a = create_address(&ph.peers[cp].id, 545 a = create_address (&ph.peers[cp].id,
539 "Test 1", "test 1", strlen("test 1") + 1, 0); 546 "Test 1", "test 1", strlen ("test 1") + 1, 0);
540 GNUNET_CONTAINER_multipeermap_put(ph.addresses, &ph.peers[cp].id, a, 547 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
541 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 548 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
542 return a; 549 return a;
543} 550}
544 551
@@ -551,252 +558,264 @@ perf_create_address(int cp, int ca)
551 * @param add additional solver information 558 * @param add additional solver information
552 */ 559 */
553static void 560static void
554solver_info_cb(void *cls, 561solver_info_cb (void *cls,
555 enum GAS_Solver_Operation op, 562 enum GAS_Solver_Operation op,
556 enum GAS_Solver_Status stat, 563 enum GAS_Solver_Status stat,
557 enum GAS_Solver_Additional_Information add) 564 enum GAS_Solver_Additional_Information add)
558{ 565{
559 char *add_info; 566 char *add_info;
560 567
561 switch (add) 568 switch (add)
562 { 569 {
563 case GAS_INFO_NONE: 570 case GAS_INFO_NONE:
564 add_info = "GAS_INFO_NONE"; 571 add_info = "GAS_INFO_NONE";
565 break; 572 break;
566 573
567 case GAS_INFO_FULL: 574 case GAS_INFO_FULL:
568 add_info = "GAS_INFO_MLP_FULL"; 575 add_info = "GAS_INFO_MLP_FULL";
569 break; 576 break;
570 577
571 case GAS_INFO_UPDATED: 578 case GAS_INFO_UPDATED:
572 add_info = "GAS_INFO_MLP_UPDATED"; 579 add_info = "GAS_INFO_MLP_UPDATED";
573 break; 580 break;
574 581
575 case GAS_INFO_PROP_ALL: 582 case GAS_INFO_PROP_ALL:
576 add_info = "GAS_INFO_PROP_ALL"; 583 add_info = "GAS_INFO_PROP_ALL";
577 break; 584 break;
578 585
579 case GAS_INFO_PROP_SINGLE: 586 case GAS_INFO_PROP_SINGLE:
580 add_info = "GAS_INFO_PROP_SINGLE"; 587 add_info = "GAS_INFO_PROP_SINGLE";
581 break; 588 break;
582 589
583 default: 590 default:
584 add_info = "INVALID"; 591 add_info = "INVALID";
585 break; 592 break;
586 } 593 }
587 594
588 struct Result *tmp; 595 struct Result *tmp;
589 switch (op) 596 switch (op)
597 {
598 case GAS_OP_SOLVE_START:
599 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
600 "Solver notifies `%s' with result `%s' `%s'\n",
601 "GAS_OP_SOLVE_START",
602 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
603 if (GNUNET_NO == ph.expecting_solution)
590 { 604 {
591 case GAS_OP_SOLVE_START: 605 /* We do not expect a solution at the moment */
592 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 606 GNUNET_break (0);
593 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
594 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
595 if (GNUNET_NO == ph.expecting_solution)
596 {
597 /* We do not expect a solution at the moment */
598 GNUNET_break(0);
599 return;
600 }
601
602 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
603 {
604 tmp = GNUNET_new(struct Result);
605 /* Create new result */
606 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
607 {
608 ph.current_result = tmp;
609 //fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p);
610 ph.iterations_results[ph.current_iteration - 1].update_results_array[ph.current_p] = tmp;
611 }
612 else
613 {
614 ph.current_result = tmp;
615 //fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p);
616 ph.iterations_results[ph.current_iteration - 1].results_array[ph.current_p] = tmp;
617 }
618
619 ph.current_result->addresses = ph.current_a;
620 ph.current_result->peers = ph.current_p;
621 ph.current_result->s_total = GNUNET_TIME_absolute_get();
622 ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL;
623 ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL;
624 ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL;
625 ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL;
626 ph.current_result->info = add;
627 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
628 {
629 ph.current_result->update = GNUNET_YES;
630 }
631 else
632 {
633 ph.current_result->update = GNUNET_NO;
634 }
635 }
636 return; 607 return;
608 }
637 609
638 case GAS_OP_SOLVE_STOP: 610 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
639 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 611 {
640 "Solver notifies `%s' with result `%s', `%s'\n", "GAS_OP_SOLVE_STOP", 612 tmp = GNUNET_new (struct Result);
641 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); 613 /* Create new result */
642 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) 614 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
643 { 615 {
644 /* We do not expect a solution at the moment */ 616 ph.current_result = tmp;
645 GNUNET_break(0); 617 // fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p);
646 return; 618 ph.iterations_results[ph.current_iteration
647 } 619 - 1].update_results_array[ph.current_p] = tmp;
648 620 }
649 if (GAS_STAT_SUCCESS == stat)
650 ph.current_result->valid = GNUNET_YES;
651 else 621 else
652 ph.current_result->valid = GNUNET_NO; 622 {
623 ph.current_result = tmp;
624 // fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p);
625 ph.iterations_results[ph.current_iteration
626 - 1].results_array[ph.current_p] = tmp;
627 }
628
629 ph.current_result->addresses = ph.current_a;
630 ph.current_result->peers = ph.current_p;
631 ph.current_result->s_total = GNUNET_TIME_absolute_get ();
632 ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL;
633 ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL;
634 ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL;
635 ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL;
636 ph.current_result->info = add;
637 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
638 {
639 ph.current_result->update = GNUNET_YES;
640 }
641 else
642 {
643 ph.current_result->update = GNUNET_NO;
644 }
645 }
646 return;
653 647
654 if (NULL != ph.current_result) 648 case GAS_OP_SOLVE_STOP:
655 { 649 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
656 /* Finalize result */ 650 "Solver notifies `%s' with result `%s', `%s'\n",
657 ph.current_result->e_total = GNUNET_TIME_absolute_get(); 651 "GAS_OP_SOLVE_STOP",
658 ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference( 652 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
659 ph.current_result->s_total, ph.current_result->e_total); 653 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
660 } 654 {
661 ph.current_result = NULL; 655 /* We do not expect a solution at the moment */
656 GNUNET_break (0);
662 return; 657 return;
658 }
663 659
664 case GAS_OP_SOLVE_SETUP_START: 660 if (GAS_STAT_SUCCESS == stat)
665 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 661 ph.current_result->valid = GNUNET_YES;
666 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", 662 else
667 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 663 ph.current_result->valid = GNUNET_NO;
668 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
669 {
670 GNUNET_break(0);
671 return;
672 }
673 664
674 if (GAS_STAT_SUCCESS == stat) 665 if (NULL != ph.current_result)
675 ph.current_result->valid = GNUNET_YES; 666 {
676 else 667 /* Finalize result */
677 ph.current_result->valid = GNUNET_NO; 668 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
669 ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference (
670 ph.current_result->s_total, ph.current_result->e_total);
671 }
672 ph.current_result = NULL;
673 return;
678 674
679 ph.current_result->s_setup = GNUNET_TIME_absolute_get(); 675 case GAS_OP_SOLVE_SETUP_START:
676 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
677 "Solver notifies `%s' with result `%s'\n",
678 "GAS_OP_SOLVE_SETUP_START",
679 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
680 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
681 {
682 GNUNET_break (0);
680 return; 683 return;
684 }
681 685
682 case GAS_OP_SOLVE_SETUP_STOP: 686 if (GAS_STAT_SUCCESS == stat)
683 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 687 ph.current_result->valid = GNUNET_YES;
684 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", 688 else
685 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 689 ph.current_result->valid = GNUNET_NO;
686 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
687 {
688 GNUNET_break(0);
689 return;
690 }
691 690
692 if (GAS_STAT_SUCCESS == stat) 691 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
693 ph.current_result->valid = GNUNET_YES; 692 return;
694 else
695 ph.current_result->valid = GNUNET_NO;
696 693
697 ph.current_result->e_setup = GNUNET_TIME_absolute_get(); 694 case GAS_OP_SOLVE_SETUP_STOP:
698 ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference( 695 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
699 ph.current_result->s_setup, ph.current_result->e_setup); 696 "Solver notifies `%s' with result `%s'\n",
697 "GAS_OP_SOLVE_SETUP_STOP",
698 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
699 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
700 {
701 GNUNET_break (0);
700 return; 702 return;
703 }
701 704
702 case GAS_OP_SOLVE_MLP_LP_START: 705 if (GAS_STAT_SUCCESS == stat)
703 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 706 ph.current_result->valid = GNUNET_YES;
704 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", 707 else
705 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 708 ph.current_result->valid = GNUNET_NO;
706 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
707 {
708 GNUNET_break(0);
709 return;
710 }
711 709
712 if (GAS_STAT_SUCCESS == stat) 710 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
713 ph.current_result->valid = GNUNET_YES; 711 ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference (
714 else 712 ph.current_result->s_setup, ph.current_result->e_setup);
715 ph.current_result->valid = GNUNET_NO; 713 return;
716 714
717 ph.current_result->s_lp = GNUNET_TIME_absolute_get(); 715 case GAS_OP_SOLVE_MLP_LP_START:
716 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
717 "Solver notifies `%s' with result `%s'\n",
718 "GAS_OP_SOLVE_LP_START",
719 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
720 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
721 {
722 GNUNET_break (0);
718 return; 723 return;
724 }
719 725
720 case GAS_OP_SOLVE_MLP_LP_STOP: 726 if (GAS_STAT_SUCCESS == stat)
721 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 727 ph.current_result->valid = GNUNET_YES;
722 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", 728 else
723 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 729 ph.current_result->valid = GNUNET_NO;
724 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
725 {
726 GNUNET_break(0);
727 return;
728 }
729 730
730 if (GAS_STAT_SUCCESS == stat) 731 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
731 ph.current_result->valid = GNUNET_YES; 732 return;
732 else
733 ph.current_result->valid = GNUNET_NO;
734 733
735 ph.current_result->e_lp = GNUNET_TIME_absolute_get(); 734 case GAS_OP_SOLVE_MLP_LP_STOP:
736 ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference( 735 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
737 ph.current_result->s_lp, ph.current_result->e_lp); 736 "Solver notifies `%s' with result `%s'\n",
737 "GAS_OP_SOLVE_LP_STOP",
738 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
739 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
740 {
741 GNUNET_break (0);
738 return; 742 return;
743 }
739 744
740 case GAS_OP_SOLVE_MLP_MLP_START: 745 if (GAS_STAT_SUCCESS == stat)
741 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 746 ph.current_result->valid = GNUNET_YES;
742 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", 747 else
743 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 748 ph.current_result->valid = GNUNET_NO;
744 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
745 {
746 GNUNET_break(0);
747 return;
748 }
749 749
750 if (GAS_STAT_SUCCESS == stat) 750 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
751 ph.current_result->valid = GNUNET_YES; 751 ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference (
752 else 752 ph.current_result->s_lp, ph.current_result->e_lp);
753 ph.current_result->valid = GNUNET_NO; 753 return;
754 754
755 ph.current_result->s_mlp = GNUNET_TIME_absolute_get(); 755 case GAS_OP_SOLVE_MLP_MLP_START:
756 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
757 "Solver notifies `%s' with result `%s'\n",
758 "GAS_OP_SOLVE_MLP_START",
759 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
760 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
761 {
762 GNUNET_break (0);
756 return; 763 return;
764 }
757 765
758 case GAS_OP_SOLVE_MLP_MLP_STOP: 766 if (GAS_STAT_SUCCESS == stat)
759 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 767 ph.current_result->valid = GNUNET_YES;
760 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", 768 else
761 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 769 ph.current_result->valid = GNUNET_NO;
762 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
763 {
764 GNUNET_break(0);
765 return;
766 }
767 770
768 if (GAS_STAT_SUCCESS == stat) 771 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
769 ph.current_result->valid = GNUNET_YES; 772 return;
770 else
771 ph.current_result->valid = GNUNET_NO;
772 773
773 ph.current_result->e_mlp = GNUNET_TIME_absolute_get(); 774 case GAS_OP_SOLVE_MLP_MLP_STOP:
774 ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference( 775 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
775 ph.current_result->s_mlp, ph.current_result->e_mlp); 776 "Solver notifies `%s' with result `%s'\n",
777 "GAS_OP_SOLVE_MLP_STOP",
778 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
779 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
780 {
781 GNUNET_break (0);
776 return; 782 return;
783 }
777 784
778 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: 785 if (GAS_STAT_SUCCESS == stat)
779 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 786 ph.current_result->valid = GNUNET_YES;
780 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", 787 else
781 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 788 ph.current_result->valid = GNUNET_NO;
782 return;
783 789
784 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: 790 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
785 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 791 ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference (
786 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", 792 ph.current_result->s_mlp, ph.current_result->e_mlp);
787 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 793 return;
788 if (GAS_STAT_SUCCESS != stat)
789 {
790 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
791 "Solver `%s' failed to update problem with %u peers and %u address!\n",
792 ph.ats_string, ph.current_p, ph.current_a);
793 }
794 794
795 return; 795 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
796 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
797 "Solver notifies `%s' with result `%s'\n",
798 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
799 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
800 return;
796 801
797 default: 802 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
798 break; 803 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
804 "Solver notifies `%s' with result `%s'\n",
805 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
806 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
807 if (GAS_STAT_SUCCESS != stat)
808 {
809 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
810 "Solver `%s' failed to update problem with %u peers and %u address!\n",
811 ph.ats_string, ph.current_p, ph.current_a);
799 } 812 }
813
814 return;
815
816 default:
817 break;
818 }
800} 819}
801 820
802/** 821/**
@@ -805,82 +824,86 @@ solver_info_cb(void *cls,
805 * @param iteration the iteration to evaluate 824 * @param iteration the iteration to evaluate
806 */ 825 */
807static void 826static void
808evaluate(int iteration) 827evaluate (int iteration)
809{ 828{
810 struct Result *cur; 829 struct Result *cur;
811 int cp; 830 int cp;
812 831
813 for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp++) 832 for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp++)
833 {
834 cur = ph.iterations_results[ph.current_iteration - 1].results_array[cp];
835 if (0 == cp)
836 continue;
837 if (NULL == cur)
814 { 838 {
815 cur = ph.iterations_results[ph.current_iteration - 1].results_array[cp]; 839 GNUNET_break (0);
816 if (0 == cp) 840 fprintf (stderr,
817 continue; 841 "Missing result for %u peers\n", cp);
818 if (NULL == cur) 842 continue;
819 { 843 }
820 GNUNET_break(0);
821 fprintf(stderr,
822 "Missing result for %u peers\n", cp);
823 continue;
824 }
825 844
826 845
827 if (GNUNET_NO == cur->valid) 846 if (GNUNET_NO == cur->valid)
828 { 847 {
829 fprintf(stderr, 848 fprintf (stderr,
830 "Total time to solve %s for %u peers %u addresses: %s\n", 849 "Total time to solve %s for %u peers %u addresses: %s\n",
831 (GNUNET_YES == cur->update) ? "updated" : "full", 850 (GNUNET_YES == cur->update) ? "updated" : "full",
832 cur->peers, cur->addresses, "Failed to solve!"); 851 cur->peers, cur->addresses, "Failed to solve!");
833 continue; 852 continue;
834 } 853 }
835 854
836 855
837 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total_full.rel_value_us) 856 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
838 { 857 cur->d_total_full.rel_value_us)
839 fprintf(stderr, 858 {
840 "Total time to solve %s for %u peers %u addresses: %llu us\n", 859 fprintf (stderr,
841 (GNUNET_YES == cur->update) ? "updated" : "full", 860 "Total time to solve %s for %u peers %u addresses: %llu us\n",
842 cur->peers, cur->addresses, 861 (GNUNET_YES == cur->update) ? "updated" : "full",
843 (unsigned long long)cur->d_total_full.rel_value_us); 862 cur->peers, cur->addresses,
844 } 863 (unsigned long long) cur->d_total_full.rel_value_us);
864 }
845 865
846 866
847 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup_full.rel_value_us) 867 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
848 { 868 cur->d_setup_full.rel_value_us)
849 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 869 {
850 "Total time to setup %s %u peers %u addresses: %llu us\n", 870 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
851 (GNUNET_YES == cur->update) ? "updated" : "full", 871 "Total time to setup %s %u peers %u addresses: %llu us\n",
852 cur->peers, cur->addresses, 872 (GNUNET_YES == cur->update) ? "updated" : "full",
853 (unsigned long long)cur->d_setup_full.rel_value_us); 873 cur->peers, cur->addresses,
854 } 874 (unsigned long long) cur->d_setup_full.rel_value_us);
875 }
855 876
856 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp_full.rel_value_us) 877 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
857 { 878 cur->d_lp_full.rel_value_us)
858 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 879 {
859 "Total time to solve %s LP for %u peers %u addresses: %llu us\n", 880 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
860 (GNUNET_YES == cur->update) ? "updated" : "full", 881 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
861 cur->peers, 882 (GNUNET_YES == cur->update) ? "updated" : "full",
862 cur->addresses, 883 cur->peers,
863 (unsigned long long )cur->d_lp_full.rel_value_us); 884 cur->addresses,
864 } 885 (unsigned long long ) cur->d_lp_full.rel_value_us);
886 }
865 887
866 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp_full.rel_value_us) 888 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
867 { 889 cur->d_mlp_full.rel_value_us)
868 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 890 {
869 "Total time to solve %s MLP for %u peers %u addresses: %llu us\n", 891 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
870 (GNUNET_YES == cur->update) ? "updated" : "full", 892 "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
871 cur->peers, cur->addresses, 893 (GNUNET_YES == cur->update) ? "updated" : "full",
872 (unsigned long long )cur->d_mlp_full.rel_value_us); 894 cur->peers, cur->addresses,
873 } 895 (unsigned long long ) cur->d_mlp_full.rel_value_us);
874 } 896 }
897 }
875} 898}
876 899
877 900
878static unsigned int 901static unsigned int
879get_connectivity_cb(void *cls, 902get_connectivity_cb (void *cls,
880 const struct GNUNET_PeerIdentity *peer) 903 const struct GNUNET_PeerIdentity *peer)
881{ 904{
882 return GNUNET_CONTAINER_multipeermap_contains(ph.addresses, 905 return GNUNET_CONTAINER_multipeermap_contains (ph.addresses,
883 peer); 906 peer);
884} 907}
885 908
886 909
@@ -888,16 +911,16 @@ get_connectivity_cb(void *cls,
888 * Evaluate average results for all iterations 911 * Evaluate average results for all iterations
889 */ 912 */
890static void 913static void
891write_all_iterations(void) 914write_all_iterations (void)
892{ 915{
893 int c_iteration; 916 int c_iteration;
894 int c_peer; 917 int c_peer;
895 918
896 struct GNUNET_DISK_FileHandle *f_full; 919 struct GNUNET_DISK_FileHandle *f_full;
897 struct GNUNET_DISK_FileHandle *f_update; 920 struct GNUNET_DISK_FileHandle *f_update;
898 char * data_fn_full; 921 char *data_fn_full;
899 char * data_fn_update; 922 char *data_fn_update;
900 char * data; 923 char *data;
901 924
902 f_full = NULL; 925 f_full = NULL;
903 f_update = NULL; 926 f_update = NULL;
@@ -907,179 +930,192 @@ write_all_iterations(void)
907 if (GNUNET_NO == ph.create_datafile) 930 if (GNUNET_NO == ph.create_datafile)
908 return; 931 return;
909 932
910 GNUNET_asprintf(&data_fn_full, 933 GNUNET_asprintf (&data_fn_full,
911 "perf_%s_full_%u-%u_%u_%u.data", 934 "perf_%s_full_%u-%u_%u_%u.data",
912 ph.ats_string, 935 ph.ats_string,
913 ph.total_iterations, 936 ph.total_iterations,
914 ph.N_peers_start, 937 ph.N_peers_start,
915 ph.N_peers_end, 938 ph.N_peers_end,
916 ph.N_address); 939 ph.N_address);
917 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 940 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
918 "Using data file `%s'\n", 941 "Using data file `%s'\n",
919 data_fn_full); 942 data_fn_full);
920 943
921 f_full = GNUNET_DISK_file_open(data_fn_full, 944 f_full = GNUNET_DISK_file_open (data_fn_full,
922 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 945 GNUNET_DISK_OPEN_WRITE
923 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 946 | GNUNET_DISK_OPEN_CREATE,
947 GNUNET_DISK_PERM_USER_EXEC
948 | GNUNET_DISK_PERM_USER_READ
949 | GNUNET_DISK_PERM_USER_WRITE);
924 if (NULL == f_full) 950 if (NULL == f_full)
925 { 951 {
926 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 952 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
927 "Cannot open data file `%s'\n", 953 "Cannot open data file `%s'\n",
928 data_fn_full); 954 data_fn_full);
929 GNUNET_free(data_fn_full); 955 GNUNET_free (data_fn_full);
930 return; 956 return;
931 } 957 }
932 958
933 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; 959 data =
934 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data))) 960 "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
935 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 961 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen (data)))
936 "Cannot write data to log file `%s'\n", 962 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
937 data_fn_full); 963 "Cannot write data to log file `%s'\n",
964 data_fn_full);
938 965
939 data_fn_update = NULL; 966 data_fn_update = NULL;
940 if (GNUNET_YES == ph.measure_updates) 967 if (GNUNET_YES == ph.measure_updates)
968 {
969 GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data",
970 ph.ats_string,
971 ph.total_iterations,
972 ph.N_peers_start,
973 ph.N_peers_end,
974 ph.N_address);
975 f_update = GNUNET_DISK_file_open (data_fn_update,
976 GNUNET_DISK_OPEN_WRITE
977 | GNUNET_DISK_OPEN_CREATE,
978 GNUNET_DISK_PERM_USER_EXEC
979 | GNUNET_DISK_PERM_USER_READ
980 | GNUNET_DISK_PERM_USER_WRITE);
981 if (NULL == f_update)
941 { 982 {
942 GNUNET_asprintf(&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data", 983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
943 ph.ats_string, 984 "Cannot open gnuplot file `%s'\n", data_fn_update);
944 ph.total_iterations, 985 GNUNET_free (data_fn_update);
945 ph.N_peers_start, 986 if (NULL != f_full)
946 ph.N_peers_end, 987 GNUNET_DISK_file_close (f_full);
947 ph.N_address); 988 GNUNET_free (data_fn_full);
948 f_update = GNUNET_DISK_file_open(data_fn_update, 989 return;
949 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 990 }
950 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
951 if (NULL == f_update)
952 {
953 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
954 "Cannot open gnuplot file `%s'\n", data_fn_update);
955 GNUNET_free(data_fn_update);
956 if (NULL != f_full)
957 GNUNET_DISK_file_close(f_full);
958 GNUNET_free(data_fn_full);
959 return;
960 }
961 991
962 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 992 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
963 "Using update data file `%s'\n", 993 "Using update data file `%s'\n",
964 data_fn_update); 994 data_fn_update);
965 995
966 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; 996 data =
967 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_update, data, strlen(data))) 997 "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
968 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 998 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen (data)))
969 "Cannot write data to log file `%s'\n", 999 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
970 data_fn_update); 1000 "Cannot write data to log file `%s'\n",
971 } 1001 data_fn_update);
1002 }
972 1003
973 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer++) 1004 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer++)
1005 {
1006 char *data_str;
1007 char *data_tmp;
1008 char *data_upd_str;
1009 char *data_upd_tmp;
1010 GNUNET_asprintf (&data_str, "%u;%u", c_peer, ph.N_address);
1011 if (ph.measure_updates)
1012 GNUNET_asprintf (&data_upd_str, "%u;%u", c_peer, ph.N_address);
1013 for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration++)
974 { 1014 {
975 char * data_str; 1015 struct Result *cur_full_res;
976 char * data_tmp; 1016 struct Result *cur_upd_res;
977 char * data_upd_str;
978 char * data_upd_tmp;
979 GNUNET_asprintf(&data_str, "%u;%u", c_peer, ph.N_address);
980 if (ph.measure_updates)
981 GNUNET_asprintf(&data_upd_str, "%u;%u", c_peer, ph.N_address);
982 for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration++)
983 {
984 struct Result *cur_full_res;
985 struct Result *cur_upd_res;
986
987
988
989 //fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res);
990 cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer];
991 if (c_peer == 0)
992 continue;
993 if (NULL == cur_full_res)
994 continue;
995
996 if (ph.measure_updates)
997 {
998 cur_upd_res = ph.iterations_results[c_iteration].update_results_array[c_peer];
999 data_upd_tmp = GNUNET_strdup(data_upd_str);
1000 GNUNET_free(data_upd_str);
1001 if (GNUNET_YES == cur_full_res->valid)
1002 {
1003 GNUNET_asprintf(&data_upd_str, "%s;%llu", data_upd_tmp,
1004 (NULL == cur_upd_res) ? 0 : cur_upd_res->d_total_full.rel_value_us);
1005 }
1006 else
1007 {
1008 GNUNET_asprintf(&data_upd_str, "%s;", data_upd_tmp);
1009 }
1010 GNUNET_free(data_upd_tmp);
1011 }
1012
1013 //fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses);
1014 //fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1015
1016 data_tmp = GNUNET_strdup(data_str);
1017 GNUNET_free(data_str);
1018 if (GNUNET_YES == cur_full_res->valid)
1019 {
1020 GNUNET_asprintf(&data_str, "%s;%llu", data_tmp,
1021 cur_full_res->d_total_full.rel_value_us);
1022 }
1023 else
1024 {
1025 GNUNET_asprintf(&data_str, "%s;", data_tmp);
1026 }
1027
1028 GNUNET_free(data_tmp);
1029 }
1030 data_tmp = GNUNET_strdup(data_str);
1031 GNUNET_free(data_str);
1032 GNUNET_asprintf(&data_str, "%s\n", data_tmp);
1033 GNUNET_free(data_tmp);
1034 1017
1035 fprintf(stderr, "Result full solution: %s\n", data_str); 1018
1036 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data_str, strlen(data_str))) 1019
1037 GNUNET_break(0); 1020 // fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res);
1038 GNUNET_free(data_str); 1021 cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer];
1022 if (c_peer == 0)
1023 continue;
1024 if (NULL == cur_full_res)
1025 continue;
1039 1026
1040 if (ph.measure_updates) 1027 if (ph.measure_updates)
1028 {
1029 cur_upd_res =
1030 ph.iterations_results[c_iteration].update_results_array[c_peer];
1031 data_upd_tmp = GNUNET_strdup (data_upd_str);
1032 GNUNET_free (data_upd_str);
1033 if (GNUNET_YES == cur_full_res->valid)
1041 { 1034 {
1042 data_upd_tmp = GNUNET_strdup(data_upd_str); 1035 GNUNET_asprintf (&data_upd_str, "%s;%llu", data_upd_tmp,
1043 GNUNET_free(data_upd_str); 1036 (NULL == cur_upd_res) ? 0 :
1044 GNUNET_asprintf(&data_upd_str, "%s\n", data_upd_tmp); 1037 cur_upd_res->d_total_full.rel_value_us);
1045 GNUNET_free(data_upd_tmp);
1046
1047 fprintf(stderr, "Result updated solution: `%s'\n", data_upd_str);
1048 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_update, data_upd_str, strlen(data_upd_str)))
1049 GNUNET_break(0);
1050 GNUNET_free(data_upd_str);
1051 } 1038 }
1052 } 1039 else
1053 1040 {
1054 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close(f_full))) 1041 GNUNET_asprintf (&data_upd_str, "%s;", data_upd_tmp);
1055 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", 1042 }
1056 data_fn_full); 1043 GNUNET_free (data_upd_tmp);
1057 GNUNET_free_non_null(data_fn_full); 1044 }
1045
1046 // fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses);
1047 // fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1048
1049 data_tmp = GNUNET_strdup (data_str);
1050 GNUNET_free (data_str);
1051 if (GNUNET_YES == cur_full_res->valid)
1052 {
1053 GNUNET_asprintf (&data_str, "%s;%llu", data_tmp,
1054 cur_full_res->d_total_full.rel_value_us);
1055 }
1056 else
1057 {
1058 GNUNET_asprintf (&data_str, "%s;", data_tmp);
1059 }
1058 1060
1059 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close(f_update))) 1061 GNUNET_free (data_tmp);
1060 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", 1062 }
1061 data_fn_update); 1063 data_tmp = GNUNET_strdup (data_str);
1062 GNUNET_free_non_null(data_fn_update); 1064 GNUNET_free (data_str);
1065 GNUNET_asprintf (&data_str, "%s\n", data_tmp);
1066 GNUNET_free (data_tmp);
1067
1068 fprintf (stderr, "Result full solution: %s\n", data_str);
1069 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data_str, strlen (
1070 data_str)))
1071 GNUNET_break (0);
1072 GNUNET_free (data_str);
1073
1074 if (ph.measure_updates)
1075 {
1076 data_upd_tmp = GNUNET_strdup (data_upd_str);
1077 GNUNET_free (data_upd_str);
1078 GNUNET_asprintf (&data_upd_str, "%s\n", data_upd_tmp);
1079 GNUNET_free (data_upd_tmp);
1080
1081 fprintf (stderr, "Result updated solution: `%s'\n", data_upd_str);
1082 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data_upd_str,
1083 strlen (data_upd_str)))
1084 GNUNET_break (0);
1085 GNUNET_free (data_upd_str);
1086 }
1087 }
1088
1089 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1090 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1091 data_fn_full);
1092 GNUNET_free_non_null (data_fn_full);
1093
1094 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (
1095 f_update)))
1096 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1097 data_fn_update);
1098 GNUNET_free_non_null (data_fn_update);
1063} 1099}
1064 1100
1065 1101
1066static int 1102static int
1067do_delete_address(void *cls, 1103do_delete_address (void *cls,
1068 const struct GNUNET_PeerIdentity *pid, 1104 const struct GNUNET_PeerIdentity *pid,
1069 void *value) 1105 void *value)
1070{ 1106{
1071 struct ATS_Address *cur = value; 1107 struct ATS_Address *cur = value;
1072 1108
1073 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1074 "Deleting addresses for peer %u\n", 1110 "Deleting addresses for peer %u\n",
1075 pid); 1111 pid);
1076 GNUNET_assert(GNUNET_OK == 1112 GNUNET_assert (GNUNET_OK ==
1077 GNUNET_CONTAINER_multipeermap_remove(ph.addresses, 1113 GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1078 pid, 1114 pid,
1079 cur)); 1115 cur));
1080 ph.sf->s_del(ph.sf->cls, cur); 1116 ph.sf->s_del (ph.sf->cls, cur);
1081 GNUNET_free_non_null(cur->atsi); 1117 GNUNET_free_non_null (cur->atsi);
1082 GNUNET_free(cur); 1118 GNUNET_free (cur);
1083 return GNUNET_OK; 1119 return GNUNET_OK;
1084} 1120}
1085 1121
@@ -1088,134 +1124,139 @@ do_delete_address(void *cls,
1088 * Run a performance iteration 1124 * Run a performance iteration
1089 */ 1125 */
1090static void 1126static void
1091perf_run_iteration(void) 1127perf_run_iteration (void)
1092{ 1128{
1093 int cp; 1129 int cp;
1094 int ca; 1130 int ca;
1095 int count_p = ph.N_peers_end; 1131 int count_p = ph.N_peers_end;
1096 int count_a = ph.N_address; 1132 int count_a = ph.N_address;
1097 struct ATS_Address * cur_addr; 1133 struct ATS_Address *cur_addr;
1098 uint32_t net; 1134 uint32_t net;
1099 1135
1100 ph.iterations_results[ph.current_iteration - 1].results_array = GNUNET_malloc((count_p + 1) * sizeof(struct Result *)); 1136 ph.iterations_results[ph.current_iteration - 1].results_array =
1137 GNUNET_malloc ((count_p + 1) * sizeof(struct Result *));
1101 if (ph.measure_updates) 1138 if (ph.measure_updates)
1102 ph.iterations_results[ph.current_iteration - 1].update_results_array = GNUNET_malloc((count_p + 1) * sizeof(struct Result *)); 1139 ph.iterations_results[ph.current_iteration - 1].update_results_array =
1103 ph.peers = GNUNET_malloc((count_p) * sizeof(struct PerfPeer)); 1140 GNUNET_malloc ((count_p + 1) * sizeof(struct Result *));
1141 ph.peers = GNUNET_malloc ((count_p) * sizeof(struct PerfPeer));
1104 for (cp = 0; cp < count_p; cp++) 1142 for (cp = 0; cp < count_p; cp++)
1105 perf_create_peer(cp); 1143 perf_create_peer (cp);
1106 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1144 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1107 "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp); 1145 "Iteration %u of %u, added %u peers\n", ph.current_iteration,
1146 ph.total_iterations, cp);
1108 1147
1109 for (cp = 0; cp < count_p; cp++) 1148 for (cp = 0; cp < count_p; cp++)
1149 {
1150 fprintf (stderr, "%u..", cp);
1151 if (GNUNET_NO == ph.bulk_running)
1110 { 1152 {
1111 fprintf(stderr, "%u..", cp); 1153 ph.bulk_running = GNUNET_YES;
1112 if (GNUNET_NO == ph.bulk_running) 1154 ph.sf->s_bulk_start (ph.sf->cls);
1113 {
1114 ph.bulk_running = GNUNET_YES;
1115 ph.sf->s_bulk_start(ph.sf->cls);
1116 }
1117 ph.current_p = cp + 1;
1118 for (ca = 0; ca < count_a; ca++)
1119 {
1120 cur_addr = perf_create_address(cp, ca);
1121 /* Add address */
1122
1123 /* Random network selection */
1124 //net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_NT_COUNT - 1);
1125 /* Random equally distributed network selection */
1126 net = 1 + (ca % (GNUNET_NT_COUNT - 1));
1127 /* fprintf (stderr, "Network: %u `%s'\n",
1128 * mod_net , GNUNET_NT_to_string(mod_net)); */
1129
1130 cur_addr->atsi = GNUNET_new(struct GNUNET_ATS_Information);
1131 cur_addr->atsi_count = 1;
1132 cur_addr->atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE);
1133 cur_addr->atsi[0].value = htonl(net);
1134 ph.sf->s_add(ph.sf->cls, cur_addr, net);
1135
1136 ph.current_a = ca + 1;
1137 perf_address_initial_update(NULL, ph.addresses, cur_addr);
1138 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1139 "Adding address for peer %u address %u in network %s\n", cp, ca,
1140 GNUNET_NT_to_string(net));
1141 }
1142 /* Notify solver about request */
1143 ph.sf->s_get(ph.sf->cls, &ph.peers[cp].id);
1144
1145 if (cp + 1 >= ph.N_peers_start)
1146 {
1147 /* Disable bulk to solve the problem */
1148 if (GNUNET_YES == ph.bulk_running)
1149 {
1150 ph.expecting_solution = GNUNET_YES;
1151 ph.bulk_running = GNUNET_NO;
1152 ph.sf->s_bulk_stop(ph.sf->cls);
1153 }
1154 else
1155 GNUNET_break(0);
1156
1157 /* Problem is solved by the solver here due to unlocking */
1158 ph.expecting_solution = GNUNET_NO;
1159
1160 /* Update the problem */
1161 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1162 {
1163 /* Update */
1164 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1165 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
1166
1167 ph.expecting_solution = GNUNET_YES;
1168 ph.performed_update = GNUNET_YES;
1169 if (GNUNET_NO == ph.bulk_running)
1170 {
1171 ph.bulk_running = GNUNET_YES;
1172 ph.sf->s_bulk_start(ph.sf->cls);
1173 }
1174 perf_update_all_addresses(cp + 1, ca, ph.opt_update_percent);
1175 ph.bulk_running = GNUNET_NO;
1176 ph.sf->s_bulk_stop(ph.sf->cls);
1177 /* Problem is solved by the solver here due to unlocking */
1178 ph.performed_update = GNUNET_NO;
1179 ph.expecting_solution = GNUNET_NO;
1180 }
1181 GNUNET_assert(GNUNET_NO == ph.bulk_running);
1182 }
1183 } 1155 }
1184 fprintf(stderr, "\n"); 1156 ph.current_p = cp + 1;
1185 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1157 for (ca = 0; ca < count_a; ca++)
1186 "Done, cleaning up addresses\n");
1187 if (GNUNET_NO == ph.bulk_running)
1188 { 1158 {
1189 ph.sf->s_bulk_start(ph.sf->cls); 1159 cur_addr = perf_create_address (cp, ca);
1190 ph.bulk_running = GNUNET_YES; 1160 /* Add address */
1161
1162 /* Random network selection */
1163 // net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_NT_COUNT - 1);
1164 /* Random equally distributed network selection */
1165 net = 1 + (ca % (GNUNET_NT_COUNT - 1));
1166 /* fprintf (stderr, "Network: %u `%s'\n",
1167 * mod_net , GNUNET_NT_to_string(mod_net)); */
1168
1169 cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information);
1170 cur_addr->atsi_count = 1;
1171 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1172 cur_addr->atsi[0].value = htonl (net);
1173 ph.sf->s_add (ph.sf->cls, cur_addr, net);
1174
1175 ph.current_a = ca + 1;
1176 perf_address_initial_update (NULL, ph.addresses, cur_addr);
1177 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1178 "Adding address for peer %u address %u in network %s\n", cp,
1179 ca,
1180 GNUNET_NT_to_string (net));
1191 } 1181 }
1182 /* Notify solver about request */
1183 ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
1192 1184
1193 for (cp = 0; cp < count_p; cp++) 1185 if (cp + 1 >= ph.N_peers_start)
1194 { 1186 {
1195 GNUNET_CONTAINER_multipeermap_get_multiple(ph.addresses, 1187 /* Disable bulk to solve the problem */
1196 &ph.peers[cp].id, 1188 if (GNUNET_YES == ph.bulk_running)
1197 &do_delete_address, 1189 {
1198 NULL); 1190 ph.expecting_solution = GNUNET_YES;
1191 ph.bulk_running = GNUNET_NO;
1192 ph.sf->s_bulk_stop (ph.sf->cls);
1193 }
1194 else
1195 GNUNET_break (0);
1196
1197 /* Problem is solved by the solver here due to unlocking */
1198 ph.expecting_solution = GNUNET_NO;
1199
1200 /* Update the problem */
1201 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1202 {
1203 /* Update */
1204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1205 "Updating problem with %u peers and %u addresses\n", cp + 1,
1206 ca);
1207
1208 ph.expecting_solution = GNUNET_YES;
1209 ph.performed_update = GNUNET_YES;
1210 if (GNUNET_NO == ph.bulk_running)
1211 {
1212 ph.bulk_running = GNUNET_YES;
1213 ph.sf->s_bulk_start (ph.sf->cls);
1214 }
1215 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1216 ph.bulk_running = GNUNET_NO;
1217 ph.sf->s_bulk_stop (ph.sf->cls);
1218 /* Problem is solved by the solver here due to unlocking */
1219 ph.performed_update = GNUNET_NO;
1220 ph.expecting_solution = GNUNET_NO;
1221 }
1222 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1199 } 1223 }
1224 }
1225 fprintf (stderr, "\n");
1226 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1227 "Done, cleaning up addresses\n");
1200 if (GNUNET_NO == ph.bulk_running) 1228 if (GNUNET_NO == ph.bulk_running)
1201 { 1229 {
1202 ph.sf->s_bulk_stop(ph.sf->cls); 1230 ph.sf->s_bulk_start (ph.sf->cls);
1203 ph.bulk_running = GNUNET_NO; 1231 ph.bulk_running = GNUNET_YES;
1204 } 1232 }
1205 1233
1206 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1234 for (cp = 0; cp < count_p; cp++)
1207 "Iteration done\n"); 1235 {
1208 GNUNET_free(ph.peers); 1236 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
1237 &ph.peers[cp].id,
1238 &do_delete_address,
1239 NULL);
1240 }
1241 if (GNUNET_NO == ph.bulk_running)
1242 {
1243 ph.sf->s_bulk_stop (ph.sf->cls);
1244 ph.bulk_running = GNUNET_NO;
1245 }
1246
1247 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1248 "Iteration done\n");
1249 GNUNET_free (ph.peers);
1209} 1250}
1210 1251
1211 1252
1212static void 1253static void
1213run(void *cls, char * const *args, const char *cfgfile, 1254run (void *cls, char *const *args, const char *cfgfile,
1214 const struct GNUNET_CONFIGURATION_Handle *cfg) 1255 const struct GNUNET_CONFIGURATION_Handle *cfg)
1215{ 1256{
1216 GNUNET_log_setup("perf-ats-solver", "WARNING", NULL); 1257 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1217 char *sep; 1258 char *sep;
1218 char *src_filename = GNUNET_strdup(__FILE__); 1259 char *src_filename = GNUNET_strdup (__FILE__);
1219 char *test_filename = cls; 1260 char *test_filename = cls;
1220 char *solver; 1261 char *solver;
1221 char *plugin; 1262 char *plugin;
@@ -1226,92 +1267,98 @@ run(void *cls, char * const *args, const char *cfgfile,
1226 int c2; 1267 int c2;
1227 1268
1228 /* Extract test name */ 1269 /* Extract test name */
1229 if (NULL == (sep = (strstr(src_filename, ".c")))) 1270 if (NULL == (sep = (strstr (src_filename, ".c"))))
1230 { 1271 {
1231 GNUNET_free(src_filename); 1272 GNUNET_free (src_filename);
1232 GNUNET_break(0); 1273 GNUNET_break (0);
1233 ret = 1; 1274 ret = 1;
1234 return; 1275 return;
1235 } 1276 }
1236 sep[0] = '\0'; 1277 sep[0] = '\0';
1237 1278
1238 if (NULL != (sep = strstr(test_filename, ".exe"))) 1279 if (NULL != (sep = strstr (test_filename, ".exe")))
1239 sep[0] = '\0'; 1280 sep[0] = '\0';
1240 1281
1241 if (NULL == (solver = strstr(test_filename, src_filename))) 1282 if (NULL == (solver = strstr (test_filename, src_filename)))
1242 { 1283 {
1243 GNUNET_free(src_filename); 1284 GNUNET_free (src_filename);
1244 GNUNET_break(0); 1285 GNUNET_break (0);
1245 ret = 1; 1286 ret = 1;
1246 return; 1287 return;
1247 } 1288 }
1248 solver += strlen(src_filename) + 1; 1289 solver += strlen (src_filename) + 1;
1249 1290
1250 if (0 == strcmp(solver, "proportional")) 1291 if (0 == strcmp (solver, "proportional"))
1251 { 1292 {
1252 ph.ats_string = "proportional"; 1293 ph.ats_string = "proportional";
1253 } 1294 }
1254 else if (0 == strcmp(solver, "mlp")) 1295 else if (0 == strcmp (solver, "mlp"))
1255 { 1296 {
1256 ph.ats_string = "mlp"; 1297 ph.ats_string = "mlp";
1257 } 1298 }
1258 else if ((0 == strcmp(solver, "ril"))) 1299 else if ((0 == strcmp (solver, "ril")))
1259 { 1300 {
1260 ph.ats_string = "ril"; 1301 ph.ats_string = "ril";
1261 } 1302 }
1262 else 1303 else
1263 { 1304 {
1264 GNUNET_free(src_filename); 1305 GNUNET_free (src_filename);
1265 GNUNET_break(0); 1306 GNUNET_break (0);
1266 ret = 1; 1307 ret = 1;
1267 return; 1308 return;
1268 } 1309 }
1269 GNUNET_free(src_filename); 1310 GNUNET_free (src_filename);
1270 1311
1271 /* Calculcate peers */ 1312 /* Calculcate peers */
1272 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end)) 1313 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1273 { 1314 {
1274 ph.N_peers_start = DEFAULT_PEERS_START; 1315 ph.N_peers_start = DEFAULT_PEERS_START;
1275 ph.N_peers_end = DEFAULT_PEERS_END; 1316 ph.N_peers_end = DEFAULT_PEERS_END;
1276 } 1317 }
1277 if (0 == ph.N_address) 1318 if (0 == ph.N_address)
1278 ph.N_address = DEFAULT_ADDRESSES; 1319 ph.N_address = DEFAULT_ADDRESSES;
1279 1320
1280 1321
1281 if (ph.N_peers_start != ph.N_peers_end) 1322 if (ph.N_peers_start != ph.N_peers_end)
1282 fprintf(stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n", 1323 fprintf (stderr,
1283 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations); 1324 "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1325 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address,
1326 ph.total_iterations);
1284 else 1327 else
1285 fprintf(stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n", 1328 fprintf (stderr,
1286 ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations); 1329 "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1330 ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations);
1287 1331
1288 if (0 == ph.opt_update_percent) 1332 if (0 == ph.opt_update_percent)
1289 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE; 1333 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1290 1334
1291 /* Load quotas */ 1335 /* Load quotas */
1292 solver_cfg = GNUNET_CONFIGURATION_create(); 1336 solver_cfg = GNUNET_CONFIGURATION_create ();
1293 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load(solver_cfg, "perf_ats_solver.conf")))) 1337 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load (
1294 { 1338 solver_cfg,
1295 GNUNET_break(0); 1339 "perf_ats_solver.conf"))))
1296 end_now(1); 1340 {
1297 return; 1341 GNUNET_break (0);
1298 } 1342 end_now (1);
1299 if (GNUNET_NT_COUNT != load_quotas(solver_cfg, 1343 return;
1300 quotas_out, quotas_in, GNUNET_NT_COUNT)) 1344 }
1301 { 1345 if (GNUNET_NT_COUNT != load_quotas (solver_cfg,
1302 GNUNET_break(0); 1346 quotas_out, quotas_in, GNUNET_NT_COUNT))
1303 end_now(1); 1347 {
1304 return; 1348 GNUNET_break (0);
1305 } 1349 end_now (1);
1350 return;
1351 }
1306 1352
1307 /* Create array of DLL to store results for iterations */ 1353 /* Create array of DLL to store results for iterations */
1308 ph.iterations_results = GNUNET_malloc(sizeof(struct Iteration) * ph.total_iterations); 1354 ph.iterations_results = GNUNET_malloc (sizeof(struct Iteration)
1355 * ph.total_iterations);
1309 1356
1310 /* Load solver */ 1357 /* Load solver */
1311 ph.env.cfg = solver_cfg; 1358 ph.env.cfg = solver_cfg;
1312 ph.stat = GNUNET_STATISTICS_create("ats", cfg); 1359 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1313 ph.env.stats = ph.stat; 1360 ph.env.stats = ph.stat;
1314 ph.addresses = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_NO); 1361 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1315 ph.env.addresses = ph.addresses; 1362 ph.env.addresses = ph.addresses;
1316 ph.env.bandwidth_changed_cb = bandwidth_changed_cb; 1363 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1317 ph.env.get_connectivity = &get_connectivity_cb; 1364 ph.env.get_connectivity = &get_connectivity_cb;
@@ -1320,75 +1367,77 @@ run(void *cls, char * const *args, const char *cfgfile,
1320 ph.env.info_cb = &solver_info_cb; 1367 ph.env.info_cb = &solver_info_cb;
1321 1368
1322 for (c = 0; c < GNUNET_NT_COUNT; c++) 1369 for (c = 0; c < GNUNET_NT_COUNT; c++)
1323 { 1370 {
1324 ph.env.out_quota[c] = quotas_out[c]; 1371 ph.env.out_quota[c] = quotas_out[c];
1325 ph.env.in_quota[c] = quotas_in[c]; 1372 ph.env.in_quota[c] = quotas_in[c];
1326 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1373 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1327 "Loading network quotas: `%s' %llu %llu \n", 1374 "Loading network quotas: `%s' %llu %llu \n",
1328 GNUNET_NT_to_string(c), 1375 GNUNET_NT_to_string (c),
1329 ph.env.out_quota[c], 1376 ph.env.out_quota[c],
1330 ph.env.in_quota[c]); 1377 ph.env.in_quota[c]);
1331 } 1378 }
1332 GAS_normalization_start(); 1379 GAS_normalization_start ();
1333 GAS_preference_init(); 1380 GAS_preference_init ();
1334 1381
1335 GNUNET_asprintf(&plugin, 1382 GNUNET_asprintf (&plugin,
1336 "libgnunet_plugin_ats_%s", 1383 "libgnunet_plugin_ats_%s",
1337 ph.ats_string); 1384 ph.ats_string);
1338 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1385 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1339 _("Initializing solver `%s'\n"), 1386 _ ("Initializing solver `%s'\n"),
1340 ph.ats_string); 1387 ph.ats_string);
1341 if (NULL == (ph.sf = GNUNET_PLUGIN_load(plugin, &ph.env))) 1388 if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
1342 { 1389 {
1343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1344 _("Failed to initialize solver `%s'!\n"), 1391 _ ("Failed to initialize solver `%s'!\n"),
1345 plugin); 1392 plugin);
1346 ret = 1; 1393 ret = 1;
1347 return; 1394 return;
1348 } 1395 }
1349 1396
1350 /* Do the benchmark */ 1397 /* Do the benchmark */
1351 for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++) 1398 for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations;
1352 { 1399 ph.current_iteration++)
1353 fprintf(stderr, 1400 {
1354 "Iteration %u of %u starting\n", 1401 fprintf (stderr,
1355 ph.current_iteration, 1402 "Iteration %u of %u starting\n",
1356 ph.total_iterations); 1403 ph.current_iteration,
1357 perf_run_iteration(); 1404 ph.total_iterations);
1358 evaluate(ph.current_iteration); 1405 perf_run_iteration ();
1359 fprintf(stderr, 1406 evaluate (ph.current_iteration);
1360 "Iteration %u of %u done\n", 1407 fprintf (stderr,
1361 ph.current_iteration, 1408 "Iteration %u of %u done\n",
1362 ph.total_iterations); 1409 ph.current_iteration,
1363 } 1410 ph.total_iterations);
1411 }
1364 if (ph.create_datafile) 1412 if (ph.create_datafile)
1365 write_all_iterations(); 1413 write_all_iterations ();
1366 1414
1367 /* Unload solver*/ 1415 /* Unload solver*/
1368 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1416 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1369 _("Unloading solver `%s'\n"), 1417 _ ("Unloading solver `%s'\n"),
1370 ph.ats_string); 1418 ph.ats_string);
1371 GNUNET_PLUGIN_unload(plugin, ph.sf); 1419 GNUNET_PLUGIN_unload (plugin, ph.sf);
1372 ph.sf = NULL; 1420 ph.sf = NULL;
1373 GNUNET_free(plugin); 1421 GNUNET_free (plugin);
1374 for (c = 0; c < ph.total_iterations; c++) 1422 for (c = 0; c < ph.total_iterations; c++)
1423 {
1424 for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++)
1375 { 1425 {
1376 for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++) 1426 if (0 == c2)
1377 { 1427 continue;
1378 if (0 == c2)
1379 continue;
1380 if (ph.measure_updates)
1381 GNUNET_free_non_null(ph.iterations_results[c].update_results_array[c2]);
1382 GNUNET_free(ph.iterations_results[c].results_array[c2]);
1383 }
1384 if (ph.measure_updates) 1428 if (ph.measure_updates)
1385 GNUNET_free(ph.iterations_results[c].update_results_array); 1429 GNUNET_free_non_null (
1386 GNUNET_free(ph.iterations_results[c].results_array); 1430 ph.iterations_results[c].update_results_array[c2]);
1431 GNUNET_free (ph.iterations_results[c].results_array[c2]);
1387 } 1432 }
1388 GNUNET_free(ph.iterations_results); 1433 if (ph.measure_updates)
1389 1434 GNUNET_free (ph.iterations_results[c].update_results_array);
1390 GNUNET_CONFIGURATION_destroy(solver_cfg); 1435 GNUNET_free (ph.iterations_results[c].results_array);
1391 GNUNET_STATISTICS_destroy(ph.stat, GNUNET_NO); 1436 }
1437 GNUNET_free (ph.iterations_results);
1438
1439 GNUNET_CONFIGURATION_destroy (solver_cfg);
1440 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1392} 1441}
1393 1442
1394 1443
@@ -1399,7 +1448,7 @@ run(void *cls, char * const *args, const char *cfgfile,
1399 * @param argv argument values 1448 * @param argv argument values
1400 */ 1449 */
1401int 1450int
1402main(int argc, char *argv[]) 1451main (int argc, char *argv[])
1403{ 1452{
1404 /* extract command line arguments */ 1453 /* extract command line arguments */
1405 ph.opt_update_percent = 0; 1454 ph.opt_update_percent = 0;
@@ -1412,45 +1461,47 @@ main(int argc, char *argv[])
1412 ph.total_iterations = 1; 1461 ph.total_iterations = 1;
1413 1462
1414 static struct GNUNET_GETOPT_CommandLineOption options[] = { 1463 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1415 GNUNET_GETOPT_option_uint('a', 1464 GNUNET_GETOPT_option_uint ('a',
1416 "addresses", 1465 "addresses",
1417 gettext_noop("addresses to use"), 1466 gettext_noop ("addresses to use"),
1418 &ph.N_address), 1467 &ph.N_address),
1419 1468
1420 GNUNET_GETOPT_option_uint('s', 1469 GNUNET_GETOPT_option_uint ('s',
1421 "start", 1470 "start",
1422 gettext_noop("start with peer"), 1471 gettext_noop ("start with peer"),
1423 &ph.N_peers_start), 1472 &ph.N_peers_start),
1424 1473
1425 GNUNET_GETOPT_option_uint('e', 1474 GNUNET_GETOPT_option_uint ('e',
1426 "end", 1475 "end",
1427 gettext_noop("end with peer"), 1476 gettext_noop ("end with peer"),
1428 &ph.N_peers_end), 1477 &ph.N_peers_end),
1429 1478
1430 GNUNET_GETOPT_option_uint('i', 1479 GNUNET_GETOPT_option_uint ('i',
1431 "iterations", 1480 "iterations",
1432 gettext_noop("number of iterations used for averaging (default: 1)"), 1481 gettext_noop (
1433 &ph.total_iterations), 1482 "number of iterations used for averaging (default: 1)"),
1434 1483 &ph.total_iterations),
1435 GNUNET_GETOPT_option_uint('p', 1484
1436 "percentage", 1485 GNUNET_GETOPT_option_uint ('p',
1437 gettext_noop("update a fix percentage of addresses"), 1486 "percentage",
1438 &ph.opt_update_percent), 1487 gettext_noop (
1439 1488 "update a fix percentage of addresses"),
1440 GNUNET_GETOPT_option_flag('d', 1489 &ph.opt_update_percent),
1441 "data", 1490
1442 gettext_noop("create data file"), 1491 GNUNET_GETOPT_option_flag ('d',
1443 &ph.create_datafile), 1492 "data",
1444 1493 gettext_noop ("create data file"),
1445 GNUNET_GETOPT_option_flag('u', 1494 &ph.create_datafile),
1446 "update", 1495
1447 gettext_noop("measure updates"), 1496 GNUNET_GETOPT_option_flag ('u',
1448 &ph.measure_updates), 1497 "update",
1498 gettext_noop ("measure updates"),
1499 &ph.measure_updates),
1449 1500
1450 GNUNET_GETOPT_OPTION_END 1501 GNUNET_GETOPT_OPTION_END
1451 }; 1502 };
1452 1503
1453 GNUNET_PROGRAM_run(argc, argv, argv[0], NULL, options, &run, argv[0]); 1504 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1454 return ret; 1505 return ret;
1455} 1506}
1456 1507