diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-03 14:50:15 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-03 14:50:15 +0000 |
commit | a3b64a461bf4e1638ffb0884ed42bde42c56c77e (patch) | |
tree | 66844dd0f90f3e68a9d215ff57d025ed4ec992a8 | |
parent | 7098267e7ae29b19bc797c5c5c5f5a7e1b146a78 (diff) |
changes
-rw-r--r-- | src/ats/Makefile.am | 1 | ||||
-rw-r--r-- | src/ats/ats.conf.in | 7 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 159 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_simplistic.c | 64 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_simplistic.h | 53 | ||||
-rw-r--r-- | src/ats/test_ats_api.conf | 2 |
6 files changed, 223 insertions, 63 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 57ca63e08a..bd6d6def27 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -44,6 +44,7 @@ libexec_PROGRAMS = \ gnunet_service_ats_SOURCES = \ gnunet-service-ats.c gnunet-service-ats.h\ gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ + gnunet-service-ats_addresses_simplistic.c gnunet-service-ats_addresses_simplistic.h \ $(GN_MLP_SRC) \ gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ diff --git a/src/ats/ats.conf.in b/src/ats/ats.conf.in index d997081746..d063af3334 100644 --- a/src/ats/ats.conf.in +++ b/src/ats/ats.conf.in @@ -10,8 +10,9 @@ UNIXPATH = /tmp/gnunet-service-ats.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES -# Enable MLP mode (default: NO) -MLP = NO +# Designated assigment mode: simplistic / MLP +MODE = simplistic + # Network specific inbound/outbound quotas # LOOPBACK LOOPBACK_QUOTA_IN = unlimited @@ -27,6 +28,8 @@ WLAN_QUOTA_IN = 1 MiB WLAN_QUOTA_OUT = 1 MiB # ATS options + +# MLP specific settings 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 584978e2a1..1262c0ad40 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -34,29 +34,37 @@ #if HAVE_LIBGLPK #include "gnunet-service-ats_addresses_mlp.h" #endif +#include "gnunet-service-ats_addresses_simplistic.h" #define ATS_BLOCKING_DELTA GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100) + +/** + * Available ressource assignment modes + */ enum ATS_Mode { /* + * Simplistic mode: + * * Assign each peer an equal amount of bandwidth (bw) * * bw_per_peer = bw_total / #active addresses */ - SIMPLE, + MODE_SIMPLISTIC, /* - * Use MLP solver to assign bandwidth + * MLP mode: + * + * Solve ressource assignment as an optimization problem + * Uses an mixed integer programming solver */ - MLP + MODE_MLP }; static struct GNUNET_CONTAINER_MultiHashMap *addresses; -#if HAVE_LIBGLPK -static struct GAS_MLP_Handle *mlp; -#endif +static void *solver; static unsigned long long wan_quota_in; @@ -223,8 +231,8 @@ destroy_address (struct ATS_Address *addr) addr)); #if HAVE_LIBGLPK - if (ats_mode == MLP) - GAS_mlp_address_delete (mlp, addresses, addr); + if (ats_mode == MODE_MLP) + GAS_mlp_address_delete (solver, addresses, addr); #endif if (GNUNET_YES == addr->active) @@ -556,8 +564,8 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, break; } #if HAVE_LIBGLPK - if (ats_mode == MLP) - GAS_mlp_address_update (mlp, addresses, old); + if (ats_mode == MODE_MLP) + GAS_mlp_address_update (solver, addresses, old); #endif } @@ -627,8 +635,8 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *valu { /* session was set to 0, update address */ #if HAVE_LIBGLPK - if (ats_mode == MLP) - GAS_mlp_address_update (mlp, addresses, aa); + if (ats_mode == MODE_MLP) + GAS_mlp_address_update (solver, addresses, aa); #endif } @@ -796,8 +804,8 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, } old->used = in_use; #if HAVE_LIBGLPK - if (ats_mode == MLP) - GAS_mlp_address_update (mlp, addresses, old); + if (ats_mode == MODE_MLP) + GAS_mlp_address_update (solver, addresses, old); #endif return GNUNET_OK; } @@ -810,7 +818,7 @@ request_address_mlp (const struct GNUNET_PeerIdentity *peer) aa = NULL; #if HAVE_GLPK - /* Get preferred address from MLP */ + /* Get preferred address from MODE_MLP */ struct ATS_PreferedAddress * paddr = NULL; paddr = GAS_mlp_get_preferred_address (mlp, addresses, peer); aa = paddr->address; @@ -870,7 +878,7 @@ request_address_simple (const struct GNUNET_PeerIdentity *peer) { aa->active = GNUNET_YES; active_addr_count++; - if (ats_mode == SIMPLE) + if (ats_mode == MODE_SIMPLISTIC) { recalculate_assigned_bw (); } @@ -893,11 +901,11 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) if (GNUNET_NO == running) return; - if (ats_mode == SIMPLE) + if (ats_mode == MODE_SIMPLISTIC) { request_address_simple (peer); } - if (ats_mode == MLP) + if (ats_mode == MODE_MLP) { request_address_mlp(peer); } @@ -939,8 +947,8 @@ GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, if (GNUNET_NO == running) return; #if HAVE_LIBGLPK - if (ats_mode == MLP) - GAS_mlp_address_change_preference (mlp, peer, kind, score); + if (ats_mode == MODE_MLP) + GAS_mlp_address_change_preference (solver, peer, kind, score); #endif } @@ -956,16 +964,13 @@ void GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats) { - int mode; - + int c; char *quota_wan_in_str; char *quota_wan_out_str; - + char *mode_str; running = GNUNET_NO; - addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); - GNUNET_assert (NULL != addresses); - + /* Initialize the system with configuration values */ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_IN", "a_wan_in_str)) { if (0 == strcmp(quota_wan_in_str, "unlimited") || @@ -994,47 +999,72 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, wan_quota_out = (UINT32_MAX) /10; } - mode = GNUNET_CONFIGURATION_get_value_yesno (cfg, "ats", "MLP"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP mode %u", mode); - switch (mode) + /* Initialize the addresses database */ + addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); + GNUNET_assert (NULL != addresses); + + /* Figure out configured solution method */ + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str)) { - /* MLP = YES */ - case GNUNET_YES: -#if HAVE_LIBGLPK - ats_mode = MLP; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "No ressource assignment method configured, using simplistic approch\n"); + ats_mode = MODE_SIMPLISTIC; + } + else + { + for (c = 0; c < strlen (mode_str); c++) + mode_str[c] = toupper (mode_str[c]); + if (0 == strcmp (mode_str, "SIMPLISTIC")) + { + ats_mode = MODE_SIMPLISTIC; + } + else if (0 == strcmp (mode_str, "MLP")) + { + ats_mode = MODE_MLP; +#if !HAVE_LIBGLPK + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Assignment method `%s' configured, but GLPK is not availabe, please install \n", mode_str); + ats_mode = MODE_SIMPLISTIC; +#endif + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid ressource assignment method `%s' configured, using simplistic approch\n", mode_str); + ats_mode = MODE_SIMPLISTIC; + } + } + + /* Start configured solution method */ + switch (ats_mode) + { + case MODE_MLP: /* Init the MLP solver with default values */ - mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); - if (NULL == mlp) + solver = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); + if (NULL != solver) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode\n"); - GNUNET_STATISTICS_update (GSA_stats, "MLP mode enabled", 0, GNUNET_NO); - break; + 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"); + case MODE_SIMPLISTIC: + /* Init the simplistic solver with default values */ + 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_STATISTICS_update (GSA_stats, "MLP enabled", 1, GNUNET_NO); - break; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize simplistic solver!\n"); + return; } -#else - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode"); - GNUNET_STATISTICS_update (GSA_stats, "MLP enabled", 0, GNUNET_NO); - ats_mode = SIMPLE; - break; -#endif - /* MLP = NO */ - case GNUNET_NO: - GNUNET_STATISTICS_update (GSA_stats, "MLP enabled", 0, GNUNET_NO); - ats_mode = SIMPLE; - break; - /* No configuration value */ - case GNUNET_SYSERR: - GNUNET_STATISTICS_update (GSA_stats, "MLP enabled", 0, GNUNET_NO); - ats_mode = SIMPLE; break; default: break; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS started with %s mode\n", (SIMPLE == ats_mode) ? "SIMPLE" : "MLP"); + /* up and running */ running = GNUNET_YES; } @@ -1079,12 +1109,21 @@ GAS_addresses_done () running = GNUNET_NO; GNUNET_CONTAINER_multihashmap_destroy (addresses); addresses = NULL; -#if HAVE_LIBGLPK - if (ats_mode == MLP) + + /* Stop configured solution method */ + switch (ats_mode) { - GAS_mlp_done (mlp); + case MODE_MLP: + /* Init the MLP solver with default values */ + GAS_mlp_done (solver); + break; + case MODE_SIMPLISTIC: + /* Init the simplistic solver with default values */ + GAS_simplistic_done (solver); + break; + default: + break; } -#endif } struct PeerIteratorContext diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.c b/src/ats/gnunet-service-ats_addresses_simplistic.c new file mode 100644 index 0000000000..ac9828f11b --- /dev/null +++ b/src/ats/gnunet-service-ats_addresses_simplistic.c @@ -0,0 +1,64 @@ +/* + This file is part of GNUnet. + (C) 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file ats/gnunet-service-ats_addresses_simplistic.c + * @brief ats mlp problem solver + * @author Matthias Wachs + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet-service-ats_addresses.h" +#include "gnunet_statistics_service.h" +#include "glpk.h" + +struct GAS_SIMPLISTIC_Handle +{ + +}; + +/** + * Init the simplistic 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 + * @return struct GAS_MLP_Handle * on success, NULL on fail + */ +struct GAS_SIMPLISTIC_Handle * +GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_STATISTICS_Handle *stats) +{ + struct GAS_SIMPLISTIC_Handle *solver = GNUNET_malloc (sizeof (struct GAS_SIMPLISTIC_Handle)); + return solver; +} + +/** + * Shutdown the simplistic problem solving component + */ +void +GAS_simplistic_done (struct GAS_SIMPLISTIC_Handle *solver) +{ + GNUNET_free (solver); +} + +/* end of gnunet-service-ats_addresses_simplistic.c */ diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.h b/src/ats/gnunet-service-ats_addresses_simplistic.h new file mode 100644 index 0000000000..654753a7fb --- /dev/null +++ b/src/ats/gnunet-service-ats_addresses_simplistic.h @@ -0,0 +1,53 @@ +/* + This file is part of GNUnet. + (C) 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file ats/gnunet-service-ats_addresses_simplistic.h + * @brief ats mlp problem solver + * @author Matthias Wachs + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_statistics_service.h" +#include "gnunet-service-ats_addresses.h" + +struct GAS_SIMPLISTIC_Handle; + +/** + * Init the simplistic 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 + * @return struct GAS_MLP_Handle * on success, NULL on fail + */ +struct GAS_SIMPLISTIC_Handle * +GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_STATISTICS_Handle *stats); + +/** + * Shutdown the simplistic problem solving component + */ +void +GAS_simplistic_done (struct GAS_SIMPLISTIC_Handle *); + + +/* end of gnunet-service-ats_addresses_simplistic.h */ diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf index 2ac499c663..d55d9911c1 100644 --- a/src/ats/test_ats_api.conf +++ b/src/ats/test_ats_api.conf @@ -20,7 +20,7 @@ UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES # Enable MLP mode (default: NO) -MLP = NO +MODE = SIMPLISTIC # Network specific inbound/outbound quotas # LOOPBACK LOOPBACK_QUOTA_IN = unlimited |