diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-12 14:49:27 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-12 14:49:27 +0000 |
commit | a89bc2071408040efd07c6b7fdd00a95b03ab10c (patch) | |
tree | 633e07f084efc2c26968379c84eb9b4212f758d9 /src | |
parent | 987e618a2240e7a8cf5c61e33af9bb413a118e7a (diff) | |
download | gnunet-a89bc2071408040efd07c6b7fdd00a95b03ab10c.tar.gz gnunet-a89bc2071408040efd07c6b7fdd00a95b03ab10c.zip |
- mlp
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/Makefile.am | 13 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 58 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 43 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 77 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 36 |
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 | |||
16 | if HAVE_LIBGLPK | 16 | if 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 | ||
19 | endif | 20 | endif |
20 | 21 | ||
21 | lib_LTLIBRARIES = libgnunetats.la | 22 | lib_LTLIBRARIES = libgnunetats.la |
@@ -50,7 +51,8 @@ gnunet_service_ats_LDADD = \ | |||
50 | 51 | ||
51 | 52 | ||
52 | check_PROGRAMS = \ | 53 | check_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 | |||
58 | TESTS = $(check_PROGRAMS) | 60 | TESTS = $(check_PROGRAMS) |
59 | endif | 61 | endif |
60 | 62 | ||
63 | if HAVE_LIBGLPK | ||
64 | test_ats_mlp_SOURCES = \ | ||
65 | $(GN_MLP_SRC) \ | ||
66 | test_ats_mlp.c | ||
67 | test_ats_mlp_LDADD = \ | ||
68 | $(GN_LIBGLPK) \ | ||
69 | $(top_builddir)/src/util/libgnunetutil.la | ||
70 | endif | ||
71 | |||
61 | test_ats_api_scheduling_SOURCES = \ | 72 | test_ats_api_scheduling_SOURCES = \ |
62 | test_ats_api_scheduling.c | 73 | test_ats_api_scheduling.c |
63 | test_ats_api_scheduling_LDADD = \ | 74 | 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 @@ | |||
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 | ||
36 | struct 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 | |||
79 | enum ATS_Mode | 36 | enum 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 | ||
34 | struct 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 | ||
34 | struct GAS_MLP_Handle *GAS_mlp; | 35 | /* |
36 | * The MLP handle | ||
37 | */ | ||
38 | static 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 | */ |
39 | void | 48 | int |
40 | GAS_mlp_init () | 49 | GAS_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 | */ | ||
83 | void | ||
84 | GAS_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 | */ | ||
94 | void | ||
95 | GAS_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 | */ | ||
103 | void | ||
104 | GAS_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 () | |||
49 | void | 112 | void |
50 | GAS_mlp_done () | 113 | GAS_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 | |||
35 | struct GAS_MLP_Handle | 40 | struct 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 | */ | ||
79 | int | ||
80 | GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations); | ||
81 | |||
82 | /** | ||
83 | * Update address in the MLP problem | ||
50 | */ | 84 | */ |
51 | void | 85 | void |
52 | GAS_mlp_init (); | 86 | GAS_mlp_update (struct ATS_Address *address); |
53 | 87 | ||
54 | /** | 88 | /** |
55 | * Shutdown the MLP problem solving component | 89 | * Shutdown the MLP problem solving component |