aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-10-22 13:01:33 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-10-22 13:01:33 +0000
commit28ec7b4a5f711ee355dd5fb2a23d5016e56432a7 (patch)
tree1b8de42e125f681c8398be1f2d040c8fceb635cc /src/transport
parentd53e0ea2ab53023ab080c35f0eb074bef0c65024 (diff)
downloadgnunet-28ec7b4a5f711ee355dd5fb2a23d5016e56432a7.tar.gz
gnunet-28ec7b4a5f711ee355dd5fb2a23d5016e56432a7.zip
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/test_quota_compliance.c158
1 files changed, 10 insertions, 148 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index c53f4d424..a800dae73 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -39,6 +39,7 @@
39#define VERBOSE_ARM GNUNET_NO 39#define VERBOSE_ARM GNUNET_NO
40 40
41#define START_ARM GNUNET_YES 41#define START_ARM GNUNET_YES
42#define DEBUG_MEASUREMENT GNUNET_NO
42 43
43/** 44/**
44 * Note that this value must not significantly exceed 45 * Note that this value must not significantly exceed
@@ -179,81 +180,6 @@ get_size_new (unsigned int iter)
179} 180}
180 181
181static void 182static void
182notify_receive (void *cls,
183 const struct GNUNET_PeerIdentity *peer,
184 const struct GNUNET_MessageHeader *message,
185 struct GNUNET_TIME_Relative latency,
186 uint32_t distance)
187{
188 static int n;
189 unsigned int s;
190 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
191 const struct TestMessage *hdr;
192
193 hdr = (const struct TestMessage*) message;
194 s = get_size (n);
195 if (MTYPE != ntohs (message->type))
196 return;
197 msg_recv_expected = n;
198 msg_recv = ntohl(hdr->num);
199 if (ntohs (message->size) != s)
200 {
201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
202 "Expected message %u of size %u, got %u bytes of message %u\n",
203 n, s,
204 ntohs (message->size),
205 ntohl (hdr->num));
206 GNUNET_SCHEDULER_cancel (sched, die_task);
207 die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
208 return;
209 }
210 if (ntohl (hdr->num) != n)
211 {
212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
213 "Expected message %u of size %u, got %u bytes of message %u\n",
214 n, s,
215 ntohs (message->size),
216 ntohl (hdr->num));
217 GNUNET_SCHEDULER_cancel (sched, die_task);
218 die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
219 return;
220 }
221 memset (cbuf, n, s - sizeof (struct TestMessage));
222 if (0 != memcmp (cbuf,
223 &hdr[1],
224 s - sizeof (struct TestMessage)))
225 {
226 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
227 "Expected message %u with bits %u, but body did not match\n",
228 n, (unsigned char) n);
229 GNUNET_SCHEDULER_cancel (sched, die_task);
230 die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
231 return;
232 }
233#if VERBOSE
234 if (ntohl(hdr->num) % 5000 == 0)
235 {
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
237 "Got message %u of size %u\n",
238 ntohl (hdr->num),
239 ntohs (message->size));
240 }
241#endif
242 n++;
243 if (0 == (n % (TOTAL_MSGS/100)))
244 {
245 fprintf (stderr, ".");
246 GNUNET_SCHEDULER_cancel (sched, die_task);
247 die_task = GNUNET_SCHEDULER_add_delayed (sched,
248 TIMEOUT,
249 &end_badly,
250 NULL);
251 }
252 if (n == TOTAL_MSGS)
253 end ();
254}
255
256static void
257notify_receive_new (void *cls, 183notify_receive_new (void *cls,
258 const struct GNUNET_PeerIdentity *peer, 184 const struct GNUNET_PeerIdentity *peer,
259 const struct GNUNET_MessageHeader *message, 185 const struct GNUNET_MessageHeader *message,
@@ -310,7 +236,7 @@ notify_receive_new (void *cls,
310 return; 236 return;
311 } 237 }
312 */ 238 */
313#if VERBOSE 239#if DEBUG_MEASUREMENT
314 if (ntohl(hdr->num) % 5000 == 0) 240 if (ntohl(hdr->num) % 5000 == 0)
315 { 241 {
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -320,7 +246,9 @@ notify_receive_new (void *cls,
320 } 246 }
321#endif 247#endif
322 n++; 248 n++;
323 if (0 == (n % (TOTAL_MSGS/100))) 249
250
251 if (0 == (n % (TOTAL_MSGS/1000)))
324 { 252 {
325 fprintf (stderr, "."); 253 fprintf (stderr, ".");
326 GNUNET_SCHEDULER_cancel (sched, die_task); 254 GNUNET_SCHEDULER_cancel (sched, die_task);
@@ -329,73 +257,6 @@ notify_receive_new (void *cls,
329 &end_badly, 257 &end_badly,
330 NULL); 258 NULL);
331 } 259 }
332/*
333 if (n == TOTAL_MSGS)
334 end ();*/
335}
336
337static size_t
338notify_ready (void *cls, size_t size, void *buf)
339{
340 static int n;
341 char *cbuf = buf;
342 struct TestMessage hdr;
343 unsigned int s;
344 unsigned int ret;
345
346 if (buf == NULL)
347 {
348 GNUNET_break (0);
349 ok = 42;
350 return 0;
351 }
352 ret = 0;
353 s = get_size (n);
354 GNUNET_assert (size >= s);
355 GNUNET_assert (buf != NULL);
356 cbuf = buf;
357 do
358 {
359 hdr.header.size = htons (s);
360 hdr.header.type = htons (MTYPE);
361 hdr.num = htonl (n);
362 msg_sent = n;
363 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
364 ret += sizeof (struct TestMessage);
365 memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
366 ret += s - sizeof (struct TestMessage);
367#if VERBOSE
368 if (n % 5000 == 0)
369 {
370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
371 "Sending message %u of size %u\n",
372 n,
373 s);
374 }
375#endif
376 n++;
377 s = get_size (n);
378 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
379 break; /* sometimes pack buffer full, sometimes not */
380 }
381 while (size - ret >= s);
382 if (n < TOTAL_MSGS)
383 {
384 GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
385 &p1.id,
386 s, 0, TIMEOUT,
387 &notify_ready,
388 NULL);
389 msg_scheduled = n;
390 }
391 if (n % 5000 == 0)
392 {
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "Returning total message block of size %u\n",
395 ret);
396 }
397 total_bytes += ret;
398 return ret;
399} 260}
400 261
401static size_t 262static size_t
@@ -428,7 +289,7 @@ notify_ready_new (void *cls, size_t size, void *buf)
428 ret += sizeof (struct TestMessage); 289 ret += sizeof (struct TestMessage);
429 memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); 290 memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
430 ret += s - sizeof (struct TestMessage); 291 ret += s - sizeof (struct TestMessage);
431#if VERBOSE 292#if DEBUG_MEASUREMENT
432 if (n % 5000 == 0) 293 if (n % 5000 == 0)
433 { 294 {
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -446,8 +307,8 @@ notify_ready_new (void *cls, size_t size, void *buf)
446 s, 0, TIMEOUT, 307 s, 0, TIMEOUT,
447 &notify_ready_new, 308 &notify_ready_new,
448 NULL); 309 NULL);
449 msg_scheduled = n; 310 msg_scheduled = n;
450 total_bytes += ret; 311 total_bytes += s;
451 return ret; 312 return ret;
452} 313}
453 314
@@ -455,9 +316,10 @@ static void
455stop_measurement (void *cls, 316stop_measurement (void *cls,
456 const struct GNUNET_SCHEDULER_TaskContext *tc) 317 const struct GNUNET_SCHEDULER_TaskContext *tc)
457{ 318{
319 struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
458 320
459 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
460 "END OF MEASUREMENT %u bytes sent \n ", total_bytes); 322 "Measurement: %u bytes sent in %llu sec. : %llu\n kb/s", total_bytes, (duration.value/1000) ,(total_bytes/(duration.value / 1000)/1024));
461 323
462 end(); 324 end();
463} 325}