do not print two messages, one is enough
[oweals/gnunet.git] / src / ats-tests / ats-testing.c
index 08a61367b9796b7f86ac0445391b7870a999c689..f64fa1822b2d0a06859189d6eff8fd63cb533980 100644 (file)
@@ -48,6 +48,7 @@ struct TestbedConnectOperation
   struct GNUNET_TESTBED_Operation *connect_op;
 };
 
+struct GNUNET_CONFIGURATION_Handle *cfg;
 
 struct GNUNET_ATS_TEST_Topology *top;
 
@@ -65,7 +66,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   int c_op;
   struct BenchmarkPeer *p;
 
-  top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
+  top->shutdown_task = NULL;
   top->state.benchmarking = GNUNET_NO;
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
@@ -81,9 +82,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       p->peer_id_op = NULL;
     }
 
-    if (GNUNET_SCHEDULER_NO_TASK != p->ats_task)
+    if (NULL != p->ats_task)
       GNUNET_SCHEDULER_cancel (p->ats_task);
-    p->ats_task = GNUNET_SCHEDULER_NO_TASK;
+    p->ats_task = NULL;
 
     for (c_op = 0; c_op < p->num_partners; c_op++)
     {
@@ -418,7 +419,7 @@ connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
         _("Failed to connect master peer [%u] with slave [%u]\n"),
         cop->master->no, cop->slave->no);
     GNUNET_break(0);
-    if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
+    if (NULL != top->shutdown_task)
       GNUNET_SCHEDULER_cancel (top->shutdown_task);
     top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
   }
@@ -469,7 +470,7 @@ do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
             _("Could not connect master [%u] and slave [%u]\n"), p->no,
             top->sps[c_s].no);
         GNUNET_break(0);
-        if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
+        if (NULL != top->shutdown_task)
           GNUNET_SCHEDULER_cancel (top->shutdown_task);
         top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
         return;
@@ -488,7 +489,7 @@ comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
   {
     GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
     GNUNET_break(0);
-    if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
+    if (NULL != top->shutdown_task)
       GNUNET_SCHEDULER_cancel (top->shutdown_task);
     top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
     return;
@@ -540,14 +541,15 @@ do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
 }
 
+
 static void
 ats_performance_info_cb (void *cls,
-    const struct GNUNET_HELLO_Address *address,
-    int address_active,
-    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
-    const struct GNUNET_ATS_Information *ats,
-    uint32_t ats_count)
+                         const struct GNUNET_HELLO_Address *address,
+                         int address_active,
+                         struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                         struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+                         const struct GNUNET_ATS_Information *ats,
+                         uint32_t ats_count)
 {
   struct BenchmarkPeer *me = cls;
   struct BenchmarkPartner *p;
@@ -631,8 +633,11 @@ ats_performance_info_cb (void *cls,
      }
    }
   if (GNUNET_YES == log)
-    top->ats_perf_cb (cls, address, address_active, bandwidth_out, bandwidth_in,
-      ats, ats_count);
+    top->ats_perf_cb (cls, address,
+                      address_active,
+                      bandwidth_out,
+                      bandwidth_in,
+                      ats, ats_count);
   GNUNET_free(peer_id);
 }
 
@@ -643,7 +648,9 @@ ats_perf_connect_adapter (void *cls,
 {
   struct BenchmarkPeer *me = cls;
 
-  me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, ats_performance_info_cb, me);
+  me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
+                                                     &ats_performance_info_cb,
+                                                     me);
   if (NULL == me->ats_perf_handle)
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
         "Failed to create ATS performance handle \n");
@@ -669,7 +676,7 @@ ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
   {
     GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
     GNUNET_break(0);
-    if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
+    if (NULL != top->shutdown_task)
       GNUNET_SCHEDULER_cancel (top->shutdown_task);
     top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
     return;
@@ -740,6 +747,7 @@ peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
  * Signature of a main function for a testcase.
  *
  * @param cls closure
+ * @param h testbed handle
  * @param num_peers number of peers in 'peers'
  * @param peers_ handle to peers run in the testbed
  * @param links_succeeded the number of overlay link connection attempts that
@@ -835,18 +843,48 @@ controller_event_cb (void *cls,
   }
 }
 
+struct BenchmarkPeer *
+GNUNET_ATS_TEST_get_peer (int src)
+{
+  if (src > top->num_masters)
+    return NULL;
+  return &top->mps[src];
+}
+
+struct BenchmarkPartner *
+GNUNET_ATS_TEST_get_partner (int src, int dest)
+{
+  if (src > top->num_masters)
+    return NULL;
+  if (dest > top->num_slaves)
+    return NULL;
+  return &top->mps[src].partners[dest];
+}
 
+
+/**
+ * Create a topology for ats testing
+ *
+ * @param name test name
+ * @param cfg_file configuration file to use for the peers
+ * @param num_slaves number of slaves
+ * @param num_masters number of masters
+ * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
+ * @param done_cb function to call when topology is setup
+ * @param done_cb_cls cls for callback
+ * @param transport_recv_cb callback to call when data are received
+ * @param log_request_cb callback to call when logging is required
+ */
 void
 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
-    unsigned int num_slaves,
-    unsigned int num_masters,
-    int test_core,
-    GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
-    void *done_cb_cls,
-    GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
-    GNUNET_ATS_AddressInformationCallback log_request_cb)
+                                 unsigned int num_slaves,
+                                 unsigned int num_masters,
+                                 int test_core,
+                                 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
+                                 void *done_cb_cls,
+                                 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
+                                 GNUNET_ATS_AddressInformationCallback log_request_cb)
 {
-
   static struct GNUNET_CORE_MessageHandler handlers[] = {
       {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
       {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
@@ -871,16 +909,21 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
   event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
   event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
   (void) GNUNET_TESTBED_test_run (name, cfg_file,
-      num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
-      &main_run, NULL);
+                                  num_slaves + num_masters,
+                                  event_mask,
+                                  &controller_event_cb, NULL,
+                                  &main_run, NULL);
 }
 
+
+/**
+ * Shutdown topology
+ */
 void
 GNUNET_ATS_TEST_shutdown_topology (void)
 {
   if (NULL == top)
     return;
-
   GNUNET_SCHEDULER_shutdown();
 }