diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-27 10:04:42 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-27 10:04:42 +0000 |
commit | f47cc990ea9a89cb39acc9c6a9789e6474197708 (patch) | |
tree | f8301a2b5405ed692592fb98c94d53dc4a9c9151 /src/transport/test_quota_compliance.c | |
parent | abcb868988fd2d754e13ef5122c8ada9c404b273 (diff) | |
download | gnunet-f47cc990ea9a89cb39acc9c6a9789e6474197708.tar.gz gnunet-f47cc990ea9a89cb39acc9c6a9789e6474197708.zip |
Refactoring gnunet time
Diffstat (limited to 'src/transport/test_quota_compliance.c')
-rw-r--r-- | src/transport/test_quota_compliance.c | 91 |
1 files changed, 71 insertions, 20 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 018324a4e..a5a836d48 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -49,18 +49,20 @@ | |||
49 | */ | 49 | */ |
50 | #define TOTAL_MSGS (10000 * 2) | 50 | #define TOTAL_MSGS (10000 * 2) |
51 | 51 | ||
52 | #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | 52 | #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
53 | #define MEASUREMENT_MSG_SIZE 1024 | 53 | #define MEASUREMENT_MSG_SIZE 10000 |
54 | #define MEASUREMENT_MSG_SIZE_BIG 32768 | 54 | #define MEASUREMENT_MSG_SIZE_BIG 32768 |
55 | #define MEASUREMENT_MAX_QUOTA 1024*1024*1024 | 55 | #define MEASUREMENT_MAX_QUOTA 50000 |
56 | #define MEASUREMENT_MIN_QUOTA 1024 | 56 | /*#define MEASUREMENT_MAX_QUOTA 1000000*/ |
57 | 57 | #define MEASUREMENT_MIN_QUOTA 1000 | |
58 | #define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
58 | /** | 59 | /** |
59 | * Testcase timeout | 60 | * Testcase timeout |
60 | */ | 61 | */ |
61 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200) | 62 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200) |
62 | 63 | ||
63 | 64 | ||
65 | |||
64 | #define MTYPE 11111 | 66 | #define MTYPE 11111 |
65 | 67 | ||
66 | struct PeerContext | 68 | struct PeerContext |
@@ -73,6 +75,54 @@ struct PeerContext | |||
73 | #endif | 75 | #endif |
74 | }; | 76 | }; |
75 | 77 | ||
78 | /** | ||
79 | * Handle for a transmission-ready request. | ||
80 | */ | ||
81 | struct GNUNET_TRANSPORT_TransmitHandle | ||
82 | { | ||
83 | |||
84 | /** | ||
85 | * Neighbour for this handle, NULL for control-traffic. | ||
86 | */ | ||
87 | struct NeighbourList *neighbour; | ||
88 | |||
89 | /** | ||
90 | * Function to call when notify_size bytes are available | ||
91 | * for transmission. | ||
92 | */ | ||
93 | GNUNET_CONNECTION_TransmitReadyNotify notify; | ||
94 | |||
95 | /** | ||
96 | * Closure for notify. | ||
97 | */ | ||
98 | void *notify_cls; | ||
99 | |||
100 | /** | ||
101 | * transmit_ready task Id. The task is used to introduce the | ||
102 | * artificial delay that may be required to maintain the bandwidth | ||
103 | * limits. Later, this will be the ID of the "transmit_timeout" | ||
104 | * task which is used to signal a timeout if the transmission could | ||
105 | * not be done in a timely fashion. | ||
106 | */ | ||
107 | GNUNET_SCHEDULER_TaskIdentifier notify_delay_task; | ||
108 | |||
109 | /** | ||
110 | * Timeout for this request. | ||
111 | */ | ||
112 | struct GNUNET_TIME_Absolute timeout; | ||
113 | |||
114 | /** | ||
115 | * How many bytes is our notify callback waiting for? | ||
116 | */ | ||
117 | size_t notify_size; | ||
118 | |||
119 | /** | ||
120 | * How important is this message? | ||
121 | */ | ||
122 | unsigned int priority; | ||
123 | |||
124 | }; | ||
125 | |||
76 | static struct PeerContext p1; | 126 | static struct PeerContext p1; |
77 | 127 | ||
78 | static struct PeerContext p2; | 128 | static struct PeerContext p2; |
@@ -177,7 +227,7 @@ struct TestMessage | |||
177 | }; | 227 | }; |
178 | 228 | ||
179 | static unsigned int | 229 | static unsigned int |
180 | get_size_new (unsigned int iter) | 230 | get_size (unsigned int iter) |
181 | { | 231 | { |
182 | return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage); | 232 | return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage); |
183 | } | 233 | } |
@@ -194,7 +244,7 @@ notify_receive_new (void *cls, | |||
194 | const struct TestMessage *hdr; | 244 | const struct TestMessage *hdr; |
195 | 245 | ||
196 | hdr = (const struct TestMessage*) message; | 246 | hdr = (const struct TestMessage*) message; |
197 | s = get_size_new (n); | 247 | s = get_size (n); |
198 | if (MTYPE != ntohs (message->type)) | 248 | if (MTYPE != ntohs (message->type)) |
199 | return; | 249 | return; |
200 | #if DEBUG_MEASUREMENT | 250 | #if DEBUG_MEASUREMENT |
@@ -234,7 +284,7 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
234 | return 0; | 284 | return 0; |
235 | 285 | ||
236 | ret = 0; | 286 | ret = 0; |
237 | s = get_size_new (n); | 287 | s = get_size (n); |
238 | GNUNET_assert (size >= s); | 288 | GNUNET_assert (size >= s); |
239 | GNUNET_assert (buf != NULL); | 289 | GNUNET_assert (buf != NULL); |
240 | cbuf = buf; | 290 | cbuf = buf; |
@@ -255,14 +305,14 @@ notify_ready_new (void *cls, size_t size, void *buf) | |||
255 | } | 305 | } |
256 | #endif | 306 | #endif |
257 | n++; | 307 | n++; |
258 | s = get_size_new (n); | 308 | s = get_size (n); |
259 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 309 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
260 | break; /* sometimes pack buffer full, sometimes not */ | 310 | break; /* sometimes pack buffer full, sometimes not */ |
261 | } | 311 | } |
262 | while (size - ret >= s); | 312 | while (size - ret >= s); |
263 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 313 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
264 | &p1.id, | 314 | &p1.id, |
265 | s, 0, TIMEOUT, | 315 | s, 0, SEND_TIMEOUT, |
266 | ¬ify_ready_new, | 316 | ¬ify_ready_new, |
267 | NULL); | 317 | NULL); |
268 | total_bytes += s; | 318 | total_bytes += s; |
@@ -313,14 +363,14 @@ measurement_end (void *cls, | |||
313 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); | 363 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); |
314 | transmit_handle = NULL; | 364 | transmit_handle = NULL; |
315 | } | 365 | } |
316 | if (current_quota_p1 < total_bytes/(duration.value / 1000)) | 366 | if ((total_bytes/(duration.rel_value / 1000)) > (current_quota_p1 + (current_quota_p1 / 10))) |
317 | { | 367 | { |
318 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
319 | "\nQuota compliance failed: \n"\ | 369 | "\nQuota compliance failed: \n"\ |
320 | "Quota allowed: %10llu kb/s\n"\ | 370 | "Quota allowed: %10llu kB/s\n"\ |
321 | "Throughput : %10llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); | 371 | "Throughput : %10llu kB/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.rel_value / 1000)/1024)); |
322 | ok = 1; | 372 | ok = 1; |
323 | end(); | 373 | //end(); |
324 | return; | 374 | return; |
325 | } | 375 | } |
326 | else | 376 | else |
@@ -328,14 +378,15 @@ measurement_end (void *cls, | |||
328 | 378 | ||
329 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 379 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
330 | "\nQuota compliance ok: \n"\ | 380 | "\nQuota compliance ok: \n"\ |
331 | "Quota allowed: %10llu kb/s\n"\ | 381 | "Quota allowed: %10llu kB/s\n"\ |
332 | "Throughput : %10llu kb/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.value / 1000)/1024)); | 382 | "Throughput : %10llu kB/s\n", (current_quota_p1 / (1024)) , (total_bytes/(duration.rel_value / 1000)/1024)); |
333 | ok = 0; | 383 | ok = 0; |
334 | } | 384 | } |
335 | if (current_quota_p1 < (MEASUREMENT_MIN_QUOTA)) | 385 | if (current_quota_p1 < MEASUREMENT_MIN_QUOTA) |
336 | end(); | 386 | end(); |
337 | else | 387 | else |
338 | measure (current_quota_p1/100, current_quota_p2/100); | 388 | |
389 | measure (current_quota_p1- 1000, current_quota_p2- 1000); | ||
339 | } | 390 | } |
340 | 391 | ||
341 | static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | 392 | static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) |
@@ -344,7 +395,7 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | |||
344 | current_quota_p2 = quota_p2; | 395 | current_quota_p2 = quota_p2; |
345 | #if VERBOSE | 396 | #if VERBOSE |
346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
347 | "Starting transport level measurement: Duration: %u Quota: %u\n", MEASUREMENT_INTERVALL, current_quota_p1); | 398 | "Starting transport level measurement: Duration: %u Quota: %llu\n", MEASUREMENT_INTERVALL, current_quota_p1); |
348 | #endif | 399 | #endif |
349 | GNUNET_TRANSPORT_set_quota (p1.th, | 400 | GNUNET_TRANSPORT_set_quota (p1.th, |
350 | &p2.id, | 401 | &p2.id, |
@@ -383,7 +434,7 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 ) | |||
383 | 434 | ||
384 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 435 | transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
385 | &p1.id, | 436 | &p1.id, |
386 | get_size_new (0), 0, TIMEOUT, | 437 | get_size (0), 0, SEND_TIMEOUT, |
387 | ¬ify_ready_new, | 438 | ¬ify_ready_new, |
388 | NULL); | 439 | NULL); |
389 | } | 440 | } |