- update
[oweals/gnunet.git] / src / ats / perf_ats_mlp.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20 /**
21  * @file ats/test_ats_mlp.c
22  * @brief test for the MLP solver
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25
26  */
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_statistics_service.h"
30 #include "gnunet-service-ats_addresses_mlp.h"
31
32 #define VERBOSE GNUNET_YES
33 #define VERBOSE_ARM GNUNET_NO
34
35 #define MLP_MAX_EXEC_DURATION   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
36 #define MLP_MAX_ITERATIONS      INT_MAX
37
38 #define DEF_PEERS 10
39 #define DEF_ADDRESSES_PER_PEER 5
40
41 static unsigned int peers;
42 static unsigned int addresses;
43
44 static int ret;
45
46 struct GNUNET_STATISTICS_Handle * stats;
47
48 struct GNUNET_CONTAINER_MultiHashMap * amap;
49
50 struct GAS_MLP_Handle *mlp;
51
52 struct PeerContext
53 {
54   struct GNUNET_PeerIdentity id;
55
56   struct Address *addr;
57 };
58
59 struct Address
60 {
61   char *plugin;
62   size_t plugin_len;
63
64   void *addr;
65   size_t addr_len;
66
67   struct GNUNET_ATS_Information *ats;
68   int ats_count;
69
70   void *session;
71 };
72
73 static void
74 check (void *cls, char *const *args, const char *cfgfile,
75        const struct GNUNET_CONFIGURATION_Handle *cfg)
76 {
77 #if !HAVE_LIBGLPK
78   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
79   ret = 1;
80   return;
81 #endif
82   unsigned int c = 0;
83   unsigned int c2 = 0;
84   unsigned int ca = 0;
85   //char * pid;
86
87   if (peers == 0)
88     peers = DEF_PEERS;
89   if (addresses == 0)
90     addresses = DEF_ADDRESSES_PER_PEER;
91
92   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
93
94   struct PeerContext p[peers];
95   struct ATS_Address a[addresses * peers];
96
97   amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers);
98
99   mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
100   mlp->auto_solve = GNUNET_NO;
101   for (c=0; c < peers; c++)
102   {
103     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Setting up peer %u\n", c);
104     GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[c].id.hashPubKey);
105
106     for (c2=0; c2 < addresses; c2++)
107     {
108       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Setting up address %u for peer %u\n", c2, c);
109       a[ca].mlp_information = NULL;
110       a[ca].peer = p[c].id;
111       a[ca].plugin = strdup("test");
112       //a[ca].addr = GNUNET_HELLO_address_allocate(&a[ca].peer, a[ca].plugin, NULL, 0);
113       //a[ca].addr_len = GNUNET_HELLO_address_get_size(a[ca].addr);
114       a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information));
115       a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
116       a[ca].ats[0].value = 20;
117       a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE;
118       a[ca].ats[1].value = 2;
119       a[ca].ats_count = 2;
120       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Setting up address %u\n", ca);
121       ca++;
122       /*
123       GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
124       GAS_mlp_address_update(mlp, amap, &a[ca]);
125       */
126     }
127
128   }
129
130
131   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
132   /* Solving the problem */
133   //GAS_mlp_solve_problem(mlp);
134
135
136   //GAS_mlp_done (mlp);
137
138   for (ca=0; ca < (peers * addresses); ca++)
139   {
140     GNUNET_free (a[ca].plugin);
141     GNUNET_free (a[ca].ats);
142    // GNUNET_free ((void *) a[c2].addr);
143   }
144
145   ret = 0;
146   return;
147 }
148
149
150 int
151 main (int argc, char *argv[])
152 {
153
154   static char *const argv2[] = { "test_ats_mlp",
155     "-c",
156     "test_ats_api.conf",
157 #if VERBOSE
158     "-L", "DEBUG",
159 #else
160     "-L", "WARNING",
161 #endif
162     NULL
163   };
164
165   static struct GNUNET_GETOPT_CommandLineOption options[] = {
166     {'a', "addresses", NULL,
167      gettext_noop ("addresses per peer"), 1,
168      &GNUNET_GETOPT_set_uint, &addresses},
169     {'p', "peers", NULL,
170      gettext_noop ("peers"), 1,
171      &GNUNET_GETOPT_set_uint, &peers},
172     GNUNET_GETOPT_OPTION_END
173   };
174
175   GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
176                       "test_ats_mlp", "nohelp", options,
177                       &check, NULL);
178
179
180   return ret;
181 }
182
183 /* end of file test_ats_api_bandwidth_consumption.c */