aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-11 14:46:51 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-11 14:46:51 +0000
commitf5c90ebc3dcaf15ec375016bd628717b92461d76 (patch)
treed347f83fa412a674345673e3b5a1f6f0a9c1d4e1 /src/ats
parentdf768b66a2456c07b95f69f8b0dd57b12234a346 (diff)
downloadgnunet-f5c90ebc3dcaf15ec375016bd628717b92461d76.tar.gz
gnunet-f5c90ebc3dcaf15ec375016bd628717b92461d76.zip
implemented ats info updates + initial address update (fixing issue of execution time peaks)
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/perf_ats_mlp.c110
1 files changed, 98 insertions, 12 deletions
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c
index cf61a1829..0da00ea10 100644
--- a/src/ats/perf_ats_mlp.c
+++ b/src/ats/perf_ats_mlp.c
@@ -100,7 +100,8 @@ struct GAS_MLP_Handle *mlp;
100 */ 100 */
101struct GNUNET_CONTAINER_MultiHashMap * addresses; 101struct GNUNET_CONTAINER_MultiHashMap * addresses;
102 102
103struct GNUNET_ATS_Information ats[3]; 103#define ATS_COUNT 2
104struct GNUNET_ATS_Information ats[2];
104 105
105struct PerfPeer *peers; 106struct PerfPeer *peers;
106 107
@@ -156,23 +157,85 @@ perf_create_address (int cp, int ca)
156 return a; 157 return a;
157} 158}
158 159
159 160static void
160static int 161address_initial_update (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
161update_address_it (void *cls, const struct GNUNET_HashCode *key, void * value)
162{ 162{
163 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
164 ats[0].value = htonl (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100));
163 165
164 return GNUNET_OK; 166 ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
167 ats[1].value = htonl (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10));
168
169 GAS_mlp_address_update (mlp, addresses, address, 0, GNUNET_YES, ats, 2);
165} 170}
166 171
172
167static void 173static void
168update_addresses (void) 174update_single_addresses (struct ATS_Address *cur)
169{ 175{
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating addresses %u addresses per peer \n", opt_update_quantity); 176 int r_type;
177 int r_val;
178
179 r_type = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2);
180 switch (r_type) {
181 case 0:
182 r_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100);
183 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
184 ats[0].value = htonl (r_val);
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' address %p type %s val %u\n",
186 GNUNET_i2s (&cur->peer), cur,
187 "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
188 break;
189 case 1:
190 r_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10);
191 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
192 ats[0].value = htonl (r_val);
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' address %p type %s val %u\n",
194 GNUNET_i2s (&cur->peer), cur,
195 "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
196 break;
197 default:
198 break;
199 }
200 GAS_mlp_address_update (mlp, addresses, cur, 0, GNUNET_YES, ats, 1);
201}
171 202
203static void
204update_addresses (unsigned int cp, unsigned int ca, unsigned int up_q)
205{
206 struct ATS_Address *cur;
207 int c_peer;
208 int c_select;
209 int c_addr;
210 int r;
172 211
173 GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_address_it, NULL); 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating addresses %u addresses per peer \n", up_q);
213 unsigned int m [ca];
174 214
215 for (c_peer = 0; c_peer < cp; c_peer++)
216 {
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s'\n", GNUNET_i2s (&peers[c_peer].id));
218 for (c_select = 0; c_select < ca; c_select++)
219 m[c_select] = 0;
220 c_select = 0;
221 while (c_select < opt_update_quantity)
222 {
223 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, ca);
224 if (0 == m[r])
225 {
226 m[r] = 1;
227 c_select++;
228 }
229 }
175 230
231 c_addr = 0;
232 for (cur = peers[c_peer].head; NULL != cur; cur = cur->next)
233 {
234 if (1 == m[c_addr])
235 update_single_addresses (cur);
236 c_addr ++;
237 }
238 }
176} 239}
177 240
178 241
@@ -242,13 +305,13 @@ check (void *cls, char *const *args, const char *cfgfile,
242 cur_addr = perf_create_address(cp, ca); 305 cur_addr = perf_create_address(cp, ca);
243 /* add address */ 306 /* add address */
244 GAS_mlp_address_add (mlp, addresses, cur_addr); 307 GAS_mlp_address_add (mlp, addresses, cur_addr);
308 address_initial_update (mlp, addresses, cur_addr);
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer %u address %u: \n", cp, ca); 309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer %u address %u: \n", cp, ca);
246 } 310 }
247 GAS_mlp_get_preferred_address( mlp, addresses, &peers[cp].id); 311 GAS_mlp_get_preferred_address( mlp, addresses, &peers[cp].id);
248 /* solve */ 312 /* solve */
249 if (cp + 1 >= N_peers_start) 313 if (cp + 1 >= N_peers_start)
250 { 314 {
251
252 GAS_mlp_solve_problem (mlp, addresses); 315 GAS_mlp_solve_problem (mlp, addresses);
253 if (GNUNET_NO == opt_numeric) 316 if (GNUNET_NO == opt_numeric)
254 fprintf (stderr, "%u peers each %u addresses; LP/MIP state [%s/%s] presolv [%s/%s], (build/LP/MIP in ms): %04llu %04llu %04llu; size (cols x rows, nonzero elements): [%u x %u] = %u\n", 317 fprintf (stderr, "%u peers each %u addresses; LP/MIP state [%s/%s] presolv [%s/%s], (build/LP/MIP in ms): %04llu %04llu %04llu; size (cols x rows, nonzero elements): [%u x %u] = %u\n",
@@ -275,9 +338,32 @@ check (void *cls, char *const *args, const char *cfgfile,
275 if ((0 < opt_update_quantity) || (0 < opt_update_percent)) 338 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
276 { 339 {
277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem with %u peers and %u addresses\n", cp + 1, ca); 340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
278 update_addresses (); 341 update_addresses (cp + 1, ca, opt_update_quantity);
279 GAS_mlp_solve_problem (mlp, addresses); 342 GAS_mlp_solve_problem (mlp, addresses);
343 if (GNUNET_NO == opt_numeric)
344 fprintf (stderr, "%u peers each %u addresses; LP/MIP state [%s/%s] presolv [%s/%s], (build/LP/MIP in ms): %04llu %04llu %04llu; size (cols x rows, nonzero elements): [%u x %u] = %u\n",
345 cp + 1, ca,
346 (GNUNET_OK == mlp->ps.lp_res) ? "OK" : "FAIL",
347 (GNUNET_OK == mlp->ps.mip_res) ? "OK" : "FAIL",
348 (GLP_YES == mlp->ps.lp_presolv) ? "YES" : "NO",
349 (GNUNET_OK == mlp->ps.mip_presolv) ? "YES" : "NO",
350 (unsigned long long) mlp->ps.build_dur.rel_value,
351 (unsigned long long) mlp->ps.lp_dur.rel_value,
352 (unsigned long long) mlp->ps.mip_dur.rel_value,
353 mlp->ps.p_cols, mlp->ps.p_rows, mlp->ps.p_elements);
354 else
355 fprintf (stderr, "%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu;%u;%u;%u\n",
356 cp + 1, ca,
357 (GNUNET_OK == mlp->ps.lp_res) ? "OK" : "FAIL",
358 (GNUNET_OK == mlp->ps.mip_res) ? "OK" : "FAIL",
359 (GLP_YES == mlp->ps.lp_presolv) ? "YES" : "NO",
360 (GNUNET_OK == mlp->ps.mip_presolv) ? "YES" : "NO",
361 (unsigned long long) mlp->ps.build_dur.rel_value,
362 (unsigned long long) mlp->ps.lp_dur.rel_value,
363 (unsigned long long) mlp->ps.mip_dur.rel_value,
364 mlp->ps.p_cols, mlp->ps.p_rows, mlp->ps.p_elements);
280 } 365 }
366 fprintf (stderr, "\n");
281 } 367 }
282 } 368 }
283 369
@@ -386,9 +472,9 @@ main (int argc, char *argv[])
386 if (0 == N_address) 472 if (0 == N_address)
387 N_address = ADDRESSES; 473 N_address = ADDRESSES;
388 474
389 if (opt_update_quantity >= N_address) 475 if (opt_update_quantity > N_address)
390 { 476 {
391 fprintf (stderr, _("Trying to Update more addresses than we have per peer!")); 477 fprintf (stderr, _("Trying to update more addresses than we have per peer! (%u vs %u)"), opt_update_quantity, N_address);
392 exit (1); 478 exit (1);
393 } 479 }
394 480