better test for comms
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Wed, 25 Dec 2019 10:39:20 +0000 (19:39 +0900)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Wed, 25 Dec 2019 10:39:20 +0000 (19:39 +0900)
src/transport/test_communicator_basic.c
src/transport/test_communicator_unix_peer1.conf
src/transport/test_communicator_unix_peer2.conf
src/transport/test_transport_defaults.conf

index ef91e133dfe6702c29ed7099762035ce16cc9da0..7ae50be050b275834c6d14fbdd3045a8f645c950 100644 (file)
 
 #define NUM_PEERS 2
 
+static struct GNUNET_SCHEDULER_Task *to_task;
+
+static int queue_est = GNUNET_NO;
+
 static struct GNUNET_PeerIdentity peer_id[NUM_PEERS];
 
 static char *communicator_binary;
@@ -124,12 +128,16 @@ add_address_cb (void *cls,
        aid,
        nt);
   // addresses[1] = GNUNET_strdup (address);
-  if (0 == strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1]))
+  if ((0 == strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) &&
+      (GNUNET_NO == queue_est))
+  {
+    queue_est = GNUNET_YES;
     GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0],
                                                                 &peer_id[
                                                                   NUM_PEERS
                                                                   - 1],
                                                                 address);
+  }
 }
 
 
@@ -175,6 +183,18 @@ make_payload (size_t payload_size)
 }
 
 
+static void
+latency_timeout (void *cls)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Latency too high. Test failed. (Phase: %d. Received: %lu\n",
+              phase, num_received);
+  ret = 2;
+  to_task = NULL;
+  GNUNET_SCHEDULER_shutdown ();
+}
+
+
 static void
 size_test (void *cls)
 {
@@ -190,24 +210,13 @@ size_test (void *cls)
     GNUNET_free (payload);
     ack += 5;
     num_sent++;
+    if (NULL == to_task)
+      to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                              &latency_timeout,
+                                              NULL);
     if (ack < 64000)
       GNUNET_SCHEDULER_add_now (&size_test, NULL);
-    else
-      GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW,
-                                    &size_test, NULL);
-    return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-              "Size packet test done.\n");
-  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-              "%lu/%lu packets -- avg latency: %lu us\n",
-              num_received,
-              num_sent,
-              avg_latency);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Finished\n");
-  GNUNET_SCHEDULER_shutdown ();
-  // Finished!
 }
 
 
@@ -223,27 +232,17 @@ long_test (void *cls)
                                                           LONG_MESSAGE_SIZE);
     num_sent++;
     GNUNET_free (payload);
-    if (num_sent < BURST_PACKETS)
-      GNUNET_SCHEDULER_add_now (&long_test, NULL);
-    if (num_sent == BURST_PACKETS)
-      GNUNET_SCHEDULER_add_delayed (LONG_BURST_WINDOW,
-                                    &long_test, NULL);
+    if (NULL == to_task)
+      to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                              &latency_timeout,
+                                              NULL);
+
+    GNUNET_SCHEDULER_add_now (&long_test, NULL);
+    //if (num_sent == BURST_PACKETS)
+    //  GNUNET_SCHEDULER_add_delayed (LONG_BURST_WINDOW,
+    //                                &long_test, NULL);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-              "Long size packet test done.\n");
-  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-              "%lu/%lu packets in %lu us (%lu kb/s) -- avg latency: %lu us\n",
-              num_received,
-              num_sent,
-              duration.rel_value_us,
-              (LONG_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000),
-              avg_latency);
-  ack = 10;
-  num_received = 0;
-  num_sent = 0;
-  avg_latency = 0;
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &size_test, NULL);
 }
 
 
@@ -251,7 +250,7 @@ static void
 short_test (void *cls)
 {
   char *payload;
-  while (num_sent < BURST_PACKETS)
+  if (num_sent < BURST_PACKETS)
   {
     payload = make_payload (SHORT_MESSAGE_SIZE);
     GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
@@ -259,33 +258,23 @@ short_test (void *cls)
                                                           SHORT_MESSAGE_SIZE);
     num_sent++;
     GNUNET_free (payload);
-    //if (num_sent < BURST_PACKETS)
-    //  GNUNET_SCHEDULER_add_now (&short_test, NULL);
-    if (num_sent == BURST_PACKETS)
+    if (NULL == to_task)
+      to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                              &latency_timeout,
+                                              NULL);
+
+    GNUNET_SCHEDULER_add_now (&short_test, NULL);
+    /*if (num_sent == BURST_PACKETS)
     {
       GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW,
                                     &short_test, NULL);
       return;
-    }
+    }*/
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-              "Short size packet test done.\n");
-  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-              "%lu/%lu packets in %lu us (%lu kb/s) -- avg latency: %lu us\n",
-              num_received,
-              num_sent,
-              duration.rel_value_us,
-              (SHORT_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000),
-              avg_latency);
-  start_long = GNUNET_TIME_absolute_get ();
-  phase = BURST_LONG;
-  num_sent = 0;
-  avg_latency = 0;
-  num_received = 0;
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test, NULL);
 }
 
 
