finish implementing reservation test, and fix bandwidth reservation logic
authorChristian Grothoff <christian@grothoff.org>
Wed, 11 Feb 2015 18:44:19 +0000 (18:44 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 11 Feb 2015 18:44:19 +0000 (18:44 +0000)
src/ats/gnunet-service-ats_plugins.c
src/ats/gnunet-service-ats_reservations.c
src/ats/test_ats_lib.c
src/ats/test_ats_lib.h
src/ats/test_ats_reservation_api.c

index b0bbb910b9bd66938c0843a1870e610ceab93659..11f9c752caf10c852c726715492331239f07f71e 100644 (file)
@@ -30,6 +30,7 @@
 #include "gnunet-service-ats_performance.h"
 #include "gnunet-service-ats_preferences.h"
 #include "gnunet-service-ats_plugins.h"
+#include "gnunet-service-ats_reservations.h"
 #include "gnunet-service-ats_scheduling.h"
 #include "gnunet-service-ats_normalization.h"
 
@@ -207,7 +208,8 @@ bandwidth_changed_cb (void *cls,
               GNUNET_i2s (&address->peer),
               (unsigned int) address->assigned_bw_in,
               (unsigned int) address->assigned_bw_out);
-
+  GAS_reservations_set_bandwidth (&address->peer,
+                                  GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
   /* Notify performance clients about changes to address */
   GAS_performance_notify_all_clients (&address->peer,
                                      address->plugin,
index d1f80b762f251bb8765e60c86c1d33462f76751c..ba06f7634b86c8b22ad37486c225582c4d142c01 100644 (file)
@@ -29,7 +29,8 @@
 
 /**
  * Number of seconds that available bandwidth carries over
- * (can accumulate).
+ * (can accumulate).  Note that the
+ * test_ats_reservation_api test depends on this value!
  */
 #define MAX_BANDWIDTH_CARRY_S 5
 
@@ -117,7 +118,10 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
   if (NULL == tracker)
   {
     tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker);
-    GNUNET_BANDWIDTH_tracker_init (tracker, NULL, NULL, bandwidth_in,
+    GNUNET_BANDWIDTH_tracker_init (tracker,
+                                   NULL,
+                                   NULL,
+                                   bandwidth_in,
                                    MAX_BANDWIDTH_CARRY_S);
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CONTAINER_multipeermap_put (trackers,
index 9a972612450fac8936f21314e8a95dc1f4d1f9f7..590696ab2df3390583c6b46be3f2f10f907ccff2 100644 (file)
@@ -567,7 +567,7 @@ reservation_cb (void *cls,
                    (0 != res_delay.rel_value_us) );
     break;
   case GNUNET_SYSERR:
-    if ( (amount != cmd->details.reserve_bandwidth.amount) ||
+    if ( (amount != 0) ||
          (0 == res_delay.rel_value_us) )
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -858,6 +858,12 @@ interpreter (void *cls,
                                           cmd);
         return;
       }
+    case CMD_SLEEP:
+      off++;
+      interpreter_task = GNUNET_SCHEDULER_add_delayed (cmd->details.sleep.delay,
+                                                       &interpreter,
+                                                       NULL);
+      return;
     } /* end switch */
   } /* end while(1) */
 }
index 099fa9b45b4f7103c783b7d8f8b4dcd556febd34..975172f2fd4af5364bc3409adf319fa882d439d4 100644 (file)
@@ -117,7 +117,12 @@ enum CommandCode
    * Reserve bandwidth, testing
    * #GNUNET_ATS_reserve_bandwidth().
    */
-  CMD_RESERVE_BANDWIDTH
+  CMD_RESERVE_BANDWIDTH,
+
+  /**
+   * Wait for a bit.
+   */
+  CMD_SLEEP
 
 };
 
@@ -434,6 +439,18 @@ struct CommandReserveBandwidth
 };
 
 
+/**
+ * Details for the #CMD_SLEEP command.
+ */
+struct CommandSleep
+{
+  /**
+   * How long should we wait before running the next command?
+   */
+  struct GNUNET_TIME_Relative delay;
+};
+
+
 /**
  * A command for the test case interpreter.
  */
