aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-12 14:49:27 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-12 14:49:27 +0000
commita89bc2071408040efd07c6b7fdd00a95b03ab10c (patch)
tree633e07f084efc2c26968379c84eb9b4212f758d9
parent987e618a2240e7a8cf5c61e33af9bb413a118e7a (diff)
downloadgnunet-a89bc2071408040efd07c6b7fdd00a95b03ab10c.tar.gz
gnunet-a89bc2071408040efd07c6b7fdd00a95b03ab10c.zip
- mlp
-rw-r--r--src/ats/Makefile.am13
-rw-r--r--src/ats/gnunet-service-ats_addresses.c58
-rw-r--r--src/ats/gnunet-service-ats_addresses.h43
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c77
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.h36
5 files changed, 171 insertions, 56 deletions
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
16if HAVE_LIBGLPK 16if HAVE_LIBGLPK
17 GN_LIBGLPK = -lglpk 17 GN_LIBGLPK = -lglpk
18 GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h 18 GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h
19 GN_MLP_TEST = test_ats_mlp
19endif 20endif
20 21
21lib_LTLIBRARIES = libgnunetats.la 22lib_LTLIBRARIES = libgnunetats.la
@@ -50,7 +51,8 @@ gnunet_service_ats_LDADD = \
50 51
51 52
52check_PROGRAMS = \ 53check_PROGRAMS = \
53 test_ats_api_scheduling 54 test_ats_api_scheduling \
55 $(GN_MLP_TEST)
54# test_ats_api_scheduling_get_type 56# test_ats_api_scheduling_get_type
55# test_ats_api_bandwidth_consumption 57# test_ats_api_bandwidth_consumption
56 58
@@ -58,6 +60,15 @@ if ENABLE_TEST_RUN
58TESTS = $(check_PROGRAMS) 60TESTS = $(check_PROGRAMS)
59endif 61endif
60 62
63if HAVE_LIBGLPK
64test_ats_mlp_SOURCES = \
65 $(GN_MLP_SRC) \
66 test_ats_mlp.c
67test_ats_mlp_LDADD = \
68 $(GN_LIBGLPK) \
69 $(top_builddir)/src/util/libgnunetutil.la
70endif
71
61test_ats_api_scheduling_SOURCES = \ 72test_ats_api_scheduling_SOURCES = \
62 test_ats_api_scheduling.c 73 test_ats_api_scheduling.c
63test_ats_api_scheduling_LDADD = \ 74test_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 @@
33#include "gnunet-service-ats_scheduling.h" 33#include "gnunet-service-ats_scheduling.h"
34#include "gnunet-service-ats_reservations.h" 34#include "gnunet-service-ats_reservations.h"
35 35
36struct ATS_Address
37{
38 struct GNUNET_PeerIdentity peer;
39
40 size_t addr_len;
41
42 uint32_t session_id;
43
44 uint32_t ats_count;
45
46 const void *addr;
47
48 char *plugin;
49
50 struct GNUNET_ATS_Information *ats;
51
52 struct GNUNET_TIME_Relative atsp_latency;
53
54 struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in;
55
56 struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out;
57
58 uint32_t atsp_distance;
59
60 uint32_t atsp_cost_wan;
61
62 uint32_t atsp_cost_lan;
63
64 uint32_t atsp_cost_wlan;
65
66 uint32_t atsp_network_type;
67
68 struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
69
70 struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
71
72 /**
73 * Is this the active address for this peer?
74 */
75 int active;
76
77};
78
79enum ATS_Mode 36enum ATS_Mode
80{ 37{
81 SIMPLE, 38 SIMPLE,
@@ -501,15 +458,16 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
501 { 458 {
502 /* MLP = YES */ 459 /* MLP = YES */
503 case GNUNET_YES: 460 case GNUNET_YES:
504#if !HAVE_LIBGLPK 461#if HAVE_LIBGLPK
505 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode"); 462 ats_mode = MLP;
506 ats_mode = SIMPLE; 463 /* Init the MLP solver with default values */
507 break; 464 GAS_mlp_init (MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
465 break;
508#else 466#else
509 ats_mode = MLP; 467 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode");
510 GAS_mlp_init (); 468 ats_mode = SIMPLE;
469 break;
511#endif 470#endif
512 break;
513 /* MLP = NO */ 471 /* MLP = NO */
514 case GNUNET_NO: 472 case GNUNET_NO:
515 ats_mode = SIMPLE; 473 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 @@
31#include "gnunet_ats_service.h" 31#include "gnunet_ats_service.h"
32#include "ats.h" 32#include "ats.h"
33 33
34struct ATS_Address
35{
36 struct GNUNET_PeerIdentity peer;
37
38 size_t addr_len;
39
40 uint32_t session_id;
41
42 uint32_t ats_count;
43
44 const void *addr;
45
46 char *plugin;
47
48 struct GNUNET_ATS_Information *ats;
49
50 struct GNUNET_TIME_Relative atsp_latency;
51
52 struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in;
53
54 struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out;
55
56 uint32_t atsp_distance;
57
58 uint32_t atsp_cost_wan;
59
60 uint32_t atsp_cost_lan;
61
62 uint32_t atsp_cost_wlan;
63
64 uint32_t atsp_network_type;
65
66 struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
67
68 struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
69
70 /**
71 * Is this the active address for this peer?
72 */
73 int active;
74
75};
76
34/** 77/**
35 * Initialize address subsystem. 78 * Initialize address subsystem.
36 * @param cfg configuration to use 79 * @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 @@
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet-service-ats_addresses.h"
29#include "gnunet-service-ats_addresses_mlp.h" 30#include "gnunet-service-ats_addresses_mlp.h"
30#if HAVE_LIBGLPK 31#if HAVE_LIBGLPK
31#include "glpk.h" 32#include "glpk.h"
32#endif 33#endif
33 34
34struct GAS_MLP_Handle *GAS_mlp; 35/*
36 * The MLP handle
37 */
38static struct GAS_MLP_Handle *GAS_mlp;
39
35 40
36/** 41/**
37 * Init the MLP problem solving component 42 * Init the MLP problem solving component
43 *
44 * @param max_duration maximum numbers of iterations for the LP/MLP Solver
45 * @param max_iterations maximum time limit for the LP/MLP Solver
46 * @return GNUNET_OK on success, GNUNET_SYSERR on fail
38 */ 47 */
39void 48int
40GAS_mlp_init () 49GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations)
41{ 50{
42 GAS_mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); 51 GAS_mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle));
43 GAS_mlp->prob = NULL; 52
53 /* Init GLPK environment */
54 GNUNET_assert (glp_init_env() == 0);
55
56 /* Create initial MLP problem */
57 GAS_mlp->prob = glp_create_prob();
58 GNUNET_assert (GAS_mlp->prob != NULL);
59
60 GAS_mlp->max_iterations = max_iterations;
61 GAS_mlp->max_exec_duration = max_duration;
62
63 /* Init LP solving parameters */
64 glp_init_smcp(&GAS_mlp->control_param_lp);
65 GAS_mlp->control_param_lp.it_lim = max_iterations;
66 GAS_mlp->control_param_lp.tm_lim = max_duration.rel_value;
67 /* Init MLP solving parameters */
68 glp_init_iocp(&GAS_mlp->control_param_mlp);
69 GAS_mlp->control_param_mlp.tm_lim = max_duration.rel_value;
70
71 return GNUNET_OK;
72}
73
74/**
75 * Updates a single address in the MLP problem
76 *
77 * If the address did not exist before in the problem:
78 * The MLP problem has to be recreated and the problem has to be resolved
79 *
80 * Otherwise the addresses' values can be updated and the existing base can
81 * be reused
82 */
83void
84GAS_mlp_address_update (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
85{
86
87}
88
89/**
90 * Deletes a single address in the MLP problem
91 *
92 * The MLP problem has to be recreated and the problem has to be resolved
93 */
94void
95GAS_mlp_address_delete (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
96{
97
98}
99
100/**
101 * Deletes a single address in the MLP problem
102 */
103void
104GAS_mlp_address_change_preference (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
105{
106
44} 107}
45 108
46/** 109/**
@@ -49,6 +112,12 @@ GAS_mlp_init ()
49void 112void
50GAS_mlp_done () 113GAS_mlp_done ()
51{ 114{
115 if (GAS_mlp != NULL)
116 glp_delete_prob(GAS_mlp->prob);
117
118 /* Clean up GLPK environment */
119 glp_free_env();
120
52 GNUNET_free (GAS_mlp); 121 GNUNET_free (GAS_mlp);
53} 122}
54 123
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 @@
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "gnunet-service-ats_addresses.h"
28#if HAVE_LIBGLPK 29#if HAVE_LIBGLPK
29#include "glpk.h" 30#include "glpk.h"
30#endif 31#endif
@@ -32,6 +33,10 @@
32#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H 33#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
33#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H 34#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
34 35
36
37#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
38#define MLP_MAX_ITERATIONS INT_MAX
39
35struct GAS_MLP_Handle 40struct GAS_MLP_Handle
36{ 41{
37 /** 42 /**
@@ -43,13 +48,42 @@ struct GAS_MLP_Handle
43 void *prob; 48 void *prob;
44#endif 49#endif
45 50
51 /**
52 * GLPK LP control parameter
53 */
54 glp_smcp control_param_lp;
55
56 /**
57 * GLPK LP control parameter
58 */
59 glp_iocp control_param_mlp;
60
61 /**
62 * Maximum execution time per problem solving
63 */
64 struct GNUNET_TIME_Relative max_exec_duration;
65
66 /**
67 * Maximum number of LP iterations per problem solving
68 */
69 unsigned int max_iterations;
70
46}; 71};
47 72
48/** 73/**
49 * Init the MLP problem solving component 74 * Init the MLP problem solving component
75 * @param max_duration maximum numbers of iterations for the LP/MLP Solver
76 * @param max_iterations maximum time limit for the LP/MLP Solver
77 * @return GNUNET_OK on success, GNUNET_SYSERR on fail
78 */
79int
80GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations);
81
82/**
83 * Update address in the MLP problem
50 */ 84 */
51void 85void
52GAS_mlp_init (); 86GAS_mlp_update (struct ATS_Address *address);
53 87
54/** 88/**
55 * Shutdown the MLP problem solving component 89 * Shutdown the MLP problem solving component