diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-17 12:51:44 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-11-17 12:51:44 +0000 |
commit | 2052a779a65a09a1d4cdda1d71185e6b401878c2 (patch) | |
tree | df1dbd2f8ccf653d6e6e55533b4bc59d7a6eb09b /src/core/test_core_quota_compliance.c | |
parent | 748c1e3d6d2121ab60a58f130861030696e17e4e (diff) | |
download | gnunet-2052a779a65a09a1d4cdda1d71185e6b401878c2.tar.gz gnunet-2052a779a65a09a1d4cdda1d71185e6b401878c2.zip |
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r-- | src/core/test_core_quota_compliance.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index d42149099..22f3414dc 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include "gnunet_transport_service.h" | 36 | #include "gnunet_transport_service.h" |
37 | 37 | ||
38 | #define VERBOSE GNUNET_YES | 38 | #define VERBOSE GNUNET_YES |
39 | #define DEBUG_TRANSMISSION GNUNET_NO | 39 | #define DEBUG_TRANSMISSION GNUNET_YES |
40 | 40 | ||
41 | #define START_ARM GNUNET_YES | 41 | #define START_ARM GNUNET_YES |
42 | 42 | ||
@@ -45,7 +45,7 @@ | |||
45 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise | 45 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise |
46 | * messages may be dropped even for a reliable transport. | 46 | * messages may be dropped even for a reliable transport. |
47 | */ | 47 | */ |
48 | #define TOTAL_MSGS (60 * 10) | 48 | #define TOTAL_MSGS (60000 * 10) |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * How long until we give up on transmitting the message? | 51 | * How long until we give up on transmitting the message? |
@@ -63,7 +63,8 @@ | |||
63 | #define MSIZE 1024 | 63 | #define MSIZE 1024 |
64 | #define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 64 | #define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
65 | 65 | ||
66 | static unsigned long long total_bytes; | 66 | static unsigned long long total_bytes_sent; |
67 | static unsigned long long total_bytes_recv; | ||
67 | 68 | ||
68 | static struct GNUNET_TIME_Absolute start_time; | 69 | static struct GNUNET_TIME_Absolute start_time; |
69 | 70 | ||
@@ -150,7 +151,8 @@ static void | |||
150 | measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 151 | measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
151 | { | 152 | { |
152 | unsigned long long int delta; | 153 | unsigned long long int delta; |
153 | unsigned long long int throughput; | 154 | unsigned long long int throughput_out; |
155 | unsigned long long int throughput_int; | ||
154 | unsigned long long int max_quota_in; | 156 | unsigned long long int max_quota_in; |
155 | unsigned long long int max_quota_out; | 157 | unsigned long long int max_quota_out; |
156 | unsigned long long int quota_delta; | 158 | unsigned long long int quota_delta; |
@@ -160,7 +162,10 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
160 | running = GNUNET_NO; | 162 | running = GNUNET_NO; |
161 | 163 | ||
162 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | 164 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; |
163 | throughput = total_bytes * 1000 / 1024 / delta; | 165 | |
166 | throughput_out = total_bytes_sent * 1000 / 1024 / delta; | ||
167 | throughput_int = total_bytes_recv * 1000 / 1024 / delta; | ||
168 | |||
164 | if (current_quota_p1_in < current_quota_p2_in) | 169 | if (current_quota_p1_in < current_quota_p2_in) |
165 | max_quota_in = current_quota_p1_in; | 170 | max_quota_in = current_quota_p1_in; |
166 | else | 171 | else |
@@ -175,7 +180,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
175 | else | 180 | else |
176 | quota_delta = max_quota_out / 10; | 181 | quota_delta = max_quota_out / 10; |
177 | 182 | ||
178 | if ((throughput < (max_quota_out/1024)) && (throughput < (max_quota_in/1024))) | 183 | if ((throughput_out < (max_quota_out/1024)) && (throughput_out < (max_quota_in/1024))) |
179 | { | 184 | { |
180 | ok = 0; | 185 | ok = 0; |
181 | } | 186 | } |
@@ -183,8 +188,12 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
183 | { | 188 | { |
184 | ok = 1; | 189 | ok = 1; |
185 | } | 190 | } |
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Throughput: %llu kb/s\n",throughput); | 191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Bytes in: %llu Bytes\n",total_bytes_recv); |
192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Throughput in: %llu kb/s\n",throughput_out); | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kb/s\n",max_quota_in/1024); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kb/s\n",max_quota_in/1024); |
194 | |||
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Bytes out: %llu Bytes\n",total_bytes_sent); | ||
196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Throughput out: %llu kb/s\n",throughput_out); | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kb/s\n",max_quota_out/1024); | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kb/s\n",max_quota_out/1024); |
189 | 198 | ||
190 | GNUNET_SCHEDULER_cancel (err_task); | 199 | GNUNET_SCHEDULER_cancel (err_task); |
@@ -197,7 +206,6 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
197 | { | 206 | { |
198 | char *cbuf = buf; | 207 | char *cbuf = buf; |
199 | struct TestMessage hdr; | 208 | struct TestMessage hdr; |
200 | unsigned int s; | ||
201 | unsigned int ret; | 209 | unsigned int ret; |
202 | 210 | ||
203 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); | 211 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); |
@@ -215,8 +223,7 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
215 | } | 223 | } |
216 | GNUNET_assert (tr_n < TOTAL_MSGS); | 224 | GNUNET_assert (tr_n < TOTAL_MSGS); |
217 | ret = 0; | 225 | ret = 0; |
218 | s = MSIZE; | 226 | GNUNET_assert (size >= MSIZE); |
219 | GNUNET_assert (size >= s); | ||
220 | GNUNET_assert (buf != NULL); | 227 | GNUNET_assert (buf != NULL); |
221 | cbuf = buf; | 228 | cbuf = buf; |
222 | do | 229 | do |
@@ -225,28 +232,27 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
226 | "Sending message %u of size %u at offset %u\n", | 233 | "Sending message %u of size %u at offset %u\n", |
227 | tr_n, | 234 | tr_n, |
228 | s, | 235 | MSIZE, |
229 | ret); | 236 | ret); |
230 | #endif | 237 | #endif |
231 | hdr.header.size = htons (s); | 238 | hdr.header.size = htons (MSIZE); |
232 | hdr.header.type = htons (MTYPE); | 239 | hdr.header.type = htons (MTYPE); |
233 | hdr.num = htonl (tr_n); | 240 | hdr.num = htonl (tr_n); |
234 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 241 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
235 | ret += sizeof (struct TestMessage); | 242 | ret += sizeof (struct TestMessage); |
236 | memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage)); | 243 | memset (&cbuf[ret], tr_n, MSIZE - sizeof (struct TestMessage)); |
237 | ret += s - sizeof (struct TestMessage); | 244 | ret += MSIZE - sizeof (struct TestMessage); |
238 | tr_n++; | 245 | tr_n++; |
239 | s = MSIZE; | ||
240 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 246 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
241 | break; /* sometimes pack buffer full, sometimes not */ | 247 | break; /* sometimes pack buffer full, sometimes not */ |
242 | } | 248 | } |
243 | while (size - ret >= s); | 249 | while (size - ret >= MSIZE); |
244 | GNUNET_SCHEDULER_cancel (err_task); | 250 | GNUNET_SCHEDULER_cancel (err_task); |
245 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 251 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
246 | &terminate_task_error, | 252 | &terminate_task_error, |
247 | NULL); | 253 | NULL); |
248 | 254 | ||
249 | total_bytes += ret; | 255 | total_bytes_sent += ret; |
250 | return ret; | 256 | return ret; |
251 | } | 257 | } |
252 | 258 | ||
@@ -309,8 +315,9 @@ inbound_notify (void *cls, | |||
309 | { | 315 | { |
310 | #if DEBUG_TRANSMISSION | 316 | #if DEBUG_TRANSMISSION |
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
312 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); | 318 | "Core provides inbound data from `%4s' %llu.\n", GNUNET_i2s (other), ntohs(message->size)); |
313 | #endif | 319 | #endif |
320 | total_bytes_recv += ntohs(message->size); | ||
314 | return GNUNET_OK; | 321 | return GNUNET_OK; |
315 | } | 322 | } |
316 | 323 | ||