From 72002c196893a932c5f3bcdde818581a6209d4c9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 11 Feb 2015 18:44:19 +0000 Subject: finish implementing reservation test, and fix bandwidth reservation logic --- src/ats/gnunet-service-ats_plugins.c | 4 ++- src/ats/gnunet-service-ats_reservations.c | 8 +++-- src/ats/test_ats_lib.c | 8 ++++- src/ats/test_ats_lib.h | 21 +++++++++++- src/ats/test_ats_reservation_api.c | 55 ++++++++++++++++++++----------- 5 files changed, 71 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c index b0bbb910b..11f9c752c 100644 --- a/src/ats/gnunet-service-ats_plugins.c +++ b/src/ats/gnunet-service-ats_plugins.c @@ -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, diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c index d1f80b762..ba06f7634 100644 --- a/src/ats/gnunet-service-ats_reservations.c +++ b/src/ats/gnunet-service-ats_reservations.c @@ -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, diff --git a/src/ats/test_ats_lib.c b/src/ats/test_ats_lib.c index 9a9726124..590696ab2 100644 --- a/src/ats/test_ats_lib.c +++ b/src/ats/test_ats_lib.c @@ -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) */ } diff --git a/src/ats/test_ats_lib.h b/src/ats/test_ats_lib.h index 099fa9b45..975172f2f 100644 --- a/src/ats/test_ats_lib.h +++ b/src/ats/test_ats_lib.h @@ -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; }; diff --git a/src/ats/test_ats_reservation_api.c b/src/ats/test_ats_reservation_api.c index e45ffe2cc..54aa74a59 100644 --- a/src/ats/test_ats_reservation_api.c +++ b/src/ats/test_ats_reservation_api.c @@ -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 = { -- cgit v1.2.3