aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/perf_ats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats-tests/perf_ats.c')
-rw-r--r--src/ats-tests/perf_ats.c571
1 files changed, 286 insertions, 285 deletions
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c
index b8ab35f99..c31e8a1c4 100644
--- a/src/ats-tests/perf_ats.c
+++ b/src/ats-tests/perf_ats.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010-2013, 2016 GNUnet e.V. 3 Copyright (C) 2010-2013, 2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -31,15 +31,15 @@
31#include "ats-testing.h" 31#include "ats-testing.h"
32 32
33 33
34#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 34#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
35#define TEST_ATS_PREFRENCE_START 1.0 35#define TEST_ATS_PREFRENCE_START 1.0
36#define TEST_ATS_PREFRENCE_DELTA 1.0 36#define TEST_ATS_PREFRENCE_DELTA 1.0
37 37
38#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 38#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
39 39
40#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 40#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
41#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 41#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
42#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) 42#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
43#define TESTNAME_PREFIX "perf_ats_" 43#define TESTNAME_PREFIX "perf_ats_"
44#define DEFAULT_SLAVES_NUM 2 44#define DEFAULT_SLAVES_NUM 2
45#define DEFAULT_MASTERS_NUM 1 45#define DEFAULT_MASTERS_NUM 1
@@ -123,7 +123,7 @@ static struct LoggingHandle *l;
123 123
124 124
125static void 125static void
126evaluate () 126evaluate()
127{ 127{
128 int c_m; 128 int c_m;
129 int c_s; 129 int c_s;
@@ -139,48 +139,48 @@ evaluate ()
139 139
140 duration = 1 + (perf_duration.rel_value_us / (1000 * 1000)); 140 duration = 1 + (perf_duration.rel_value_us / (1000 * 1000));
141 for (c_m = 0; c_m < num_masters; c_m++) 141 for (c_m = 0; c_m < num_masters; c_m++)
142 {
143 mp = &mps[c_m];
144 fprintf (stderr,
145 "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n",
146 mp->no, mp->total_bytes_sent / 1024, duration,
147 (mp->total_bytes_sent / 1024) / duration,
148 mp->total_bytes_received / 1024, duration,
149 (mp->total_bytes_received / 1024) / duration);
150
151 for (c_s = 0; c_s < num_slaves; c_s++)
152 { 142 {
153 p = &mp->partners[c_s]; 143 mp = &mps[c_m];
154 kb_sent_sec = 0; 144 fprintf(stderr,
155 kb_recv_sec = 0; 145 "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n",
156 kb_sent_percent = 0.0; 146 mp->no, mp->total_bytes_sent / 1024, duration,
157 kb_recv_percent = 0.0; 147 (mp->total_bytes_sent / 1024) / duration,
158 rtt = 0; 148 mp->total_bytes_received / 1024, duration,
159 149 (mp->total_bytes_received / 1024) / duration);
160 if (duration > 0) 150
161 { 151 for (c_s = 0; c_s < num_slaves; c_s++)
162 kb_sent_sec = (p->bytes_sent / 1024) / duration; 152 {
163 kb_recv_sec = (p->bytes_received / 1024) / duration; 153 p = &mp->partners[c_s];
164 } 154 kb_sent_sec = 0;
165 155 kb_recv_sec = 0;
166 if (mp->total_bytes_sent > 0) 156 kb_sent_percent = 0.0;
167 kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent; 157 kb_recv_percent = 0.0;
168 if (mp->total_bytes_received > 0) 158 rtt = 0;
169 kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received; 159
170 if (1000 * p->messages_sent > 0) 160 if (duration > 0)
171 rtt = p->total_app_rtt / (1000 * p->messages_sent); 161 {
172 fprintf (stderr, 162 kb_sent_sec = (p->bytes_sent / 1024) / duration;
173 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n", 163 kb_recv_sec = (p->bytes_received / 1024) / duration;
174 (mp->pref_partner == p->dest) ? '*' : ' ', 164 }
175 mp->no, p->dest->no, 165
176 kb_sent_sec, kb_sent_percent, 166 if (mp->total_bytes_sent > 0)
177 kb_recv_sec, kb_recv_percent); 167 kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent;
178 fprintf (stderr, 168 if (mp->total_bytes_received > 0)
179 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", 169 kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received;
180 (mp->pref_partner == p->dest) ? '*' : ' ', 170 if (1000 * p->messages_sent > 0)
181 mp->no, p->dest->no, rtt); 171 rtt = p->total_app_rtt / (1000 * p->messages_sent);
172 fprintf(stderr,
173 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
174 (mp->pref_partner == p->dest) ? '*' : ' ',
175 mp->no, p->dest->no,
176 kb_sent_sec, kb_sent_percent,
177 kb_recv_sec, kb_recv_percent);
178 fprintf(stderr,
179 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
180 (mp->pref_partner == p->dest) ? '*' : ' ',
181 mp->no, p->dest->no, rtt);
182 }
182 } 183 }
183 }
184} 184}
185 185
186 186
@@ -190,24 +190,24 @@ evaluate ()
190 * @param cls NULL 190 * @param cls NULL
191 */ 191 */
192static void 192static void
193do_shutdown (void *cls) 193do_shutdown(void *cls)
194{ 194{
195 if (GNUNET_YES == logging) 195 if (GNUNET_YES == logging)
196 GNUNET_ATS_TEST_logging_clean_up(l); 196 GNUNET_ATS_TEST_logging_clean_up(l);
197 if (NULL != timeout_task) 197 if (NULL != timeout_task)
198 { 198 {
199 GNUNET_SCHEDULER_cancel (timeout_task); 199 GNUNET_SCHEDULER_cancel(timeout_task);
200 timeout_task = NULL; 200 timeout_task = NULL;
201 } 201 }
202 if (NULL != progress_task) 202 if (NULL != progress_task)
203 { 203 {
204 fprintf (stderr, "0\n"); 204 fprintf(stderr, "0\n");
205 GNUNET_SCHEDULER_cancel (progress_task); 205 GNUNET_SCHEDULER_cancel(progress_task);
206 progress_task = NULL; 206 progress_task = NULL;
207 } 207 }
208 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 208 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
209 "Benchmarking done\n"); 209 "Benchmarking done\n");
210 GNUNET_ATS_TEST_shutdown_topology (); 210 GNUNET_ATS_TEST_shutdown_topology();
211} 211}
212 212
213 213
@@ -217,162 +217,163 @@ do_shutdown (void *cls)
217 * @param cls NULL 217 * @param cls NULL
218 */ 218 */
219static void 219static void
220do_timeout (void *cls) 220do_timeout(void *cls)
221{ 221{
222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 222 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
223 "Terminating with timeout\n"); 223 "Terminating with timeout\n");
224 timeout_task = NULL; 224 timeout_task = NULL;
225 evaluate (); 225 evaluate();
226 GNUNET_SCHEDULER_shutdown (); 226 GNUNET_SCHEDULER_shutdown();
227} 227}
228 228
229 229
230static void 230static void
231print_progress (void *cls) 231print_progress(void *cls)
232{ 232{
233 static int calls; 233 static int calls;
234 234
235 progress_task = NULL; 235 progress_task = NULL;
236 fprintf (stderr, 236 fprintf(stderr,
237 "%llu..", 237 "%llu..",
238 (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls); 238 (long long unsigned)perf_duration.rel_value_us / (1000 * 1000) - calls);
239 calls++; 239 calls++;
240 240
241 progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 241 progress_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
242 &print_progress, 242 &print_progress,
243 NULL); 243 NULL);
244} 244}
245 245
246 246
247static void 247static void
248ats_pref_task (void *cls) 248ats_pref_task(void *cls)
249{ 249{
250 struct BenchmarkPeer *me = cls; 250 struct BenchmarkPeer *me = cls;
251 251
252 me->ats_task = NULL; 252 me->ats_task = NULL;
253 253
254 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n", 254 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n",
255 me->no, me->pref_partner->no, me->pref_value); 255 me->no, me->pref_partner->no, me->pref_value);
256 GNUNET_ATS_performance_change_preference (me->ats_perf_handle, 256 GNUNET_ATS_performance_change_preference(me->ats_perf_handle,
257 &me->pref_partner->id, 257 &me->pref_partner->id,
258 pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END); 258 pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END);
259 me->pref_value += TEST_ATS_PREFRENCE_DELTA; 259 me->pref_value += TEST_ATS_PREFRENCE_DELTA;
260 me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY, 260 me->ats_task = GNUNET_SCHEDULER_add_delayed(TEST_ATS_PREFRENCE_FREQUENCY,
261 &ats_pref_task, cls); 261 &ats_pref_task, cls);
262} 262}
263 263
264 264
265static void 265static void
266start_benchmark (void *cls) 266start_benchmark(void *cls)
267{ 267{
268 int c_m; 268 int c_m;
269 int c_s; 269 int c_s;
270 270
271 progress_task = GNUNET_SCHEDULER_add_now (&print_progress, 271 progress_task = GNUNET_SCHEDULER_add_now(&print_progress,
272 NULL); 272 NULL);
273 273
274 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 274 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
275 "Topology connected, start benchmarking...\n"); 275 "Topology connected, start benchmarking...\n");
276 276
277 /* Start sending test messages */ 277 /* Start sending test messages */
278 for (c_m = 0; c_m < num_masters; c_m++) 278 for (c_m = 0; c_m < num_masters; c_m++)
279 {
280 for (c_s = 0; c_s < num_slaves; c_s++)
281 { 279 {
282 GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], 280 for (c_s = 0; c_s < num_slaves; c_s++)
283 &mps[c_m].partners[c_s], 281 {
284 GNUNET_ATS_TEST_TG_LINEAR, 282 GNUNET_ATS_TEST_generate_traffic_start(&mps[c_m],
285 UINT32_MAX, 283 &mps[c_m].partners[c_s],
286 UINT32_MAX, 284 GNUNET_ATS_TEST_TG_LINEAR,
287 GNUNET_TIME_UNIT_MINUTES, 285 UINT32_MAX,
288 GNUNET_TIME_UNIT_FOREVER_REL); 286 UINT32_MAX,
287 GNUNET_TIME_UNIT_MINUTES,
288 GNUNET_TIME_UNIT_FOREVER_REL);
289 }
290 if (pref_val != GNUNET_ATS_PREFERENCE_END)
291 mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task,
292 &mps[c_m]);
289 } 293 }
290 if (pref_val != GNUNET_ATS_PREFERENCE_END)
291 mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task,
292 &mps[c_m]);
293 }
294 294
295 if (GNUNET_YES == logging) 295 if (GNUNET_YES == logging)
296 l = GNUNET_ATS_TEST_logging_start (log_frequency, 296 l = GNUNET_ATS_TEST_logging_start(log_frequency,
297 testname, mps, 297 testname, mps,
298 num_masters, num_slaves, 298 num_masters, num_slaves,
299 GNUNET_NO); 299 GNUNET_NO);
300} 300}
301 301
302 302
303static void 303static void
304do_benchmark (void *cls, 304do_benchmark(void *cls,
305 struct BenchmarkPeer *masters, 305 struct BenchmarkPeer *masters,
306 struct BenchmarkPeer *slaves) 306 struct BenchmarkPeer *slaves)
307{ 307{
308 mps = masters; 308 mps = masters;
309 sps = slaves; 309 sps = slaves;
310 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 310 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
311 NULL); 311 NULL);
312 timeout_task = GNUNET_SCHEDULER_add_delayed (perf_duration, 312 timeout_task = GNUNET_SCHEDULER_add_delayed(perf_duration,
313 &do_timeout, 313 &do_timeout,
314 NULL); 314 NULL);
315 progress_task = GNUNET_SCHEDULER_add_now (&start_benchmark, 315 progress_task = GNUNET_SCHEDULER_add_now(&start_benchmark,
316 NULL); 316 NULL);
317} 317}
318 318
319 319
320static struct BenchmarkPartner * 320static struct BenchmarkPartner *
321find_partner (struct BenchmarkPeer *me, 321find_partner(struct BenchmarkPeer *me,
322 const struct GNUNET_PeerIdentity *peer) 322 const struct GNUNET_PeerIdentity *peer)
323{ 323{
324 int c_m; 324 int c_m;
325 GNUNET_assert (NULL != me); 325
326 GNUNET_assert (NULL != peer); 326 GNUNET_assert(NULL != me);
327 GNUNET_assert(NULL != peer);
327 328
328 for (c_m = 0; c_m < me->num_partners; c_m++) 329 for (c_m = 0; c_m < me->num_partners; c_m++)
329 {
330 /* Find a partner with other as destination */
331 if (0 == GNUNET_memcmp (peer, &me->partners[c_m].dest->id))
332 { 330 {
333 return &me->partners[c_m]; 331 /* Find a partner with other as destination */
332 if (0 == GNUNET_memcmp(peer, &me->partners[c_m].dest->id))
333 {
334 return &me->partners[c_m];
335 }
334 } 336 }
335 }
336 return NULL; 337 return NULL;
337} 338}
338 339
339 340
340static void 341static void
341log_request_cb (void *cls, 342log_request_cb(void *cls,
342 const struct GNUNET_HELLO_Address *address, 343 const struct GNUNET_HELLO_Address *address,
343 int address_active, 344 int address_active,
344 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 345 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
345 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 346 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
346 const struct GNUNET_ATS_Properties *ats) 347 const struct GNUNET_ATS_Properties *ats)
347{ 348{
348 struct BenchmarkPeer *me = cls; 349 struct BenchmarkPeer *me = cls;
349 struct BenchmarkPartner *p; 350 struct BenchmarkPartner *p;
350 char *peer_id; 351 char *peer_id;
351 352
352 p = find_partner (me, &address->peer); 353 p = find_partner(me, &address->peer);
353 if (NULL == p) 354 if (NULL == p)
354 { 355 {
355 /* This is not one of my partners 356 /* This is not one of my partners
356 * Will happen since the peers will connect to each other due to gossiping 357 * Will happen since the peers will connect to each other due to gossiping
357 */ 358 */
358 return; 359 return;
359 } 360 }
360 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id)); 361 peer_id = GNUNET_strdup(GNUNET_i2s(&me->id));
361 362
362 if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) || 363 if ((p->bandwidth_in != ntohl(bandwidth_in.value__)) ||
363 (p->bandwidth_out != ntohl (bandwidth_out.value__))) 364 (p->bandwidth_out != ntohl(bandwidth_out.value__)))
364 p->bandwidth_in = ntohl (bandwidth_in.value__); 365 p->bandwidth_in = ntohl(bandwidth_in.value__);
365 p->bandwidth_out = ntohl (bandwidth_out.value__); 366 p->bandwidth_out = ntohl(bandwidth_out.value__);
366 367
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 368 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
368 "%s [%u] received ATS information for peers `%s'\n", 369 "%s [%u] received ATS information for peers `%s'\n",
369 (GNUNET_YES == p->me->master) ? "Master" : "Slave", 370 (GNUNET_YES == p->me->master) ? "Master" : "Slave",
370 p->me->no, 371 p->me->no,
371 GNUNET_i2s (&p->dest->id)); 372 GNUNET_i2s(&p->dest->id));
372 373
373 GNUNET_free (peer_id); 374 GNUNET_free(peer_id);
374 if (NULL != l) 375 if (NULL != l)
375 GNUNET_ATS_TEST_logging_now (l); 376 GNUNET_ATS_TEST_logging_now(l);
376} 377}
377 378
378 379
@@ -380,7 +381,7 @@ log_request_cb (void *cls,
380 * Start the performance test case 381 * Start the performance test case
381 */ 382 */
382int 383int
383main (int argc, char *argv[]) 384main(int argc, char *argv[])
384{ 385{
385 char *tmp; 386 char *tmp;
386 char *tmp_sep; 387 char *tmp_sep;
@@ -397,187 +398,187 @@ main (int argc, char *argv[])
397 * perf_ats_<solver>_<transport>_<preference>[.exe]*/ 398 * perf_ats_<solver>_<transport>_<preference>[.exe]*/
398 399
399 /* Find test prefix, store in temp */ 400 /* Find test prefix, store in temp */
400 tmp = strstr (argv[0], TESTNAME_PREFIX); 401 tmp = strstr(argv[0], TESTNAME_PREFIX);
401 if (NULL == tmp) 402 if (NULL == tmp)
402 { 403 {
403 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]); 404 fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]);
404 return GNUNET_SYSERR; 405 return GNUNET_SYSERR;
405 } 406 }
406 407
407 /* Set tmp to end of test name prefix */ 408 /* Set tmp to end of test name prefix */
408 tmp += strlen (TESTNAME_PREFIX); 409 tmp += strlen(TESTNAME_PREFIX);
409 410
410 /* Determine solver name */ 411 /* Determine solver name */
411 solver = GNUNET_strdup (tmp); 412 solver = GNUNET_strdup(tmp);
412 /* Remove .exe prefix */ 413 /* Remove .exe prefix */
413 if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0') 414 if (NULL != (dotexe = strstr(solver, ".exe")) && dotexe[4] == '\0')
414 dotexe[0] = '\0'; 415 dotexe[0] = '\0';
415 416
416 /* Determine first '_' after solver */ 417 /* Determine first '_' after solver */
417 tmp_sep = strchr (solver, '_'); 418 tmp_sep = strchr(solver, '_');
418 if (NULL == tmp_sep) 419 if (NULL == tmp_sep)
419 { 420 {
420 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]); 421 fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]);
421 GNUNET_free(solver); 422 GNUNET_free(solver);
422 return GNUNET_SYSERR; 423 return GNUNET_SYSERR;
423 } 424 }
424 tmp_sep[0] = '\0'; 425 tmp_sep[0] = '\0';
425 comm_name = GNUNET_strdup (&tmp_sep[1]); 426 comm_name = GNUNET_strdup(&tmp_sep[1]);
426 tmp_sep = strchr (comm_name, '_'); 427 tmp_sep = strchr(comm_name, '_');
427 if (NULL == tmp_sep) 428 if (NULL == tmp_sep)
428 { 429 {
429 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]); 430 fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]);
430 GNUNET_free(solver); 431 GNUNET_free(solver);
431 return GNUNET_SYSERR; 432 return GNUNET_SYSERR;
432 } 433 }
433 tmp_sep[0] = '\0'; 434 tmp_sep[0] = '\0';
434 for (c = 0; c <= strlen (comm_name); c++) 435 for (c = 0; c <= strlen(comm_name); c++)
435 comm_name[c] = toupper (comm_name[c]); 436 comm_name[c] = toupper(comm_name[c]);
436 if (0 == strcmp (comm_name, "CORE")) 437 if (0 == strcmp(comm_name, "CORE"))
437 test_core = GNUNET_YES; 438 test_core = GNUNET_YES;
438 else if (0 == strcmp (comm_name, "TRANSPORT")) 439 else if (0 == strcmp(comm_name, "TRANSPORT"))
439 test_core = GNUNET_NO; 440 test_core = GNUNET_NO;
440 else 441 else
441 { 442 {
442 GNUNET_free (comm_name); 443 GNUNET_free(comm_name);
443 GNUNET_free (solver); 444 GNUNET_free(solver);
444 return GNUNET_SYSERR; 445 return GNUNET_SYSERR;
445 } 446 }
446 447
447 pref_str = GNUNET_strdup(tmp_sep + 1); 448 pref_str = GNUNET_strdup(tmp_sep + 1);
448 449
449 GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver, 450 GNUNET_asprintf(&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
450 pref_str); 451 pref_str);
451 GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str); 452 GNUNET_asprintf(&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
452 453
453 for (c = 0; c <= strlen (pref_str); c++) 454 for (c = 0; c <= strlen(pref_str); c++)
454 pref_str[c] = toupper (pref_str[c]); 455 pref_str[c] = toupper(pref_str[c]);
455 pref_val = -1; 456 pref_val = -1;
456 457
457 if (0 != strcmp (pref_str, "NONE")) 458 if (0 != strcmp(pref_str, "NONE"))
458 {
459 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
460 { 459 {
461 if (0 == strcmp (pref_str, prefs[c])) 460 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
462 { 461 {
463 pref_val = c; 462 if (0 == strcmp(pref_str, prefs[c]))
464 break; 463 {
465 } 464 pref_val = c;
465 break;
466 }
467 }
466 } 468 }
467 }
468 else 469 else
469 { 470 {
470 /* abuse terminator to indicate no pref */ 471 /* abuse terminator to indicate no pref */
471 pref_val = GNUNET_ATS_PREFERENCE_END; 472 pref_val = GNUNET_ATS_PREFERENCE_END;
472 } 473 }
473 if (-1 == pref_val) 474 if (-1 == pref_val)
474 { 475 {
475 fprintf (stderr, "Unknown preference: `%s'\n", pref_str); 476 fprintf(stderr, "Unknown preference: `%s'\n", pref_str);
476 GNUNET_free(solver); 477 GNUNET_free(solver);
477 GNUNET_free(pref_str); 478 GNUNET_free(pref_str);
478 GNUNET_free (comm_name); 479 GNUNET_free(comm_name);
479 return -1; 480 return -1;
480 } 481 }
481 482
482 for (c = 0; c < (argc - 1); c++) 483 for (c = 0; c < (argc - 1); c++)
483 { 484 {
484 if (0 == strcmp (argv[c], "-d")) 485 if (0 == strcmp(argv[c], "-d"))
485 break; 486 break;
486 } 487 }
487 if (c < argc - 1) 488 if (c < argc - 1)
488 { 489 {
489 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration)) 490 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &perf_duration))
490 fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]); 491 fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
491 } 492 }
492 else 493 else
493 { 494 {
494 perf_duration = BENCHMARK_DURATION; 495 perf_duration = BENCHMARK_DURATION;
495 } 496 }
496 fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000)); 497 fprintf(stderr, "Running benchmark for %llu secs\n", (unsigned long long)(perf_duration.rel_value_us) / (1000 * 1000));
497 498
498 for (c = 0; c < (argc - 1); c++) 499 for (c = 0; c < (argc - 1); c++)
499 { 500 {
500 if (0 == strcmp (argv[c], "-s")) 501 if (0 == strcmp(argv[c], "-s"))
501 break; 502 break;
502 } 503 }
503 if (c < argc - 1) 504 if (c < argc - 1)
504 { 505 {
505 if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10))) 506 if ((0L != (num_slaves = strtol(argv[c + 1], NULL, 10)))
506 && (num_slaves >= 1)) 507 && (num_slaves >= 1))
507 fprintf (stderr, "Starting %u slave peers\n", num_slaves); 508 fprintf(stderr, "Starting %u slave peers\n", num_slaves);
508 else 509 else
509 num_slaves = DEFAULT_SLAVES_NUM; 510 num_slaves = DEFAULT_SLAVES_NUM;
510 } 511 }
511 else 512 else
512 num_slaves = DEFAULT_SLAVES_NUM; 513 num_slaves = DEFAULT_SLAVES_NUM;
513 514
514 for (c = 0; c < (argc - 1); c++) 515 for (c = 0; c < (argc - 1); c++)
515 { 516 {
516 if (0 == strcmp (argv[c], "-m")) 517 if (0 == strcmp(argv[c], "-m"))
517 break; 518 break;
518 } 519 }
519 if (c < argc - 1) 520 if (c < argc - 1)
520 { 521 {
521 if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10))) 522 if ((0L != (num_masters = strtol(argv[c + 1], NULL, 10)))
522 && (num_masters >= 2)) 523 && (num_masters >= 2))
523 fprintf (stderr, "Starting %u master peers\n", num_masters); 524 fprintf(stderr, "Starting %u master peers\n", num_masters);
524 else 525 else
525 num_masters = DEFAULT_MASTERS_NUM; 526 num_masters = DEFAULT_MASTERS_NUM;
526 } 527 }
527 else 528 else
528 num_masters = DEFAULT_MASTERS_NUM; 529 num_masters = DEFAULT_MASTERS_NUM;
529 530
530 logging = GNUNET_NO; 531 logging = GNUNET_NO;
531 for (c = 0; c < argc; c++) 532 for (c = 0; c < argc; c++)
532 {
533 if (0 == strcmp (argv[c], "-l"))
534 logging = GNUNET_YES;
535 }
536
537 if (GNUNET_YES == logging)
538 {
539 for (c = 0; c < (argc - 1); c++)
540 { 533 {
541 if (0 == strcmp (argv[c], "-f")) 534 if (0 == strcmp(argv[c], "-l"))
542 break; 535 logging = GNUNET_YES;
543 } 536 }
544 if (c < argc - 1) 537
545 { 538 if (GNUNET_YES == logging)
546 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency))
547 fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
548 }
549 else
550 { 539 {
551 log_frequency = LOGGING_FREQUENCY; 540 for (c = 0; c < (argc - 1); c++)
541 {
542 if (0 == strcmp(argv[c], "-f"))
543 break;
544 }
545 if (c < argc - 1)
546 {
547 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &log_frequency))
548 fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
549 }
550 else
551 {
552 log_frequency = LOGGING_FREQUENCY;
553 }
554 fprintf(stderr, "Using log frequency %llu ms\n",
555 (unsigned long long)(log_frequency.rel_value_us) / (1000));
552 } 556 }
553 fprintf (stderr, "Using log frequency %llu ms\n",
554 (unsigned long long) (log_frequency.rel_value_us) / (1000));
555 }
556 557
557 GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str); 558 GNUNET_asprintf(&testname, "%s_%s_%s", solver, comm_name, pref_str);
558 559
559 if (num_slaves < num_masters) 560 if (num_slaves < num_masters)
560 { 561 {
561 fprintf (stderr, 562 fprintf(stderr,
562 "Number of master peers is lower than slaves! exit...\n"); 563 "Number of master peers is lower than slaves! exit...\n");
563 GNUNET_free(test_name); 564 GNUNET_free(test_name);
564 GNUNET_free(solver); 565 GNUNET_free(solver);
565 GNUNET_free(pref_str); 566 GNUNET_free(pref_str);
566 GNUNET_free (comm_name); 567 GNUNET_free(comm_name);
567 return GNUNET_SYSERR; 568 return GNUNET_SYSERR;
568 } 569 }
569 570
570 /** 571 /**
571 * Setup the topology 572 * Setup the topology
572 */ 573 */
573 GNUNET_ATS_TEST_create_topology ("perf-ats", 574 GNUNET_ATS_TEST_create_topology("perf-ats",
574 conf_name, 575 conf_name,
575 num_slaves, 576 num_slaves,
576 num_masters, 577 num_masters,
577 test_core, 578 test_core,
578 &do_benchmark, 579 &do_benchmark,
579 NULL, 580 NULL,
580 &log_request_cb); 581 &log_request_cb);
581 582
582 return result; 583 return result;
583} 584}