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
28 #include "gnunet_util_lib.h"
29 #include "gnunet_statistics_service.h"
30 #include "gnunet-service-ats_addresses_mlp.h"
32 #define VERBOSE GNUNET_YES
33 #define VERBOSE_ARM GNUNET_NO
35 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
36 #define MLP_MAX_ITERATIONS INT_MAX
39 #define DEF_ADDRESSES_PER_PEER 5
41 static unsigned int peers;
42 static unsigned int addresses;
46 struct GNUNET_STATISTICS_Handle * stats;
48 struct GNUNET_CONTAINER_MultiHashMap * amap;
50 struct GAS_MLP_Handle *mlp;
54 struct GNUNET_PeerIdentity id;
67 struct GNUNET_ATS_Information *ats;
74 check (void *cls, char *const *args, const char *cfgfile,
75 const struct GNUNET_CONFIGURATION_Handle *cfg)
78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
89 addresses = DEF_ADDRESSES_PER_PEER;
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
93 struct PeerContext p[peers];
94 struct ATS_Address a[addresses * peers];
96 amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers);
98 mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
99 mlp->auto_solve = GNUNET_NO;
100 for (c=0; c < peers; c++)
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c);
103 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[c].id.hashPubKey);
105 for (c2=0; c2 < addresses; c2++)
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u for peer %u\n", c2, c);
108 /* Setting required information */
109 a[ca].mlp_information = NULL;
113 /* Setting address */
114 a[ca].peer = p[c].id;
115 a[ca].plugin = strdup("test");
116 a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK;
118 //a[ca].addr = GNUNET_HELLO_address_allocate(&a[ca].peer, a[ca].plugin, NULL, 0);
119 //a[ca].addr_len = GNUNET_HELLO_address_get_size(a[ca].addr);
120 a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information));
121 a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
122 a[ca].ats[0].value = 20;
123 a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE;
124 a[ca].ats[1].value = 2;
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca);
127 GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
128 GAS_mlp_address_update(mlp, amap, &a[ca]);
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
134 /* Solving the problem */
135 if (GNUNET_OK == GAS_mlp_solve_problem(mlp))
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved successfully \n");
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved failed \n");
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution duration %llu\n", mlp->max_exec_duration);
145 for (ca=0; ca < (peers * addresses); ca++)
147 GNUNET_free (a[ca].plugin);
148 GNUNET_free (a[ca].ats);
149 // GNUNET_free ((void *) a[c2].addr);
151 GNUNET_CONTAINER_multihashmap_destroy(amap);
159 main (int argc, char *argv[])
162 static struct GNUNET_GETOPT_CommandLineOption options[] = {
163 {'a', "addresses", NULL,
164 gettext_noop ("addresses per peer"), 1,
165 &GNUNET_GETOPT_set_uint, &addresses},
167 gettext_noop ("peers"), 1,
168 &GNUNET_GETOPT_set_uint, &peers},
169 GNUNET_GETOPT_OPTION_END
172 GNUNET_PROGRAM_run (argc, argv,
173 "perf_ats_mlp", "nohelp", options,
180 /* end of file perf_ats_mlp.c */