2 This file is part of GNUnet.
3 Copyright (C) 2010-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file ats-tests/ats-testing.h
22 * @brief ats testing library: setup topology and provide logging to test ats
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testbed_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet_core_service.h"
32 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
35 * Message type sent for traffic generation
37 #define TEST_MESSAGE_TYPE_PING 12345
40 * Message type sent as response during traffic generation
42 #define TEST_MESSAGE_TYPE_PONG 12346
45 * Size of test messages
47 #define TEST_MESSAGE_SIZE 100
49 struct BenchmarkPartner;
53 struct GNUNET_ATS_TEST_Topology;
55 struct TrafficGenerator;
61 GNUNET_ATS_TEST_TG_LINEAR,
62 GNUNET_ATS_TEST_TG_CONSTANT,
63 GNUNET_ATS_TEST_TG_RANDOM,
64 GNUNET_ATS_TEST_TG_SINUS
69 * Callback to call when topology setup is completed
71 * @param cls the closure
72 * @param masters array of master peers
73 * @param slaves array of master peers
75 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
76 struct BenchmarkPeer *masters,
77 struct BenchmarkPeer *slaves);
80 * Callback called when logging is required for the data contained
82 * @param cls the closure
83 * @param address an address
84 * @param address_active is address active
85 * @param bandwidth_out bandwidth outbound
86 * @param bandwidth_in bandwidth inbound
87 * @param prop performance information
90 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
91 const struct GNUNET_HELLO_Address *address,
93 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
94 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
95 const struct GNUNET_ATS_Properties *prop);
98 * Information we track for a peer in the testbed.
103 * Handle with testbed.
105 struct GNUNET_TESTBED_Peer *peer;
113 * Is this peer a measter: GNUNET_YES/GNUNET_NO
120 struct GNUNET_PeerIdentity id;
123 * Testbed operation to get peer information
125 struct GNUNET_TESTBED_Operation *peer_id_op;
128 * Testbed operation to connect to ATS performance service
130 struct GNUNET_TESTBED_Operation *ats_perf_op;
133 * Testbed operation to connect to core
135 struct GNUNET_TESTBED_Operation *comm_op;
138 * ATS performance handle
140 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
144 * Testbed connect operations to connect masters to slaves
146 struct TestbedConnectOperation *core_connect_ops;
151 struct GNUNET_CORE_Handle *ch;
156 struct GNUNET_TRANSPORT_Handle *th;
160 * Peer to set ATS preferences for
162 struct BenchmarkPeer *pref_partner;
168 struct GNUNET_SCHEDULER_Task * ats_task;
177 * Array of partners with num_slaves entries (if master) or
178 * num_master entries (if slave)
180 struct BenchmarkPartner *partners;
188 * Number of core connections
190 int core_connections;
194 * Number of connections to slave peers
196 int core_slave_connections;
199 * Total number of messages this peer has sent
201 unsigned int total_messages_sent;
204 * Total number of bytes this peer has sent
206 unsigned int total_bytes_sent;
209 * Total number of messages this peer has received
211 unsigned int total_messages_received;
214 * Total number of bytes this peer has received
216 unsigned int total_bytes_received;
219 struct TrafficGenerator
221 struct TrafficGenerator *prev;
222 struct TrafficGenerator *next;
224 enum GeneratorType type;
226 struct BenchmarkPeer *src;
227 struct BenchmarkPartner *dest;
231 struct GNUNET_TIME_Relative duration_period;
233 struct GNUNET_SCHEDULER_Task * send_task;
234 struct GNUNET_TIME_Absolute next_ping_transmission;
235 struct GNUNET_TIME_Absolute time_start;
239 struct PreferenceGenerator
241 struct PreferenceGenerator *prev;
242 struct PreferenceGenerator *next;
244 enum GeneratorType type;
246 struct BenchmarkPeer *src;
247 struct BenchmarkPartner *dest;
249 enum GNUNET_ATS_PreferenceKind kind;
253 struct GNUNET_TIME_Relative duration_period;
254 struct GNUNET_TIME_Relative frequency;
256 struct GNUNET_SCHEDULER_Task * set_task;
257 struct GNUNET_TIME_Absolute next_ping_transmission;
258 struct GNUNET_TIME_Absolute time_start;
262 * Information about a benchmarking partner
264 struct BenchmarkPartner
267 * The peer itself this partner belongs to
269 struct BenchmarkPeer *me;
274 struct BenchmarkPeer *dest;
277 * Core transmit handles
279 struct GNUNET_CORE_TransmitHandle *cth;
282 * Transport transmit handles
284 struct GNUNET_TRANSPORT_TransmitHandle *tth;
288 * Handle for traffic generator
290 struct TrafficGenerator *tg;
293 * Handle for preference generator
295 struct PreferenceGenerator *pg;
298 * Timestamp to calculate communication layer delay
300 struct GNUNET_TIME_Absolute last_message_sent;
303 * Accumulated RTT for all messages
305 unsigned int total_app_rtt;
308 * Number of messages sent to this partner
310 unsigned int messages_sent;
313 * Number of bytes sent to this partner
315 unsigned int bytes_sent;
318 * Number of messages received from this partner
320 unsigned int messages_received;
323 * Number of bytes received from this partner
325 unsigned int bytes_received;
327 /* Current ATS properties */
328 struct GNUNET_ATS_Properties props;
330 /* Bandwidth assigned inbound */
331 uint32_t bandwidth_in;
333 /* Bandwidth assigned outbound */
334 uint32_t bandwidth_out;
336 /* Current preference values for bandwidth */
337 double pref_bandwidth;
339 /* Current preference values for delay */
346 * Overall state of the performance benchmark
348 struct BenchmarkState
351 * Are we connected to ATS service of all peers: GNUNET_YES/NO
353 int connected_ATS_service;
356 * Are we connected to CORE service of all peers: GNUNET_YES/NO
358 int connected_COMM_service;
361 * Are we connected to all peers: GNUNET_YES/NO
366 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
371 * Are we connected to CORE service of all peers: GNUNET_YES/NO
377 struct GNUNET_ATS_TEST_Topology
382 struct GNUNET_SCHEDULER_Task * shutdown_task;
387 struct GNUNET_SCHEDULER_Task * progress_task;
394 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
414 * ATS preference value
419 * Number master peers
421 unsigned int num_masters;
424 * Array of master peers
426 struct BenchmarkPeer *mps;
431 unsigned int num_slaves;
434 * Array of slave peers
436 struct BenchmarkPeer *sps;
441 struct GNUNET_TIME_Relative perf_duration;
446 struct GNUNET_TIME_Relative log_frequency;
451 struct BenchmarkState state;
453 struct GNUNET_CORE_MessageHandler *handlers;
455 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
457 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
458 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
474 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
477 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
478 struct GNUNET_TIME_Relative duration,int success);
481 * An operation in an experiment
483 struct GNUNET_ATS_TEST_Operation
485 struct GNUNET_ATS_TEST_Operation *next;
486 struct GNUNET_ATS_TEST_Operation *prev;
488 long long unsigned int src_id;
489 long long unsigned int dest_id;
491 long long unsigned int base_rate;
492 long long unsigned int max_rate;
493 struct GNUNET_TIME_Relative period;
494 struct GNUNET_TIME_Relative frequency;
496 enum OperationType type;
497 enum GeneratorType gen_type;
498 enum GNUNET_ATS_PreferenceKind pref_type;
504 struct Episode *next;
505 struct GNUNET_TIME_Relative duration;
507 struct GNUNET_ATS_TEST_Operation *head;
508 struct GNUNET_ATS_TEST_Operation *tail;
516 unsigned long long int num_masters;
517 unsigned long long int num_slaves;
518 struct GNUNET_TIME_Relative log_freq;
519 struct GNUNET_TIME_Relative max_duration;
520 struct GNUNET_TIME_Relative total_duration;
521 struct GNUNET_TIME_Absolute start_time;
522 unsigned int num_episodes;
523 struct Episode *start;
525 struct GNUNET_SCHEDULER_Task * experiment_timeout_task;
526 struct GNUNET_SCHEDULER_Task * episode_timeout_task;
529 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
530 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
534 * Experiment related functions
536 extern struct GNUNET_CONFIGURATION_Handle *cfg;
539 * Execute the specified experiment
541 * @param e the Experiment
542 * @param ep_done_cb a episode is completed
543 * @param e_done_cb the experiment is completed
546 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
547 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
548 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
551 * Load an experiment from a file
553 * @param filename the file
554 * @return the Experiment or NULL on failure
557 GNUNET_ATS_TEST_experimentation_load (char *filename);
563 * @param e the experiment
566 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
569 * Traffic related functions
573 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
576 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
580 * Generate between the source master and the partner and send traffic with a
583 * @param src traffic source
584 * @param dest traffic partner
585 * @param type type of traffic to generate
586 * @param base_rate traffic base rate to send data with
587 * @param max_rate traffic maximum rate to send data with
588 * @param period duration of a period of traffic generation (~ 1/frequency)
589 * @param duration how long to generate traffic
590 * @return the traffic generator
592 struct TrafficGenerator *
593 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
594 struct BenchmarkPartner *dest,
595 enum GeneratorType type,
596 unsigned int base_rate,
597 unsigned int max_rate,
598 struct GNUNET_TIME_Relative period,
599 struct GNUNET_TIME_Relative duration);
603 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
606 * Stop all traffic generators
609 GNUNET_ATS_TEST_generate_traffic_stop_all ();
612 * Generate between the source master and the partner and set preferences with a
613 * value depending on the generator.
616 * @param dest partner
617 * @param type type of preferences to generate
618 * @param base_value traffic base rate to send data with
619 * @param value_rate traffic maximum rate to send data with
620 * @param period duration of a period of preferences generation (~ 1/frequency)
621 * @param frequency how long to generate preferences
622 * @param kind ATS preference to generate
623 * @return the traffic generator
625 struct PreferenceGenerator *
626 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
627 struct BenchmarkPartner *dest,
628 enum GeneratorType type,
629 unsigned int base_value,
630 unsigned int value_rate,
631 struct GNUNET_TIME_Relative period,
632 struct GNUNET_TIME_Relative frequency,
633 enum GNUNET_ATS_PreferenceKind kind);
636 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
639 GNUNET_ATS_TEST_generate_preferences_stop_all ();
642 * Logging related functions
648 * @param log_frequency the logging frequency
649 * @param testname the testname
650 * @param masters the master peers used for benchmarking
651 * @param num_masters the number of master peers
652 * @param num_slaves the number of slave peers
653 * @param verbose verbose logging
654 * @return the logging handle or NULL on error
656 struct LoggingHandle *
657 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
658 char *testname, struct BenchmarkPeer *masters, int num_masters, int num_slaves,
664 * @param l the logging handle
667 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
672 * @param l the logging handle
675 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
680 * @param l logging handle to use
683 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
687 * Write logging data to file
689 * @param l logging handle to use
690 * @param test_name name of the current test
691 * @param plots create gnuplots: GNUNET_YES or GNUNET_NO
694 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
695 char *test_name, int plots);
698 * Topology related functions
701 struct BenchmarkPeer *
702 GNUNET_ATS_TEST_get_peer (int src);
704 struct BenchmarkPartner *
705 GNUNET_ATS_TEST_get_partner (int src, int dest);
708 * Create a topology for ats testing
710 * @param name test name
711 * @param cfg_file configuration file to use for the peers
712 * @param num_slaves number of slaves
713 * @param num_masters number of masters
714 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
715 * @param done_cb function to call when topology is setup
716 * @param done_cb_cls cls for callback
717 * @param transport_recv_cb callback to call when data are received
718 * @param log_request_cb callback to call when logging is required
721 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
722 unsigned int num_slaves,
723 unsigned int num_masters,
725 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
727 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
728 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
734 GNUNET_ATS_TEST_shutdown_topology (void);
736 /* end of file ats-testing.h */