daffb9f289539d84bc060b09ccf490cd753c62d3
[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   GNUNET_break (0);
432   if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
433       (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
434       TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
435   {
436     return;
437   }
438   if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
439     comm_handle_ping (cls, peer, message);
440
441   if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
442     comm_handle_pong (cls, peer, message);
443 }
444
445
446
447
448
449 static void
450 ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
451     int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
452     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
453     const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
454 {
455   struct BenchmarkPeer *me = cls;
456   struct BenchmarkPartner *p;
457   int c_a;
458   int log;
459   char *peer_id;
460
461   p = find_partner (me, &address->peer);
462   if (NULL == p)
463   {
464     /* This is not one of my partners
465      * Will happen since the peers will connect to each other due to gossiping
466      */
467     return;
468   }
469   peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
470
471   log = GNUNET_NO;
472   if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
473       (p->bandwidth_out != ntohl (bandwidth_out.value__)))
474       log = GNUNET_YES;
475   p->bandwidth_in = ntohl (bandwidth_in.value__);
476   p->bandwidth_out = ntohl (bandwidth_out.value__);
477
478   for (c_a = 0; c_a < ats_count; c_a++)
479   {
480     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
481         (GNUNET_YES == p->me->master) ? "Master" : "Slave",
482         p->me->no,
483         GNUNET_i2s (&p->dest->id),
484         GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
485         ntohl(ats[c_a].value));
486     switch (ntohl (ats[c_a].type ))
487     {
488       case GNUNET_ATS_ARRAY_TERMINATOR:
489         break;
490       case GNUNET_ATS_UTILIZATION_OUT:
491         if (p->ats_utilization_up != ntohl (ats[c_a].value))
492             log = GNUNET_YES;
493         p->ats_utilization_up = ntohl (ats[c_a].value);
494
495         break;
496       case GNUNET_ATS_UTILIZATION_IN:
497         if (p->ats_utilization_down != ntohl (ats[c_a].value))
498             log = GNUNET_YES;
499         p->ats_utilization_down = ntohl (ats[c_a].value);
500         break;
501       case GNUNET_ATS_NETWORK_TYPE:
502         if (p->ats_network_type != ntohl (ats[c_a].value))
503             log = GNUNET_YES;
504         p->ats_network_type = ntohl (ats[c_a].value);
505         break;
506       case GNUNET_ATS_QUALITY_NET_DELAY:
507         if (p->ats_delay != ntohl (ats[c_a].value))
508             log = GNUNET_YES;
509         p->ats_delay = ntohl (ats[c_a].value);
510         break;
511       case GNUNET_ATS_QUALITY_NET_DISTANCE:
512         if (p->ats_distance != ntohl (ats[c_a].value))
513             log = GNUNET_YES;
514         p->ats_distance = ntohl (ats[c_a].value);
515         GNUNET_break (0);
516         break;
517       case GNUNET_ATS_COST_WAN:
518         if (p->ats_cost_wan != ntohl (ats[c_a].value))
519             log = GNUNET_YES;
520         p->ats_cost_wan = ntohl (ats[c_a].value);
521         break;
522       case GNUNET_ATS_COST_LAN:
523         if (p->ats_cost_lan != ntohl (ats[c_a].value))
524             log = GNUNET_YES;
525         p->ats_cost_lan = ntohl (ats[c_a].value);
526         break;
527       case GNUNET_ATS_COST_WLAN:
528         if (p->ats_cost_wlan != ntohl (ats[c_a].value))
529             log = GNUNET_YES;
530         p->ats_cost_wlan = ntohl (ats[c_a].value);
531         break;
532       default:
533         break;
534     }
535   }
536   /*
537   if ((GNUNET_YES == logging) && (GNUNET_YES == log))
538     collect_log_now();
539     */
540   GNUNET_free(peer_id);
541 }
542
543
544
545
546
547 int
548 main (int argc, char *argv[])
549 {
550   char *tmp;
551   char *tmp_sep;
552   char *test_name;
553   char *conf_name;
554   char *comm_name;
555   char *dotexe;
556   char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
557   int c;
558
559   result = 0;
560
561   /* figure out testname */
562   tmp = strstr (argv[0], TESTNAME_PREFIX);
563   if (NULL == tmp)
564   {
565     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
566     return GNUNET_SYSERR;
567   }
568   tmp += strlen (TESTNAME_PREFIX);
569   solver = GNUNET_strdup (tmp);
570   if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
571     dotexe[0] = '\0';
572   tmp_sep = strchr (solver, '_');
573   if (NULL == tmp_sep)
574   {
575     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
576     GNUNET_free(solver);
577     return GNUNET_SYSERR;
578   }
579   tmp_sep[0] = '\0';
580   comm_name = GNUNET_strdup (&tmp_sep[1]);
581   tmp_sep = strchr (comm_name, '_');
582   if (NULL == tmp_sep)
583   {
584     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
585     GNUNET_free(solver);
586     return GNUNET_SYSERR;
587   }
588   tmp_sep[0] = '\0';
589   for (c = 0; c <= strlen (comm_name); c++)
590     comm_name[c] = toupper (comm_name[c]);
591   if (0 == strcmp (comm_name, "CORE"))
592     test_core = GNUNET_YES;
593   else if (0 == strcmp (comm_name, "TRANSPORT"))
594     test_core = GNUNET_NO;
595   else
596   {
597     GNUNET_free (comm_name);
598     GNUNET_free (solver);
599     return GNUNET_SYSERR;
600   }
601
602   pref_str = GNUNET_strdup(tmp_sep + 1);
603
604   GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
605       pref_str);
606   GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
607
608   for (c = 0; c <= strlen (pref_str); c++)
609     pref_str[c] = toupper (pref_str[c]);
610   pref_val = -1;
611
612   if (0 != strcmp (pref_str, "NONE"))
613   {
614     for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
615     {
616       if (0 == strcmp (pref_str, prefs[c]))
617       {
618         pref_val = c;
619         break;
620       }
621     }
622   }
623   else
624   {
625     /* abuse terminator to indicate no pref */
626     pref_val = GNUNET_ATS_PREFERENCE_END;
627   }
628   if (-1 == pref_val)
629   {
630     fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
631     GNUNET_free(solver);
632     GNUNET_free(pref_str);
633     GNUNET_free (comm_name);
634     return -1;
635   }
636
637   for (c = 0; c < (argc - 1); c++)
638   {
639     if (0 == strcmp (argv[c], "-d"))
640       break;
641   }
642   if (c < argc - 1)
643   {
644     if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration))
645         fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
646   }
647   else
648   {
649     perf_duration = BENCHMARK_DURATION;
650   }
651   fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000));
652
653   for (c = 0; c < (argc - 1); c++)
654   {
655     if (0 == strcmp (argv[c], "-s"))
656       break;
657   }
658   if (c < argc - 1)
659   {
660     if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
661         && (num_slaves >= 1))
662       fprintf (stderr, "Starting %u slave peers\n", num_slaves);
663     else
664       num_slaves = DEFAULT_SLAVES_NUM;
665   }
666   else
667     num_slaves = DEFAULT_SLAVES_NUM;
668
669   for (c = 0; c < (argc - 1); c++)
670   {
671     if (0 == strcmp (argv[c], "-m"))
672       break;
673   }
674   if (c < argc - 1)
675   {
676     if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
677         && (num_masters >= 2))
678       fprintf (stderr, "Starting %u master peers\n", num_masters);
679     else
680       num_masters = DEFAULT_MASTERS_NUM;
681   }
682   else
683     num_masters = DEFAULT_MASTERS_NUM;
684
685   logging = GNUNET_NO;
686   for (c = 0; c < argc; c++)
687   {
688     if (0 == strcmp (argv[c], "-l"))
689       logging = GNUNET_YES;
690   }
691
692   if (GNUNET_YES == logging)
693   {
694     for (c = 0; c < (argc - 1); c++)
695     {
696       if (0 == strcmp (argv[c], "-f"))
697         break;
698     }
699     if (c < argc - 1)
700     {
701       if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency))
702           fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
703     }
704     else
705     {
706       log_frequency = LOGGING_FREQUENCY;
707     }
708     fprintf (stderr, "Using log frequency %llu ms\n",
709         (unsigned long long) (log_frequency.rel_value_us) / (1000));
710   }
711
712   GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str);
713
714   if (num_slaves < num_masters)
715   {
716     fprintf (stderr, "Number of master peers is lower than slaves! exit...\n");
717     GNUNET_free(test_name);
718     GNUNET_free(solver);
719     GNUNET_free(pref_str);
720     GNUNET_free (comm_name);
721     return GNUNET_SYSERR;
722   }
723
724   static struct GNUNET_CORE_MessageHandler handlers[] = {
725       {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
726       {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
727       { NULL, 0, 0 } };
728
729   GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name,
730       num_slaves, num_masters, test_core,
731       &do_benchmark, NULL, handlers, &transport_recv_cb);
732
733   return result;
734 }
735
736 /* end of file perf_ats.c */