logging application layer RTT
[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     /*
939     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%c %03u: %s %s %u\n"),
940      (GNUNET_YES == p->me->master) ? 'M' : 'S',
941      p->me->no,
942      GNUNET_i2s (&address->peer),
943      GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
944      ntohl(ats[c_a].value));
945      */
946   }
947
948   GNUNET_free(peer_id);
949 }
950
951 static void *
952 ats_perf_connect_adapter (void *cls,
953     const struct GNUNET_CONFIGURATION_Handle *cfg)
954 {
955   struct BenchmarkPeer *me = cls;
956
957   me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
958       &ats_performance_info_cb, me);
959   if (NULL == me->ats_perf_handle)
960     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
961         "Failed to create ATS performance handle \n");
962   return me->ats_perf_handle;
963 }
964
965 static void
966 ats_perf_disconnect_adapter (void *cls, void *op_result)
967 {
968   struct BenchmarkPeer *me = cls;
969
970   GNUNET_ATS_performance_done (me->ats_perf_handle);
971   me->ats_perf_handle = NULL;
972 }
973
974 static void
975 ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
976     void *ca_result, const char *emsg)
977 {
978   static int op_done = 0;
979
980   if ((NULL != emsg) || (NULL == ca_result))
981   {
982     GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
983     GNUNET_break(0);
984     if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
985       GNUNET_SCHEDULER_cancel (shutdown_task);
986     shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
987     return;
988   }
989   op_done++;
990   if (op_done == (num_masters + num_slaves))
991   {
992     GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
993     state.connected_ATS_service = GNUNET_YES;
994     GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL );
995   }
996 }
997
998 static void
999 do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1000 {
1001   int c_m;
1002   int c_s;
1003
1004   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
1005   for (c_m = 0; c_m < num_masters; c_m++)
1006   {
1007     mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
1008         "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
1009         &ats_perf_disconnect_adapter, &mps[c_m]);
1010
1011   }
1012
1013   for (c_s = 0; c_s < num_slaves; c_s++)
1014   {
1015     sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
1016         "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
1017         &ats_perf_disconnect_adapter, &sps[c_s]);
1018   }
1019
1020 }
1021
1022 static void
1023 peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
1024     const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
1025 {
1026   struct BenchmarkPeer *p = cb_cls;
1027   static int done = 0;
1028
1029   GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
1030
1031   p->id = *pinfo->result.id;
1032   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
1033       (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
1034       GNUNET_i2s (&p->id));
1035
1036   GNUNET_TESTBED_operation_done (op);
1037   p->peer_id_op = NULL;
1038   done++;
1039
1040   if (done == num_slaves + num_masters)
1041   {
1042     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1043         "Retrieved all peer ID, connect to ATS\n");
1044     GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
1045   }
1046 }
1047
1048 /**
1049  * Signature of a main function for a testcase.
1050  *
1051  * @param cls closure
1052  * @param num_peers number of peers in 'peers'
1053  * @param peers_ handle to peers run in the testbed
1054  * @param links_succeeded the number of overlay link connection attempts that
1055  *          succeeded
1056  * @param links_failed the number of overlay link connection attempts that
1057  *          failed
1058  */
1059 static void
1060 main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
1061     struct GNUNET_TESTBED_Peer **peers_, unsigned int links_succeeded,
1062     unsigned int links_failed)
1063 {
1064   int c_m;
1065   int c_s;
1066   GNUNET_assert(NULL == cls);
1067   GNUNET_assert(num_masters + num_slaves == num_peers);
1068   GNUNET_assert(NULL != peers_);
1069
1070   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1071       _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
1072       solver, pref_str, num_masters, num_slaves);
1073
1074   shutdown_task = GNUNET_SCHEDULER_add_delayed (
1075       GNUNET_TIME_relative_multiply (TEST_TIMEOUT, num_masters + num_slaves),
1076       &do_shutdown, NULL );
1077
1078   /* Setup master peers */
1079   for (c_m = 0; c_m < num_masters; c_m++)
1080   {
1081     GNUNET_assert(NULL != peers_[c_m]);
1082     mps[c_m].peer = peers_[c_m];
1083     mps[c_m].no = c_m;
1084     mps[c_m].master = GNUNET_YES;
1085     mps[c_m].pref_partner = &sps[c_m];
1086     mps[c_m].pref_value = TEST_ATS_PREFRENCE_START;
1087     mps[c_m].partners =
1088         GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1089     mps[c_m].num_partners = num_slaves;
1090     /* Initialize partners */
1091     for (c_s = 0; c_s < num_slaves; c_s++)
1092     {
1093       mps[c_m].partners[c_s].me = &mps[c_m];
1094       mps[c_m].partners[c_s].dest = &sps[c_s];
1095     }
1096     mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (mps[c_m].peer,
1097         GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &mps[c_m]);
1098   }
1099
1100   /* Setup slave peers */
1101   for (c_s = 0; c_s < num_slaves; c_s++)
1102   {
1103     GNUNET_assert(NULL != peers_[c_s + num_masters]);
1104     sps[c_s].peer = peers_[c_s + num_masters];
1105     sps[c_s].no = c_s + num_masters;
1106     sps[c_s].master = GNUNET_NO;
1107     sps[c_s].partners =
1108         GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1109     sps[c_s].num_partners = num_masters;
1110     /* Initialize partners */
1111     for (c_m = 0; c_m < num_masters; c_m++)
1112     {
1113       sps[c_s].partners[c_m].me = &sps[c_s];
1114       sps[c_s].partners[c_m].dest = &mps[c_m];
1115     }
1116     sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (sps[c_s].peer,
1117         GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &sps[c_s]);
1118   }
1119 }
1120
1121 int
1122 main (int argc, char *argv[])
1123 {
1124   char *tmp;
1125   char *tmp_sep;
1126   char *test_name;
1127   char *conf_name;
1128   char *comm_name;
1129   char *dotexe;
1130   char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1131   int c;
1132
1133   result = 0;
1134
1135   /* figure out testname */
1136   tmp = strstr (argv[0], TESTNAME_PREFIX);
1137   if (NULL == tmp)
1138   {
1139     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1140     return GNUNET_SYSERR;
1141   }
1142   tmp += strlen (TESTNAME_PREFIX);
1143   solver = GNUNET_strdup (tmp);
1144   if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
1145     dotexe[0] = '\0';
1146   tmp_sep = strchr (solver, '_');
1147   if (NULL == tmp_sep)
1148   {
1149     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1150     GNUNET_free(solver);
1151     return GNUNET_SYSERR;
1152   }
1153   tmp_sep[0] = '\0';
1154   comm_name = GNUNET_strdup (&tmp_sep[1]);
1155   tmp_sep = strchr (comm_name, '_');
1156   if (NULL == tmp_sep)
1157   {
1158     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1159     GNUNET_free(solver);
1160     return GNUNET_SYSERR;
1161   }
1162   tmp_sep[0] = '\0';
1163   for (c = 0; c <= strlen (comm_name); c++)
1164     comm_name[c] = toupper (comm_name[c]);
1165   if (0 == strcmp (comm_name, "CORE"))
1166     test_core = GNUNET_YES;
1167   else if (0 == strcmp (comm_name, "TRANSPORT"))
1168     test_core = GNUNET_NO;
1169   else
1170   {
1171     GNUNET_free (comm_name);
1172     GNUNET_free (solver);
1173     return GNUNET_SYSERR;
1174   }
1175
1176   pref_str = GNUNET_strdup(tmp_sep + 1);
1177
1178   GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
1179       pref_str);
1180   GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
1181
1182   for (c = 0; c <= strlen (pref_str); c++)
1183     pref_str[c] = toupper (pref_str[c]);
1184   pref_val = -1;
1185
1186   if (0 != strcmp (pref_str, "NONE"))
1187   {
1188     for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
1189     {
1190       if (0 == strcmp (pref_str, prefs[c]))
1191       {
1192         pref_val = c;
1193         break;
1194       }
1195     }
1196   }
1197   else
1198   {
1199     /* abuse terminator to indicate no pref */
1200     pref_val = GNUNET_ATS_PREFERENCE_END;
1201   }
1202   if (-1 == pref_val)
1203   {
1204     fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
1205     GNUNET_free(solver);
1206     GNUNET_free(pref_str);
1207     GNUNET_free (comm_name);
1208     return -1;
1209   }
1210
1211   for (c = 0; c < (argc - 1); c++)
1212   {
1213     if (0 == strcmp (argv[c], "-d"))
1214       break;
1215   }
1216   if (c < argc - 1)
1217   {
1218     if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration))
1219         fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
1220   }
1221   else
1222   {
1223     perf_duration = BENCHMARK_DURATION;
1224   }
1225   fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000));
1226
1227   for (c = 0; c < (argc - 1); c++)
1228   {
1229     if (0 == strcmp (argv[c], "-s"))
1230       break;
1231   }
1232   if (c < argc - 1)
1233   {
1234     if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
1235         && (num_slaves >= 1))
1236       fprintf (stderr, "Starting %u slave peers\n", num_slaves);
1237     else
1238       num_slaves = DEFAULT_SLAVES_NUM;
1239   }
1240   else
1241     num_slaves = DEFAULT_SLAVES_NUM;
1242
1243   for (c = 0; c < (argc - 1); c++)
1244   {
1245     if (0 == strcmp (argv[c], "-m"))
1246       break;
1247   }
1248   if (c < argc - 1)
1249   {
1250     if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
1251         && (num_masters >= 2))
1252       fprintf (stderr, "Starting %u master peers\n", num_masters);
1253     else
1254       num_masters = DEFAULT_MASTERS_NUM;
1255   }
1256   else
1257     num_masters = DEFAULT_MASTERS_NUM;
1258
1259   logging = GNUNET_NO;
1260   for (c = 0; c < argc; c++)
1261   {
1262     if (0 == strcmp (argv[c], "-l"))
1263       logging = GNUNET_YES;
1264   }
1265
1266   if (GNUNET_YES == logging)
1267   {
1268     for (c = 0; c < (argc - 1); c++)
1269     {
1270       if (0 == strcmp (argv[c], "-f"))
1271         break;
1272     }
1273     if (c < argc - 1)
1274     {
1275       if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency))
1276           fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
1277     }
1278     else
1279     {
1280       log_frequency = LOGGING_FREQUENCY;
1281     }
1282     fprintf (stderr, "Using log frequency %llu ms\n",
1283         (unsigned long long) (log_frequency.rel_value_us) / (1000));
1284   }
1285
1286   GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str);
1287
1288   if (num_slaves < num_masters)
1289   {
1290     fprintf (stderr, "Number of master peers is lower than slaves! exit...\n");
1291     GNUNET_free(test_name);
1292     GNUNET_free(solver);
1293     GNUNET_free(pref_str);
1294     GNUNET_free (comm_name);
1295     return GNUNET_SYSERR;
1296   }
1297
1298   state.connected_ATS_service = GNUNET_NO;
1299   state.connected_COMM_service = GNUNET_NO;
1300   state.connected_PEERS = GNUNET_NO;
1301   state.benchmarking = GNUNET_NO;
1302   state.connected_PEERS = GNUNET_NO;
1303
1304   mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1305   sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1306
1307   /* Start topology */
1308   uint64_t event_mask;
1309   event_mask = 0;
1310   event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1311   event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1312   (void) GNUNET_TESTBED_test_run ("perf-ats", conf_name,
1313       num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
1314       &main_run, NULL );
1315
1316   GNUNET_free(solver);
1317   GNUNET_free(pref_str);
1318   GNUNET_free(conf_name);
1319   GNUNET_free(test_name);
1320   GNUNET_free(testname);
1321   GNUNET_free (comm_name);
1322   GNUNET_free(mps);
1323   GNUNET_free(sps);
1324
1325   return result;
1326 }
1327
1328 /* end of file perf_ats.c */