2 This file is part of GNUnet.
3 (C) 2011, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file stream/perf_stream_api.c
23 * @brief performance benchmarks for stream api
24 * @author Sree Harsha Totakura
27 #define LOG(kind, ...) \
28 GNUNET_log (kind, __VA_ARGS__);
30 /****************************************************************************************/
31 /* Test is setup into the following major steps: */
32 /* 1. Measurements over loopback (1 hop). i.e. we use only one peer and open */
33 /* stream connections over loopback. Messages will go through */
34 /* STREAM_API->MESH_API->MESH_SERVICE->MESH_API->STREAM_API. */
35 /* 2. Measurements over 2 peers (2 hops). We use testbed to create 2 peers, */
36 /* connect them and then create stream connections. Messages will go through */
37 /* STREAM_API->MESH_API->MESH_SERVICE->CORE1.....CORE2->MESH_API->STREAM_API */
38 /* 3. Measurements over 3 peers (3 hops). We use testbed to create 3 peers, */
39 /* connect them in a line topology: peer1->peer2->peer3. Messages will go */
41 /* STREAM_API->MESH_API->MESH_SERVICE->CORE1..CORE2..CORE3->MESH_API->STREAM_API. */
42 /****************************************************************************************/
45 #include "gnunet_common.h"
46 #include "gnunet_util_lib.h"
47 #include "gnunet_testbed_service.h"
48 #include "gnunet_stream_lib.h"
51 * Simple struct to keep track of progress, and print a
52 * nice little percentage meter for long running tasks.
62 unsigned int completed;
76 * Single hop loopback testing
81 * Testing with 2 peers
86 * Testing with 3 peers
93 * Structure for holding peer's sockets and IO Handles
98 * Peer's stream socket
100 struct GNUNET_STREAM_Socket *socket;
103 * Peer's io write handle
105 struct GNUNET_STREAM_WriteHandle *io_write_handle;
108 * Peer's io read handle
110 struct GNUNET_STREAM_ReadHandle *io_read_handle;
113 * The peer handle when we use the testbed servie
115 struct GNUNET_TESTBED_Peer *peer;
118 * Handle to peer specific opearations while using testbed service
120 struct GNUNET_TESTBED_Operation *op;
123 * The identity of this peer
125 struct GNUNET_PeerIdentity id;
128 * Peer's shutdown handle
130 struct GNUNET_STREAM_ShutdownHandle *shutdown_handle;
133 * Bytes the peer has written
138 * Byte the peer has read
143 * number of packets sent
145 unsigned int packets_wrote;
148 * number of packets read
150 unsigned int packets_read;
155 * Enumeration of stages in this testing
165 * Uplink testing stage
170 * Downlink testing stage
177 * Maximum size of the data which we will transfer during tests
179 #define DATA_SIZE 5000000 /* 5mB */
182 * Fixed number of packets we send in each direction during each subtest
184 #define MAX_PACKETS 1000
187 * Listen socket of peer2
189 struct GNUNET_STREAM_ListenSocket *peer2_listen_socket;
192 * Handle to configuration during TEST_STEP_1_HOP
194 const struct GNUNET_CONFIGURATION_Handle *config;
197 * Handle for the progress meter
199 static struct ProgressMeter *meter;
202 * Placeholder for peer data
204 static struct PeerData peer_data[3];
207 * Handle to common operations while using testbed
209 static struct GNUNET_TESTBED_Operation *common_op;
212 * Task ID for abort task
214 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
217 * Task ID for write task
219 static GNUNET_SCHEDULER_TaskIdentifier write_task;
222 * Task ID for read task
224 static GNUNET_SCHEDULER_TaskIdentifier read_task;
227 * Absolute time when profiling starts
229 static struct GNUNET_TIME_Absolute prof_start_time;
232 * Test time taken for sending the data
234 static struct GNUNET_TIME_Relative prof_time;
237 * Random data block. Should generate data first
239 static uint32_t data[DATA_SIZE / 4];
242 * Payload sizes to test each major test with
244 static uint16_t payload_size[] =
245 { 20, 500, 2000, 7000, 13000, 25000, 30000};//, 50000, 60000, 63000, 64000 };
248 * Current step of testing
250 static enum TestStep test_step;
253 * Index for choosing payload size
255 static unsigned int payload_size_index;
258 * Number of peers we want to create while using the testbed service
260 static int num_peers;
263 * Flag to indicate that the other peer should reset its data read source index
265 static int reset_read;
268 * Testing result of a major test
270 static enum TestStage result;
273 * Create a meter to keep track of the progress of some task.
275 * @param total the total number of items to complete
276 * @param start_string a string to prefix the meter with (if printing)
277 * @param print GNUNET_YES to print the meter, GNUNET_NO to count
280 * @return the progress meter
282 static struct ProgressMeter *
283 create_meter (unsigned int total, char *start_string, int print)
285 struct ProgressMeter *ret;
287 ret = GNUNET_malloc (sizeof (struct ProgressMeter));
290 ret->modnum = total / 4;
291 if (ret->modnum == 0) /* Divide by zero check */
293 ret->dotnum = (total / 50) + 1;
294 if (start_string != NULL)
295 ret->startup_string = GNUNET_strdup (start_string);
297 ret->startup_string = GNUNET_strdup ("");
304 * Update progress meter (increment by one).
306 * @param meter the meter to update and print info for
308 * @return GNUNET_YES if called the total requested,
309 * GNUNET_NO if more items expected
312 update_meter (struct ProgressMeter *meter)
314 if (meter->print == GNUNET_YES)
316 if (meter->completed % meter->modnum == 0)
318 if (meter->completed == 0)
320 FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string);
323 FPRINTF (stdout, "%d%%",
324 (int) (((float) meter->completed / meter->total) * 100));
326 else if (meter->completed % meter->dotnum == 0)
327 FPRINTF (stdout, "%s", ".");
329 if (meter->completed + 1 == meter->total)
330 FPRINTF (stdout, "%d%%]\n", 100);
335 if (meter->completed == meter->total)
337 if (meter->completed > meter->total)
338 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
344 * Reset progress meter.
346 * @param meter the meter to reset
348 * @return GNUNET_YES if meter reset,
349 * GNUNET_SYSERR on error
352 reset_meter (struct ProgressMeter *meter)
355 return GNUNET_SYSERR;
357 meter->completed = 0;
363 * Release resources for meter
365 * @param meter the meter to free
368 free_meter (struct ProgressMeter *meter)
370 GNUNET_free_non_null (meter->startup_string);
379 do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
383 case TEST_STEP_1_HOP:
384 if (NULL != peer_data[0].socket)
385 GNUNET_STREAM_close (peer_data[0].socket);
386 if (NULL != peer_data[1].socket)
387 GNUNET_STREAM_close (peer_data[1].socket);
388 if (NULL != peer2_listen_socket)
389 GNUNET_STREAM_listen_close (peer2_listen_socket); /* Close listen socket */
391 case TEST_STEP_2_HOP:
392 if (NULL != peer_data[1].socket)
393 GNUNET_STREAM_close (peer_data[1].socket);
394 if (NULL != peer_data[0].op)
395 GNUNET_TESTBED_operation_done (peer_data[0].op);
396 if (NULL != peer_data[1].op)
397 GNUNET_TESTBED_operation_done (peer_data[1].op);
399 case TEST_STEP_3_HOP:
402 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
403 GNUNET_SCHEDULER_cancel (abort_task);
404 if (GNUNET_SCHEDULER_NO_TASK != write_task)
405 GNUNET_SCHEDULER_cancel (write_task);
406 GNUNET_SCHEDULER_shutdown (); /* Shutdown this testcase */
416 * Something went wrong and timed out. Kill everything and set error flag
419 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
421 abort_task = GNUNET_SCHEDULER_NO_TASK;
422 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: ABORT\n");
423 if (GNUNET_SCHEDULER_NO_TASK != read_task)
424 GNUNET_SCHEDULER_cancel (read_task);
425 result = GNUNET_SYSERR;
431 * Completion callback for shutdown
433 * @param cls the closure from GNUNET_STREAM_shutdown call
434 * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR,
438 shutdown_completion (void *cls,
441 static int shutdowns;
443 if (++shutdowns == 1)
445 peer_data[0].shutdown_handle = NULL;
446 peer_data[1].shutdown_handle = GNUNET_STREAM_shutdown (peer_data[1].socket, SHUT_RDWR,
447 &shutdown_completion, cls);
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STREAM shutdown successful\n");
451 GNUNET_SCHEDULER_add_now (&do_close, cls);
456 * Shutdown sockets gracefully
459 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
461 peer_data[0].shutdown_handle = GNUNET_STREAM_shutdown (peer_data[0].socket, SHUT_RDWR,
462 &shutdown_completion, cls);
467 * Scheduler call back; to be executed when a new stream is connected
468 * Called from listen connect for peer2
471 stream_read_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
475 * Task for calling STREAM_write with a chunk of random data
477 * @param cls the peer data entity
478 * @param tc the task context
481 stream_write_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
485 * The write completion function; called upon writing some data to stream or
488 * @param cls the closure from GNUNET_STREAM_write/read
489 * @param status the status of the stream at the time this function is called
490 * @param size the number of bytes written
493 write_completion (void *cls, enum GNUNET_STREAM_Status status, size_t size)
495 struct PeerData *pdata = cls;
497 double prof_time_sec;
498 unsigned int packets_wrote;
500 if (GNUNET_STREAM_OK != status)
502 GNUNET_SCHEDULER_cancel (abort_task);
503 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
506 GNUNET_assert (size <= DATA_SIZE);
507 packets_wrote = (size + payload_size[payload_size_index] - 1)
508 / payload_size[payload_size_index];
509 pdata->bytes_wrote += size;
510 for (;packets_wrote > 0; packets_wrote--)
512 update_meter (meter);
513 pdata->packets_wrote++;
515 if (pdata->packets_wrote < MAX_PACKETS) /* Have more data to send */
519 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
521 GNUNET_SCHEDULER_cancel (abort_task);
523 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
524 (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort,
527 write_amount = (MAX_PACKETS - pdata->packets_wrote) *
528 payload_size[payload_size_index];
529 if (write_amount > DATA_SIZE)
530 write_amount = DATA_SIZE;
531 reset_read = GNUNET_YES;
532 pdata->io_write_handle = GNUNET_STREAM_write (pdata->socket, data,
534 GNUNET_TIME_UNIT_FOREVER_REL,
535 &write_completion, pdata);
536 GNUNET_assert (NULL != pdata->io_write_handle);
542 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
543 prof_time_sec = (((double) prof_time.rel_value)/ ((double) 1000));
544 throughput = ((float) pdata->bytes_wrote) / prof_time_sec;
545 PRINTF ("Throughput %.2f kB/sec\n", throughput / 1000.00);
550 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == read_task);
551 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == write_task);
552 pdata->bytes_read = 0;
553 pdata->packets_read = 0;
554 meter = create_meter (MAX_PACKETS, "Testing Downlink\n", GNUNET_YES);
555 read_task = GNUNET_SCHEDULER_add_now (&stream_read_task, &peer_data[0]);
556 write_task = GNUNET_SCHEDULER_add_now (&stream_write_task, &peer_data[1]);
559 result = DOWNLINK_OK;
560 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
570 * Task for calling STREAM_write with a chunk of random data
572 * @param cls the peer data entity
573 * @param tc the task context
576 stream_write_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
578 struct PeerData *pdata = cls;
581 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
583 GNUNET_SCHEDULER_cancel (abort_task);
585 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
586 (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort,
589 write_task = GNUNET_SCHEDULER_NO_TASK;
590 prof_start_time = GNUNET_TIME_absolute_get ();
591 pdata->bytes_wrote = 0;
592 pdata->packets_wrote = 0;
593 write_amount = MAX_PACKETS * payload_size[payload_size_index];
594 if (write_amount > DATA_SIZE)
595 write_amount = DATA_SIZE;
596 reset_read = GNUNET_YES;
597 pdata->io_write_handle = GNUNET_STREAM_write (pdata->socket, data,
599 GNUNET_TIME_UNIT_FOREVER_REL,
600 &write_completion, pdata);
601 GNUNET_assert (NULL != pdata->io_write_handle);
606 * Scheduler call back; to be executed when a new stream is connected
607 * Called from listen connect for peer2
610 stream_read_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
617 * @param status the status of the stream at the time this function is called
618 * @param data traffic from the other side
619 * @param size the number of bytes available in data read
620 * @return number of bytes of processed from 'data' (any data remaining should be
621 * given to the next time the read processor is called).
624 input_processor (void *cls, enum GNUNET_STREAM_Status status,
625 const void *input_data, size_t size)
627 struct PeerData *pdata = cls;
629 if (GNUNET_STREAM_OK != status)
631 GNUNET_SCHEDULER_cancel (abort_task);
632 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
635 GNUNET_assert (size <= DATA_SIZE);
636 if (GNUNET_YES == reset_read)
638 pdata->bytes_read = 0;
639 reset_read = GNUNET_NO;
641 GNUNET_assert ((pdata->bytes_read + size) <= DATA_SIZE);
642 GNUNET_assert (0 == memcmp (((void *)data ) + pdata->bytes_read,
644 pdata->bytes_read += size;
645 pdata->packets_read += (size + payload_size[payload_size_index] - 1)
646 / payload_size[payload_size_index];
647 if (pdata->packets_read < MAX_PACKETS)
649 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == read_task);
650 read_task = GNUNET_SCHEDULER_add_now (&stream_read_task, pdata);
654 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reading finished successfully\n");
661 * Scheduler call back; to be executed when a new stream is connected
662 * Called from listen connect for peer2
665 stream_read_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
667 struct PeerData *pdata = cls;
669 read_task = GNUNET_SCHEDULER_NO_TASK;
670 pdata->io_read_handle =
671 GNUNET_STREAM_read (pdata->socket, GNUNET_TIME_UNIT_FOREVER_REL,
672 &input_processor, pdata);
673 GNUNET_assert (NULL != pdata->io_read_handle);
678 * Functions of this type are called upon new stream connection from other peers
680 * @param cls the closure from GNUNET_STREAM_listen
681 * @param socket the socket representing the stream
682 * @param initiator the identity of the peer who wants to establish a stream
684 * @return GNUNET_OK to keep the socket open, GNUNET_SYSERR to close the
685 * stream (the socket will be invalid after the call)
688 stream_listen_cb (void *cls, struct GNUNET_STREAM_Socket *socket,
689 const struct GNUNET_PeerIdentity *initiator)
691 struct PeerData *pdata = cls;
694 if ((NULL == socket) || (NULL == initiator))
696 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Binding error\n");
697 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
698 GNUNET_SCHEDULER_cancel (abort_task);
699 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
702 GNUNET_assert (NULL != socket);
703 GNUNET_assert (pdata == &peer_data[1]);
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer connected: %s\n",
705 GNUNET_i2s(initiator));
706 pdata->socket = socket;
707 pdata->bytes_read = 0;
708 read_task = GNUNET_SCHEDULER_add_now (&stream_read_task, pdata);
714 * Function executed after stream has been established
716 * @param cls the closure from GNUNET_STREAM_open
717 * @param socket socket to use to communicate with the other side (read/write)
720 stream_open_cb (void *cls,
721 struct GNUNET_STREAM_Socket *socket)
723 struct PeerData *pdata = cls;
725 GNUNET_assert (socket == pdata->socket);
726 meter = create_meter (MAX_PACKETS, "Testing Uplink\n", GNUNET_YES);
727 write_task = GNUNET_SCHEDULER_add_now (&stream_write_task, pdata);
732 * Listen success callback; connects a peer to stream as client
735 stream_connect (void)
737 peer_data[0].socket =
738 GNUNET_STREAM_open (config, &peer_data[1].id, 10, &stream_open_cb,
740 GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE,
741 payload_size[payload_size_index],
742 GNUNET_STREAM_OPTION_END);
743 GNUNET_assert (NULL != peer_data[0].socket);
748 * Initialize framework and start test
751 * @param cfg configuration of the peer that was started
752 * @param peer identity of the peer that was created
756 const struct GNUNET_CONFIGURATION_Handle *cfg,
757 struct GNUNET_TESTING_Peer *peer)
759 struct GNUNET_PeerIdentity id;
761 GNUNET_TESTING_peer_get_identity (peer, &id);
763 peer2_listen_socket =
764 GNUNET_STREAM_listen (config, 10, &stream_listen_cb, &peer_data[1],
765 GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS,
767 GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE,
768 payload_size[payload_size_index],
769 GNUNET_STREAM_OPTION_END);
770 GNUNET_assert (NULL != peer2_listen_socket);
771 peer_data[0].id = id;
772 peer_data[1].id = id;
774 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
775 (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort,
781 * Adapter function called to establish a connection to
785 * @param cfg configuration of the peer to connect to; will be available until
786 * GNUNET_TESTBED_operation_done() is called on the operation returned
787 * from GNUNET_TESTBED_service_connect()
788 * @return service handle to return in 'op_result', NULL on error
791 stream_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
795 * Adapter function called to destroy a connection to
799 * @param op_result service handle returned from the connect adapter
802 stream_da (void *cls, void *op_result)
804 if (&peer_data[1] == cls)
806 GNUNET_STREAM_listen_close (op_result);
809 else if (&peer_data[0] == cls)
811 GNUNET_STREAM_close (op_result);
819 * Listen success callback; connects a peer to stream as client. Called from
823 stream_connect2 (void)
825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stream listen open successful\n");
827 GNUNET_TESTBED_service_connect (&peer_data[0], peer_data[0].peer,
828 "stream", NULL, NULL, stream_ca,
829 stream_da, &peer_data[0]);
834 * Adapter function called to establish a connection to
838 * @param cfg configuration of the peer to connect to; will be available until
839 * GNUNET_TESTBED_operation_done() is called on the operation returned
840 * from GNUNET_TESTBED_service_connect()
841 * @return service handle to return in 'op_result', NULL on error
844 stream_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
846 struct PeerData *pdata = cls;
848 if (&peer_data[1] == pdata)
850 peer2_listen_socket = NULL;
851 peer2_listen_socket =
852 GNUNET_STREAM_listen (cfg, 10, &stream_listen_cb, &peer_data[1],
853 GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS,
855 GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE,
856 payload_size[payload_size_index],
857 GNUNET_STREAM_OPTION_END);
858 GNUNET_assert (NULL != peer2_listen_socket);
859 return peer2_listen_socket;
861 if (&peer_data[0] == pdata)
864 GNUNET_STREAM_open (cfg, &peer_data[1].id, 10, &stream_open_cb,
866 GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE,
867 payload_size[payload_size_index],
868 GNUNET_STREAM_OPTION_END);
869 GNUNET_assert (NULL != pdata->socket);
870 return pdata->socket;
878 * Callback to be called when the requested peer information is available
880 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
881 * @param op the operation this callback corresponds to
882 * @param pinfo the result; will be NULL if the operation has failed
883 * @param emsg error message if the operation has failed; will be NULL if the
884 * operation is successfull
887 peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
888 const struct GNUNET_TESTBED_PeerInformation *pinfo,
891 struct PeerData *pdata = cb_cls;
893 GNUNET_assert (NULL == emsg);
894 GNUNET_assert (common_op == op);
895 GNUNET_assert (NULL != pdata);
896 memcpy (&pdata->id, pinfo->result.id, sizeof (struct GNUNET_PeerIdentity));
897 GNUNET_TESTBED_operation_done (op);
898 if (pdata == &peer_data[0])
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n",
901 GNUNET_i2s (&pdata->id));
902 common_op = GNUNET_TESTBED_peer_get_information (peer_data[1].peer,
903 GNUNET_TESTBED_PIT_IDENTITY,
904 &peerinfo_cb, &peer_data[1]);
906 else if (pdata == &peer_data[1])
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n",
909 GNUNET_i2s (&pdata->id));
910 if (TEST_STEP_2_HOP == test_step)
912 GNUNET_TESTBED_service_connect (&peer_data[1], peer_data[1].peer,
913 "stream", NULL, NULL, stream_ca,
914 stream_da, &peer_data[1]);
916 GNUNET_break (0); /* FIXME: 3 hop test case here... */
922 * Controller event callback
925 * @param event the controller event
928 controller_event_cb (void *cls,
929 const struct GNUNET_TESTBED_EventInformation *event)
933 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
934 if (NULL != event->details.operation_finished.emsg)
936 FPRINTF (stderr, "Error while expecting an operation to succeed:%s \n",
937 event->details.operation_finished.emsg);
948 * Signature of a main function for a testcase.
951 * @param num_peers number of peers in 'peers'
952 * @param peers handle to peers run in the testbed
955 test_master (void *cls, unsigned int num_peers_,
956 struct GNUNET_TESTBED_Peer **peers)
958 GNUNET_assert (NULL != peers);
959 GNUNET_assert (NULL != peers[0]);
960 GNUNET_assert (NULL != peers[1]);
961 GNUNET_assert (num_peers_ == num_peers);
962 peer_data[0].peer = peers[0];
963 peer_data[1].peer = peers[1];
965 /* Get the peer identity and configuration of peers */
967 GNUNET_TESTBED_peer_get_information (peer_data[0].peer,
968 GNUNET_TESTBED_PIT_IDENTITY,
969 &peerinfo_cb, &peer_data[0]);
973 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
974 (GNUNET_TIME_UNIT_SECONDS, 120), &do_abort,
982 int main (int argc, char **argv)
984 char *test_name = "perf_stream_api";
985 char *cfg_file = "test_stream_local.conf";
990 meter = create_meter ((sizeof (data) / 4), "Generating random data\n", GNUNET_YES);
991 for (count=0; count < (sizeof (data) / 4); count++)
993 data[count] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
995 update_meter (meter);
1000 test_step = TEST_STEP_1_HOP;
1001 for (payload_size_index = 0;
1002 payload_size_index < (sizeof (payload_size) / sizeof (uint16_t));
1003 payload_size_index++)
1005 PRINTF ("\nTesting over loopback with payload size %hu\n",
1006 payload_size[payload_size_index]);
1007 (void) memset (peer_data, 0, sizeof (peer_data));
1009 reset_read = GNUNET_NO;
1010 ret = GNUNET_TESTING_peer_run (test_name, cfg_file, &run, NULL);
1011 if ((0 != ret) || (DOWNLINK_OK != result))
1014 test_step = TEST_STEP_2_HOP;
1017 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1018 for (payload_size_index = 0;
1019 payload_size_index < (sizeof (payload_size) / sizeof (uint16_t));
1020 payload_size_index++)
1022 PRINTF ("\nTesting over 1 hop with payload size %hu\n",
1023 payload_size[payload_size_index]);
1024 (void) memset (peer_data, 0, sizeof (peer_data));
1026 reset_read = GNUNET_NO;
1027 (void) GNUNET_TESTBED_test_run (test_name, cfg_file, num_peers, event_mask,
1028 &controller_event_cb, NULL, &test_master,
1030 if (DOWNLINK_OK != result)
1033 test_step = TEST_STEP_3_HOP;
1034 for (payload_size_index = 0;
1035 payload_size_index < (sizeof (payload_size) / sizeof (uint16_t));
1036 payload_size_index++)
1038 /* Initialize testbed here */
1043 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test failed\n");
1047 /* end of perf_stream_api.c */