(no commit message)
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 31 Mar 2011 14:30:30 +0000 (14:30 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 31 Mar 2011 14:30:30 +0000 (14:30 +0000)
src/transport/gnunet-service-transport.c
src/transport/test_transport_ats.c

index 70a15775b484cb522ea0e94fd2a8400040e45adc..9edd38c2818e36ce14a50f3f20dc8a43cb0b07d8 100644 (file)
@@ -5574,6 +5574,14 @@ struct ATS_peer
        int     t;
 };
 
+struct ATS_result
+{
+       int c_mechs;
+       int c_peers;
+       int solution;
+};
+
+
 #define DEBUG_ATS GNUNET_NO
 #define VERBOSE_ATS GNUNET_NO
 
@@ -5585,9 +5593,10 @@ struct ATS_peer
  * @param R weight for relativity
  * @param v_b_min minimal bandwidth per peer
  * @param v_n_min minimum number of connections
+ * @param res result struct
  * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used
  */
-static int ats_create_problem (int max_it, int max_dur , double D, double U, double R, int v_b_min, int v_n_min)
+static int ats_create_problem (int max_it, int max_dur , double D, double U, double R, int v_b_min, int v_n_min, struct ATS_result *res)
 {
 #if !HAVE_LIBGLPK
        if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "no glpk installed\n");
