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/>.
19 * @file ats-tests/ats-testing.h
20 * @brief ats testing library: setup topology and provide logging to test ats
21 * @author Christian Grothoff
22 * @author Matthias Wachs
25 #include "gnunet_util_lib.h"
26 #include "gnunet_testbed_service.h"
27 #include "gnunet_ats_service.h"
28 #include "gnunet_core_service.h"
29 #include "gnunet_transport_core_service.h"
31 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
34 * Message type sent for traffic generation
36 #define TEST_MESSAGE_TYPE_PING 12345
39 * Message type sent as response during traffic generation
41 #define TEST_MESSAGE_TYPE_PONG 12346
44 * Size of test messages
46 #define TEST_MESSAGE_SIZE 100
51 struct GNUNET_MessageHeader header;
53 uint8_t padding[TEST_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader)];
57 struct BenchmarkPartner;
61 struct GNUNET_ATS_TEST_Topology;
63 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
84 (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
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
99 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
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.
112 * Handle with testbed.
114 struct GNUNET_TESTBED_Peer *peer;
122 * Is this peer a measter: GNUNET_YES/GNUNET_NO
129 struct GNUNET_PeerIdentity id;
132 * Testbed operation to get peer information
134 struct GNUNET_TESTBED_Operation *peer_id_op;
137 * Testbed operation to connect to ATS performance service
139 struct GNUNET_TESTBED_Operation *ats_perf_op;
142 * Testbed operation to connect to core
144 struct GNUNET_TESTBED_Operation *comm_op;
147 * ATS performance handle
149 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
153 * Testbed connect operations to connect masters to slaves
155 struct TestbedConnectOperation *core_connect_ops;
160 struct GNUNET_CORE_Handle *ch;
165 struct GNUNET_TRANSPORT_CoreHandle *th;
169 * Peer to set ATS preferences for
171 struct BenchmarkPeer *pref_partner;
177 struct GNUNET_SCHEDULER_Task * ats_task;
186 * Array of partners with num_slaves entries (if master) or
187 * num_master entries (if slave)
189 struct BenchmarkPartner *partners;
197 * Number of core connections
199 int core_connections;
203 * Number of connections to slave peers
205 int core_slave_connections;
208 * Total number of messages this peer has sent
210 unsigned int total_messages_sent;
213 * Total number of bytes this peer has sent
215 unsigned int total_bytes_sent;
218 * Total number of messages this peer has received
220 unsigned int total_messages_received;
223 * Total number of bytes this peer has received
225 unsigned int total_bytes_received;
228 struct TrafficGenerator
230 struct TrafficGenerator *prev;
231 struct TrafficGenerator *next;
233 enum GeneratorType type;
235 struct BenchmarkPeer *src;
236 struct BenchmarkPartner *dest;
240 struct GNUNET_TIME_Relative duration_period;
242 struct GNUNET_SCHEDULER_Task * send_task;
243 struct GNUNET_TIME_Absolute next_ping_transmission;
244 struct GNUNET_TIME_Absolute time_start;
248 struct PreferenceGenerator
250 struct PreferenceGenerator *prev;
251 struct PreferenceGenerator *next;
253 enum GeneratorType type;
255 struct BenchmarkPeer *src;
256 struct BenchmarkPartner *dest;
258 enum GNUNET_ATS_PreferenceKind kind;
262 struct GNUNET_TIME_Relative duration_period;
263 struct GNUNET_TIME_Relative frequency;
265 struct GNUNET_SCHEDULER_Task * set_task;
266 struct GNUNET_TIME_Absolute next_ping_transmission;
267 struct GNUNET_TIME_Absolute time_start;
271 * Information about a benchmarking partner
273 struct BenchmarkPartner
276 * The peer itself this partner belongs to
278 struct BenchmarkPeer *me;
283 struct BenchmarkPeer *dest;
286 * Message queue handle.
288 struct GNUNET_MQ_Handle *mq;
291 * Handle for traffic generator
293 struct TrafficGenerator *tg;
296 * Handle for preference generator
298 struct PreferenceGenerator *pg;
301 * Timestamp to calculate communication layer delay
303 struct GNUNET_TIME_Absolute last_message_sent;
306 * Accumulated RTT for all messages
308 unsigned int total_app_rtt;
311 * Number of messages sent to this partner
313 unsigned int messages_sent;
316 * Number of bytes sent to this partner
318 unsigned int bytes_sent;
321 * Number of messages received from this partner
323 unsigned int messages_received;
326 * Number of bytes received from this partner
328 unsigned int bytes_received;
331 * Current ATS properties
333 struct GNUNET_ATS_Properties props;
336 * Bandwidth assigned inbound
338 uint32_t bandwidth_in;
341 * Bandwidth assigned outbound
343 uint32_t bandwidth_out;
346 * Current preference values for bandwidth
348 double pref_bandwidth;
351 * Current preference values for delay
359 * Overall state of the performance benchmark
361 struct BenchmarkState
364 * Are we connected to ATS service of all peers: GNUNET_YES/NO
366 int connected_ATS_service;
369 * Are we connected to CORE service of all peers: GNUNET_YES/NO
371 int connected_COMM_service;
374 * Are we connected to all peers: GNUNET_YES/NO
379 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
384 * Are we connected to CORE service of all peers: GNUNET_YES/NO
390 struct GNUNET_ATS_TEST_Topology
395 struct GNUNET_SCHEDULER_Task *progress_task;
403 * Test core (#GNUNET_YES) or transport (#GNUNET_NO)
423 * ATS preference value
428 * Number master peers
430 unsigned int num_masters;
433 * Array of master peers
435 struct BenchmarkPeer *mps;
440 unsigned int num_slaves;
443 * Array of slave peers
445 struct BenchmarkPeer *sps;
450 struct GNUNET_TIME_Relative perf_duration;
455 struct GNUNET_TIME_Relative log_frequency;
460 struct BenchmarkState state;
462 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
464 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
482 (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (struct Episode *e);
485 (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
486 struct GNUNET_TIME_Relative duration,
490 * An operation in an experiment
492 struct GNUNET_ATS_TEST_Operation
494 struct GNUNET_ATS_TEST_Operation *next;
495 struct GNUNET_ATS_TEST_Operation *prev;
497 long long unsigned int src_id;
498 long long unsigned int dest_id;
500 long long unsigned int base_rate;
501 long long unsigned int max_rate;
502 struct GNUNET_TIME_Relative period;
503 struct GNUNET_TIME_Relative frequency;
505 enum OperationType type;
506 enum GeneratorType gen_type;
507 enum GNUNET_ATS_PreferenceKind pref_type;
513 struct Episode *next;
514 struct GNUNET_TIME_Relative duration;
516 struct GNUNET_ATS_TEST_Operation *head;
517 struct GNUNET_ATS_TEST_Operation *tail;
525 unsigned long long int num_masters;
526 unsigned long long int num_slaves;
527 struct GNUNET_TIME_Relative log_freq;
528 struct GNUNET_TIME_Relative max_duration;
529 struct GNUNET_TIME_Relative total_duration;
530 struct GNUNET_TIME_Absolute start_time;
531 unsigned int num_episodes;
532 struct Episode *start;
534 struct GNUNET_SCHEDULER_Task * experiment_timeout_task;
535 struct GNUNET_SCHEDULER_Task * episode_timeout_task;
538 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
539 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
543 extern struct GNUNET_CONFIGURATION_Handle *cfg;
546 * Execute the specified experiment
548 * @param e the Experiment
549 * @param ep_done_cb a episode is completed
550 * @param e_done_cb the experiment is completed
553 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
554 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
555 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
559 * Load an experiment from a file
561 * @param filename the file
562 * @return the Experiment or NULL on failure
565 GNUNET_ATS_TEST_experimentation_load (const char *filename);
571 * @param e the experiment
574 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
578 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
582 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
586 * Generate between the source master and the partner and send traffic with a
589 * @param src traffic source
590 * @param dest traffic partner
591 * @param type type of traffic to generate
592 * @param base_rate traffic base rate to send data with
593 * @param max_rate traffic maximum rate to send data with
594 * @param period duration of a period of traffic generation (~ 1/frequency)
595 * @param duration how long to generate traffic
596 * @return the traffic generator
598 struct TrafficGenerator *
599 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
600 struct BenchmarkPartner *dest,
601 enum GeneratorType type,
602 unsigned int base_rate,
603 unsigned int max_rate,
604 struct GNUNET_TIME_Relative period,
605 struct GNUNET_TIME_Relative duration);
609 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
613 * Stop all traffic generators
616 GNUNET_ATS_TEST_generate_traffic_stop_all (void);
620 * Generate between the source master and the partner and set preferences with a
621 * value depending on the generator.
624 * @param dest partner
625 * @param type type of preferences to generate
626 * @param base_value traffic base rate to send data with
627 * @param value_rate traffic maximum rate to send data with
628 * @param period duration of a period of preferences generation (~ 1/frequency)
629 * @param frequency how long to generate preferences
630 * @param kind ATS preference to generate
631 * @return the traffic generator
633 struct PreferenceGenerator *
634 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
635 struct BenchmarkPartner *dest,
636 enum GeneratorType type,
637 unsigned int base_value,
638 unsigned int value_rate,
639 struct GNUNET_TIME_Relative period,
640 struct GNUNET_TIME_Relative frequency,
641 enum GNUNET_ATS_PreferenceKind kind);
645 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
649 GNUNET_ATS_TEST_generate_preferences_stop_all (void);
655 * @param log_frequency the logging frequency
656 * @param testname the testname
657 * @param masters the master peers used for benchmarking
658 * @param num_masters the number of master peers
659 * @param num_slaves the number of slave peers
660 * @param verbose verbose logging
661 * @return the logging handle or NULL on error
663 struct LoggingHandle *
664 GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
665 const char *testname,
666 struct BenchmarkPeer *masters,
675 * @param l the logging handle
678 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
684 * @param l the logging handle
687 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
693 * @param l logging handle to use
696 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
700 * Write logging data to file
702 * @param l logging handle to use
703 * @param test_name name of the current test
704 * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO
707 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
708 const char *test_name,
713 * Topology related functions
715 struct BenchmarkPeer *
716 GNUNET_ATS_TEST_get_peer (int src);
719 struct BenchmarkPartner *
720 GNUNET_ATS_TEST_get_partner (int src, int dest);
724 * Create a topology for ats testing
726 * @param name test name
727 * @param cfg_file configuration file to use for the peers
728 * @param num_slaves number of slaves
729 * @param num_masters number of masters
730 * @param test_core connect to CORE service (#GNUNET_YES) or transport (#GNUNET_NO)
731 * @param done_cb function to call when topology is setup
732 * @param done_cb_cls cls for callback
733 * @param log_request_cb callback to call when logging is required
736 GNUNET_ATS_TEST_create_topology (char *name,
738 unsigned int num_slaves,
739 unsigned int num_masters,
741 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
743 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
750 GNUNET_ATS_TEST_shutdown_topology (void);
753 /* end of file ats-testing.h */