multiple operation queues for an operation
[oweals/gnunet.git] / src / testbed / test_testbed_api_3peers_3controllers.c
index 8042c436962d14afbcab72596bea34c8a527a262..691e04727329b9d9eaa557dd5c3036893b0b98fe 100644 (file)
 
 /**
  * The testing architecture is:
- *                  C1
- *                 /  \
- *                /    \
- *               C2 == C3
- * C1 is the master controller and C2, C3 are slave controllers. C2 links to C3
- * laterally
+ *                  A
+ *                 / \
+ *                /   \
+ *               B === C 
+ * A is the master controller and B, C are slave controllers. B links to C
+ * laterally.
+ * Peers are mapped to controllers in the following relations:
+ *             Peer         Controller
+ *               1              A
+ *               2              B
+ *               3              C
+ *
  */
 
 #include "platform.h"
@@ -106,11 +112,6 @@ static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
  */
 static struct GNUNET_TESTBED_Controller *controller1;
 
-/**
- * The controller handle of another controller
- */
-static struct GNUNET_TESTBED_Controller *controller2;
-
 /**
  * peer 1
  */
@@ -132,8 +133,8 @@ static struct PeerContext peer3;
 static struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
- * Handle to controller2 configuration, used to establish lateral link from
- * controller 1
+ * Handle to slave controller C's configuration, used to establish lateral link from
+ * master controller
  */
 static struct GNUNET_CONFIGURATION_Handle *cfg2;
 
@@ -209,9 +210,14 @@ enum Stage
   PEER3_STARTED,
 
   /**
-   * peers are connected
+   * peer1 and peer2 are connected
    */
-  PEERS_CONNECTED,
+  PEERS_1_2_CONNECTED,
+
+  /**
+   * peer2 and peer3 are connected
+   */
+  PEERS_2_3_CONNECTED,
 
   /**
    * Peers are connected once again (this should not fail as they are already connected)
@@ -250,8 +256,6 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_TESTBED_cancel_registration (reg_handle);
   if (NULL != controller1)
     GNUNET_TESTBED_controller_disconnect (controller1);
-  if (NULL != controller2)
-    GNUNET_TESTBED_controller_disconnect (controller2);
   GNUNET_CONFIGURATION_destroy (cfg);
   if (NULL != cfg2)
     GNUNET_CONFIGURATION_destroy (cfg2);
@@ -330,13 +334,22 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
     GNUNET_assert (NULL != common_operation);
     GNUNET_TESTBED_operation_done (common_operation);
     common_operation = NULL;
-    result = PEERS_CONNECTED;
+    result = PEERS_1_2_CONNECTED;
     LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
+    common_operation = 
+        GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
+                                         peer3.peer);
+    break;
+  case PEERS_1_2_CONNECTED:
+    GNUNET_assert (NULL != common_operation);
+    GNUNET_TESTBED_operation_done (common_operation);
+    common_operation = NULL;
+    result = PEERS_2_3_CONNECTED;
     delayed_connect_task =
-       GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3),
-                                     &do_delayed_connect, NULL);
+          GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3),
+                                        &do_delayed_connect, NULL);
     break;
-  case PEERS_CONNECTED:
+  case PEERS_2_3_CONNECTED:
     GNUNET_assert (NULL == peer1.operation);
     GNUNET_assert (NULL == peer2.operation);
     GNUNET_assert (NULL != common_operation);
@@ -375,7 +388,7 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
     peer1.peer = peer;
     GNUNET_TESTBED_operation_done (peer1.operation);
     result = PEER1_CREATED;
-    peer1.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
+    peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
     break;
   case CONTROLLER2_UP:
     GNUNET_assert (NULL != peer2.operation);
@@ -384,7 +397,7 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
     peer2.peer = peer;
     GNUNET_TESTBED_operation_done (peer2.operation);
     result = PEER2_CREATED;
-    peer2.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
+    peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
     break;
   case CONTROLLER3_UP:
     GNUNET_assert (NULL != peer3.operation);
@@ -393,7 +406,7 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
     peer3.peer = peer;
     GNUNET_TESTBED_operation_done (peer3.operation);
     result = PEER3_CREATED;
-    peer3.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
+    peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
     break;
   default:
     GNUNET_assert (0);
@@ -429,10 +442,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
     GNUNET_assert (NULL == event->details.operation_finished.op_cls);
     GNUNET_assert (NULL == event->details.operation_finished.emsg);
-    GNUNET_assert (NULL == event->details.operation_finished.generic);
     switch (result)
-    {
+    {      
     case PEERS_STOPPED:
+      GNUNET_assert (NULL == event->details.operation_finished.generic);
       if (event->details.operation_finished.operation == peer1.operation)
       {
         GNUNET_TESTBED_operation_done (peer1.operation);
@@ -460,6 +473,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       }
       break;
     case PEER1_STARTED:
+      GNUNET_assert (NULL == event->details.operation_finished.generic);
       GNUNET_assert (NULL != common_operation);
       GNUNET_TESTBED_operation_done (common_operation);
       common_operation = NULL;
@@ -470,6 +484,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       GNUNET_assert (NULL != peer2.operation);
       break;
     case PEER2_STARTED:
+      GNUNET_assert (NULL == event->details.operation_finished.generic);
       GNUNET_assert (NULL != common_operation);
       GNUNET_TESTBED_operation_done (common_operation);
       common_operation = NULL;
@@ -493,7 +508,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       peer1.operation = NULL;
       result = PEER1_STARTED;
       common_operation =
-          GNUNET_TESTBED_controller_link (controller1, neighbour1, NULL, cfg,
+          GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, cfg,
                                           GNUNET_YES); 
       break;
     case PEER2_CREATED:
@@ -504,7 +519,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       result = PEER2_STARTED;
       GNUNET_assert (NULL == common_operation);              
       common_operation =
-          GNUNET_TESTBED_controller_link (controller1, neighbour2, NULL, cfg,
+          GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, cfg,
                                           GNUNET_YES);
       GNUNET_assert (NULL != common_operation);
       break;
@@ -515,8 +530,8 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       peer3.operation = NULL;
       result = PEER3_STARTED;
       common_operation =
-          GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
-                                          peer2.peer);
+          GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
+                                          peer1.peer);
       break;
     default:
       GNUNET_assert (0);
@@ -552,16 +567,25 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
     }
     break;
   case GNUNET_TESTBED_ET_CONNECT:
+    GNUNET_assert (NULL == peer1.operation);
+    GNUNET_assert (NULL == peer2.operation);
+    GNUNET_assert (NULL == peer3.operation);
     switch (result)
     {
     case PEER3_STARTED:
-    case PEERS_CONNECTED:
-      GNUNET_assert (NULL == peer1.operation);
-      GNUNET_assert (NULL == peer2.operation);
-      GNUNET_assert (NULL == peer3.operation);
       GNUNET_assert (NULL != common_operation);
-      /* GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) && */
-      /*            (event->details.peer_connect.peer2 == peer2.peer)); */
+      GNUNET_assert ((event->details.peer_connect.peer1 == peer2.peer) &&
+                    (event->details.peer_connect.peer2 == peer1.peer));
+      break;
+    case PEERS_2_3_CONNECTED:
+      GNUNET_assert (NULL != common_operation);
+      GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) &&
+                    (event->details.peer_connect.peer2 == peer2.peer));
+      break;
+    case PEERS_1_2_CONNECTED: 
+      GNUNET_assert (NULL != common_operation);
+      GNUNET_assert ((event->details.peer_connect.peer1 == peer2.peer) &&
+                    (event->details.peer_connect.peer2 == peer3.peer));      
       break;
     default:
       GNUNET_assert (0);
