diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-22 14:51:29 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-22 14:51:29 +0000 |
commit | fdb5a20adad300cab0166a7afea32f59eca746eb (patch) | |
tree | 93bba6a289665fe8ed5edcaa51beeba6510af5be /src/transport | |
parent | 318468a976ec426f517663f7a244c969623df882 (diff) | |
download | gnunet-fdb5a20adad300cab0166a7afea32f59eca746eb.tar.gz gnunet-fdb5a20adad300cab0166a7afea32f59eca746eb.zip |
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/test_quota_compliance.c | 187 |
1 files changed, 86 insertions, 101 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index b9fd319e6..c6da0e024 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -91,12 +91,9 @@ static struct GNUNET_TIME_Absolute start_time; | |||
91 | 91 | ||
92 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 92 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
93 | static GNUNET_SCHEDULER_TaskIdentifier measurement_task; | 93 | static GNUNET_SCHEDULER_TaskIdentifier measurement_task; |
94 | static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task; | ||
94 | 95 | ||
95 | static int msg_scheduled; | 96 | struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle; |
96 | static int msg_sent; | ||
97 | static int msg_recv_expected; | ||
98 | static int msg_recv; | ||
99 | |||
100 | 97 | ||
101 | #if VERBOSE | 98 | #if VERBOSE |
102 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 99 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
@@ -108,10 +105,20 @@ static int msg_recv; | |||
108 | static void | 105 | static void |
109 | end () | 106 | end () |
110 | { | 107 | { |
111 | unsigned long long delta; | ||
112 | |||
113 | GNUNET_SCHEDULER_cancel (sched, die_task); | 108 | GNUNET_SCHEDULER_cancel (sched, die_task); |
114 | die_task = GNUNET_SCHEDULER_NO_TASK; | 109 | die_task = GNUNET_SCHEDULER_NO_TASK; |
110 | |||
111 | if (measurement_task != GNUNET_SCHEDULER_NO_TASK) | ||
112 | { | ||
113 | GNUNET_SCHEDULER_cancel (sched, measurement_task); | ||
114 | measurement_task = GNUNET_SCHEDULER_NO_TASK; | ||
115 | } | ||
116 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | ||
117 | { | ||
118 | GNUNET_SCHEDULER_cancel (sched, measurement_counter_task); | ||
119 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | ||
120 | } | ||
121 | |||
115 | #if VERBOSE | 122 | #if VERBOSE |
116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); |
117 | #endif | 124 | #endif |
@@ -121,10 +128,6 @@ end () | |||
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
122 | "Transports disconnected, returning success!\n"); | 129 | "Transports disconnected, returning success!\n"); |
123 | #endif | 130 | #endif |
124 | delta = GNUNET_TIME_absolute_get_duration (start_time).value; | ||
125 | fprintf (stderr, | ||
126 | "\nThroughput was %llu kb/s\n", | ||
127 | total_bytes * 1000 / 1024 / delta); | ||
128 | ok = 0; | 131 | ok = 0; |
129 | 132 | ||
130 | } | 133 | } |
@@ -147,9 +150,16 @@ static void | |||
147 | end_badly (void *cls, | 150 | end_badly (void *cls, |
148 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 151 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
149 | { | 152 | { |
150 | 153 | if (measurement_task != GNUNET_SCHEDULER_NO_TASK) | |
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 154 | { |
152 | "end_badly \n "); | 155 | GNUNET_SCHEDULER_cancel (sched, measurement_task); |
156 | measurement_task = GNUNET_SCHEDULER_NO_TASK; | ||
157 | } | ||
158 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | ||
159 | { | ||
160 | GNUNET_SCHEDULER_cancel (sched, measurement_counter_task); | ||
161 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | ||
162 | } | ||
153 | GNUNET_break (0); | 163 | GNUNET_break (0); |
154 | if (p1.th != NULL) | 164 | if (p1.th != NULL) |
155 | GNUNET_TRANSPORT_disconnect (p1.th); | 165 | GNUNET_TRANSPORT_disconnect (p1.th); |
@@ -164,18 +174,6 @@ struct TestMessage | |||
164 | uint32_t num; | 174 | uint32_t num; |
165 | }; | 175 | }; |
166 | 176 | ||
167 | |||
168 | static unsigned int | ||
169 | get_size (unsigned int iter) | ||
170 | { | ||
171 | unsigned int ret; | ||
172 | |||
173 | if (iter < 60000) | ||
174 | return iter + sizeof (struct TestMessage); | ||
175 | ret = (iter * iter * iter); | ||
176 | return sizeof (struct TestMessage) + (ret % 60000); | ||
177 | } | ||
178 | |||
179 | static unsigned int | 177 | static unsigned int |
180 | get_size_new (unsigned int iter) | 178 | get_size_new (unsigned int iter) |
181 | { | 179 | { |
@@ -191,54 +189,12 @@ notify_receive_new (void *cls, | |||
191 | { | 189 | { |
192 | static int n; | 190 | static int n; |
193 | unsigned int s; | 191 | unsigned int s; |
194 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | ||
195 | const struct TestMessage *hdr; | 192 | const struct TestMessage *hdr; |
196 | 193 | ||
197 | hdr = (const struct TestMessage*) message; | 194 | hdr = (const struct TestMessage*) message; |
198 | s = get_size_new (n); | 195 | s = get_size_new (n); |
199 | if (MTYPE != ntohs (message->type)) | 196 | if (MTYPE != ntohs (message->type)) |
200 | return; | 197 | return; |
201 | msg_recv_expected = n; | ||
202 | msg_recv = ntohl(hdr->num); | ||
203 | /* | ||
204 | if (ntohs (message->size) != s) | ||
205 | { | ||
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
207 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
208 | n, s, | ||
209 | ntohs (message->size), | ||
210 | ntohl (hdr->num)); | ||
211 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
212 | die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
213 | return; | ||
214 | } | ||
215 | |||
216 | if (ntohl (hdr->num) != n) | ||
217 | { | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
219 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
220 | n, s, | ||
221 | ntohs (message->size), | ||
222 | ntohl (hdr->num)); | ||
223 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
224 | die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
225 | return; | ||
226 | } | ||
227 | */ | ||
228 | /* | ||
229 | memset (cbuf, n, s - sizeof (struct TestMessage)); | ||
230 | if (0 != memcmp (cbuf, | ||
231 | &hdr[1], | ||
232 | s - sizeof (struct TestMessage))) | ||
233 | { | ||
234 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
235 | "Expected message %u with bits %u, but body did not match\n", | ||
236 | n, (unsigned char) n); | ||
237 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
238 | die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
239 | return; | ||
240 | } | ||
241 | */ | ||
242 | #if DEBUG_MEASUREMENT | 198 | #if DEBUG_MEASUREMENT |
243 | if (ntohl(hdr->num) % 5000 == 0) | 199 | if (ntohl(hdr->num) % 5000 == 0) |
244 | { | 200 | { |
@@ -249,12 +205,6 @@ notify_receive_new (void *cls, | |||
249 | } | 205 | } |
250 | #endif | 206 | #endif |
251 | n++; | 207 | n++; |
252 | |||
253 | |||
254 | if (0 == (n % (TOTAL_MSGS/10))) | ||
255 | { | ||
256 | fprintf (stderr, "."); | ||
257 | } | ||
258 | } | 208 | } |
259 | 209 | ||
260 | static size_t | 210 | static size_t |
@@ -266,6 +216,8 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
266 | unsigned int s; | 216 | unsigned int s; |
267 | unsigned int ret; | 217 | unsigned int ret; |
268 | 218 | ||
219 | transmit_handle = NULL; | ||
220 | |||
269 | if (buf == NULL) | 221 | if (buf == NULL) |
270 | { | 222 | { |
271 | GNUNET_break (0); | 223 | GNUNET_break (0); |
@@ -282,7 +234,6 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
282 | hdr.header.size = htons (s); | 234 | hdr.header.size = htons (s); |
283 | hdr.header.type = htons (MTYPE); | 235 | hdr.header.type = htons (MTYPE); |
284 | hdr.num = htonl (n); | 236 | hdr.num = htonl (n); |
285 | msg_sent = n; | ||
286 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 237 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
287 | ret += sizeof (struct TestMessage); | 238 | ret += sizeof (struct TestMessage); |
288 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | 239 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); |
@@ -300,23 +251,53 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
300 | break; /* sometimes pack buffer full, sometimes not */ | 251 | break; /* sometimes pack buffer full, sometimes not */ |
301 | } | 252 | } |
302 | while (size - ret >= s); | 253 | while (size - ret >= s); |
303 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 254 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
304 | &p1.id, | 255 | &p1.id, |
305 | s, 0, TIMEOUT, | 256 | s, 0, TIMEOUT, |
306 | ¬ify_ready_new, | 257 | ¬ify_ready_new, |
307 | NULL); | 258 | NULL); |
308 | msg_scheduled = n; | ||
309 | total_bytes += s; | 259 | total_bytes += s; |
310 | return ret; | 260 | return ret; |
311 | } | 261 | } |
312 | 262 | ||
313 | static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ); | 263 | static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ); |
314 | 264 | ||
265 | static void measurement_counter | ||
266 | (void *cls, | ||
267 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
268 | { | ||
269 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | ||
270 | |||
271 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
272 | return; | ||
273 | #if VERBOSE | ||
274 | fprintf(stderr,"."); | ||
275 | #endif | ||
276 | measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched, | ||
277 | GNUNET_TIME_UNIT_SECONDS, | ||
278 | &measurement_counter, | ||
279 | NULL); | ||
280 | } | ||
281 | |||
315 | static void | 282 | static void |
316 | stop_measurement (void *cls, | 283 | measurement_end (void *cls, |
317 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 284 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
318 | { | 285 | { |
286 | measurement_task = GNUNET_SCHEDULER_NO_TASK; | ||
287 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
288 | return; | ||
289 | |||
319 | struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get()); | 290 | struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get()); |
291 | |||
292 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | ||
293 | { | ||
294 | GNUNET_SCHEDULER_cancel (sched, measurement_counter_task); | ||
295 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | ||
296 | } | ||
297 | /* | ||
298 | if (transmit_handle != NULL) | ||
299 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); | ||
300 | */ | ||
320 | fprintf (stderr, "\n"); | 301 | fprintf (stderr, "\n"); |
321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 302 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
322 | "Measurement finished: \n Quota allowed: %llu kb/s\n Throughput: %llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); | 303 | "Measurement finished: \n Quota allowed: %llu kb/s\n Throughput: %llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); |
@@ -326,7 +307,6 @@ stop_measurement (void *cls, | |||
326 | measure (current_quota_p1/100, current_quota_p2/100); | 307 | measure (current_quota_p1/100, current_quota_p2/100); |
327 | } | 308 | } |
328 | 309 | ||
329 | |||
330 | static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | 310 | static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) |
331 | { | 311 | { |
332 | current_quota_p1 = quota_p1; | 312 | current_quota_p1 = quota_p1; |
@@ -335,36 +315,41 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | |||
335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
336 | "Starting measurement: Duration: %u Quota: %u\n", MEASUREMENT_INTERVALL, current_quota_p1); | 316 | "Starting measurement: Duration: %u Quota: %u\n", MEASUREMENT_INTERVALL, current_quota_p1); |
337 | #endif | 317 | #endif |
338 | 318 | GNUNET_TRANSPORT_set_quota (p1.th, | |
339 | GNUNET_TRANSPORT_set_quota (p1.th, | ||
340 | &p2.id, | 319 | &p2.id, |
341 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), | 320 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), |
342 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), | 321 | GNUNET_BANDWIDTH_value_init (current_quota_p1 ), |
343 | GNUNET_TIME_UNIT_FOREVER_REL, | 322 | GNUNET_TIME_UNIT_FOREVER_REL, |
344 | NULL, NULL); | 323 | NULL, NULL); |
345 | GNUNET_TRANSPORT_set_quota (p2.th, | 324 | GNUNET_TRANSPORT_set_quota (p2.th, |
346 | &p1.id, | 325 | &p1.id, |
347 | GNUNET_BANDWIDTH_value_init (current_quota_p2), | 326 | GNUNET_BANDWIDTH_value_init (current_quota_p2), |
348 | GNUNET_BANDWIDTH_value_init (current_quota_p2), | 327 | GNUNET_BANDWIDTH_value_init (current_quota_p2), |
349 | GNUNET_TIME_UNIT_FOREVER_REL, | 328 | GNUNET_TIME_UNIT_FOREVER_REL, |
350 | NULL, NULL); | 329 | NULL, NULL); |
351 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 330 | transmit_handle =GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
352 | &p1.id, | 331 | &p1.id, |
353 | get_size_new (0), 0, TIMEOUT, | 332 | get_size_new (0), 0, TIMEOUT, |
354 | ¬ify_ready_new, | 333 | ¬ify_ready_new, |
355 | NULL); | 334 | NULL); |
356 | 335 | ||
357 | GNUNET_SCHEDULER_cancel (sched, die_task); | 336 | GNUNET_SCHEDULER_cancel (sched, die_task); |
358 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 337 | die_task = GNUNET_SCHEDULER_add_delayed (sched, |
359 | TIMEOUT, | 338 | TIMEOUT, |
360 | &end_badly, | 339 | &end_badly, |
361 | NULL); | 340 | NULL); |
362 | measurement_task = GNUNET_SCHEDULER_add_delayed (sched, | 341 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) |
363 | MEASUREMENT_INTERVALL, | 342 | GNUNET_SCHEDULER_cancel (sched, measurement_counter_task); |
364 | &stop_measurement, | 343 | measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched, |
365 | NULL); | 344 | GNUNET_TIME_UNIT_SECONDS, |
366 | total_bytes = 0; | 345 | &measurement_counter, |
367 | start_time = GNUNET_TIME_absolute_get (); | 346 | NULL); |
347 | measurement_task = GNUNET_SCHEDULER_add_delayed (sched, | ||
348 | MEASUREMENT_INTERVALL, | ||
349 | &measurement_end, | ||
350 | NULL); | ||
351 | total_bytes = 0; | ||
352 | start_time = GNUNET_TIME_absolute_get (); | ||
368 | } | 353 | } |
369 | 354 | ||
370 | static void | 355 | static void |
@@ -482,8 +467,8 @@ run (void *cls, | |||
482 | NULL); | 467 | NULL); |
483 | 468 | ||
484 | /* Setting initial quota for both peers */ | 469 | /* Setting initial quota for both peers */ |
485 | current_quota_p1 = 1024 * 1024 * 1024; | 470 | // current_quota_p1 = 1024 * 1024 * 1024; |
486 | current_quota_p2 = 1024 * 1024 * 1024; | 471 | // current_quota_p2 = 1024 * 1024 * 1024; |
487 | 472 | ||
488 | setup_peer (&p1, "test_quota_compliance_peer1.conf"); | 473 | setup_peer (&p1, "test_quota_compliance_peer1.conf"); |
489 | setup_peer (&p2, "test_quota_compliance_peer2.conf"); | 474 | setup_peer (&p2, "test_quota_compliance_peer2.conf"); |