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_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
52 struct GNUNET_MessageHeader header;
54 uint8_t padding[TEST_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader)];
58 struct BenchmarkPartner;
62 struct GNUNET_ATS_TEST_Topology;
64 struct TrafficGenerator;
69 GNUNET_ATS_TEST_TG_LINEAR,
70 GNUNET_ATS_TEST_TG_CONSTANT,
71 GNUNET_ATS_TEST_TG_RANDOM,
72 GNUNET_ATS_TEST_TG_SINUS
77 * Callback to call when topology setup is completed
79 * @param cls the closure
80 * @param masters array of master peers
81 * @param slaves array of master peers
83 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (
85 struct BenchmarkPeer *masters,
86 struct BenchmarkPeer *slaves);
89 * Callback called when logging is required for the data contained
91 * @param cls the closure
92 * @param address an address
93 * @param address_active is address active
94 * @param bandwidth_out bandwidth outbound
95 * @param bandwidth_in bandwidth inbound
96 * @param prop performance information
98 typedef void (*GNUNET_ATS_TEST_LogRequest) (
100 const struct GNUNET_HELLO_Address *address,
102 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
103 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
104 const struct GNUNET_ATS_Properties *prop);
107 * Information we track for a peer in the testbed.
109 struct BenchmarkPeer {
111 * Handle with testbed.
113 struct GNUNET_TESTBED_Peer *peer;
121 * Is this peer a measter: GNUNET_YES/GNUNET_NO
128 struct GNUNET_PeerIdentity id;
131 * Testbed operation to get peer information
133 struct GNUNET_TESTBED_Operation *peer_id_op;
136 * Testbed operation to connect to ATS performance service
138 struct GNUNET_TESTBED_Operation *ats_perf_op;
141 * Testbed operation to connect to core
143 struct GNUNET_TESTBED_Operation *comm_op;
146 * ATS performance handle
148 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
152 * Testbed connect operations to connect masters to slaves
154 struct TestbedConnectOperation *core_connect_ops;
159 struct GNUNET_CORE_Handle *ch;
164 struct GNUNET_TRANSPORT_CoreHandle *th;
168 * Peer to set ATS preferences for
170 struct BenchmarkPeer *pref_partner;
176 struct GNUNET_SCHEDULER_Task *ats_task;
185 * Array of partners with num_slaves entries (if master) or
186 * num_master entries (if slave)
188 struct BenchmarkPartner *partners;
196 * Number of core connections
198 int core_connections;
202 * Number of connections to slave peers
204 int core_slave_connections;
207 * Total number of messages this peer has sent
209 unsigned int total_messages_sent;
212 * Total number of bytes this peer has sent
214 unsigned int total_bytes_sent;
217 * Total number of messages this peer has received
219 unsigned int total_messages_received;
222 * Total number of bytes this peer has received
224 unsigned int total_bytes_received;
227 struct TrafficGenerator {
228 struct TrafficGenerator *prev;
229 struct TrafficGenerator *next;
231 enum GeneratorType type;
233 struct BenchmarkPeer *src;
234 struct BenchmarkPartner *dest;
238 struct GNUNET_TIME_Relative duration_period;
240 struct GNUNET_SCHEDULER_Task *send_task;
241 struct GNUNET_TIME_Absolute next_ping_transmission;
242 struct GNUNET_TIME_Absolute time_start;
246 struct PreferenceGenerator {
247 struct PreferenceGenerator *prev;
248 struct PreferenceGenerator *next;
250 enum GeneratorType type;
252 struct BenchmarkPeer *src;
253 struct BenchmarkPartner *dest;
255 enum GNUNET_ATS_PreferenceKind kind;
259 struct GNUNET_TIME_Relative duration_period;
260 struct GNUNET_TIME_Relative frequency;
262 struct GNUNET_SCHEDULER_Task *set_task;
263 struct GNUNET_TIME_Absolute next_ping_transmission;
264 struct GNUNET_TIME_Absolute time_start;
268 * Information about a benchmarking partner
270 struct BenchmarkPartner {
272 * The peer itself this partner belongs to
274 struct BenchmarkPeer *me;
279 struct BenchmarkPeer *dest;
282 * Message queue handle.
284 struct GNUNET_MQ_Handle *mq;
287 * Handle for traffic generator
289 struct TrafficGenerator *tg;
292 * Handle for preference generator
294 struct PreferenceGenerator *pg;
297 * Timestamp to calculate communication layer delay
299 struct GNUNET_TIME_Absolute last_message_sent;
302 * Accumulated RTT for all messages
304 unsigned int total_app_rtt;
307 * Number of messages sent to this partner
309 unsigned int messages_sent;
312 * Number of bytes sent to this partner
314 unsigned int bytes_sent;
317 * Number of messages received from this partner
319 unsigned int messages_received;
322 * Number of bytes received from this partner
324 unsigned int bytes_received;
327 * Current ATS properties
329 struct GNUNET_ATS_Properties props;
332 * Bandwidth assigned inbound
334 uint32_t bandwidth_in;
337 * Bandwidth assigned outbound
339 uint32_t bandwidth_out;
342 * Current preference values for bandwidth
344 double pref_bandwidth;
347 * Current preference values for delay
354 * Overall state of the performance benchmark
356 struct BenchmarkState {
358 * Are we connected to ATS service of all peers: GNUNET_YES/NO
360 int connected_ATS_service;
363 * Are we connected to CORE service of all peers: GNUNET_YES/NO
365 int connected_COMM_service;
368 * Are we connected to all peers: GNUNET_YES/NO
373 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
378 * Are we connected to CORE service of all peers: GNUNET_YES/NO
384 struct GNUNET_ATS_TEST_Topology {
388 struct GNUNET_SCHEDULER_Task *progress_task;
396 * Test core (#GNUNET_YES) or transport (#GNUNET_NO)
416 * ATS preference value
421 * Number master peers
423 unsigned int num_masters;
426 * Array of master peers
428 struct BenchmarkPeer *mps;
433 unsigned int num_slaves;
436 * Array of slave peers
438 struct BenchmarkPeer *sps;
443 struct GNUNET_TIME_Relative perf_duration;
448 struct GNUNET_TIME_Relative log_frequency;
453 struct BenchmarkState state;
455 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
457 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
473 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (struct Episode *e);
475 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (
476 struct Experiment *e,
477 struct GNUNET_TIME_Relative duration,
481 * An operation in an experiment
483 struct GNUNET_ATS_TEST_Operation {
484 struct GNUNET_ATS_TEST_Operation *next;
485 struct GNUNET_ATS_TEST_Operation *prev;
487 long long unsigned int src_id;
488 long long unsigned int dest_id;
490 long long unsigned int base_rate;
491 long long unsigned int max_rate;
492 struct GNUNET_TIME_Relative period;
493 struct GNUNET_TIME_Relative frequency;
495 enum OperationType type;
496 enum GeneratorType gen_type;
497 enum GNUNET_ATS_PreferenceKind pref_type;
502 struct Episode *next;
503 struct GNUNET_TIME_Relative duration;
505 struct GNUNET_ATS_TEST_Operation *head;
506 struct GNUNET_ATS_TEST_Operation *tail;
513 unsigned long long int num_masters;
514 unsigned long long int num_slaves;
515 struct GNUNET_TIME_Relative log_freq;
516 struct GNUNET_TIME_Relative max_duration;
517 struct GNUNET_TIME_Relative total_duration;
518 struct GNUNET_TIME_Absolute start_time;
519 unsigned int num_episodes;
520 struct Episode *start;
522 struct GNUNET_SCHEDULER_Task *experiment_timeout_task;
523 struct GNUNET_SCHEDULER_Task *episode_timeout_task;
526 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
527 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
531 extern struct GNUNET_CONFIGURATION_Handle *cfg;
534 * Execute the specified experiment
536 * @param e the Experiment
537 * @param ep_done_cb a episode is completed
538 * @param e_done_cb the experiment is completed
541 GNUNET_ATS_TEST_experimentation_run(
542 struct Experiment *e,
543 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
544 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
548 * Load an experiment from a file
550 * @param filename the file
551 * @return the Experiment or NULL on failure
554 GNUNET_ATS_TEST_experimentation_load(const char *filename);
560 * @param e the experiment
563 GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e);
567 GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p);
571 GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p);
575 * Generate between the source master and the partner and send traffic with a
578 * @param src traffic source
579 * @param dest traffic partner
580 * @param type type of traffic to generate
581 * @param base_rate traffic base rate to send data with
582 * @param max_rate traffic maximum rate to send data with
583 * @param period duration of a period of traffic generation (~ 1/frequency)
584 * @param duration how long to generate traffic
585 * @return the traffic generator
587 struct TrafficGenerator *
588 GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src,
589 struct BenchmarkPartner *dest,
590 enum GeneratorType type,
591 unsigned int base_rate,
592 unsigned int max_rate,
593 struct GNUNET_TIME_Relative period,
594 struct GNUNET_TIME_Relative duration);
598 GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg);
602 * Stop all traffic generators
605 GNUNET_ATS_TEST_generate_traffic_stop_all(void);
609 * Generate between the source master and the partner and set preferences with a
610 * value depending on the generator.
613 * @param dest partner
614 * @param type type of preferences to generate
615 * @param base_value traffic base rate to send data with
616 * @param value_rate traffic maximum rate to send data with
617 * @param period duration of a period of preferences generation (~ 1/frequency)
618 * @param frequency how long to generate preferences
619 * @param kind ATS preference to generate
620 * @return the traffic generator
622 struct PreferenceGenerator *
623 GNUNET_ATS_TEST_generate_preferences_start(
624 struct BenchmarkPeer *src,
625 struct BenchmarkPartner *dest,
626 enum GeneratorType type,
627 unsigned int base_value,
628 unsigned int value_rate,
629 struct GNUNET_TIME_Relative period,
630 struct GNUNET_TIME_Relative frequency,
631 enum GNUNET_ATS_PreferenceKind kind);
635 GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg);
639 GNUNET_ATS_TEST_generate_preferences_stop_all(void);
645 * @param log_frequency the logging frequency
646 * @param testname the testname
647 * @param masters the master peers used for benchmarking
648 * @param num_masters the number of master peers
649 * @param num_slaves the number of slave peers
650 * @param verbose verbose logging
651 * @return the logging handle or NULL on error
653 struct LoggingHandle *
654 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
655 const char *testname,
656 struct BenchmarkPeer *masters,
665 * @param l the logging handle
668 GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l);
674 * @param l the logging handle
677 GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l);
683 * @param l logging handle to use
686 GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l);
690 * Write logging data to file
692 * @param l logging handle to use
693 * @param test_name name of the current test
694 * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO
697 GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l,
698 const char *test_name,
703 * Topology related functions
705 struct BenchmarkPeer *
706 GNUNET_ATS_TEST_get_peer(int src);
709 struct BenchmarkPartner *
710 GNUNET_ATS_TEST_get_partner(int src, int dest);
714 * Create a topology for ats testing
716 * @param name test name
717 * @param cfg_file configuration file to use for the peers
718 * @param num_slaves number of slaves
719 * @param num_masters number of masters
720 * @param test_core connect to CORE service (#GNUNET_YES) or transport
722 * @param done_cb function to call when topology is setup
723 * @param done_cb_cls cls for callback
724 * @param log_request_cb callback to call when logging is required
727 GNUNET_ATS_TEST_create_topology(
730 unsigned int num_slaves,
731 unsigned int num_masters,
733 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
735 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
742 GNUNET_ATS_TEST_shutdown_topology(void);
745 /* end of file ats-testing.h */