add function conv param string
[oweals/gnunet.git] / src / ats-tests / gnunet-ats-sim.c
index 6a9797179ad89025dfab85d1a4b99fc8fc95b4db..27850e3e76852fa17d96b6b5561c73522ca58785 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2013 GNUnet e.V.
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
  You should have received a copy of the GNU General Public License
  along with GNUnet; see the file COPYING.  If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
  */
 /**
  * @file ats-tests/gnunet-ats-sim.c
@@ -47,7 +47,17 @@ static char *opt_exp_file;
  */
 static int opt_log;
 
-GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+/**
+ * cmd option -p: enable plots
+ */
+static int opt_plot;
+
+/**
+ * cmd option -v: verbose logs
+ */
+static int opt_verbose;
+
+struct GNUNET_SCHEDULER_Task * timeout_task;
 
 struct Experiment *e;
 struct LoggingHandle *l;
@@ -61,9 +71,9 @@ evaluate (struct GNUNET_TIME_Relative duration_total)
   struct BenchmarkPeer *mp;
   struct BenchmarkPartner *p;
 
-  unsigned int kb_sent_sec;
+  unsigned int b_sent_sec;
   double kb_sent_percent;
-  unsigned int kb_recv_sec;
+  unsigned int b_recv_sec;
   double kb_recv_percent;
   unsigned int rtt;
 
