aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-11-02 17:09:24 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-11-02 17:09:24 +0000
commit2e29eebbea91c5fd93a4dd751d10b3a91ce4f775 (patch)
treee0353aa7c597a4f3b7294040bf9eaafb9a6842d0
parent53caaccac28ba77aa6fd870da74ab95f218cc36c (diff)
downloadgnunet-2e29eebbea91c5fd93a4dd751d10b3a91ce4f775.tar.gz
gnunet-2e29eebbea91c5fd93a4dd751d10b3a91ce4f775.zip
-rw-r--r--src/core/test_core_quota_compliance.c110
1 files changed, 65 insertions, 45 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index a67f5b1bb..f662b19e0 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -65,8 +65,13 @@
65 65
66#define MTYPE 12345 66#define MTYPE 12345
67 67
68static int is_asymmetric_send_constant;
69static int is_asymmetric_recv_constant;
70static unsigned long long current_quota_p1;
71static unsigned long long current_quota_p2;
68 72
69static unsigned long long total_bytes; 73static unsigned long long total_bytes;
74static unsigned long long total_bytes_sent;
70 75
71static struct GNUNET_TIME_Absolute start_time; 76static struct GNUNET_TIME_Absolute start_time;
72 77
@@ -106,14 +111,6 @@ struct TestMessage
106 uint32_t num; 111 uint32_t num;
107}; 112};
108 113
109
110static unsigned int
111get_size (unsigned int iter)
112{
113 return sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE;
114}
115
116
117static void 114static void
118terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 115terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119{ 116{
@@ -128,9 +125,6 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
128 GNUNET_TRANSPORT_disconnect (p2.th); 125 GNUNET_TRANSPORT_disconnect (p2.th);
129 p2.th = NULL; 126 p2.th = NULL;
130 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 127 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
131 fprintf (stderr,
132 "\nThroughput was %llu kb/s\n",
133 total_bytes * 1000 / 1024 / delta);
134 ok = 0; 128 ok = 0;
135} 129}
136 130
@@ -183,7 +177,7 @@ inbound_notify (void *cls,
183 struct GNUNET_TIME_Relative latency, 177 struct GNUNET_TIME_Relative latency,
184 uint32_t distance) 178 uint32_t distance)
185{ 179{
186#if VERBOSE 180#if DEBUG_CONNECTIONS
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); 182 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other));
189#endif 183#endif
@@ -198,7 +192,7 @@ outbound_notify (void *cls,
198 struct GNUNET_TIME_Relative latency, 192 struct GNUNET_TIME_Relative latency,
199 uint32_t distance) 193 uint32_t distance)
200{ 194{
201#if VERBOSE 195#if DEBUG_CONNECTIONS
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Core notifies about outbound data for `%4s'.\n", 197 "Core notifies about outbound data for `%4s'.\n",
204 GNUNET_i2s (other)); 198 GNUNET_i2s (other));
@@ -216,12 +210,22 @@ static void
216measurement_end (void *cls, 210measurement_end (void *cls,
217 const struct GNUNET_SCHEDULER_TaskContext *tc) 211 const struct GNUNET_SCHEDULER_TaskContext *tc)
218{ 212{
213 struct GNUNET_TIME_Relative duration;
214
219 measure_task = GNUNET_SCHEDULER_NO_TASK; 215 measure_task = GNUNET_SCHEDULER_NO_TASK;
220 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 216 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
221 return; 217 return;
222 measurement_running = GNUNET_NO; 218 measurement_running = GNUNET_NO;
219
220 duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
221
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "TIMEOUT\n"); 223 "TIMEOUT\n");
224
225 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
226 "\nQuota compliance: \n"\
227 "Throughput : %10llu kB/s\n", (total_bytes_sent/(duration.rel_value / 1000)/1024));
228
225 if (err_task != GNUNET_SCHEDULER_NO_TASK) 229 if (err_task != GNUNET_SCHEDULER_NO_TASK)
226 GNUNET_SCHEDULER_cancel (sched, err_task); 230 GNUNET_SCHEDULER_cancel (sched, err_task);
227 GNUNET_SCHEDULER_add_now (sched, &terminate_task, NULL); 231 GNUNET_SCHEDULER_add_now (sched, &terminate_task, NULL);
@@ -230,6 +234,42 @@ measurement_end (void *cls,
230static size_t 234static size_t
231transmit_ready (void *cls, size_t size, void *buf); 235transmit_ready (void *cls, size_t size, void *buf);
232 236
237static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
238{
239#if VERBOSE
240 if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES))
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Starting transport 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 / 1024, current_quota_p2 / 1024);
243 else
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p2 / 1024);
246
247#endif
248
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
250 "Asking core (1) for transmission to peer `%4s'\n",
251 GNUNET_i2s (&p2.id));
252 err_task =
253 GNUNET_SCHEDULER_add_delayed (sched,
254 TIMEOUT,
255 &terminate_task_error,
256 NULL);
257 measure_task = GNUNET_SCHEDULER_add_delayed (sched,
258 MEASUREMENT_INTERVALL,
259 &measurement_end,
260 NULL);
261 start_time = GNUNET_TIME_absolute_get ();
262 measurement_running = GNUNET_YES;
263 GNUNET_break (NULL !=
264 GNUNET_CORE_notify_transmit_ready (p1.ch,
265 0,
266 TIMEOUT,
267 &p2.id,
268 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
269 &transmit_ready, &p1));
270
271}
272
233static int tr_n; 273static int tr_n;
234 274
235 275
@@ -245,11 +285,11 @@ process_mtype (void *cls,
245 const struct TestMessage *hdr; 285 const struct TestMessage *hdr;
246 286
247 hdr = (const struct TestMessage*) message; 287 hdr = (const struct TestMessage*) message;
248 s = get_size (n); 288 s = sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE;
249 if (MTYPE != ntohs (message->type)) 289 if (MTYPE != ntohs (message->type))
250 return GNUNET_SYSERR; 290 return GNUNET_SYSERR;
251 291
252#if VERBOSE 292#if DEBUG_CONNECTIONS
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "Got message %u of size %u\n", 294 "Got message %u of size %u\n",
255 ntohl (hdr->num), 295 ntohl (hdr->num),
@@ -289,7 +329,7 @@ transmit_ready (void *cls, size_t size, void *buf)
289 0, 329 0,
290 FAST_TIMEOUT, 330 FAST_TIMEOUT,
291 &p2.id, 331 &p2.id,
292 get_size(tr_n), 332 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
293 &transmit_ready, &p1); 333 &transmit_ready, &p1);
294 GNUNET_break (NULL != ch); 334 GNUNET_break (NULL != ch);
295 } 335 }
@@ -297,13 +337,14 @@ transmit_ready (void *cls, size_t size, void *buf)
297 } 337 }
298 ret = 0; 338 ret = 0;
299 ch = NULL; 339 ch = NULL;
300 s = get_size (tr_n); 340 s = sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE;
341
301 GNUNET_assert (size >= s); 342 GNUNET_assert (size >= s);
302 GNUNET_assert (buf != NULL); 343 GNUNET_assert (buf != NULL);
303 cbuf = buf; 344 cbuf = buf;
304 do 345 do
305 { 346 {
306#if VERBOSE 347#if DEBUG_CONNECTIONS
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "Sending message %u of size %u at offset %u\n", 349 "Sending message %u of size %u at offset %u\n",
309 tr_n, 350 tr_n,
@@ -318,7 +359,6 @@ transmit_ready (void *cls, size_t size, void *buf)
318 memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage)); 359 memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
319 ret += s - sizeof (struct TestMessage); 360 ret += s - sizeof (struct TestMessage);
320 tr_n++; 361 tr_n++;
321 s = get_size (tr_n);
322 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) 362 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
323 break; /* sometimes pack buffer full, sometimes not */ 363 break; /* sometimes pack buffer full, sometimes not */
324 } 364 }
@@ -328,16 +368,15 @@ transmit_ready (void *cls, size_t size, void *buf)
328 TIMEOUT, 368 TIMEOUT,
329 &terminate_task_error, 369 &terminate_task_error,
330 NULL); 370 NULL);
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 371
332 "Returning total message block of size %u\n",
333 ret);
334 total_bytes += ret; 372 total_bytes += ret;
373 total_bytes_sent += ret;
335 374
336 ch = GNUNET_CORE_notify_transmit_ready (p1.ch, 375 ch = GNUNET_CORE_notify_transmit_ready (p1.ch,
337 0, 376 0,
338 FAST_TIMEOUT, 377 FAST_TIMEOUT,
339 &p2.id, 378 &p2.id,
340 get_size(tr_n), 379 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
341 &transmit_ready, &p1); 380 &transmit_ready, &p1);
342 return ret; 381 return ret;
343} 382}
@@ -380,27 +419,8 @@ init_notify (void *cls,
380 GNUNET_assert (ok == 3); 419 GNUNET_assert (ok == 3);
381 OKPP; 420 OKPP;
382 GNUNET_assert (cls == &p2); 421 GNUNET_assert (cls == &p2);
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 422
384 "Asking core (1) for transmission to peer `%4s'\n", 423 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
385 GNUNET_i2s (&p2.id));
386 err_task =
387 GNUNET_SCHEDULER_add_delayed (sched,
388 TIMEOUT,
389 &terminate_task_error,
390 NULL);
391 measure_task = GNUNET_SCHEDULER_add_delayed (sched,
392 MEASUREMENT_INTERVALL,
393 &measurement_end,
394 NULL);
395 start_time = GNUNET_TIME_absolute_get ();
396 measurement_running = GNUNET_YES;
397 GNUNET_break (NULL !=
398 GNUNET_CORE_notify_transmit_ready (p1.ch,
399 0,
400 TIMEOUT,
401 &p2.id,
402 get_size (0),
403 &transmit_ready, &p1));
404 } 424 }
405} 425}
406 426
@@ -524,7 +544,7 @@ main (int argc, char *argv[])
524#endif 544#endif
525 NULL); 545 NULL);
526 ret = check (); 546 ret = check ();
527 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 547 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
528 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); 548 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
529 549
530 return ret; 550 return ret;