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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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"
31 #include "gnunet_transport_core_service.h"
33 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
36 * Message type sent for traffic generation
38 #define TEST_MESSAGE_TYPE_PING 12345
41 * Message type sent as response during traffic generation
43 #define TEST_MESSAGE_TYPE_PONG 12346
46 * Size of test messages
48 #define TEST_MESSAGE_SIZE 100
53 struct GNUNET_MessageHeader header;
55 uint8_t padding[TEST_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader)];
59 struct BenchmarkPartner;
63 struct GNUNET_ATS_TEST_Topology;
65 struct TrafficGenerator;
71 GNUNET_ATS_TEST_TG_LINEAR,
72 GNUNET_ATS_TEST_TG_CONSTANT,
73 GNUNET_ATS_TEST_TG_RANDOM,
74 GNUNET_ATS_TEST_TG_SINUS
79 * Callback to call when topology setup is completed
81 * @param cls the closure
82 * @param masters array of master peers
83 * @param slaves array of master peers
86 (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
87 struct BenchmarkPeer *masters,
88 struct BenchmarkPeer *slaves);
91 * Callback called when logging is required for the data contained
93 * @param cls the closure
94 * @param address an address
95 * @param address_active is address active
96 * @param bandwidth_out bandwidth outbound
97 * @param bandwidth_in bandwidth inbound
98 * @param prop performance information
101 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
102 const struct GNUNET_HELLO_Address *address,
104 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
105 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
106 const struct GNUNET_ATS_Properties *prop);
109 * Information we track for a peer in the testbed.
114 * Handle with testbed.
116 struct GNUNET_TESTBED_Peer *peer;
124 * Is this peer a measter: GNUNET_YES/GNUNET_NO
131 struct GNUNET_PeerIdentity id;
134 * Testbed operation to get peer information
136 struct GNUNET_TESTBED_Operation *peer_id_op;
139 * Testbed operation to connect to ATS performance service
141 struct GNUNET_TESTBED_Operation *ats_perf_op;
144 * Testbed operation to connect to core
146 struct GNUNET_TESTBED_Operation *comm_op;
149 * ATS performance handle
151 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
155 * Testbed connect operations to connect masters to slaves
157 struct TestbedConnectOperation *core_connect_ops;
162 struct GNUNET_CORE_Handle *ch;
167 struct GNUNET_TRANSPORT_CoreHandle *th;
171 * Peer to set ATS preferences for
173 struct BenchmarkPeer *pref_partner;
179 struct GNUNET_SCHEDULER_Task * ats_task;
188 * Array of partners with num_slaves entries (if master) or
189 * num_master entries (if slave)
191 struct BenchmarkPartner *partners;
199 * Number of core connections
201 int core_connections;
205 * Number of connections to slave peers
207 int core_slave_connections;
210 * Total number of messages this peer has sent
212 unsigned int total_messages_sent;
215 * Total number of bytes this peer has sent
217 unsigned int total_bytes_sent;
220 * Total number of messages this peer has received
222 unsigned int total_messages_received;
225 * Total number of bytes this peer has received
227 unsigned int total_bytes_received;
230 struct TrafficGenerator
232 struct TrafficGenerator *prev;
233 struct TrafficGenerator *next;
235 enum GeneratorType type;
237 struct BenchmarkPeer *src;
238 struct BenchmarkPartner *dest;
242 struct GNUNET_TIME_Relative duration_period;
244 struct GNUNET_SCHEDULER_Task * send_task;
245 struct GNUNET_TIME_Absolute next_ping_transmission;
246 struct GNUNET_TIME_Absolute time_start;
250 struct PreferenceGenerator
252 struct PreferenceGenerator *prev;
253 struct PreferenceGenerator *next;
255 enum GeneratorType type;
257 struct BenchmarkPeer *src;
258 struct BenchmarkPartner *dest;
260 enum GNUNET_ATS_PreferenceKind kind;
264 struct GNUNET_TIME_Relative duration_period;
265 struct GNUNET_TIME_Relative frequency;
267 struct GNUNET_SCHEDULER_Task * set_task;
268 struct GNUNET_TIME_Absolute next_ping_transmission;
269 struct GNUNET_TIME_Absolute time_start;
273 * Information about a benchmarking partner
275 struct BenchmarkPartner
278 * The peer itself this partner belongs to
280 struct BenchmarkPeer *me;
285 struct BenchmarkPeer *dest;
288 * Message queue handle.
290 struct GNUNET_MQ_Handle *mq;
293 * Handle for traffic generator
295 struct TrafficGenerator *tg;
298 * Handle for preference generator
300 struct PreferenceGenerator *pg;
303 * Timestamp to calculate communication layer delay
305 struct GNUNET_TIME_Absolute last_message_sent;
308 * Accumulated RTT for all messages
310 unsigned int total_app_rtt;
313 * Number of messages sent to this partner
315 unsigned int messages_sent;
318 * Number of bytes sent to this partner
320 unsigned int bytes_sent;
323 * Number of messages received from this partner
325 unsigned int messages_received;
328 * Number of bytes received from this partner
330 unsigned int bytes_received;
333 * Current ATS properties
335 struct GNUNET_ATS_Properties props;
338 * Bandwidth assigned inbound
340 uint32_t bandwidth_in;
343 * Bandwidth assigned outbound
345 uint32_t bandwidth_out;
348 * Current preference values for bandwidth
350 double pref_bandwidth;
353 * Current preference values for delay
361 * Overall state of the performance benchmark
363 struct BenchmarkState
366 * Are we connected to ATS service of all peers: GNUNET_YES/NO
368 int connected_ATS_service;
371 * Are we connected to CORE service of all peers: GNUNET_YES/NO
373 int connected_COMM_service;
376 * Are we connected to all peers: GNUNET_YES/NO
381 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
386 * Are we connected to CORE service of all peers: GNUNET_YES/NO
392 struct GNUNET_ATS_TEST_Topology
397 struct GNUNET_SCHEDULER_Task *progress_task;
405 * Test core (#GNUNET_YES) or transport (#GNUNET_NO)
425 * ATS preference value
430 * Number master peers
432 unsigned int num_masters;
435 * Array of master peers
437 struct BenchmarkPeer *mps;
442 unsigned int num_slaves;
445 * Array of slave peers
447 struct BenchmarkPeer *sps;
452 struct GNUNET_TIME_Relative perf_duration;
457 struct GNUNET_TIME_Relative log_frequency;
462 struct BenchmarkState state;
464 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
466 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
484 (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (struct Episode *e);
487 (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
488 struct GNUNET_TIME_Relative duration,
492 * An operation in an experiment
494 struct GNUNET_ATS_TEST_Operation
496 struct GNUNET_ATS_TEST_Operation *next;
497 struct GNUNET_ATS_TEST_Operation *prev;
499 long long unsigned int src_id;
500 long long unsigned int dest_id;
502 long long unsigned int base_rate;
503 long long unsigned int max_rate;
504 struct GNUNET_TIME_Relative period;
505 struct GNUNET_TIME_Relative frequency;
507 enum OperationType type;
508 enum GeneratorType gen_type;
509 enum GNUNET_ATS_PreferenceKind pref_type;
515 struct Episode *next;
516 struct GNUNET_TIME_Relative duration;
518 struct GNUNET_ATS_TEST_Operation *head;
519 struct GNUNET_ATS_TEST_Operation *tail;
527 unsigned long long int num_masters;
528 unsigned long long int num_slaves;
529 struct GNUNET_TIME_Relative log_freq;
530 struct GNUNET_TIME_Relative max_duration;
531 struct GNUNET_TIME_Relative total_duration;
532 struct GNUNET_TIME_Absolute start_time;
533 unsigned int num_episodes;
534 struct Episode *start;
536 struct GNUNET_SCHEDULER_Task * experiment_timeout_task;
537 struct GNUNET_SCHEDULER_Task * episode_timeout_task;
540 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
541 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
545 extern struct GNUNET_CONFIGURATION_Handle *cfg;
548 * Execute the specified experiment
550 * @param e the Experiment
551 * @param ep_done_cb a episode is completed
552 * @param e_done_cb the experiment is completed
555 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
556 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
557 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
561 * Load an experiment from a file
563 * @param filename the file
564 * @return the Experiment or NULL on failure
567 GNUNET_ATS_TEST_experimentation_load (const char *filename);
573 * @param e the experiment
576 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
580 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
584 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
588 * Generate between the source master and the partner and send traffic with a
591 * @param src traffic source
592 * @param dest traffic partner
593 * @param type type of traffic to generate
594 * @param base_rate traffic base rate to send data with
595 * @param max_rate traffic maximum rate to send data with
596 * @param period duration of a period of traffic generation (~ 1/frequency)
597 * @param duration how long to generate traffic
598 * @return the traffic generator
600 struct TrafficGenerator *
601 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
602 struct BenchmarkPartner *dest,
603 enum GeneratorType type,
604 unsigned int base_rate,
605 unsigned int max_rate,
606 struct GNUNET_TIME_Relative period,
607 struct GNUNET_TIME_Relative duration);
611 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
615 * Stop all traffic generators
618 GNUNET_ATS_TEST_generate_traffic_stop_all (void);
622 * Generate between the source master and the partner and set preferences with a
623 * value depending on the generator.
626 * @param dest partner
627 * @param type type of preferences to generate
628 * @param base_value traffic base rate to send data with
629 * @param value_rate traffic maximum rate to send data with
630 * @param period duration of a period of preferences generation (~ 1/frequency)
631 * @param frequency how long to generate preferences
632 * @param kind ATS preference to generate
633 * @return the traffic generator
635 struct PreferenceGenerator *
636 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
637 struct BenchmarkPartner *dest,
638 enum GeneratorType type,
639 unsigned int base_value,
640 unsigned int value_rate,
641 struct GNUNET_TIME_Relative period,
642 struct GNUNET_TIME_Relative frequency,
643 enum GNUNET_ATS_PreferenceKind kind);
647 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
651 GNUNET_ATS_TEST_generate_preferences_stop_all (void);
657 * @param log_frequency the logging frequency
658 * @param testname the testname
659 * @param masters the master peers used for benchmarking
660 * @param num_masters the number of master peers
661 * @param num_slaves the number of slave peers
662 * @param verbose verbose logging
663 * @return the logging handle or NULL on error
665 struct LoggingHandle *
666 GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
667 const char *testname,
668 struct BenchmarkPeer *masters,
677 * @param l the logging handle
680 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
686 * @param l the logging handle
689 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
695 * @param l logging handle to use
698 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
702 * Write logging data to file
704 * @param l logging handle to use
705 * @param test_name name of the current test
706 * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO
709 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
710 const char *test_name,
715 * Topology related functions
717 struct BenchmarkPeer *
718 GNUNET_ATS_TEST_get_peer (int src);
721 struct BenchmarkPartner *
722 GNUNET_ATS_TEST_get_partner (int src, int dest);
726 * Create a topology for ats testing
728 * @param name test name
729 * @param cfg_file configuration file to use for the peers
730 * @param num_slaves number of slaves
731 * @param num_masters number of masters
732 * @param test_core connect to CORE service (#GNUNET_YES) or transport (#GNUNET_NO)
733 * @param done_cb function to call when topology is setup
734 * @param done_cb_cls cls for callback
735 * @param log_request_cb callback to call when logging is required
738 GNUNET_ATS_TEST_create_topology (char *name,
740 unsigned int num_slaves,
741 unsigned int num_masters,
743 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
745 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
752 GNUNET_ATS_TEST_shutdown_topology (void);
755 /* end of file ats-testing.h */