2 This file is part of GNUnet.
3 (C) 2010-2013 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.
21 * @file ats-tests/ats-testing-experiment.c
22 * @brief ats benchmark: controlled experiment execution
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_ats_plugin.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet-service-ats_addresses.h"
31 #include "gnunet-service-ats_normalization.h"
32 #include "test_ats_api_common.h"
36 GNUNET_ATS_TEST_TG_LINEAR,
37 GNUNET_ATS_TEST_TG_CONSTANT,
38 GNUNET_ATS_TEST_TG_RANDOM,
39 GNUNET_ATS_TEST_TG_SINUS
45 SOLVER_OP_ADD_ADDRESS,
46 SOLVER_OP_DEL_ADDRESS,
47 SOLVER_OP_START_SET_PROPERTY,
48 SOLVER_OP_STOP_SET_PROPERTY,
49 SOLVER_OP_START_SET_PREFERENCE,
50 SOLVER_OP_STOP_SET_PREFERENCE
57 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
60 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
61 struct GNUNET_TIME_Relative duration,int success);
64 * An operation in an experiment
66 struct GNUNET_ATS_TEST_Operation
68 struct GNUNET_ATS_TEST_Operation *next;
69 struct GNUNET_ATS_TEST_Operation *prev;
71 long long unsigned int address_id;
72 long long unsigned int peer_id;
73 long long unsigned int address_session;
74 long long unsigned int address_network;
79 long long unsigned int base_rate;
80 long long unsigned int max_rate;
81 struct GNUNET_TIME_Relative period;
82 struct GNUNET_TIME_Relative frequency;
84 enum OperationType type;
85 enum GeneratorType tg_type;
86 enum GNUNET_ATS_PreferenceKind pref_type;
87 enum GNUNET_ATS_Property prop_type;
94 struct GNUNET_TIME_Relative duration;
96 struct GNUNET_ATS_TEST_Operation *head;
97 struct GNUNET_ATS_TEST_Operation *tail;
105 unsigned long long int num_masters;
106 unsigned long long int num_slaves;
107 struct GNUNET_TIME_Relative log_freq;
108 struct GNUNET_TIME_Relative max_duration;
109 struct GNUNET_TIME_Relative total_duration;
110 struct GNUNET_TIME_Absolute start_time;
111 unsigned int num_episodes;
112 struct Episode *start;
114 struct GNUNET_CONFIGURATION_Handle *cfg;
116 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
117 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
120 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
121 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
126 * A single logging time step for a partner
128 struct PartnerLoggingTimestep
133 struct BenchmarkPeer *slave;
136 * Total number of messages this peer has sent
138 unsigned int total_messages_sent;
141 * Total number of bytes this peer has sent
143 unsigned int total_bytes_sent;
146 * Total number of messages this peer has received
148 unsigned int total_messages_received;
151 * Total number of bytes this peer has received
153 unsigned int total_bytes_received;
156 * Total outbound throughput for master in Bytes / s
158 unsigned int throughput_sent;
161 * Total inbound throughput for master in Bytes / s
163 unsigned int throughput_recv;
166 * Accumulated RTT for all messages
168 unsigned int total_app_rtt;
171 * Current application level delay
173 unsigned int app_rtt;
175 /* Current ATS properties */
177 uint32_t ats_distance;
181 uint32_t bandwidth_in;
183 uint32_t bandwidth_out;
185 uint32_t ats_utilization_up;
187 uint32_t ats_utilization_down;
189 uint32_t ats_network_type;
191 uint32_t ats_cost_wan;
193 uint32_t ats_cost_lan;
195 uint32_t ats_cost_wlan;
197 double pref_bandwidth;
203 * A single logging time step for a peer
205 struct PeerLoggingTimestep
210 struct PeerLoggingTimestep *next;
215 struct PeerLoggingTimestep *prev;
220 struct GNUNET_TIME_Absolute timestamp;
223 * Total number of messages this peer has sent
225 unsigned int total_messages_sent;
228 * Total number of bytes this peer has sent
230 unsigned int total_bytes_sent;
233 * Total number of messages this peer has received
235 unsigned int total_messages_received;
238 * Total number of bytes this peer has received
240 unsigned int total_bytes_received;
243 * Total outbound throughput for master in Bytes / s
245 unsigned int total_throughput_send;
248 * Total inbound throughput for master in Bytes / s
250 unsigned int total_throughput_recv;
255 struct PartnerLoggingTimestep *slaves_log;
259 * Entry for a benchmark peer
266 struct BenchmarkPeer *peer;
271 struct GNUNET_TIME_Absolute start;
274 * DLL for logging entries: head
276 struct PeerLoggingTimestep *head;
279 * DLL for logging entries: tail
281 struct PeerLoggingTimestep *tail;
290 GNUNET_SCHEDULER_TaskIdentifier log_task;
293 * Reference to perf_ats' masters
300 struct GNUNET_TIME_Relative frequency;
303 * Log structure of length num_peers
305 struct LoggingPeer *lp;
312 * @param log_frequency the logging frequency
313 * @param testname the testname
314 * @param masters the master peers used for benchmarking
315 * @param num_master the number of master peers
316 * @return the logging handle or NULL on error
318 struct LoggingHandle *
319 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
320 char *testname, struct BenchmarkPeer *masters, int num_masters, int num_slaves,
326 * @param l the logging handle
329 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
334 * @param l the logging handle
337 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
342 * @param l logging handle to use
345 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
349 * Write logging data to file
351 * @param l logging handle to use
352 * @param test_name name of the current test
353 * @param plots create gnuplots: GNUNET_YES or GNUNET_NO
356 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
357 char *test_name, int plots);
367 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
370 * Message type sent for traffic generation
372 #define TEST_MESSAGE_TYPE_PING 12345
375 * Message type sent as response during traffic generation
377 #define TEST_MESSAGE_TYPE_PONG 12346
380 * Size of test messages
382 #define TEST_MESSAGE_SIZE 100
384 struct BenchmarkPartner;
386 struct BenchmarkPeer;
388 struct GNUNET_ATS_TEST_Topology;
390 struct TrafficGenerator;
397 * Callback to call when topology setup is completed
399 * @param cls the closure
400 * @param masters array of master peers
401 * @param slaves array of master peers
403 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
404 struct BenchmarkPeer *masters,
405 struct BenchmarkPeer *slaves);
408 * Callback called when logging is required for the data contained
410 * @param cls the closure
411 * @param address an address
412 * @param address_active is address active
413 * @param bandwidth_out bandwidth outbound
414 * @param bandwidth_in bandwidth inbound
415 * @param ats ats information
416 * @param ats_count number of ats inforation
419 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
420 const struct GNUNET_HELLO_Address *address,
422 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
423 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
424 const struct GNUNET_ATS_Information *ats,
428 * Information we track for a peer in the testbed.
433 * Handle with testbed.
435 struct GNUNET_TESTBED_Peer *peer;
443 * Is this peer a measter: GNUNET_YES/GNUNET_NO
450 struct GNUNET_PeerIdentity id;
453 * Testbed operation to get peer information
455 struct GNUNET_TESTBED_Operation *peer_id_op;
458 * Testbed operation to connect to ATS performance service
460 struct GNUNET_TESTBED_Operation *ats_perf_op;
463 * Testbed operation to connect to core
465 struct GNUNET_TESTBED_Operation *comm_op;
468 * ATS performance handle
470 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
474 * Testbed connect operations to connect masters to slaves
476 struct TestbedConnectOperation *core_connect_ops;
481 struct GNUNET_CORE_Handle *ch;
486 struct GNUNET_TRANSPORT_Handle *th;
490 * Peer to set ATS preferences for
492 struct BenchmarkPeer *pref_partner;
498 GNUNET_SCHEDULER_TaskIdentifier ats_task;
507 * Array of partners with num_slaves entries (if master) or
508 * num_master entries (if slave)
510 struct BenchmarkPartner *partners;
518 * Number of core connections
520 int core_connections;
524 * Number of connections to slave peers
526 int core_slave_connections;
529 * Total number of messages this peer has sent
531 unsigned int total_messages_sent;
534 * Total number of bytes this peer has sent
536 unsigned int total_bytes_sent;
539 * Total number of messages this peer has received
541 unsigned int total_messages_received;
544 * Total number of bytes this peer has received
546 unsigned int total_bytes_received;
549 struct TrafficGenerator
551 struct TrafficGenerator *prev;
552 struct TrafficGenerator *next;
554 enum GeneratorType type;
556 struct BenchmarkPeer *src;
557 struct BenchmarkPartner *dest;
561 struct GNUNET_TIME_Relative duration_period;
563 GNUNET_SCHEDULER_TaskIdentifier send_task;
564 struct GNUNET_TIME_Absolute next_ping_transmission;
565 struct GNUNET_TIME_Absolute time_start;
569 struct PreferenceGenerator
571 struct PreferenceGenerator *prev;
572 struct PreferenceGenerator *next;
574 enum GeneratorType type;
576 struct BenchmarkPeer *src;
577 struct BenchmarkPartner *dest;
579 enum GNUNET_ATS_PreferenceKind kind;
583 struct GNUNET_TIME_Relative duration_period;
584 struct GNUNET_TIME_Relative frequency;
586 GNUNET_SCHEDULER_TaskIdentifier set_task;
587 struct GNUNET_TIME_Absolute next_ping_transmission;
588 struct GNUNET_TIME_Absolute time_start;
592 * Information about a benchmarking partner
594 struct BenchmarkPartner
597 * The peer itself this partner belongs to
599 struct BenchmarkPeer *me;
604 struct BenchmarkPeer *dest;
607 * Core transmit handles
609 struct GNUNET_CORE_TransmitHandle *cth;
612 * Transport transmit handles
614 struct GNUNET_TRANSPORT_TransmitHandle *tth;
616 struct TrafficGenerator *tg;
617 struct PreferenceGenerator *pg;
620 * Timestamp to calculate communication layer delay
622 struct GNUNET_TIME_Absolute last_message_sent;
625 * Accumulated RTT for all messages
627 unsigned int total_app_rtt;
630 * Number of messages sent to this partner
632 unsigned int messages_sent;
635 * Number of bytes sent to this partner
637 unsigned int bytes_sent;
640 * Number of messages received from this partner
642 unsigned int messages_received;
645 * Number of bytes received from this partner
647 unsigned int bytes_received;
649 /* Current ATS properties */
651 uint32_t ats_distance;
655 uint32_t bandwidth_in;
657 uint32_t bandwidth_out;
659 uint32_t ats_utilization_up;
661 uint32_t ats_utilization_down;
663 uint32_t ats_network_type;
665 uint32_t ats_cost_wan;
667 uint32_t ats_cost_lan;
669 uint32_t ats_cost_wlan;
671 double pref_bandwidth;
676 * Overall state of the performance benchmark
678 struct BenchmarkState
681 * Are we connected to ATS service of all peers: GNUNET_YES/NO
683 int connected_ATS_service;
686 * Are we connected to CORE service of all peers: GNUNET_YES/NO
688 int connected_COMM_service;
691 * Are we connected to all peers: GNUNET_YES/NO
696 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
701 * Are we connected to CORE service of all peers: GNUNET_YES/NO
707 struct GNUNET_ATS_TEST_Topology
712 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
717 GNUNET_SCHEDULER_TaskIdentifier progress_task;
724 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
744 * ATS preference value
749 * Number master peers
751 unsigned int num_masters;
754 * Array of master peers
756 struct BenchmarkPeer *mps;
761 unsigned int num_slaves;
764 * Array of slave peers
766 struct BenchmarkPeer *sps;
771 struct GNUNET_TIME_Relative perf_duration;
776 struct GNUNET_TIME_Relative log_frequency;
781 struct BenchmarkState state;
783 struct GNUNET_CORE_MessageHandler *handlers;
785 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
787 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
788 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
795 * Experiment related functions
800 * Execute the specified experiment
802 * @param e the Experiment
803 * @param ep_done_cb a episode is completed
804 * @param e_done_cb the experiment is completed
807 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
808 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
809 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
812 * Load an experiment from a file
814 * @param filename the file
815 * @return the Experiment or NULL on failure
818 GNUNET_ATS_TEST_experimentation_load (char *filename);
824 * @param e the experiment
827 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
830 * Traffic related functions
834 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
837 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
841 * Generate between the source master and the partner and send traffic with a
844 * @param src traffic source
845 * @param dest traffic partner
846 * @param type type of traffic to generate
847 * @param base_rate traffic base rate to send data with
848 * @param max_rate traffic maximum rate to send data with
849 * @param period duration of a period of traffic generation (~ 1/frequency)
850 * @param duration how long to generate traffic
851 * @return the traffic generator
853 struct TrafficGenerator *
854 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
855 struct BenchmarkPartner *dest,
856 enum GeneratorType type,
859 struct GNUNET_TIME_Relative period,
860 struct GNUNET_TIME_Relative duration);
863 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
866 * Stop all traffic generators
869 GNUNET_ATS_TEST_generate_traffic_stop_all ();
871 struct PreferenceGenerator *
872 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
873 struct BenchmarkPartner *dest,
874 enum GeneratorType type,
877 struct GNUNET_TIME_Relative period,
878 struct GNUNET_TIME_Relative frequency,
879 enum GNUNET_ATS_PreferenceKind kind);
882 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
885 GNUNET_ATS_TEST_generate_preferences_stop_all ();
888 * Logging related functions
894 * Topology related functions
897 struct BenchmarkPeer *
898 GNUNET_ATS_TEST_get_peer (int src);
900 struct BenchmarkPartner *
901 GNUNET_ATS_TEST_get_partner (int src, int dest);
904 * Create a topology for ats testing
906 * @param name test name
907 * @param cfg_file configuration file to use for the peers
908 * @param num_slaves number of slaves
909 * @param num_masters number of masters
910 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
911 * @param done_cb function to call when topology is setup
912 * @param done_cb_cls cls for callback
913 * @param recv_cb callback to call when data are received
914 * @param perf_cb callback to call when performance info are received
917 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
918 unsigned int num_slaves,
919 unsigned int num_masters,
921 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
923 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
924 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
930 GNUNET_ATS_TEST_shutdown_topology (void);
932 /* end of file ats-testing.h */