topology option support for GNUNET_TESTBED_run() via configuration
[oweals/gnunet.git] / src / testbed / testbed_api_topology.c
index 0e237cde3a545e2dd0ebe6a9dc621c2a3f8d1d57..edf0f5d3f40ead2b8963ba3ec467631c4268e370 100644 (file)
@@ -94,7 +94,12 @@ struct TopologyContext
   /**
    * The size of the link array
    */
-  unsigned int link_array_size;  
+  unsigned int link_array_size;
+
+  /**
+   * should the automatic retry be disabled
+   */
+  int disable_retry;
   
 };
 
@@ -117,10 +122,10 @@ overlay_link_completed (void *cls,
 
   GNUNET_assert (op == link->op);
   GNUNET_TESTBED_operation_done (op);
-  link->op = NULL;  
-  if (NULL != emsg)
+  link->op = NULL;
+  tc = link->tc;
+  if ((NULL != emsg) && (GNUNET_NO == tc->disable_retry))
   {
-    tc = link->tc;
     LOG (GNUNET_ERROR_TYPE_WARNING,
         "Error while establishing a link: %s -- Retrying\n", emsg);
     link->op =
@@ -172,7 +177,7 @@ oprelease_overlay_configure_topology (void *cls)
   {
     for (p = 0; p < tc->link_array_size; p++)
       if (NULL != tc->link_array[p].op)
-        GNUNET_TESTBED_operation_cancel (tc->link_array[p].op);
+        GNUNET_TESTBED_operation_done (tc->link_array[p].op);
     GNUNET_free (tc->link_array);
   }
   GNUNET_free (tc);
@@ -251,6 +256,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
   struct TopologyContext *tc;
   struct GNUNET_TESTBED_Operation *op;
   struct GNUNET_TESTBED_Controller *c;
+  enum GNUNET_TESTBED_TopologyOption secondary_option;
   unsigned int cnt;
 
   if (num_peers < 2)
@@ -269,6 +275,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
     {
       tc->link_array[cnt-1].A = cnt-1;
       tc->link_array[cnt-1].B = cnt;
+      tc->link_array[cnt-1].tc = tc;
     }
     break;
   case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
@@ -291,15 +298,58 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
       tc->link_array[cnt].tc = tc;
     }
     break;
+  case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
+    tc->link_array_size = num_peers * (num_peers - 1);
+    tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
+                                    tc->link_array_size);
+    {
+      unsigned int offset;
+      
+      offset = 0;
+      for (cnt=0; cnt < num_peers; cnt++)
+      {
+        unsigned int neighbour;
+        
+        for (neighbour=0; neighbour < num_peers; neighbour++)
+        {
+          if (neighbour == cnt)
+            continue;
+          tc->link_array[offset].A = cnt;
+          tc->link_array[offset].B = neighbour;
+          tc->link_array[offset].tc = tc;
+          offset++;
+        }
+      }
+    }
+    break;
   default:
     GNUNET_break (0);
     return NULL;
   }
+  do
+  {
+    secondary_option = va_arg (va, enum GNUNET_TESTBED_TopologyOption);
+    switch (secondary_option)
+    {
+    case GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY:
+      tc->disable_retry = GNUNET_YES;
+      break;
+    case GNUNET_TESTBED_TOPOLOGY_OPTION_END:
+      break;
+    default:
+      GNUNET_break (0);         /* Should not use any other option apart from
+                                   the ones handled here */
+      GNUNET_free_non_null (tc->link_array);
+      GNUNET_free (tc);
+      return NULL;
+    }
+  } while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option);
   op = GNUNET_TESTBED_operation_create_ (tc,
                                         &opstart_overlay_configure_topology,
                                         &oprelease_overlay_configure_topology);
   GNUNET_TESTBED_operation_queue_insert_
       (c->opq_parallel_topology_config_operations, op);
+  GNUNET_TESTBED_operation_begin_wait_ (op);
   return op;
 }
 
@@ -327,6 +377,7 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, unsigned int num_peers,
   struct GNUNET_TESTBED_Operation *op;
   va_list vargs;
 
+  GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END);
   va_start (vargs, topo);
   op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers,
                                                     topo, vargs);