2d38b84326b36ce031815047936d4fcf48551c7e
[oweals/gnunet.git] / test_testbed_api_3peers_3controllers.c
1 /*
2       This file is part of GNUnet
3       (C) 2008--2012 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 /**
22  * @file testbed/test_testbed_api_3peers_3controllers.c
23  * @brief testcases for the testbed api: 3 peers are configured, started and
24  *          connected together. Each peer resides on its own controller.
25  * @author Sree Harsha Totakura
26  */
27
28
29 /**
30  * The testing architecture is:
31  *                  A
32  *                 / \
33  *                /   \
34  *               B === C 
35  * A is the master controller and B, C are slave controllers. B links to C
36  * laterally.
37  * Peers are mapped to controllers in the following relations:
38  *             Peer         Controller
39  *               1              A
40  *               2              B
41  *               3              C
42  *
43  */
44
45 #include "platform.h"
46 #include "gnunet_util_lib.h"
47 #include "gnunet_testing_lib-new.h"
48 #include "gnunet_testbed_service.h"
49
50
51 /**
52  * Generic logging shortcut
53  */
54 #define LOG(kind,...)                           \
55   GNUNET_log (kind, __VA_ARGS__)
56
57 /**
58  * Relative time seconds shorthand
59  */
60 #define TIME_REL_SECS(sec) \
61   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
62
63
64 /**
65  * Peer context
66  */
67 struct PeerContext
68 {
69   /**
70    * The peer handle
71    */
72   struct GNUNET_TESTBED_Peer *peer;
73
74   /**
75    * Operations involving this peer
76    */
77   struct GNUNET_TESTBED_Operation *operation;
78
79   /**
80    * set to GNUNET_YES when peer is started
81    */
82   int is_running;
83 };
84
85 /**
86  * Our localhost
87  */
88 static struct GNUNET_TESTBED_Host *host;
89
90 /**
91  * The controller process of one controller
92  */
93 static struct GNUNET_TESTBED_ControllerProc *cp1;
94
95 /**
96  * A neighbouring host
97  */
98 static struct GNUNET_TESTBED_Host *neighbour1;
99
100 /**
101  * Another neighbouring host
102  */
103 static struct GNUNET_TESTBED_Host *neighbour2;
104
105 /**
106  * Handle for neighbour registration
107  */
108 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
109
110 /**
111  * The controller handle of one controller
112  */
113 static struct GNUNET_TESTBED_Controller *controller1;
114
115 /**
116  * peer 1
117  */
118 static struct PeerContext peer1;
119
120 /**
121  * peer2
122  */
123 static struct PeerContext peer2;
124
125 /**
126  * peer3
127  */
128 static struct PeerContext peer3;
129
130 /**
131  * Handle to starting configuration
132  */
133 static struct GNUNET_CONFIGURATION_Handle *cfg;
134
135 /**
136  * Handle to slave controller C's configuration, used to establish lateral link from
137  * master controller
138  */
139 static struct GNUNET_CONFIGURATION_Handle *cfg2;
140
141 /**
142  * Handle to operations involving both peers
143  */
144 static struct GNUNET_TESTBED_Operation *common_operation;
145
146 /**
147  * Abort task identifier
148  */
149 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
150
151 /**
152  * Delayed connect job identifier
153  */
154 static GNUNET_SCHEDULER_TaskIdentifier delayed_connect_task;
155
156 /**
157  * Different stages in testing
158  */
159 enum Stage
160 {
161
162   /**
163    * Initial stage
164    */
165   INIT,
166
167   /**
168    * Controller 1 has started
169    */
170   CONTROLLER1_UP,
171
172   /**
173    * peer1 is created
174    */
175   PEER1_CREATED,
176
177   /**
178    * peer1 is started
179    */
180   PEER1_STARTED,
181
182   /**
183    * Controller 2 has started
184    */
185   CONTROLLER2_UP,
186
187   /**
188    * peer2 is created
189    */
190   PEER2_CREATED,
191
192   /**
193    * peer2 is started
194    */
195   PEER2_STARTED,
196
197   /**
198    * Controller 3 has started
199    */
200   CONTROLLER3_UP,
201
202   /**
203    * Peer3 is created
204    */
205   PEER3_CREATED,
206
207   /**
208    * Peer3 started
209    */
210   PEER3_STARTED,
211
212   /**
213    * peer1 and peer2 are connected
214    */
215   PEERS_1_2_CONNECTED,
216
217   /**
218    * peer2 and peer3 are connected
219    */
220   PEERS_2_3_CONNECTED,
221
222   /**
223    * Peers are connected once again (this should not fail as they are already connected)
224    */
225   PEERS_CONNECTED_2,
226
227   /**
228    * peers are stopped
229    */
230   PEERS_STOPPED,
231
232   /**
233    * Final success stage
234    */
235   SUCCESS
236 };
237
238 /**
239  * The testing result
240  */
241 static enum Stage result;
242
243 /**
244  * Shutdown nicely
245  *
246  * @param cls NULL
247  * @param tc the task context
248  */
249 static void
250 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 {
252   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
253     GNUNET_SCHEDULER_cancel (abort_task);
254   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task);
255   if (NULL != reg_handle)
256     GNUNET_TESTBED_cancel_registration (reg_handle);
257   if (NULL != controller1)
258     GNUNET_TESTBED_controller_disconnect (controller1);
259   GNUNET_CONFIGURATION_destroy (cfg);
260   if (NULL != cfg2)
261     GNUNET_CONFIGURATION_destroy (cfg2);
262   if (NULL != cp1)
263     GNUNET_TESTBED_controller_stop (cp1);
264   if (NULL != host)
265     GNUNET_TESTBED_host_destroy (host);
266   if (NULL != neighbour1)
267     GNUNET_TESTBED_host_destroy (neighbour1);
268   if (NULL != neighbour2)
269     GNUNET_TESTBED_host_destroy (neighbour2);
270 }
271
272
273 /**
274  * abort task to run on test timed out
275  *
276  * @param cls NULL
277  * @param tc the task context
278  */
279 static void
280 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
281 {
282   LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
283   abort_task = GNUNET_SCHEDULER_NO_TASK;
284   if (GNUNET_SCHEDULER_NO_TASK != delayed_connect_task)
285   {
286     GNUNET_SCHEDULER_cancel (delayed_connect_task);
287     delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
288   }
289   do_shutdown (cls, tc);
290 }
291
292 static void
293 abort_test ()
294 {
295   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
296     GNUNET_SCHEDULER_cancel (abort_task);
297   abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
298 }
299
300
301 /**
302  * Callback to be called when an operation is completed
303  *
304  * @param cls the callback closure from functions generating an operation
305  * @param op the operation that has been finished
306  * @param emsg error message in case the operation has failed; will be NULL if
307  *          operation has executed successfully.
308  */
309 static void 
310 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
311
312
313 /**
314  * task for delaying a connect
315  *
316  * @param cls NULL
317  * @param tc the task context
318  */
319 static void
320 do_delayed_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
321 {
322   delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
323   if (NULL != common_operation)
324   {
325     GNUNET_break (0);
326     abort_test();
327     return;
328   }
329   common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, 
330                                                      peer1.peer, peer2.peer);
331 }
332
333
334 /**
335  * Callback to be called when an operation is completed
336  *
337  * @param cls the callback closure from functions generating an operation
338  * @param op the operation that has been finished
339  * @param emsg error message in case the operation has failed; will be NULL if
340  *          operation has executed successfully.
341  */
342 static void 
343 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
344 {
345   if (common_operation != op)
346   {
347     GNUNET_break (0);
348     abort_test();
349     return;
350   }
351   switch(result)
352   {
353   case PEER3_STARTED:
354     if ((NULL != peer1.operation) ||
355         (NULL != peer2.operation) ||
356         (NULL == common_operation))
357     {
358       GNUNET_break (0);
359       abort_test();
360       return;
361     }
362     GNUNET_TESTBED_operation_done (common_operation);
363     common_operation = NULL;
364     result = PEERS_1_2_CONNECTED;
365     LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
366     common_operation = 
367         GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
368                                           peer3.peer);
369     break;
370   case PEERS_1_2_CONNECTED:
371     if (NULL == common_operation)
372     {
373       GNUNET_break (0);
374       abort_test();
375       return;
376     }
377     GNUNET_TESTBED_operation_done (common_operation);
378     common_operation = NULL;
379     result = PEERS_2_3_CONNECTED;
380     delayed_connect_task =
381           GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3),
382                                         &do_delayed_connect, NULL);
383     break;
384   case PEERS_2_3_CONNECTED:
385     if ((NULL != peer1.operation) ||
386         (NULL != peer2.operation) ||
387         (NULL == common_operation))
388     {
389       GNUNET_break (0);
390       abort_test();
391       return;
392     }
393     GNUNET_TESTBED_operation_done (common_operation);
394     common_operation = NULL;
395     result = PEERS_CONNECTED_2;
396     LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
397     peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer, NULL, NULL);
398     peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer, NULL, NULL);
399     peer3.operation = GNUNET_TESTBED_peer_stop (peer3.peer, NULL, NULL);
400     break;
401   default:
402     GNUNET_break (0);
403     abort_test();
404     return;
405   }
406 }
407
408
409 /**
410  * Functions of this signature are called when a peer has been successfully
411  * created
412  *
413  * @param cls NULL
414  * @param peer the handle for the created peer; NULL on any error during
415  *          creation
416  * @param emsg NULL if peer is not NULL; else MAY contain the error description
417  */
418 static void
419 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
420 {
421   switch (result)
422   {
423   case CONTROLLER1_UP:
424     if ((NULL == peer1.operation) ||
425         (NULL == peer) ||
426         (NULL != peer1.peer))
427     {
428       GNUNET_break (0);
429       abort_test();
430       return;
431     }
432     peer1.peer = peer;
433     GNUNET_TESTBED_operation_done (peer1.operation);
434     result = PEER1_CREATED;
435     peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
436     break;
437   case CONTROLLER2_UP:
438     if ((NULL == peer2.operation) ||
439         (NULL == peer) ||
440         (NULL != peer2.peer))
441     {
442       GNUNET_break (0);
443       abort_test();
444       return;
445     }
446     peer2.peer = peer;
447     GNUNET_TESTBED_operation_done (peer2.operation);
448     result = PEER2_CREATED;
449     peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
450     break;
451   case CONTROLLER3_UP:
452     if ((NULL == peer3.operation) ||
453         (NULL == peer) ||
454         (NULL != peer3.peer))
455     {
456       GNUNET_break (0);
457       abort_test();
458       return;
459     }
460     peer3.peer = peer;
461     GNUNET_TESTBED_operation_done (peer3.operation);
462     result = PEER3_CREATED;
463     peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
464     break;
465   default:
466     GNUNET_break (0);
467     abort_test();
468     return;
469   }  
470 }
471
472
473 /**
474  * Callback to signal successfull startup of the controller process
475  *
476  * @param cls the closure from GNUNET_TESTBED_controller_start()
477  * @param cfg the configuration with which the controller has been started;
478  *          NULL if status is not GNUNET_OK
479  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
480  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
481  */
482 static void
483 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status);
484
485
486 /**
487  * Signature of the event handler function called by the
488  * respective event controller.
489  *
490  * @param cls closure
491  * @param event information about the event
492  */
493 static void
494 controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
495 {
496   switch (event->type)
497   {
498   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
499     if ((NULL != event->details.operation_finished.op_cls)
500         || (NULL != event->details.operation_finished.emsg))
501     {
502       GNUNET_break (0);
503       abort_test();
504       return;
505     }
506     switch (result)
507     {      
508     case PEERS_STOPPED:
509       if (NULL != event->details.operation_finished.generic)
510       {
511         GNUNET_break (0);
512         abort_test();
513         return;
514       }
515       if (event->details.operation_finished.operation == peer1.operation)
516       {
517         GNUNET_TESTBED_operation_done (peer1.operation);
518         peer1.operation = NULL;
519         peer1.peer = NULL;
520       }
521       else if (event->details.operation_finished.operation == peer2.operation)
522       {
523         GNUNET_TESTBED_operation_done (peer2.operation);
524         peer2.operation = NULL;
525         peer2.peer = NULL;
526       }
527       else if (event->details.operation_finished.operation == peer3.operation)
528       {
529         GNUNET_TESTBED_operation_done (peer3.operation);
530         peer3.operation = NULL;
531         peer3.peer = NULL;
532       }
533       else
534       {
535         GNUNET_break (0);
536         abort_test();
537         return;
538       }
539       if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
540       {
541         result = SUCCESS;
542         GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
543       }
544       break;
545     case PEER1_STARTED:
546       if ((NULL != event->details.operation_finished.generic) ||
547           (NULL == common_operation))
548       {
549         GNUNET_break (0);
550         abort_test();
551         return;
552       }
553       GNUNET_TESTBED_operation_done (common_operation);
554       common_operation = NULL;
555       result = CONTROLLER2_UP;
556       peer2.operation =
557           GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg,
558                                       &peer_create_cb, NULL);
559       if (NULL == peer2.operation)
560       {
561         GNUNET_break (0);
562         abort_test();
563         return;
564       }
565       break;
566     case PEER2_STARTED:
567       if ((NULL != event->details.operation_finished.generic) ||
568           (NULL == common_operation))
569       {
570         GNUNET_break (0);
571         abort_test();
572         return;
573       }
574       GNUNET_TESTBED_operation_done (common_operation);
575       common_operation = NULL;
576       result = CONTROLLER3_UP;
577       peer3.operation =
578           GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg,
579                                       &peer_create_cb, NULL);
580       if (NULL == peer3.operation)
581       {
582         GNUNET_break (0);
583         abort_test();
584         return;
585       }
586       break;
587     default:
588       GNUNET_break (0);
589       abort_test();
590       return;
591     }
592     break;
593   case GNUNET_TESTBED_ET_PEER_START:    
594     switch (result)
595     {
596     case PEER1_CREATED:
597       if (event->details.peer_start.host != host)
598       {
599         GNUNET_break (0);
600         abort_test();
601         return;
602       }
603       peer1.is_running = GNUNET_YES;
604       GNUNET_TESTBED_operation_done (peer1.operation);
605       peer1.operation = NULL;
606       result = PEER1_STARTED;
607       common_operation =
608           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, cfg,
609                                           GNUNET_YES); 
610       break;
611     case PEER2_CREATED:
612       if (event->details.peer_start.host != neighbour1)
613       {
614         GNUNET_break (0);
615         abort_test();
616         return;
617       }
618       peer2.is_running = GNUNET_YES;
619       GNUNET_TESTBED_operation_done (peer2.operation);
620       peer2.operation = NULL;
621       result = PEER2_STARTED;
622       if (NULL != common_operation)
623       {
624         GNUNET_break (0);
625         abort_test();
626         return;
627       }
628       common_operation =
629           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, cfg,
630                                           GNUNET_YES);
631       if (NULL == common_operation)
632       {
633         GNUNET_break (0);
634         abort_test();
635         return;
636       }
637       break;
638     case PEER3_CREATED:
639       if (event->details.peer_start.host != neighbour2)
640       {
641         GNUNET_break (0);
642         abort_test();
643         return;
644       }
645       peer3.is_running = GNUNET_YES;
646       GNUNET_TESTBED_operation_done (peer3.operation);
647       peer3.operation = NULL;
648       result = PEER3_STARTED;
649       common_operation =
650           GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
651                                           peer1.peer);
652       break;
653     default:
654       GNUNET_break (0);
655       abort_test();
656       return;
657     }    
658     break;
659   case GNUNET_TESTBED_ET_PEER_STOP:
660     if (PEERS_CONNECTED_2 != result)
661     {
662       GNUNET_break (0);
663       abort_test();
664       return;
665     }
666     if (event->details.peer_stop.peer == peer1.peer)
667     {
668       peer1.is_running = GNUNET_NO;
669       GNUNET_TESTBED_operation_done (peer1.operation);
670     }
671     else if (event->details.peer_stop.peer == peer2.peer)
672     {
673       peer2.is_running = GNUNET_NO;
674       GNUNET_TESTBED_operation_done (peer2.operation);
675     }
676     else if (event->details.peer_stop.peer == peer3.peer)
677     {
678       peer3.is_running = GNUNET_NO;
679       GNUNET_TESTBED_operation_done (peer3.operation);
680     }
681     else
682     {
683       GNUNET_break (0);
684       abort_test();
685       return;
686     }
687     if ((GNUNET_NO == peer1.is_running) &&
688         (GNUNET_NO == peer2.is_running) &&
689         (GNUNET_NO == peer3.is_running))
690     {
691       result = PEERS_STOPPED;
692       peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
693       peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
694       peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer);
695     }
696     break;
697   case GNUNET_TESTBED_ET_CONNECT:
698     if ((NULL != peer1.operation) ||
699         (NULL != peer2.operation) ||
700         (NULL != peer3.operation))
701     {
702       GNUNET_break (0);
703       abort_test();
704       return;
705     }
706     switch (result)
707     {
708     case PEER3_STARTED:
709       if ((NULL == common_operation) ||
710           (event->details.peer_connect.peer1 != peer2.peer) ||
711           (event->details.peer_connect.peer2 != peer1.peer))
712       {
713         GNUNET_break (0);
714         abort_test();
715         return;
716       }
717       break;
718     case PEERS_2_3_CONNECTED:
719       if ((NULL == common_operation) ||
720           (event->details.peer_connect.peer1 != peer1.peer) ||
721           (event->details.peer_connect.peer2 != peer2.peer))
722       {
723         GNUNET_break (0);
724         abort_test();
725         return;
726       }
727       break;
728     case PEERS_1_2_CONNECTED: 
729       if ((NULL == common_operation) ||
730           (event->details.peer_connect.peer1 != peer2.peer) ||
731           (event->details.peer_connect.peer2 != peer3.peer))
732       {
733         GNUNET_break (0);
734         abort_test();
735         return;
736       }
737       break;
738     default:
739       GNUNET_break (0);
740       abort_test();
741       return;
742     }
743     break;
744   default:
745     GNUNET_break (0);
746     abort_test();
747     return;
748   }
749 }
750
751
752 /**
753  * Callback which will be called to after a host registration succeeded or failed
754  *
755  * @param cls the host which has been registered
756  * @param emsg the error message; NULL if host registration is successful
757  */
758 static void
759 registration_comp (void *cls, const char *emsg)
760 {
761   reg_handle = NULL;
762   if (cls == neighbour1)
763   {
764     neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
765     if (NULL == neighbour2)
766     {
767       GNUNET_break (0);
768       abort_test();
769       return;
770     }
771     reg_handle =
772         GNUNET_TESTBED_register_host (controller1, neighbour2, &registration_comp,
773                                       neighbour2);
774     if (NULL == reg_handle)
775     {
776       GNUNET_break (0);
777       abort_test();
778       return;
779     }
780     return;
781   }
782   if (cls != neighbour2)
783   {
784     GNUNET_break (0);
785     abort_test();
786     return;
787   }
788   peer1.operation =
789       GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb,
790                                   &peer1);
791   if (NULL == peer1.operation)
792   {
793     GNUNET_break (0);
794     abort_test();
795     return;
796   }
797 }
798
799
800 /**
801  * Callback to signal successfull startup of the controller process
802  *
803  * @param cls the closure from GNUNET_TESTBED_controller_start()
804  * @param cfg the configuration with which the controller has been started;
805  *          NULL if status is not GNUNET_OK
806  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
807  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
808  */
809 static void
810 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
811 {
812   uint64_t event_mask;
813   
814   if (GNUNET_OK != status)
815   {
816     GNUNET_break (0);
817     abort_test();
818     return;
819   }
820   event_mask = 0;
821   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
822   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
823   event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
824   event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
825   switch (result)
826   {
827   case INIT:
828     controller1 =
829         GNUNET_TESTBED_controller_connect (config, host, event_mask, &controller_cb,
830                                            NULL);
831     if (NULL == controller1)
832     {
833       GNUNET_break (0);
834       abort_test();
835       return;
836     }
837     result = CONTROLLER1_UP;
838     neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
839     if (NULL == neighbour1)
840     {
841       GNUNET_break (0);
842       abort_test();
843       return;
844     }
845     reg_handle =
846         GNUNET_TESTBED_register_host (controller1, neighbour1, &registration_comp,
847                                       neighbour1);
848     if (NULL == reg_handle)
849     {
850       GNUNET_break (0);
851       abort_test();
852       return;
853     }
854     break;
855   default:
856     GNUNET_break (0);
857     abort_test();
858     return;
859   }  
860 }
861
862
863 /**
864  * Main run function.
865  *
866  * @param cls NULL
867  * @param args arguments passed to GNUNET_PROGRAM_run
868  * @param cfgfile the path to configuration file
869  * @param cfg the configuration file handle
870  */
871 static void
872 run (void *cls, char *const *args, const char *cfgfile,
873      const struct GNUNET_CONFIGURATION_Handle *config)
874 {
875   host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
876   if (NULL == host)
877   {
878     GNUNET_break (0);
879     abort_test();
880     return;
881   }
882   if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (host, config))
883   {
884     GNUNET_TESTBED_host_destroy (host);
885     host = NULL;
886     (void) PRINTF ("%s",
887                    "Unable to run the test as this system is not configured "
888                    "to use password less SSH logins to localhost.\n"
889                    "Marking test as successful\n");
890     result = SUCCESS;
891     return;
892   }
893   cfg = GNUNET_CONFIGURATION_dup (config);
894   cp1 = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
895                                          NULL);
896   abort_task =
897       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
898                                     (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
899                                     NULL);
900 }
901
902
903 /**
904  * Main function
905  */
906 int
907 main (int argc, char **argv)
908 {
909   char *const argv2[] = { "test_testbed_api_3peers_3controllers",
910                           "-c", "test_testbed_api.conf",
911                           NULL
912   };
913   struct GNUNET_GETOPT_CommandLineOption options[] = {
914     GNUNET_GETOPT_OPTION_END
915   };
916   int ret;
917
918   result = INIT;
919   ret =
920       GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
921                           "test_testbed_api_3peers_3controllers", "nohelp",
922                           options, &run, NULL);
923   if ((GNUNET_OK != ret) || (SUCCESS != result))
924     return 1;
925   return 0;
926 }
927
928 /* end of test_testbed_api_3peers_3controllers.c */