aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-03-13 15:01:42 +0000
committerBart Polot <bart@net.in.tum.de>2014-03-13 15:01:42 +0000
commit5516effa03143377dab7a839abc8580d249cca85 (patch)
treeaca8de7435649f56b3666d9a60b51ca707290adf /src
parent0fcf414562219d1b2016df33eb43a6a3899b557f (diff)
downloadgnunet-5516effa03143377dab7a839abc8580d249cca85.tar.gz
gnunet-5516effa03143377dab7a839abc8580d249cca85.zip
- change cls to pointers instead of indexes
Diffstat (limited to 'src')
-rw-r--r--src/mesh/mesh_profiler.c82
1 files changed, 39 insertions, 43 deletions
diff --git a/src/mesh/mesh_profiler.c b/src/mesh/mesh_profiler.c
index b15f2acf1..7c74a59ee 100644
--- a/src/mesh/mesh_profiler.c
+++ b/src/mesh/mesh_profiler.c
@@ -77,6 +77,16 @@ struct MeshPeer
77 */ 77 */
78 struct GNUNET_MESH_Channel *incoming_ch; 78 struct GNUNET_MESH_Channel *incoming_ch;
79 79
80 /**
81 * Number of payload packes sent
82 */
83 int data_sent;
84
85 /**
86 * Number of payload packets received
87 */
88 int data_received;
89
80 unsigned int dest; 90 unsigned int dest;
81 GNUNET_SCHEDULER_TaskIdentifier ping_task; 91 GNUNET_SCHEDULER_TaskIdentifier ping_task;
82}; 92};
@@ -122,21 +132,6 @@ unsigned int p_ids;
122static int initialized; 132static int initialized;
123 133
124/** 134/**
125 * Number of payload packes sent
126 */
127static int data_sent;
128
129/**
130 * Number of payload packets received
131 */
132static int data_received;
133
134/**
135 * Number of payload packed explicitly (app level) acknowledged
136 */
137static int data_ack;
138
139/**
140 * Total number of currently running peers. 135 * Total number of currently running peers.
141 */ 136 */
142static unsigned long long peers_running; 137static unsigned long long peers_running;
@@ -173,6 +168,21 @@ static struct GNUNET_TIME_Absolute start_time;
173static unsigned int ka_sent; 168static unsigned int ka_sent;
174static unsigned int ka_received; 169static unsigned int ka_received;
175 170
171/**
172 * Calculate a random delay.
173 *
174 * @param max Exclusive maximum, in ms.
175 *
176 * @return A time between 0 a max-1 ms.
177 */
178static struct GNUNET_TIME_Relative
179delay_ms_rnd (unsigned int max)
180{
181 unsigned int rnd;
182
183 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
184 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
185}
176 186
177/** 187/**
178 * Show the results of the test (banwidth acheived) and log them to GAUGER 188 * Show the results of the test (banwidth acheived) and log them to GAUGER
@@ -342,7 +352,7 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
342/** 352/**
343 * Transmit ready callback. 353 * Transmit ready callback.
344 * 354 *
345 * @param cls Closure (message type). 355 * @param cls Closure (peer).
346 * @param size Size of the tranmist buffer. 356 * @param size Size of the tranmist buffer.
347 * @param buf Pointer to the beginning of the buffer. 357 * @param buf Pointer to the beginning of the buffer.
348 * 358 *
@@ -355,25 +365,25 @@ tmt_rdy (void *cls, size_t size, void *buf);
355/** 365/**
356 * Task to schedule a new data transmission. 366 * Task to schedule a new data transmission.
357 * 367 *
358 * @param cls Closure (peer #). 368 * @param cls Closure (peer).
359 * @param tc Task Context. 369 * @param tc Task Context.
360 */ 370 */
361static void 371static void
362data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 372data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
363{ 373{
374 struct MeshPeer *peer = (struct MeshPeer *) cls;
364 struct GNUNET_MESH_TransmitHandle *th; 375 struct GNUNET_MESH_TransmitHandle *th;
365 struct GNUNET_MESH_Channel *channel; 376 struct GNUNET_MESH_Channel *channel;
366 long n = (long) cls;
367 377
368 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) 378 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
369 return; 379 return;
370 380
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n"); 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
372 382
373 channel = peers[n].ch; 383 channel = peer->ch;
374 th = GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO, 384 th = GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO,
375 GNUNET_TIME_UNIT_FOREVER_REL, 385 GNUNET_TIME_UNIT_FOREVER_REL,
376 size_payload, &tmt_rdy, (void *) 1L); 386 size_payload, &tmt_rdy, peer);
377 if (NULL == th) 387 if (NULL == th)
378 GNUNET_abort (); 388 GNUNET_abort ();
379} 389}
@@ -382,13 +392,14 @@ data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
382/** 392/**
383 * Transmit ready callback 393 * Transmit ready callback
384 * 394 *
385 * @param cls Closure (message type). 395 * @param cls Closure (peer).
386 * @param size Size of the buffer we have. 396 * @param size Size of the buffer we have.
387 * @param buf Buffer to copy data to. 397 * @param buf Buffer to copy data to.
388 */ 398 */
389size_t 399size_t
390tmt_rdy (void *cls, size_t size, void *buf) 400tmt_rdy (void *cls, size_t size, void *buf)
391{ 401{
402 struct MeshPeer *peer = (struct MeshPeer *) cls;
392 struct GNUNET_MessageHeader *msg = buf; 403 struct GNUNET_MessageHeader *msg = buf;
393 uint32_t *data; 404 uint32_t *data;
394 405
@@ -398,7 +409,7 @@ tmt_rdy (void *cls, size_t size, void *buf)
398 GNUNET_break (ok >= ok_goal - 2); 409 GNUNET_break (ok >= ok_goal - 2);
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
400 "size %u, buf %p, data_sent %u, data_received %u\n", 411 "size %u, buf %p, data_sent %u, data_received %u\n",
401 size, buf, data_sent, data_received); 412 size, buf, peer->data_sent, peer->data_received);
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok %u, ok goal %u\n", ok, ok_goal); 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok %u, ok goal %u\n", ok, ok_goal);
403 414
404 return 0; 415 return 0;
@@ -406,7 +417,7 @@ tmt_rdy (void *cls, size_t size, void *buf)
406 msg->size = htons (size); 417 msg->size = htons (size);
407 msg->type = htons ((long) cls); 418 msg->type = htons ((long) cls);
408 data = (uint32_t *) &msg[1]; 419 data = (uint32_t *) &msg[1];
409 *data = htonl (data_sent); 420 *data = htonl (peer->data_sent);
410 if (GNUNET_NO == initialized) 421 if (GNUNET_NO == initialized)
411 { 422 {
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -414,14 +425,14 @@ tmt_rdy (void *cls, size_t size, void *buf)
414 } 425 }
415 else 426 else
416 { 427 {
417 data_sent++; 428 peer->data_sent++;
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 " Sent packet %d\n", data_sent); 430 " Sent packet %d\n", peer->data_sent);
420 if (data_sent < TOTAL_PACKETS) 431 if (peer->data_sent < TOTAL_PACKETS)
421 { 432 {
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 " Scheduling packet %d\n", data_sent + 1); 434 " Scheduling packet %d\n", peer->data_sent + 1);
424 GNUNET_SCHEDULER_add_now (&data_task, NULL); 435 GNUNET_SCHEDULER_add_now (&data_task, peer);
425 } 436 }
426 } 437 }
427 438
@@ -563,16 +574,6 @@ ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
563} 574}
564 575
565 576
566static struct GNUNET_TIME_Relative
567delay_ms_rnd (unsigned int max)
568{
569 unsigned int rnd;
570
571 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
572 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
573}
574
575
576/** 577/**
577 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES. 578 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
578 * 579 *
@@ -611,11 +612,6 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
611 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd(2000), 612 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd(2000),
612 &ping, &peers[i]); 613 &ping, &peers[i]);
613 } 614 }
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending data initializer...\n");
615 data_ack = 0;
616 data_received = 0;
617 data_sent = 0;
618
619} 615}
620 616
621 617