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;
94 struct TestAddress *addr_head;
95 struct TestAddress *addr_tail;
101 struct TestAddress *next;
102 struct TestAddress *prev;
105 struct ATS_Address *ats_addr;
112 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
115 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
116 struct GNUNET_TIME_Relative duration,int success);
119 * An operation in an experiment
121 struct GNUNET_ATS_TEST_Operation
123 struct GNUNET_ATS_TEST_Operation *next;
124 struct GNUNET_ATS_TEST_Operation *prev;
126 long long unsigned int address_id;
127 long long unsigned int peer_id;
128 long long unsigned int address_session;
129 long long unsigned int address_network;
134 long long unsigned int base_rate;
135 long long unsigned int max_rate;
136 struct GNUNET_TIME_Relative period;
137 struct GNUNET_TIME_Relative frequency;
139 enum OperationType type;
140 enum GeneratorType gen_type;
141 enum GNUNET_ATS_PreferenceKind pref_type;
142 enum GNUNET_ATS_Property prop_type;
148 struct Episode *next;
149 struct GNUNET_TIME_Relative duration;
151 struct GNUNET_ATS_TEST_Operation *head;
152 struct GNUNET_ATS_TEST_Operation *tail;
157 GNUNET_SCHEDULER_TaskIdentifier logging_task;
158 struct GNUNET_TIME_Relative log_freq;
165 unsigned long long int num_masters;
166 unsigned long long int num_slaves;
167 struct GNUNET_TIME_Relative log_freq;
168 struct GNUNET_TIME_Relative max_duration;
169 struct GNUNET_TIME_Relative total_duration;
170 struct GNUNET_TIME_Absolute start_time;
171 unsigned int num_episodes;
172 struct Episode *start;
174 struct GNUNET_CONFIGURATION_Handle *cfg;
176 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
177 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
180 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
181 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
184 struct PreferenceGenerator
186 struct PreferenceGenerator *prev;
187 struct PreferenceGenerator *next;
189 enum GeneratorType type;
192 unsigned int address_id;
194 enum GNUNET_ATS_PreferenceKind kind;
198 struct GNUNET_TIME_Relative duration_period;
199 struct GNUNET_TIME_Relative frequency;
201 GNUNET_SCHEDULER_TaskIdentifier set_task;
202 struct GNUNET_TIME_Absolute next_ping_transmission;
203 struct GNUNET_TIME_Absolute time_start;
207 struct PropertyGenerator
209 struct PropertyGenerator *prev;
210 struct PropertyGenerator *next;
212 enum GeneratorType type;
215 unsigned int address_id;
217 struct TestPeer *test_peer;
218 struct TestAddress *test_address;
219 uint32_t ats_property;
223 struct GNUNET_TIME_Relative duration_period;
224 struct GNUNET_TIME_Relative frequency;
226 GNUNET_SCHEDULER_TaskIdentifier set_task;
227 struct GNUNET_TIME_Absolute next_ping_transmission;
228 struct GNUNET_TIME_Absolute time_start;
235 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
238 * Message type sent for traffic generation
240 #define TEST_MESSAGE_TYPE_PING 12345
243 * Message type sent as response during traffic generation
245 #define TEST_MESSAGE_TYPE_PONG 12346
248 * Size of test messages
250 #define TEST_MESSAGE_SIZE 100
252 struct BenchmarkPartner;
254 struct BenchmarkPeer;
256 struct GNUNET_ATS_TEST_Topology;
258 struct TrafficGenerator;
265 * Callback to call when topology setup is completed
267 * @param cls the closure
268 * @param masters array of master peers
269 * @param slaves array of master peers
271 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
272 struct BenchmarkPeer *masters,
273 struct BenchmarkPeer *slaves);
276 * Callback called when logging is required for the data contained
278 * @param cls the closure
279 * @param address an address
280 * @param address_active is address active
281 * @param bandwidth_out bandwidth outbound
282 * @param bandwidth_in bandwidth inbound
283 * @param ats ats information
284 * @param ats_count number of ats inforation
287 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
288 const struct GNUNET_HELLO_Address *address_id,
290 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
291 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
292 const struct GNUNET_ATS_Information *ats,
296 * Information we track for a peer in the testbed.
301 * Handle with testbed.
303 struct GNUNET_TESTBED_Peer *peer;
311 * Is this peer a measter: GNUNET_YES/GNUNET_NO
318 struct GNUNET_PeerIdentity id;
321 * Testbed operation to get peer information
323 struct GNUNET_TESTBED_Operation *peer_id_op;
326 * Testbed operation to connect to ATS performance service
328 struct GNUNET_TESTBED_Operation *ats_perf_op;
331 * Testbed operation to connect to core
333 struct GNUNET_TESTBED_Operation *comm_op;
336 * ATS performance handle
338 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
342 * Testbed connect operations to connect masters to slaves
344 struct TestbedConnectOperation *core_connect_ops;
349 struct GNUNET_CORE_Handle *ch;
354 struct GNUNET_TRANSPORT_Handle *th;
358 * Peer to set ATS preferences for
360 struct BenchmarkPeer *pref_partner;
366 GNUNET_SCHEDULER_TaskIdentifier ats_task;
375 * Array of partners with num_slaves entries (if master) or
376 * num_master entries (if slave)
378 struct BenchmarkPartner *partners;
386 * Number of core connections
388 int core_connections;
392 * Number of connections to slave peers
394 int core_slave_connections;
397 * Total number of messages this peer has sent
399 unsigned int total_messages_sent;
402 * Total number of bytes this peer has sent
404 unsigned int total_bytes_sent;
407 * Total number of messages this peer has received
409 unsigned int total_messages_received;
412 * Total number of bytes this peer has received
414 unsigned int total_bytes_received;
417 struct TrafficGenerator
419 struct TrafficGenerator *prev;
420 struct TrafficGenerator *next;
422 enum GeneratorType type;
424 struct BenchmarkPeer *src;
425 struct BenchmarkPartner *dest;
429 struct GNUNET_TIME_Relative duration_period;
431 GNUNET_SCHEDULER_TaskIdentifier send_task;
432 struct GNUNET_TIME_Absolute next_ping_transmission;
433 struct GNUNET_TIME_Absolute time_start;
437 struct PreferenceGenerator
439 struct PreferenceGenerator *prev;
440 struct PreferenceGenerator *next;
442 enum GeneratorType type;
444 struct BenchmarkPeer *src;
445 struct BenchmarkPartner *dest;
447 enum GNUNET_ATS_PreferenceKind kind;
451 struct GNUNET_TIME_Relative duration_period;
452 struct GNUNET_TIME_Relative frequency;
454 GNUNET_SCHEDULER_TaskIdentifier set_task;
455 struct GNUNET_TIME_Absolute next_ping_transmission;
456 struct GNUNET_TIME_Absolute time_start;
460 * Information about a benchmarking partner
462 struct BenchmarkPartner
465 * The peer itself this partner belongs to
467 struct BenchmarkPeer *me;
472 struct BenchmarkPeer *dest;
475 * Core transmit handles
477 struct GNUNET_CORE_TransmitHandle *cth;
480 * Transport transmit handles
482 struct GNUNET_TRANSPORT_TransmitHandle *tth;
484 struct TrafficGenerator *tg;
485 struct PreferenceGenerator *pg;
488 * Timestamp to calculate communication layer delay
490 struct GNUNET_TIME_Absolute last_message_sent;
493 * Accumulated RTT for all messages
495 unsigned int total_app_rtt;
498 * Number of messages sent to this partner
500 unsigned int messages_sent;
503 * Number of bytes sent to this partner
505 unsigned int bytes_sent;
508 * Number of messages received from this partner
510 unsigned int messages_received;
513 * Number of bytes received from this partner
515 unsigned int bytes_received;
517 /* Current ATS properties */
519 uint32_t ats_distance;
523 uint32_t bandwidth_in;
525 uint32_t bandwidth_out;
527 uint32_t ats_utilization_up;
529 uint32_t ats_utilization_down;
531 uint32_t ats_network_type;
533 uint32_t ats_cost_wan;
535 uint32_t ats_cost_lan;
537 uint32_t ats_cost_wlan;
539 double pref_bandwidth;
544 * Overall state of the performance benchmark
546 struct BenchmarkState
549 * Are we connected to ATS service of all peers: GNUNET_YES/NO
551 int connected_ATS_service;
554 * Are we connected to CORE service of all peers: GNUNET_YES/NO
556 int connected_COMM_service;
559 * Are we connected to all peers: GNUNET_YES/NO
564 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
569 * Are we connected to CORE service of all peers: GNUNET_YES/NO
575 struct GNUNET_ATS_TEST_Topology
580 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
585 GNUNET_SCHEDULER_TaskIdentifier progress_task;
592 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
612 * ATS preference value
617 * Number master peers
619 unsigned int num_masters;
622 * Array of master peers
624 struct BenchmarkPeer *mps;
629 unsigned int num_slaves;
632 * Array of slave peers
634 struct BenchmarkPeer *sps;
639 struct GNUNET_TIME_Relative perf_duration;
644 struct GNUNET_TIME_Relative log_frequency;
649 struct BenchmarkState state;
651 struct GNUNET_CORE_MessageHandler *handlers;
653 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
655 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
656 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
663 * Experiment related functions
668 * Execute the specified experiment
670 * @param e the Experiment
671 * @param ep_done_cb a episode is completed
672 * @param e_done_cb the experiment is completed
675 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
676 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
677 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
680 * Load an experiment from a file
682 * @param filename the file
683 * @return the Experiment or NULL on failure
686 GNUNET_ATS_TEST_experimentation_load (char *filename);
692 * @param e the experiment
695 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
698 * Traffic related functions
702 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
705 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
709 * Generate between the source master and the partner and send traffic with a
712 * @param src traffic source
713 * @param dest traffic partner
714 * @param type type of traffic to generate
715 * @param base_rate traffic base rate to send data with
716 * @param max_rate traffic maximum rate to send data with
717 * @param period duration of a period of traffic generation (~ 1/frequency)
718 * @param duration how long to generate traffic
719 * @return the traffic generator
721 struct TrafficGenerator *
722 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
723 struct BenchmarkPartner *dest,
724 enum GeneratorType type,
727 struct GNUNET_TIME_Relative period,
728 struct GNUNET_TIME_Relative duration);
731 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
734 * Stop all traffic generators
737 GNUNET_ATS_TEST_generate_traffic_stop_all ();
739 struct PreferenceGenerator *
740 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
741 struct BenchmarkPartner *dest,
742 enum GeneratorType type,
745 struct GNUNET_TIME_Relative period,
746 struct GNUNET_TIME_Relative frequency,
747 enum GNUNET_ATS_PreferenceKind kind);
750 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
753 GNUNET_ATS_TEST_generate_preferences_stop_all ();
756 * Logging related functions
762 * Topology related functions
765 struct BenchmarkPeer *
766 GNUNET_ATS_TEST_get_peer (int src);
768 struct BenchmarkPartner *
769 GNUNET_ATS_TEST_get_partner (int src, int dest);
772 * Create a topology for ats testing
774 * @param name test name
775 * @param cfg_file configuration file to use for the peers
776 * @param num_slaves number of slaves
777 * @param num_masters number of masters
778 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
779 * @param done_cb function to call when topology is setup
780 * @param done_cb_cls cls for callback
781 * @param recv_cb callback to call when data are received
782 * @param perf_cb callback to call when performance info are received
785 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
786 unsigned int num_slaves,
787 unsigned int num_masters,
789 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
791 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
792 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
798 GNUNET_ATS_TEST_shutdown_topology (void);
800 /* end of file ats-testing.h */