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,
88 struct TestPeer *prev;
89 struct TestPeer *next;
92 struct GNUNET_PeerIdentity peer_id;
100 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
103 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
104 struct GNUNET_TIME_Relative duration,int success);
107 * An operation in an experiment
109 struct GNUNET_ATS_TEST_Operation
111 struct GNUNET_ATS_TEST_Operation *next;
112 struct GNUNET_ATS_TEST_Operation *prev;
114 long long unsigned int address_id;
115 long long unsigned int peer_id;
116 long long unsigned int address_session;
117 long long unsigned int address_network;
122 long long unsigned int base_rate;
123 long long unsigned int max_rate;
124 struct GNUNET_TIME_Relative period;
125 struct GNUNET_TIME_Relative frequency;
127 enum OperationType type;
128 enum GeneratorType gen_type;
129 enum GNUNET_ATS_PreferenceKind pref_type;
130 enum GNUNET_ATS_Property prop_type;
136 struct Episode *next;
137 struct GNUNET_TIME_Relative duration;
139 struct GNUNET_ATS_TEST_Operation *head;
140 struct GNUNET_ATS_TEST_Operation *tail;
145 GNUNET_SCHEDULER_TaskIdentifier logging_task;
146 struct GNUNET_TIME_Relative log_freq;
153 unsigned long long int num_masters;
154 unsigned long long int num_slaves;
155 struct GNUNET_TIME_Relative log_freq;
156 struct GNUNET_TIME_Relative max_duration;
157 struct GNUNET_TIME_Relative total_duration;
158 struct GNUNET_TIME_Absolute start_time;
159 unsigned int num_episodes;
160 struct Episode *start;
162 struct GNUNET_CONFIGURATION_Handle *cfg;
164 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
165 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
168 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
169 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
172 struct PreferenceGenerator
174 struct PreferenceGenerator *prev;
175 struct PreferenceGenerator *next;
177 enum GeneratorType type;
180 unsigned int address_id;
182 enum GNUNET_ATS_PreferenceKind kind;
186 struct GNUNET_TIME_Relative duration_period;
187 struct GNUNET_TIME_Relative frequency;
189 GNUNET_SCHEDULER_TaskIdentifier set_task;
190 struct GNUNET_TIME_Absolute next_ping_transmission;
191 struct GNUNET_TIME_Absolute time_start;
195 struct PropertyGenerator
197 struct PropertyGenerator *prev;
198 struct PropertyGenerator *next;
200 enum GeneratorType type;
203 unsigned int address_id;
205 uint32_t ats_property;
209 struct GNUNET_TIME_Relative duration_period;
210 struct GNUNET_TIME_Relative frequency;
212 GNUNET_SCHEDULER_TaskIdentifier set_task;
213 struct GNUNET_TIME_Absolute next_ping_transmission;
214 struct GNUNET_TIME_Absolute time_start;
221 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
224 * Message type sent for traffic generation
226 #define TEST_MESSAGE_TYPE_PING 12345
229 * Message type sent as response during traffic generation
231 #define TEST_MESSAGE_TYPE_PONG 12346
234 * Size of test messages
236 #define TEST_MESSAGE_SIZE 100
238 struct BenchmarkPartner;
240 struct BenchmarkPeer;
242 struct GNUNET_ATS_TEST_Topology;
244 struct TrafficGenerator;
251 * Callback to call when topology setup is completed
253 * @param cls the closure
254 * @param masters array of master peers
255 * @param slaves array of master peers
257 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
258 struct BenchmarkPeer *masters,
259 struct BenchmarkPeer *slaves);
262 * Callback called when logging is required for the data contained
264 * @param cls the closure
265 * @param address an address
266 * @param address_active is address active
267 * @param bandwidth_out bandwidth outbound
268 * @param bandwidth_in bandwidth inbound
269 * @param ats ats information
270 * @param ats_count number of ats inforation
273 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
274 const struct GNUNET_HELLO_Address *address_id,
276 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
277 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
278 const struct GNUNET_ATS_Information *ats,
282 * Information we track for a peer in the testbed.
287 * Handle with testbed.
289 struct GNUNET_TESTBED_Peer *peer;
297 * Is this peer a measter: GNUNET_YES/GNUNET_NO
304 struct GNUNET_PeerIdentity id;
307 * Testbed operation to get peer information
309 struct GNUNET_TESTBED_Operation *peer_id_op;
312 * Testbed operation to connect to ATS performance service
314 struct GNUNET_TESTBED_Operation *ats_perf_op;
317 * Testbed operation to connect to core
319 struct GNUNET_TESTBED_Operation *comm_op;
322 * ATS performance handle
324 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
328 * Testbed connect operations to connect masters to slaves
330 struct TestbedConnectOperation *core_connect_ops;
335 struct GNUNET_CORE_Handle *ch;
340 struct GNUNET_TRANSPORT_Handle *th;
344 * Peer to set ATS preferences for
346 struct BenchmarkPeer *pref_partner;
352 GNUNET_SCHEDULER_TaskIdentifier ats_task;
361 * Array of partners with num_slaves entries (if master) or
362 * num_master entries (if slave)
364 struct BenchmarkPartner *partners;
372 * Number of core connections
374 int core_connections;
378 * Number of connections to slave peers
380 int core_slave_connections;
383 * Total number of messages this peer has sent
385 unsigned int total_messages_sent;
388 * Total number of bytes this peer has sent
390 unsigned int total_bytes_sent;
393 * Total number of messages this peer has received
395 unsigned int total_messages_received;
398 * Total number of bytes this peer has received
400 unsigned int total_bytes_received;
403 struct TrafficGenerator
405 struct TrafficGenerator *prev;
406 struct TrafficGenerator *next;
408 enum GeneratorType type;
410 struct BenchmarkPeer *src;
411 struct BenchmarkPartner *dest;
415 struct GNUNET_TIME_Relative duration_period;
417 GNUNET_SCHEDULER_TaskIdentifier send_task;
418 struct GNUNET_TIME_Absolute next_ping_transmission;
419 struct GNUNET_TIME_Absolute time_start;
423 struct PreferenceGenerator
425 struct PreferenceGenerator *prev;
426 struct PreferenceGenerator *next;
428 enum GeneratorType type;
430 struct BenchmarkPeer *src;
431 struct BenchmarkPartner *dest;
433 enum GNUNET_ATS_PreferenceKind kind;
437 struct GNUNET_TIME_Relative duration_period;
438 struct GNUNET_TIME_Relative frequency;
440 GNUNET_SCHEDULER_TaskIdentifier set_task;
441 struct GNUNET_TIME_Absolute next_ping_transmission;
442 struct GNUNET_TIME_Absolute time_start;
446 * Information about a benchmarking partner
448 struct BenchmarkPartner
451 * The peer itself this partner belongs to
453 struct BenchmarkPeer *me;
458 struct BenchmarkPeer *dest;
461 * Core transmit handles
463 struct GNUNET_CORE_TransmitHandle *cth;
466 * Transport transmit handles
468 struct GNUNET_TRANSPORT_TransmitHandle *tth;
470 struct TrafficGenerator *tg;
471 struct PreferenceGenerator *pg;
474 * Timestamp to calculate communication layer delay
476 struct GNUNET_TIME_Absolute last_message_sent;
479 * Accumulated RTT for all messages
481 unsigned int total_app_rtt;
484 * Number of messages sent to this partner
486 unsigned int messages_sent;
489 * Number of bytes sent to this partner
491 unsigned int bytes_sent;
494 * Number of messages received from this partner
496 unsigned int messages_received;
499 * Number of bytes received from this partner
501 unsigned int bytes_received;
503 /* Current ATS properties */
505 uint32_t ats_distance;
509 uint32_t bandwidth_in;
511 uint32_t bandwidth_out;
513 uint32_t ats_utilization_up;
515 uint32_t ats_utilization_down;
517 uint32_t ats_network_type;
519 uint32_t ats_cost_wan;
521 uint32_t ats_cost_lan;
523 uint32_t ats_cost_wlan;
525 double pref_bandwidth;
530 * Overall state of the performance benchmark
532 struct BenchmarkState
535 * Are we connected to ATS service of all peers: GNUNET_YES/NO
537 int connected_ATS_service;
540 * Are we connected to CORE service of all peers: GNUNET_YES/NO
542 int connected_COMM_service;
545 * Are we connected to all peers: GNUNET_YES/NO
550 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
555 * Are we connected to CORE service of all peers: GNUNET_YES/NO
561 struct GNUNET_ATS_TEST_Topology
566 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
571 GNUNET_SCHEDULER_TaskIdentifier progress_task;
578 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
598 * ATS preference value
603 * Number master peers
605 unsigned int num_masters;
608 * Array of master peers
610 struct BenchmarkPeer *mps;
615 unsigned int num_slaves;
618 * Array of slave peers
620 struct BenchmarkPeer *sps;
625 struct GNUNET_TIME_Relative perf_duration;
630 struct GNUNET_TIME_Relative log_frequency;
635 struct BenchmarkState state;
637 struct GNUNET_CORE_MessageHandler *handlers;
639 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
641 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
642 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
649 * Experiment related functions
654 * Execute the specified experiment
656 * @param e the Experiment
657 * @param ep_done_cb a episode is completed
658 * @param e_done_cb the experiment is completed
661 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
662 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
663 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
666 * Load an experiment from a file
668 * @param filename the file
669 * @return the Experiment or NULL on failure
672 GNUNET_ATS_TEST_experimentation_load (char *filename);
678 * @param e the experiment
681 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
684 * Traffic related functions
688 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
691 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
695 * Generate between the source master and the partner and send traffic with a
698 * @param src traffic source
699 * @param dest traffic partner
700 * @param type type of traffic to generate
701 * @param base_rate traffic base rate to send data with
702 * @param max_rate traffic maximum rate to send data with
703 * @param period duration of a period of traffic generation (~ 1/frequency)
704 * @param duration how long to generate traffic
705 * @return the traffic generator
707 struct TrafficGenerator *
708 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
709 struct BenchmarkPartner *dest,
710 enum GeneratorType type,
713 struct GNUNET_TIME_Relative period,
714 struct GNUNET_TIME_Relative duration);
717 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
720 * Stop all traffic generators
723 GNUNET_ATS_TEST_generate_traffic_stop_all ();
725 struct PreferenceGenerator *
726 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
727 struct BenchmarkPartner *dest,
728 enum GeneratorType type,
731 struct GNUNET_TIME_Relative period,
732 struct GNUNET_TIME_Relative frequency,
733 enum GNUNET_ATS_PreferenceKind kind);
736 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
739 GNUNET_ATS_TEST_generate_preferences_stop_all ();
742 * Logging related functions
748 * Topology related functions
751 struct BenchmarkPeer *
752 GNUNET_ATS_TEST_get_peer (int src);
754 struct BenchmarkPartner *
755 GNUNET_ATS_TEST_get_partner (int src, int dest);
758 * Create a topology for ats testing
760 * @param name test name
761 * @param cfg_file configuration file to use for the peers
762 * @param num_slaves number of slaves
763 * @param num_masters number of masters
764 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
765 * @param done_cb function to call when topology is setup
766 * @param done_cb_cls cls for callback
767 * @param recv_cb callback to call when data are received
768 * @param perf_cb callback to call when performance info are received
771 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
772 unsigned int num_slaves,
773 unsigned int num_masters,
775 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
777 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
778 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
784 GNUNET_ATS_TEST_shutdown_topology (void);
786 /* end of file ats-testing.h */