diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-02-11 14:07:59 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-02-11 14:07:59 +0000 |
commit | 84faee523650bb8613d67f99777e990a7497bf73 (patch) | |
tree | d40b4efb0eb53b2f618787756adb84988314ab6f /src/ats/gnunet-ats-solver-eval.c | |
parent | a5b4af52529d598adc78ae86621f8803d12eef8f (diff) | |
download | gnunet-84faee523650bb8613d67f99777e990a7497bf73.tar.gz gnunet-84faee523650bb8613d67f99777e990a7497bf73.zip |
+ setting preference
+ set preference example
+ adding client_id to suport multiple applications
Diffstat (limited to 'src/ats/gnunet-ats-solver-eval.c')
-rw-r--r-- | src/ats/gnunet-ats-solver-eval.c | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c index 234492962..afe65d5a1 100644 --- a/src/ats/gnunet-ats-solver-eval.c +++ b/src/ats/gnunet-ats-solver-eval.c | |||
@@ -296,7 +296,6 @@ set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
296 | pg->test_address->ats_addr, &atsi, 1); | 296 | pg->test_address->ats_addr, &atsi, 1); |
297 | sh->env.sf.s_bulk_stop (sh->solver); | 297 | sh->env.sf.s_bulk_stop (sh->solver); |
298 | 298 | ||
299 | |||
300 | switch (pg->ats_property) { | 299 | switch (pg->ats_property) { |
301 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 300 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
302 | //p->pref_bandwidth = pref_value; | 301 | //p->pref_bandwidth = pref_value; |
@@ -515,20 +514,29 @@ set_pref_task (void *cls, | |||
515 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 514 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
516 | { | 515 | { |
517 | struct PreferenceGenerator *pg = cls; | 516 | struct PreferenceGenerator *pg = cls; |
517 | struct TestPeer *p; | ||
518 | double pref_value; | 518 | double pref_value; |
519 | pg->set_task = GNUNET_SCHEDULER_NO_TASK; | 519 | pg->set_task = GNUNET_SCHEDULER_NO_TASK; |
520 | 520 | ||
521 | if (NULL == (p = find_peer_by_id (pg->peer))) | ||
522 | { | ||
523 | GNUNET_break (0); | ||
524 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
525 | "Setting preference for unknown peer %u\n", pg->peer); | ||
526 | return; | ||
527 | } | ||
528 | |||
521 | pref_value = get_preference (pg); | 529 | pref_value = get_preference (pg); |
522 | 530 | ||
523 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 531 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
524 | "Setting preference for peer [%u] address [%u] for %s to %f\n", | 532 | "Setting preference for peer [%u] address [%u] for client %p pref %s to %f\n", |
525 | pg->peer, pg->address_id, | 533 | pg->peer, pg->address_id, NULL + (pg->client_id), |
526 | GNUNET_ATS_print_preference_type (pg->kind), pref_value); | 534 | GNUNET_ATS_print_preference_type (pg->kind), pref_value); |
527 | 535 | ||
528 | /* set performance here! | 536 | sh->env.sf.s_bulk_start (sh->solver); |
529 | GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle, | 537 | GAS_normalization_normalize_preference (NULL + (pg->client_id), &p->peer_id, |
530 | &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END); | 538 | pg->kind, pref_value); |
531 | */ | 539 | sh->env.sf.s_bulk_stop (sh->solver); |
532 | 540 | ||
533 | switch (pg->kind) { | 541 | switch (pg->kind) { |
534 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 542 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
@@ -591,6 +599,7 @@ GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg) | |||
591 | struct PreferenceGenerator * | 599 | struct PreferenceGenerator * |
592 | GNUNET_ATS_solver_generate_preferences_start (unsigned int peer, | 600 | GNUNET_ATS_solver_generate_preferences_start (unsigned int peer, |
593 | unsigned int address_id, | 601 | unsigned int address_id, |
602 | unsigned int client_id, | ||
594 | enum GeneratorType type, | 603 | enum GeneratorType type, |
595 | long int base_value, | 604 | long int base_value, |
596 | long int value_rate, | 605 | long int value_rate, |
@@ -605,6 +614,7 @@ GNUNET_ATS_solver_generate_preferences_start (unsigned int peer, | |||
605 | pg->type = type; | 614 | pg->type = type; |
606 | pg->peer = peer; | 615 | pg->peer = peer; |
607 | pg->address_id = address_id; | 616 | pg->address_id = address_id; |
617 | pg->client_id = client_id; | ||
608 | pg->kind = kind; | 618 | pg->kind = kind; |
609 | pg->base_value = base_value; | 619 | pg->base_value = base_value; |
610 | pg->max_value = value_rate; | 620 | pg->max_value = value_rate; |
@@ -960,6 +970,18 @@ load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, | |||
960 | } | 970 | } |
961 | GNUNET_free (op_name); | 971 | GNUNET_free (op_name); |
962 | 972 | ||
973 | /* address id */ | ||
974 | GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter); | ||
975 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | ||
976 | sec_name, op_name, &o->client_id)) | ||
977 | { | ||
978 | fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n", | ||
979 | op_counter, "START_SET_PREFERENCE", op_name); | ||
980 | GNUNET_free (op_name); | ||
981 | return GNUNET_SYSERR; | ||
982 | } | ||
983 | GNUNET_free (op_name); | ||
984 | |||
963 | /* generator */ | 985 | /* generator */ |
964 | GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); | 986 | GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); |
965 | if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | 987 | if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
@@ -1483,7 +1505,6 @@ load_episode (struct Experiment *e, struct Episode *cur, | |||
1483 | o->type = SOLVER_OP_START_SET_PREFERENCE; | 1505 | o->type = SOLVER_OP_START_SET_PREFERENCE; |
1484 | res = load_op_start_set_preference (o, cur, | 1506 | res = load_op_start_set_preference (o, cur, |
1485 | op_counter, sec_name, cfg); | 1507 | op_counter, sec_name, cfg); |
1486 | break; | ||
1487 | } | 1508 | } |
1488 | else if (0 == strcmp (op, "stop_set_preference")) | 1509 | else if (0 == strcmp (op, "stop_set_preference")) |
1489 | { | 1510 | { |
@@ -1733,7 +1754,7 @@ enforce_start_property (struct GNUNET_ATS_TEST_Operation *op) | |||
1733 | { | 1754 | { |
1734 | GNUNET_break (0); | 1755 | GNUNET_break (0); |
1735 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1756 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1736 | "Setting proprterty for unknown address %u\n", op->peer_id); | 1757 | "Setting property for unknown address %u\n", op->peer_id); |
1737 | return; | 1758 | return; |
1738 | } | 1759 | } |
1739 | 1760 | ||
@@ -1761,14 +1782,24 @@ static void | |||
1761 | enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op) | 1782 | enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op) |
1762 | { | 1783 | { |
1763 | struct PreferenceGenerator *pg; | 1784 | struct PreferenceGenerator *pg; |
1785 | struct TestPeer *p; | ||
1764 | if (NULL != (pg = find_pref_gen (op->peer_id, op->address_id, op->pref_type))) | 1786 | if (NULL != (pg = find_pref_gen (op->peer_id, op->address_id, op->pref_type))) |
1765 | { | 1787 | { |
1766 | GNUNET_ATS_solver_generate_preferences_stop (pg); | 1788 | GNUNET_ATS_solver_generate_preferences_stop (pg); |
1767 | GNUNET_free (pg); | 1789 | GNUNET_free (pg); |
1768 | } | 1790 | } |
1769 | 1791 | ||
1792 | if (NULL == (p = find_peer_by_id (op->peer_id))) | ||
1793 | { | ||
1794 | GNUNET_break (0); | ||
1795 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1796 | "Starting preference generation for unknown peer %u\n", op->peer_id); | ||
1797 | return; | ||
1798 | } | ||
1799 | |||
1770 | GNUNET_ATS_solver_generate_preferences_start (op->peer_id, | 1800 | GNUNET_ATS_solver_generate_preferences_start (op->peer_id, |
1771 | op->address_id, | 1801 | op->address_id, |
1802 | op->client_id, | ||
1772 | op->gen_type, | 1803 | op->gen_type, |
1773 | op->base_rate, | 1804 | op->base_rate, |
1774 | op->max_rate, | 1805 | op->max_rate, |
@@ -2335,6 +2366,21 @@ normalized_property_changed_cb (void *cls, struct ATS_Address *address, | |||
2335 | } | 2366 | } |
2336 | 2367 | ||
2337 | 2368 | ||
2369 | static void | ||
2370 | normalized_preference_changed_cb (void *cls, | ||
2371 | const struct GNUNET_PeerIdentity *peer, | ||
2372 | enum GNUNET_ATS_PreferenceKind kind, | ||
2373 | double pref_rel) | ||
2374 | { | ||
2375 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
2376 | "Normalized preference %s for peer `%s' changed to %.3f \n", | ||
2377 | GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), | ||
2378 | pref_rel); | ||
2379 | |||
2380 | sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel); | ||
2381 | } | ||
2382 | |||
2383 | |||
2338 | struct SolverHandle * | 2384 | struct SolverHandle * |
2339 | GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) | 2385 | GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) |
2340 | { | 2386 | { |
@@ -2374,7 +2420,8 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) | |||
2374 | 2420 | ||
2375 | 2421 | ||
2376 | /* start normalization */ | 2422 | /* start normalization */ |
2377 | GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL ); | 2423 | GAS_normalization_start (&normalized_preference_changed_cb, NULL, |
2424 | &normalized_property_changed_cb, NULL ); | ||
2378 | 2425 | ||
2379 | /* load quotas */ | 2426 | /* load quotas */ |
2380 | if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg, | 2427 | if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg, |