+
 /**
  * @brief Handle opening of queue
  *
@@ -361,6 +350,28 @@ incoming_message_cb (void *cls,
     num_received++;
     duration = GNUNET_TIME_absolute_get_duration (start_short);
     update_avg_latency (payload);
+    if (num_received == BURST_PACKETS)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+                  "Short size packet test done.\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+                  "%lu/%lu packets in %llu us (%llu kb/s) -- avg latency: %llu us\n",
+                  num_received,
+                  num_sent,
+                  duration.rel_value_us,
+                  (SHORT_MESSAGE_SIZE * num_received) / (duration.rel_value_us
+                                                         / 1000),
+                  avg_latency);
+      start_long = GNUNET_TIME_absolute_get ();
+      phase = BURST_LONG;
+      num_sent = 0;
+      avg_latency = 0;
+      num_received = 0;
+      GNUNET_SCHEDULER_cancel (to_task);
+      to_task = NULL;
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test, NULL);
+    }
+
   }
   else if (phase == BURST_LONG)
   {
@@ -373,11 +384,58 @@ incoming_message_cb (void *cls,
     num_received++;
     duration = GNUNET_TIME_absolute_get_duration (start_long);
     update_avg_latency (payload);
+    if (num_received == BURST_PACKETS)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+                  "Long size packet test done.\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+                  "%lu/%lu packets in %llu us (%llu kb/s) -- avg latency: %llu us\n",
+                  num_received,
+                  num_sent,
+                  duration.rel_value_us,
+                  (LONG_MESSAGE_SIZE * num_received) / (duration.rel_value_us
+                                                        / 1000),
+                  avg_latency);
+      ack = 10;
+      phase = SIZE_CHECK;
+      num_received = 0;
+      num_sent = 0;
+      avg_latency = 0;
+      GNUNET_SCHEDULER_cancel (to_task);
+      to_task = NULL;
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &size_test, NULL);
+
+    }
   }
   else         // if (phase == SIZE_CHECK) {
   {
     num_received++;
     update_avg_latency (payload);
+    if (num_received >= (64000 - 10) / 5)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+                  "Size packet test done.\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+                  "%lu/%lu packets -- avg latency: %llu us\n",
+                  num_received,
+                  num_sent,
+                  avg_latency);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Finished\n");
+      GNUNET_SCHEDULER_cancel (to_task);
+      to_task = NULL;
+      GNUNET_SCHEDULER_shutdown ();
+      // Finished!
+      // }
+    }
+  }
+  // Reset timeout
+  if (to_task != NULL)
+  {
+    GNUNET_SCHEDULER_cancel (to_task);
+    to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                            &latency_timeout,
+                                            NULL);
   }
 }
 
@@ -404,7 +462,7 @@ run (void *cls)
       &queue_create_reply_cb,
       &add_queue_cb,
       &incoming_message_cb,
-      cfg_peers_name[i]); /* cls */
+      cfg_peers_name[i]);   /* cls */
   }
 }
 
index 411b7f5870b0175655f3e1f92120166ef0b44b95..d5058800713054359811107099ae7a4fd794b713 100644 (file)
@@ -17,11 +17,11 @@ PORT = 60000
 UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-transport_test_1.sock
 
 [nat]
-UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/nat.sock
+UNIXPATH = $GNUNET_TMP/communicator-unix-1/nat.sock
 ENABLE_IPSCAN = YES
 
 [communicator-unix]
-UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock
+UNIXPATH = $GNUNET_RUNTIME_DIR/communicator-unix-1.sock
 
 [communicator-tcp]
 BINDTO = 60002
index d06ef0d1e61ba635509718b62b2b627577fc2d1d..fe27ef1a690150ff1f5125b62407d8fdc634406d 100644 (file)
@@ -18,10 +18,10 @@ PORT = 60001
 UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-transport_test_2.sock
 
 [nat]
-UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/nat.sock
+UNIXPATH = $GNUNET_TMP/communicator-unix-2/nat.sock
 
 [communicator-unix]
-UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock
+UNIXPATH = $GNUNET_RUNTIME_DIR/communicator-unix-2.sock
 
 [communicator-tcp]
 BINDTO = 60003
index 3f38eeab73b79ac62772b52982b09c75eada9e30..3aed73f0ca0d71c78fb0500f45c4c231bb2cd0e6 100644 (file)
@@ -1,7 +1,7 @@
 @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf
 
 [PATHS]
-GNUNET_TEST_HOME = $GNUNET_TMP/test-transport-api/
+GNUNET_TEST_HOME = $GNUNET_TMP/test-tng/
 
 [transport-tcp]
 TIMEOUT = 300 s