aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-11-03 17:30:50 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-11-03 17:30:50 +0000
commit261274f4c1081bee8b2b77a8efe8423e1e0c9a3b (patch)
tree462a00b5a4449df02ef13f5b8064c47bb139ffb2
parent0283d45a7318a2ac34a75b65793e934ca37a912b (diff)
downloadgnunet-261274f4c1081bee8b2b77a8efe8423e1e0c9a3b.tar.gz
gnunet-261274f4c1081bee8b2b77a8efe8423e1e0c9a3b.zip
limiting send rate
-rw-r--r--src/core/test_core_quota_compliance.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 3546e542c..9bc0e9e38 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -50,7 +50,7 @@
50#define MEASUREMENT_MSG_SIZE 1024 50#define MEASUREMENT_MSG_SIZE 1024
51#define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024 51#define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024
52#define MEASUREMENT_MIN_QUOTA 1024 52#define MEASUREMENT_MIN_QUOTA 1024
53#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 8) 53#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
54 54
55/** 55/**
56 * How long until we give up on transmitting the message? 56 * How long until we give up on transmitting the message?
@@ -75,9 +75,16 @@ static unsigned long long current_quota_p2_out;
75 75
76static unsigned long long total_bytes; 76static unsigned long long total_bytes;
77static unsigned long long total_bytes_sent; 77static unsigned long long total_bytes_sent;
78static unsigned long long total_bytes_recv;
78 79
79static struct GNUNET_TIME_Absolute start_time; 80static struct GNUNET_TIME_Absolute start_time;
80 81
82static GNUNET_SCHEDULER_TaskIdentifier err_task;
83
84static GNUNET_SCHEDULER_TaskIdentifier send_task;
85
86static GNUNET_SCHEDULER_TaskIdentifier measure_task;
87
81struct PeerContext 88struct PeerContext
82{ 89{
83 struct GNUNET_CONFIGURATION_Handle *cfg; 90 struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -136,6 +143,8 @@ static void
136terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 143terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
137{ 144{
138 GNUNET_break (0); 145 GNUNET_break (0);
146 if (send_task != GNUNET_SCHEDULER_NO_TASK)
147 GNUNET_SCHEDULER_cancel (sched,send_task);
139 GNUNET_CORE_disconnect (p1.ch); 148 GNUNET_CORE_disconnect (p1.ch);
140 p1.ch = NULL; 149 p1.ch = NULL;
141 GNUNET_CORE_disconnect (p2.ch); 150 GNUNET_CORE_disconnect (p2.ch);
@@ -184,10 +193,11 @@ inbound_notify (void *cls,
184 struct GNUNET_TIME_Relative latency, 193 struct GNUNET_TIME_Relative latency,
185 uint32_t distance) 194 uint32_t distance)
186{ 195{
187#if DEBUG_CONNECTIONS 196 total_bytes_recv += ntohs (message->size);
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); 198 "Core provides inbound data from `%4s' size %u.\n", GNUNET_i2s (other), ntohs (message->size));
190#endif 199#if DEBUG_CONNECTIONS
200 #endif
191 return GNUNET_OK; 201 return GNUNET_OK;
192} 202}
193 203
@@ -207,12 +217,6 @@ outbound_notify (void *cls,
207 return GNUNET_OK; 217 return GNUNET_OK;
208} 218}
209 219
210
211static GNUNET_SCHEDULER_TaskIdentifier err_task;
212
213static GNUNET_SCHEDULER_TaskIdentifier measure_task;
214
215
216static void 220static void
217measurement_end (void *cls, 221measurement_end (void *cls,
218 const struct GNUNET_SCHEDULER_TaskContext *tc) 222 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -227,23 +231,40 @@ measurement_end (void *cls,
227 duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get()); 231 duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
228 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 232 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
229 "\nQuota compliance: \n"\ 233 "\nQuota compliance: \n"\
230 "Throughput : %10llu kB/s\n"\ 234 "Received %llu \n"
231 "Quota : %10llu kB/s\n", (total_bytes_sent/(duration.rel_value / 1000)/1024),current_quota_p1_in/1024); 235 "Throughput: %10llu kB/s\n"\
236 "Quota : %10llu kB/s\n",
237 total_bytes_recv,
238 (total_bytes_sent/(duration.rel_value / 1000)/1024),current_quota_p1_in/1024);
232 239
233 if (err_task != GNUNET_SCHEDULER_NO_TASK) 240 if (err_task != GNUNET_SCHEDULER_NO_TASK)
234 GNUNET_SCHEDULER_cancel (sched, err_task); 241 GNUNET_SCHEDULER_cancel (sched, err_task);
242 if (send_task != GNUNET_SCHEDULER_NO_TASK)
243 GNUNET_SCHEDULER_cancel (sched,send_task);
235 GNUNET_SCHEDULER_add_now (sched, &terminate_task, NULL); 244 GNUNET_SCHEDULER_add_now (sched, &terminate_task, NULL);
236} 245}
237 246
238static size_t 247static size_t
239transmit_ready (void *cls, size_t size, void *buf); 248transmit_ready (void *cls, size_t size, void *buf);
240 249
250static void
251send_tsk (void *cls,
252 const struct GNUNET_SCHEDULER_TaskContext *tc)
253{
254 ch = GNUNET_CORE_notify_transmit_ready (p1.ch,
255 0,
256 FAST_TIMEOUT,
257 &p2.id,
258 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
259 &transmit_ready, &p1);
260}
261
241static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) 262static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
242{ 263{
243#if VERBOSE 264#if VERBOSE
244 if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES)) 265 if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES))
245 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 266 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
246 "Starting core level measurement for %u seconds, receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p1_in / 1024, current_quota_p2_out / 1024); 267 "Starting core level measurement for %u seconds receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p1_in / 1024, current_quota_p2_out / 1024);
247 else 268 else
248 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 269 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
249 "Starting core level measurement for %u seconds, symmetric quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p2_out / 1024); 270 "Starting core level measurement for %u seconds, symmetric quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p2_out / 1024);
@@ -375,13 +396,8 @@ transmit_ready (void *cls, size_t size, void *buf)
375 396
376 total_bytes += ret; 397 total_bytes += ret;
377 total_bytes_sent += ret; 398 total_bytes_sent += ret;
399 send_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500), &send_tsk, NULL);
378 400
379 ch = GNUNET_CORE_notify_transmit_ready (p1.ch,
380 0,
381 FAST_TIMEOUT,
382 &p2.id,
383 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
384 &transmit_ready, &p1);
385 return ret; 401 return ret;
386} 402}
387 403