fixes for ats measurement
[oweals/gnunet.git] / src / ats-tests / perf_ats.c
1 /*
2  This file is part of GNUnet.
3  (C) 2010-2013 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/perf_ats.c
22  * @brief ats benchmark: start peers and modify preferences, monitor change over time
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testbed_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet_core_service.h"
31 #include "ats-testing.h"
32
33
34 #define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
35 #define TEST_ATS_PREFRENCE_START 1.0
36 #define TEST_ATS_PREFRENCE_DELTA 1.0
37
38 #define TEST_MESSAGE_TYPE_PING 12345
39 #define TEST_MESSAGE_TYPE_PONG 12346
40 #define TEST_MESSAGE_SIZE 1000
41 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
42
43
44 /**
45  * Shutdown task
46  */
47 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
48
49 /**
50  * Progress task
51  */
52 static GNUNET_SCHEDULER_TaskIdentifier progress_task;
53
54 /**
55  * Test result
56  */
57 static int result;
58
59 /**
60  * Test result logging
61  */
62 static int logging;
63
64 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
65  */
66 static int test_core;
67
68 /**
69  * Solver string
70  */
71 static char *solver;
72
73 /**
74  * Preference string
75  */
76 static char *testname;
77
78 /**
79  * Preference string
80  */
81 static char *pref_str;
82
83 /**
84  * ATS preference value
85  */
86 static int pref_val;
87
88 /**
89  * Benchmark duration
90  */
91 static struct GNUNET_TIME_Relative perf_duration;
92
93 /**
94  * Logging frequency
95  */
96 static struct GNUNET_TIME_Relative log_frequency;
97
98 /**
99  * Number master peers
100  */
101 static unsigned int num_masters;
102
103 /**
104  * Array of master peers
105  */
106 static struct BenchmarkPeer *mps;
107
108 /**
109  * Number slave peers
110  */
111 static unsigned int num_slaves;
112
113 /**
114  * Array of master peers
115  */
116 static struct BenchmarkPeer *sps;
117
118 static void
119 evaluate ()
120 {
121   int c_m;
122   int c_s;
123   unsigned int duration;
124   struct BenchmarkPeer *mp;
125   struct BenchmarkPartner *p;
126
127   duration = (perf_duration.rel_value_us / (1000 * 1000));
128   for (c_m = 0; c_m < num_masters; c_m++)
129   {
130     mp = &mps[c_m];
131     fprintf (stderr,
132         _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
133         mp->no, mp->total_bytes_sent / 1024, duration,
134         (mp->total_bytes_sent / 1024) / duration,
135         mp->total_bytes_received / 1024, duration,
136         (mp->total_bytes_received / 1024) / duration);
137
138     for (c_s = 0; c_s < num_slaves; c_s++)
139     {
140       p = &mp->partners[c_s];
141       fprintf (stderr,
142           "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
143           (mp->pref_partner == p->dest) ? '*' : ' ',
144           mp->no, p->dest->no,
145           (p->bytes_sent / 1024) / duration,
146           ((double) p->bytes_sent * 100) / mp->total_bytes_sent,
147           (p->bytes_received / 1024) / duration,
148           ((double) p->bytes_received * 100) / mp->total_bytes_received );
149       fprintf (stderr,
150           "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
151           (mp->pref_partner == p->dest) ? '*' : ' ',
152           mp->no, p->dest->no,
153           p->total_app_rtt / (1000 * p->messages_sent));
154     }
155   }
156 }
157
158 /**
159  * Shutdown nicely
160  *
161  * @param cls NULL
162  * @param tc the task context
163  */
164 static void
165 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
166 {
167   /*
168   if (GNUNET_YES == logging)
169     perf_logging_stop();
170 */
171   shutdown_task = GNUNET_SCHEDULER_NO_TASK;
172   if (GNUNET_SCHEDULER_NO_TASK != progress_task)
173   {
174     fprintf (stderr, "0\n");
175     GNUNET_SCHEDULER_cancel (progress_task);
176   }
177   progress_task = GNUNET_SCHEDULER_NO_TASK;
178
179   evaluate ();
180   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
181
182   GNUNET_ATS_TEST_shutdown_topology();
183 }
184
185 static size_t
186 comm_send_ready (void *cls, size_t size, void *buf)
187 {
188   static char msgbuf[TEST_MESSAGE_SIZE];
189   struct BenchmarkPartner *p = cls;
190   struct GNUNET_MessageHeader *msg;
191
192   if (GNUNET_YES == test_core)
193     p->cth = NULL;
194   else
195     p->tth = NULL;
196
197   if (NULL == buf)
198   {
199     GNUNET_break (0);
200     return 0;
201   }
202   if (size < TEST_MESSAGE_SIZE)
203   {
204     GNUNET_break (0);
205     return 0;
206   }
207
208   GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Master [%u]: Sending PING to [%u]\n",
209       p->me->no, p->dest->no);
210
211   p->messages_sent++;
212   p->bytes_sent += TEST_MESSAGE_SIZE;
213   p->me->total_messages_sent++;
214   p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
215
216   msg = (struct GNUNET_MessageHeader *) &msgbuf;
217   memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
218   msg->type = htons (TEST_MESSAGE_TYPE_PING);
219   msg->size = htons (TEST_MESSAGE_SIZE);
220   memcpy (buf, msg, TEST_MESSAGE_SIZE);
221   return TEST_MESSAGE_SIZE;
222 }
223
224 static void
225 comm_schedule_send (struct BenchmarkPartner *p)
226 {
227   p->last_message_sent = GNUNET_TIME_absolute_get();
228   if (GNUNET_YES == test_core)
229   {
230     p->cth = GNUNET_CORE_notify_transmit_ready (
231       p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
232       TEST_MESSAGE_SIZE, &comm_send_ready, p);
233   }
234   else
235   {
236     p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
237       p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
238       &comm_send_ready, p);
239   }
240
241 }
242
243 static void
244 print_progress ()
245 {
246   static int calls;
247   progress_task = GNUNET_SCHEDULER_NO_TASK;
248
249   fprintf (stderr, "%llu..",
250       (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls);
251   calls++;
252
253   progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
254       &print_progress, NULL );
255 }
256
257 static void
258 ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
259 {
260   struct BenchmarkPeer *me = cls;
261
262   me->ats_task = GNUNET_SCHEDULER_NO_TASK;
263
264   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n",
265       me->no, me->pref_partner->no, me->pref_value);
266   GNUNET_ATS_performance_change_preference (me->ats_perf_handle,
267       &me->pref_partner->id,
268       pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END);
269   me->pref_value += TEST_ATS_PREFRENCE_DELTA;
270   me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY,
271       &ats_pref_task, cls);
272 }
273
274 static void
275 do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves)
276 {
277   int c_m;
278   int c_s;
279
280   mps = masters;
281   sps = slaves;
282
283   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
284
285   if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
286     GNUNET_SCHEDULER_cancel (shutdown_task);
287   shutdown_task = GNUNET_SCHEDULER_add_delayed (perf_duration,
288       &do_shutdown, NULL );
289
290   progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL );
291
292   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Topology connected, start benchmarking...\n");
293
294   /* Start sending test messages */
295   for (c_m = 0; c_m < num_masters; c_m++)
296   {
297     for (c_s = 0; c_s < num_slaves; c_s++)
298       comm_schedule_send (&masters[c_m].partners[c_s]);
299     if (pref_val != GNUNET_ATS_PREFERENCE_END)
300       masters[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &masters[c_m]);
301   }
302
303   /*
304   if (GNUNET_YES == logging)
305     perf_logging_start (log_frequency, testname, mps, num_masters);
306 */
307 }
308
309
310 static size_t
311 comm_send_pong_ready (void *cls, size_t size, void *buf)
312 {
313   static char msgbuf[TEST_MESSAGE_SIZE];
314   struct BenchmarkPartner *p = cls;
315   struct GNUNET_MessageHeader *msg;
316
317   if (GNUNET_YES == test_core)
318     p->cth = NULL;
319   else
320     p->tth = NULL;
321
322   p->messages_sent++;
323   p->bytes_sent += TEST_MESSAGE_SIZE;
324   p->me->total_messages_sent++;
325   p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
326
327   msg = (struct GNUNET_MessageHeader *) &msgbuf;
328   memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
329   msg->type = htons (TEST_MESSAGE_TYPE_PONG);
330   msg->size = htons (TEST_MESSAGE_SIZE);
331   memcpy (buf, msg, TEST_MESSAGE_SIZE);
332
333   return TEST_MESSAGE_SIZE;
334 }
335
336 static struct BenchmarkPartner *
337 find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
338 {
339   int c_m;
340   GNUNET_assert (NULL != me);
341   GNUNET_assert (NULL != peer);
342
343   for (c_m = 0; c_m < me->num_partners; c_m++)
344   {
345     /* Find a partner with other as destination */
346     if (0 == memcmp (peer, &me->partners[c_m].dest->id,
347             sizeof(struct GNUNET_PeerIdentity)))
348     {
349       return &me->partners[c_m];
350     }
351   }
352
353   return NULL;
354 }
355
356 static int
357 comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
358     const struct GNUNET_MessageHeader *message)
359 {
360
361   struct BenchmarkPeer *me = cls;
362   struct BenchmarkPartner *p = NULL;
363
364   if (NULL == (p = find_partner(me, other)))
365   {
366     GNUNET_break(0);
367     return GNUNET_SYSERR;
368   }
369
370   GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
371       "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
372       p->dest->no);
373
374   p->messages_received++;
375   p->bytes_received += TEST_MESSAGE_SIZE;
376   p->me->total_messages_received++;
377   p->me->total_bytes_received += TEST_MESSAGE_SIZE;
378
379   if (GNUNET_YES == test_core)
380   {
381     GNUNET_assert (NULL == p->cth);
382     p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
383         GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
384         &comm_send_pong_ready, p);
385   }
386   else
387   {
388     GNUNET_assert (NULL == p->tth);
389     p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
390         TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
391         p);
392   }
393   return GNUNET_OK;
394 }
395
396 static int
397 comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
398     const struct GNUNET_MessageHeader *message)
399 {
400   struct BenchmarkPeer *me = cls;
401   struct BenchmarkPartner *p = NULL;
402
403   if (NULL == (p = find_partner (me, other)))
404   {
405     GNUNET_break(0);
406     return GNUNET_SYSERR;
407   }
408
409   GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
410       "Master [%u]: Received PONG from [%u], next message\n", me->no,
411       p->dest->no);
412
413   p->messages_received++;
414   p->bytes_received += TEST_MESSAGE_SIZE;
415   p->me->total_messages_received++;
416   p->me->total_bytes_received += TEST_MESSAGE_SIZE;
417   p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
418       GNUNET_TIME_absolute_get()).rel_value_us;
419
420   comm_schedule_send (p);
421   return GNUNET_OK;
422 }
423
424
425
426 static void
427 transport_recv_cb (void *cls,
428                    const struct GNUNET_PeerIdentity * peer,
429                    const struct GNUNET_MessageHeader * message)
430 {
431   if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
432       (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
433       TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
434   {
435     return;
436   }
437   if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
438     comm_handle_ping (cls, peer, message);
439
440   if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
441     comm_handle_pong (cls, peer, message);
442 }
443
444
445
446
447
448 static void
449 ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
450     int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
451     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
452     const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
453 {
454   struct BenchmarkPeer *me = cls;
455   struct BenchmarkPartner *p;
456   int c_a;
457   int log;
458   char *peer_id;
459
460   p = find_partner (me, &address->peer);
461   if (NULL == p)
462   {
463     /* This is not one of my partners
464      * Will happen since the peers will connect to each other due to gossiping
465      */
466     return;
467   }
468   peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
469
470   log = GNUNET_NO;
471   if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
472       (p->bandwidth_out != ntohl (bandwidth_out.value__)))
473       log = GNUNET_YES;
474   p->bandwidth_in = ntohl (bandwidth_in.value__);
475   p->bandwidth_out = ntohl (bandwidth_out.value__);
476
477   for (c_a = 0; c_a < ats_count; c_a++)
478   {
479     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
480         (GNUNET_YES == p->me->master) ? "Master" : "Slave",
481         p->me->no,
482         GNUNET_i2s (&p->dest->id),
483         GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
484         ntohl(ats[c_a].value));
485     switch (ntohl (ats[c_a].type ))
486     {
487       case GNUNET_ATS_ARRAY_TERMINATOR:
488         break;
489       case GNUNET_ATS_UTILIZATION_OUT:
490         if (p->ats_utilization_up != ntohl (ats[c_a].value))
491             log = GNUNET_YES;
492         p->ats_utilization_up = ntohl (ats[c_a].value);
493
494         break;
495       case GNUNET_ATS_UTILIZATION_IN:
496         if (p->ats_utilization_down != ntohl (ats[c_a].value))
497             log = GNUNET_YES;
498         p->ats_utilization_down = ntohl (ats[c_a].value);
499         break;
500       case GNUNET_ATS_NETWORK_TYPE:
501         if (p->ats_network_type != ntohl (ats[c_a].value))
502             log = GNUNET_YES;
503         p->ats_network_type = ntohl (ats[c_a].value);
504         break;
505       case GNUNET_ATS_QUALITY_NET_DELAY:
506         if (p->ats_delay != ntohl (ats[c_a].value))
507             log = GNUNET_YES;
508         p->ats_delay = ntohl (ats[c_a].value);
509         break;
510       case GNUNET_ATS_QUALITY_NET_DISTANCE:
511         if (p->ats_distance != ntohl (ats[c_a].value))
512             log = GNUNET_YES;
513         p->ats_distance = ntohl (ats[c_a].value);
514         GNUNET_break (0);
515         break;
516       case GNUNET_ATS_COST_WAN:
517         if (p->ats_cost_wan != ntohl (ats[c_a].value))
518             log = GNUNET_YES;
519         p->ats_cost_wan = ntohl (ats[c_a].value);
520         break;
521       case GNUNET_ATS_COST_LAN:
522         if (p->ats_cost_lan != ntohl (ats[c_a].value))
523             log = GNUNET_YES;
524         p->ats_cost_lan = ntohl (ats[c_a].value);
525         break;
526       case GNUNET_ATS_COST_WLAN:
527         if (p->ats_cost_wlan != ntohl (ats[c_a].value))
528             log = GNUNET_YES;
529         p->ats_cost_wlan = ntohl (ats[c_a].value);
530         break;
531       default:
532         break;
533     }
534   }
535   /*
536   if ((GNUNET_YES == logging) && (GNUNET_YES == log))
537     collect_log_now();
538     */
539   GNUNET_free(peer_id);
540 }
541
542
543
544
545
546 int
547 main (int argc, char *argv[])
548 {
549   char *tmp;
550   char *tmp_sep;
551   char *test_name;
552   char *conf_name;
553   char *comm_name;
554   char *dotexe;
555   char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
556   int c;
557
558   result = 0;
559
560   /* figure out testname */
561   tmp = strstr (argv[0], TESTNAME_PREFIX);
562   if (NULL == tmp)
563   {
564     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
565     return GNUNET_SYSERR;
566   }
567   tmp += strlen (TESTNAME_PREFIX);
568   solver = GNUNET_strdup (tmp);
569   if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
570     dotexe[0] = '\0';
571   tmp_sep = strchr (solver, '_');
572   if (NULL == tmp_sep)
573   {
574     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
575     GNUNET_free(solver);
576     return GNUNET_SYSERR;
577   }
578   tmp_sep[0] = '\0';
579   comm_name = GNUNET_strdup (&tmp_sep[1]);
580   tmp_sep = strchr (comm_name, '_');
581   if (NULL == tmp_sep)
582   {
583     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
584     GNUNET_free(solver);
585     return GNUNET_SYSERR;
586   }
587   tmp_sep[0] = '\0';
588   for (c = 0; c <= strlen (comm_name); c++)
589     comm_name[c] = toupper (comm_name[c]);
590   if (0 == strcmp (comm_name, "CORE"))
591     test_core = GNUNET_YES;
592   else if (0 == strcmp (comm_name, "TRANSPORT"))
593     test_core = GNUNET_NO;
594   else
595   {
596     GNUNET_free (comm_name);
597     GNUNET_free (solver);
598     return GNUNET_SYSERR;
599   }
600
601   pref_str = GNUNET_strdup(tmp_sep + 1);
602
603   GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
604       pref_str);
605   GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
606
607   for (c = 0; c <= strlen (pref_str); c++)
608     pref_str[c] = toupper (pref_str[c]);
609   pref_val = -1;
610
611   if (0 != strcmp (pref_str, "NONE"))
612   {
613     for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
614     {
615       if (0 == strcmp (pref_str, prefs[c]))
616       {
617         pref_val = c;
618         break;
619       }
620     }
621   }
622   else
623   {
624     /* abuse terminator to indicate no pref */
625     pref_val = GNUNET_ATS_PREFERENCE_END;
626   }
627   if (-1 == pref_val)
628   {
629     fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
630     GNUNET_free(solver);
631     GNUNET_free(pref_str);
632     GNUNET_free (comm_name);
633     return -1;
634   }
635
636   for (c = 0; c < (argc - 1); c++)
637   {
638     if (0 == strcmp (argv[c], "-d"))
639       break;
640   }
641   if (c < argc - 1)
642   {
643     if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration))
644         fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
645   }
646   else
647   {
648     perf_duration = BENCHMARK_DURATION;
649   }
650   fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000));
651
652   for (c = 0; c < (argc - 1); c++)
653   {
654     if (0 == strcmp (argv[c], "-s"))
655       break;
656   }
657   if (c < argc - 1)
658   {
659     if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
660         && (num_slaves >= 1))
661       fprintf (stderr, "Starting %u slave peers\n", num_slaves);
662     else
663       num_slaves = DEFAULT_SLAVES_NUM;
664   }
665   else
666     num_slaves = DEFAULT_SLAVES_NUM;
667
668   for (c = 0; c < (argc - 1); c++)
669   {
670     if (0 == strcmp (argv[c], "-m"))
671       break;
672   }
673   if (c < argc - 1)
674   {
675     if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
676         && (num_masters >= 2))
677       fprintf (stderr, "Starting %u master peers\n", num_masters);
678     else
679       num_masters = DEFAULT_MASTERS_NUM;
680   }
681   else
682     num_masters = DEFAULT_MASTERS_NUM;
683
684   logging = GNUNET_NO;
685   for (c = 0; c < argc; c++)
686   {
687     if (0 == strcmp (argv[c], "-l"))
688       logging = GNUNET_YES;
689   }
690
691   if (GNUNET_YES == logging)
692   {
693     for (c = 0; c < (argc - 1); c++)
694     {
695       if (0 == strcmp (argv[c], "-f"))
696         break;
697     }
698     if (c < argc - 1)
699     {
700       if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency))
701           fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
702     }
703     else
704     {
705       log_frequency = LOGGING_FREQUENCY;
706     }
707     fprintf (stderr, "Using log frequency %llu ms\n",
708         (unsigned long long) (log_frequency.rel_value_us) / (1000));
709   }
710
711   GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str);
712
713   if (num_slaves < num_masters)
714   {
715     fprintf (stderr, "Number of master peers is lower than slaves! exit...\n");
716     GNUNET_free(test_name);
717     GNUNET_free(solver);
718     GNUNET_free(pref_str);
719     GNUNET_free (comm_name);
720     return GNUNET_SYSERR;
721   }
722
723   static struct GNUNET_CORE_MessageHandler handlers[] = {
724       {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
725       {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
726       { NULL, 0, 0 } };
727
728   GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name,
729       num_slaves, num_masters, test_core,
730       &do_benchmark, NULL, handlers, &transport_recv_cb,
731       &ats_performance_info_cb);
732
733   return result;
734 }
735
736 /* end of file perf_ats.c */