aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-02-07 17:25:36 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-02-07 17:25:36 +0000
commit952ca72d5735f0acf3ad5f43f3570e5db3892003 (patch)
tree05e225462f46d3cb506c98083f6cc636b57aad62 /src/ats
parent4bd372001299fd08dc0d5a44ceae04f9102be0f0 (diff)
downloadgnunet-952ca72d5735f0acf3ad5f43f3570e5db3892003.tar.gz
gnunet-952ca72d5735f0acf3ad5f43f3570e5db3892003.zip
experiment loading complete
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-ats-solver-eval.c349
-rw-r--r--src/ats/gnunet-ats-solver-eval.h2
2 files changed, 313 insertions, 38 deletions
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c
index bf032ebb4..e59381cdd 100644
--- a/src/ats/gnunet-ats-solver-eval.c
+++ b/src/ats/gnunet-ats-solver-eval.c
@@ -307,6 +307,18 @@ load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
307 return GNUNET_OK; 307 return GNUNET_OK;
308} 308}
309 309
310static enum GNUNET_ATS_Property
311parse_preference_string (const char * str)
312{
313 int c = 0;
314 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
315
316 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
317 if (0 == strcmp(str, props[c]))
318 return c;
319 return 0;
320};
321
310static int 322static int
311load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, 323load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
312 struct Episode *e, 324 struct Episode *e,
@@ -441,29 +453,24 @@ load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
441 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n", 453 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
442 op_counter, op_name, e->id); 454 op_counter, op_name, e->id);
443 GNUNET_free (op_name); 455 GNUNET_free (op_name);
444 GNUNET_free_non_null (pref);
445 return GNUNET_SYSERR; 456 return GNUNET_SYSERR;
446 } 457 }
447 458
448 if (0 == strcmp(pref, "bandwidth")) 459 if (0 == (o->pref_type = parse_preference_string(pref)))
449 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
450 else if (0 == strcmp(pref, "latency"))
451 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
452 else
453 { 460 {
454 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n", 461 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
455 op_counter, op_name, e->id); 462 op_counter, op_name, e->id);
456 GNUNET_free (op_name); 463 GNUNET_free (op_name);
457 GNUNET_free (pref); 464 GNUNET_free (pref);
458 GNUNET_free_non_null (pref);
459 return GNUNET_SYSERR; 465 return GNUNET_SYSERR;
460 } 466 }
461 GNUNET_free (pref); 467 GNUNET_free (pref);
462 GNUNET_free (op_name); 468 GNUNET_free (op_name);
463 469
464 fprintf (stderr, 470 fprintf (stderr,
465 "Found operation %s: [%llu:%llu] %llu\n", 471 "Found operation %s: [%llu:%llu]: %s = %llu\n",
466 "START_SET_PREFERENCE", o->peer_id, o->address_id, o->base_rate); 472 "START_SET_PREFERENCE", o->peer_id, o->address_id,
473 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
467 474
468 return GNUNET_OK; 475 return GNUNET_OK;
469} 476}
@@ -510,28 +517,263 @@ load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
510 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n", 517 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
511 op_counter, "STOP_SET_PREFERENCE", op_name); 518 op_counter, "STOP_SET_PREFERENCE", op_name);
512 GNUNET_free (op_name); 519 GNUNET_free (op_name);
513 GNUNET_free_non_null (pref);
514 return GNUNET_SYSERR; 520 return GNUNET_SYSERR;
515 } 521 }
516 522
517 if (0 == strcmp(pref, "bandwidth")) 523 if (0 == (o->pref_type = parse_preference_string(pref)))
518 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
519 else if (0 == strcmp(pref, "latency"))
520 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
521 else
522 { 524 {
523 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n", 525 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
524 op_counter, op_name, e->id); 526 op_counter, op_name, e->id);
525 GNUNET_free (op_name); 527 GNUNET_free (op_name);
526 GNUNET_free (pref); 528 GNUNET_free (pref);
527 GNUNET_free_non_null (pref);
528 return GNUNET_SYSERR; 529 return GNUNET_SYSERR;
529 } 530 }
530 GNUNET_free (pref); 531 GNUNET_free (pref);
531 GNUNET_free (op_name); 532 GNUNET_free (op_name);
533
534 fprintf (stderr,
535 "Found operation %s: [%llu:%llu]: %s\n",
536 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
537 GNUNET_ATS_print_preference_type(o->pref_type));
532 return GNUNET_OK; 538 return GNUNET_OK;
533} 539}
534 540
541static enum GNUNET_ATS_Property
542parse_property_string (const char * str)
543{
544 int c = 0;
545 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
546
547 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
548 if (0 == strcmp(str, props[c]))
549 return c;
550 return 0;
551};
552
553static int
554load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
555 struct Episode *e,
556 int op_counter,
557 char *sec_name,
558 const struct GNUNET_CONFIGURATION_Handle *cfg)
559{
560 char *op_name;
561 char *type;
562 char *prop;
563
564 /* peer id */
565 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
566 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
567 sec_name, op_name, &o->peer_id))
568 {
569 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
570 op_counter, "START_SET_PROPERTY", op_name);
571 GNUNET_free (op_name);
572 return GNUNET_SYSERR;
573 }
574 GNUNET_free (op_name);
575
576 /* address id */
577 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
578 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
579 sec_name, op_name, &o->address_id))
580 {
581 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
582 op_counter, "START_SET_PROPERTY", op_name);
583 GNUNET_free (op_name);
584 return GNUNET_SYSERR;
585 }
586 GNUNET_free (op_name);
587
588 /* generator */
589 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
590 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
591 sec_name, op_name, &type)) )
592 {
593 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
594 op_counter, "START_SET_PROPERTY", op_name);
595 GNUNET_free (op_name);
596 return GNUNET_SYSERR;
597 }
598
599 /* Load arguments for set_rate, start_send, set_preference */
600 if (0 == strcmp (type, "constant"))
601 {
602 o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT;
603 }
604 else if (0 == strcmp (type, "linear"))
605 {
606 o->tg_type = GNUNET_ATS_TEST_TG_LINEAR;
607 }
608 else if (0 == strcmp (type, "sinus"))
609 {
610 o->tg_type = GNUNET_ATS_TEST_TG_SINUS;
611 }
612 else if (0 == strcmp (type, "random"))
613 {
614 o->tg_type = GNUNET_ATS_TEST_TG_RANDOM;
615 }
616 else
617 {
618 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
619 op_counter, op_name, e->id);
620 GNUNET_free (type);
621 GNUNET_free (op_name);
622 return GNUNET_SYSERR;
623 }
624 GNUNET_free (type);
625 GNUNET_free (op_name);
626
627
628 /* Get base rate */
629 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
630 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
631 sec_name, op_name, &o->base_rate))
632 {
633 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
634 op_counter, op_name, e->id);
635 GNUNET_free (op_name);
636 return GNUNET_SYSERR;
637 }
638 GNUNET_free (op_name);
639
640
641 /* Get max rate */
642 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
643 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
644 sec_name, op_name, &o->max_rate))
645 {
646 if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
647 (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) ||
648 (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
649 {
650 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
651 op_counter, op_name, e->id);
652 GNUNET_free (op_name);
653 return GNUNET_SYSERR;
654 }
655 }
656 GNUNET_free (op_name);
657
658 /* Get period */
659 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
660 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
661 sec_name, op_name, &o->period))
662 {
663 o->period = e->duration;
664 }
665 GNUNET_free (op_name);
666
667 /* Get frequency */
668 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
669 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
670 sec_name, op_name, &o->frequency))
671 {
672 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
673 op_counter, op_name, e->id);
674 GNUNET_free (op_name);
675 return GNUNET_SYSERR;
676 }
677 GNUNET_free (op_name);
678
679 /* Get preference */
680 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
681 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
682 sec_name, op_name, &prop))
683 {
684 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
685 op_counter, op_name, e->id);
686 GNUNET_free (op_name);
687 GNUNET_free_non_null (prop);
688 return GNUNET_SYSERR;
689 }
690
691 if (0 == (o->prop_type = parse_property_string(prop)))
692 {
693 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
694 op_counter, op_name, e->id);
695 GNUNET_free (op_name);
696 GNUNET_free (prop);
697 return GNUNET_SYSERR;
698 }
699
700 GNUNET_free (prop);
701 GNUNET_free (op_name);
702
703 fprintf (stderr,
704 "Found operation %s: [%llu:%llu] %s = %llu\n",
705 "START_SET_PROPERTY", o->peer_id, o->address_id,
706 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
707
708 return GNUNET_OK;
709}
710
711static int
712load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
713 struct Episode *e,
714 int op_counter,
715 char *sec_name,
716 const struct GNUNET_CONFIGURATION_Handle *cfg)
717{
718 char *op_name;
719 char *pref;
720
721 /* peer id */
722 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
723 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
724 sec_name, op_name, &o->peer_id))
725 {
726 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
727 op_counter, "STOP_SET_PROPERTY", op_name);
728 GNUNET_free (op_name);
729 return GNUNET_SYSERR;
730 }
731 GNUNET_free (op_name);
732
733 /* address id */
734 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
735 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
736 sec_name, op_name, &o->address_id))
737 {
738 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
739 op_counter, "STOP_SET_PROPERTY", op_name);
740 GNUNET_free (op_name);
741 return GNUNET_SYSERR;
742 }
743 GNUNET_free (op_name);
744
745 /* Get property */
746 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
747 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
748 sec_name, op_name, &pref))
749 {
750 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
751 op_counter, "STOP_SET_PROPERTY", op_name);
752 GNUNET_free (op_name);
753 GNUNET_free_non_null (pref);
754 return GNUNET_SYSERR;
755 }
756
757 if (0 == (o->prop_type = parse_property_string(pref)))
758 {
759 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
760 op_counter, op_name, e->id);
761 GNUNET_free (op_name);
762 GNUNET_free (pref);
763 GNUNET_free_non_null (pref);
764 return GNUNET_SYSERR;
765 }
766
767 GNUNET_free (pref);
768 GNUNET_free (op_name);
769
770 fprintf (stderr,
771 "Found operation %s: [%llu:%llu] %s\n",
772 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
773 GNUNET_ATS_print_property_type (o->prop_type));
774
775 return GNUNET_OK;
776}
535 777
536static int 778static int
537load_episode (struct Experiment *e, struct Episode *cur, 779load_episode (struct Experiment *e, struct Episode *cur,
@@ -566,6 +808,7 @@ load_episode (struct Experiment *e, struct Episode *cur,
566 GNUNET_free (o); 808 GNUNET_free (o);
567 GNUNET_free (op); 809 GNUNET_free (op);
568 GNUNET_free (op_name); 810 GNUNET_free (op_name);
811 GNUNET_free (sec_name);
569 return GNUNET_SYSERR; 812 return GNUNET_SYSERR;
570 } 813 }
571 } 814 }
@@ -578,16 +821,35 @@ load_episode (struct Experiment *e, struct Episode *cur,
578 GNUNET_free (o); 821 GNUNET_free (o);
579 GNUNET_free (op); 822 GNUNET_free (op);
580 GNUNET_free (op_name); 823 GNUNET_free (op_name);
824 GNUNET_free (sec_name);
581 return GNUNET_SYSERR; 825 return GNUNET_SYSERR;
582 } 826 }
583 } 827 }
584 else if (0 == strcmp (op, "start_set_property")) 828 else if (0 == strcmp (op, "start_set_property"))
585 { 829 {
586 o->type = SOLVER_OP_START_SET_PROPERTY; 830 o->type = SOLVER_OP_START_SET_PROPERTY;
831 if (GNUNET_SYSERR == load_op_start_set_property (o, cur,
832 op_counter, sec_name, cfg))
833 {
834 GNUNET_free (o);
835 GNUNET_free (op);
836 GNUNET_free (op_name);
837 GNUNET_free (sec_name);
838 return GNUNET_SYSERR;
839 }
587 } 840 }
588 else if (0 == strcmp (op, "stop_set_property")) 841 else if (0 == strcmp (op, "stop_set_property"))
589 { 842 {
590 o->type = SOLVER_OP_STOP_SET_PROPERTY; 843 o->type = SOLVER_OP_STOP_SET_PROPERTY;
844 if (GNUNET_SYSERR == load_op_stop_set_property (o, cur,
845 op_counter, sec_name, cfg))
846 {
847 GNUNET_free (o);
848 GNUNET_free (op);
849 GNUNET_free (op_name);
850 GNUNET_free (sec_name);
851 return GNUNET_SYSERR;
852 }
591 } 853 }
592 else if (0 == strcmp (op, "start_set_preference")) 854 else if (0 == strcmp (op, "start_set_preference"))
593 { 855 {
@@ -598,6 +860,7 @@ load_episode (struct Experiment *e, struct Episode *cur,
598 GNUNET_free (o); 860 GNUNET_free (o);
599 GNUNET_free (op); 861 GNUNET_free (op);
600 GNUNET_free (op_name); 862 GNUNET_free (op_name);
863 GNUNET_free (sec_name);
601 return GNUNET_SYSERR; 864 return GNUNET_SYSERR;
602 } 865 }
603 } 866 }
@@ -610,6 +873,7 @@ load_episode (struct Experiment *e, struct Episode *cur,
610 GNUNET_free (o); 873 GNUNET_free (o);
611 GNUNET_free (op); 874 GNUNET_free (op);
612 GNUNET_free (op_name); 875 GNUNET_free (op_name);
876 GNUNET_free (sec_name);
613 return GNUNET_SYSERR; 877 return GNUNET_SYSERR;
614 } 878 }
615 } 879 }
@@ -617,8 +881,10 @@ load_episode (struct Experiment *e, struct Episode *cur,
617 { 881 {
618 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n", 882 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
619 op_counter, op, cur->id); 883 op_counter, op, cur->id);
884 GNUNET_free (o);
620 GNUNET_free (op); 885 GNUNET_free (op);
621 GNUNET_free (op_name); 886 GNUNET_free (op_name);
887 GNUNET_free (sec_name);
622 return GNUNET_SYSERR; 888 return GNUNET_SYSERR;
623 } 889 }
624 GNUNET_free (op); 890 GNUNET_free (op);
@@ -1137,6 +1403,27 @@ GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
1137 1403
1138} 1404}
1139 1405
1406void
1407GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
1408{
1409 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1410 {
1411 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1412 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1413 }
1414 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1415 {
1416 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1417 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1418 }
1419 if (NULL != e->cfg)
1420 {
1421 GNUNET_CONFIGURATION_destroy(e->cfg);
1422 e->cfg = NULL;
1423 }
1424 free_experiment (e);
1425}
1426
1140 1427
1141struct Experiment * 1428struct Experiment *
1142GNUNET_ATS_solvers_experimentation_load (char *filename) 1429GNUNET_ATS_solvers_experimentation_load (char *filename)
@@ -1229,7 +1516,14 @@ GNUNET_ATS_solvers_experimentation_load (char *filename)
1229 fprintf (stderr, "Experiment duration: `%s'\n", 1516 fprintf (stderr, "Experiment duration: `%s'\n",
1230 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES)); 1517 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
1231 1518
1232 load_episodes (e, cfg); 1519 if (GNUNET_SYSERR == load_episodes (e, cfg))
1520 {
1521 GNUNET_ATS_solvers_experimentation_stop (e);
1522 GNUNET_CONFIGURATION_destroy (cfg);
1523 e = NULL;
1524 fprintf (stderr, "Failed to load experiment\n");
1525 return NULL;
1526 }
1233 fprintf (stderr, "Loaded %u episodes with total duration %s\n", 1527 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
1234 e->num_episodes, 1528 e->num_episodes,
1235 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES)); 1529 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
@@ -1238,27 +1532,6 @@ GNUNET_ATS_solvers_experimentation_load (char *filename)
1238 return e; 1532 return e;
1239} 1533}
1240 1534
1241void
1242GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
1243{
1244 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1245 {
1246 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1247 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1248 }
1249 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1250 {
1251 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1252 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1253 }
1254 if (NULL != e->cfg)
1255 {
1256 GNUNET_CONFIGURATION_destroy(e->cfg);
1257 e->cfg = NULL;
1258 }
1259 free_experiment (e);
1260}
1261
1262/** 1535/**
1263 * Logging 1536 * Logging
1264 */ 1537 */
diff --git a/src/ats/gnunet-ats-solver-eval.h b/src/ats/gnunet-ats-solver-eval.h
index 0b30fead7..9ea91cb3b 100644
--- a/src/ats/gnunet-ats-solver-eval.h
+++ b/src/ats/gnunet-ats-solver-eval.h
@@ -75,6 +75,7 @@ struct GNUNET_ATS_TEST_Operation
75 char*address; 75 char*address;
76 char*plugin; 76 char*plugin;
77 77
78
78 long long unsigned int base_rate; 79 long long unsigned int base_rate;
79 long long unsigned int max_rate; 80 long long unsigned int max_rate;
80 struct GNUNET_TIME_Relative period; 81 struct GNUNET_TIME_Relative period;
@@ -83,6 +84,7 @@ struct GNUNET_ATS_TEST_Operation
83 enum OperationType type; 84 enum OperationType type;
84 enum GeneratorType tg_type; 85 enum GeneratorType tg_type;
85 enum GNUNET_ATS_PreferenceKind pref_type; 86 enum GNUNET_ATS_PreferenceKind pref_type;
87 enum GNUNET_ATS_Property prop_type;
86}; 88};
87 89
88struct Episode 90struct Episode