aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ats/gnunet-service-ats_plugins.c4
-rw-r--r--src/ats/gnunet-service-ats_reservations.c8
-rw-r--r--src/ats/test_ats_lib.c8
-rw-r--r--src/ats/test_ats_lib.h21
-rw-r--r--src/ats/test_ats_reservation_api.c55
5 files changed, 71 insertions, 25 deletions
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 @@
30#include "gnunet-service-ats_performance.h" 30#include "gnunet-service-ats_performance.h"
31#include "gnunet-service-ats_preferences.h" 31#include "gnunet-service-ats_preferences.h"
32#include "gnunet-service-ats_plugins.h" 32#include "gnunet-service-ats_plugins.h"
33#include "gnunet-service-ats_reservations.h"
33#include "gnunet-service-ats_scheduling.h" 34#include "gnunet-service-ats_scheduling.h"
34#include "gnunet-service-ats_normalization.h" 35#include "gnunet-service-ats_normalization.h"
35 36
@@ -207,7 +208,8 @@ bandwidth_changed_cb (void *cls,
207 GNUNET_i2s (&address->peer), 208 GNUNET_i2s (&address->peer),
208 (unsigned int) address->assigned_bw_in, 209 (unsigned int) address->assigned_bw_in,
209 (unsigned int) address->assigned_bw_out); 210 (unsigned int) address->assigned_bw_out);
210 211 GAS_reservations_set_bandwidth (&address->peer,
212 GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
211 /* Notify performance clients about changes to address */ 213 /* Notify performance clients about changes to address */
212 GAS_performance_notify_all_clients (&address->peer, 214 GAS_performance_notify_all_clients (&address->peer,
213 address->plugin, 215 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 @@
29 29
30/** 30/**
31 * Number of seconds that available bandwidth carries over 31 * Number of seconds that available bandwidth carries over
32 * (can accumulate). 32 * (can accumulate). Note that the
33 * test_ats_reservation_api test depends on this value!
33 */ 34 */
34#define MAX_BANDWIDTH_CARRY_S 5 35#define MAX_BANDWIDTH_CARRY_S 5
35 36
@@ -117,7 +118,10 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
117 if (NULL == tracker) 118 if (NULL == tracker)
118 { 119 {
119 tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker); 120 tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker);
120 GNUNET_BANDWIDTH_tracker_init (tracker, NULL, NULL, bandwidth_in, 121 GNUNET_BANDWIDTH_tracker_init (tracker,
122 NULL,
123 NULL,
124 bandwidth_in,
121 MAX_BANDWIDTH_CARRY_S); 125 MAX_BANDWIDTH_CARRY_S);
122 GNUNET_assert (GNUNET_OK == 126 GNUNET_assert (GNUNET_OK ==
123 GNUNET_CONTAINER_multipeermap_put (trackers, 127 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,
567 (0 != res_delay.rel_value_us) ); 567 (0 != res_delay.rel_value_us) );
568 break; 568 break;
569 case GNUNET_SYSERR: 569 case GNUNET_SYSERR:
570 if ( (amount != cmd->details.reserve_bandwidth.amount) || 570 if ( (amount != 0) ||
571 (0 == res_delay.rel_value_us) ) 571 (0 == res_delay.rel_value_us) )
572 { 572 {
573 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 573 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -858,6 +858,12 @@ interpreter (void *cls,
858 cmd); 858 cmd);
859 return; 859 return;
860 } 860 }
861 case CMD_SLEEP:
862 off++;
863 interpreter_task = GNUNET_SCHEDULER_add_delayed (cmd->details.sleep.delay,
864 &interpreter,
865 NULL);
866 return;
861 } /* end switch */ 867 } /* end switch */
862 } /* end while(1) */ 868 } /* end while(1) */
863} 869}
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
117 * Reserve bandwidth, testing 117 * Reserve bandwidth, testing
118 * #GNUNET_ATS_reserve_bandwidth(). 118 * #GNUNET_ATS_reserve_bandwidth().
119 */ 119 */
120 CMD_RESERVE_BANDWIDTH 120 CMD_RESERVE_BANDWIDTH,
121
122 /**
123 * Wait for a bit.
124 */
125 CMD_SLEEP
121 126
122}; 127};
123 128
@@ -435,6 +440,18 @@ struct CommandReserveBandwidth
435 440
436 441
437/** 442/**
443 * Details for the #CMD_SLEEP command.
444 */
445struct CommandSleep
446{
447 /**
448 * How long should we wait before running the next command?
449 */
450 struct GNUNET_TIME_Relative delay;
451};
452
453
454/**
438 * A command for the test case interpreter. 455 * A command for the test case interpreter.
439 */ 456 */
440struct Command 457struct Command
@@ -482,6 +499,8 @@ struct Command
482 499
483 struct CommandReserveBandwidth reserve_bandwidth; 500 struct CommandReserveBandwidth reserve_bandwidth;
484 501
502 struct CommandSleep sleep;
503
485 } details; 504 } details;
486 505
487}; 506};
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 @@
19*/ 19*/
20/** 20/**
21 * @file ats/test_ats_reservation_api.c 21 * @file ats/test_ats_reservation_api.c
22 * @brief test ATS 22 * @brief test ATS bandwidth reservation API
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
@@ -28,7 +28,7 @@
28/** 28/**
29 * Global timeout for the testcase. 29 * Global timeout for the testcase.
30 */ 30 */
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
32 32
33/** 33/**
34 * Definition of the test as a sequence of commands. 34 * Definition of the test as a sequence of commands.
@@ -63,36 +63,35 @@ static struct Command test_commands[] = {
63 .add_label = "add-address-0-0" 63 .add_label = "add-address-0-0"
64 } 64 }
65 }, 65 },
66 /* 3: reserve 32k -- should work */ 66 /* 3: sleep 7s, should give us 5s * 64k/s = 320k buffer;
67 Note that this depends on MAX_BANDWIDTH_CARRY_S. We
68 sleep more than 5s to show that only MAX_BANDWIDTH carries. */
67 { 69 {
68 .code = CMD_RESERVE_BANDWIDTH, 70 .code = CMD_SLEEP,
69 .label = "initial reservation", 71 .label = "sleep",
70 .details.reserve_bandwidth = { 72 .details.sleep.delay = { 7 * 1000LL * 1000LL }
71 .pid = 0,
72 .amount = 32 * 1024,
73 .expected_result = GNUNET_OK
74 }
75 }, 73 },
76 /* 4: reserve another 32k -- might work */ 74 /* 4: reserve 128k -- should work (5s carry, so we had 320k) */
77 { 75 {
78 .code = CMD_RESERVE_BANDWIDTH, 76 .code = CMD_RESERVE_BANDWIDTH,
79 .details.reserve_bandwidth = { 77 .details.reserve_bandwidth = {
80 .pid = 0, 78 .pid = 0,
81 .amount = 32 * 1024, 79 .amount = 128 * 1024,
82 .expected_result = GNUNET_NO 80 .expected_result = GNUNET_YES
83 } 81 }
84 }, 82 },
85 /* 5: reserve another 128k -- might work */ 83 /* 5: reserve another 192k -- should just work (now exactly pushing the limit) */
86 { 84 {
87 .code = CMD_RESERVE_BANDWIDTH, 85 .code = CMD_RESERVE_BANDWIDTH,
88 .label = "big reservation", 86 .label = "big reservation",
89 .details.reserve_bandwidth = { 87 .details.reserve_bandwidth = {
90 .pid = 0, 88 .pid = 0,
91 .amount = 128 * 1024, 89 .amount = 192 * 1024,
92 .expected_result = GNUNET_NO 90 .expected_result = GNUNET_YES
93 } 91 }
94 }, 92 },
95 /* 6: reserve another 32k -- should now fail */ 93 /* 6: reserve another 32k -- should now fail (if MAX_BANDWIDTH_CARRY_S
94 is precisely observed) */
96 { 95 {
97 .code = CMD_RESERVE_BANDWIDTH, 96 .code = CMD_RESERVE_BANDWIDTH,
98 .label = "failing reservation", 97 .label = "failing reservation",
@@ -102,21 +101,37 @@ static struct Command test_commands[] = {
102 .expected_result = GNUNET_SYSERR 101 .expected_result = GNUNET_SYSERR
103 } 102 }
104 }, 103 },
105 /* 7: remove address */ 104 /* 7: sleep 3s, should give us 3s * 64k/s - 32k = 160k buffer */
105 {
106 .code = CMD_SLEEP,
107 .label = "sleep",
108 .details.sleep.delay = { 6 * 1000LL * 1000LL }
109 },
110 /* 8: reserve another 160k -- should now work */
111 {
112 .code = CMD_RESERVE_BANDWIDTH,
113 .label = "successful final reservation",
114 .details.reserve_bandwidth = {
115 .pid = 0,
116 .amount = 160 * 1024,
117 .expected_result = GNUNET_YES
118 }
119 },
120 /* 9: remove address */
106 { 121 {
107 .code = CMD_DEL_ADDRESS, 122 .code = CMD_DEL_ADDRESS,
108 .details.del_address = { 123 .details.del_address = {
109 .add_label = "add-address-0-0" 124 .add_label = "add-address-0-0"
110 } 125 }
111 }, 126 },
112 /* 8: check we got disconnected */ 127 /* 10: check we got disconnected */
113 { 128 {
114 .code = CMD_AWAIT_DISCONNECT_SUGGESTION, 129 .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
115 .details.await_disconnect_suggestion = { 130 .details.await_disconnect_suggestion = {
116 .pid = 0 131 .pid = 0
117 } 132 }
118 }, 133 },
119 /* 9: just for symmetry, also stop asking for the connection */ 134 /* 11: just for symmetry, also stop asking for the connection */
120 { 135 {
121 .code = CMD_REQUEST_CONNECTION_STOP, 136 .code = CMD_REQUEST_CONNECTION_STOP,
122 .details.request_connection_stop = { 137 .details.request_connection_stop = {