diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-16 15:10:12 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-16 15:10:12 +0000 |
commit | 669d12d4d3893b92c212ae9b2259becdd3cf505d (patch) | |
tree | 644e7c3610452dd1b1c7382dc4acb0fb75e4d300 /src/core/test_core_quota_compliance.c | |
parent | b65e40508cbfd1eef561529e110efcace93037e2 (diff) | |
download | gnunet-669d12d4d3893b92c212ae9b2259becdd3cf505d.tar.gz gnunet-669d12d4d3893b92c212ae9b2259becdd3cf505d.zip |
More changes
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r-- | src/core/test_core_quota_compliance.c | 68 |
1 files changed, 55 insertions, 13 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index d144dd4b3..c74a84cbd 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include "gnunet_scheduler_lib.h" | 35 | #include "gnunet_scheduler_lib.h" |
36 | #include "gnunet_transport_service.h" | 36 | #include "gnunet_transport_service.h" |
37 | 37 | ||
38 | #define VERBOSE GNUNET_NO | 38 | #define VERBOSE GNUNET_YES |
39 | 39 | ||
40 | #define START_ARM GNUNET_YES | 40 | #define START_ARM GNUNET_YES |
41 | 41 | ||
@@ -85,9 +85,13 @@ struct PeerContext | |||
85 | }; | 85 | }; |
86 | 86 | ||
87 | static struct PeerContext p1; | 87 | static struct PeerContext p1; |
88 | |||
89 | static struct PeerContext p2; | 88 | static struct PeerContext p2; |
90 | 89 | ||
90 | static unsigned long long current_quota_p1_in; | ||
91 | static unsigned long long current_quota_p1_out; | ||
92 | static unsigned long long current_quota_p2_in; | ||
93 | static unsigned long long current_quota_p2_out; | ||
94 | |||
91 | static int ok; | 95 | static int ok; |
92 | 96 | ||
93 | static int32_t tr_n; | 97 | static int32_t tr_n; |
@@ -110,8 +114,6 @@ struct TestMessage | |||
110 | static void | 114 | static void |
111 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 115 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
112 | { | 116 | { |
113 | unsigned long long delta; | ||
114 | |||
115 | GNUNET_CORE_disconnect (p1.ch); | 117 | GNUNET_CORE_disconnect (p1.ch); |
116 | p1.ch = NULL; | 118 | p1.ch = NULL; |
117 | GNUNET_CORE_disconnect (p2.ch); | 119 | GNUNET_CORE_disconnect (p2.ch); |
@@ -120,10 +122,6 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
120 | p1.th = NULL; | 122 | p1.th = NULL; |
121 | GNUNET_TRANSPORT_disconnect (p2.th); | 123 | GNUNET_TRANSPORT_disconnect (p2.th); |
122 | p2.th = NULL; | 124 | p2.th = NULL; |
123 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | ||
124 | fprintf (stderr, | ||
125 | "\nThroughput was %llu kb/s\n", | ||
126 | total_bytes * 1000 / 1024 / delta); | ||
127 | ok = 0; | 125 | ok = 0; |
128 | } | 126 | } |
129 | 127 | ||
@@ -151,11 +149,39 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
151 | static void | 149 | static void |
152 | measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 150 | measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
153 | { | 151 | { |
152 | unsigned long long int delta; | ||
153 | unsigned long long int throughput; | ||
154 | unsigned long long int max_quota_in; | ||
155 | unsigned long long int max_quota_out; | ||
156 | unsigned long long int quota_delta; | ||
157 | |||
154 | measure_task = GNUNET_SCHEDULER_NO_TASK; | 158 | measure_task = GNUNET_SCHEDULER_NO_TASK; |
155 | fprintf(stdout,"\n"); | 159 | fprintf(stdout,"\n"); |
156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FINIIISH!\n"); | 160 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FINIIISH!\n"); |
157 | running = GNUNET_NO; | 161 | running = GNUNET_NO; |
158 | 162 | ||
163 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | ||
164 | throughput = total_bytes * 1000 / 1024 / delta; | ||
165 | if (current_quota_p1_in < current_quota_p2_in) | ||
166 | max_quota_in = current_quota_p1_in; | ||
167 | else | ||
168 | max_quota_in = current_quota_p2_in; | ||
169 | if (current_quota_p1_out < current_quota_p2_out) | ||
170 | max_quota_out = current_quota_p1_out; | ||
171 | else | ||
172 | max_quota_out = current_quota_p2_out; | ||
173 | |||
174 | if (max_quota_out < max_quota_in) | ||
175 | quota_delta = max_quota_in / 10; | ||
176 | else | ||
177 | quota_delta = max_quota_out / 10; | ||
178 | |||
179 | if ((throughput < max_quota_out)&& (throughput < max_quota_in)) | ||
180 | { | ||
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Throughput: %llu kb/s\n",throughput); | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kb/s\n",max_quota_in/1024); | ||
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kb/s\n",max_quota_out/1024); | ||
184 | } | ||
159 | GNUNET_SCHEDULER_cancel (err_task); | 185 | GNUNET_SCHEDULER_cancel (err_task); |
160 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); | 186 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); |
161 | 187 | ||
@@ -308,18 +334,16 @@ process_mtype (void *cls, | |||
308 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 334 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
309 | { | 335 | { |
310 | static int n; | 336 | static int n; |
311 | unsigned int s; | ||
312 | const struct TestMessage *hdr; | 337 | const struct TestMessage *hdr; |
313 | 338 | ||
314 | hdr = (const struct TestMessage*) message; | 339 | hdr = (const struct TestMessage*) message; |
315 | s = MSIZE; | ||
316 | if (MTYPE != ntohs (message->type)) | 340 | if (MTYPE != ntohs (message->type)) |
317 | return GNUNET_SYSERR; | 341 | return GNUNET_SYSERR; |
318 | if (ntohs (message->size) != s) | 342 | if (ntohs (message->size) != MSIZE) |
319 | { | 343 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 344 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
321 | "Expected message %u of size %u, got %u bytes of message %u\n", | 345 | "Expected message %u of size %u, got %u bytes of message %u\n", |
322 | n, s, | 346 | n, MSIZE, |
323 | ntohs (message->size), | 347 | ntohs (message->size), |
324 | ntohl (hdr->num)); | 348 | ntohl (hdr->num)); |
325 | GNUNET_SCHEDULER_cancel (err_task); | 349 | GNUNET_SCHEDULER_cancel (err_task); |
@@ -330,7 +354,7 @@ process_mtype (void *cls, | |||
330 | { | 354 | { |
331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 355 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
332 | "Expected message %u of size %u, got %u bytes of message %u\n", | 356 | "Expected message %u of size %u, got %u bytes of message %u\n", |
333 | n, s, | 357 | n, MSIZE, |
334 | ntohs (message->size), | 358 | ntohs (message->size), |
335 | ntohl (hdr->num)); | 359 | ntohl (hdr->num)); |
336 | GNUNET_SCHEDULER_cancel (err_task); | 360 | GNUNET_SCHEDULER_cancel (err_task); |
@@ -473,6 +497,24 @@ run (void *cls, | |||
473 | OKPP; | 497 | OKPP; |
474 | setup_peer (&p1, "test_core_quota_peer1.conf"); | 498 | setup_peer (&p1, "test_core_quota_peer1.conf"); |
475 | setup_peer (&p2, "test_core_quota_peer2.conf"); | 499 | setup_peer (&p2, "test_core_quota_peer2.conf"); |
500 | |||
501 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, | ||
502 | "CORE", | ||
503 | "TOTAL_QUOTA_IN", | ||
504 | ¤t_quota_p1_in)); | ||
505 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, | ||
506 | "CORE", | ||
507 | "TOTAL_QUOTA_IN", | ||
508 | ¤t_quota_p2_in)); | ||
509 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, | ||
510 | "CORE", | ||
511 | "TOTAL_QUOTA_OUT", | ||
512 | ¤t_quota_p1_out)); | ||
513 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, | ||
514 | "CORE", | ||
515 | "TOTAL_QUOTA_OUT", | ||
516 | ¤t_quota_p2_out)); | ||
517 | |||
476 | GNUNET_CORE_connect (p1.cfg, 1, | 518 | GNUNET_CORE_connect (p1.cfg, 1, |
477 | &p1, | 519 | &p1, |
478 | &init_notify, | 520 | &init_notify, |