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,
51 SOLVER_OP_START_REQUEST,
52 SOLVER_OP_STOP_REQUEST,
65 struct GNUNET_ATS_PluginEnvironment env;
75 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
78 enum GNUNET_ATS_Solvers
80 GNUNET_ATS_SOLVER_PROPORTIONAL,
81 GNUNET_ATS_SOLVER_MLP,
82 GNUNET_ATS_SOLVER_RIL,
86 struct LoggingTimeStep
88 struct LoggingTimeStep *prev;
89 struct LoggingTimeStep *next;
91 struct GNUNET_TIME_Absolute timestamp;
97 struct TestPeer *prev;
98 struct TestPeer *next;
101 struct GNUNET_PeerIdentity peer_id;
103 struct TestAddress *addr_head;
104 struct TestAddress *addr_tail;
110 struct TestAddress *next;
111 struct TestAddress *prev;
114 struct ATS_Address *ats_addr;
121 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
124 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
125 struct GNUNET_TIME_Relative duration,int success);
128 * An operation in an experiment
130 struct GNUNET_ATS_TEST_Operation
132 struct GNUNET_ATS_TEST_Operation *next;
133 struct GNUNET_ATS_TEST_Operation *prev;
135 long long unsigned int address_id;
136 long long unsigned int peer_id;
137 long long unsigned int client_id;
138 long long unsigned int address_session;
139 long long unsigned int address_network;
144 long long unsigned int base_rate;
145 long long unsigned int max_rate;
146 struct GNUNET_TIME_Relative period;
147 struct GNUNET_TIME_Relative frequency;
149 enum OperationType type;
150 enum GeneratorType gen_type;
151 enum GNUNET_ATS_PreferenceKind pref_type;
152 enum GNUNET_ATS_Property prop_type;
158 struct Episode *next;
159 struct GNUNET_TIME_Relative duration;
161 struct GNUNET_ATS_TEST_Operation *head;
162 struct GNUNET_ATS_TEST_Operation *tail;
167 GNUNET_SCHEDULER_TaskIdentifier logging_task;
168 struct GNUNET_TIME_Relative log_freq;
170 struct LoggingTimeStep *head;
172 struct LoggingTimeStep *tail;
179 struct GNUNET_TIME_Relative log_freq;
180 struct GNUNET_TIME_Relative max_duration;
181 struct GNUNET_TIME_Relative total_duration;
182 struct GNUNET_TIME_Absolute start_time;
183 unsigned int num_episodes;
184 struct Episode *start;
186 struct GNUNET_CONFIGURATION_Handle *cfg;
188 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
189 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
192 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
193 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
196 struct PreferenceGenerator
198 struct PreferenceGenerator *prev;
199 struct PreferenceGenerator *next;
201 enum GeneratorType type;
204 unsigned int address_id;
205 unsigned int client_id;
207 enum GNUNET_ATS_PreferenceKind kind;
211 struct GNUNET_TIME_Relative duration_period;
212 struct GNUNET_TIME_Relative frequency;
214 GNUNET_SCHEDULER_TaskIdentifier set_task;
215 struct GNUNET_TIME_Absolute next_ping_transmission;
216 struct GNUNET_TIME_Absolute time_start;
220 struct PropertyGenerator
222 struct PropertyGenerator *prev;
223 struct PropertyGenerator *next;
225 enum GeneratorType type;
228 unsigned int address_id;
230 struct TestPeer *test_peer;
231 struct TestAddress *test_address;
232 uint32_t ats_property;
236 struct GNUNET_TIME_Relative duration_period;
237 struct GNUNET_TIME_Relative frequency;
239 GNUNET_SCHEDULER_TaskIdentifier set_task;
240 struct GNUNET_TIME_Absolute next_ping_transmission;
241 struct GNUNET_TIME_Absolute time_start;
248 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
251 * Message type sent for traffic generation
253 #define TEST_MESSAGE_TYPE_PING 12345
256 * Message type sent as response during traffic generation
258 #define TEST_MESSAGE_TYPE_PONG 12346
261 * Size of test messages
263 #define TEST_MESSAGE_SIZE 100
265 struct BenchmarkPartner;
267 struct BenchmarkPeer;
269 struct GNUNET_ATS_TEST_Topology;
271 struct TrafficGenerator;
278 * Callback to call when topology setup is completed
280 * @param cls the closure
281 * @param masters array of master peers
282 * @param slaves array of master peers
284 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
285 struct BenchmarkPeer *masters,
286 struct BenchmarkPeer *slaves);
289 * Callback called when logging is required for the data contained
291 * @param cls the closure
292 * @param address an address
293 * @param address_active is address active
294 * @param bandwidth_out bandwidth outbound
295 * @param bandwidth_in bandwidth inbound
296 * @param ats ats information
297 * @param ats_count number of ats inforation
300 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
301 const struct GNUNET_HELLO_Address *address_id,
303 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
304 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
305 const struct GNUNET_ATS_Information *ats,
309 * Information we track for a peer in the testbed.
314 * Handle with testbed.
316 struct GNUNET_TESTBED_Peer *peer;
324 * Is this peer a measter: GNUNET_YES/GNUNET_NO
331 struct GNUNET_PeerIdentity id;
334 * Testbed operation to get peer information
336 struct GNUNET_TESTBED_Operation *peer_id_op;
339 * Testbed operation to connect to ATS performance service
341 struct GNUNET_TESTBED_Operation *ats_perf_op;
344 * Testbed operation to connect to core
346 struct GNUNET_TESTBED_Operation *comm_op;
349 * ATS performance handle
351 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
355 * Testbed connect operations to connect masters to slaves
357 struct TestbedConnectOperation *core_connect_ops;
362 struct GNUNET_CORE_Handle *ch;
367 struct GNUNET_TRANSPORT_Handle *th;
371 * Peer to set ATS preferences for
373 struct BenchmarkPeer *pref_partner;
379 GNUNET_SCHEDULER_TaskIdentifier ats_task;
388 * Array of partners with num_slaves entries (if master) or
389 * num_master entries (if slave)
391 struct BenchmarkPartner *partners;
399 * Number of core connections
401 int core_connections;
405 * Number of connections to slave peers
407 int core_slave_connections;
410 * Total number of messages this peer has sent
412 unsigned int total_messages_sent;
415 * Total number of bytes this peer has sent
417 unsigned int total_bytes_sent;
420 * Total number of messages this peer has received
422 unsigned int total_messages_received;
425 * Total number of bytes this peer has received
427 unsigned int total_bytes_received;
430 struct TrafficGenerator
432 struct TrafficGenerator *prev;
433 struct TrafficGenerator *next;
435 enum GeneratorType type;
437 struct BenchmarkPeer *src;
438 struct BenchmarkPartner *dest;
442 struct GNUNET_TIME_Relative duration_period;
444 GNUNET_SCHEDULER_TaskIdentifier send_task;
445 struct GNUNET_TIME_Absolute next_ping_transmission;
446 struct GNUNET_TIME_Absolute time_start;
450 struct PreferenceGenerator
452 struct PreferenceGenerator *prev;
453 struct PreferenceGenerator *next;
455 enum GeneratorType type;
457 struct BenchmarkPeer *src;
458 struct BenchmarkPartner *dest;
460 enum GNUNET_ATS_PreferenceKind kind;
464 struct GNUNET_TIME_Relative duration_period;
465 struct GNUNET_TIME_Relative frequency;
467 GNUNET_SCHEDULER_TaskIdentifier set_task;
468 struct GNUNET_TIME_Absolute next_ping_transmission;
469 struct GNUNET_TIME_Absolute time_start;
473 * Information about a benchmarking partner
475 struct BenchmarkPartner
478 * The peer itself this partner belongs to
480 struct BenchmarkPeer *me;
485 struct BenchmarkPeer *dest;
488 * Core transmit handles
490 struct GNUNET_CORE_TransmitHandle *cth;
493 * Transport transmit handles
495 struct GNUNET_TRANSPORT_TransmitHandle *tth;
497 struct TrafficGenerator *tg;
498 struct PreferenceGenerator *pg;
501 * Timestamp to calculate communication layer delay
503 struct GNUNET_TIME_Absolute last_message_sent;
506 * Accumulated RTT for all messages
508 unsigned int total_app_rtt;
511 * Number of messages sent to this partner
513 unsigned int messages_sent;
516 * Number of bytes sent to this partner
518 unsigned int bytes_sent;
521 * Number of messages received from this partner
523 unsigned int messages_received;
526 * Number of bytes received from this partner
528 unsigned int bytes_received;
530 /* Current ATS properties */
532 uint32_t ats_distance;
536 uint32_t bandwidth_in;
538 uint32_t bandwidth_out;
540 uint32_t ats_utilization_up;
542 uint32_t ats_utilization_down;
544 uint32_t ats_network_type;
546 uint32_t ats_cost_wan;
548 uint32_t ats_cost_lan;
550 uint32_t ats_cost_wlan;
552 double pref_bandwidth;
557 * Overall state of the performance benchmark
559 struct BenchmarkState
562 * Are we connected to ATS service of all peers: GNUNET_YES/NO
564 int connected_ATS_service;
567 * Are we connected to CORE service of all peers: GNUNET_YES/NO
569 int connected_COMM_service;
572 * Are we connected to all peers: GNUNET_YES/NO
577 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
582 * Are we connected to CORE service of all peers: GNUNET_YES/NO
588 struct GNUNET_ATS_TEST_Topology
593 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
598 GNUNET_SCHEDULER_TaskIdentifier progress_task;
605 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
625 * ATS preference value
630 * Number master peers
632 unsigned int num_masters;
635 * Array of master peers
637 struct BenchmarkPeer *mps;
642 unsigned int num_slaves;
645 * Array of slave peers
647 struct BenchmarkPeer *sps;
652 struct GNUNET_TIME_Relative perf_duration;
657 struct GNUNET_TIME_Relative log_frequency;
662 struct BenchmarkState state;
664 struct GNUNET_CORE_MessageHandler *handlers;
666 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
668 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
669 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
676 * Experiment related functions
681 * Execute the specified experiment
683 * @param e the Experiment
684 * @param ep_done_cb a episode is completed
685 * @param e_done_cb the experiment is completed
688 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
689 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
690 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
693 * Load an experiment from a file
695 * @param filename the file
696 * @return the Experiment or NULL on failure
699 GNUNET_ATS_TEST_experimentation_load (char *filename);
705 * @param e the experiment
708 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
711 * Traffic related functions
715 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
718 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
722 * Generate between the source master and the partner and send traffic with a
725 * @param src traffic source
726 * @param dest traffic partner
727 * @param type type of traffic to generate
728 * @param base_rate traffic base rate to send data with
729 * @param max_rate traffic maximum rate to send data with
730 * @param period duration of a period of traffic generation (~ 1/frequency)
731 * @param duration how long to generate traffic
732 * @return the traffic generator
734 struct TrafficGenerator *
735 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
736 struct BenchmarkPartner *dest,
737 enum GeneratorType type,
740 struct GNUNET_TIME_Relative period,
741 struct GNUNET_TIME_Relative duration);
744 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
747 * Stop all traffic generators
750 GNUNET_ATS_TEST_generate_traffic_stop_all ();
752 struct PreferenceGenerator *
753 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
754 struct BenchmarkPartner *dest,
755 enum GeneratorType type,
758 struct GNUNET_TIME_Relative period,
759 struct GNUNET_TIME_Relative frequency,
760 enum GNUNET_ATS_PreferenceKind kind);
763 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
766 GNUNET_ATS_TEST_generate_preferences_stop_all ();
769 * Logging related functions
775 * Topology related functions
778 struct BenchmarkPeer *
779 GNUNET_ATS_TEST_get_peer (int src);
781 struct BenchmarkPartner *
782 GNUNET_ATS_TEST_get_partner (int src, int dest);
785 * Create a topology for ats testing
787 * @param name test name
788 * @param cfg_file configuration file to use for the peers
789 * @param num_slaves number of slaves
790 * @param num_masters number of masters
791 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
792 * @param done_cb function to call when topology is setup
793 * @param done_cb_cls cls for callback
794 * @param recv_cb callback to call when data are received
795 * @param perf_cb callback to call when performance info are received
798 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
799 unsigned int num_slaves,
800 unsigned int num_masters,
802 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
804 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
805 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
811 GNUNET_ATS_TEST_shutdown_topology (void);
813 /* end of file ats-testing.h */