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;
81 static int N_peers_start;
82 static int N_peers_end;
88 struct GNUNET_STATISTICS_Handle * stats;
93 struct GAS_MLP_Handle *mlp;
96 * Hashmap containing addresses
98 struct GNUNET_CONTAINER_MultiHashMap * addresses;
100 struct PerfPeer *peers;
107 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
111 if (NULL != addresses)
113 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
114 GNUNET_CONTAINER_multihashmap_destroy (addresses);
132 bandwidth_changed_cb (void *cls, struct ATS_Address *address)
138 perf_create_peer (int cp)
140 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &peers[cp].id.hashPubKey);
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, GNUNET_i2s (&peers[cp].id));
144 static struct ATS_Address *
145 perf_create_address (int cp, int ca)
147 struct ATS_Address *a;
148 a = create_address (&peers[cp].id, "Test 1", "test 1", strlen ("test 1") + 1, 0);
149 GNUNET_CONTAINER_DLL_insert (peers[cp].head, peers[cp].tail, a);
150 GNUNET_CONTAINER_multihashmap_put (addresses, &peers[cp].id.hashPubKey, a, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
159 check (void *cls, char *const *args, const char *cfgfile,
160 const struct GNUNET_CONFIGURATION_Handle *cfg)
162 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
163 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
164 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
167 struct ATS_Address * cur_addr;
169 stats = GNUNET_STATISTICS_create("ats", cfg);
178 if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in,
179 GNUNET_ATS_NetworkTypeCount))
186 GNUNET_assert (N_peers_end >= N_peers_start);
187 GNUNET_assert (N_address >= 0);
189 if ((0 == N_peers_start) && (0 == N_peers_end))
191 N_peers_start = PEERS_START;
192 N_peers_end = PEERS_END;
195 N_address = ADDRESSES;
197 fprintf (stderr, "Solving problem for %u..%u peers with %u addresses\n",
198 N_peers_start, N_peers_end, N_address);
200 count_p = N_peers_end;
202 peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
203 /* Setup address hashmap */
204 addresses = GNUNET_CONTAINER_multihashmap_create (N_address, GNUNET_NO);
206 /* Init MLP solver */
207 mlp = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in,
208 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL);
215 mlp->mlp_auto_solve = GNUNET_NO;
217 for (cp = 0; cp < count_p; cp++)
218 perf_create_peer (cp);
220 if (GNUNET_YES == numeric)
221 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");
223 for (cp = 0; cp < count_p; cp++)
225 for (ca = 0; ca < count_a; ca++)
227 cur_addr = perf_create_address(cp, ca);
229 GAS_mlp_address_add (mlp, addresses, cur_addr);
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer %u address %u: \n", cp, ca);
232 GAS_mlp_get_preferred_address( mlp, addresses, &peers[cp].id);
234 if (cp + 1 >= N_peers_start)
237 GAS_mlp_solve_problem (mlp, addresses);
238 if (GNUNET_NO == numeric)
239 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",
241 (GNUNET_OK == mlp->ps.lp_res) ? "OK" : "FAIL",
242 (GNUNET_OK == mlp->ps.mip_res) ? "OK" : "FAIL",
243 (GLP_YES == mlp->ps.lp_presolv) ? "YES" : "NO",
244 (GNUNET_OK == mlp->ps.mip_presolv) ? "YES" : "NO",
245 (unsigned long long) mlp->ps.build_dur.rel_value,
246 (unsigned long long) mlp->ps.lp_dur.rel_value,
247 (unsigned long long) mlp->ps.mip_dur.rel_value,
248 mlp->ps.p_cols, mlp->ps.p_rows, mlp->ps.p_elements);
250 fprintf (stderr, "%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu;%u;%u;%u\n",
252 (GNUNET_OK == mlp->ps.lp_res) ? "OK" : "FAIL",
253 (GNUNET_OK == mlp->ps.mip_res) ? "OK" : "FAIL",
254 (GLP_YES == mlp->ps.lp_presolv) ? "YES" : "NO",
255 (GNUNET_OK == mlp->ps.mip_presolv) ? "YES" : "NO",
256 (unsigned long long) mlp->ps.build_dur.rel_value,
257 (unsigned long long) mlp->ps.lp_dur.rel_value,
258 (unsigned long long) mlp->ps.mip_dur.rel_value,
259 mlp->ps.p_cols, mlp->ps.p_rows, mlp->ps.p_elements);
265 struct ATS_Address *cur;
266 struct ATS_Address *next;
267 for (cp = 0; cp < count_p; cp++)
269 for (cur = peers[cp].head; cur != NULL; cur = next)
271 GAS_mlp_address_delete (mlp, addresses, cur, GNUNET_NO);
273 GNUNET_CONTAINER_DLL_remove (peers[cp].head, peers[cp].tail, cur);
284 main (int argc, char *argv[])
287 static char *const argv2[] = { "perf_ats_mlp",
298 for (c = 0; c < argc; c++)
300 if ((0 == strcmp (argv[c], "-q")) && (c < argc))
302 if (0 != atoi(argv[c+1]))
304 N_peers_start = atoi(argv[c+1]);
307 if ((0 == strcmp (argv[c], "-w")) && (c < argc))
309 if (0 != atoi(argv[c+1]))
311 N_peers_end = atoi(argv[c+1]);
314 if ((0 == strcmp (argv[c], "-a")) && (c < argc))
316 if (0 != atoi(argv[c+1]))
318 N_address = atoi(argv[c+1]);
321 if ((0 == strcmp (argv[c], "-n")))
323 numeric = GNUNET_YES;
327 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
328 GNUNET_GETOPT_OPTION_END
332 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
333 "perf_ats_mlp", "nohelp", options,
340 /* end of file perf_ats_mlp.c */