llu prob
[oweals/gnunet.git] / src / transport / test_transport_ats.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 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 testing/test_transport_ats.c
22  * @brief testcase for ats functionality
23  */
24 #include "platform.h"
25 #include "gnunet_testing_lib.h"
26 #include "gnunet_transport_service.h"
27 #include "gnunet_scheduler_lib.h"
28 #include "gauger.h"
29
30 #define VERBOSE GNUNET_NO
31
32 #define NUM_PEERS 11
33 #define MEASUREMENTS 5
34
35 #define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
36 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
37 #define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
38
39 #define ATS_NEW 0
40 #define ATS_Q_UPDATED 1
41 #define ATS_C_UPDATED 2
42 #define ATS_QC_UPDATED 3
43 #define ATS_UNMODIFIED 4
44
45 static int ok;
46
47 static int peers_left;
48
49 static int failed_peers;
50
51 static int measurement_started = GNUNET_NO;
52 static char * config_file;
53
54 static struct GNUNET_TESTING_PeerGroup *pg;
55
56 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
57 static GNUNET_SCHEDULER_TaskIdentifier stats_task;
58 static GNUNET_SCHEDULER_TaskIdentifier send_task;
59 struct GNUNET_TESTING_Daemon * master_deamon;
60 struct GNUNET_TESTING_Daemon * ping_deamon;
61
62 struct GNUNET_STATISTICS_Handle * stats;
63
64 struct TEST_result
65 {
66         uint64_t timestamp;
67         uint64_t duration;
68         uint64_t mechs;
69         uint64_t peers;
70         uint64_t solution;
71         uint64_t state;
72 };
73
74 struct TestMessage
75 {
76   struct GNUNET_MessageHeader header;
77   uint32_t num;
78 };
79
80
81 static int count;
82 static int c_new;
83 static int c_unmodified;
84 static int c_modified;
85 static int connected;
86 static int peers;
87
88 static int force_q_updates;
89 static int force_rebuild;
90 static int send_msg;
91 static int machine_parsable;
92
93 static struct TEST_result results_new       [MEASUREMENTS+1];
94 static struct TEST_result results_modified  [MEASUREMENTS+1];
95 static struct TEST_result results_unmodified[MEASUREMENTS+1];
96 static struct TEST_result current;
97
98 static struct GNUNET_STATISTICS_GetHandle * s_solution;
99 static struct GNUNET_STATISTICS_GetHandle * s_time;
100 static struct GNUNET_STATISTICS_GetHandle * s_peers;
101 static struct GNUNET_STATISTICS_GetHandle * s_mechs;
102 static struct GNUNET_STATISTICS_GetHandle * s_duration;
103 static struct GNUNET_STATISTICS_GetHandle * s_invalid;
104 static struct GNUNET_STATISTICS_GetHandle * s_state;
105
106 struct GNUNET_TRANSPORT_TransmitHandle * t;
107 struct GNUNET_TRANSPORT_Handle * th;
108
109 /**
110  * Check whether peers successfully shut down.
111  */
112 void
113 shutdown_callback (void *cls, const char *emsg)
114 {
115   if (emsg != NULL)
116     {
117 #if VERBOSE
118       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
119 #endif
120       if (ok == 0)
121         ok = 666;
122     }
123   else
124     {
125 #if VERBOSE
126       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127                   "All peers successfully shut down!\n");
128         if (stats != NULL)
129                 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
130         stats = NULL;
131 #endif
132     }
133 }
134
135 static void shutdown_peers()
136 {
137         if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
138         {
139                 GNUNET_SCHEDULER_cancel(shutdown_task);
140                 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
141         }
142         if (stats_task != GNUNET_SCHEDULER_NO_TASK)
143         {
144                 GNUNET_SCHEDULER_cancel(stats_task);
145                 stats_task = GNUNET_SCHEDULER_NO_TASK;
146         }
147         if (send_task != GNUNET_SCHEDULER_NO_TASK)
148         {
149                 GNUNET_SCHEDULER_cancel(send_task);
150                 send_task = GNUNET_SCHEDULER_NO_TASK;
151         }
152
153         if (t!=NULL)
154         {
155                 GNUNET_TRANSPORT_notify_transmit_ready_cancel(t);
156                 t = NULL;
157         }
158
159         GNUNET_TRANSPORT_disconnect(th);
160
161         if (s_time != NULL)
162         {
163                 GNUNET_STATISTICS_get_cancel(s_time);
164                 s_time = NULL;
165         }
166         if (s_peers != NULL)
167         {
168                 GNUNET_STATISTICS_get_cancel(s_peers);
169                 s_peers = NULL;
170         }
171         if (s_mechs != NULL)
172         {
173                 GNUNET_STATISTICS_get_cancel(s_mechs);
174                 s_mechs = NULL;
175         }
176         if (s_solution != NULL)
177         {
178                 GNUNET_STATISTICS_get_cancel(s_solution);
179                 s_solution = NULL;
180         }
181         if (s_duration != NULL)
182         {
183                 GNUNET_STATISTICS_get_cancel(s_duration);
184                 s_duration = NULL;
185         }
186         if (s_invalid != NULL)
187         {
188                 GNUNET_STATISTICS_get_cancel(s_invalid);
189                 s_invalid = NULL;
190         }
191         if (s_state != NULL)
192         {
193                 GNUNET_STATISTICS_get_cancel(s_state);
194                 s_state = NULL;
195         }
196
197     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
198 }
199
200 static void evaluate_measurements()
201 {
202         int c;
203         //int mechs = 0;
204         double average[3];
205         double stddev[3];
206         //char * output;
207         c = 1;
208
209         //GNUNET_asprintf(&output, "p,%i,m,%i,",peers, MEASUREMENTS, results_modified[0].mechs,
210
211         average[0] = 0.0;
212         for (c=0; c<c_new;c++)
213         {
214                 average[0] += (double) results_new[c].duration;
215         }
216         average[0] /= c_new;
217
218         stddev[0] = 0.0;
219         for (c=0; c<c_new;c++)
220         {
221                 stddev[0] += (results_new[c].duration - average[0]) * (results_new[c].duration - average[0]);
222         }
223         stddev[0] /= c_new;
224         stddev[0] = sqrt (stddev[0]);
225         if (!machine_parsable)
226           fprintf (stderr,
227                    "new, %i measurements, average: %f stddev: %f\n",
228                    c_new, average[0], stddev[0]);
229
230         average[1] = 0.0;
231         for (c=0; c<c_modified;c++)
232         {
233                 average[1] += (double) results_modified[c].duration;
234         }
235         average[1] /= c_modified;
236
237         stddev[1] = 0.0;
238         for (c=0; c<c_modified;c++)
239         {
240                 stddev[1] += (results_modified[c].duration - average[1]) * (results_modified[c].duration - average[1]);
241         }
242         stddev[1] /= c_modified;
243         stddev[1] = sqrt (stddev[1]);
244         if (!machine_parsable) 
245           fprintf (stderr,
246                    "modified, %i measurements, average: %f stddev: %f\n",
247                    c_modified, average[1], stddev[1]);
248
249         average[2] = 0.0;
250         for (c=0; c<c_unmodified;c++)
251         {
252                 average[2] += (double) results_unmodified[c].duration;
253         }
254         average[2] /= c_unmodified;
255         stddev[2] = 0.0;
256         for (c=0; c<c_unmodified;c++)
257         {
258                 stddev[2] += (results_unmodified[c].duration - average[2]) * (results_unmodified[c].duration - average[2]);
259         }
260         stddev[2] /= c_unmodified;
261         stddev[2] = sqrt (stddev[2]);
262
263         if (!machine_parsable) 
264           fprintf (stderr,
265                    "unmodified, %i measurements, average: %f stddev: %f\n",
266                    c_unmodified, average[2], stddev[2]);
267         
268         if (machine_parsable)
269           fprintf (stderr,
270                    "peers,%i,mechs,%llu,"
271                    "new,%i,%f,%f,"
272                    "mod,%i,%f,%f,"
273                    "unmod,%i,%f,%f\n",
274                    peers-1, (unsigned long long) results_unmodified[0].mechs,
275                    c_new, average[0], stddev[0],
276                    c_modified, average[1], stddev[1],
277                    c_unmodified, average[2], stddev[2]);
278         shutdown_peers();
279 }
280
281 int stats_cb (void *cls,
282                            const char *subsystem,
283                            const char *name,
284                            uint64_t value,
285                            int is_persistent)
286 {
287         static int printed = GNUNET_NO;
288         //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s = %llu\n", name ,value);
289         if (0 == strcmp (name,"ATS invalid solutions"))
290         {
291                 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
292                 {
293                         GNUNET_SCHEDULER_cancel(stats_task);
294                         stats_task = GNUNET_SCHEDULER_NO_TASK;
295                 }
296                 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"MLP produced invalid %llu result(s)!\n", value);
297                 shutdown_peers();
298                 return GNUNET_SYSERR;
299         }
300
301         if (0 == strcmp (name,"ATS solution"))
302         {
303                 s_solution = NULL;
304         }
305
306         if (0 == strcmp (name,"ATS peers"))
307         {
308                 s_peers = NULL;
309         }
310
311         if (0 == strcmp (name,"ATS mechanisms"))
312         {
313                 s_mechs = NULL;
314         }
315
316         if (0 == strcmp (name,"ATS duration"))
317         {
318                 s_duration = NULL;
319         }
320         if (0 == strcmp (name,"ATS timestamp"))
321         {
322                 s_time = NULL;
323         }
324         if (0 == strcmp (name,"ATS state"))
325         {
326                 s_state = NULL;
327         }
328
329     if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) && (value == peers-1))
330     {
331                 measurement_started = GNUNET_YES;
332                 count = 1;
333                 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %llu peers connected\n", value);
334 #if !VERBOSE
335                 if (!machine_parsable)  fprintf(stderr, "%i", count);
336 #endif
337     }
338
339     if (measurement_started == GNUNET_YES)
340     {
341                 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
342                 if (0 == strcmp (name,"ATS timestamp"))
343                 {
344                         if (current.timestamp == 0)
345                         {
346                                 printed = GNUNET_NO;
347                                 current.timestamp = value;
348                         }
349                         if (current.timestamp == value)
350                         {
351                                 printed = GNUNET_YES;
352                         }
353                         if (current.timestamp != value)
354                         {
355                                 if (current.state == ATS_NEW)
356                                 {
357                                         if (c_new < MEASUREMENTS)
358                                         {
359                                                 results_new[c_new] = current;
360                                                 c_new++;
361                                         }
362                                         else
363                                         {
364                                           force_rebuild = GNUNET_NO;
365                                           force_q_updates = GNUNET_NO;
366                                           send_msg = GNUNET_NO;
367                                         }
368                                 }
369                                 if (current.state == ATS_UNMODIFIED)
370                                 {
371                                         if (c_unmodified < MEASUREMENTS)
372                                         {
373                                                 results_unmodified[c_unmodified] = current;
374                                                 c_unmodified++;
375                                         }
376
377                                 }
378                                 if (current.state == ATS_Q_UPDATED)
379                                 {
380                                         if (c_modified < MEASUREMENTS)
381                                         {
382                                                 results_modified[c_modified] = current;
383                                                 c_modified++;
384                                         }
385                                         else
386                                         {
387                                                 force_q_updates = GNUNET_NO;
388                                                 force_rebuild = GNUNET_YES;
389                                         }
390                                 }
391                                 count ++;
392 #if VERBOSE
393                                 fprintf (stderr,
394                                          "(new: %i / modified: %i / unmodified: %i) of %i \n", 
395                                          c_new, c_modified, c_unmodified , MEASUREMENTS);
396 #endif
397                                 if ((c_modified >= MEASUREMENTS) && (c_new >= MEASUREMENTS) && (c_unmodified >= MEASUREMENTS))
398                                 {
399 #if !VERBOSE
400                                         if (!machine_parsable) fprintf(stdout, "\n");
401 #endif
402                                         if (stats_task != GNUNET_SCHEDULER_NO_TASK)
403                                         {
404                                                 GNUNET_SCHEDULER_cancel(stats_task);
405                                                 stats_task = GNUNET_SCHEDULER_NO_TASK;
406                                         }
407                                         evaluate_measurements();
408                                         return GNUNET_SYSERR;
409                                 }
410
411                                 printed = GNUNET_NO;
412                                 current.timestamp = value;
413 #if !VERBOSE
414                                 if (!machine_parsable) fprintf(stderr, "..%i", count);
415 #endif
416                                 return GNUNET_OK;
417                         }
418                 }
419
420                 if (0 == strcmp (name,"ATS solution"))
421                 {
422                         current.solution = value;
423                         if (printed == GNUNET_NO)
424                           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
425                 }
426
427                 if (0 == strcmp (name,"ATS peers"))
428                 {
429                         current.peers = value;
430                         if (printed == GNUNET_NO)
431                           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
432                 }
433
434                 if (0 == strcmp (name,"ATS mechanisms"))
435                 {
436                         current.mechs = value;
437                         if (printed == GNUNET_NO) 
438                           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
439                 }
440
441                 if (0 == strcmp (name,"ATS duration"))
442                 {
443                         current.duration = value;
444                         if (printed == GNUNET_NO) 
445                           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
446                 }
447                 if (0 == strcmp (name,"ATS state"))
448                 {
449                         current.state = value;
450                         char * cont;
451                         if (value == ATS_NEW)
452                                 cont = "NEW";
453                         if (value == ATS_C_UPDATED)
454                                 cont = "C_UPDATED";
455                         if (value == ATS_Q_UPDATED)
456                                 cont = "Q_UPDATED";
457                         if (value == ATS_QC_UPDATED)
458                                 cont = "QC_UPDATED";
459                         if (value == ATS_UNMODIFIED)
460                                 cont = "UNMODIFIED";
461                         if (printed == GNUNET_NO) 
462                           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS state: %s\n", count, cont);
463                 }
464     }
465     return GNUNET_OK;
466 }
467
468
469 void
470 stats_get_task (void *cls,
471                           const struct GNUNET_SCHEDULER_TaskContext *tc)
472 {
473         stats_task = GNUNET_SCHEDULER_NO_TASK;
474         if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
475             return;
476
477         s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL, &stats_cb, NULL);
478         s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL, &stats_cb, NULL);
479         s_duration = GNUNET_STATISTICS_get (stats, "transport","ATS duration", TIMEOUT, NULL, &stats_cb, NULL);
480         s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL, &stats_cb, NULL);
481         s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT, NULL, &stats_cb, NULL);
482         s_invalid = GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions", TIMEOUT, NULL, &stats_cb, NULL);
483         s_state = GNUNET_STATISTICS_get (stats, "transport", "ATS state", TIMEOUT, NULL, &stats_cb, NULL);
484
485         stats_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100), &stats_get_task, NULL);
486 }
487
488 void
489 delay (void *cls,
490                           const struct GNUNET_SCHEDULER_TaskContext *tc)
491 {
492         shutdown_task = GNUNET_SCHEDULER_NO_TASK;
493         if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
494             return;
495
496 #if VERBOSE
497         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
498 #endif
499         shutdown_peers ();
500 }
501
502 static void connect_peers()
503 {
504     shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
505
506 }
507
508 size_t send_dummy_data_task (void *cls, size_t size, void *buf)
509 {
510
511         int s = sizeof (struct TestMessage);
512         struct TestMessage hdr;
513
514         hdr.header.size = htons (s);
515         hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ATS);
516         if (force_rebuild)
517                 hdr.num = htonl (1);
518         if (force_q_updates)
519                 hdr.num = htonl (2);
520
521
522         memcpy (buf,&hdr, s);
523         // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i of %i\n", s, s);
524         t  = NULL;
525         return s;
526 }
527
528 void send_task_f (void *cls,
529                           const struct GNUNET_SCHEDULER_TaskContext *tc)
530 {
531         send_task = GNUNET_SCHEDULER_NO_TASK;
532         if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
533             return;
534
535         if (t!=NULL)
536         {
537                 GNUNET_TRANSPORT_notify_transmit_ready_cancel(t);
538                 t = NULL;
539         }
540         // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i to %s\n", size, GNUNET_i2s(&master_deamon->id));
541         if (send_msg == GNUNET_YES)
542                 t = GNUNET_TRANSPORT_notify_transmit_ready(th, &master_deamon->id, sizeof (struct TestMessage), 0, SEND_TIMEOUT, &send_dummy_data_task, NULL);
543         send_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,1000), &send_task_f, NULL);
544 }
545
546
547
548 void daemon_connect_cb(void *cls,
549                                                 const struct GNUNET_PeerIdentity *first,
550                                                 const struct GNUNET_PeerIdentity *second,
551                                                 uint32_t distance,
552                                                 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
553                                                 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
554                                                 struct GNUNET_TESTING_Daemon *first_daemon,
555                                                 struct GNUNET_TESTING_Daemon *second_daemon,
556                                                 const char *emsg)
557 {
558         char * firstc =  strdup(GNUNET_i2s(first));
559         char * secondc =  strdup(GNUNET_i2s(second));
560         connected++;
561         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
562                     "Connected peers `%s'<->`%s' (%i/%i)\n", firstc, secondc, connected, peers-1);
563         GNUNET_free(firstc);
564         GNUNET_free(secondc);
565
566         if (((first_daemon == ping_deamon) || (second_daemon == ping_deamon)) && (master_deamon != NULL) && (ping_deamon != NULL))
567         {
568                   th = GNUNET_TRANSPORT_connect (ping_deamon->cfg,&ping_deamon->id, NULL, NULL,NULL, NULL);
569                   t = NULL;
570                   force_q_updates = GNUNET_YES;
571                   send_msg = GNUNET_YES;
572                   send_task = GNUNET_SCHEDULER_add_now(&send_task_f, NULL);
573         }
574 }
575
576 void cont_cb (void *cls, int success)
577 {
578     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
579                 "STATS cont_cb: %i\n", success);
580 }
581
582 static void
583 daemon_start_cb (void *cls,
584        const struct GNUNET_PeerIdentity *id,
585        const struct GNUNET_CONFIGURATION_Handle *cfg,
586        struct GNUNET_TESTING_Daemon *d, const char *emsg)
587 {
588   if (id == NULL)
589     {
590       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
591                   "Start callback called with error (too long starting peers), aborting test!\n");
592       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
593       failed_peers++;
594       if (failed_peers == peers_left)
595         {
596           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
597                       "Too many peers failed, ending test!\n");
598           ok = 1;
599         shutdown_peers ();
600         }
601       return;
602     }
603   peers_left--;
604
605   if (master_deamon == NULL)
606   {
607           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
608
609           master_deamon = d;
610           stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
611           GNUNET_assert (stats != NULL);
612           stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
613   }
614   else
615   {
616           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
617           GNUNET_TESTING_daemons_connect(d, master_deamon, TIMEOUT, 0, GNUNET_YES,&daemon_connect_cb, NULL);
618   }
619
620   if (peers_left == 0)
621     {
622           if (ping_deamon == NULL)
623           {
624                   ping_deamon = d;
625                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ping peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
626           }
627
628           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
629                   "All peers started successfully!\n");
630       connect_peers();
631       ok = 0;
632     }
633   else if (failed_peers == peers_left)
634     {
635       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636                   "Too many peers failed, ending test!\n");
637       shutdown_peers();
638       ok = 1;
639     }
640 }
641
642
643 static void
644 run (void *cls,
645      char *const *args,
646      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
647 {
648   ok = 1;
649   measurement_started = GNUNET_NO;
650 #if VERBOSE
651   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", peers);
652 #endif
653   peers_left = peers;
654   pg = GNUNET_TESTING_daemons_start (cfg,
655                                      peers_left, /* Total number of peers */
656                                      peers_left, /* Number of outstanding connections */
657                                      peers_left, /* Number of parallel ssh connections, or peers being started at once */
658                                      TIMEOUT,
659                                      NULL, NULL,
660                                      &daemon_start_cb, NULL, NULL, NULL, NULL);
661   GNUNET_assert (pg != NULL);
662 }
663
664 static int
665 check ()
666 {
667   char *const argv[] = { "test-testing",
668     "-c",
669     config_file,
670 #if VERBOSE
671     "-L", "DEBUG",
672 #endif
673     NULL
674   };
675   struct GNUNET_GETOPT_CommandLineOption options[] = {
676     GNUNET_GETOPT_OPTION_END
677   };
678   GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
679                       argv, "test-transport-ats", "nohelp",
680                       options, &run, &ok);
681   return ok;
682 }
683
684 int
685 main (int argc, char *argv[])
686 {
687
688   int ret;
689
690   GNUNET_log_setup ("test-transport-ats",
691 #if VERBOSE
692                     "DEBUG",
693 #else
694                     "INFO",
695 #endif
696                     NULL);
697
698 #if !HAVE_LIBGLPK
699         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed, exiting testcase\n");
700         return 0;
701 #endif
702
703   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
704
705
706   machine_parsable = GNUNET_NO;
707   peers = NUM_PEERS;
708   config_file = "test_transport_ats_4addr.conf";
709
710   int c = 0;
711   if (argc >= 2)
712   {
713          for (c=0; c<argc; c++)
714          {
715                  /* set peers */
716                  if ((strcmp(argv[c], "-p") == 0) && c < (argc-1))
717                  {
718                           peers = atoi(argv[c+1]);
719                           peers++;
720                  }
721                  /* set machine parsable */
722                  if (strcmp(argv[c], "-m") == 0)
723                  {
724                          machine_parsable = GNUNET_YES;
725                  }
726                  /* set config file */
727                  if ((strcmp(argv[c], "-c") == 0) && c < (argc-1))
728                  {
729                          config_file = argv[c+1];
730                  }
731          }
732   }
733
734
735
736   ret = check ();
737   /**
738    * Still need to remove the base testing directory here,
739    * because group starts will create subdirectories under this
740    * main dir.  However, we no longer need to sleep, as the
741    * shutdown sequence won't return until everything is cleaned
742    * up.
743    */
744   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
745   return ret;
746 }
747
748 /* end of test_transport_ats.c*/