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;
78 long long unsigned int base_rate;
79 long long unsigned int max_rate;
80 struct GNUNET_TIME_Relative period;
81 struct GNUNET_TIME_Relative frequency;
83 enum OperationType type;
84 enum GeneratorType tg_type;
85 enum GNUNET_ATS_PreferenceKind pref_type;
92 struct GNUNET_TIME_Relative duration;
94 struct GNUNET_ATS_TEST_Operation *head;
95 struct GNUNET_ATS_TEST_Operation *tail;
103 unsigned long long int num_masters;
104 unsigned long long int num_slaves;
105 struct GNUNET_TIME_Relative log_freq;
106 struct GNUNET_TIME_Relative max_duration;
107 struct GNUNET_TIME_Relative total_duration;
108 struct GNUNET_TIME_Absolute start_time;
109 unsigned int num_episodes;
110 struct Episode *start;
112 struct GNUNET_CONFIGURATION_Handle *cfg;
114 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
115 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
118 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
119 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
124 * A single logging time step for a partner
126 struct PartnerLoggingTimestep
131 struct BenchmarkPeer *slave;
134 * Total number of messages this peer has sent
136 unsigned int total_messages_sent;
139 * Total number of bytes this peer has sent
141 unsigned int total_bytes_sent;
144 * Total number of messages this peer has received
146 unsigned int total_messages_received;
149 * Total number of bytes this peer has received
151 unsigned int total_bytes_received;
154 * Total outbound throughput for master in Bytes / s
156 unsigned int throughput_sent;
159 * Total inbound throughput for master in Bytes / s
161 unsigned int throughput_recv;
164 * Accumulated RTT for all messages
166 unsigned int total_app_rtt;
169 * Current application level delay
171 unsigned int app_rtt;
173 /* Current ATS properties */
175 uint32_t ats_distance;
179 uint32_t bandwidth_in;
181 uint32_t bandwidth_out;
183 uint32_t ats_utilization_up;
185 uint32_t ats_utilization_down;
187 uint32_t ats_network_type;
189 uint32_t ats_cost_wan;
191 uint32_t ats_cost_lan;
193 uint32_t ats_cost_wlan;
195 double pref_bandwidth;
201 * A single logging time step for a peer
203 struct PeerLoggingTimestep
208 struct PeerLoggingTimestep *next;
213 struct PeerLoggingTimestep *prev;
218 struct GNUNET_TIME_Absolute timestamp;
221 * Total number of messages this peer has sent
223 unsigned int total_messages_sent;
226 * Total number of bytes this peer has sent
228 unsigned int total_bytes_sent;
231 * Total number of messages this peer has received
233 unsigned int total_messages_received;
236 * Total number of bytes this peer has received
238 unsigned int total_bytes_received;
241 * Total outbound throughput for master in Bytes / s
243 unsigned int total_throughput_send;
246 * Total inbound throughput for master in Bytes / s
248 unsigned int total_throughput_recv;
253 struct PartnerLoggingTimestep *slaves_log;
257 * Entry for a benchmark peer
264 struct BenchmarkPeer *peer;
269 struct GNUNET_TIME_Absolute start;
272 * DLL for logging entries: head
274 struct PeerLoggingTimestep *head;
277 * DLL for logging entries: tail
279 struct PeerLoggingTimestep *tail;
288 GNUNET_SCHEDULER_TaskIdentifier log_task;
291 * Reference to perf_ats' masters
298 struct GNUNET_TIME_Relative frequency;
301 * Log structure of length num_peers
303 struct LoggingPeer *lp;
310 * @param log_frequency the logging frequency
311 * @param testname the testname
312 * @param masters the master peers used for benchmarking
313 * @param num_master the number of master peers
314 * @return the logging handle or NULL on error
316 struct LoggingHandle *
317 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
318 char *testname, struct BenchmarkPeer *masters, int num_masters, int num_slaves,
324 * @param l the logging handle
327 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
332 * @param l the logging handle
335 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
340 * @param l logging handle to use
343 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
347 * Write logging data to file
349 * @param l logging handle to use
350 * @param test_name name of the current test
351 * @param plots create gnuplots: GNUNET_YES or GNUNET_NO
354 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
355 char *test_name, int plots);
365 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
368 * Message type sent for traffic generation
370 #define TEST_MESSAGE_TYPE_PING 12345
373 * Message type sent as response during traffic generation
375 #define TEST_MESSAGE_TYPE_PONG 12346
378 * Size of test messages
380 #define TEST_MESSAGE_SIZE 100
382 struct BenchmarkPartner;
384 struct BenchmarkPeer;
386 struct GNUNET_ATS_TEST_Topology;
388 struct TrafficGenerator;
395 * Callback to call when topology setup is completed
397 * @param cls the closure
398 * @param masters array of master peers
399 * @param slaves array of master peers
401 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
402 struct BenchmarkPeer *masters,
403 struct BenchmarkPeer *slaves);
406 * Callback called when logging is required for the data contained
408 * @param cls the closure
409 * @param address an address
410 * @param address_active is address active
411 * @param bandwidth_out bandwidth outbound
412 * @param bandwidth_in bandwidth inbound
413 * @param ats ats information
414 * @param ats_count number of ats inforation
417 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
418 const struct GNUNET_HELLO_Address *address,
420 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
421 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
422 const struct GNUNET_ATS_Information *ats,
426 * Information we track for a peer in the testbed.
431 * Handle with testbed.
433 struct GNUNET_TESTBED_Peer *peer;
441 * Is this peer a measter: GNUNET_YES/GNUNET_NO
448 struct GNUNET_PeerIdentity id;
451 * Testbed operation to get peer information
453 struct GNUNET_TESTBED_Operation *peer_id_op;
456 * Testbed operation to connect to ATS performance service
458 struct GNUNET_TESTBED_Operation *ats_perf_op;
461 * Testbed operation to connect to core
463 struct GNUNET_TESTBED_Operation *comm_op;
466 * ATS performance handle
468 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
472 * Testbed connect operations to connect masters to slaves
474 struct TestbedConnectOperation *core_connect_ops;
479 struct GNUNET_CORE_Handle *ch;
484 struct GNUNET_TRANSPORT_Handle *th;
488 * Peer to set ATS preferences for
490 struct BenchmarkPeer *pref_partner;
496 GNUNET_SCHEDULER_TaskIdentifier ats_task;
505 * Array of partners with num_slaves entries (if master) or
506 * num_master entries (if slave)
508 struct BenchmarkPartner *partners;
516 * Number of core connections
518 int core_connections;
522 * Number of connections to slave peers
524 int core_slave_connections;
527 * Total number of messages this peer has sent
529 unsigned int total_messages_sent;
532 * Total number of bytes this peer has sent
534 unsigned int total_bytes_sent;
537 * Total number of messages this peer has received
539 unsigned int total_messages_received;
542 * Total number of bytes this peer has received
544 unsigned int total_bytes_received;
547 struct TrafficGenerator
549 struct TrafficGenerator *prev;
550 struct TrafficGenerator *next;
552 enum GeneratorType type;
554 struct BenchmarkPeer *src;
555 struct BenchmarkPartner *dest;
559 struct GNUNET_TIME_Relative duration_period;
561 GNUNET_SCHEDULER_TaskIdentifier send_task;
562 struct GNUNET_TIME_Absolute next_ping_transmission;
563 struct GNUNET_TIME_Absolute time_start;
567 struct PreferenceGenerator
569 struct PreferenceGenerator *prev;
570 struct PreferenceGenerator *next;
572 enum GeneratorType type;
574 struct BenchmarkPeer *src;
575 struct BenchmarkPartner *dest;
577 enum GNUNET_ATS_PreferenceKind kind;
581 struct GNUNET_TIME_Relative duration_period;
582 struct GNUNET_TIME_Relative frequency;
584 GNUNET_SCHEDULER_TaskIdentifier set_task;
585 struct GNUNET_TIME_Absolute next_ping_transmission;
586 struct GNUNET_TIME_Absolute time_start;
590 * Information about a benchmarking partner
592 struct BenchmarkPartner
595 * The peer itself this partner belongs to
597 struct BenchmarkPeer *me;
602 struct BenchmarkPeer *dest;
605 * Core transmit handles
607 struct GNUNET_CORE_TransmitHandle *cth;
610 * Transport transmit handles
612 struct GNUNET_TRANSPORT_TransmitHandle *tth;
614 struct TrafficGenerator *tg;
615 struct PreferenceGenerator *pg;
618 * Timestamp to calculate communication layer delay
620 struct GNUNET_TIME_Absolute last_message_sent;
623 * Accumulated RTT for all messages
625 unsigned int total_app_rtt;
628 * Number of messages sent to this partner
630 unsigned int messages_sent;
633 * Number of bytes sent to this partner
635 unsigned int bytes_sent;
638 * Number of messages received from this partner
640 unsigned int messages_received;
643 * Number of bytes received from this partner
645 unsigned int bytes_received;
647 /* Current ATS properties */
649 uint32_t ats_distance;
653 uint32_t bandwidth_in;
655 uint32_t bandwidth_out;
657 uint32_t ats_utilization_up;
659 uint32_t ats_utilization_down;
661 uint32_t ats_network_type;
663 uint32_t ats_cost_wan;
665 uint32_t ats_cost_lan;
667 uint32_t ats_cost_wlan;
669 double pref_bandwidth;
674 * Overall state of the performance benchmark
676 struct BenchmarkState
679 * Are we connected to ATS service of all peers: GNUNET_YES/NO
681 int connected_ATS_service;
684 * Are we connected to CORE service of all peers: GNUNET_YES/NO
686 int connected_COMM_service;
689 * Are we connected to all peers: GNUNET_YES/NO
694 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
699 * Are we connected to CORE service of all peers: GNUNET_YES/NO
705 struct GNUNET_ATS_TEST_Topology
710 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
715 GNUNET_SCHEDULER_TaskIdentifier progress_task;
722 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
742 * ATS preference value
747 * Number master peers
749 unsigned int num_masters;
752 * Array of master peers
754 struct BenchmarkPeer *mps;
759 unsigned int num_slaves;
762 * Array of slave peers
764 struct BenchmarkPeer *sps;
769 struct GNUNET_TIME_Relative perf_duration;
774 struct GNUNET_TIME_Relative log_frequency;
779 struct BenchmarkState state;
781 struct GNUNET_CORE_MessageHandler *handlers;
783 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
785 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
786 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
793 * Experiment related functions
798 * Execute the specified experiment
800 * @param e the Experiment
801 * @param ep_done_cb a episode is completed
802 * @param e_done_cb the experiment is completed
805 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
806 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
807 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
810 * Load an experiment from a file
812 * @param filename the file
813 * @return the Experiment or NULL on failure
816 GNUNET_ATS_TEST_experimentation_load (char *filename);
822 * @param e the experiment
825 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
828 * Traffic related functions
832 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
835 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
839 * Generate between the source master and the partner and send traffic with a
842 * @param src traffic source
843 * @param dest traffic partner
844 * @param type type of traffic to generate
845 * @param base_rate traffic base rate to send data with
846 * @param max_rate traffic maximum rate to send data with
847 * @param period duration of a period of traffic generation (~ 1/frequency)
848 * @param duration how long to generate traffic
849 * @return the traffic generator
851 struct TrafficGenerator *
852 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
853 struct BenchmarkPartner *dest,
854 enum GeneratorType type,
857 struct GNUNET_TIME_Relative period,
858 struct GNUNET_TIME_Relative duration);
861 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
864 * Stop all traffic generators
867 GNUNET_ATS_TEST_generate_traffic_stop_all ();
869 struct PreferenceGenerator *
870 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
871 struct BenchmarkPartner *dest,
872 enum GeneratorType type,
875 struct GNUNET_TIME_Relative period,
876 struct GNUNET_TIME_Relative frequency,
877 enum GNUNET_ATS_PreferenceKind kind);
880 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
883 GNUNET_ATS_TEST_generate_preferences_stop_all ();
886 * Logging related functions
892 * Topology related functions
895 struct BenchmarkPeer *
896 GNUNET_ATS_TEST_get_peer (int src);
898 struct BenchmarkPartner *
899 GNUNET_ATS_TEST_get_partner (int src, int dest);
902 * Create a topology for ats testing
904 * @param name test name
905 * @param cfg_file configuration file to use for the peers
906 * @param num_slaves number of slaves
907 * @param num_masters number of masters
908 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
909 * @param done_cb function to call when topology is setup
910 * @param done_cb_cls cls for callback
911 * @param recv_cb callback to call when data are received
912 * @param perf_cb callback to call when performance info are received
915 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
916 unsigned int num_slaves,
917 unsigned int num_masters,
919 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
921 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
922 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
928 GNUNET_ATS_TEST_shutdown_topology (void);
930 /* end of file ats-testing.h */