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;
124 struct PreferenceGenerator
126 struct PreferenceGenerator *prev;
127 struct PreferenceGenerator *next;
129 enum GeneratorType type;
132 unsigned int address_id;
134 enum GNUNET_ATS_PreferenceKind kind;
138 struct GNUNET_TIME_Relative duration_period;
139 struct GNUNET_TIME_Relative frequency;
141 GNUNET_SCHEDULER_TaskIdentifier set_task;
142 struct GNUNET_TIME_Absolute next_ping_transmission;
143 struct GNUNET_TIME_Absolute time_start;
147 struct PropertyGenerator
149 struct PropertyGenerator *prev;
150 struct PropertyGenerator *next;
152 enum GeneratorType type;
155 unsigned int address_id;
157 uint32_t ats_property;
161 struct GNUNET_TIME_Relative duration_period;
162 struct GNUNET_TIME_Relative frequency;
164 GNUNET_SCHEDULER_TaskIdentifier set_task;
165 struct GNUNET_TIME_Absolute next_ping_transmission;
166 struct GNUNET_TIME_Absolute time_start;
173 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
176 * Message type sent for traffic generation
178 #define TEST_MESSAGE_TYPE_PING 12345
181 * Message type sent as response during traffic generation
183 #define TEST_MESSAGE_TYPE_PONG 12346
186 * Size of test messages
188 #define TEST_MESSAGE_SIZE 100
190 struct BenchmarkPartner;
192 struct BenchmarkPeer;
194 struct GNUNET_ATS_TEST_Topology;
196 struct TrafficGenerator;
203 * Callback to call when topology setup is completed
205 * @param cls the closure
206 * @param masters array of master peers
207 * @param slaves array of master peers
209 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
210 struct BenchmarkPeer *masters,
211 struct BenchmarkPeer *slaves);
214 * Callback called when logging is required for the data contained
216 * @param cls the closure
217 * @param address an address
218 * @param address_active is address active
219 * @param bandwidth_out bandwidth outbound
220 * @param bandwidth_in bandwidth inbound
221 * @param ats ats information
222 * @param ats_count number of ats inforation
225 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
226 const struct GNUNET_HELLO_Address *address_id,
228 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
229 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
230 const struct GNUNET_ATS_Information *ats,
234 * Information we track for a peer in the testbed.
239 * Handle with testbed.
241 struct GNUNET_TESTBED_Peer *peer;
249 * Is this peer a measter: GNUNET_YES/GNUNET_NO
256 struct GNUNET_PeerIdentity id;
259 * Testbed operation to get peer information
261 struct GNUNET_TESTBED_Operation *peer_id_op;
264 * Testbed operation to connect to ATS performance service
266 struct GNUNET_TESTBED_Operation *ats_perf_op;
269 * Testbed operation to connect to core
271 struct GNUNET_TESTBED_Operation *comm_op;
274 * ATS performance handle
276 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
280 * Testbed connect operations to connect masters to slaves
282 struct TestbedConnectOperation *core_connect_ops;
287 struct GNUNET_CORE_Handle *ch;
292 struct GNUNET_TRANSPORT_Handle *th;
296 * Peer to set ATS preferences for
298 struct BenchmarkPeer *pref_partner;
304 GNUNET_SCHEDULER_TaskIdentifier ats_task;
313 * Array of partners with num_slaves entries (if master) or
314 * num_master entries (if slave)
316 struct BenchmarkPartner *partners;
324 * Number of core connections
326 int core_connections;
330 * Number of connections to slave peers
332 int core_slave_connections;
335 * Total number of messages this peer has sent
337 unsigned int total_messages_sent;
340 * Total number of bytes this peer has sent
342 unsigned int total_bytes_sent;
345 * Total number of messages this peer has received
347 unsigned int total_messages_received;
350 * Total number of bytes this peer has received
352 unsigned int total_bytes_received;
355 struct TrafficGenerator
357 struct TrafficGenerator *prev;
358 struct TrafficGenerator *next;
360 enum GeneratorType type;
362 struct BenchmarkPeer *src;
363 struct BenchmarkPartner *dest;
367 struct GNUNET_TIME_Relative duration_period;
369 GNUNET_SCHEDULER_TaskIdentifier send_task;
370 struct GNUNET_TIME_Absolute next_ping_transmission;
371 struct GNUNET_TIME_Absolute time_start;
375 struct PreferenceGenerator
377 struct PreferenceGenerator *prev;
378 struct PreferenceGenerator *next;
380 enum GeneratorType type;
382 struct BenchmarkPeer *src;
383 struct BenchmarkPartner *dest;
385 enum GNUNET_ATS_PreferenceKind kind;
389 struct GNUNET_TIME_Relative duration_period;
390 struct GNUNET_TIME_Relative frequency;
392 GNUNET_SCHEDULER_TaskIdentifier set_task;
393 struct GNUNET_TIME_Absolute next_ping_transmission;
394 struct GNUNET_TIME_Absolute time_start;
398 * Information about a benchmarking partner
400 struct BenchmarkPartner
403 * The peer itself this partner belongs to
405 struct BenchmarkPeer *me;
410 struct BenchmarkPeer *dest;
413 * Core transmit handles
415 struct GNUNET_CORE_TransmitHandle *cth;
418 * Transport transmit handles
420 struct GNUNET_TRANSPORT_TransmitHandle *tth;
422 struct TrafficGenerator *tg;
423 struct PreferenceGenerator *pg;
426 * Timestamp to calculate communication layer delay
428 struct GNUNET_TIME_Absolute last_message_sent;
431 * Accumulated RTT for all messages
433 unsigned int total_app_rtt;
436 * Number of messages sent to this partner
438 unsigned int messages_sent;
441 * Number of bytes sent to this partner
443 unsigned int bytes_sent;
446 * Number of messages received from this partner
448 unsigned int messages_received;
451 * Number of bytes received from this partner
453 unsigned int bytes_received;
455 /* Current ATS properties */
457 uint32_t ats_distance;
461 uint32_t bandwidth_in;
463 uint32_t bandwidth_out;
465 uint32_t ats_utilization_up;
467 uint32_t ats_utilization_down;
469 uint32_t ats_network_type;
471 uint32_t ats_cost_wan;
473 uint32_t ats_cost_lan;
475 uint32_t ats_cost_wlan;
477 double pref_bandwidth;
482 * Overall state of the performance benchmark
484 struct BenchmarkState
487 * Are we connected to ATS service of all peers: GNUNET_YES/NO
489 int connected_ATS_service;
492 * Are we connected to CORE service of all peers: GNUNET_YES/NO
494 int connected_COMM_service;
497 * Are we connected to all peers: GNUNET_YES/NO
502 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
507 * Are we connected to CORE service of all peers: GNUNET_YES/NO
513 struct GNUNET_ATS_TEST_Topology
518 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
523 GNUNET_SCHEDULER_TaskIdentifier progress_task;
530 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
550 * ATS preference value
555 * Number master peers
557 unsigned int num_masters;
560 * Array of master peers
562 struct BenchmarkPeer *mps;
567 unsigned int num_slaves;
570 * Array of slave peers
572 struct BenchmarkPeer *sps;
577 struct GNUNET_TIME_Relative perf_duration;
582 struct GNUNET_TIME_Relative log_frequency;
587 struct BenchmarkState state;
589 struct GNUNET_CORE_MessageHandler *handlers;
591 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
593 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
594 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
601 * Experiment related functions
606 * Execute the specified experiment
608 * @param e the Experiment
609 * @param ep_done_cb a episode is completed
610 * @param e_done_cb the experiment is completed
613 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
614 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
615 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
618 * Load an experiment from a file
620 * @param filename the file
621 * @return the Experiment or NULL on failure
624 GNUNET_ATS_TEST_experimentation_load (char *filename);
630 * @param e the experiment
633 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
636 * Traffic related functions
640 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
643 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
647 * Generate between the source master and the partner and send traffic with a
650 * @param src traffic source
651 * @param dest traffic partner
652 * @param type type of traffic to generate
653 * @param base_rate traffic base rate to send data with
654 * @param max_rate traffic maximum rate to send data with
655 * @param period duration of a period of traffic generation (~ 1/frequency)
656 * @param duration how long to generate traffic
657 * @return the traffic generator
659 struct TrafficGenerator *
660 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
661 struct BenchmarkPartner *dest,
662 enum GeneratorType type,
665 struct GNUNET_TIME_Relative period,
666 struct GNUNET_TIME_Relative duration);
669 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
672 * Stop all traffic generators
675 GNUNET_ATS_TEST_generate_traffic_stop_all ();
677 struct PreferenceGenerator *
678 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
679 struct BenchmarkPartner *dest,
680 enum GeneratorType type,
683 struct GNUNET_TIME_Relative period,
684 struct GNUNET_TIME_Relative frequency,
685 enum GNUNET_ATS_PreferenceKind kind);
688 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
691 GNUNET_ATS_TEST_generate_preferences_stop_all ();
694 * Logging related functions
700 * Topology related functions
703 struct BenchmarkPeer *
704 GNUNET_ATS_TEST_get_peer (int src);
706 struct BenchmarkPartner *
707 GNUNET_ATS_TEST_get_partner (int src, int dest);
710 * Create a topology for ats testing
712 * @param name test name
713 * @param cfg_file configuration file to use for the peers
714 * @param num_slaves number of slaves
715 * @param num_masters number of masters
716 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
717 * @param done_cb function to call when topology is setup
718 * @param done_cb_cls cls for callback
719 * @param recv_cb callback to call when data are received
720 * @param perf_cb callback to call when performance info are received
723 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
724 unsigned int num_slaves,
725 unsigned int num_masters,
727 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
729 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
730 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
736 GNUNET_ATS_TEST_shutdown_topology (void);
738 /* end of file ats-testing.h */