From c9ff33b9a7421d4f6659722a077c00399c68c2e3 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 4 Dec 2012 13:16:26 +0000 Subject: [PATCH] changes --- src/ats/ats.conf.in | 5 ++ src/ats/gnunet-service-ats_addresses.c | 77 +++++++++++++------ src/ats/gnunet-service-ats_addresses.h | 22 +++++- src/ats/gnunet-service-ats_addresses_mlp.c | 34 ++++++-- src/ats/gnunet-service-ats_addresses_mlp.h | 10 +-- .../gnunet-service-ats_addresses_simplistic.c | 14 +++- .../gnunet-service-ats_addresses_simplistic.h | 11 ++- src/ats/perf_ats_mlp.c | 2 +- src/ats/test_ats_mlp.c | 2 +- src/ats/test_ats_mlp_averaging.c | 2 +- 10 files changed, 129 insertions(+), 50 deletions(-) diff --git a/src/ats/ats.conf.in b/src/ats/ats.conf.in index d063af333..9c43d9428 100644 --- a/src/ats/ats.conf.in +++ b/src/ats/ats.conf.in @@ -30,6 +30,11 @@ WLAN_QUOTA_OUT = 1 MiB # MLP specific settings +# MAX_DURATION = 3 s +# MAX_ITERATIONS = 1024 + + + DUMP_MLP = NO DUMP_SOLUTION = NO DUMP_OVERWRITE = NO diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 1a511eb3d..586bed79d 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -64,8 +64,6 @@ enum ATS_Mode static struct GNUNET_CONTAINER_MultiHashMap *addresses; -static void *solver; - static unsigned long long wan_quota_in; static unsigned long long wan_quota_out; @@ -76,6 +74,21 @@ static int ats_mode; static int running; +void *solver; + +struct GAS_Addresses_Handle +{ + int ats_mode; + /* Solver handle */ + void *solver; + + /* Solver functions */ + GAS_solver_init s_init; + GAS_solver_done s_done; + GAS_solver_address_delete s_del; + GAS_solver_address_change_preference s_pref; +}; + static unsigned int assemble_ats_information (struct ATS_Address *aa, struct GNUNET_ATS_Information **dest) @@ -991,10 +1004,11 @@ GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, * @param cfg configuration to use * @param stats the statistics handle to use */ -void +struct GAS_Addresses_Handle * GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats) { + struct GAS_Addresses_Handle *ah; int c; char *quota_wan_in_str; char *quota_wan_out_str; @@ -1063,41 +1077,56 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, } } + + ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle)); + /* Start configured solution method */ switch (ats_mode) { case MODE_MLP: /* Init the MLP solver with default values */ - solver = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); - if (NULL != solver) - { - ats_mode = MODE_MLP; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "MLP"); - break; - } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize MLP solver!\n"); +#if HAVE_LIBGLPK + ah->ats_mode = MODE_MLP; + ah->s_init = &GAS_mlp_init; + ah->s_pref = &GAS_mlp_address_change_preference; + ah->s_del = &GAS_mlp_address_delete; + ah->s_done = &GAS_mlp_done; +#else + GNUNET_freee (ah); + return NULL; +#endif + break; case MODE_SIMPLISTIC: /* Init the simplistic solver with default values */ + ah->ats_mode = MODE_SIMPLISTIC; + ah->s_init = &GAS_simplistic_init; + ah->s_pref = &GAS_simplistic_address_change_preference; + ah->s_del = &GAS_simplistic_address_delete; + ah->s_done = &GAS_simplistic_done; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "SIMPLISTIC"); - solver = GAS_simplistic_init (cfg, stats); - if (NULL != solver) - { - ats_mode = MODE_SIMPLISTIC; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "SIMPLISTIC"); - break; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize simplistic solver!\n"); - return; - } break; default: - GNUNET_break (0); + return NULL; break; } + + GNUNET_assert (NULL != ah->s_init); + GNUNET_assert (NULL != ah->s_pref); + GNUNET_assert (NULL != ah->s_del); + GNUNET_assert (NULL != ah->s_done); + + ah->solver = ah->s_init (cfg, stats); + /* REMOVE */ solver = ah->solver; + if (NULL == ah->solver) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize MLP solver!\n"); + GNUNET_free (ah); + return NULL; + } + /* up and running */ running = GNUNET_YES; + return ah; } diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index a570ba66c..54fb7b7cb 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -95,17 +95,35 @@ struct ATS_Address int used; }; +typedef void +(*GAS_solver_address_change_preference) (void *solver, + const struct GNUNET_PeerIdentity *peer, + enum GNUNET_ATS_PreferenceKind kind, + float score); + +typedef void + (*GAS_solver_address_delete) (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); + + +typedef void * + (*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_STATISTICS_Handle *stats); + + +typedef void + (*GAS_solver_done) (void *solver); + + /** * Initialize address subsystem. * * @param cfg configuration to use * @param stats the statistics handle to use */ -void +struct GAS_Addresses_Handle * GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats); - /** * Shutdown address subsystem. */ diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index b3c1512ce..0edf6eed1 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -1073,11 +1073,9 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContex * @param max_iterations maximum time limit for the LP/MLP Solver * @return struct GAS_MLP_Handle * on success, NULL on fail */ -struct GAS_MLP_Handle * +void * GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_STATISTICS_Handle *stats, - struct GNUNET_TIME_Relative max_duration, - unsigned int max_iterations) + const struct GNUNET_STATISTICS_Handle *stats) { struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); @@ -1092,6 +1090,9 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, char * quota_out_str; char * quota_in_str; + struct GNUNET_TIME_Relative max_duration; + long long unsigned int max_iterations; + /* Init GLPK environment */ int res = glp_init_env(); switch (res) { @@ -1125,6 +1126,21 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, mlp->BIG_M = (double) BIG_M_VALUE; + /* Get maximum number of iterations */ + + + /* Get timeout for iterations */ + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, "ats", "MAX_DURATION", &max_duration)) + { + max_duration = MLP_MAX_EXEC_DURATION; + } + + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(cfg, "ats", "MAX_ITERATIONS", &max_iterations)) + { + max_iterations = MLP_MAX_ITERATIONS; + } + /* Get diversity coefficient from configuration */ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "COEFFICIENT_D", @@ -1614,8 +1630,9 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult * @param address the address to delete */ void -GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) +GAS_mlp_address_delete (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) { + struct GAS_MLP_Handle *mlp = solver; GNUNET_STATISTICS_update (mlp->stats,"# LP address deletions", 1, GNUNET_NO); struct GAS_MLP_SolutionContext ctx; @@ -1718,16 +1735,18 @@ GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp, * @param score the score */ void -GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, +GAS_mlp_address_change_preference (void *solver, const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, float score) { + struct GAS_MLP_Handle *mlp = solver; GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO); //struct ATS_Peer *p = mlp_find_peer (mlp, peer); //FIXME to finish implementation /* Here we have to do the matching */ + } /** @@ -1735,8 +1754,9 @@ GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, * @param mlp the MLP handle */ void -GAS_mlp_done (struct GAS_MLP_Handle *mlp) +GAS_mlp_done (void *solver) { + struct GAS_MLP_Handle *mlp = solver; struct ATS_Peer * peer; struct ATS_Address *addr; diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index d37eea752..af3625c8d 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h @@ -321,11 +321,9 @@ struct MLP_information * @param max_iterations maximum time limit for the LP/MLP Solver * @return struct GAS_MLP_Handle * on success, NULL on fail */ -struct GAS_MLP_Handle * +void * GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_STATISTICS_Handle *stats, - struct GNUNET_TIME_Relative max_duration, - unsigned int max_iterations); + const struct GNUNET_STATISTICS_Handle *stats); /** * Solves the MLP problem on demand @@ -367,7 +365,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult * @param address the address to delete */ void -GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); +GAS_mlp_address_delete (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); /** @@ -379,7 +377,7 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult * @param score the score */ void -GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, +GAS_mlp_address_change_preference (void *solver, const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, float score); diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.c b/src/ats/gnunet-service-ats_addresses_simplistic.c index be7380692..e942f7abe 100644 --- a/src/ats/gnunet-service-ats_addresses_simplistic.c +++ b/src/ats/gnunet-service-ats_addresses_simplistic.c @@ -42,7 +42,7 @@ struct GAS_SIMPLISTIC_Handle * @param stats the GNUNET_STATISTICS handle * @return struct GAS_SIMPLISTIC_Handle * on success, NULL on fail */ -struct GAS_SIMPLISTIC_Handle * +void * GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats) { @@ -54,7 +54,7 @@ GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, * Shutdown the simplistic problem solving component */ void -GAS_simplistic_done (struct GAS_SIMPLISTIC_Handle *solver) +GAS_simplistic_done (void *solver) { GNUNET_free (solver); } @@ -68,7 +68,13 @@ GAS_simplistic_done (struct GAS_SIMPLISTIC_Handle *solver) * @param address the address to update */ void -GAS_simplistic_address_update (struct GAS_SIMPLISTIC_Handle *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) +GAS_simplistic_address_update (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) +{ + +} + +void +GAS_simplistic_address_delete (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) { } @@ -82,7 +88,7 @@ GAS_simplistic_address_update (struct GAS_SIMPLISTIC_Handle *solver, struct GNUN * @param score the score */ void -GAS_simplistic_address_change_preference (struct GAS_SIMPLISTIC_Handle *solver, +GAS_simplistic_address_change_preference (void *solver, const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, float score) diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.h b/src/ats/gnunet-service-ats_addresses_simplistic.h index dcaf27b46..f68eff9c1 100644 --- a/src/ats/gnunet-service-ats_addresses_simplistic.h +++ b/src/ats/gnunet-service-ats_addresses_simplistic.h @@ -37,7 +37,7 @@ struct GAS_SIMPLISTIC_Handle; * @param stats the GNUNET_STATISTICS handle * @return struct GAS_SIMPLISTIC_Handle * on success, NULL on fail */ -struct GAS_SIMPLISTIC_Handle * +void * GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats); @@ -45,7 +45,7 @@ GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, * Shutdown the simplistic problem solving component */ void -GAS_simplistic_done (struct GAS_SIMPLISTIC_Handle *); +GAS_simplistic_done (void * solver); /** @@ -57,7 +57,10 @@ GAS_simplistic_done (struct GAS_SIMPLISTIC_Handle *); * @param address the address to update */ void -GAS_simplistic_address_update (struct GAS_SIMPLISTIC_Handle *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); +GAS_simplistic_address_update (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); + +void +GAS_simplistic_address_delete (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address); /** * Changes the preferences for a peer in the problem @@ -68,7 +71,7 @@ GAS_simplistic_address_update (struct GAS_SIMPLISTIC_Handle *solver, struct GNUN * @param score the score */ void -GAS_simplistic_address_change_preference (struct GAS_SIMPLISTIC_Handle *solver, +GAS_simplistic_address_change_preference (void *solver, const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, float score); diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c index 751fad51a..6567e3c01 100644 --- a/src/ats/perf_ats_mlp.c +++ b/src/ats/perf_ats_mlp.c @@ -195,7 +195,7 @@ check (void *cls, char *const *args, const char *cfgfile, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses); - mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); + mlp = GAS_mlp_init (cfg, NULL); if (NULL == mlp) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n"); diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 3e449dbd2..a0b081360 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c @@ -78,7 +78,7 @@ check (void *cls, char *const *args, const char *cfgfile, addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); - mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); + mlp = GAS_mlp_init (cfg, NULL); mlp->auto_solve = GNUNET_NO; struct GNUNET_PeerIdentity p[10]; diff --git a/src/ats/test_ats_mlp_averaging.c b/src/ats/test_ats_mlp_averaging.c index 2f70137df..371f9e994 100644 --- a/src/ats/test_ats_mlp_averaging.c +++ b/src/ats/test_ats_mlp_averaging.c @@ -79,7 +79,7 @@ check (void *cls, char *const *args, const char *cfgfile, addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); - mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); + mlp = GAS_mlp_init (cfg, NULL); mlp->auto_solve = GNUNET_NO; struct GNUNET_PeerIdentity p[10]; -- 2.25.1