gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r24162 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r24162 - gnunet/src/testbed
Date: Tue, 2 Oct 2012 16:54:17 +0200

Author: harsha
Date: 2012-10-02 16:54:16 +0200 (Tue, 02 Oct 2012)
New Revision: 24162

Modified:
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testbed/test_testbed_api_controllerlink.c
   gnunet/src/testbed/testbed_api.c
Log:
test case for lateral connections between controllers

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-10-02 12:16:27 UTC (rev 
24161)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-10-02 14:54:16 UTC (rev 
24162)
@@ -729,16 +729,19 @@
 host_list_add (struct GNUNET_TESTBED_Host *host)
 {
   uint32_t host_id;
+  uint32_t orig_size;
 
   host_id = GNUNET_TESTBED_host_get_id_ (host);
+  orig_size = host_list_size;  
   if (host_list_size <= host_id)
   {
+    while (host_list_size <= host_id)
+      host_list_size += LIST_GROW_STEP;
     host_list =
         TESTBED_realloc (host_list,
-                         sizeof (struct GNUNET_TESTBED_Host *) * 
host_list_size,
-                         sizeof (struct GNUNET_TESTBED_Host *) *
-                         (host_list_size + LIST_GROW_STEP));
-    host_list_size += LIST_GROW_STEP;
+                         sizeof (struct GNUNET_TESTBED_Host *) * orig_size,
+                         sizeof (struct GNUNET_TESTBED_Host *)
+                        * host_list_size);
   }
   if (NULL != host_list[host_id])
   {
@@ -758,13 +761,17 @@
 static void
 route_list_add (struct Route *route)
 {
+  uint32_t orig_size;
+
+  orig_size = route_list_size;  
   if (route->dest >= route_list_size)
   {
+    while (route->dest >= route_list_size)
+      route_list_size += LIST_GROW_STEP;
     route_list =
-        TESTBED_realloc (route_list, sizeof (struct Route *) * route_list_size,
-                         sizeof (struct Route *) * (route_list_size +
-                                                    LIST_GROW_STEP));
-    route_list_size += LIST_GROW_STEP;
+        TESTBED_realloc (route_list,
+                        sizeof (struct Route *) * orig_size,
+                         sizeof (struct Route *) * route_list_size);
   }
   GNUNET_assert (NULL == route_list[route->dest]);
   route_list[route->dest] = route;
@@ -1204,7 +1211,7 @@
 
   if (NULL != master_context)
   {
-    /* We are being connected to laterally */
+    LOG_DEBUG ("We are being connected to laterally\n");
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -1586,11 +1593,24 @@
     GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
   /* FIXME: Adding a new route should happen after the controllers are linked
    * successfully */
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+  if (1 != msg->is_subordinate)
+  {
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+  if ((delegated_host_id < route_list_size)
+      && (NULL != route_list[delegated_host_id]))
+  {
+    GNUNET_break_op (0);       /* Are you trying to link delegated host twice
+                                  with is subordinate flag set to GNUNET_YES? 
*/
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
   new_route = GNUNET_malloc (sizeof (struct Route));
   new_route->dest = delegated_host_id;
   new_route->thru = route->dest;
   route_list_add (new_route);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
@@ -2695,14 +2715,14 @@
   GNUNET_free (config);  
   reply_size = xconfig_size + sizeof (struct 
GNUNET_TESTBED_SlaveConfiguration);
   GNUNET_break (reply_size <= UINT16_MAX);
-  GNUNET_break (config_size <= UINT32_MAX);
+  GNUNET_break (config_size <= UINT16_MAX);
   reply = GNUNET_realloc (xconfig, reply_size);
   (void) memmove (&reply[1], reply, xconfig_size);
   reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG);
   reply->header.size = htons ((uint16_t) reply_size);
   reply->slave_id = msg->slave_id;
   reply->operation_id = msg->operation_id;
-  reply->config_size = htonl ((uint32_t) config_size);
+  reply->config_size = htons ((uint16_t) config_size);
   queue_message (client, &reply->header);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }

Modified: gnunet/src/testbed/test_testbed_api_controllerlink.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_controllerlink.c        2012-10-02 
12:16:27 UTC (rev 24161)
+++ gnunet/src/testbed/test_testbed_api_controllerlink.c        2012-10-02 
14:54:16 UTC (rev 24162)
@@ -24,6 +24,19 @@
  * @author Sree Harsha Totakura <address@hidden>
  */
 
+
+/**
+ * The controller architecture we try to achieve in this test case:
+ *
+ *                    Master Controller 
+ *                    //             \\
+ *                   //               \\
+ *         Slave Controller 1---------Slave Controller 3
+ *                  ||                  
+ *                  ||                 
+ *         Slave Controller 2
+ */
+
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_testing_lib-new.h"
@@ -47,75 +60,96 @@
 enum Stage
 {
 
-    /**
-     * Initial stage
-     */
+  /**
+   * Initial stage
+   */
   INIT,
-
-    /**
-     * Master controller has started
-     */
+  
+  /**
+   * Master controller has started
+   */
   MASTER_STARTED,
 
-    /**
-     * The first slave has been registered at master controller
-     */
+  /**
+   * The first slave has been registered at master controller
+   */
   SLAVE1_REGISTERED,
 
-    /**
-     * The second slave has been registered at the master controller
-     */
+  /**
+   * The second slave has been registered at the master controller
+   */
   SLAVE2_REGISTERED,
 
-    /**
-     * Link from master to slave 1 has been successfully created
-     */
+  /**
+   * Link from master to slave 1 has been successfully created
+   */
   SLAVE1_LINK_SUCCESS,
 
-    /**
-     * Link from slave 1 to slave 2 has been successfully created.
-     */
+  /**
+   * Link from slave 1 to slave 2 has been successfully created.
+   */
   SLAVE2_LINK_SUCCESS,
 
-    /**
-     * Peer create on slave 1 successful
-     */
+  /**
+   * Peer create on slave 1 successful
+   */
   SLAVE1_PEER_CREATE_SUCCESS,
 
-    /**
-     * Peer create on slave 2 successful
-     */
+  /**
+   * Peer create on slave 2 successful
+   */
   SLAVE2_PEER_CREATE_SUCCESS,
 
-    /**
-     * Peer startup on slave 1 successful
-     */
+  /**
+   * Peer startup on slave 1 successful
+   */
   SLAVE1_PEER_START_SUCCESS,
 
-    /**
-     * Peer on slave 1 successfully stopped
-     */
+  /**
+   * Peer on slave 1 successfully stopped
+   */
   SLAVE1_PEER_STOP_SUCCESS,
 
-    /**
-     * Peer startup on slave 2 successful
-     */
+  /**
+   * Peer startup on slave 2 successful
+   */
   SLAVE2_PEER_START_SUCCESS,
 
-    /**
-     * Peer on slave 2 successfully stopped
-     */
+  /**
+   * Peer on slave 2 successfully stopped
+   */
   SLAVE2_PEER_STOP_SUCCESS,
 
-    /**
-     * Peer destroy on slave 1 successful
-     */
+  /**
+   * Peer destroy on slave 1 successful
+   */
   SLAVE1_PEER_DESTROY_SUCCESS,
 
-    /**
-     * Peer destory on slave 2 successful; Marks test as successful
-     */
-  SUCCESS
+  /**
+   * Peer destory on slave 2 successful
+   */
+  SLAVE2_PEER_DESTROY_SUCCESS,
+
+  /**
+   * Slave 3 has successfully registered
+   */
+  SLAVE3_REGISTERED,
+
+  /**
+   * Slave 3 has successfully started
+   */
+  SLAVE3_STARTED,
+
+  /**
+   * The configuration of slave 3 is acquired
+   */
+  SLAVE3_GET_CONFIG_SUCCESS,
+
+  /**
+   * Slave 1 has linked to slave 3; Also marks test as success
+   */
+  SLAVE3_LINK_SUCCESS,
+
 };
 
 /**
@@ -144,6 +178,11 @@
 static struct GNUNET_TESTBED_Host *slave2;
 
 /**
+ * Host for slave 3
+ */
+static struct GNUNET_TESTBED_Host *slave3;
+
+/**
  * Slave host registration handle
  */
 static struct GNUNET_TESTBED_HostRegistrationHandle *rh;
@@ -154,6 +193,11 @@
 static struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
+ * Configuration of slave 3 controller
+ */
+static struct GNUNET_CONFIGURATION_Handle *cfg3;
+
+/**
  * Abort task
  */
 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
@@ -195,6 +239,8 @@
 {
   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
     GNUNET_SCHEDULER_cancel (abort_task);
+  if (NULL != slave3)
+    GNUNET_TESTBED_host_destroy (slave3);
   if (NULL != slave2)
     GNUNET_TESTBED_host_destroy (slave2);
   if (NULL != slave)
@@ -205,11 +251,12 @@
     GNUNET_TESTBED_controller_disconnect (mc);
   if (NULL != cfg)
     GNUNET_CONFIGURATION_destroy (cfg);
+  if (NULL != cfg3)
+    GNUNET_CONFIGURATION_destroy (cfg3);
   if (NULL != cp)
     GNUNET_TESTBED_controller_stop (cp);
   if (NULL != rh)
     GNUNET_TESTBED_cancel_registration (rh);
-
 }
 
 
@@ -229,6 +276,21 @@
 
 
 /**
+ * Calls abort now
+ *
+ * @param 
+ * @return 
+ */
+static void
+do_abort_now (void *cls)
+{
+  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+    GNUNET_SCHEDULER_cancel (abort_task);
+  abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+}
+
+
+/**
  * Task for inserting delay between tests
  *
  * @param
@@ -310,6 +372,16 @@
 
 
 /**
+ * Callback which will be called to after a host registration succeeded or 
failed
+ *
+ * @param cls the host which has been registered
+ * @param emsg the error message; NULL if host registration is successful
+ */
+static void
+registration_cont (void *cls, const char *emsg);
+
+
+/**
  * Signature of the event handler function called by the
  * respective event controller.
  *
@@ -385,9 +457,37 @@
   case SLAVE1_PEER_DESTROY_SUCCESS:
     check_operation_success (event);
     GNUNET_TESTBED_operation_done (op);
-    result = SUCCESS;
-    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    op = NULL;
+    result = SLAVE2_PEER_DESTROY_SUCCESS;
+    slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, 0);
+    rh = GNUNET_TESTBED_register_host (mc, slave3, &registration_cont, NULL);
     break;
+  case SLAVE3_REGISTERED:
+    check_operation_success (event);
+    GNUNET_TESTBED_operation_done (op);
+    op = NULL;
+    result = SLAVE3_STARTED;
+    op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3);
+    GNUNET_assert (NULL != op);    
+    break;
+  case SLAVE3_STARTED:
+    GNUNET_assert (NULL != event);
+    GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
+    GNUNET_assert (event->details.operation_finished.operation == op);
+    GNUNET_assert (NULL == event->details.operation_finished.op_cls);
+    GNUNET_assert (NULL == event->details.operation_finished.emsg);
+    cfg3 = GNUNET_CONFIGURATION_dup 
(event->details.operation_finished.generic);
+    GNUNET_TESTBED_operation_done (op);
+    result = SLAVE3_GET_CONFIG_SUCCESS;
+    op = GNUNET_TESTBED_controller_link (mc, slave3, slave, cfg3, GNUNET_NO);
+    break;
+  case SLAVE3_GET_CONFIG_SUCCESS:
+    result = SLAVE3_LINK_SUCCESS;
+    GNUNET_TESTBED_operation_done (op);
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                 (GNUNET_TIME_UNIT_SECONDS, 3),
+                                 &do_shutdown, NULL);
+    break;
   default:
     GNUNET_assert (0);
   }
@@ -423,8 +523,17 @@
     op = GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES);
     GNUNET_assert (NULL != op);
     break;
+  case SLAVE2_PEER_DESTROY_SUCCESS:
+    GNUNET_assert (NULL == emsg);
+    GNUNET_assert (NULL != mc);
+    GNUNET_assert (NULL == op);
+    result = SLAVE3_REGISTERED;
+    op = GNUNET_TESTBED_controller_link (mc, slave3, NULL, cfg, GNUNET_YES);
+    GNUNET_assert (NULL != op);
+    break;
   default:
-    GNUNET_assert (0);
+    GNUNET_break (0);
+    do_abort_now (NULL);
   }
 }
 
@@ -459,8 +568,10 @@
     rh = GNUNET_TESTBED_register_host (mc, slave, &registration_cont, NULL);
     GNUNET_assert (NULL != rh);
     break;
-  default:
-    GNUNET_assert (0);
+  default:    
+    GNUNET_break (0);
+    cp = NULL;
+    do_abort_now (NULL);
   }
 }
 
@@ -536,7 +647,7 @@
       GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
                           "test_testbed_api_controllerlink", "nohelp", options,
                           &run, NULL);
-  if ((GNUNET_OK != ret) || (SUCCESS != result))
+  if ((GNUNET_OK != ret) || (SLAVE3_LINK_SUCCESS != result))
     return 1;
   return 0;
 }

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-10-02 12:16:27 UTC (rev 24161)
+++ gnunet/src/testbed/testbed_api.c    2012-10-02 14:54:16 UTC (rev 24162)
@@ -1972,7 +1972,7 @@
       xdata = (const Bytef *) &imsg[1];
     }
     break;
-  case GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG:
+  case GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG:
     {
       const struct GNUNET_TESTBED_SlaveConfiguration *imsg;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]