diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-04-17 16:40:30 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-04-17 16:40:30 +0000 |
commit | d1747c6a270ecf83e1ac609bdd20dd1229654a09 (patch) | |
tree | 218be575b2f1dfa3dddd0a08cb2a656af2f0afc3 /src/ats/gnunet-ats-solver-eval.c | |
parent | c95ac75360aa7be7ae3186d96903096285fc1d88 (diff) | |
download | gnunet-d1747c6a270ecf83e1ac609bdd20dd1229654a09.tar.gz gnunet-d1747c6a270ecf83e1ac609bdd20dd1229654a09.zip |
fix normalization logging
Diffstat (limited to 'src/ats/gnunet-ats-solver-eval.c')
-rw-r--r-- | src/ats/gnunet-ats-solver-eval.c | 86 |
1 files changed, 61 insertions, 25 deletions
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c index 1c6e6ad52..8566b03a7 100644 --- a/src/ats/gnunet-ats-solver-eval.c +++ b/src/ats/gnunet-ats-solver-eval.c | |||
@@ -38,6 +38,9 @@ static struct SolverHandle *sh; | |||
38 | static struct TestPeer *peer_head; | 38 | static struct TestPeer *peer_head; |
39 | static struct TestPeer *peer_tail; | 39 | static struct TestPeer *peer_tail; |
40 | 40 | ||
41 | static double default_properties[GNUNET_ATS_PropertyCount]; | ||
42 | static double default_preferences[GNUNET_ATS_PreferenceCount]; | ||
43 | |||
41 | /** | 44 | /** |
42 | * cmd option -e: experiment file | 45 | * cmd option -e: experiment file |
43 | */ | 46 | */ |
@@ -149,7 +152,7 @@ find_address_by_id (struct TestPeer *peer, int aid) | |||
149 | 152 | ||
150 | 153 | ||
151 | static struct TestAddress * | 154 | static struct TestAddress * |
152 | find_address_by_ats_address (struct TestPeer *p, struct ATS_Address *addr) | 155 | find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr) |
153 | { | 156 | { |
154 | struct TestAddress *cur; | 157 | struct TestAddress *cur; |
155 | for (cur = p->addr_head; NULL != cur; cur = cur->next) | 158 | for (cur = p->addr_head; NULL != cur; cur = cur->next) |
@@ -307,9 +310,8 @@ GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l) | |||
307 | for (lts = l->head; NULL != lts; lts = lts->next) | 310 | for (lts = l->head; NULL != lts; lts = lts->next) |
308 | { | 311 | { |
309 | 312 | ||
310 | fprintf (stderr, "Log step %llu %llu: \n", | 313 | fprintf (stderr, "Writing log step %llu\n", |
311 | (long long unsigned int) lts->timestamp.abs_value_us, | 314 | (long long unsigned int) lts->timestamp.abs_value_us); |
312 | (long long unsigned int) lts->delta.rel_value_us); | ||
313 | 315 | ||
314 | for (log_p = lts->head; NULL != log_p; log_p = log_p->next) | 316 | for (log_p = lts->head; NULL != log_p; log_p = log_p->next) |
315 | { | 317 | { |
@@ -324,11 +326,13 @@ GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l) | |||
324 | cur->aid = log_a->aid; | 326 | cur->aid = log_a->aid; |
325 | cur->pid = log_p->id; | 327 | cur->pid = log_p->id; |
326 | 328 | ||
327 | fprintf (stderr, "Add logging for %i %i: \n", | ||
328 | cur->pid, cur->aid); | ||
329 | |||
330 | GNUNET_asprintf (&filename, "%s_%s_%u_%u_%llu.log", e->log_prefix, opt_solver, | 329 | GNUNET_asprintf (&filename, "%s_%s_%u_%u_%llu.log", e->log_prefix, opt_solver, |
331 | cur->aid, cur->pid, l->head->timestamp.abs_value_us); | 330 | cur->aid, cur->pid, l->head->timestamp.abs_value_us); |
331 | |||
332 | fprintf (stderr, "Add writing log data for %i %i to file `%s'\n", | ||
333 | cur->pid, cur->aid, filename); | ||
334 | |||
335 | |||
332 | cur->f_hd = GNUNET_DISK_file_open (filename, | 336 | cur->f_hd = GNUNET_DISK_file_open (filename, |
333 | GNUNET_DISK_OPEN_READWRITE | | 337 | GNUNET_DISK_OPEN_READWRITE | |
334 | GNUNET_DISK_OPEN_CREATE | | 338 | GNUNET_DISK_OPEN_CREATE | |
@@ -364,25 +368,30 @@ GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l) | |||
364 | prefstring = GNUNET_strdup(""); | 368 | prefstring = GNUNET_strdup(""); |
365 | for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) | 369 | for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) |
366 | { | 370 | { |
371 | /* | ||
367 | fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n", | 372 | fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n", |
368 | GNUNET_ATS_print_preference_type(c), | 373 | GNUNET_ATS_print_preference_type(c), |
369 | log_p->pref_abs[c], log_p->pref_norm[c]); | 374 | log_p->pref_abs[c], log_p->pref_norm[c]); |
370 | 375 | */ | |
371 | GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f", | 376 | GNUNET_asprintf(&prefstring_tmp,"%s|%.3f|%.3f", |
372 | prefstring, log_p->pref_abs[c], log_p->pref_norm[c]); | 377 | prefstring, log_p->pref_abs[c], log_p->pref_norm[c]); |
378 | |||
379 | |||
373 | GNUNET_free (prefstring); | 380 | GNUNET_free (prefstring); |
374 | prefstring = GNUNET_strdup(prefstring_tmp); | 381 | prefstring = GNUNET_strdup(prefstring_tmp); |
375 | GNUNET_free (prefstring_tmp); | 382 | GNUNET_free (prefstring_tmp); |
376 | } | 383 | } |
377 | 384 | ||
385 | |||
378 | propstring = GNUNET_strdup(""); | 386 | propstring = GNUNET_strdup(""); |
379 | for (c = 1; c < GNUNET_ATS_PropertyCount; c++) | 387 | for (c = 1; c < GNUNET_ATS_PropertyCount; c++) |
380 | { | 388 | { |
381 | if (GNUNET_ATS_NETWORK_TYPE == c) | 389 | if (GNUNET_ATS_NETWORK_TYPE == c) |
382 | continue; | 390 | continue; |
391 | /* | ||
383 | fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", | 392 | fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", |
384 | GNUNET_ATS_print_property_type(c), | 393 | GNUNET_ATS_print_property_type(c), |
385 | log_a->prop_abs[c], log_a->prop_norm[c]); | 394 | log_a->prop_abs[c], log_a->prop_norm[c]);*/ |
386 | GNUNET_asprintf(&propstring_tmp,"%s;%.3f;%.3f", | 395 | GNUNET_asprintf(&propstring_tmp,"%s;%.3f;%.3f", |
387 | propstring, log_a->prop_abs[c], log_a->prop_norm[c]); | 396 | propstring, log_a->prop_abs[c], log_a->prop_norm[c]); |
388 | GNUNET_free (propstring); | 397 | GNUNET_free (propstring); |
@@ -390,14 +399,14 @@ GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l) | |||
390 | GNUNET_free (propstring_tmp); | 399 | GNUNET_free (propstring_tmp); |
391 | } | 400 | } |
392 | 401 | ||
393 | 402 | GNUNET_asprintf(&datastring,"%llu;%u;%i;%u;%u;%s;%s\n", | |
394 | GNUNET_asprintf(&datastring,"%llu;%u;%i;%u;%u;%s\n", | ||
395 | lts->timestamp.abs_value_us, | 403 | lts->timestamp.abs_value_us, |
396 | log_a->network, | 404 | log_a->network, |
397 | log_a->active, | 405 | log_a->active, |
398 | ntohl (log_a->assigned_bw_in.value__), | 406 | ntohl (log_a->assigned_bw_in.value__), |
399 | ntohl (log_a->assigned_bw_out.value__), | 407 | ntohl (log_a->assigned_bw_out.value__), |
400 | propstring, prefstring); | 408 | propstring, prefstring); |
409 | |||
401 | GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring)); | 410 | GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring)); |
402 | GNUNET_free (datastring); | 411 | GNUNET_free (datastring); |
403 | GNUNET_free (prefstring); | 412 | GNUNET_free (prefstring); |
@@ -578,7 +587,7 @@ set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
578 | struct PropertyGenerator *pg = cls; | 587 | struct PropertyGenerator *pg = cls; |
579 | struct TestPeer *p; | 588 | struct TestPeer *p; |
580 | struct TestAddress *a; | 589 | struct TestAddress *a; |
581 | double pref_value; | 590 | double prop_value; |
582 | struct GNUNET_ATS_Information atsi; | 591 | struct GNUNET_ATS_Information atsi; |
583 | 592 | ||
584 | pg->set_task = GNUNET_SCHEDULER_NO_TASK; | 593 | pg->set_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -605,22 +614,25 @@ set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
605 | pg->peer); | 614 | pg->peer); |
606 | } | 615 | } |
607 | 616 | ||
608 | pref_value = get_property (pg); | 617 | prop_value = get_property (pg); |
609 | a->prop_abs[pg->ats_property] = pref_value; | 618 | a->prop_abs[pg->ats_property] = prop_value; |
610 | 619 | ||
611 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 620 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
612 | "Setting property for peer [%u] address [%u] for %s to %f\n", | 621 | "Setting property for peer [%u] address [%u] for %s to %f\n", |
613 | pg->peer, pg->address_id, | 622 | pg->peer, pg->address_id, |
614 | GNUNET_ATS_print_property_type (pg->ats_property), pref_value); | 623 | GNUNET_ATS_print_property_type (pg->ats_property), prop_value); |
615 | 624 | ||
616 | atsi.type = htonl (pg->ats_property); | 625 | atsi.type = htonl (pg->ats_property); |
617 | atsi.value = htonl ((uint32_t) pref_value); | 626 | atsi.value = htonl ((uint32_t) prop_value); |
618 | 627 | ||
619 | /* set performance here! */ | 628 | /* set performance here! */ |
620 | sh->env.sf.s_bulk_start (sh->solver); | 629 | sh->env.sf.s_bulk_start (sh->solver); |
621 | if (GNUNET_YES == opt_disable_normalization) | 630 | if (GNUNET_YES == opt_disable_normalization) |
622 | { | 631 | { |
623 | GNUNET_break (0); | 632 | a->prop_abs[pg->ats_property] = prop_value; |
633 | a->prop_norm[pg->ats_property] = prop_value; | ||
634 | sh->env.sf.s_address_update_property (sh->solver, a->ats_addr, | ||
635 | pg->ats_property, prop_value, prop_value); | ||
624 | } | 636 | } |
625 | else | 637 | else |
626 | GAS_normalization_normalize_property (sh->addresses, | 638 | GAS_normalization_normalize_property (sh->addresses, |
@@ -866,7 +878,9 @@ set_pref_task (void *cls, | |||
866 | sh->env.sf.s_bulk_start (sh->solver); | 878 | sh->env.sf.s_bulk_start (sh->solver); |
867 | if (GNUNET_YES == opt_disable_normalization) | 879 | if (GNUNET_YES == opt_disable_normalization) |
868 | { | 880 | { |
869 | GNUNET_break (0); | 881 | p->pref_abs[pg->kind] = pref_value; |
882 | p->pref_norm[pg->kind] = pref_value; | ||
883 | sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value); | ||
870 | } | 884 | } |
871 | else | 885 | else |
872 | GAS_normalization_normalize_preference (NULL + (pg->client_id), | 886 | GAS_normalization_normalize_preference (NULL + (pg->client_id), |
@@ -2053,12 +2067,19 @@ enforce_add_address (struct GNUNET_ATS_TEST_Operation *op) | |||
2053 | { | 2067 | { |
2054 | struct TestPeer *p; | 2068 | struct TestPeer *p; |
2055 | struct TestAddress *a; | 2069 | struct TestAddress *a; |
2070 | int c; | ||
2056 | 2071 | ||
2057 | if (NULL == (p = find_peer_by_id (op->peer_id))) | 2072 | if (NULL == (p = find_peer_by_id (op->peer_id))) |
2058 | { | 2073 | { |
2059 | p = GNUNET_new (struct TestPeer); | 2074 | p = GNUNET_new (struct TestPeer); |
2060 | p->id = op->peer_id; | 2075 | p->id = op->peer_id; |
2061 | memset (&p->peer_id, op->peer_id, sizeof (p->peer_id)); | 2076 | memset (&p->peer_id, op->peer_id, sizeof (p->peer_id)); |
2077 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) | ||
2078 | { | ||
2079 | p->pref_abs[c] = DEFAULT_ABS_PREFERENCE; | ||
2080 | p->pref_norm[c] = DEFAULT_REL_PREFERENCE; | ||
2081 | } | ||
2082 | |||
2062 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p); | 2083 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p); |
2063 | } | 2084 | } |
2064 | 2085 | ||
@@ -2077,6 +2098,9 @@ enforce_add_address (struct GNUNET_ATS_TEST_Operation *op) | |||
2077 | memset (&p->peer_id, op->peer_id, sizeof (p->peer_id)); | 2098 | memset (&p->peer_id, op->peer_id, sizeof (p->peer_id)); |
2078 | GNUNET_CONTAINER_DLL_insert (p->addr_head, p->addr_tail, a); | 2099 | GNUNET_CONTAINER_DLL_insert (p->addr_head, p->addr_tail, a); |
2079 | 2100 | ||
2101 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) | ||
2102 | a->prop_norm[c] = DEFAULT_REL_QUALITY; | ||
2103 | |||
2080 | GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr, | 2104 | GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr, |
2081 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2105 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2082 | 2106 | ||
@@ -2771,11 +2795,12 @@ solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
2771 | const double * | 2795 | const double * |
2772 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | 2796 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) |
2773 | { | 2797 | { |
2774 | 2798 | struct TestPeer *p; | |
2775 | if (GNUNET_YES == opt_disable_normalization) | 2799 | if (GNUNET_YES == opt_disable_normalization) |
2776 | { | 2800 | { |
2777 | GNUNET_break (0); | 2801 | if (NULL == (p = find_peer_by_pid (id))) |
2778 | return NULL; | 2802 | return NULL; |
2803 | return p->pref_abs; | ||
2779 | } | 2804 | } |
2780 | else | 2805 | else |
2781 | return GAS_normalization_get_preferences_by_peer (id); | 2806 | return GAS_normalization_get_preferences_by_peer (id); |
@@ -2785,10 +2810,14 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | |||
2785 | const double * | 2810 | const double * |
2786 | get_property_cb (void *cls, const struct ATS_Address *address) | 2811 | get_property_cb (void *cls, const struct ATS_Address *address) |
2787 | { | 2812 | { |
2813 | struct TestPeer *p; | ||
2814 | struct TestAddress *a; | ||
2815 | |||
2788 | if (GNUNET_YES == opt_disable_normalization) | 2816 | if (GNUNET_YES == opt_disable_normalization) |
2789 | { | 2817 | { |
2790 | GNUNET_break (0); | 2818 | p = find_peer_by_pid (&address->peer); |
2791 | return NULL; | 2819 | a = find_address_by_ats_address (p, address); |
2820 | return a->prop_abs; | ||
2792 | } | 2821 | } |
2793 | else | 2822 | else |
2794 | return GAS_normalization_get_properties ((struct ATS_Address *) address); | 2823 | return GAS_normalization_get_properties ((struct ATS_Address *) address); |
@@ -2812,7 +2841,7 @@ set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_r | |||
2812 | return; | 2841 | return; |
2813 | } | 2842 | } |
2814 | a->prop_norm[type] = prop_rel; | 2843 | a->prop_norm[type] = prop_rel; |
2815 | sh->env.sf.s_address_update_property (sh->solver, address, type, 0, prop_rel); | 2844 | sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel); |
2816 | } | 2845 | } |
2817 | 2846 | ||
2818 | 2847 | ||
@@ -3041,6 +3070,7 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
3041 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 3070 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
3042 | { | 3071 | { |
3043 | enum GNUNET_ATS_Solvers solver; | 3072 | enum GNUNET_ATS_Solvers solver; |
3073 | int c; | ||
3044 | 3074 | ||
3045 | if (NULL == opt_exp_file) | 3075 | if (NULL == opt_exp_file) |
3046 | { | 3076 | { |
@@ -3078,6 +3108,12 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
3078 | return; | 3108 | return; |
3079 | } | 3109 | } |
3080 | 3110 | ||
3111 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) | ||
3112 | default_properties[c] = DEFAULT_REL_QUALITY; | ||
3113 | |||
3114 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) | ||
3115 | default_preferences[c] = DEFAULT_REL_PREFERENCE; | ||
3116 | |||
3081 | /* load experiment */ | 3117 | /* load experiment */ |
3082 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n"); | 3118 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n"); |
3083 | e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file); | 3119 | e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file); |