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;
151 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
154 * Message type sent for traffic generation
156 #define TEST_MESSAGE_TYPE_PING 12345
159 * Message type sent as response during traffic generation
161 #define TEST_MESSAGE_TYPE_PONG 12346
164 * Size of test messages
166 #define TEST_MESSAGE_SIZE 100
168 struct BenchmarkPartner;
170 struct BenchmarkPeer;
172 struct GNUNET_ATS_TEST_Topology;
174 struct TrafficGenerator;
181 * Callback to call when topology setup is completed
183 * @param cls the closure
184 * @param masters array of master peers
185 * @param slaves array of master peers
187 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
188 struct BenchmarkPeer *masters,
189 struct BenchmarkPeer *slaves);
192 * Callback called when logging is required for the data contained
194 * @param cls the closure
195 * @param address an address
196 * @param address_active is address active
197 * @param bandwidth_out bandwidth outbound
198 * @param bandwidth_in bandwidth inbound
199 * @param ats ats information
200 * @param ats_count number of ats inforation
203 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
204 const struct GNUNET_HELLO_Address *address_id,
206 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
207 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
208 const struct GNUNET_ATS_Information *ats,
212 * Information we track for a peer in the testbed.
217 * Handle with testbed.
219 struct GNUNET_TESTBED_Peer *peer;
227 * Is this peer a measter: GNUNET_YES/GNUNET_NO
234 struct GNUNET_PeerIdentity id;
237 * Testbed operation to get peer information
239 struct GNUNET_TESTBED_Operation *peer_id_op;
242 * Testbed operation to connect to ATS performance service
244 struct GNUNET_TESTBED_Operation *ats_perf_op;
247 * Testbed operation to connect to core
249 struct GNUNET_TESTBED_Operation *comm_op;
252 * ATS performance handle
254 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
258 * Testbed connect operations to connect masters to slaves
260 struct TestbedConnectOperation *core_connect_ops;
265 struct GNUNET_CORE_Handle *ch;
270 struct GNUNET_TRANSPORT_Handle *th;
274 * Peer to set ATS preferences for
276 struct BenchmarkPeer *pref_partner;
282 GNUNET_SCHEDULER_TaskIdentifier ats_task;
291 * Array of partners with num_slaves entries (if master) or
292 * num_master entries (if slave)
294 struct BenchmarkPartner *partners;
302 * Number of core connections
304 int core_connections;
308 * Number of connections to slave peers
310 int core_slave_connections;
313 * Total number of messages this peer has sent
315 unsigned int total_messages_sent;
318 * Total number of bytes this peer has sent
320 unsigned int total_bytes_sent;
323 * Total number of messages this peer has received
325 unsigned int total_messages_received;
328 * Total number of bytes this peer has received
330 unsigned int total_bytes_received;
333 struct TrafficGenerator
335 struct TrafficGenerator *prev;
336 struct TrafficGenerator *next;
338 enum GeneratorType type;
340 struct BenchmarkPeer *src;
341 struct BenchmarkPartner *dest;
345 struct GNUNET_TIME_Relative duration_period;
347 GNUNET_SCHEDULER_TaskIdentifier send_task;
348 struct GNUNET_TIME_Absolute next_ping_transmission;
349 struct GNUNET_TIME_Absolute time_start;
353 struct PreferenceGenerator
355 struct PreferenceGenerator *prev;
356 struct PreferenceGenerator *next;
358 enum GeneratorType type;
360 struct BenchmarkPeer *src;
361 struct BenchmarkPartner *dest;
363 enum GNUNET_ATS_PreferenceKind kind;
367 struct GNUNET_TIME_Relative duration_period;
368 struct GNUNET_TIME_Relative frequency;
370 GNUNET_SCHEDULER_TaskIdentifier set_task;
371 struct GNUNET_TIME_Absolute next_ping_transmission;
372 struct GNUNET_TIME_Absolute time_start;
376 * Information about a benchmarking partner
378 struct BenchmarkPartner
381 * The peer itself this partner belongs to
383 struct BenchmarkPeer *me;
388 struct BenchmarkPeer *dest;
391 * Core transmit handles
393 struct GNUNET_CORE_TransmitHandle *cth;
396 * Transport transmit handles
398 struct GNUNET_TRANSPORT_TransmitHandle *tth;
400 struct TrafficGenerator *tg;
401 struct PreferenceGenerator *pg;
404 * Timestamp to calculate communication layer delay
406 struct GNUNET_TIME_Absolute last_message_sent;
409 * Accumulated RTT for all messages
411 unsigned int total_app_rtt;
414 * Number of messages sent to this partner
416 unsigned int messages_sent;
419 * Number of bytes sent to this partner
421 unsigned int bytes_sent;
424 * Number of messages received from this partner
426 unsigned int messages_received;
429 * Number of bytes received from this partner
431 unsigned int bytes_received;
433 /* Current ATS properties */
435 uint32_t ats_distance;
439 uint32_t bandwidth_in;
441 uint32_t bandwidth_out;
443 uint32_t ats_utilization_up;
445 uint32_t ats_utilization_down;
447 uint32_t ats_network_type;
449 uint32_t ats_cost_wan;
451 uint32_t ats_cost_lan;
453 uint32_t ats_cost_wlan;
455 double pref_bandwidth;
460 * Overall state of the performance benchmark
462 struct BenchmarkState
465 * Are we connected to ATS service of all peers: GNUNET_YES/NO
467 int connected_ATS_service;
470 * Are we connected to CORE service of all peers: GNUNET_YES/NO
472 int connected_COMM_service;
475 * Are we connected to all peers: GNUNET_YES/NO
480 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
485 * Are we connected to CORE service of all peers: GNUNET_YES/NO
491 struct GNUNET_ATS_TEST_Topology
496 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
501 GNUNET_SCHEDULER_TaskIdentifier progress_task;
508 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
528 * ATS preference value
533 * Number master peers
535 unsigned int num_masters;
538 * Array of master peers
540 struct BenchmarkPeer *mps;
545 unsigned int num_slaves;
548 * Array of slave peers
550 struct BenchmarkPeer *sps;
555 struct GNUNET_TIME_Relative perf_duration;
560 struct GNUNET_TIME_Relative log_frequency;
565 struct BenchmarkState state;
567 struct GNUNET_CORE_MessageHandler *handlers;
569 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
571 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
572 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
579 * Experiment related functions
584 * Execute the specified experiment
586 * @param e the Experiment
587 * @param ep_done_cb a episode is completed
588 * @param e_done_cb the experiment is completed
591 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
592 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
593 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
596 * Load an experiment from a file
598 * @param filename the file
599 * @return the Experiment or NULL on failure
602 GNUNET_ATS_TEST_experimentation_load (char *filename);
608 * @param e the experiment
611 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
614 * Traffic related functions
618 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
621 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
625 * Generate between the source master and the partner and send traffic with a
628 * @param src traffic source
629 * @param dest traffic partner
630 * @param type type of traffic to generate
631 * @param base_rate traffic base rate to send data with
632 * @param max_rate traffic maximum rate to send data with
633 * @param period duration of a period of traffic generation (~ 1/frequency)
634 * @param duration how long to generate traffic
635 * @return the traffic generator
637 struct TrafficGenerator *
638 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
639 struct BenchmarkPartner *dest,
640 enum GeneratorType type,
643 struct GNUNET_TIME_Relative period,
644 struct GNUNET_TIME_Relative duration);
647 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
650 * Stop all traffic generators
653 GNUNET_ATS_TEST_generate_traffic_stop_all ();
655 struct PreferenceGenerator *
656 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
657 struct BenchmarkPartner *dest,
658 enum GeneratorType type,
661 struct GNUNET_TIME_Relative period,
662 struct GNUNET_TIME_Relative frequency,
663 enum GNUNET_ATS_PreferenceKind kind);
666 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
669 GNUNET_ATS_TEST_generate_preferences_stop_all ();
672 * Logging related functions
678 * Topology related functions
681 struct BenchmarkPeer *
682 GNUNET_ATS_TEST_get_peer (int src);
684 struct BenchmarkPartner *
685 GNUNET_ATS_TEST_get_partner (int src, int dest);
688 * Create a topology for ats testing
690 * @param name test name
691 * @param cfg_file configuration file to use for the peers
692 * @param num_slaves number of slaves
693 * @param num_masters number of masters
694 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
695 * @param done_cb function to call when topology is setup
696 * @param done_cb_cls cls for callback
697 * @param recv_cb callback to call when data are received
698 * @param perf_cb callback to call when performance info are received
701 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
702 unsigned int num_slaves,
703 unsigned int num_masters,
705 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
707 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
708 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
714 GNUNET_ATS_TEST_shutdown_topology (void);
716 /* end of file ats-testing.h */