diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-11 16:43:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-11 16:43:25 +0000 |
commit | d927e4cf8a05f8e2a29ebb5a6f37224f80f93648 (patch) | |
tree | 0e8822cea1a0097c50817ae655e6b15682bfe792 /src/ats | |
parent | 50e17d63c37dc0b35b6b7302144e47659653c058 (diff) | |
download | gnunet-d927e4cf8a05f8e2a29ebb5a6f37224f80f93648.tar.gz gnunet-d927e4cf8a05f8e2a29ebb5a6f37224f80f93648.zip |
-testcase was long dead
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/test_ats_mlp_averaging.c | 266 |
1 files changed, 0 insertions, 266 deletions
diff --git a/src/ats/test_ats_mlp_averaging.c b/src/ats/test_ats_mlp_averaging.c deleted file mode 100644 index 1a2333fac..000000000 --- a/src/ats/test_ats_mlp_averaging.c +++ /dev/null | |||
@@ -1,266 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file ats/test_ats_mlp.c | ||
22 | * @brief test for the MLP solver | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | |||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_statistics_service.h" | ||
30 | #include "gnunet_ats_service.h" | ||
31 | #include "gnunet-service-ats_addresses_mlp.h" | ||
32 | |||
33 | #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) | ||
34 | #define MLP_MAX_ITERATIONS INT_MAX | ||
35 | |||
36 | |||
37 | static int ret; | ||
38 | |||
39 | struct GNUNET_STATISTICS_Handle *stats; | ||
40 | |||
41 | struct GNUNET_CONTAINER_MultiPeerMap *addresses; | ||
42 | |||
43 | struct GAS_MLP_Handle *mlp; | ||
44 | |||
45 | |||
46 | static void | ||
47 | create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats) | ||
48 | { | ||
49 | addr->solver_information = NULL; | ||
50 | addr->next = NULL; | ||
51 | addr->prev = NULL; | ||
52 | addr->plugin = GNUNET_strdup (plugin); | ||
53 | addr->ats_count = ats_count; | ||
54 | addr->ats = ats; | ||
55 | } | ||
56 | |||
57 | static void | ||
58 | set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value) | ||
59 | { | ||
60 | ats->type = type; | ||
61 | ats->value = value; | ||
62 | } | ||
63 | |||
64 | static unsigned int | ||
65 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length) | ||
66 | { | ||
67 | int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | ||
68 | char * entry_in = NULL; | ||
69 | char * entry_out = NULL; | ||
70 | char * quota_out_str; | ||
71 | char * quota_in_str; | ||
72 | int c; | ||
73 | |||
74 | for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++) | ||
75 | { | ||
76 | in_dest[c] = 0; | ||
77 | out_dest[c] = 0; | ||
78 | switch (quotas[c]) { | ||
79 | case GNUNET_ATS_NET_UNSPECIFIED: | ||
80 | entry_out = "UNSPECIFIED_QUOTA_OUT"; | ||
81 | entry_in = "UNSPECIFIED_QUOTA_IN"; | ||
82 | break; | ||
83 | case GNUNET_ATS_NET_LOOPBACK: | ||
84 | entry_out = "LOOPBACK_QUOTA_OUT"; | ||
85 | entry_in = "LOOPBACK_QUOTA_IN"; | ||
86 | break; | ||
87 | case GNUNET_ATS_NET_LAN: | ||
88 | entry_out = "LAN_QUOTA_OUT"; | ||
89 | entry_in = "LAN_QUOTA_IN"; | ||
90 | break; | ||
91 | case GNUNET_ATS_NET_WAN: | ||
92 | entry_out = "WAN_QUOTA_OUT"; | ||
93 | entry_in = "WAN_QUOTA_IN"; | ||
94 | break; | ||
95 | case GNUNET_ATS_NET_WLAN: | ||
96 | entry_out = "WLAN_QUOTA_OUT"; | ||
97 | entry_in = "WLAN_QUOTA_IN"; | ||
98 | break; | ||
99 | default: | ||
100 | break; | ||
101 | } | ||
102 | |||
103 | if ((entry_in == NULL) || (entry_out == NULL)) | ||
104 | continue; | ||
105 | |||
106 | /* quota out */ | ||
107 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | ||
108 | { | ||
109 | if (0 == strcmp(quota_out_str, BIG_M_STRING) || | ||
110 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) | ||
111 | out_dest[c] = UINT32_MAX; | ||
112 | |||
113 | GNUNET_free (quota_out_str); | ||
114 | quota_out_str = NULL; | ||
115 | } | ||
116 | else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c]) | ||
117 | out_dest[c] = UINT32_MAX; | ||
118 | else | ||
119 | out_dest[c] = UINT32_MAX; | ||
120 | |||
121 | /* quota in */ | ||
122 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) | ||
123 | { | ||
124 | if (0 == strcmp(quota_in_str, BIG_M_STRING) || | ||
125 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) | ||
126 | in_dest[c] = UINT32_MAX; | ||
127 | |||
128 | GNUNET_free (quota_in_str); | ||
129 | quota_in_str = NULL; | ||
130 | } | ||
131 | else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c]) | ||
132 | { | ||
133 | in_dest[c] = UINT32_MAX; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | in_dest[c] = UINT32_MAX; | ||
138 | } | ||
139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota: %s %u, %s %u\n", entry_in, in_dest[c], entry_out, out_dest[c]); | ||
140 | |||
141 | } | ||
142 | return GNUNET_ATS_NetworkTypeCount; | ||
143 | } | ||
144 | |||
145 | |||
146 | static void | ||
147 | check (void *cls, char *const *args, const char *cfgfile, | ||
148 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
149 | { | ||
150 | #if !HAVE_LIBGLPK | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); | ||
152 | ret = 1; | ||
153 | return; | ||
154 | #endif | ||
155 | struct ATS_Address addr[10]; | ||
156 | struct ATS_Address *res[10]; | ||
157 | int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | ||
158 | unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; | ||
159 | unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; | ||
160 | int quota_count; | ||
161 | // struct MLP_information *mlpi; | ||
162 | struct GAS_MLP_SolutionContext ctx; | ||
163 | |||
164 | stats = GNUNET_STATISTICS_create("ats", cfg); | ||
165 | |||
166 | addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | ||
167 | |||
168 | quota_count = load_quotas(cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount); | ||
169 | mlp = GAS_mlp_init (cfg, NULL, quotas, quotas_in, quotas_out, quota_count); | ||
170 | mlp->auto_solve = GNUNET_NO; | ||
171 | |||
172 | struct GNUNET_PeerIdentity p[10]; | ||
173 | |||
174 | /* Creating peer 1 */ | ||
175 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[0].hashPubKey); | ||
176 | |||
177 | /* Creating peer 1 address 1 */ | ||
178 | addr[0].peer.hashPubKey = p[0].hashPubKey; | ||
179 | struct GNUNET_ATS_Information a1_ats[3]; | ||
180 | set_ats (&a1_ats[0], GNUNET_ATS_QUALITY_NET_DISTANCE, 1); | ||
181 | set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 0); | ||
182 | set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0); | ||
183 | create_address (&addr[0], "dummy", 3, &a1_ats[0]); | ||
184 | addr[0].atsp_network_type = GNUNET_ATS_NET_LAN; | ||
185 | |||
186 | GNUNET_CONTAINER_multipeermap_put(addresses, &addr[0].peer, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
187 | |||
188 | /* Add peer 1 address 1 */ | ||
189 | GAS_mlp_address_update (mlp, addresses, &addr[0]); | ||
190 | // mlpi = addr[0].mlp_information; | ||
191 | |||
192 | GNUNET_assert (mlp != NULL); | ||
193 | GNUNET_assert (mlp->addresses_in_problem == 1); | ||
194 | |||
195 | /* Update an peer 1 address 1 */ | ||
196 | set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 20); | ||
197 | GAS_mlp_address_update (mlp, addresses, &addr[0]); | ||
198 | GNUNET_assert (mlp->addresses_in_problem == 1); | ||
199 | |||
200 | |||
201 | /* Update an peer 1 address 1 */ | ||
202 | set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 10); | ||
203 | GAS_mlp_address_update (mlp, addresses, &addr[0]); | ||
204 | GNUNET_assert (mlp->addresses_in_problem == 1); | ||
205 | |||
206 | /* Update an peer 1 address 1 */ | ||
207 | set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 10); | ||
208 | GAS_mlp_address_update (mlp, addresses, &addr[0]); | ||
209 | GNUNET_assert (mlp->addresses_in_problem == 1); | ||
210 | |||
211 | /* Update an peer 1 address 1 */ | ||
212 | set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 30); | ||
213 | GAS_mlp_address_update (mlp, addresses, &addr[0]); | ||
214 | GNUNET_assert (mlp->addresses_in_problem == 1); | ||
215 | |||
216 | |||
217 | GNUNET_assert (GNUNET_OK == GAS_mlp_solve_problem(mlp, &ctx)); | ||
218 | GNUNET_assert (GNUNET_OK == ctx.lp_result); | ||
219 | GNUNET_assert (GNUNET_OK == ctx.mlp_result); | ||
220 | |||
221 | res[0] = GAS_mlp_get_preferred_address(mlp, addresses, &p[0]); | ||
222 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
223 | "Preferred address `%s' outbound bandwidth: %u Bps\n", | ||
224 | res[0]->plugin, | ||
225 | (unsigned int) ntohl (res[0]->assigned_bw_out.value__)); | ||
226 | |||
227 | /* Delete an address */ | ||
228 | GNUNET_CONTAINER_multipeermap_remove (addresses, &addr[0].peer, &addr[0]); | ||
229 | GAS_mlp_address_delete (mlp, addresses, &addr[0]); | ||
230 | |||
231 | GNUNET_assert (mlp->addresses_in_problem == 0); | ||
232 | |||
233 | GAS_mlp_done (mlp); | ||
234 | |||
235 | GNUNET_free (addr[0].plugin); | ||
236 | GNUNET_CONTAINER_multihashmap_destroy (addresses); | ||
237 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | ||
238 | |||
239 | ret = 0; | ||
240 | } | ||
241 | |||
242 | |||
243 | int | ||
244 | main (int argc, char *argv[]) | ||
245 | { | ||
246 | |||
247 | static char *const argv2[] = { "test_ats_mlp", | ||
248 | "-c", | ||
249 | "test_ats_api.conf", | ||
250 | "-L", "WARNING", | ||
251 | NULL | ||
252 | }; | ||
253 | |||
254 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
255 | GNUNET_GETOPT_OPTION_END | ||
256 | }; | ||
257 | |||
258 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
259 | "test_ats_mlp_averaging", "nohelp", options, | ||
260 | &check, NULL); | ||
261 | |||
262 | |||
263 | return ret; | ||
264 | } | ||
265 | |||
266 | /* end of file test_ats_mlp_averaging.c */ | ||