summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-10-29 15:44:24 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-10-29 15:44:24 +0000
commitb6e3ab8c3be136e6b6cb5e1e68f3ad5eda47faa2 (patch)
tree59a9de14e49e4430b4840b70a8b98120a0a7a605
parent4e54bdcddfad714651eb193864d93f60a8a0d53b (diff)
downloadgnunet-b6e3ab8c3be136e6b6cb5e1e68f3ad5eda47faa2.tar.gz
gnunet-b6e3ab8c3be136e6b6cb5e1e68f3ad5eda47faa2.zip
next steps to generic perf test
-rw-r--r--src/ats/Makefile.am6
-rw-r--r--src/ats/libgnunet_plugin_ats_proportional.c1
-rw-r--r--src/ats/perf_ats_solver.c659
3 files changed, 302 insertions, 364 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 83bb6e406..2420446cb 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -437,7 +437,7 @@ test_ats_solver_alternative_after_delete_address_ril_LDADD = \
437# $(top_builddir)/src/ats/libgnunetats.la 437# $(top_builddir)/src/ats/libgnunetats.la
438 438
439perf_ats_solver_mlp_SOURCES = \ 439perf_ats_solver_mlp_SOURCES = \
440 perf_ats_solver.c 440 perf_ats_solver.c test_ats_api_common.c gnunet-service-ats_normalization.c
441perf_ats_solver_mlp_LDADD = \ 441perf_ats_solver_mlp_LDADD = \
442 $(GN_LIBGLPK) \ 442 $(GN_LIBGLPK) \
443 $(top_builddir)/src/util/libgnunetutil.la \ 443 $(top_builddir)/src/util/libgnunetutil.la \
@@ -445,7 +445,7 @@ perf_ats_solver_mlp_LDADD = \
445 $(top_builddir)/src/ats/libgnunetats.la 445 $(top_builddir)/src/ats/libgnunetats.la
446 446
447perf_ats_solver_proportional_SOURCES = \ 447perf_ats_solver_proportional_SOURCES = \
448 perf_ats_solver.c 448 perf_ats_solver.c test_ats_api_common.c gnunet-service-ats_normalization.c
449perf_ats_solver_proportional_LDADD = \ 449perf_ats_solver_proportional_LDADD = \
450 $(GN_LIBGLPK) \ 450 $(GN_LIBGLPK) \
451 $(top_builddir)/src/util/libgnunetutil.la \ 451 $(top_builddir)/src/util/libgnunetutil.la \
@@ -453,7 +453,7 @@ perf_ats_solver_proportional_LDADD = \
453 $(top_builddir)/src/ats/libgnunetats.la 453 $(top_builddir)/src/ats/libgnunetats.la
454 454
455perf_ats_solver_ril_SOURCES = \ 455perf_ats_solver_ril_SOURCES = \
456 perf_ats_solver.c 456 perf_ats_solver.c test_ats_api_common.c gnunet-service-ats_normalization.c
457perf_ats_solver_ril_LDADD = \ 457perf_ats_solver_ril_LDADD = \
458 $(GN_LIBGLPK) \ 458 $(GN_LIBGLPK) \
459 $(top_builddir)/src/util/libgnunetutil.la \ 459 $(top_builddir)/src/util/libgnunetutil.la \
diff --git a/src/ats/libgnunet_plugin_ats_proportional.c b/src/ats/libgnunet_plugin_ats_proportional.c
index 98e33cadf..8ae4d3617 100644
--- a/src/ats/libgnunet_plugin_ats_proportional.c
+++ b/src/ats/libgnunet_plugin_ats_proportional.c
@@ -830,7 +830,6 @@ get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type)
830 { 830 {
831 if (s->network_entries[c].type == type) 831 if (s->network_entries[c].type == type)
832 return &s->network_entries[c]; 832 return &s->network_entries[c];
833
834 } 833 }
835 return NULL ; 834 return NULL ;
836} 835}
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c
index 3b03f44c7..36863755a 100644
--- a/src/ats/perf_ats_solver.c
+++ b/src/ats/perf_ats_solver.c
@@ -18,26 +18,90 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 */ 19 */
20/** 20/**
21 * @file ats/perf_ats_mlp 21 * @file ats/perf_ats_solver.c
22 * @brief performance test for the MLP solver 22 * @brief generic performance test for ATS solvers
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25
26 */ 25 */
27#include "platform.h" 26#include "platform.h"
28#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
29#include "gnunet_statistics_service.h" 28#include "gnunet_statistics_service.h"
29#include "gnunet-service-ats_addresses.h"
30#include "gnunet-service-ats_normalization.h"
30#include "gnunet_ats_service.h" 31#include "gnunet_ats_service.h"
31#include "gnunet_ats_plugin.h" 32#include "gnunet_ats_plugin.h"
32#include "test_ats_api_common.h" 33#include "test_ats_api_common.h"
33 34
34#define PEERS_START 100 35#define DEFAULT_PEERS_START 100
35#define PEERS_END 100 36#define DEFAULT_PEERS_END 100
37#define DEFAULT_ADDRESSES 10
38#define DEFAULT_ATS_COUNT 2
39
40/**
41 * Handle for ATS address component
42 */
43struct PerfHandle
44{
45 struct PerfPeer *peers;
46
47 /**
48 * #peers to start benchmarking with
49 */
50 int N_peers_start;
36 51
37#define ADDRESSES 10 52 /**
53 * #peers to end benchmarking with
54 */
55 int N_peers_end;
38 56
39int count_p; 57 /**
40int count_a; 58 * #addresses to benchmarking with
59 */
60 int N_address;
61
62 int opt_numeric;
63 int opt_dump;
64 int opt_update_percent;
65 int opt_update_quantity;
66
67 char *ats_string;
68
69 /**
70 *
71 */
72 struct GNUNET_STATISTICS_Handle *stat;
73
74 /**
75 * A multihashmap to store all addresses
76 */
77 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
78
79
80 /**
81 * Configured ATS solver
82 */
83 int ats_mode;
84
85 /**
86 * Solver handle
87 */
88 void *solver;
89
90 /**
91 * Address suggestion requests DLL head
92 */
93 struct GAS_Addresses_Suggestion_Requests *r_head;
94
95 /**
96 * Address suggestion requests DLL tail
97 */
98 struct GAS_Addresses_Suggestion_Requests *r_tail;
99
100 /* Solver functions */
101 struct GNUNET_ATS_PluginEnvironment env;
102
103 char *plugin;
104};
41 105
42struct PerfPeer 106struct PerfPeer
43{ 107{
@@ -47,43 +111,31 @@ struct PerfPeer
47 struct ATS_Address *tail; 111 struct ATS_Address *tail;
48}; 112};
49 113
50static int ret; 114static struct PerfHandle ph;
51static int opt_numeric;
52static int opt_dump;
53static int opt_update_percent;
54static int opt_update_quantity;
55 115
56static int N_peers_start;
57static int N_peers_end;
58static int N_address;
59 116
60/** 117int count_p;
61 * Statistics handle 118int count_a;
62 */
63struct GNUNET_STATISTICS_Handle * stats;
64 119
65/** 120/**
66 * MLP solver handle 121 * Return value
67 */ 122 */
68struct GAS_MLP_Handle *mlp; 123static int ret;
124
69 125
70/** 126/**
71 * Hashmap containing addresses 127 * ATS information
72 */ 128 */
73struct GNUNET_CONTAINER_MultiHashMap * addresses; 129//static struct GNUNET_ATS_Information ats[2];
74 130
75#define ATS_COUNT 2
76struct GNUNET_ATS_Information ats[2];
77 131
78struct PerfPeer *peers;
79#if 0
80static void 132static void
81end_now (int res) 133end_now (int res)
82{ 134{
83 if (NULL != stats) 135 if (NULL != ph.stat)
84 { 136 {
85 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 137 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
86 stats = NULL; 138 ph.stat = NULL;
87 } 139 }
88 /* 140 /*
89 if (NULL != addresses) 141 if (NULL != addresses)
@@ -92,80 +144,27 @@ end_now (int res)
92 GNUNET_CONTAINER_multihashmap_destroy (addresses); 144 GNUNET_CONTAINER_multihashmap_destroy (addresses);
93 addresses = NULL ; 145 addresses = NULL ;
94 }*/ 146 }*/
95 if (NULL != peers) 147 if (NULL != ph.peers)
96 { 148 {
97 GNUNET_free(peers); 149 GNUNET_free(ph.peers);
98 }
99 if (NULL != mlp)
100 {
101 GAS_mlp_done (mlp);
102 mlp = NULL;
103 } 150 }
151
104 GAS_normalization_stop (); 152 GAS_normalization_stop ();
105 ret = res; 153 ret = res;
106} 154}
107 155
108static void
109bandwidth_changed_cb (void *cls, struct ATS_Address *address)
110{
111
112}
113
114static void
115normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
116 uint32_t type, double prop_rel)
117{
118 /* TODO */
119}
120
121const double *
122get_property_cb (void *cls, const struct ATS_Address *address)
123{
124 return GAS_normalization_get_properties ((struct ATS_Address *) address);
125}
126
127static const double *
128get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
129{
130 return GAS_normalization_get_preferences (id);
131}
132 156
133static void 157static void
134perf_create_peer (int cp) 158perf_create_peer (int cp)
135{ 159{
160 /*
136 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 161 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
137 &peers[cp].id.hashPubKey); 162 &ph.peers[cp].id.);*/
138 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, 163 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
139 GNUNET_i2s (&peers[cp].id)); 164 GNUNET_i2s (&ph.peers[cp].id));
140}
141
142static struct ATS_Address *
143perf_create_address (int cp, int ca)
144{
145 struct ATS_Address *a;
146 a = create_address (&peers[cp].id, "Test 1", "test 1", strlen ("test 1") + 1,
147 0);
148 GNUNET_CONTAINER_DLL_insert(peers[cp].head, peers[cp].tail, a);
149 GNUNET_CONTAINER_multihashmap_put (addresses, &peers[cp].id.hashPubKey, a,
150 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
151 return a;
152} 165}
153 166
154static void
155address_initial_update (void *solver,
156 struct GNUNET_CONTAINER_MultiHashMap * addresses,
157 struct ATS_Address *address)
158{
159 GAS_mlp_address_property_changed (mlp, address, GNUNET_ATS_QUALITY_NET_DELAY,
160 100,
161 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
162 / 100);
163 167
164 GAS_mlp_address_property_changed (mlp, address,
165 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
166 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
167 / 100);
168}
169 168
170static void 169static void
171update_single_addresses (struct ATS_Address *cur) 170update_single_addresses (struct ATS_Address *cur)
@@ -181,7 +180,8 @@ update_single_addresses (struct ATS_Address *cur)
181 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 180 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
182 "Updating peer `%s' address %p type %s val %u\n", 181 "Updating peer `%s' address %p type %s val %u\n",
183 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val); 182 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
184 GAS_mlp_address_property_changed (mlp, cur, GNUNET_ATS_QUALITY_NET_DELAY, 183 ph.env.sf.s_address_update_property (ph.solver, cur,
184 GNUNET_ATS_QUALITY_NET_DELAY,
185 r_val, (double) (100 + r_val / 100)); 185 r_val, (double) (100 + r_val / 100));
186 break; 186 break;
187 case 1: 187 case 1:
@@ -190,14 +190,58 @@ update_single_addresses (struct ATS_Address *cur)
190 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
191 "Updating peer `%s' address %p type %s val %u\n", 191 "Updating peer `%s' address %p type %s val %u\n",
192 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val); 192 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
193 GAS_mlp_address_property_changed (mlp, cur, GNUNET_ATS_QUALITY_NET_DISTANCE, 193 ph.env.sf.s_address_update_property (ph.solver, cur,
194 GNUNET_ATS_QUALITY_NET_DISTANCE,
194 r_val, (double) (100 + r_val) / 100); 195 r_val, (double) (100 + r_val) / 100);
195 break; 196 break;
196 default: 197 default:
197 break; 198 break;
198 } 199 }
199 GAS_mlp_address_inuse_changed (mlp, cur, GNUNET_YES); 200 ph.env.sf.s_address_update_inuse (ph.solver, cur, GNUNET_YES);
201}
202
203
200 204
205static void
206bandwidth_changed_cb (void *cls, struct ATS_Address *address)
207{
208 return;
209}
210
211const double *
212get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
213{
214 return GAS_normalization_get_preferences (id);
215}
216
217
218const double *
219get_property_cb (void *cls, const struct ATS_Address *address)
220{
221 return GAS_normalization_get_properties ((struct ATS_Address *) address);
222}
223
224static void
225normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
226 uint32_t type, double prop_rel)
227{
228 /* TODO */
229}
230
231static void
232address_initial_update (void *solver,
233 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
234 struct ATS_Address *address)
235{
236 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
237 100,
238 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
239 / 100);
240
241 ph.env.sf.s_address_update_property (solver, address,
242 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
243 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
244 / 100);
201} 245}
202 246
203static void 247static void
@@ -216,11 +260,11 @@ update_addresses (unsigned int cp, unsigned int ca, unsigned int up_q)
216 for (c_peer = 0; c_peer < cp; c_peer++) 260 for (c_peer = 0; c_peer < cp; c_peer++)
217 { 261 {
218 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s'\n", 262 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s'\n",
219 GNUNET_i2s (&peers[c_peer].id)); 263 GNUNET_i2s (&ph.peers[c_peer].id));
220 for (c_select = 0; c_select < ca; c_select++) 264 for (c_select = 0; c_select < ca; c_select++)
221 m[c_select] = 0; 265 m[c_select] = 0;
222 c_select = 0; 266 c_select = 0;
223 while (c_select < opt_update_quantity) 267 while (c_select < ph.opt_update_quantity)
224 { 268 {
225 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca); 269 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
226 if (0 == m[r]) 270 if (0 == m[r])
@@ -231,7 +275,7 @@ update_addresses (unsigned int cp, unsigned int ca, unsigned int up_q)
231 } 275 }
232 276
233 c_addr = 0; 277 c_addr = 0;
234 for (cur = peers[c_peer].head; NULL != cur; cur = cur->next) 278 for (cur = ph.peers[c_peer].head; NULL != cur; cur = cur->next)
235 { 279 {
236 if (1 == m[c_addr]) 280 if (1 == m[c_addr])
237 update_single_addresses (cur); 281 update_single_addresses (cur);
@@ -239,300 +283,98 @@ update_addresses (unsigned int cp, unsigned int ca, unsigned int up_q)
239 } 283 }
240 } 284 }
241} 285}
242#endif
243 286
244 287
288static struct ATS_Address *
289perf_create_address (int cp, int ca)
290{
291 struct ATS_Address *a;
292 a = create_address (&ph.peers[cp].id, "Test 1", "test 1", strlen ("test 1") + 1,
293 0);
294 GNUNET_CONTAINER_DLL_insert(ph.peers[cp].head, ph.peers[cp].tail, a);
295 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
296 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
297 return a;
298}
299
245static void 300static void
246check (void *cls, char * const *args, const char *cfgfile, 301check ()
247 const struct GNUNET_CONFIGURATION_Handle *cfg)
248{ 302{
249#if 0 303 struct ATS_Address *cur;
250 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; 304 struct ATS_Address *next;
251 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
252 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
253 int cp; 305 int cp;
254 int ca; 306 int ca;
307 int count_p = ph.N_peers_end;
308 int count_a = ph.N_address;
255 struct ATS_Address * cur_addr; 309 struct ATS_Address * cur_addr;
256 310 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
257 int full_lp_res;
258 int full_mip_res;
259 int full_lp_presolv;
260 int full_mip_presolv;
261 struct GNUNET_TIME_Relative full_build_dur;
262 struct GNUNET_TIME_Relative full_lp_dur;
263 struct GNUNET_TIME_Relative full_mip_dur;
264
265 int update_lp_res;
266 int update_mip_res;
267 int update_lp_presolv;
268 int update_mip_presolv;
269 struct GNUNET_TIME_Relative update_build_dur;
270 struct GNUNET_TIME_Relative update_lp_dur;
271 struct GNUNET_TIME_Relative update_mip_dur;
272
273 stats = GNUNET_STATISTICS_create ("ats", cfg);
274 if (NULL == stats)
275 {
276 GNUNET_break(0);
277 end_now (1);
278 return;
279 }
280 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
281 /* Load quotas */
282 if (GNUNET_ATS_NetworkTypeCount
283 != load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
284 {
285 GNUNET_break(0);
286 end_now (1);
287 return;
288 }
289
290 GNUNET_assert(N_peers_end >= N_peers_start);
291 GNUNET_assert(N_address >= 0);
292
293 fprintf (stderr, "Solving problem for %u..%u peers with %u addresses\n",
294 N_peers_start, N_peers_end, N_address);
295
296 count_p = N_peers_end;
297 count_a = N_address;
298 peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
299 /* Setup address hashmap */
300 addresses = GNUNET_CONTAINER_multihashmap_create (N_address, GNUNET_NO);
301
302 /* Init MLP solver */
303 mlp = GAS_mlp_init (cfg, stats, addresses, quotas, quotas_out, quotas_in,
304 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL,
305 &get_preferences_cb, NULL, &get_property_cb, NULL );
306 if (NULL == mlp)
307 {
308 GNUNET_break(0);
309 end_now (1);
310 return;
311 }
312 mlp->mlp_auto_solve = GNUNET_NO;
313 mlp->write_mip_mps = opt_dump;
314 mlp->write_mip_sol = opt_dump;
315 311
316 for (cp = 0; cp < count_p; cp++) 312 for (cp = 0; cp < count_p; cp++)
317 perf_create_peer (cp); 313 perf_create_peer (cp);
318 314
319 if (GNUNET_YES == opt_numeric)
320 fprintf (stderr,
321 "#peers;#addresses per peer;LP/MIP state;presolv;exec build in ms;exec LP in ms; exec MIP in ms;#cols;#rows;#nonzero elements\n");
322
323 for (cp = 0; cp < count_p; cp++) 315 for (cp = 0; cp < count_p; cp++)
324 { 316 {
325 for (ca = 0; ca < count_a; ca++) 317 for (ca = 0; ca < count_a; ca++)
326 { 318 {
327 cur_addr = perf_create_address (cp, ca); 319 cur_addr = perf_create_address (cp, ca);
328 /* add address */ 320 /* add address */
329 GAS_mlp_address_add (mlp, cur_addr, GNUNET_ATS_NET_UNSPECIFIED); 321 ph.env.sf.s_add (ph.solver, cur_addr, GNUNET_ATS_NET_LAN);
330 address_initial_update (mlp, addresses, cur_addr); 322 address_initial_update (ph.solver, ph.addresses, cur_addr);
331 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 323 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
332 "Adding address for peer %u address %u: \n", cp, ca); 324 "Adding address for peer %u address %u\n", cp, ca);
333 } 325 }
334 GAS_mlp_get_preferred_address (mlp, &peers[cp].id); 326 //ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
335 /* solve */ 327 if (cp + 1 >= ph.N_peers_start)
336 if (cp + 1 >= N_peers_start)
337 { 328 {
338 329 /* Solve */
339 update_mip_dur = GNUNET_TIME_UNIT_FOREVER_REL; 330 if ((0 < ph.opt_update_quantity) || (0 < ph.opt_update_percent))
340 update_lp_dur = GNUNET_TIME_UNIT_FOREVER_REL;
341 update_build_dur = GNUNET_TIME_UNIT_FOREVER_REL;
342 update_mip_presolv = GNUNET_SYSERR;
343 update_lp_presolv = GNUNET_SYSERR;
344 update_mip_res = GNUNET_SYSERR;
345 update_lp_res = GNUNET_SYSERR;
346 /* Solve the full problem */
347 GAS_mlp_solve_problem (mlp);
348 full_lp_res = mlp->ps.lp_res;
349 full_mip_res = mlp->ps.mip_res;
350 full_lp_presolv = mlp->ps.lp_presolv;
351 full_mip_presolv = mlp->ps.mip_presolv;
352 full_build_dur = mlp->ps.build_dur;
353 full_lp_dur = mlp->ps.lp_dur;
354 full_mip_dur = mlp->ps.mip_dur;
355
356 /* Update and solve the problem */
357 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
358 { 331 {
332 /* Update */
359 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
360 "Updating problem with %u peers and %u addresses\n", cp + 1, ca); 334 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
361 update_addresses (cp + 1, ca, opt_update_quantity); 335 //ph.env.sf.s_bulk_start (ph.solver);
362 GAS_mlp_solve_problem (mlp); 336 //update_addresses (cp + 1, ca, ph.opt_update_quantity);
363 GAS_mlp_solve_problem (mlp); 337 //ph.env.sf.s_bulk_stop (ph.solver);
364 update_lp_res = mlp->ps.lp_res;
365 update_mip_res = mlp->ps.mip_res;
366 update_lp_presolv = mlp->ps.lp_presolv;
367 update_mip_presolv = mlp->ps.mip_presolv;
368 update_build_dur = mlp->ps.build_dur;
369 update_lp_dur = mlp->ps.lp_dur;
370 update_mip_dur = mlp->ps.mip_dur;
371
372 }
373 if (GNUNET_NO == opt_numeric)
374 {
375 fprintf (stderr,
376 "Rebuild: %03u peers each %02u addresses; rebuild: LP/MIP state [%3s/%3s] presolv [%3s/%3s], (build/LP/MIP in us) %04llu / %04llu / %04llu\n",
377 cp + 1, ca, (GNUNET_OK == full_lp_res) ? "OK" : "FAIL",
378 (GNUNET_OK == full_mip_res) ? "OK" : "FAIL",
379 (GLP_YES == full_lp_presolv) ? "YES" : "NO",
380 (GNUNET_OK == full_mip_presolv) ? "YES" : "NO",
381 (unsigned long long) full_build_dur.rel_value_us,
382 (unsigned long long) full_lp_dur.rel_value_us,
383 (unsigned long long) full_mip_dur.rel_value_us);
384 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
385 fprintf (stderr,
386 "Update: %03u peers each %02u addresses; rebuild: LP/MIP state [%3s/%3s] presolv [%3s/%3s], (build/LP/MIP in us) %04llu / %04llu / %04llu\n",
387 cp + 1, ca, (GNUNET_OK == update_lp_res) ? "OK" : "FAIL",
388 (GNUNET_OK == update_mip_res) ? "OK" : "FAIL",
389 (GLP_YES == update_lp_presolv) ? "YES" : "NO",
390 (GNUNET_OK == update_mip_presolv) ? "YES" : "NO",
391 (unsigned long long) update_build_dur.rel_value_us,
392 (unsigned long long) update_lp_dur.rel_value_us,
393 (unsigned long long) update_mip_dur.rel_value_us);
394 }
395 else
396 {
397 fprintf (stderr, "Rebuild;%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu\n",
398 cp + 1, ca, (GNUNET_OK == full_lp_res) ? "OK" : "FAIL",
399 (GNUNET_OK == full_mip_res) ? "OK" : "FAIL",
400 (GLP_YES == full_lp_presolv) ? "YES" : "NO",
401 (GNUNET_OK == full_mip_presolv) ? "YES" : "NO",
402 (unsigned long long) full_build_dur.rel_value_us,
403 (unsigned long long) full_lp_dur.rel_value_us,
404 (unsigned long long) full_mip_dur.rel_value_us);
405 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
406 fprintf (stderr, "Update;%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu\n",
407 cp + 1, ca, (GNUNET_OK == update_lp_res) ? "OK" : "FAIL",
408 (GNUNET_OK == update_mip_res) ? "OK" : "FAIL",
409 (GLP_YES == update_lp_presolv) ? "YES" : "NO",
410 (GNUNET_OK == update_mip_presolv) ? "YES" : "NO",
411 (unsigned long long) update_build_dur.rel_value_us,
412 (unsigned long long) update_lp_dur.rel_value_us,
413 (unsigned long long) update_mip_dur.rel_value_us);
414 } 338 }
415 } 339 }
416 } 340 }
417
418 struct ATS_Address *cur;
419 struct ATS_Address *next;
420 for (cp = 0; cp < count_p; cp++) 341 for (cp = 0; cp < count_p; cp++)
421 { 342 {
422 for (cur = peers[cp].head; cur != NULL ; cur = next) 343 for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
423 { 344 {
424 GAS_mlp_address_delete (mlp, cur, GNUNET_NO); 345 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
346 "Deleting addresses for peer %u\n", cp);
347 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
425 next = cur->next; 348 next = cur->next;
426 GNUNET_CONTAINER_DLL_remove(peers[cp].head, peers[cp].tail, cur); 349 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
427 GNUNET_free(cur); 350 GNUNET_free(cur);
428 } 351 }
429 352
430 } 353 }
431 GNUNET_free(peers); 354 GNUNET_free(ph.peers);
432#endif
433} 355}
434 356
435int 357
436main (int argc, char *argv[]) 358static void
359run (void *cls, char * const *args, const char *cfgfile,
360 const struct GNUNET_CONFIGURATION_Handle *cfg)
437{ 361{
362 GNUNET_log_setup ("perf-ats", "WARNING", NULL);
438 char *sep; 363 char *sep;
439 char *src_filename = GNUNET_strdup (__FILE__); 364 char *src_filename = GNUNET_strdup (__FILE__);
440 char *test_filename = GNUNET_strdup (argv[0]); 365 char *test_filename = cls;
441 char *config_file;
442 char *solver; 366 char *solver;
443 367 char *plugin;
444 static char * const argv2[] = { "perf_ats_mlp", "-c", "perf_ats_mlp.conf", 368 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
445 "-L", "WARNING", NULL }; 369 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
446
447 opt_dump = GNUNET_NO;
448 opt_update_quantity = 0;
449 opt_update_percent = 0;
450
451 N_peers_start = 0;
452 N_peers_end = 0;
453 N_address = 0;
454 int c; 370 int c;
455 /* extract command line arguments */
456 for (c = 0; c < argc; c++)
457 {
458 if ((0 == strcmp (argv[c], "-z")) && (c < (argc - 1)))
459 {
460 if (0 != atoi (argv[c + 1]))
461 {
462 N_peers_start = atoi (argv[c + 1]);
463 }
464 }
465 if ((0 == strcmp (argv[c], "-x")) && (c < (argc - 1)))
466 {
467 if (0 != atoi (argv[c + 1]))
468 {
469 N_peers_end = atoi (argv[c + 1]);
470 }
471 }
472 if ((0 == strcmp (argv[c], "-c")) && (c < (argc - 1)))
473 {
474 if (0 != atoi (argv[c + 1]))
475 {
476 N_address = atoi (argv[c + 1]);
477 }
478 }
479 if ((0 == strcmp (argv[c], "-n")))
480 {
481 opt_numeric = GNUNET_YES;
482 }
483 if ((0 == strcmp (argv[c], "-d")))
484 {
485 opt_dump = GNUNET_YES;
486 }
487 if ((0 == strcmp (argv[c], "-p")) && (c < (argc - 1)))
488 {
489 if (0 != atoi (argv[c + 1]))
490 {
491 /* Update a fix "p"ercentage of addresses */
492 opt_update_percent = atoi (argv[c + 1]);
493 if ((0 <= opt_update_percent) && (100 <= opt_update_percent))
494 {
495 fprintf (stderr, _("Percentage has to be: 0 <= p <= 100 ") );
496 exit (1);
497 }
498 }
499 }
500 if ((0 == strcmp (argv[c], "-q")) && (c < (argc - 1)))
501 {
502 if (0 != atoi (argv[c + 1]))
503 {
504 /* Update a fix "q"uantity of addresses */
505 opt_update_quantity = atoi (argv[c + 1]);
506 if (0 >= opt_update_quantity)
507 {
508 fprintf (stderr, _("Quantity has to be: p => 0 ") );
509 exit (1);
510 }
511 }
512 }
513 }
514
515 if ((0 == N_peers_start) && (0 == N_peers_end))
516 {
517 N_peers_start = PEERS_START;
518 N_peers_end = PEERS_END;
519 }
520 if (0 == N_address)
521 N_address = ADDRESSES;
522
523 if (opt_update_quantity > N_address)
524 {
525 fprintf (stderr,
526 _("Trying to update more addresses than we have per peer! (%u vs %u)"),
527 opt_update_quantity, N_address);
528 exit (1);
529 }
530 371
531 /* Extract test name */ 372 /* Extract test name */
532 if (NULL == (sep = (strstr (src_filename,".c")))) 373 if (NULL == (sep = (strstr (src_filename,".c"))))
533 { 374 {
534 GNUNET_break (0); 375 GNUNET_break (0);
535 return -1; 376 ret = 1;
377 return;
536 } 378 }
537 sep[0] = '\0'; 379 sep[0] = '\0';
538 380
@@ -542,43 +384,140 @@ main (int argc, char *argv[])
542 if (NULL == (solver = strstr (test_filename, src_filename))) 384 if (NULL == (solver = strstr (test_filename, src_filename)))
543 { 385 {
544 GNUNET_break (0); 386 GNUNET_break (0);
545 return -1; 387 ret = 1;
388 return ;
546 } 389 }
547 solver += strlen (src_filename) +1; 390 solver += strlen (src_filename) +1;
548 391
549 if (0 == strcmp(solver, "proportional")) 392 if (0 == strcmp(solver, "proportional"))
550 { 393 {
551 config_file = "perf_ats_solver_proportional.conf"; 394 ph.ats_mode = MODE_PROPORTIONAL;
395 ph.ats_string = "proportional";
552 } 396 }
553 else if (0 == strcmp(solver, "mlp")) 397 else if (0 == strcmp(solver, "mlp"))
554 { 398 {
555 config_file = "perf_ats_solver_mlp.conf"; 399 ph.ats_mode = MODE_MLP;
400 ph.ats_string = "mlp";
556 } 401 }
557 else if ((0 == strcmp(solver, "ril"))) 402 else if ((0 == strcmp(solver, "ril")))
558 { 403 {
559 config_file = "perf_ats_solver_ril.conf"; 404 ph.ats_mode = MODE_RIL;
405 ph.ats_string = "ril";
560 } 406 }
561 else 407 else
562 { 408 {
563 GNUNET_break (0);
564 GNUNET_free (src_filename); 409 GNUNET_free (src_filename);
565 GNUNET_free (test_filename); 410 GNUNET_break (0);
566 return 1; 411 ret = 1;
412 return ;
567 } 413 }
568
569 GNUNET_free (src_filename); 414 GNUNET_free (src_filename);
570 GNUNET_free (test_filename);
571 415
572 fprintf (stderr, "Using cfg file `%s'\n",config_file); 416 /* Calculcate peers */
573 return 0; 417 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
418 {
419 ph.N_peers_start = DEFAULT_PEERS_START;
420 ph.N_peers_end = DEFAULT_PEERS_END;
421 }
422 if (0 == ph.N_address)
423 ph.N_address = DEFAULT_ADDRESSES;
424
425 if (ph.opt_update_quantity > ph.N_address)
426 {
427 fprintf (stderr,
428 _("Trying to update more addresses than we have per peer! (%u vs %u)"),
429 ph.opt_update_quantity, ph.N_address);
430 exit (1);
431 }
432
433 if (ph.N_peers_start != ph.N_peers_end)
434 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses\n",
435 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
436 else
437 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses\n",
438 ph.ats_string, ph.N_peers_end, ph.N_address);
439
440 /* Load quotas */
441 if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg,
442 quotas_in, quotas_in, GNUNET_ATS_NetworkTypeCount))
443 {
444 GNUNET_break(0);
445 end_now (1);
446 return;
447 }
448
449 /* Load solver */
450 ph.env.cfg = cfg;
451 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
452 ph.env.stats = ph.stat;
453 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
454 ph.env.addresses = ph.addresses;
455 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
456 ph.env.get_preferences = &get_preferences_cb;
457 ph.env.get_property = &get_property_cb;
458 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
459 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
460 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
461 {
462 ph.env.networks[c] = networks[c];
463 ph.env.out_quota[c] = quotas_out[c];
464 ph.env.in_quota[c] = quotas_in[c];
465 }
466 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
467
574 468
575 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 469 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
576 GNUNET_GETOPT_OPTION_END }; 470 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s '`%s'\n"), ph.ats_string, plugin);
471 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
472 {
473 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
474 ret = 1;
475 return;
476 }
577 477
578 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2, 478 /* Do work */
579 "perf_ats", "nohelp", options, &check, NULL ); 479 check ();
480
481 /* Unload solver*/
482 GNUNET_PLUGIN_unload (plugin, ph.solver);
483 GNUNET_free (plugin);
484 ph.solver = NULL;
485}
486
487int
488main (int argc, char *argv[])
489{
490 /* extract command line arguments */
491 ph.opt_dump = GNUNET_NO;
492 ph.opt_update_quantity = 0;
493 ph.opt_update_percent = 0;
494 ph.N_peers_start = 0;
495 ph.N_peers_end = 0;
496 ph.N_address = 0;
497 ph.ats_string = NULL;
498
499 static struct GNUNET_GETOPT_CommandLineOption options[] = {
500 { 'a', "addresses", NULL,
501 gettext_noop ("addresses to use"),
502 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
503 { 's', "start", NULL,
504 gettext_noop ("start with peer"),
505 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
506 { 'e', "end", NULL,
507 gettext_noop ("end with peer"),
508 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
509 { 'p', "percentage", NULL,
510 gettext_noop ("update a fix percentage of addresses"),
511 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
512 { 'q', "quantity", NULL,
513 gettext_noop ("update a fix quantity of addresses"),
514 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_quantity },
515 GNUNET_GETOPT_OPTION_END
516 };
517
518 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
580 519
581 return ret; 520 return ret;
582} 521}
583 522
584/* end of file perf_ats_mlp.c */ 523/* end of file perf_ats_solver.c */