@@ -638,8 +662,7 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int stat
     break;
   default:
     GNUNET_assert (0);
-  }
-  
+  }  
 }
 
 
@@ -659,7 +682,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_assert (NULL != host);
   cfg = GNUNET_CONFIGURATION_dup (config);
   cp1 = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
-                                        NULL);
+                                         NULL);
   abort_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
@@ -668,7 +691,9 @@ run (void *cls, char *const *args, const char *cfgfile,
 
 
 /**
- * Function to check if password-less SSH logins to given ip work
+ * Function to check if 
+ * 1. Password-less SSH logins to given ip work
+ * 2. gnunet-helper-testbed is found on the PATH on the remote side
  *
  * @param host_str numeric representation of the host's ip
  * @return GNUNET_YES if password-less SSH login to the given host works;
@@ -678,8 +703,9 @@ static int
 check_ssh (char *host_str)
 {
   char *const remote_args[] = {
-    "ssh", "-o", "BatchMode=yes", "-o", "CheckHostIP=no", "-q",
-    host_str, "echo", "SSH", "works", NULL
+    "ssh", "-o", "BatchMode=yes", "-o", "CheckHostIP=no", 
+    "-o", "NoHostAuthenticationForLocalhost=yes", "-q",
+    host_str, "which", "gnunet-helper-testbed", NULL
   };
   struct GNUNET_OS_Process *auxp;
   enum GNUNET_OS_ProcessStatusType type;
@@ -710,16 +736,14 @@ int
 main (int argc, char **argv)
 {
   char *const argv2[] = { "test_testbed_api_3peers_3controllers",
-    "-c", "test_testbed_api.conf",
-    NULL
+                          "-c", "test_testbed_api.conf",
+                          NULL
   };
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
   int ret;
 
-  //GNUNET_OS_network_interfaces_list (&interface_processor, NULL);
-
   if (GNUNET_YES != check_ssh ("127.0.0.1"))
     goto error_exit;
   result = INIT;
@@ -732,7 +756,8 @@ main (int argc, char **argv)
   return 0;
 
  error_exit:
-  (void) PRINTF ("Unable to run the test as this system is not configured "
+  (void) PRINTF ("%s",
+                 "Unable to run the test as this system is not configured "
                  "to use password less SSH logins to localhost.\n"
                  "Marking test as successful\n");
   return 0;