implemented ATS perf info logging + push logging
[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 "perf_ats.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  * Connect peers with testbed
45  */
46 struct TestbedConnectOperation
47 {
48   /**
49    * The benchmarking master initiating this connection
50    */
51   struct BenchmarkPeer *master;
52
53   /**
54    * The benchmarking slave to connect to
55    */
56   struct BenchmarkPeer *slave;
57
58   /**
59    * Testbed operation to connect peers
60    */
61   struct GNUNET_TESTBED_Operation *connect_op;
62 };
63
64 /**
65  * Overall state of the performance benchmark
66  */
67 struct BenchmarkState
68 {
69   /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
70   int connected_ATS_service;
71
72   /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
73   int connected_COMM_service;
74
75   /* Are we connected to all peers: GNUNET_YES/NO */
76   int connected_PEERS;
77
78   /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
79   int connected_CORE;
80
81   /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
82   int benchmarking;
83 };
84
85 /**
86  * Shutdown task
87  */
88 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
89
90 /**
91  * Progress task
92  */
93 static GNUNET_SCHEDULER_TaskIdentifier progress_task;
94
95 /**
96  * Test result
97  */
98 static int result;
99
100 /**
101  * Test result logging
102  */
103 static int logging;
104
105 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
106  */
107 static int test_core;
108
109 /**
110  * Solver string
111  */
112 static char *solver;
113
114 /**
115  * Preference string
116  */
117 static char *testname;
118
119 /**
120  * Preference string
121  */
122 static char *pref_str;
123
124 /**
125  * ATS preference value
126  */
127 static int pref_val;
128
129 /**
130  * Number master peers
131  */
132 static int num_masters;
133
134 /**
135  * Array of master peers
136  */
137 static  struct BenchmarkPeer *mps;
138
139 /**
140  * Number slave peers
141  */
142 static int num_slaves;
143 /**
144  * Array of slave peers
145  */
146 static struct BenchmarkPeer *sps;
147
148 /**
149  * Benchmark duration
150  */
151 static struct GNUNET_TIME_Relative perf_duration;
152
153 /**
154  * Logging frequency
155  */
156 static struct GNUNET_TIME_Relative log_frequency;
157
158 /**
159  * Benchmark state
160  */
161 static struct BenchmarkState state;
162
163 static void
164 evaluate ()
165 {
166   int c_m;
167   int c_s;
168   unsigned int duration;
169   struct BenchmarkPeer *mp;
170   struct BenchmarkPartner *p;
171
172   duration = (perf_duration.rel_value_us / (1000 * 1000));
173   for (c_m = 0; c_m < num_masters; c_m++)
174   {
175     mp = &mps[c_m];
176     fprintf (stderr,
177         _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
178         mp->no, mp->total_bytes_sent / 1024, duration,
179         (mp->total_bytes_sent / 1024) / duration,
180         mp->total_bytes_received / 1024, duration,
181         (mp->total_bytes_received / 1024) / duration);
182
183     for (c_s = 0; c_s < num_slaves; c_s++)
184     {
185       p = &mp->partners[c_s];
186       fprintf (stderr,
187           "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f \%), received %u KiB/s (%.2f \%)\n",
188           (mp->pref_partner == p->dest) ? '*' : ' ',
189           mp->no, p->dest->no,
190           (p->bytes_sent / 1024) / duration,
191           ((double) p->bytes_sent * 100) / mp->total_bytes_sent,
192           (p->bytes_received / 1024) / duration,
193           ((double) p->bytes_received * 100) / mp->total_bytes_received );
194       fprintf (stderr,
195           "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
196           (mp->pref_partner == p->dest) ? '*' : ' ',
197           mp->no, p->dest->no,
198           p->total_app_rtt / (1000 * p->messages_sent));
199     }
200   }
201 }
202
203 /**
204  * Shutdown nicely
205  *
206  * @param cls NULL
207  * @param tc the task context
208  */
209 static void
210 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
211 {
212   int c_m;
213   int c_s;
214   int c_op;
215
216   if (GNUNET_YES == logging)
217     perf_logging_stop();
218
219   shutdown_task = GNUNET_SCHEDULER_NO_TASK;
220   if (GNUNET_SCHEDULER_NO_TASK != progress_task)
221   {
222     fprintf (stderr, "0\n");
223     GNUNET_SCHEDULER_cancel (progress_task);
224   }
225   progress_task = GNUNET_SCHEDULER_NO_TASK;
226
227   evaluate ();
228   state.benchmarking = GNUNET_NO;
229   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
230
231   for (c_m = 0; c_m < num_masters; c_m++)
232   {
233     if (NULL != mps[c_m].peer_id_op)
234     {
235       GNUNET_TESTBED_operation_done (mps[c_m].peer_id_op);
236       mps[c_m].peer_id_op = NULL;
237     }
238
239     if (GNUNET_SCHEDULER_NO_TASK != mps[c_m].ats_task)
240       GNUNET_SCHEDULER_cancel (mps[c_m].ats_task);
241     mps[c_m].ats_task = GNUNET_SCHEDULER_NO_TASK;
242
243     for (c_op = 0; c_op < num_slaves; c_op++)
244     {
245
246       if (NULL != mps[c_m].partners[c_op].cth)
247       {
248         GNUNET_CORE_notify_transmit_ready_cancel (mps[c_m].partners[c_op].cth);
249         mps[c_m].partners[c_op].cth = NULL;
250       }
251       if (NULL != mps[c_m].partners[c_op].tth)
252       {
253         GNUNET_TRANSPORT_notify_transmit_ready_cancel (mps[c_m].partners[c_op].tth);
254         mps[c_m].partners[c_op].tth = NULL;
255       }
256
257
258       if (NULL != mps[c_m].core_connect_ops[c_op].connect_op)
259       {
260         GNUNET_log(GNUNET_ERROR_TYPE_INFO,
261             _("Failed to connect peer 0 and %u\n"), c_op);
262         GNUNET_TESTBED_operation_done (
263             mps[c_m].core_connect_ops[c_op].connect_op);
264         mps[c_m].core_connect_ops[c_op].connect_op = NULL;
265         result = 1;
266       }
267     }
268
269     if (NULL != mps[c_m].ats_perf_op)
270     {
271       GNUNET_TESTBED_operation_done (mps[c_m].ats_perf_op);
272       mps[c_m].ats_perf_op = NULL;
273     }
274
275     if (NULL != mps[c_m].comm_op)
276     {
277       GNUNET_TESTBED_operation_done (mps[c_m].comm_op);
278       mps[c_m].comm_op = NULL;
279     }
280     GNUNET_free(mps[c_m].core_connect_ops);
281     GNUNET_free(mps[c_m].partners);
282     mps[c_m].partners = NULL;
283   }
284
285   for (c_s = 0; c_s < num_slaves; c_s++)
286   {
287     if (NULL != sps[c_s].peer_id_op)
288     {
289       GNUNET_TESTBED_operation_done (sps[c_s].peer_id_op);
290       sps[c_s].peer_id_op = NULL;
291     }
292
293     for (c_op = 0; c_op < num_slaves; c_op++)
294     {
295       if (NULL != sps[c_s].partners[c_op].cth)
296       {
297         GNUNET_CORE_notify_transmit_ready_cancel (sps[c_s].partners[c_op].cth);
298         sps[c_s].partners[c_op].cth = NULL;
299       }
300
301       if (NULL != sps[c_s].partners[c_op].tth)
302       {
303         GNUNET_TRANSPORT_notify_transmit_ready_cancel (sps[c_s].partners[c_op].tth);
304         sps[c_s].partners[c_op].tth = NULL;
305       }
306     }
307
308     if (NULL != sps[c_s].ats_perf_op)
309     {
310       GNUNET_TESTBED_operation_done (sps[c_s].ats_perf_op);
311       sps[c_s].ats_perf_op = NULL;
312     }
313     if (NULL != sps[c_s].comm_op)
314     {
315       GNUNET_TESTBED_operation_done (sps[c_s].comm_op);
316       sps[c_s].comm_op = NULL;
317     }
318
319     GNUNET_free(sps[c_s].partners);
320     sps[c_s].partners = NULL;
321   }
322
323   GNUNET_SCHEDULER_shutdown ();
324 }
325
326 static struct BenchmarkPeer *
327 find_peer (const struct GNUNET_PeerIdentity * peer)
328 {
329   int c_p;
330
331   for (c_p = 0; c_p < num_masters; c_p++)
332   {
333     if (0 == memcmp (&mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
334       return &mps[c_p];
335   }
336
337   for (c_p = 0; c_p < num_slaves; c_p++)
338   {
339     if (0 == memcmp (&sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
340       return &sps[c_p];
341   }
342   return NULL ;
343 }
344
345 /**
346  * Controller event callback
347  *
348  * @param cls NULL
349  * @param event the controller event
350  */
351 static void
352 controller_event_cb (void *cls,
353     const struct GNUNET_TESTBED_EventInformation *event)
354 {
355   //struct BenchmarkPeer *p = cls;
356   switch (event->type)
357   {
358   case GNUNET_TESTBED_ET_CONNECT:
359     break;
360   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
361     break;
362   default:
363     GNUNET_break(0);
364     result = 2;
365     GNUNET_SCHEDULER_cancel (shutdown_task);
366     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
367   }
368 }
369
370 static size_t
371 comm_send_ready (void *cls, size_t size, void *buf)
372 {
373   static char msgbuf[TEST_MESSAGE_SIZE];
374   struct BenchmarkPartner *p = cls;
375   struct GNUNET_MessageHeader *msg;
376
377   if (GNUNET_YES == test_core)
378     p->cth = NULL;
379   else
380     p->tth = NULL;
381
382   if (NULL == buf)
383   {
384     GNUNET_break (0);
385     return 0;
386   }
387   if (size < TEST_MESSAGE_SIZE)
388   {
389     GNUNET_break (0);
390     return 0;
391   }
392
393   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n",
394       p->me->no, p->dest->no);
395
396   p->messages_sent++;
397   p->bytes_sent += TEST_MESSAGE_SIZE;
398   p->me->total_messages_sent++;
399   p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
400
401   msg = (struct GNUNET_MessageHeader *) &msgbuf;
402   memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
403   msg->type = htons (TEST_MESSAGE_TYPE_PING);
404   msg->size = htons (TEST_MESSAGE_SIZE);
405   memcpy (buf, msg, TEST_MESSAGE_SIZE);
406   return TEST_MESSAGE_SIZE;
407 }
408
409 static void
410 comm_schedule_send (struct BenchmarkPartner *p)
411 {
412   p->last_message_sent = GNUNET_TIME_absolute_get();
413   if (GNUNET_YES == test_core)
414   {
415     p->cth = GNUNET_CORE_notify_transmit_ready (
416       p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
417       TEST_MESSAGE_SIZE, &comm_send_ready, p);
418   }
419   else
420   {
421     p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
422       p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
423       &comm_send_ready, p);
424   }
425
426 }
427
428 static void
429 print_progress ()
430 {
431   static int calls;
432   progress_task = GNUNET_SCHEDULER_NO_TASK;
433
434   fprintf (stderr, "%llu..",
435       (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls);
436   calls++;
437
438   progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
439       &print_progress, NULL );
440 }
441
442 static void
443 ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
444 {
445   struct BenchmarkPeer *me = cls;
446
447   me->ats_task = GNUNET_SCHEDULER_NO_TASK;
448
449   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n",
450       me->no, me->pref_partner->no, me->pref_value);
451   GNUNET_ATS_performance_change_preference (me->ats_perf_handle,
452       &me->pref_partner->id,
453       pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END);
454   me->pref_value += TEST_ATS_PREFRENCE_DELTA;
455   me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY,
456       &ats_pref_task, cls);
457 }
458
459 static void
460 do_benchmark ()
461 {
462   int c_m;
463   int c_s;
464
465   if ((state.connected_ATS_service == GNUNET_NO)
466       || (state.connected_COMM_service == GNUNET_NO)
467       || (state.connected_PEERS == GNUNET_NO)
468       || (state.connected_CORE == GNUNET_NO))
469     return;
470
471   state.benchmarking = GNUNET_YES;
472   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
473
474   if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
475     GNUNET_SCHEDULER_cancel (shutdown_task);
476   shutdown_task = GNUNET_SCHEDULER_add_delayed (perf_duration,
477       &do_shutdown, NULL );
478
479   progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL );
480
481   /* Start sending test messages */
482   for (c_m = 0; c_m < num_masters; c_m++)
483   {
484     for (c_s = 0; c_s < num_slaves; c_s++)
485       comm_schedule_send (&mps[c_m].partners[c_s]);
486     if (pref_val != GNUNET_ATS_PREFERENCE_END)
487       mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &mps[c_m]);
488   }
489   if (GNUNET_YES == logging)
490     perf_logging_start (log_frequency, testname, mps, num_masters);
491
492 }
493
494 static void
495 connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
496     const char *emsg)
497 {
498   struct TestbedConnectOperation *cop = cls;
499   static int ops = 0;
500   int c;
501   if (NULL == emsg)
502   {
503     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
504         _("Connected master [%u] with slave [%u]\n"), cop->master->no,
505         cop->slave->no);
506   }
507   else
508   {
509     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
510         _("Failed to connect master peer [%u] with slave [%u]\n"),
511         cop->master->no, cop->slave->no);
512     GNUNET_break(0);
513     if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
514       GNUNET_SCHEDULER_cancel (shutdown_task);
515     shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
516   }
517   GNUNET_TESTBED_operation_done (op);
518   ops++;
519   for (c = 0; c < num_slaves; c++)
520   {
521     if (cop == &cop->master->core_connect_ops[c])
522       cop->master->core_connect_ops[c].connect_op = NULL;
523   }
524   if (ops == num_masters * num_slaves)
525   {
526     state.connected_PEERS = GNUNET_YES;
527     GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
528   }
529 }
530
531 static void
532 do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
533 {
534   int c_m;
535   int c_s;
536   struct BenchmarkPeer *p;
537
538   if ((state.connected_ATS_service == GNUNET_NO)
539       || (state.connected_COMM_service == GNUNET_NO))
540     return;
541
542   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
543
544   for (c_m = 0; c_m < num_masters; c_m++)
545   {
546     p = &mps[c_m];
547     p->core_connect_ops = GNUNET_malloc (num_slaves *
548         sizeof (struct TestbedConnectOperation));
549
550     for (c_s = 0; c_s < num_slaves; c_s++)
551     {
552       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
553           _("Connecting master [%u] with slave [%u]\n"), p->no, sps[c_s].no);
554       p->core_connect_ops[c_s].master = p;
555       p->core_connect_ops[c_s].slave = &sps[c_s];
556       p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (
557           NULL, &connect_completion_callback, &p->core_connect_ops[c_s],
558           sps[c_s].peer, p->peer);
559       if (NULL == p->core_connect_ops[c_s].connect_op)
560       {
561         GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
562             _("Could not connect master [%u] and slave [%u]\n"), p->no,
563             sps[c_s].no);
564         GNUNET_break(0);
565         if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
566           GNUNET_SCHEDULER_cancel (shutdown_task);
567         shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
568         return;
569       }
570     }
571   }
572 }
573
574 /**
575  * Method called whenever a given peer connects.
576  *
577  * @param cls closure
578  * @param peer peer identity this notification is about
579  */
580 static void
581 comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
582 {
583   struct BenchmarkPeer *me = cls;
584   struct BenchmarkPeer *remote;
585   char *id;
586   int c;
587   int completed;
588
589   remote = find_peer (peer);
590   if (NULL == remote)
591   {
592     GNUNET_break(0);
593     return;
594   }
595
596   id = GNUNET_strdup (GNUNET_i2s (&me->id));
597   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n",
598       (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id,
599       (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no,
600       GNUNET_i2s (peer));
601
602   me->core_connections++;
603   if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master)
604       && (GNUNET_NO == state.connected_CORE))
605   {
606     me->core_slave_connections++;
607
608     if (me->core_slave_connections == num_slaves)
609     {
610       GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
611           me->no);
612     }
613     completed = GNUNET_YES;
614     for (c = 0; c < num_masters; c++)
615     {
616       if (mps[c].core_slave_connections != num_slaves)
617         completed = GNUNET_NO;
618     }
619     if (GNUNET_YES == completed)
620     {
621       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
622           "All master peers connected all slave peers\n", id,
623           GNUNET_i2s (peer));
624       state.connected_CORE = GNUNET_YES;
625       GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
626     }
627   }
628   GNUNET_free(id);
629 }
630
631 static void
632 comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
633 {
634   struct BenchmarkPeer *me = cls;
635   struct BenchmarkPeer *remote;
636   char *id;
637
638   remote = find_peer (peer);
639   if (NULL == remote)
640   {
641     GNUNET_break(0);
642     return;
643   }
644
645   id = GNUNET_strdup (GNUNET_i2s (&me->id));
646   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
647       GNUNET_i2s (peer));
648   GNUNET_assert(me->core_connections > 0);
649   me->core_connections--;
650
651   if ((GNUNET_YES == state.benchmarking)
652       && ((GNUNET_YES == me->master) || (GNUNET_YES == remote->master)))
653   {
654     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
655         "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
656   }
657   GNUNET_free(id);
658 }
659
660 static size_t
661 comm_send_pong_ready (void *cls, size_t size, void *buf)
662 {
663   static char msgbuf[TEST_MESSAGE_SIZE];
664   struct BenchmarkPartner *p = cls;
665   struct GNUNET_MessageHeader *msg;
666
667   if (GNUNET_YES == test_core)
668     p->cth = NULL;
669   else
670     p->tth = NULL;
671
672   p->messages_sent++;
673   p->bytes_sent += TEST_MESSAGE_SIZE;
674   p->me->total_messages_sent++;
675   p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
676
677   msg = (struct GNUNET_MessageHeader *) &msgbuf;
678   memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
679   msg->type = htons (TEST_MESSAGE_TYPE_PONG);
680   msg->size = htons (TEST_MESSAGE_SIZE);
681   memcpy (buf, msg, TEST_MESSAGE_SIZE);
682
683   return TEST_MESSAGE_SIZE;
684 }
685
686 static int
687 comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
688     const struct GNUNET_MessageHeader *message)
689 {
690   int c_m;
691   struct BenchmarkPeer *me = cls;
692   struct BenchmarkPartner *p = NULL;
693   for (c_m = 0; c_m < num_masters; c_m++)
694   {
695     /* Find a partner with other as destination */
696     if (0 == memcmp (other, &me->partners[c_m].dest->id,
697             sizeof(struct GNUNET_PeerIdentity)))
698     {
699       p = &me->partners[c_m];
700       break;
701     }
702   }
703   if (NULL == p)
704   {
705     GNUNET_break(0);
706     return GNUNET_SYSERR;
707   }
708
709   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
710       "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
711       p->dest->no);
712
713   p->messages_received++;
714   p->bytes_received += TEST_MESSAGE_SIZE;
715   p->me->total_messages_received++;
716   p->me->total_bytes_received += TEST_MESSAGE_SIZE;
717
718   if (GNUNET_YES == test_core)
719   {
720     GNUNET_assert (NULL == p->cth);
721     p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
722         GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
723         &comm_send_pong_ready, p);
724   }
725   else
726   {
727     GNUNET_assert (NULL == p->tth);
728     p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
729         TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
730         p);
731   }
732   return GNUNET_OK;
733 }
734
735 static int
736 comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
737     const struct GNUNET_MessageHeader *message)
738 {
739   int c_s;
740   struct BenchmarkPeer *me = cls;
741   struct BenchmarkPartner *p = NULL;
742
743   for (c_s = 0; c_s < num_slaves; c_s++)
744   {
745     if (0
746         == memcmp (other, &me->partners[c_s].dest->id,
747             sizeof(struct GNUNET_PeerIdentity)))
748     {
749       p = &me->partners[c_s];
750       break;
751     }
752   }
753   if (NULL == p)
754   {
755     GNUNET_break(0);
756     return GNUNET_SYSERR;
757   }
758
759
760   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
761       "Master [%u]: Received PONG from [%u], next message\n", me->no,
762       p->dest->no);
763
764   p->messages_received++;
765   p->bytes_received += TEST_MESSAGE_SIZE;
766   p->me->total_messages_received++;
767   p->me->total_bytes_received += TEST_MESSAGE_SIZE;
768   p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
769       GNUNET_TIME_absolute_get()).rel_value_us;
770
771   comm_schedule_send (p);
772   return GNUNET_OK;
773 }
774
775 static void *
776 core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
777 {
778   struct BenchmarkPeer *me = cls;
779
780   static const struct GNUNET_CORE_MessageHandler handlers[] = { {
781       &comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &comm_handle_pong,
782       TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } };
783
784   me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb,
785       comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
786   if (NULL == me->ch)
787     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
788   return me->ch;
789 }
790
791 static void
792 core_disconnect_adapter (void *cls, void *op_result)
793 {
794   struct BenchmarkPeer *me = cls;
795
796   GNUNET_CORE_disconnect (me->ch);
797   me->ch = NULL;
798 }
799
800 static void
801 comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
802     void *ca_result, const char *emsg)
803 {
804   static int comm_done = 0;
805   if ((NULL != emsg) || (NULL == ca_result))
806   {
807     GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
808     GNUNET_break(0);
809     if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
810       GNUNET_SCHEDULER_cancel (shutdown_task);
811     shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
812     return;
813   }
814   comm_done++;
815
816   if (comm_done == num_slaves + num_masters)
817   {
818     GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n",
819         (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
820     state.connected_COMM_service = GNUNET_YES;
821     GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
822   }
823 }
824
825 static void
826 transport_recv_cb (void *cls,
827                    const struct GNUNET_PeerIdentity * peer,
828                    const struct GNUNET_MessageHeader * message)
829 {
830   if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
831       (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
832       TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
833   {
834     return;
835   }
836   if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
837     comm_handle_ping (cls, peer, message);
838
839   if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
840     comm_handle_pong (cls, peer, message);
841 }
842
843
844 static void *
845 transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
846 {
847   struct BenchmarkPeer *me = cls;
848
849   me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me,  &transport_recv_cb,
850       &comm_connect_cb, &comm_disconnect_cb);
851   if (NULL == me->th)
852     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
853   return me->th;
854 }
855
856 static void
857 transport_disconnect_adapter (void *cls, void *op_result)
858 {
859   struct BenchmarkPeer *me = cls;
860
861   GNUNET_TRANSPORT_disconnect (me->th);
862   me->th = NULL;
863 }
864
865 static void
866 do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
867 {
868   int c_s;
869   int c_m;
870   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all %s services\n",
871       (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
872   for (c_m = 0; c_m < num_masters; c_m++)
873   {
874     if (GNUNET_YES == test_core)
875       mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
876         "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
877         &core_disconnect_adapter, &mps[c_m]);
878     else
879     {
880       mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
881         "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
882         &transport_disconnect_adapter, &mps[c_m]);
883     }
884   }
885
886   for (c_s = 0; c_s < num_slaves; c_s++)
887   {
888     if (GNUNET_YES == test_core)
889       sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
890         "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
891         &core_disconnect_adapter, &sps[c_s]);
892     else
893     {
894       sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
895         "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
896         &transport_disconnect_adapter, &sps[c_s]);
897     }
898   }
899 }
900
901 static void
902 ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
903     int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
904     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
905     const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
906 {
907   struct BenchmarkPeer *me = cls;
908   struct BenchmarkPartner *p;
909   int c_s;
910   int c_a;
911   char *peer_id;
912
913   p = NULL;
914   for (c_s = 0; c_s < me->num_partners; c_s++)
915   {
916
917     if (0 == memcmp (&address->peer, &me->partners[c_s].dest->id,
918         sizeof (struct GNUNET_PeerIdentity)))
919     {
920       p = &me->partners[c_s];
921       break;
922     }
923
924   }
925
926   if (NULL == p)
927   {
928     /* This is not one of my partners
929      * Will happen since the peers will connect to each other due to gossiping
930      */
931     return;
932   }
933
934   peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
935
936   for (c_a = 0; c_a < ats_count; c_a++)
937   {
938     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
939         (GNUNET_YES == p->me->master) ? "Master" : "Slave",
940         p->me->no,
941         GNUNET_i2s (&p->dest->id),
942         GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
943         ntohl(ats[c_a].value));
944     switch (ntohl (ats[c_a].type ))
945     {
946       case GNUNET_ATS_ARRAY_TERMINATOR:
947         break;
948       case GNUNET_ATS_UTILIZATION_UP:
949         p->ats_utilization_up = ntohl (ats[c_a].value);
950         break;
951       case GNUNET_ATS_UTILIZATION_DOWN:
952         p->ats_utilization_down = ntohl (ats[c_a].value);
953         break;
954       case GNUNET_ATS_NETWORK_TYPE:
955         p->ats_network_type = ntohl (ats[c_a].value);
956         break;
957       case GNUNET_ATS_QUALITY_NET_DELAY:
958         p->ats_delay = ntohl (ats[c_a].value);
959         break;
960       case GNUNET_ATS_QUALITY_NET_DISTANCE:
961         p->ats_distance = ntohl (ats[c_a].value);
962         GNUNET_break (0);
963         break;
964       case GNUNET_ATS_COST_WAN:
965         p->ats_cost_wan = ntohl (ats[c_a].value);
966         break;
967       case GNUNET_ATS_COST_LAN:
968         p->ats_cost_lan = ntohl (ats[c_a].value);
969         break;
970       case GNUNET_ATS_COST_WLAN:
971         p->ats_cost_wlan = ntohl (ats[c_a].value);
972         break;
973         break;
974       default:
975         break;
976     }
977   }
978   if (GNUNET_YES == logging)
979     collect_log_now();
980   GNUNET_free(peer_id);
981 }
982
983 static void *
984 ats_perf_connect_adapter (void *cls,
985     const struct GNUNET_CONFIGURATION_Handle *cfg)
986 {
987   struct BenchmarkPeer *me = cls;
988
989   me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
990       &ats_performance_info_cb, me);
991   if (NULL == me->ats_perf_handle)
992     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
993         "Failed to create ATS performance handle \n");
994   return me->ats_perf_handle;
995 }
996
997 static void
998 ats_perf_disconnect_adapter (void *cls, void *op_result)
999 {
1000   struct BenchmarkPeer *me = cls;
1001
1002   GNUNET_ATS_performance_done (me->ats_perf_handle);
1003   me->ats_perf_handle = NULL;
1004 }
1005
1006 static void
1007 ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1008     void *ca_result, const char *emsg)
1009 {
1010   static int op_done = 0;
1011
1012   if ((NULL != emsg) || (NULL == ca_result))
1013   {
1014     GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
1015     GNUNET_break(0);
1016     if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
1017       GNUNET_SCHEDULER_cancel (shutdown_task);
1018     shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
1019     return;
1020   }
1021   op_done++;
1022   if (op_done == (num_masters + num_slaves))
1023   {
1024     GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
1025     state.connected_ATS_service = GNUNET_YES;
1026     GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL );
1027   }
1028 }
1029
1030 static void
1031 do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1032 {
1033   int c_m;
1034   int c_s;
1035
1036   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
1037   for (c_m = 0; c_m < num_masters; c_m++)
1038   {
1039     mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
1040         "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
1041         &ats_perf_disconnect_adapter, &mps[c_m]);
1042
1043   }
1044
1045   for (c_s = 0; c_s < num_slaves; c_s++)
1046   {
1047     sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
1048         "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
1049         &ats_perf_disconnect_adapter, &sps[c_s]);
1050   }
1051
1052 }
1053
1054 static void
1055 peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
1056     const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
1057 {
1058   struct BenchmarkPeer *p = cb_cls;
1059   static int done = 0;
1060
1061   GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
1062
1063   p->id = *pinfo->result.id;
1064   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
1065       (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
1066       GNUNET_i2s (&p->id));
1067
1068   GNUNET_TESTBED_operation_done (op);
1069   p->peer_id_op = NULL;
1070   done++;
1071
1072   if (done == num_slaves + num_masters)
1073   {
1074     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1075         "Retrieved all peer ID, connect to ATS\n");
1076     GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
1077   }
1078 }
1079
1080 /**
1081  * Signature of a main function for a testcase.
1082  *
1083  * @param cls closure
1084  * @param num_peers number of peers in 'peers'
1085  * @param peers_ handle to peers run in the testbed
1086  * @param links_succeeded the number of overlay link connection attempts that
1087  *          succeeded
1088  * @param links_failed the number of overlay link connection attempts that
1089  *          failed
1090  */
1091 static void
1092 main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
1093     struct GNUNET_TESTBED_Peer **peers_, unsigned int links_succeeded,
1094     unsigned int links_failed)
1095 {
1096   int c_m;
1097   int c_s;
1098   GNUNET_assert(NULL == cls);
1099   GNUNET_assert(num_masters + num_slaves == num_peers);
1100   GNUNET_assert(NULL != peers_);
1101
1102   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1103       _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
1104       solver, pref_str, num_masters, num_slaves);
1105
1106   shutdown_task = GNUNET_SCHEDULER_add_delayed (
1107       GNUNET_TIME_relative_multiply (TEST_TIMEOUT, num_masters + num_slaves),
1108       &do_shutdown, NULL );
1109
1110   /* Setup master peers */
1111   for (c_m = 0; c_m < num_masters; c_m++)
1112   {
1113     GNUNET_assert(NULL != peers_[c_m]);
1114     mps[c_m].peer = peers_[c_m];
1115     mps[c_m].no = c_m;
1116     mps[c_m].master = GNUNET_YES;
1117     mps[c_m].pref_partner = &sps[c_m];
1118     mps[c_m].pref_value = TEST_ATS_PREFRENCE_START;
1119     mps[c_m].partners =
1120         GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1121     mps[c_m].num_partners = num_slaves;
1122     /* Initialize partners */
1123     for (c_s = 0; c_s < num_slaves; c_s++)
1124     {
1125       mps[c_m].partners[c_s].me = &mps[c_m];
1126       mps[c_m].partners[c_s].dest = &sps[c_s];
1127     }
1128     mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (mps[c_m].peer,
1129         GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &mps[c_m]);
1130   }
1131
1132   /* Setup slave peers */
1133   for (c_s = 0; c_s < num_slaves; c_s++)
1134   {
1135     GNUNET_assert(NULL != peers_[c_s + num_masters]);
1136     sps[c_s].peer = peers_[c_s + num_masters];
1137     sps[c_s].no = c_s + num_masters;
1138     sps[c_s].master = GNUNET_NO;
1139     sps[c_s].partners =
1140         GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1141     sps[c_s].num_partners = num_masters;
1142     /* Initialize partners */
1143     for (c_m = 0; c_m < num_masters; c_m++)
1144     {
1145       sps[c_s].partners[c_m].me = &sps[c_s];
1146       sps[c_s].partners[c_m].dest = &mps[c_m];
1147     }
1148     sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (sps[c_s].peer,
1149         GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &sps[c_s]);
1150   }
1151 }
1152
1153 int
1154 main (int argc, char *argv[])
1155 {
1156   char *tmp;
1157   char *tmp_sep;
1158   char *test_name;
1159   char *conf_name;
1160   char *comm_name;
1161   char *dotexe;
1162   char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1163   int c;
1164
1165   result = 0;
1166
1167   /* figure out testname */
1168   tmp = strstr (argv[0], TESTNAME_PREFIX);
1169   if (NULL == tmp)
1170   {
1171     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1172     return GNUNET_SYSERR;
1173   }
1174   tmp += strlen (TESTNAME_PREFIX);
1175   solver = GNUNET_strdup (tmp);
1176   if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
1177     dotexe[0] = '\0';
1178   tmp_sep = strchr (solver, '_');
1179   if (NULL == tmp_sep)
1180   {
1181     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1182     GNUNET_free(solver);
1183     return GNUNET_SYSERR;
1184   }
1185   tmp_sep[0] = '\0';
1186   comm_name = GNUNET_strdup (&tmp_sep[1]);
1187   tmp_sep = strchr (comm_name, '_');
1188   if (NULL == tmp_sep)
1189   {
1190     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1191     GNUNET_free(solver);
1192     return GNUNET_SYSERR;
1193   }
1194   tmp_sep[0] = '\0';
1195   for (c = 0; c <= strlen (comm_name); c++)
1196     comm_name[c] = toupper (comm_name[c]);
1197   if (0 == strcmp (comm_name, "CORE"))
1198     test_core = GNUNET_YES;
1199   else if (0 == strcmp (comm_name, "TRANSPORT"))
1200     test_core = GNUNET_NO;
1201   else
1202   {
1203     GNUNET_free (comm_name);
1204     GNUNET_free (solver);
1205     return GNUNET_SYSERR;
1206   }
1207
1208   pref_str = GNUNET_strdup(tmp_sep + 1);
1209
1210   GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
1211       pref_str);
1212   GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
1213
1214   for (c = 0; c <= strlen (pref_str); c++)
1215     pref_str[c] = toupper (pref_str[c]);
1216   pref_val = -1;
1217
1218   if (0 != strcmp (pref_str, "NONE"))
1219   {
1220     for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
1221     {
1222       if (0 == strcmp (pref_str, prefs[c]))
1223       {
1224         pref_val = c;
1225         break;
1226       }
1227     }
1228   }
1229   else
1230   {
1231     /* abuse terminator to indicate no pref */
1232     pref_val = GNUNET_ATS_PREFERENCE_END;
1233   }
1234   if (-1 == pref_val)
1235   {
1236     fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
1237     GNUNET_free(solver);
1238     GNUNET_free(pref_str);
1239     GNUNET_free (comm_name);
1240     return -1;
1241   }
1242
1243   for (c = 0; c < (argc - 1); c++)
1244   {
1245     if (0 == strcmp (argv[c], "-d"))
1246       break;
1247   }
1248   if (c < argc - 1)
1249   {
1250     if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration))
1251         fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
1252   }
1253   else
1254   {
1255     perf_duration = BENCHMARK_DURATION;
1256   }
1257   fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000));
1258
1259   for (c = 0; c < (argc - 1); c++)
1260   {
1261     if (0 == strcmp (argv[c], "-s"))
1262       break;
1263   }
1264   if (c < argc - 1)
1265   {
1266     if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
1267         && (num_slaves >= 1))
1268       fprintf (stderr, "Starting %u slave peers\n", num_slaves);
1269     else
1270       num_slaves = DEFAULT_SLAVES_NUM;
1271   }
1272   else
1273     num_slaves = DEFAULT_SLAVES_NUM;
1274
1275   for (c = 0; c < (argc - 1); c++)
1276   {
1277     if (0 == strcmp (argv[c], "-m"))
1278       break;
1279   }
1280   if (c < argc - 1)
1281   {
1282     if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
1283         && (num_masters >= 2))
1284       fprintf (stderr, "Starting %u master peers\n", num_masters);
1285     else
1286       num_masters = DEFAULT_MASTERS_NUM;
1287   }
1288   else
1289     num_masters = DEFAULT_MASTERS_NUM;
1290
1291   logging = GNUNET_NO;
1292   for (c = 0; c < argc; c++)
1293   {
1294     if (0 == strcmp (argv[c], "-l"))
1295       logging = GNUNET_YES;
1296   }
1297
1298   if (GNUNET_YES == logging)
1299   {
1300     for (c = 0; c < (argc - 1); c++)
1301     {
1302       if (0 == strcmp (argv[c], "-f"))
1303         break;
1304     }
1305     if (c < argc - 1)
1306     {
1307       if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency))
1308           fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
1309     }
1310     else
1311     {
1312       log_frequency = LOGGING_FREQUENCY;
1313     }
1314     fprintf (stderr, "Using log frequency %llu ms\n",
1315         (unsigned long long) (log_frequency.rel_value_us) / (1000));
1316   }
1317
1318   GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str);
1319
1320   if (num_slaves < num_masters)
1321   {
1322     fprintf (stderr, "Number of master peers is lower than slaves! exit...\n");
1323     GNUNET_free(test_name);
1324     GNUNET_free(solver);
1325     GNUNET_free(pref_str);
1326     GNUNET_free (comm_name);
1327     return GNUNET_SYSERR;
1328   }
1329
1330   state.connected_ATS_service = GNUNET_NO;
1331   state.connected_COMM_service = GNUNET_NO;
1332   state.connected_PEERS = GNUNET_NO;
1333   state.benchmarking = GNUNET_NO;
1334   state.connected_PEERS = GNUNET_NO;
1335
1336   mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1337   sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1338
1339   /* Start topology */
1340   uint64_t event_mask;
1341   event_mask = 0;
1342   event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1343   event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1344   (void) GNUNET_TESTBED_test_run ("perf-ats", conf_name,
1345       num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
1346       &main_run, NULL );
1347
1348   GNUNET_free(solver);
1349   GNUNET_free(pref_str);
1350   GNUNET_free(conf_name);
1351   GNUNET_free(test_name);
1352   GNUNET_free(testname);
1353   GNUNET_free (comm_name);
1354   GNUNET_free(mps);
1355   GNUNET_free(sps);
1356
1357   return result;
1358 }
1359
1360 /* end of file perf_ats.c */