@@ -482,6 +499,8 @@ struct Command
 
     struct CommandReserveBandwidth reserve_bandwidth;
 
+    struct CommandSleep sleep;
+
   } details;
 
 };
index e45ffe2cc49739e78d300114ecd9fd996079469e..54aa74a59d160ed769bd14257f87ea395be53f8e 100644 (file)
@@ -19,7 +19,7 @@
 */
 /**
  * @file ats/test_ats_reservation_api.c
- * @brief test ATS
+ * @brief test ATS bandwidth reservation API
  * @author Christian Grothoff
  */
 #include "platform.h"
@@ -28,7 +28,7 @@
 /**
  * Global timeout for the testcase.
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 
 /**
  * Definition of the test as a sequence of commands.
@@ -63,36 +63,35 @@ static struct Command test_commands[] = {
       .add_label = "add-address-0-0"
     }
   },
-  /* 3: reserve 32k -- should work */
+  /* 3: sleep 7s, should give us 5s * 64k/s = 320k buffer;
+     Note that this depends on MAX_BANDWIDTH_CARRY_S.  We
+     sleep more than 5s to show that only MAX_BANDWIDTH carries. */
   {
-    .code = CMD_RESERVE_BANDWIDTH,
-    .label = "initial reservation",
-    .details.reserve_bandwidth = {
-      .pid = 0,
-      .amount = 32 * 1024,
-      .expected_result = GNUNET_OK
-    }
+    .code = CMD_SLEEP,
+    .label = "sleep",
+    .details.sleep.delay = { 7 * 1000LL * 1000LL }
   },
-  /* 4: reserve another 32k -- might work */
+  /* 4: reserve 128k -- should work (5s carry, so we had 320k) */
   {
     .code = CMD_RESERVE_BANDWIDTH,
     .details.reserve_bandwidth = {
       .pid = 0,
-      .amount = 32 * 1024,
-      .expected_result = GNUNET_NO
+      .amount = 128 * 1024,
+      .expected_result = GNUNET_YES
     }
   },
-  /* 5: reserve another 128k -- might work */
+  /* 5: reserve another 192k -- should just work (now exactly pushing the limit) */
   {
     .code = CMD_RESERVE_BANDWIDTH,
     .label = "big reservation",
     .details.reserve_bandwidth = {
       .pid = 0,
-      .amount = 128 * 1024,
-      .expected_result = GNUNET_NO
+      .amount = 192 * 1024,
+      .expected_result = GNUNET_YES
     }
   },
-  /* 6: reserve another 32k -- should now fail */
+  /* 6: reserve another 32k -- should now fail (if MAX_BANDWIDTH_CARRY_S
+     is precisely observed) */
   {
     .code = CMD_RESERVE_BANDWIDTH,
     .label = "failing reservation",
@@ -102,21 +101,37 @@ static struct Command test_commands[] = {
       .expected_result = GNUNET_SYSERR
     }
   },
-  /* 7: remove address */
+  /* 7: sleep 3s, should give us 3s * 64k/s - 32k = 160k buffer */
+  {
+    .code = CMD_SLEEP,
+    .label = "sleep",
+    .details.sleep.delay = { 6 * 1000LL * 1000LL }
+  },
+  /* 8: reserve another 160k -- should now work */
+  {
+    .code = CMD_RESERVE_BANDWIDTH,
+    .label = "successful final reservation",
+    .details.reserve_bandwidth = {
+      .pid = 0,
+      .amount = 160 * 1024,
+      .expected_result = GNUNET_YES
+    }
+  },
+  /* 9: remove address */
   {
     .code = CMD_DEL_ADDRESS,
     .details.del_address = {
       .add_label = "add-address-0-0"
     }
   },
-  /* 8: check we got disconnected */
+  /* 10: check we got disconnected */
   {
     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
     .details.await_disconnect_suggestion = {
       .pid = 0
     }
   },
-  /* 9: just for symmetry, also stop asking for the connection */
+  /* 11: just for symmetry, also stop asking for the connection */
   {
     .code = CMD_REQUEST_CONNECTION_STOP,
     .details.request_connection_stop = {