From 18a41e0fe392a136e89d7c5aed8a5a09cd48247b Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 16 Jan 2012 17:10:07 +0000 Subject: [PATCH] - implemented: quality metrics --- src/ats/gnunet-service-ats_addresses.c | 51 +--------- src/ats/gnunet-service-ats_addresses_mlp.c | 109 ++++++++++++++++++--- src/ats/gnunet-service-ats_addresses_mlp.h | 24 +++-- src/ats/test_ats_mlp.c | 2 +- src/include/gnunet_ats_service.h | 10 ++ 5 files changed, 116 insertions(+), 80 deletions(-) diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 8693293d0..06eee9fb3 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -536,55 +536,6 @@ void GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats) { -#if HAVE_LIBGLPK - double D; - double R; - double U; - long long unsigned int tmp; - unsigned int b_min; - unsigned int n_min; - - /* Get diversity coefficient from configuration */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", - "COEFFICIENT_D", - &tmp)) - D = (double) tmp / 100; - else - D = 1.0; - - /* Get proportionality coefficient from configuration */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", - "COEFFICIENT_R", - &tmp)) - R = (double) tmp / 100; - else - R = 1.0; - - /* Get utilization coefficient from configuration */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", - "COEFFICIENT_U", - &tmp)) - U = (double) tmp / 100; - else - U = 1.0; - - /* Get minimum bandwidth per used address from configuration */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", - "MIN_BANDWIDTH", - &tmp)) - b_min = tmp; - else - b_min = 64000; - - /* Get minimum number of connections from configuration */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", - "MIN_CONNECTIONS", - &tmp)) - n_min = tmp; - else - n_min = 4; -#endif - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", "WAN_QUOTA_IN", @@ -601,7 +552,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, #if HAVE_LIBGLPK ats_mode = MLP; /* Init the MLP solver with default values */ - mlp = GAS_mlp_init (stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS, D, U, R, b_min, n_min); + mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); break; #else diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 785cb736b..c0d4dc08e 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -46,6 +46,8 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) { int res = GNUNET_OK; int col; + int c; + char *name; /* Set a problem name */ glp_set_prob_name (mlp->prob, "gnunet ats bandwidth distribution"); @@ -92,8 +94,14 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) col = glp_add_cols(mlp->prob, mlp->m); mlp->c_q_start = col; mlp->c_q_end = col + mlp->m; - - mlp->co_Q = GNUNET_malloc (mlp->m * sizeof (double)); + for (c = 0; c < mlp->m; c++) + { + GNUNET_asprintf (&name, "q_%u", mlp->q[c]); + glp_set_col_name (mlp->prob, col + c, name); + glp_set_col_bnds (mlp->prob, col + c, GLP_LO, 0.0, 0.0); + GNUNET_free (name); + glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); + } return res; } @@ -285,24 +293,23 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp) * @param stats the GNUNET_STATISTICS handle * @param max_duration maximum numbers of iterations for the LP/MLP Solver * @param max_iterations maximum time limit for the LP/MLP Solver - * @param D Diversity coefficient - * @param U Utilization coefficient - * @param R Proportionality coefficient - * @param b_min minimum bandwidth assigned to an address - * @param n_min minimum number of addresses with bandwidth assigned - * * @return struct GAS_MLP_Handle * on success, NULL on fail */ struct GAS_MLP_Handle * -GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, +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, - double D, double U, double R, - unsigned int b_min, - unsigned int n_min) + unsigned int max_iterations) { struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); + double D; + double R; + double U; + long long unsigned int tmp; + unsigned int b_min; + unsigned int n_min; + /* Init GLPK environment */ GNUNET_assert (glp_init_env() == 0); @@ -310,6 +317,78 @@ GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, mlp->prob = glp_create_prob(); GNUNET_assert (mlp->prob != NULL); + /* Get diversity coefficient from configuration */ + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", + "COEFFICIENT_D", + &tmp)) + D = (double) tmp / 100; + else + D = 1.0; + + /* Get proportionality coefficient from configuration */ + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", + "COEFFICIENT_R", + &tmp)) + R = (double) tmp / 100; + else + R = 1.0; + + /* Get utilization coefficient from configuration */ + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", + "COEFFICIENT_U", + &tmp)) + U = (double) tmp / 100; + else + U = 1.0; + + /* Get quality metric coefficients from configuration */ + int i_delay = -1; + int i_distance = -1; + int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties; + int c; + for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) + { + /* initialize quality coefficients with default value 1.0 */ + mlp->co_Q[c] = 1.0; + + mlp->q[c] = q[c]; + if (q[c] == GNUNET_ATS_QUALITY_NET_DELAY) + i_delay = c; + if (q[c] == GNUNET_ATS_QUALITY_NET_DISTANCE) + i_distance = c; + } + + if ((i_delay != -1) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", + "COEFFICIENT_QUALITY_DELAY", + &tmp))) + + mlp->co_Q[i_delay] = (double) tmp / 100; + else + mlp->co_Q[i_delay] = 1.0; + + if ((i_distance != -1) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", + "COEFFICIENT_QUALITY_DISTANCE", + &tmp))) + mlp->co_Q[i_distance] = (double) tmp / 100; + else + mlp->co_Q[i_distance] = 1.0; + + /* Get minimum bandwidth per used address from configuration */ + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", + "MIN_BANDWIDTH", + &tmp)) + b_min = tmp; + else + b_min = 64000; + + /* Get minimum number of connections from configuration */ + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", + "MIN_CONNECTIONS", + &tmp)) + n_min = tmp; + else + n_min = 4; + mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; mlp->max_iterations = max_iterations; mlp->max_exec_duration = max_duration; @@ -340,6 +419,7 @@ GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, mlp->co_U = U; mlp->b_min = b_min; mlp->n_min = n_min; + mlp->m = GNUNET_ATS_QualityPropertiesCount; mlp_create_problem (mlp); return mlp; @@ -438,9 +518,6 @@ GAS_mlp_done (struct GAS_MLP_Handle *mlp) if (mlp != NULL) glp_delete_prob(mlp->prob); - if (mlp->co_Q != NULL) - GNUNET_free (mlp->co_Q); - /* Clean up GLPK environment */ glp_free_env(); diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index e604919be..62df7a733 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h @@ -136,14 +136,19 @@ struct GAS_MLP_Handle int c_r; double co_R; + /* ATS Quality metrics + * array with GNUNET_ATS_QualityPropertiesCount elements + * contains mapping to GNUNET_ATS_Property*/ + int q[GNUNET_ATS_QualityPropertiesCount]; + /* column index first quality metric (q_1) column */ int c_q_start; /* column index last quality metric (q_n) column */ int c_q_end; - /* Array of quality metric coefficients (m elements) */ - double *co_Q; + /* quality metric coefficients*/ + double co_Q[GNUNET_ATS_QualityPropertiesCount]; /* number of quality metrics */ int m; @@ -172,24 +177,17 @@ struct MLP_information /** * Init the MLP problem solving component * + * @param cfg configuration handle * @param stats the GNUNET_STATISTICS handle * @param max_duration maximum numbers of iterations for the LP/MLP Solver * @param max_iterations maximum time limit for the LP/MLP Solver - * @param D Diversity coefficient - * @param U Utilization coefficient - * @param R Proportionality coefficient - * @param b_min minimum bandwidth assigned to an address - * @param n_min minimum number of addresses with bandwidth assigned - * * @return struct GAS_MLP_Handle * on success, NULL on fail */ struct GAS_MLP_Handle * -GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, +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, - double D, double U, double R, - unsigned int b_min, - unsigned int n_min); + unsigned int max_iterations); /** diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 32917d546..e3e714557 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c @@ -53,7 +53,7 @@ check (void *cls, char *const *args, const char *cfgfile, #endif stats = GNUNET_STATISTICS_create("ats", cfg); - mlp = GAS_mlp_init(NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); + mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); GNUNET_assert (mlp != NULL); GAS_mlp_done (mlp); diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 88cab0d9b..0db277597 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -402,6 +402,16 @@ enum GNUNET_ATS_Property // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049 }; +/** + * Number of ATS quality properties + */ +#define GNUNET_ATS_QualityPropertiesCount 2 + +/** + * ATS quality properties as array initializer + */ +#define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE} + GNUNET_NETWORK_STRUCT_BEGIN -- 2.25.1