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
26 #ifndef GNUNET_ATS_SOLVER_EVAL_H
27 #define GNUNET_ATS_SOLVER_EVAL_H
29 #include "gnunet_util_lib.h"
30 #include "gnunet_ats_plugin.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet-service-ats_addresses.h"
33 #include "gnunet-service-ats_normalization.h"
34 #include "test_ats_api_common.h"
38 GNUNET_ATS_TEST_TG_LINEAR,
39 GNUNET_ATS_TEST_TG_CONSTANT,
40 GNUNET_ATS_TEST_TG_RANDOM,
41 GNUNET_ATS_TEST_TG_SINUS
47 SOLVER_OP_ADD_ADDRESS,
48 SOLVER_OP_DEL_ADDRESS,
49 SOLVER_OP_START_SET_PROPERTY,
50 SOLVER_OP_STOP_SET_PROPERTY,
51 SOLVER_OP_START_SET_PREFERENCE,
52 SOLVER_OP_STOP_SET_PREFERENCE,
53 SOLVER_OP_START_REQUEST,
54 SOLVER_OP_STOP_REQUEST,
67 struct GNUNET_ATS_PluginEnvironment env;
77 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
80 enum GNUNET_ATS_Solvers
82 GNUNET_ATS_SOLVER_PROPORTIONAL,
83 GNUNET_ATS_SOLVER_MLP,
84 GNUNET_ATS_SOLVER_RIL,
88 struct LoggingTimeStep
90 struct LoggingTimeStep *prev;
91 struct LoggingTimeStep *next;
93 struct GNUNET_TIME_Absolute timestamp;
99 struct TestPeer *prev;
100 struct TestPeer *next;
103 struct GNUNET_PeerIdentity peer_id;
105 struct TestAddress *addr_head;
106 struct TestAddress *addr_tail;
112 struct TestAddress *next;
113 struct TestAddress *prev;
116 struct ATS_Address *ats_addr;
123 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
126 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
127 struct GNUNET_TIME_Relative duration,int success);
130 * An operation in an experiment
132 struct GNUNET_ATS_TEST_Operation
134 struct GNUNET_ATS_TEST_Operation *next;
135 struct GNUNET_ATS_TEST_Operation *prev;
137 long long unsigned int address_id;
138 long long unsigned int peer_id;
139 long long unsigned int client_id;
140 long long unsigned int address_session;
141 long long unsigned int address_network;
146 long long unsigned int base_rate;
147 long long unsigned int max_rate;
148 struct GNUNET_TIME_Relative period;
149 struct GNUNET_TIME_Relative frequency;
151 enum OperationType type;
152 enum GeneratorType gen_type;
153 enum GNUNET_ATS_PreferenceKind pref_type;
154 enum GNUNET_ATS_Property prop_type;
160 struct Episode *next;
161 struct GNUNET_TIME_Relative duration;
163 struct GNUNET_ATS_TEST_Operation *head;
164 struct GNUNET_ATS_TEST_Operation *tail;
169 GNUNET_SCHEDULER_TaskIdentifier logging_task;
170 struct GNUNET_TIME_Relative log_freq;
172 struct LoggingTimeStep *head;
174 struct LoggingTimeStep *tail;
181 struct GNUNET_TIME_Relative log_freq;
182 struct GNUNET_TIME_Relative max_duration;
183 struct GNUNET_TIME_Relative total_duration;
184 struct GNUNET_TIME_Absolute start_time;
185 unsigned int num_episodes;
186 struct Episode *start;
188 struct GNUNET_CONFIGURATION_Handle *cfg;
190 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
191 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
194 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
195 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
198 struct PreferenceGenerator
200 struct PreferenceGenerator *prev;
201 struct PreferenceGenerator *next;
203 enum GeneratorType type;
206 unsigned int address_id;
207 unsigned int client_id;
209 enum GNUNET_ATS_PreferenceKind kind;
213 struct GNUNET_TIME_Relative duration_period;
214 struct GNUNET_TIME_Relative frequency;
216 GNUNET_SCHEDULER_TaskIdentifier set_task;
217 struct GNUNET_TIME_Absolute next_ping_transmission;
218 struct GNUNET_TIME_Absolute time_start;
222 struct PropertyGenerator
224 struct PropertyGenerator *prev;
225 struct PropertyGenerator *next;
227 enum GeneratorType type;
230 unsigned int address_id;
232 struct TestPeer *test_peer;
233 struct TestAddress *test_address;
234 uint32_t ats_property;
238 struct GNUNET_TIME_Relative duration_period;
239 struct GNUNET_TIME_Relative frequency;
241 GNUNET_SCHEDULER_TaskIdentifier set_task;
242 struct GNUNET_TIME_Absolute next_ping_transmission;
243 struct GNUNET_TIME_Absolute time_start;
250 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
253 * Message type sent for traffic generation
255 #define TEST_MESSAGE_TYPE_PING 12345
258 * Message type sent as response during traffic generation
260 #define TEST_MESSAGE_TYPE_PONG 12346
263 * Size of test messages
265 #define TEST_MESSAGE_SIZE 100
267 struct BenchmarkPartner;
269 struct BenchmarkPeer;
271 struct GNUNET_ATS_TEST_Topology;
273 struct TrafficGenerator;
280 * Callback to call when topology setup is completed
282 * @param cls the closure
283 * @param masters array of master peers
284 * @param slaves array of master peers
286 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
287 struct BenchmarkPeer *masters,
288 struct BenchmarkPeer *slaves);
291 * Callback called when logging is required for the data contained
293 * @param cls the closure
294 * @param address an address
295 * @param address_active is address active
296 * @param bandwidth_out bandwidth outbound
297 * @param bandwidth_in bandwidth inbound
298 * @param ats ats information
299 * @param ats_count number of ats inforation
302 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
303 const struct GNUNET_HELLO_Address *address_id,
305 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
306 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
307 const struct GNUNET_ATS_Information *ats,
311 * Information we track for a peer in the testbed.
316 * Handle with testbed.
318 struct GNUNET_TESTBED_Peer *peer;
326 * Is this peer a measter: GNUNET_YES/GNUNET_NO
333 struct GNUNET_PeerIdentity id;
336 * Testbed operation to get peer information
338 struct GNUNET_TESTBED_Operation *peer_id_op;
341 * Testbed operation to connect to ATS performance service
343 struct GNUNET_TESTBED_Operation *ats_perf_op;
346 * Testbed operation to connect to core
348 struct GNUNET_TESTBED_Operation *comm_op;
351 * ATS performance handle
353 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
357 * Testbed connect operations to connect masters to slaves
359 struct TestbedConnectOperation *core_connect_ops;
364 struct GNUNET_CORE_Handle *ch;
369 struct GNUNET_TRANSPORT_Handle *th;
373 * Peer to set ATS preferences for
375 struct BenchmarkPeer *pref_partner;
381 GNUNET_SCHEDULER_TaskIdentifier ats_task;
390 * Array of partners with num_slaves entries (if master) or
391 * num_master entries (if slave)
393 struct BenchmarkPartner *partners;
401 * Number of core connections
403 int core_connections;
407 * Number of connections to slave peers
409 int core_slave_connections;
412 * Total number of messages this peer has sent
414 unsigned int total_messages_sent;
417 * Total number of bytes this peer has sent
419 unsigned int total_bytes_sent;
422 * Total number of messages this peer has received
424 unsigned int total_messages_received;
427 * Total number of bytes this peer has received
429 unsigned int total_bytes_received;
432 struct TrafficGenerator
434 struct TrafficGenerator *prev;
435 struct TrafficGenerator *next;
437 enum GeneratorType type;
439 struct BenchmarkPeer *src;
440 struct BenchmarkPartner *dest;
444 struct GNUNET_TIME_Relative duration_period;
446 GNUNET_SCHEDULER_TaskIdentifier send_task;
447 struct GNUNET_TIME_Absolute next_ping_transmission;
448 struct GNUNET_TIME_Absolute time_start;
452 struct PreferenceGenerator
454 struct PreferenceGenerator *prev;
455 struct PreferenceGenerator *next;
457 enum GeneratorType type;
459 struct BenchmarkPeer *src;
460 struct BenchmarkPartner *dest;
462 enum GNUNET_ATS_PreferenceKind kind;
466 struct GNUNET_TIME_Relative duration_period;
467 struct GNUNET_TIME_Relative frequency;
469 GNUNET_SCHEDULER_TaskIdentifier set_task;
470 struct GNUNET_TIME_Absolute next_ping_transmission;
471 struct GNUNET_TIME_Absolute time_start;
475 * Information about a benchmarking partner
477 struct BenchmarkPartner
480 * The peer itself this partner belongs to
482 struct BenchmarkPeer *me;
487 struct BenchmarkPeer *dest;
490 * Core transmit handles
492 struct GNUNET_CORE_TransmitHandle *cth;
495 * Transport transmit handles
497 struct GNUNET_TRANSPORT_TransmitHandle *tth;
499 struct TrafficGenerator *tg;
500 struct PreferenceGenerator *pg;
503 * Timestamp to calculate communication layer delay
505 struct GNUNET_TIME_Absolute last_message_sent;
508 * Accumulated RTT for all messages
510 unsigned int total_app_rtt;
513 * Number of messages sent to this partner
515 unsigned int messages_sent;
518 * Number of bytes sent to this partner
520 unsigned int bytes_sent;
523 * Number of messages received from this partner
525 unsigned int messages_received;
528 * Number of bytes received from this partner
530 unsigned int bytes_received;
532 /* Current ATS properties */
534 uint32_t ats_distance;
538 uint32_t bandwidth_in;
540 uint32_t bandwidth_out;
542 uint32_t ats_utilization_up;
544 uint32_t ats_utilization_down;
546 uint32_t ats_network_type;
548 uint32_t ats_cost_wan;
550 uint32_t ats_cost_lan;
552 uint32_t ats_cost_wlan;
554 double pref_bandwidth;
559 * Overall state of the performance benchmark
561 struct BenchmarkState
564 * Are we connected to ATS service of all peers: GNUNET_YES/NO
566 int connected_ATS_service;
569 * Are we connected to CORE service of all peers: GNUNET_YES/NO
571 int connected_COMM_service;
574 * Are we connected to all peers: GNUNET_YES/NO
579 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
584 * Are we connected to CORE service of all peers: GNUNET_YES/NO
590 struct GNUNET_ATS_TEST_Topology
595 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
600 GNUNET_SCHEDULER_TaskIdentifier progress_task;
607 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
627 * ATS preference value
632 * Number master peers
634 unsigned int num_masters;
637 * Array of master peers
639 struct BenchmarkPeer *mps;
644 unsigned int num_slaves;
647 * Array of slave peers
649 struct BenchmarkPeer *sps;
654 struct GNUNET_TIME_Relative perf_duration;
659 struct GNUNET_TIME_Relative log_frequency;
664 struct BenchmarkState state;
666 struct GNUNET_CORE_MessageHandler *handlers;
668 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
670 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
671 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
678 * Experiment related functions
683 * Execute the specified experiment
685 * @param e the Experiment
686 * @param ep_done_cb a episode is completed
687 * @param e_done_cb the experiment is completed
690 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
691 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
692 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
695 * Load an experiment from a file
697 * @param filename the file
698 * @return the Experiment or NULL on failure
701 GNUNET_ATS_TEST_experimentation_load (char *filename);
707 * @param e the experiment
710 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
713 * Traffic related functions
717 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
720 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
724 * Generate between the source master and the partner and send traffic with a
727 * @param src traffic source
728 * @param dest traffic partner
729 * @param type type of traffic to generate
730 * @param base_rate traffic base rate to send data with
731 * @param max_rate traffic maximum rate to send data with
732 * @param period duration of a period of traffic generation (~ 1/frequency)
733 * @param duration how long to generate traffic
734 * @return the traffic generator
736 struct TrafficGenerator *
737 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
738 struct BenchmarkPartner *dest,
739 enum GeneratorType type,
742 struct GNUNET_TIME_Relative period,
743 struct GNUNET_TIME_Relative duration);
746 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
749 * Stop all traffic generators
752 GNUNET_ATS_TEST_generate_traffic_stop_all ();
754 struct PreferenceGenerator *
755 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
756 struct BenchmarkPartner *dest,
757 enum GeneratorType type,
760 struct GNUNET_TIME_Relative period,
761 struct GNUNET_TIME_Relative frequency,
762 enum GNUNET_ATS_PreferenceKind kind);
765 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
768 GNUNET_ATS_TEST_generate_preferences_stop_all ();
771 * Logging related functions
777 * Topology related functions
780 struct BenchmarkPeer *
781 GNUNET_ATS_TEST_get_peer (int src);
783 struct BenchmarkPartner *
784 GNUNET_ATS_TEST_get_partner (int src, int dest);
787 * Create a topology for ats testing
789 * @param name test name
790 * @param cfg_file configuration file to use for the peers
791 * @param num_slaves number of slaves
792 * @param num_masters number of masters
793 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
794 * @param done_cb function to call when topology is setup
795 * @param done_cb_cls cls for callback
796 * @param recv_cb callback to call when data are received
797 * @param perf_cb callback to call when performance info are received
800 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
801 unsigned int num_slaves,
802 unsigned int num_masters,
804 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
806 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
807 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
813 GNUNET_ATS_TEST_shutdown_topology (void);
815 #endif /* #ifndef GNUNET_ATS_SOLVER_EVAL_H */
816 /* end of file ats-testing.h */