aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-25 16:27:00 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-25 16:27:00 +0000
commitc25d299397f120441f96413c10a5278feb6fd69c (patch)
tree483dcfa94ddc7ab3b6c8fdbaf4d2d59d7810c446
parent31772aeb0074780bc5777d125312937daa56c363 (diff)
downloadgnunet-c25d299397f120441f96413c10a5278feb6fd69c.tar.gz
gnunet-c25d299397f120441f96413c10a5278feb6fd69c.zip
changes to perf
-rw-r--r--src/ats/Makefile.am20
-rw-r--r--src/ats/perf_ats_mlp.c580
2 files changed, 246 insertions, 354 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 048f1e220..dd4eea4be 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -75,8 +75,7 @@ check_PROGRAMS = \
75 test_ats_simplistic_pref_aging \ 75 test_ats_simplistic_pref_aging \
76 test_ats_api_performance \ 76 test_ats_api_performance \
77 $(GN_MLP_TEST) 77 $(GN_MLP_TEST)
78# $(GN_MLP_TEST_AVG) \ 78# $(GN_MLP_TEST_AVG) $(GN_MLP_PERF)\
79# $(GN_MLP_PERF)
80# test_ats_api_scheduling_get_type 79# test_ats_api_scheduling_get_type
81# test_ats_api_bandwidth_consumption 80# test_ats_api_bandwidth_consumption
82 81
@@ -202,6 +201,15 @@ test_ats_mlp_LDADD = \
202 $(top_builddir)/src/util/libgnunetutil.la \ 201 $(top_builddir)/src/util/libgnunetutil.la \
203 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 202 $(top_builddir)/src/statistics/libgnunetstatistics.la \
204 $(top_builddir)/src/ats/libgnunetats.la 203 $(top_builddir)/src/ats/libgnunetats.la
204
205perf_ats_mlp_SOURCES = \
206 $(GN_MLP_SRC) perf_ats_mlp.c test_ats_api_common.c
207perf_ats_mlp_LDADD = \
208 $(GN_LIBGLPK) \
209 $(top_builddir)/src/util/libgnunetutil.la \
210 $(top_builddir)/src/statistics/libgnunetstatistics.la \
211 $(top_builddir)/src/ats/libgnunetats.la
212endif
205 213
206#test_ats_mlp_averaging_SOURCES = \ 214#test_ats_mlp_averaging_SOURCES = \
207# $(GN_MLP_SRC) test_ats_mlp_averaging.c test_ats_api_common.c 215# $(GN_MLP_SRC) test_ats_mlp_averaging.c test_ats_api_common.c
@@ -210,14 +218,6 @@ test_ats_mlp_LDADD = \
210# $(top_builddir)/src/util/libgnunetutil.la \ 218# $(top_builddir)/src/util/libgnunetutil.la \
211# $(top_builddir)/src/statistics/libgnunetstatistics.la 219# $(top_builddir)/src/statistics/libgnunetstatistics.la
212 220
213#perf_ats_mlp_SOURCES = \
214# $(GN_MLP_SRC) perf_ats_mlp.c test_ats_api_common.c
215#perf_ats_mlp_LDADD = \
216# $(GN_LIBGLPK) \
217# $(top_builddir)/src/util/libgnunetutil.la \
218# $(top_builddir)/src/statistics/libgnunetstatistics.la
219endif
220
221#test_ats_api_bandwidth_consumption_SOURCES = \ 221#test_ats_api_bandwidth_consumption_SOURCES = \
222# test_ats_api_bandwidth_consumption.c 222# test_ats_api_bandwidth_consumption.c
223#test_ats_api_bandwidth_consumption_LDADD = \ 223#test_ats_api_bandwidth_consumption_LDADD = \
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c
index 8f2bd8c07..ff0e8c4b3 100644
--- a/src/ats/perf_ats_mlp.c
+++ b/src/ats/perf_ats_mlp.c
@@ -24,253 +24,188 @@
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 25
26 */ 26 */
27
28/*
29 This file is part of GNUnet.
30 (C) 2010,2011 Christian Grothoff (and other contributing authors)
31
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.
36
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.
41
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.
46*/
47/**
48 * @file ats/test_ats_mlp.c
49 * @brief basic test for the MLP solver
50 * @author Christian Grothoff
51 * @author Matthias Wachs
52
53 */
27#include "platform.h" 54#include "platform.h"
28#include "gnunet_util_lib.h" 55#include "gnunet_util_lib.h"
29#include "gnunet_statistics_service.h" 56#include "gnunet_statistics_service.h"
57#include "gnunet_ats_service.h"
30#include "gnunet-service-ats_addresses_mlp.h" 58#include "gnunet-service-ats_addresses_mlp.h"
59#include "test_ats_api_common.h"
31 60
32#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) 61#define PEERS_START 1
33#define MLP_MAX_ITERATIONS INT_MAX 62#define PEERS_END 100
34 63
35#define DEF_PEERS 10 64/**
36#define DEF_ADDRESSES_PER_PEER 5 65 * Return value
37#define DEF_ATS_VALUES 2 66 */
38#define DEF_ATS_MAX_DELAY 30 67static int ret;
39#define DEF_ATS_MAX_DISTANCE 3
40 68
41static unsigned int peers; 69/**
42static unsigned int addresses; 70 * MLP solver handle
43static unsigned int numeric; 71 */
44static unsigned int update_percentage; 72struct GAS_MLP_Handle *mlp;
45 73
46static int start;
47static int end;
48 74
49struct ATS_Peer *p; 75/**
50struct ATS_Address *a; 76 * Statistics handle
77 */
78struct GNUNET_STATISTICS_Handle * stats;
51 79
52static int ret; 80/**
81 * Hashmap containing addresses
82 */
83struct GNUNET_CONTAINER_MultiHashMap * addresses;
53 84
54static struct GNUNET_CONTAINER_MultiHashMap * amap; 85/**
86 * Peer
87 */
88struct GNUNET_PeerIdentity p[2];
55 89
56static struct GAS_MLP_Handle *mlp; 90/**
91 * ATS Address
92 */
93struct ATS_Address *address[3];
57 94
95/**
96 * Timeout task
97 */
98GNUNET_SCHEDULER_TaskIdentifier timeout_task;
58 99
59 100
101#if 0
60 102
61GNUNET_SCHEDULER_TaskIdentifier shutdown_task; 103#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
104#define MLP_MAX_ITERATIONS INT_MAX
62 105
63struct PeerContext 106static void
107set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value)
64{ 108{
65 struct GNUNET_PeerIdentity id; 109 ats->type = type;
110 ats->value = value;
111}
66 112
67 struct Address *addr; 113#endif
68};
69 114
70struct Address 115int addr_it (void *cls,
116 const struct GNUNET_HashCode * key,
117 void *value)
71{ 118{
72 char *plugin; 119 struct ATS_Address *address = (struct ATS_Address *) value;
73 size_t plugin_len; 120 GAS_mlp_address_delete (mlp, addresses, address, GNUNET_NO);
74 121 GNUNET_CONTAINER_multihashmap_remove (addresses, key, value);
75 void *addr; 122 GNUNET_free (address);
76 size_t addr_len; 123 return GNUNET_OK;
77 124}
78 struct GNUNET_ATS_Information *ats;
79 int ats_count;
80 125
81 void *session;
82};
83 126
84void 127static void
85do_shutdown (void *cls, 128end_now (int res)
86 const struct GNUNET_SCHEDULER_TaskContext *tc)
87{ 129{
88 unsigned int ca; 130 if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
89 131 {
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); 132 GNUNET_SCHEDULER_cancel (timeout_task);
91 133 timeout_task = GNUNET_SCHEDULER_NO_TASK;
92 if (NULL != mlp) 134 }
135 if (NULL != stats)
93 { 136 {
94 GAS_mlp_done (mlp); 137 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
95 mlp = NULL; 138 stats = NULL;
96 } 139 }
97 140 if (NULL != addresses)
98 if (NULL != a)
99 { 141 {
100 for (ca=0; ca < (peers * addresses); ca++) 142 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
101 { 143 GNUNET_CONTAINER_multihashmap_destroy (addresses);
102 GNUNET_free (a[ca].plugin); 144 addresses = NULL ;
103 GNUNET_free (a[ca].ats); 145 }
104 } 146 if (NULL != mlp)
147 {
148 GAS_mlp_done (mlp);
149 mlp = NULL;
105 } 150 }
106 151
107 if (NULL != amap) 152 ret = res;
108 GNUNET_CONTAINER_multihashmap_destroy(amap);
109 GNUNET_free_non_null (a);
110 GNUNET_free_non_null (p);
111
112} 153}
113 154
114static void 155static void
115update_addresses (struct ATS_Address * a, unsigned int addrs, unsigned int percentage) 156end_correctly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
116{ 157{
117 if (percentage == 0) 158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with success\n"));
118 return; 159 end_now (0);
119
120 unsigned int ua = (addrs) * ((float) percentage / 100);
121 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updating %u of %u addresses per peer\n", ua, addrs);
122
123 unsigned int updated[addrs];
124 unsigned int u_types[DEF_ATS_VALUES];
125 unsigned int updates = 0;
126 unsigned int u_type = 0;
127 unsigned int u_val = 0;
128 unsigned int cur = 0;
129
130 u_types[0] = 0;
131 u_types[1] = 0;
132
133 for (cur = 0; cur < addrs; cur ++)
134 {
135 updated[cur] = 0;
136 }
137 cur = 0;
138
139 while (updates < ua)
140 {
141 cur = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, addrs);
142 if (0 == updated[cur])
143 {
144 u_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_VALUES);
145 switch (u_type) {
146 case 0:
147 do
148 {
149 u_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DELAY);
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating DELAY from %u to %u\n",a[cur].ats[u_type].value, u_val);
151 }
152 while (a[cur].ats[u_type].value == u_val);
153 break;
154 case 1:
155 do
156 {
157 u_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DISTANCE);
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating DISTANCE from %u to %u\n",a[cur].ats[u_type].value, u_val);
159 }
160 while (a[cur].ats[u_type].value == u_val);
161 break;
162 default:
163 GNUNET_break (0);
164 break;
165 }
166 u_types[u_type]++;
167
168 a[cur].ats[u_type].value = u_val;
169 updated[cur] = 1;
170 GAS_mlp_address_update(mlp, amap, &a[cur]);
171 updates++;
172 }
173 }
174 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updated %u delay and %u distance values\n", u_types[0], u_types[1]);
175
176} 160}
177 161
178static unsigned int 162static void
179load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length) 163end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
180{ 164{
181 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; 165 timeout_task = GNUNET_SCHEDULER_NO_TASK;
182 char * entry_in = NULL; 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with timeout\n"));
183 char * entry_out = NULL; 167 end_now (1);
184 char * quota_out_str; 168}
185 char * quota_in_str;
186 int c;
187 169
188 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
189 {
190 in_dest[c] = 0;
191 out_dest[c] = 0;
192 switch (quotas[c]) {
193 case GNUNET_ATS_NET_UNSPECIFIED:
194 entry_out = "UNSPECIFIED_QUOTA_OUT";
195 entry_in = "UNSPECIFIED_QUOTA_IN";
196 break;
197 case GNUNET_ATS_NET_LOOPBACK:
198 entry_out = "LOOPBACK_QUOTA_OUT";
199 entry_in = "LOOPBACK_QUOTA_IN";
200 break;
201 case GNUNET_ATS_NET_LAN:
202 entry_out = "LAN_QUOTA_OUT";
203 entry_in = "LAN_QUOTA_IN";
204 break;
205 case GNUNET_ATS_NET_WAN:
206 entry_out = "WAN_QUOTA_OUT";
207 entry_in = "WAN_QUOTA_IN";
208 break;
209 case GNUNET_ATS_NET_WLAN:
210 entry_out = "WLAN_QUOTA_OUT";
211 entry_in = "WLAN_QUOTA_IN";
212 break;
213 default:
214 break;
215 }
216
217 if ((entry_in == NULL) || (entry_out == NULL))
218 continue;
219
220 /* quota out */
221 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, &quota_out_str))
222 {
223 if (0 == strcmp(quota_out_str, BIG_M_STRING) ||
224 (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
225 out_dest[c] = UINT32_MAX;
226
227 GNUNET_free (quota_out_str);
228 quota_out_str = NULL;
229 }
230 else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
231 out_dest[c] = UINT32_MAX;
232 else
233 out_dest[c] = UINT32_MAX;
234
235 /* quota in */
236 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, &quota_in_str))
237 {
238 if (0 == strcmp(quota_in_str, BIG_M_STRING) ||
239 (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
240 in_dest[c] = UINT32_MAX;
241
242 GNUNET_free (quota_in_str);
243 quota_in_str = NULL;
244 }
245 else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
246 {
247 in_dest[c] = UINT32_MAX;
248 }
249 else
250 {
251 in_dest[c] = UINT32_MAX;
252 }
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota: %s %u, %s %u\n", entry_in, in_dest[c], entry_out, out_dest[c]);
254 170
255 } 171static void
256 return GNUNET_ATS_NetworkTypeCount; 172bandwidth_changed_cb (void *cls, struct ATS_Address *address)
173{
174 static int cb_p0 = GNUNET_NO;
175 static int cb_p1 = GNUNET_NO;
176
177 unsigned long long in = ntohl(address->assigned_bw_in.value__);
178 unsigned long long out = ntohl(address->assigned_bw_out.value__);
179
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP suggests for peer `%s' address `%s':`%s' in %llu out %llu \n",
181 GNUNET_i2s(&address->peer),
182 address->plugin,
183 address->addr,
184 in, out);
185
186 if ((in > 0) && (out > 0) &&
187 (0 == memcmp(&p[0], &address->peer, sizeof (address->peer))))
188 cb_p0 ++;
189
190 if ((in > 0) && (out > 0) &&
191 (0 == memcmp(&p[1], &address->peer, sizeof (address->peer))))
192 cb_p1 ++;
193
194 if ((1 == cb_p0) && (1 == cb_p1))
195 GNUNET_SCHEDULER_add_now (&end_correctly, NULL);
196 else if ((1 > cb_p0) || (1 > cb_p1))
197 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
257} 198}
258 199
259 200
260static void 201static void
261check (void *cls, char *const *args, const char *cfgfile, 202check (void *cls, char *const *args, const char *cfgfile,
262 const struct GNUNET_CONFIGURATION_Handle *cfg) 203 const struct GNUNET_CONFIGURATION_Handle *cfg)
263{ 204{
264 unsigned int c = 0;
265 unsigned int c2 = 0;
266 unsigned int ca = 0;
267 int update = GNUNET_NO;
268 int range = GNUNET_NO;
269 int res;
270 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; 205 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
271 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; 206 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
272 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; 207 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
273 int quota_count; 208 //struct GNUNET_ATS_Information ats;
274 209
275#if !HAVE_LIBGLPK 210#if !HAVE_LIBGLPK
276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); 211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
@@ -278,182 +213,139 @@ check (void *cls, char *const *args, const char *cfgfile,
278 return; 213 return;
279#endif 214#endif
280 215
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
282 216
283 quota_count = load_quotas(cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount); 217
284 mlp = GAS_mlp_init (cfg, NULL, quotas, quotas_in, quotas_out, quota_count); 218 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
219
220 stats = GNUNET_STATISTICS_create("ats", cfg);
221 if (NULL == stats)
222 {
223 GNUNET_break (0);
224 end_now (1);
225 return;
226 }
227
228 /* Load quotas */
229 if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in,
230 GNUNET_ATS_NetworkTypeCount))
231 {
232 GNUNET_break (0);
233 end_now (1);
234 return;
235 }
236
237 /* Setup address hashmap */
238 addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
239
240 /* Init MLP solver */
241 mlp = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in,
242 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL);
285 if (NULL == mlp) 243 if (NULL == mlp)
286 { 244 {
287 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n"); 245 GNUNET_break (0);
288 ret = 1; 246 end_now (1);
289 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 247 return;
290 GNUNET_SCHEDULER_cancel(shutdown_task);
291 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
292 } 248 }
249 mlp->mlp_auto_solve = GNUNET_NO;
293 250
294 if (peers == 0)
295 peers = DEF_PEERS;
296 if (addresses == 0)
297 addresses = DEF_ADDRESSES_PER_PEER;
298 251
299 p = GNUNET_malloc (peers * sizeof (struct ATS_Peer)); 252#if 0
300 a = GNUNET_malloc (peers * addresses * sizeof (struct ATS_Address));
301 253
302 amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers, GNUNET_NO); 254 /* Create peer 0 */
255 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].hashPubKey))
256 {
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
258 end_now (1);
259 return;
260 }
303 261
304 mlp->auto_solve = GNUNET_NO; 262 /* Create peer 1 */
305 if (start == 0) 263 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].hashPubKey))
306 start = 0;
307 if (end == 0)
308 end = -1;
309 if ((start != -1) && (end != -1))
310 { 264 {
311 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem starting from %u to %u\n", start , end); 265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
312 range = GNUNET_YES; 266 end_now (1);
267 return;
313 } 268 }
314 else
315 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem for %u peers\n", peers);
316 269
317 if ((update_percentage >= 0) && (update_percentage <= 100)) 270 /* Create address 0 */
271 address[0] = create_address (&p[0], "test_plugin0", "test_addr0", strlen("test_addr0")+1, 0);
272 if (NULL == address[0])
318 { 273 {
319 update = GNUNET_YES; 274 GNUNET_break (0);
320 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Benchmarking with existing presolution and %u%% updated addresses\n", update_percentage); 275 end_now (1);
276 return;
321 } 277 }
322 else if ((update_percentage > 100) && (update_percentage != UINT_MAX)) 278 GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0],
279 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
280 /* Adding address 0 */
281 GAS_mlp_address_add (mlp, addresses, address[0]);
282
283 /* Create address 1 */
284 address[1] = create_address (&p[0], "test_plugin1", "test_addr1", strlen("test_addr1")+1, 0);
285 if (NULL == address[1])
323 { 286 {
324 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Invalid percentage: %u\n", update_percentage); 287 GNUNET_break (0);
325 ret = 1; 288 end_now (1);
326 return; 289 return;
327 } 290 }
291 GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1],
292 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
293 /* Adding address 1*/
294 GAS_mlp_address_add (mlp, addresses, address[1]);
328 295
329 for (c=0; c < peers; c++) 296
297 /* Create address 3 */
298 address[2] = create_address (&p[1], "test_plugin2", "test_addr2", strlen("test_addr2")+1, 0);
299 if (NULL == address[2])
330 { 300 {
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c); 301 GNUNET_break (0);
332 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_NONCE, &p[c].id.hashPubKey); 302 end_now (1);
333 303 return;
334 for (c2=0; c2 < addresses; c2++)
335 {
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u for peer %u\n", c2, c);
337 /* Setting required information */
338 a[ca].solver_information = NULL;
339 a[ca].prev = NULL;
340 a[ca].next = NULL;
341
342 /* Setting address */
343 a[ca].peer = p[c].id;
344 a[ca].plugin = GNUNET_strdup("test");
345 a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK;
346
347 a[ca].ats = GNUNET_malloc (DEF_ATS_VALUES * sizeof (struct GNUNET_ATS_Information));
348 a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
349 a[ca].ats[0].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DELAY);
350 a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE;
351 a[ca].ats[1].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DISTANCE);
352 a[ca].ats_count = 2;
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca);
354 GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
355 GAS_mlp_address_update(mlp, amap, &a[ca]);
356 ca++;
357 }
358
359 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addresses_in_problem);
360
361 if (((GNUNET_YES == range) && (((start >= 0) && ((c+1) >= start)) && (c <= end))) || ((c+1) == peers))
362 {
363 GNUNET_assert ((c+1) == mlp->c_p);
364 GNUNET_assert ((c+1) * addresses == mlp->addresses_in_problem);
365
366 /* Solving the problem */
367 struct GAS_MLP_SolutionContext ctx;
368
369 res = GAS_mlp_solve_problem(mlp, &ctx);
370
371 if (GNUNET_NO == update)
372 {
373 if (GNUNET_OK == res)
374 {
375 GNUNET_assert (GNUNET_OK == ctx.lp_result);
376 GNUNET_assert (GNUNET_OK == ctx.mlp_result);
377 if (GNUNET_YES == numeric)
378 printf ("%u;%u;%llu;%llu\n",mlp->c_p, mlp->addresses_in_problem, (unsigned long long) ctx.lp_duration.rel_value, (unsigned long long) ctx.mlp_duration.rel_value);
379 else
380 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem solved for %u peers with %u address successfully (LP: %llu ms / MLP: %llu ms)\n",
381 mlp->c_p, mlp->addresses_in_problem, ctx.lp_duration.rel_value, ctx.mlp_duration.rel_value);
382 }
383 else
384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", c, c2);
385 }
386 else
387 {
388 struct GAS_MLP_SolutionContext uctx;
389 /* Update addresses */
390 update_addresses (a, (c+1) * c2, update_percentage);
391
392 /* Solve again */
393 res = GAS_mlp_solve_problem(mlp, &uctx);
394
395 if (GNUNET_OK == res)
396 {
397 GNUNET_assert (GNUNET_OK == uctx.lp_result);
398 GNUNET_assert (GNUNET_OK == uctx.mlp_result);
399 if (GNUNET_YES == numeric)
400 printf ("%u;%u;%llu;%llu;%llu;%llu\n",mlp->c_p, mlp->addresses_in_problem,
401 (unsigned long long) ctx.lp_duration.rel_value, (unsigned long long) ctx.mlp_duration.rel_value,
402 (unsigned long long) uctx.lp_duration.rel_value, (unsigned long long) uctx.mlp_duration.rel_value);
403 else
404 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updated problem solved for %u peers with %u address successfully (Initial: LP/MLP: %llu/%llu ms, Update: %llu/%llu ms)\n",
405 mlp->c_p, mlp->addresses_in_problem,
406 (unsigned long long) ctx.lp_duration.rel_value, (unsigned long long) ctx.mlp_duration.rel_value,
407 (unsigned long long) uctx.lp_duration.rel_value, (unsigned long long) uctx.mlp_duration.rel_value);
408 }
409 else
410 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving updated problem with %u peers and %u addresses failed\n", c, c2);
411 }
412 }
413 } 304 }
305 GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2],
306 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
307 /* Adding address 3*/
308 GAS_mlp_address_add (mlp, addresses, address[2]);
309
310
311 /* Updating address 0*/
312 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
313 ats.value = htonl (GNUNET_ATS_NET_WAN);
314 GAS_mlp_address_update (mlp, addresses, address[0], 1, GNUNET_NO, &ats, 1);
414 315
415 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 316 /* Retrieving preferred address for peer and wait for callback */
416 GNUNET_SCHEDULER_cancel(shutdown_task); 317 GAS_mlp_get_preferred_address (mlp, addresses, &p[0]);
417 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 318 GAS_mlp_get_preferred_address (mlp, addresses, &p[1]);
418 319
320 GAS_mlp_solve_problem (mlp, addresses);
321#endif
419} 322}
420 323
421 324
422int 325int
423main (int argc, char *const *argv) 326main (int argc, char *argv[])
424{ 327{
425 /* Init invalid */ 328
426 update_percentage = UINT_MAX; 329 static char *const argv2[] = { "perf_ats_mlp",
330 "-c",
331 "test_ats_mlp.conf",
332 "-L", "WARNING",
333 NULL
334 };
335
427 static struct GNUNET_GETOPT_CommandLineOption options[] = { 336 static struct GNUNET_GETOPT_CommandLineOption options[] = {
428 {'a', "addresses", NULL,
429 gettext_noop ("addresses per peer"), 1,
430 &GNUNET_GETOPT_set_uint, &addresses},
431 {'p', "peers", NULL,
432 gettext_noop ("peers"), 1,
433 &GNUNET_GETOPT_set_uint, &peers},
434 {'n', "numeric", NULL,
435 gettext_noop ("numeric output only"), 0,
436 &GNUNET_GETOPT_set_one, &numeric},
437 {'e', "end", NULL,
438 gettext_noop ("end solving problem"), 1,
439 &GNUNET_GETOPT_set_uint, &end},
440 {'s', "start", NULL,
441 gettext_noop ("start solving problem"), 1,
442 &GNUNET_GETOPT_set_uint, &start},
443 {'u', "update", NULL,
444 gettext_noop ("benchmark with existing solution (address updates)"), 1,
445 &GNUNET_GETOPT_set_uint, &update_percentage},
446 GNUNET_GETOPT_OPTION_END 337 GNUNET_GETOPT_OPTION_END
447 }; 338 };
448 339
449 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 340 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
450 return 2;
451
452 GNUNET_PROGRAM_run (argc, argv,
453 "perf_ats_mlp", "nohelp", options, 341 "perf_ats_mlp", "nohelp", options,
454 &check, NULL); 342 &check, NULL);
455 GNUNET_free ((void *) argv); 343
344
456 return ret; 345 return ret;
457} 346}
458 347
348/* end of file test_ats_api_bandwidth_consumption.c */
349
350
459/* end of file perf_ats_mlp.c */ 351/* end of file perf_ats_mlp.c */