From: Matthias Wachs Date: Thu, 12 Jan 2012 14:49:27 +0000 (+0000) Subject: - mlp X-Git-Tag: initial-import-from-subversion-38251~15338 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a89bc2071408040efd07c6b7fdd00a95b03ab10c;p=oweals%2Fgnunet.git - mlp --- diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 912912a8a..c8a78bc20 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -16,6 +16,7 @@ endif if HAVE_LIBGLPK GN_LIBGLPK = -lglpk GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h + GN_MLP_TEST = test_ats_mlp endif lib_LTLIBRARIES = libgnunetats.la @@ -50,7 +51,8 @@ gnunet_service_ats_LDADD = \ check_PROGRAMS = \ - test_ats_api_scheduling + test_ats_api_scheduling \ + $(GN_MLP_TEST) # test_ats_api_scheduling_get_type # test_ats_api_bandwidth_consumption @@ -58,6 +60,15 @@ if ENABLE_TEST_RUN TESTS = $(check_PROGRAMS) endif +if HAVE_LIBGLPK +test_ats_mlp_SOURCES = \ + $(GN_MLP_SRC) \ + test_ats_mlp.c +test_ats_mlp_LDADD = \ + $(GN_LIBGLPK) \ + $(top_builddir)/src/util/libgnunetutil.la +endif + test_ats_api_scheduling_SOURCES = \ test_ats_api_scheduling.c test_ats_api_scheduling_LDADD = \ diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 73545e352..b13de0df1 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -33,49 +33,6 @@ #include "gnunet-service-ats_scheduling.h" #include "gnunet-service-ats_reservations.h" -struct ATS_Address -{ - struct GNUNET_PeerIdentity peer; - - size_t addr_len; - - uint32_t session_id; - - uint32_t ats_count; - - const void *addr; - - char *plugin; - - struct GNUNET_ATS_Information *ats; - - struct GNUNET_TIME_Relative atsp_latency; - - struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in; - - struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out; - - uint32_t atsp_distance; - - uint32_t atsp_cost_wan; - - uint32_t atsp_cost_lan; - - uint32_t atsp_cost_wlan; - - uint32_t atsp_network_type; - - struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in; - - struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out; - - /** - * Is this the active address for this peer? - */ - int active; - -}; - enum ATS_Mode { SIMPLE, @@ -501,15 +458,16 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg) { /* MLP = YES */ case GNUNET_YES: -#if !HAVE_LIBGLPK - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode"); - ats_mode = SIMPLE; - break; +#if HAVE_LIBGLPK + ats_mode = MLP; + /* Init the MLP solver with default values */ + GAS_mlp_init (MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); + break; #else - ats_mode = MLP; - GAS_mlp_init (); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode"); + ats_mode = SIMPLE; + break; #endif - break; /* MLP = NO */ case GNUNET_NO: ats_mode = SIMPLE; diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 6e5d95f70..3709853a7 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -31,6 +31,49 @@ #include "gnunet_ats_service.h" #include "ats.h" +struct ATS_Address +{ + struct GNUNET_PeerIdentity peer; + + size_t addr_len; + + uint32_t session_id; + + uint32_t ats_count; + + const void *addr; + + char *plugin; + + struct GNUNET_ATS_Information *ats; + + struct GNUNET_TIME_Relative atsp_latency; + + struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in; + + struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out; + + uint32_t atsp_distance; + + uint32_t atsp_cost_wan; + + uint32_t atsp_cost_lan; + + uint32_t atsp_cost_wlan; + + uint32_t atsp_network_type; + + struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in; + + struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out; + + /** + * Is this the active address for this peer? + */ + int active; + +}; + /** * Initialize address subsystem. * @param cfg configuration to use diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 6352412f4..734d07a13 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -26,21 +26,84 @@ */ #include "platform.h" #include "gnunet_util_lib.h" +#include "gnunet-service-ats_addresses.h" #include "gnunet-service-ats_addresses_mlp.h" #if HAVE_LIBGLPK #include "glpk.h" #endif -struct GAS_MLP_Handle *GAS_mlp; +/* + * The MLP handle + */ +static struct GAS_MLP_Handle *GAS_mlp; + /** * Init the MLP problem solving component + * + * @param max_duration maximum numbers of iterations for the LP/MLP Solver + * @param max_iterations maximum time limit for the LP/MLP Solver + * @return GNUNET_OK on success, GNUNET_SYSERR on fail */ -void -GAS_mlp_init () +int +GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations) { GAS_mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); - GAS_mlp->prob = NULL; + + /* Init GLPK environment */ + GNUNET_assert (glp_init_env() == 0); + + /* Create initial MLP problem */ + GAS_mlp->prob = glp_create_prob(); + GNUNET_assert (GAS_mlp->prob != NULL); + + GAS_mlp->max_iterations = max_iterations; + GAS_mlp->max_exec_duration = max_duration; + + /* Init LP solving parameters */ + glp_init_smcp(&GAS_mlp->control_param_lp); + GAS_mlp->control_param_lp.it_lim = max_iterations; + GAS_mlp->control_param_lp.tm_lim = max_duration.rel_value; + /* Init MLP solving parameters */ + glp_init_iocp(&GAS_mlp->control_param_mlp); + GAS_mlp->control_param_mlp.tm_lim = max_duration.rel_value; + + return GNUNET_OK; +} + +/** + * Updates a single address in the MLP problem + * + * If the address did not exist before in the problem: + * The MLP problem has to be recreated and the problem has to be resolved + * + * Otherwise the addresses' values can be updated and the existing base can + * be reused + */ +void +GAS_mlp_address_update (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) +{ + +} + +/** + * Deletes a single address in the MLP problem + * + * The MLP problem has to be recreated and the problem has to be resolved + */ +void +GAS_mlp_address_delete (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) +{ + +} + +/** + * Deletes a single address in the MLP problem + */ +void +GAS_mlp_address_change_preference (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) +{ + } /** @@ -49,6 +112,12 @@ GAS_mlp_init () void GAS_mlp_done () { + if (GAS_mlp != NULL) + glp_delete_prob(GAS_mlp->prob); + + /* Clean up GLPK environment */ + glp_free_env(); + GNUNET_free (GAS_mlp); } diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 3351ca541..60c8dca05 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h @@ -25,6 +25,7 @@ * @author Christian Grothoff */ #include "platform.h" +#include "gnunet-service-ats_addresses.h" #if HAVE_LIBGLPK #include "glpk.h" #endif @@ -32,6 +33,10 @@ #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H + +#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) +#define MLP_MAX_ITERATIONS INT_MAX + struct GAS_MLP_Handle { /** @@ -43,13 +48,42 @@ struct GAS_MLP_Handle void *prob; #endif + /** + * GLPK LP control parameter + */ + glp_smcp control_param_lp; + + /** + * GLPK LP control parameter + */ + glp_iocp control_param_mlp; + + /** + * Maximum execution time per problem solving + */ + struct GNUNET_TIME_Relative max_exec_duration; + + /** + * Maximum number of LP iterations per problem solving + */ + unsigned int max_iterations; + }; /** * Init the MLP problem solving component + * @param max_duration maximum numbers of iterations for the LP/MLP Solver + * @param max_iterations maximum time limit for the LP/MLP Solver + * @return GNUNET_OK on success, GNUNET_SYSERR on fail + */ +int +GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations); + +/** + * Update address in the MLP problem */ void -GAS_mlp_init (); +GAS_mlp_update (struct ATS_Address *address); /** * Shutdown the MLP problem solving component