2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file ats/perf_ats_mlp
22 * @brief performance test for the MLP solver
23 * @author Christian Grothoff
24 * @author Matthias Wachs
29 This file is part of GNUnet.
30 (C) 2010,2011 Christian Grothoff (and other contributing authors)
32 GNUnet is free software; you can redistribute it and/or modify
33 it under the terms of the GNU General Public License as published
34 by the Free Software Foundation; either version 3, or (at your
35 option) any later version.
37 GNUnet is distributed in the hope that it will be useful, but
38 WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40 General Public License for more details.
42 You should have received a copy of the GNU General Public License
43 along with GNUnet; see the file COPYING. If not, write to the
44 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
45 Boston, MA 02111-1307, USA.
48 * @file ats/test_ats_mlp.c
49 * @brief basic test for the MLP solver
50 * @author Christian Grothoff
51 * @author Matthias Wachs
55 #include "gnunet_util_lib.h"
56 #include "gnunet_statistics_service.h"
57 #include "gnunet_ats_service.h"
58 #include "gnunet-service-ats_addresses_mlp.h"
59 #include "test_ats_api_common.h"
61 #define PEERS_START 100
72 struct GNUNET_PeerIdentity id;
74 struct ATS_Address *head;
75 struct ATS_Address *tail;
79 static int opt_numeric;
81 static int opt_update_percent;
82 static int opt_update_quantity;
84 static int N_peers_start;
85 static int N_peers_end;
91 struct GNUNET_STATISTICS_Handle * stats;
96 struct GAS_MLP_Handle *mlp;
99 * Hashmap containing addresses
101 struct GNUNET_CONTAINER_MultiHashMap * addresses;
103 struct GNUNET_ATS_Information ats[3];
105 struct PerfPeer *peers;
112 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
116 if (NULL != addresses)
118 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
119 GNUNET_CONTAINER_multihashmap_destroy (addresses);
137 bandwidth_changed_cb (void *cls, struct ATS_Address *address)
143 perf_create_peer (int cp)
145 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &peers[cp].id.hashPubKey);
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, GNUNET_i2s (&peers[cp].id));
149 static struct ATS_Address *
150 perf_create_address (int cp, int ca)
152 struct ATS_Address *a;
153 a = create_address (&peers[cp].id, "Test 1", "test 1", strlen ("test 1") + 1, 0);
154 GNUNET_CONTAINER_DLL_insert (peers[cp].head, peers[cp].tail, a);
155 GNUNET_CONTAINER_multihashmap_put (addresses, &peers[cp].id.hashPubKey, a, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
161 update_address_it (void *cls, const struct GNUNET_HashCode *key, void * value)
168 update_addresses (void)
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating addresses %u addresses per peer \n", opt_update_quantity);
173 GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_address_it, NULL);
180 check (void *cls, char *const *args, const char *cfgfile,
181 const struct GNUNET_CONFIGURATION_Handle *cfg)
183 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
184 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
185 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
188 struct ATS_Address * cur_addr;
190 stats = GNUNET_STATISTICS_create("ats", cfg);
199 if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in,
200 GNUNET_ATS_NetworkTypeCount))
207 GNUNET_assert (N_peers_end >= N_peers_start);
208 GNUNET_assert (N_address >= 0);
210 fprintf (stderr, "Solving problem for %u..%u peers with %u addresses\n",
211 N_peers_start, N_peers_end, N_address);
213 count_p = N_peers_end;
215 peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
216 /* Setup address hashmap */
217 addresses = GNUNET_CONTAINER_multihashmap_create (N_address, GNUNET_NO);
219 /* Init MLP solver */
220 mlp = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in,
221 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL);
228 mlp->mlp_auto_solve = GNUNET_NO;
229 mlp->write_mip_mps = opt_dump;
230 mlp->write_mip_sol = opt_dump;
232 for (cp = 0; cp < count_p; cp++)
233 perf_create_peer (cp);
235 if (GNUNET_YES == opt_numeric)
236 fprintf (stderr, "#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");
238 for (cp = 0; cp < count_p; cp++)
240 for (ca = 0; ca < count_a; ca++)
242 cur_addr = perf_create_address(cp, ca);
244 GAS_mlp_address_add (mlp, addresses, cur_addr);
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer %u address %u: \n", cp, ca);
247 GAS_mlp_get_preferred_address( mlp, addresses, &peers[cp].id);
249 if (cp + 1 >= N_peers_start)
252 GAS_mlp_solve_problem (mlp, addresses);
253 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",
256 (GNUNET_OK == mlp->ps.lp_res) ? "OK" : "FAIL",
257 (GNUNET_OK == mlp->ps.mip_res) ? "OK" : "FAIL",
258 (GLP_YES == mlp->ps.lp_presolv) ? "YES" : "NO",
259 (GNUNET_OK == mlp->ps.mip_presolv) ? "YES" : "NO",
260 (unsigned long long) mlp->ps.build_dur.rel_value,
261 (unsigned long long) mlp->ps.lp_dur.rel_value,
262 (unsigned long long) mlp->ps.mip_dur.rel_value,
263 mlp->ps.p_cols, mlp->ps.p_rows, mlp->ps.p_elements);
265 fprintf (stderr, "%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu;%u;%u;%u\n",
267 (GNUNET_OK == mlp->ps.lp_res) ? "OK" : "FAIL",
268 (GNUNET_OK == mlp->ps.mip_res) ? "OK" : "FAIL",
269 (GLP_YES == mlp->ps.lp_presolv) ? "YES" : "NO",
270 (GNUNET_OK == mlp->ps.mip_presolv) ? "YES" : "NO",
271 (unsigned long long) mlp->ps.build_dur.rel_value,
272 (unsigned long long) mlp->ps.lp_dur.rel_value,
273 (unsigned long long) mlp->ps.mip_dur.rel_value,
274 mlp->ps.p_cols, mlp->ps.p_rows, mlp->ps.p_elements);
275 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
279 GAS_mlp_solve_problem (mlp, addresses);
285 struct ATS_Address *cur;
286 struct ATS_Address *next;
287 for (cp = 0; cp < count_p; cp++)
289 for (cur = peers[cp].head; cur != NULL; cur = next)
291 GAS_mlp_address_delete (mlp, addresses, cur, GNUNET_NO);
293 GNUNET_CONTAINER_DLL_remove (peers[cp].head, peers[cp].tail, cur);
304 main (int argc, char *argv[])
307 static char *const argv2[] = { "perf_ats_mlp",
314 opt_dump = GNUNET_NO;
315 opt_update_quantity = 0;
316 opt_update_percent = 0;
322 for (c = 0; c < argc; c++)
324 if ((0 == strcmp (argv[c], "-z")) && (c < (argc - 1)))
326 if (0 != atoi(argv[c+1]))
328 N_peers_start = atoi(argv[c+1]);
331 if ((0 == strcmp (argv[c], "-x")) && (c < (argc - 1)))
333 if (0 != atoi(argv[c+1]))
335 N_peers_end = atoi(argv[c+1]);
338 if ((0 == strcmp (argv[c], "-c")) && (c < (argc - 1)))
340 if (0 != atoi(argv[c+1]))
342 N_address = atoi(argv[c+1]);
345 if ((0 == strcmp (argv[c], "-v")))
347 opt_numeric = GNUNET_YES;
349 if ((0 == strcmp (argv[c], "-d")))
351 opt_dump = GNUNET_YES;
353 if ((0 == strcmp (argv[c], "-p")) && (c < (argc - 1)))
355 if (0 != atoi(argv[c+1]))
357 /* Update a fix "p"ercentage of addresses */
358 opt_update_percent = atoi(argv[c+1]);
359 if ((0 <= opt_update_percent) && (100 <= opt_update_percent))
361 fprintf (stderr, _("Percentage has to be: 0 <= p <= 100 "));
366 if ((0 == strcmp (argv[c], "-q")) && (c < (argc - 1)))
368 if (0 != atoi(argv[c+1]))
370 /* Update a fix "q"uantity of addresses */
371 opt_update_quantity = atoi(argv[c+1]);
372 if (0 >= opt_update_quantity)
374 fprintf (stderr, _("Quantity has to be: p => 0 "));
381 if ((0 == N_peers_start) && (0 == N_peers_end))
383 N_peers_start = PEERS_START;
384 N_peers_end = PEERS_END;
387 N_address = ADDRESSES;
389 if (opt_update_quantity >= N_address)
391 fprintf (stderr, _("Trying to Update more addresses than we have per peer!"));
395 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
396 GNUNET_GETOPT_OPTION_END
400 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
401 "perf_ats_mlp", "nohelp", options,
408 /* end of file perf_ats_mlp.c */