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 gen_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;
102 GNUNET_SCHEDULER_TaskIdentifier logging_task;
103 struct GNUNET_TIME_Relative log_freq;
110 unsigned long long int num_masters;
111 unsigned long long int num_slaves;
112 struct GNUNET_TIME_Relative log_freq;
113 struct GNUNET_TIME_Relative max_duration;
114 struct GNUNET_TIME_Relative total_duration;
115 struct GNUNET_TIME_Absolute start_time;
116 unsigned int num_episodes;
117 struct Episode *start;
119 struct GNUNET_CONFIGURATION_Handle *cfg;
121 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
122 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
125 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
126 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
129 struct PreferenceGenerator
131 struct PreferenceGenerator *prev;
132 struct PreferenceGenerator *next;
134 enum GeneratorType type;
137 unsigned int address_id;
139 enum GNUNET_ATS_PreferenceKind kind;
143 struct GNUNET_TIME_Relative duration_period;
144 struct GNUNET_TIME_Relative frequency;
146 GNUNET_SCHEDULER_TaskIdentifier set_task;
147 struct GNUNET_TIME_Absolute next_ping_transmission;
148 struct GNUNET_TIME_Absolute time_start;
152 struct PropertyGenerator
154 struct PropertyGenerator *prev;
155 struct PropertyGenerator *next;
157 enum GeneratorType type;
160 unsigned int address_id;
162 uint32_t ats_property;
166 struct GNUNET_TIME_Relative duration_period;
167 struct GNUNET_TIME_Relative frequency;
169 GNUNET_SCHEDULER_TaskIdentifier set_task;
170 struct GNUNET_TIME_Absolute next_ping_transmission;
171 struct GNUNET_TIME_Absolute time_start;
178 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
181 * Message type sent for traffic generation
183 #define TEST_MESSAGE_TYPE_PING 12345
186 * Message type sent as response during traffic generation
188 #define TEST_MESSAGE_TYPE_PONG 12346
191 * Size of test messages
193 #define TEST_MESSAGE_SIZE 100
195 struct BenchmarkPartner;
197 struct BenchmarkPeer;
199 struct GNUNET_ATS_TEST_Topology;
201 struct TrafficGenerator;
208 * Callback to call when topology setup is completed
210 * @param cls the closure
211 * @param masters array of master peers
212 * @param slaves array of master peers
214 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
215 struct BenchmarkPeer *masters,
216 struct BenchmarkPeer *slaves);
219 * Callback called when logging is required for the data contained
221 * @param cls the closure
222 * @param address an address
223 * @param address_active is address active
224 * @param bandwidth_out bandwidth outbound
225 * @param bandwidth_in bandwidth inbound
226 * @param ats ats information
227 * @param ats_count number of ats inforation
230 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
231 const struct GNUNET_HELLO_Address *address_id,
233 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
234 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
235 const struct GNUNET_ATS_Information *ats,
239 * Information we track for a peer in the testbed.
244 * Handle with testbed.
246 struct GNUNET_TESTBED_Peer *peer;
254 * Is this peer a measter: GNUNET_YES/GNUNET_NO
261 struct GNUNET_PeerIdentity id;
264 * Testbed operation to get peer information
266 struct GNUNET_TESTBED_Operation *peer_id_op;
269 * Testbed operation to connect to ATS performance service
271 struct GNUNET_TESTBED_Operation *ats_perf_op;
274 * Testbed operation to connect to core
276 struct GNUNET_TESTBED_Operation *comm_op;
279 * ATS performance handle
281 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
285 * Testbed connect operations to connect masters to slaves
287 struct TestbedConnectOperation *core_connect_ops;
292 struct GNUNET_CORE_Handle *ch;
297 struct GNUNET_TRANSPORT_Handle *th;
301 * Peer to set ATS preferences for
303 struct BenchmarkPeer *pref_partner;
309 GNUNET_SCHEDULER_TaskIdentifier ats_task;
318 * Array of partners with num_slaves entries (if master) or
319 * num_master entries (if slave)
321 struct BenchmarkPartner *partners;
329 * Number of core connections
331 int core_connections;
335 * Number of connections to slave peers
337 int core_slave_connections;
340 * Total number of messages this peer has sent
342 unsigned int total_messages_sent;
345 * Total number of bytes this peer has sent
347 unsigned int total_bytes_sent;
350 * Total number of messages this peer has received
352 unsigned int total_messages_received;
355 * Total number of bytes this peer has received
357 unsigned int total_bytes_received;
360 struct TrafficGenerator
362 struct TrafficGenerator *prev;
363 struct TrafficGenerator *next;
365 enum GeneratorType type;
367 struct BenchmarkPeer *src;
368 struct BenchmarkPartner *dest;
372 struct GNUNET_TIME_Relative duration_period;
374 GNUNET_SCHEDULER_TaskIdentifier send_task;
375 struct GNUNET_TIME_Absolute next_ping_transmission;
376 struct GNUNET_TIME_Absolute time_start;
380 struct PreferenceGenerator
382 struct PreferenceGenerator *prev;
383 struct PreferenceGenerator *next;
385 enum GeneratorType type;
387 struct BenchmarkPeer *src;
388 struct BenchmarkPartner *dest;
390 enum GNUNET_ATS_PreferenceKind kind;
394 struct GNUNET_TIME_Relative duration_period;
395 struct GNUNET_TIME_Relative frequency;
397 GNUNET_SCHEDULER_TaskIdentifier set_task;
398 struct GNUNET_TIME_Absolute next_ping_transmission;
399 struct GNUNET_TIME_Absolute time_start;
403 * Information about a benchmarking partner
405 struct BenchmarkPartner
408 * The peer itself this partner belongs to
410 struct BenchmarkPeer *me;
415 struct BenchmarkPeer *dest;
418 * Core transmit handles
420 struct GNUNET_CORE_TransmitHandle *cth;
423 * Transport transmit handles
425 struct GNUNET_TRANSPORT_TransmitHandle *tth;
427 struct TrafficGenerator *tg;
428 struct PreferenceGenerator *pg;
431 * Timestamp to calculate communication layer delay
433 struct GNUNET_TIME_Absolute last_message_sent;
436 * Accumulated RTT for all messages
438 unsigned int total_app_rtt;
441 * Number of messages sent to this partner
443 unsigned int messages_sent;
446 * Number of bytes sent to this partner
448 unsigned int bytes_sent;
451 * Number of messages received from this partner
453 unsigned int messages_received;
456 * Number of bytes received from this partner
458 unsigned int bytes_received;
460 /* Current ATS properties */
462 uint32_t ats_distance;
466 uint32_t bandwidth_in;
468 uint32_t bandwidth_out;
470 uint32_t ats_utilization_up;
472 uint32_t ats_utilization_down;
474 uint32_t ats_network_type;
476 uint32_t ats_cost_wan;
478 uint32_t ats_cost_lan;
480 uint32_t ats_cost_wlan;
482 double pref_bandwidth;
487 * Overall state of the performance benchmark
489 struct BenchmarkState
492 * Are we connected to ATS service of all peers: GNUNET_YES/NO
494 int connected_ATS_service;
497 * Are we connected to CORE service of all peers: GNUNET_YES/NO
499 int connected_COMM_service;
502 * Are we connected to all peers: GNUNET_YES/NO
507 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
512 * Are we connected to CORE service of all peers: GNUNET_YES/NO
518 struct GNUNET_ATS_TEST_Topology
523 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
528 GNUNET_SCHEDULER_TaskIdentifier progress_task;
535 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
555 * ATS preference value
560 * Number master peers
562 unsigned int num_masters;
565 * Array of master peers
567 struct BenchmarkPeer *mps;
572 unsigned int num_slaves;
575 * Array of slave peers
577 struct BenchmarkPeer *sps;
582 struct GNUNET_TIME_Relative perf_duration;
587 struct GNUNET_TIME_Relative log_frequency;
592 struct BenchmarkState state;
594 struct GNUNET_CORE_MessageHandler *handlers;
596 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
598 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
599 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
606 * Experiment related functions
611 * Execute the specified experiment
613 * @param e the Experiment
614 * @param ep_done_cb a episode is completed
615 * @param e_done_cb the experiment is completed
618 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
619 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
620 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
623 * Load an experiment from a file
625 * @param filename the file
626 * @return the Experiment or NULL on failure
629 GNUNET_ATS_TEST_experimentation_load (char *filename);
635 * @param e the experiment
638 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
641 * Traffic related functions
645 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
648 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
652 * Generate between the source master and the partner and send traffic with a
655 * @param src traffic source
656 * @param dest traffic partner
657 * @param type type of traffic to generate
658 * @param base_rate traffic base rate to send data with
659 * @param max_rate traffic maximum rate to send data with
660 * @param period duration of a period of traffic generation (~ 1/frequency)
661 * @param duration how long to generate traffic
662 * @return the traffic generator
664 struct TrafficGenerator *
665 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
666 struct BenchmarkPartner *dest,
667 enum GeneratorType type,
670 struct GNUNET_TIME_Relative period,
671 struct GNUNET_TIME_Relative duration);
674 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
677 * Stop all traffic generators
680 GNUNET_ATS_TEST_generate_traffic_stop_all ();
682 struct PreferenceGenerator *
683 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
684 struct BenchmarkPartner *dest,
685 enum GeneratorType type,
688 struct GNUNET_TIME_Relative period,
689 struct GNUNET_TIME_Relative frequency,
690 enum GNUNET_ATS_PreferenceKind kind);
693 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
696 GNUNET_ATS_TEST_generate_preferences_stop_all ();
699 * Logging related functions
705 * Topology related functions
708 struct BenchmarkPeer *
709 GNUNET_ATS_TEST_get_peer (int src);
711 struct BenchmarkPartner *
712 GNUNET_ATS_TEST_get_partner (int src, int dest);
715 * Create a topology for ats testing
717 * @param name test name
718 * @param cfg_file configuration file to use for the peers
719 * @param num_slaves number of slaves
720 * @param num_masters number of masters
721 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
722 * @param done_cb function to call when topology is setup
723 * @param done_cb_cls cls for callback
724 * @param recv_cb callback to call when data are received
725 * @param perf_cb callback to call when performance info are received
728 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
729 unsigned int num_slaves,
730 unsigned int num_masters,
732 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
734 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
735 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
741 GNUNET_ATS_TEST_shutdown_topology (void);
743 /* end of file ats-testing.h */