@@ -5934,7 +5943,9 @@ static int ats_create_problem (int max_it, int max_dur , double D, double U, dou
        ia[array_index] = row_index;
        ja[array_index] = (2*c_mechs) + 2;
        ar[array_index] = -1;
-       if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
+#if VERBOSE_ATS
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
+#endif
 
        array_index++;
        row_index ++;
@@ -6019,7 +6030,7 @@ static int ats_create_problem (int max_it, int max_dur , double D, double U, dou
        case GLP_EOBJLL :    /* objective lower limit reached */
        case GLP_EOBJUL :    /* objective upper limit reached */
        case GLP_EROOT  :    /* root LP optimum not provided */
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid Input data\n");
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid Input data: %i\n", result);
        break;
 
        break;
@@ -6027,7 +6038,7 @@ static int ats_create_problem (int max_it, int max_dur , double D, double U, dou
                        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem has been solved\n");
        break;
        }
-
+#if VERBOSE_ATS
        switch (solution) {
                case GLP_UNDEF:
                        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MIP solution is undeļ¬ned\n");
@@ -6057,11 +6068,17 @@ static int ats_create_problem (int max_it, int max_dur , double D, double U, dou
        old = debug_solution;
        GNUNET_asprintf(&debug_solution, "%s z = %g; \n", debug_solution,  glp_get_obj_val(prob));
        if (old!=NULL) GNUNET_free(old);
-       if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s \n",debug_solution);
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s \n",debug_solution);
+       GNUNET_free(debug_solution);
+#endif
+
+       res->c_mechs = c_mechs;
+       res->c_peers = c_peers;
+       res->solution = solution;
 
        /* clean up */
 
-       GNUNET_free(debug_solution);
+
        glp_delete_prob(prob);
 
        GNUNET_free (ja);
@@ -6082,16 +6099,25 @@ void ats_benchmark (int peers, int transports, int start_peers, int end_peers)
        struct GNUNET_TIME_Absolute start;
        struct GNUNET_TIME_Relative duration;
        int c_mechs = 0;
+       struct ATS_result result;
 
        if (glpk==GNUNET_YES)
        {
                start = GNUNET_TIME_absolute_get();
-               c_mechs = ats_create_problem(5000, 5000, 1.0, 1.0, 1.0, 1000, 5);
-               if (c_mechs >= 0)
-               {
+               c_mechs = ats_create_problem(5000, 5000, 1.0, 1.0, 1.0, 1000, 5, &result);
                duration = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get());
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP execution time in [ms] for %i mechanisms: %llu\n", c_mechs, duration.rel_value);
-               //GNUNET_STATISTICS_set (stats, "ATS execution time 100 peers", duration.rel_value, GNUNET_NO);
+               if (c_mechs > 0)
+               {
+                       if (DEBUG_ATS) {GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP execution time in [ms] for %i mechanisms: %llu\n", c_mechs, duration.rel_value);}
+                       GNUNET_STATISTICS_set (stats, "ATS duration", duration.rel_value, GNUNET_NO);
+                       GNUNET_STATISTICS_set (stats, "ATS mechanisms", result.c_mechs, GNUNET_NO);
+                       GNUNET_STATISTICS_set (stats, "ATS peers", result.c_peers, GNUNET_NO);
+                       GNUNET_STATISTICS_set (stats, "ATS solution", result.solution, GNUNET_NO);
+                       GNUNET_STATISTICS_set (stats, "ATS timestamp", start.abs_value, GNUNET_NO);
+               }
+               else if (c_mechs == 0)
+               {
+                       if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP not executed: no addresses\n");
                }
                else glpk = GNUNET_NO;
        }
index 9f4e8d05f51aa9972af0f0b5fe7586b231d1ccf5..2880da8e59066fe0bee9c229097fd8d570323e99 100644 (file)
 #include "gnunet_testing_lib.h"
 #include "gnunet_scheduler_lib.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
-#define NUM_PEERS 2
+#define NUM_PEERS 11
+#define MEASUREMENTS 5
 
-#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
 
@@ -39,12 +40,27 @@ static int peers_left;
 
 static int failed_peers;
 
+static int measurement_started;
+
 static struct GNUNET_TESTING_PeerGroup *pg;
 
-static  GNUNET_SCHEDULER_TaskIdentifier task;
+static  GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+static  GNUNET_SCHEDULER_TaskIdentifier stats_task;
 
 struct GNUNET_TESTING_Daemon * master_deamon;
 
+struct GNUNET_STATISTICS_Handle * stats;
+
+struct ATS_result
+{
+       uint64_t timestamp;
+       int mechs;
+       int peers;
+       int solution;
+};
+
+//static int index;
+static struct ATS_result results[MEASUREMENTS];
 
 /**
  * Check whether peers successfully shut down.
@@ -71,26 +87,94 @@ shutdown_callback (void *cls, const char *emsg)
 
 static void shutdown_peers()
 {
+       if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
+               GNUNET_SCHEDULER_cancel(shutdown_task);
+       if (stats_task != GNUNET_SCHEDULER_NO_TASK)
+               GNUNET_SCHEDULER_cancel(stats_task);
+
     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
 }
 
+int stats_cb (void *cls,
+                          const char *subsystem,
+                          const char *name,
+                          uint64_t value,
+                          int is_persistent)
+{
+    if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) && (value == NUM_PEERS-1))
+    {
+               measurement_started = GNUNET_YES;
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                       "All %llu peers connected\n", value);
+    }
+    if (measurement_started == GNUNET_YES)
+    {
+               if (0 == strcmp (name,"ATS timestamp"))
+               {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                               "ATS timestamp: %s %llu \n",name, value);
+               }
+               if (0 == strcmp (name,"ATS solution"))
+               {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                               "ATS solution: %s %llu \n",name, value);
+               }
+               if (0 == strcmp (name,"ATS peers"))
+               {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                               "ATS peers: %s %llu \n",name, value);
+               }
+               if (0 == strcmp (name,"ATS mechanisms"))
+               {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                               "ATS mechanisms: %s %llu \n",name, value);
+               }
+               if (0 == strcmp (name,"ATS duration"))
+               {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                               "ATS duration: %s %llu \n",name, value);
+               }
+    }
+
+    return GNUNET_OK;
+}
+
+
 void
-delay_task (void *cls,
+stats_get_task (void *cls,
                          const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-       task = GNUNET_SCHEDULER_NO_TASK;
+       stats_task = GNUNET_SCHEDULER_NO_TASK;
+       if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+           return;
+
+       GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL, &stats_cb, NULL);
+       GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL, &stats_cb, NULL);
+       GNUNET_assert (NULL != GNUNET_STATISTICS_get (stats, "transport","ATS duration", TIMEOUT, NULL, &stats_cb, NULL));
+       GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL, &stats_cb, NULL);
+       GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT, NULL, &stats_cb, NULL);
+
+       stats_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &stats_get_task, NULL);
+}
+
+void
+delay (void *cls,
+                         const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+       shutdown_task = GNUNET_SCHEDULER_NO_TASK;
        if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
            return;
 
 #if VERBOSE
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
 #endif
+       GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
        shutdown_peers ();
 }
 
 static void connect_peers()
 {
-    task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay_task, NULL);
+    shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
 
 }
 
@@ -104,7 +188,13 @@ void daemon_connect_cb(void *cls,
                                                struct GNUNET_TESTING_Daemon *second_daemon,
                                                const char *emsg)
 {
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peer `%s' \n", GNUNET_i2s(first), GNUNET_i2s(second));
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peers `%s'<->`%s': `%s' \n", GNUNET_i2s(first), GNUNET_i2s(second), (emsg==NULL) ? "OK" : emsg);
+}
+
+void cont_cb (void *cls, int success)
+{
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "STATS cont_cb: %i\n", success);
 }
 
 static void
@@ -124,7 +214,7 @@ daemon_start_cb (void *cls,
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Too many peers failed, ending test!\n");
           ok = 1;
-          GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+       shutdown_peers ();
         }
       return;
     }
@@ -132,13 +222,17 @@ daemon_start_cb (void *cls,
 
   if (master_deamon == NULL)
   {
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s'\n", GNUNET_i2s(id));
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
+
          master_deamon = d;
+         stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
+         GNUNET_assert (stats != NULL);
+         stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
   }
   else
   {
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id));
-         GNUNET_TESTING_daemons_connect(master_deamon, d, TIMEOUT, 10, GNUNET_YES,&daemon_connect_cb, NULL);
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
+         GNUNET_TESTING_daemons_connect(d, master_deamon, TIMEOUT, 0, GNUNET_YES,&daemon_connect_cb, NULL);
   }
 
   if (peers_left == 0)
@@ -164,6 +258,7 @@ run (void *cls,
      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   ok = 1;
+  measurement_started = GNUNET_NO;
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", NUM_PEERS);
 #endif
@@ -183,7 +278,7 @@ check ()
 {
   char *const argv[] = { "test-testing",
     "-c",
-    "test_testing_data.conf",
+    "test_transport_ats.conf",
 #if VERBOSE
     "-L", "DEBUG",
 #endif