scheduling
[oweals/gnunet.git] / src / experimentation / test_experimentation_clique.c
index 27f9e9cde5ebf94513185be54610cdd1950a46a7..eee4cc072469a33a20fb5ec267f4633438dc523f 100644 (file)
 /**
  * Number of peers we want to start
  */
-#define NUM_PEERS 5
+#define NUM_PEERS 10
+
+#define NUM_ISSUER 1
+
+#define NUM_EXPERIMENTS 2
+
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, (5 * NUM_PEERS) + 20)
 
 /**
  * Array of peers
@@ -79,8 +85,15 @@ struct ExperimentationPeer
    * Handle to the statistics service
    */
   struct GNUNET_STATISTICS_Handle *sh;
+
+  unsigned int active_nodes;
+  unsigned int requested_nodes;
+  unsigned int inactive_nodes;
+  unsigned int issuer;
+  unsigned int experiments;
 };
 
+
 struct ExperimentationPeer ph[NUM_PEERS];
 
 /**
@@ -128,8 +141,11 @@ controller_event_cb (void *cls,
     {
       result = GNUNET_OK;
       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All %u peers connected \n", NUM_PEERS);
-
-      //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+      if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
+      {
+               GNUNET_SCHEDULER_cancel (shutdown_task);
+      }
+      shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, do_shutdown, NULL);
     }
     break;
   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
@@ -142,6 +158,53 @@ controller_event_cb (void *cls,
   }
 }
 
+static void
+check_end ()
+{
+       static int last_active_value = 0;
+       static int last_issuer_value = 0;
+       static int last_experiments_value = 0;
+  unsigned int peer;
+  unsigned int total_active = 0;
+  unsigned int total_inactive = 0;
+  unsigned int total_requested = 0;
+  unsigned int issuer = 0;
+  unsigned int experiments = 0;
+
+       for (peer = 0; peer < NUM_PEERS; peer++)
+       {
+                       total_active += ph[peer].active_nodes;
+                       total_requested += ph[peer].requested_nodes;
+                       total_inactive += ph[peer].inactive_nodes;
+                       if (NUM_ISSUER == ph[peer].issuer)
+                               issuer ++;
+                       if (NUM_EXPERIMENTS == ph[peer].experiments)
+                               experiments ++;
+       }
+       if ((last_issuer_value < issuer) && (issuer == NUM_PEERS))
+               fprintf (stderr, "I");
+       last_issuer_value = issuer;
+
+       if ((last_experiments_value < experiments) && (experiments == NUM_PEERS))
+               fprintf (stderr, "E");
+       last_experiments_value = experiments;
+
+       if (last_active_value < total_active)
+               fprintf (stderr, ".");
+       last_active_value = total_active;
+
+
+       if ((total_active == (NUM_PEERS * (NUM_PEERS -1))) &&
+                (total_requested == 0) && (total_inactive == 0) &&
+                (issuer == NUM_PEERS) && (experiments == NUM_PEERS))
+       {
+                       fprintf (stderr, "\n");
+                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All %u peers active in a clique\n", NUM_PEERS);
+                       GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+       }
+}
+
+
 
 /**
  * Callback function to process statistic values.
@@ -157,7 +220,31 @@ static int
 stat_iterator (void *cls, const char *subsystem, const char *name,
                      uint64_t value, int is_persistent)
 {
-       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "STATS `%s' %s %llu\n", subsystem, name, value);
+  struct ExperimentationPeer *peer = cls;
+
+       if (0 == strcmp (name, "# nodes active"))
+       {
+                       peer->active_nodes = value;
+       }
+       if (0 == strcmp (name, "# nodes inactive"))
+       {
+                       peer->inactive_nodes = value;
+       }
+       if (0 == strcmp (name, "# nodes requested"))
+       {
+                       peer->requested_nodes = value;
+       }
+       if (0 == strcmp (name, "# issuer"))
+       {
+                       peer->issuer = value;
+       }
+       if (0 == strcmp (name, "# experiments"))
+       {
+                       peer->experiments = value;
+       }
+
+       check_end ();
+
        return GNUNET_OK;
 }
 
@@ -193,6 +280,12 @@ stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
                 (sh, "experimentation", "# nodes requested",
                  stat_iterator, peer));
+  GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
+                (sh, "experimentation", "# issuer",
+                 stat_iterator, peer));
+  GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
+                (sh, "experimentation", "# experiments",
+                 stat_iterator, peer));
 }
 
 /**
@@ -236,6 +329,12 @@ stat_disconnect_adapter (void *cls, void *op_result)
   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
                 (peer->sh, "experimentation", "# nodes requested",
                  stat_iterator, peer));
+  GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
+                (peer->sh, "experimentation", "# issuer",
+                 stat_iterator, peer));
+  GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
+                (peer->sh, "experimentation", "# experiments",
+                 stat_iterator, peer));
   GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
   peer->sh = NULL;
 }
@@ -286,10 +385,7 @@ test_master (void *cls, unsigned int num_peers,
                                                   /* NUM_PEERS, */
                                                   GNUNET_TESTBED_TOPOLOGY_OPTION_END);
   GNUNET_assert (NULL != op);
-  shutdown_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_SECONDS, 20),
-                                    do_shutdown, NULL);
+  shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, do_shutdown, NULL);
 }