@@ -83,16 +93,16 @@ evaluate (struct GNUNET_TIME_Relative duration_total)
     {
       p = &mp->partners[c_s];
 
-      kb_sent_sec = 0;
-      kb_recv_sec = 0;
+      b_sent_sec = 0;
+      b_recv_sec = 0;
       kb_sent_percent = 0.0;
       kb_recv_percent = 0.0;
       rtt = 0;
 
       if (duration > 0)
       {
-          kb_sent_sec = (p->bytes_sent / 1024) / duration;
-          kb_recv_sec = (p->bytes_received / 1024) / duration;
+          b_sent_sec = p->bytes_sent / duration;
+          b_recv_sec = p->bytes_received / duration;
       }
 
       if (mp->total_bytes_sent > 0)
@@ -102,11 +112,11 @@ evaluate (struct GNUNET_TIME_Relative duration_total)
       if (1000 * p->messages_sent > 0)
           rtt = p->total_app_rtt / (1000 * p->messages_sent);
       fprintf (stderr,
-          "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
+          "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
           (mp->pref_partner == p->dest) ? '*' : ' ',
           mp->no, p->dest->no,
-          kb_sent_sec, kb_sent_percent,
-                  kb_recv_sec, kb_recv_percent);
+          b_sent_sec, kb_sent_percent,
+                  b_recv_sec, kb_recv_percent);
       fprintf (stderr,
           "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
           (mp->pref_partner == p->dest) ? '*' : ' ',
@@ -118,7 +128,21 @@ evaluate (struct GNUNET_TIME_Relative duration_total)
 static void
 do_shutdown ()
 {
+  fprintf (stderr, "Shutdown\n");
   /* timeout */
+  if (NULL != l)
+  {
+    GNUNET_ATS_TEST_logging_stop (l);
+    GNUNET_ATS_TEST_logging_clean_up (l);
+    l = NULL;
+  }
+
+  /* Stop traffic generation */
+  GNUNET_ATS_TEST_generate_traffic_stop_all();
+
+  /* Stop all preference generations */
+  GNUNET_ATS_TEST_generate_preferences_stop_all ();
+
   if (NULL != e)
   {
     GNUNET_ATS_TEST_experimentation_stop (e);
@@ -127,6 +151,7 @@ do_shutdown ()
   GNUNET_ATS_TEST_shutdown_topology ();
 }
 
+
 static void
 transport_recv_cb (void *cls,
                    const struct GNUNET_PeerIdentity * peer,
@@ -139,10 +164,15 @@ static void
 log_request__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_ATS_Properties *ats)
 {
+
   if (NULL != l)
-    GNUNET_ATS_TEST_logging_now (l);
+  {
+    //GNUNET_break (0);
+    //GNUNET_ATS_TEST_logging_now (l);
+  }
+
 }
 
 static void
@@ -153,22 +183,33 @@ experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,i
         GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
   else
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
-  if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
+  if (NULL != timeout_task)
   {
     GNUNET_SCHEDULER_cancel (timeout_task);
-    timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    timeout_task = NULL;
   }
   /* Stop logging */
   GNUNET_ATS_TEST_logging_stop (l);
-  evaluate (duration);
-  if (opt_log)
-    GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file);
 
   /* Stop traffic generation */
   GNUNET_ATS_TEST_generate_traffic_stop_all();
+
+  /* Stop all preference generations */
+  GNUNET_ATS_TEST_generate_preferences_stop_all ();
+
+  evaluate (duration);
+  if (opt_log)
+    GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
+
+  if (NULL != l)
+  {
+    GNUNET_ATS_TEST_logging_stop (l);
+    GNUNET_ATS_TEST_logging_clean_up (l);
+    l = NULL;
+  }
+
   /* Clean up experiment */
   GNUNET_ATS_TEST_experimentation_stop (e);
-  GNUNET_ATS_TEST_logging_clean_up (l);
   e = NULL;
 
   /* Shutdown topology */
@@ -185,30 +226,88 @@ static void topology_setup_done (void *cls,
     struct BenchmarkPeer *masters,
     struct BenchmarkPeer *slaves)
 {
-  int c_m;
-  int c_s;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n");
 
   masters_p = masters;
   slaves_p = slaves;
 
-  l = GNUNET_ATS_TEST_logging_start (GNUNET_TIME_UNIT_SECONDS,
+  l = GNUNET_ATS_TEST_logging_start (e->log_freq,
       e->name,
       masters_p,
-      e->num_masters);
+      e->num_masters, e->num_slaves,
+      opt_verbose);
   GNUNET_ATS_TEST_experimentation_run (e, &episode_done_cb, &experiment_done_cb);
-
+/*
+  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+      GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS,
+      GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
+      GNUNET_ATS_PREFERENCE_BANDWIDTH);
+*/
+/*
+  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+      GNUNET_ATS_TEST_TG_LINEAR, 1, 50,
+      GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
+      GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
+      GNUNET_ATS_PREFERENCE_BANDWIDTH);
+*/
+/*
+  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+        GNUNET_ATS_TEST_TG_RANDOM, 1, 50,
+        GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
+        GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
+        GNUNET_ATS_PREFERENCE_BANDWIDTH);
+*/
+  /*
+  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+        GNUNET_ATS_TEST_TG_SINUS, 10, 5,
+        GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
+        GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
+        GNUNET_ATS_PREFERENCE_BANDWIDTH);
+*/
+#if 0
+  int c_m;
+  int c_s;
   for (c_m = 0; c_m < e->num_masters; c_m++)
   {
       for (c_s = 0; c_s < e->num_slaves; c_s++)
       {
         /* Generate maximum traffic to all peers */
+        /* Example: Generate traffic with constant 10,000 Bytes/s */
         GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
             &masters[c_m].partners[c_s],
+            GNUNET_ATS_TEST_TG_CONSTANT,
             10000,
             GNUNET_TIME_UNIT_FOREVER_REL);
+        /* Example: Generate traffic with an increasing rate from 1000 to 2000
+         * Bytes/s with in a minute */
+        GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
+            &masters[c_m].partners[c_s],
+            GNUNET_ATS_TEST_TG_LINEAR,
+            1000,
+            2000,
+            GNUNET_TIME_UNIT_MINUTES,
+            GNUNET_TIME_UNIT_FOREVER_REL);
+        /* Example: Generate traffic with a random rate between 1000 to 2000
+         * Bytes/s */
+        GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
+            &masters[c_m].partners[c_s],
+            GNUNET_ATS_TEST_TG_RANDOM,
+            1000,
+            2000,
+            GNUNET_TIME_UNIT_FOREVER_REL,
+            GNUNET_TIME_UNIT_FOREVER_REL);
+        /* Example: Generate traffic with a sinus form, a base rate of
+         * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */
+        GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
+            &masters[c_m].partners[c_s],
+            GNUNET_ATS_TEST_TG_SINUS,
+            1000,
+            2000,
+            GNUNET_TIME_UNIT_MINUTES,
+            GNUNET_TIME_UNIT_FOREVER_REL);
       }
   }
+#endif
 
   timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (GNUNET_TIME_UNIT_MINUTES,
       e->max_duration), &do_shutdown, NULL);
@@ -220,6 +319,7 @@ parse_args (int argc, char *argv[])
   int c;
   opt_exp_file = NULL;
   opt_log = GNUNET_NO;
+  opt_plot = GNUNET_NO;
 
   for (c = 0; c < argc; c++)
   {
@@ -231,6 +331,14 @@ parse_args (int argc, char *argv[])
     {
       opt_log = GNUNET_YES;
     }
+    if (0 == strcmp (argv[c], "-p"))
+    {
+      opt_plot = GNUNET_YES;
+    }
+    if (0 == strcmp (argv[c], "-v"))
+    {
+      opt_verbose = GNUNET_YES;
+    }
   }
 }