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.h
22 * @brief ats testing library: setup topology and provide logging to test ats
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testbed_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet_core_service.h"
32 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
35 * Message type sent for traffic generation
37 #define TEST_MESSAGE_TYPE_PING 12345
40 * Message type sent as response during traffic generation
42 #define TEST_MESSAGE_TYPE_PONG 12346
45 * Size of test messages
47 #define TEST_MESSAGE_SIZE 100
49 struct BenchmarkPartner;
53 struct GNUNET_ATS_TEST_Topology;
55 struct TrafficGenerator;
61 GNUNET_ATS_TEST_TG_LINEAR,
62 GNUNET_ATS_TEST_TG_CONSTANT,
63 GNUNET_ATS_TEST_TG_RANDOM,
64 GNUNET_ATS_TEST_TG_SINUS
69 * Callback to call when topology setup is completed
71 * @param cls the closure
72 * @param masters array of master peers
73 * @param slaves array of master peers
75 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
76 struct BenchmarkPeer *masters,
77 struct BenchmarkPeer *slaves);
80 * Callback called when logging is required for the data contained
82 * @param cls the closure
83 * @param address an address
84 * @param address_active is address active
85 * @param bandwidth_out bandwidth outbound
86 * @param bandwidth_in bandwidth inbound
87 * @param ats ats information
88 * @param ats_count number of ats inforation
91 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
92 const struct GNUNET_HELLO_Address *address,
94 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
95 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
96 const struct GNUNET_ATS_Information *ats,
100 * Information we track for a peer in the testbed.
105 * Handle with testbed.
107 struct GNUNET_TESTBED_Peer *peer;
115 * Is this peer a measter: GNUNET_YES/GNUNET_NO
122 struct GNUNET_PeerIdentity id;
125 * Testbed operation to get peer information
127 struct GNUNET_TESTBED_Operation *peer_id_op;
130 * Testbed operation to connect to ATS performance service
132 struct GNUNET_TESTBED_Operation *ats_perf_op;
135 * Testbed operation to connect to core
137 struct GNUNET_TESTBED_Operation *comm_op;
140 * ATS performance handle
142 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
146 * Testbed connect operations to connect masters to slaves
148 struct TestbedConnectOperation *core_connect_ops;
153 struct GNUNET_CORE_Handle *ch;
158 struct GNUNET_TRANSPORT_Handle *th;
162 * Peer to set ATS preferences for
164 struct BenchmarkPeer *pref_partner;
170 struct GNUNET_SCHEDULER_Task * ats_task;
179 * Array of partners with num_slaves entries (if master) or
180 * num_master entries (if slave)
182 struct BenchmarkPartner *partners;
190 * Number of core connections
192 int core_connections;
196 * Number of connections to slave peers
198 int core_slave_connections;
201 * Total number of messages this peer has sent
203 unsigned int total_messages_sent;
206 * Total number of bytes this peer has sent
208 unsigned int total_bytes_sent;
211 * Total number of messages this peer has received
213 unsigned int total_messages_received;
216 * Total number of bytes this peer has received
218 unsigned int total_bytes_received;
221 struct TrafficGenerator
223 struct TrafficGenerator *prev;
224 struct TrafficGenerator *next;
226 enum GeneratorType type;
228 struct BenchmarkPeer *src;
229 struct BenchmarkPartner *dest;
233 struct GNUNET_TIME_Relative duration_period;
235 struct GNUNET_SCHEDULER_Task * send_task;
236 struct GNUNET_TIME_Absolute next_ping_transmission;
237 struct GNUNET_TIME_Absolute time_start;
241 struct PreferenceGenerator
243 struct PreferenceGenerator *prev;
244 struct PreferenceGenerator *next;
246 enum GeneratorType type;
248 struct BenchmarkPeer *src;
249 struct BenchmarkPartner *dest;
251 enum GNUNET_ATS_PreferenceKind kind;
255 struct GNUNET_TIME_Relative duration_period;
256 struct GNUNET_TIME_Relative frequency;
258 struct GNUNET_SCHEDULER_Task * set_task;
259 struct GNUNET_TIME_Absolute next_ping_transmission;
260 struct GNUNET_TIME_Absolute time_start;
264 * Information about a benchmarking partner
266 struct BenchmarkPartner
269 * The peer itself this partner belongs to
271 struct BenchmarkPeer *me;
276 struct BenchmarkPeer *dest;
279 * Core transmit handles
281 struct GNUNET_CORE_TransmitHandle *cth;
284 * Transport transmit handles
286 struct GNUNET_TRANSPORT_TransmitHandle *tth;
288 struct TrafficGenerator *tg;
289 struct PreferenceGenerator *pg;
292 * Timestamp to calculate communication layer delay
294 struct GNUNET_TIME_Absolute last_message_sent;
297 * Accumulated RTT for all messages
299 unsigned int total_app_rtt;
302 * Number of messages sent to this partner
304 unsigned int messages_sent;
307 * Number of bytes sent to this partner
309 unsigned int bytes_sent;
312 * Number of messages received from this partner
314 unsigned int messages_received;
317 * Number of bytes received from this partner
319 unsigned int bytes_received;
321 /* Current ATS properties */
323 uint32_t ats_distance;
327 uint32_t bandwidth_in;
329 uint32_t bandwidth_out;
331 uint32_t ats_utilization_up;
333 uint32_t ats_utilization_down;
335 uint32_t ats_network_type;
337 uint32_t ats_cost_wan;
339 uint32_t ats_cost_lan;
341 uint32_t ats_cost_wlan;
343 double pref_bandwidth;
348 * Overall state of the performance benchmark
350 struct BenchmarkState
353 * Are we connected to ATS service of all peers: GNUNET_YES/NO
355 int connected_ATS_service;
358 * Are we connected to CORE service of all peers: GNUNET_YES/NO
360 int connected_COMM_service;
363 * Are we connected to all peers: GNUNET_YES/NO
368 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
373 * Are we connected to CORE service of all peers: GNUNET_YES/NO
379 struct GNUNET_ATS_TEST_Topology
384 struct GNUNET_SCHEDULER_Task * shutdown_task;
389 struct GNUNET_SCHEDULER_Task * progress_task;
396 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
416 * ATS preference value
421 * Number master peers
423 unsigned int num_masters;
426 * Array of master peers
428 struct BenchmarkPeer *mps;
433 unsigned int num_slaves;
436 * Array of slave peers
438 struct BenchmarkPeer *sps;
443 struct GNUNET_TIME_Relative perf_duration;
448 struct GNUNET_TIME_Relative log_frequency;
453 struct BenchmarkState state;
455 struct GNUNET_CORE_MessageHandler *handlers;
457 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
459 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
460 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
476 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
479 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
480 struct GNUNET_TIME_Relative duration,int success);
483 * An operation in an experiment
485 struct GNUNET_ATS_TEST_Operation
487 struct GNUNET_ATS_TEST_Operation *next;
488 struct GNUNET_ATS_TEST_Operation *prev;
490 long long unsigned int src_id;
491 long long unsigned int dest_id;
493 long long unsigned int base_rate;
494 long long unsigned int max_rate;
495 struct GNUNET_TIME_Relative period;
496 struct GNUNET_TIME_Relative frequency;
498 enum OperationType type;
499 enum GeneratorType gen_type;
500 enum GNUNET_ATS_PreferenceKind pref_type;
506 struct Episode *next;
507 struct GNUNET_TIME_Relative duration;
509 struct GNUNET_ATS_TEST_Operation *head;
510 struct GNUNET_ATS_TEST_Operation *tail;
518 unsigned long long int num_masters;
519 unsigned long long int num_slaves;
520 struct GNUNET_TIME_Relative log_freq;
521 struct GNUNET_TIME_Relative max_duration;
522 struct GNUNET_TIME_Relative total_duration;
523 struct GNUNET_TIME_Absolute start_time;
524 unsigned int num_episodes;
525 struct Episode *start;
527 struct GNUNET_SCHEDULER_Task * experiment_timeout_task;
528 struct GNUNET_SCHEDULER_Task * episode_timeout_task;
531 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
532 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
536 * Experiment related functions
538 extern struct GNUNET_CONFIGURATION_Handle *cfg;
541 * Execute the specified experiment
543 * @param e the Experiment
544 * @param ep_done_cb a episode is completed
545 * @param e_done_cb the experiment is completed
548 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
549 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
550 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
553 * Load an experiment from a file
555 * @param filename the file
556 * @return the Experiment or NULL on failure
559 GNUNET_ATS_TEST_experimentation_load (char *filename);
565 * @param e the experiment
568 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
571 * Traffic related functions
575 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
578 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
582 * Generate between the source master and the partner and send traffic with a
585 * @param src traffic source
586 * @param dest traffic partner
587 * @param type type of traffic to generate
588 * @param base_rate traffic base rate to send data with
589 * @param max_rate traffic maximum rate to send data with
590 * @param period duration of a period of traffic generation (~ 1/frequency)
591 * @param duration how long to generate traffic
592 * @return the traffic generator
594 struct TrafficGenerator *
595 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
596 struct BenchmarkPartner *dest,
597 enum GeneratorType type,
600 struct GNUNET_TIME_Relative period,
601 struct GNUNET_TIME_Relative duration);
604 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
607 * Stop all traffic generators
610 GNUNET_ATS_TEST_generate_traffic_stop_all ();
613 * Generate between the source master and the partner and set preferences with a
614 * value depending on the generator.
617 * @param dest partner
618 * @param type type of preferences to generate
619 * @param base_value traffic base rate to send data with
620 * @param value_rate traffic maximum rate to send data with
621 * @param period duration of a period of preferences generation (~ 1/frequency)
622 * @param frequency how long to generate preferences
623 * @param kind ATS preference to generate
624 * @return the traffic generator
626 struct PreferenceGenerator *
627 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
628 struct BenchmarkPartner *dest,
629 enum GeneratorType type,
632 struct GNUNET_TIME_Relative period,
633 struct GNUNET_TIME_Relative frequency,
634 enum GNUNET_ATS_PreferenceKind kind);
637 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
640 GNUNET_ATS_TEST_generate_preferences_stop_all ();
643 * Logging related functions
649 * @param log_frequency the logging frequency
650 * @param testname the testname
651 * @param masters the master peers used for benchmarking
652 * @param num_masters the number of master peers
653 * @param num_slaves the number of slave peers
654 * @param verbose verbose logging
655 * @return the logging handle or NULL on error
657 struct LoggingHandle *
658 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
659 char *testname, struct BenchmarkPeer *masters, int num_masters, int num_slaves,
665 * @param l the logging handle
668 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
673 * @param l the logging handle
676 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
681 * @param l logging handle to use
684 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
688 * Write logging data to file
690 * @param l logging handle to use
691 * @param test_name name of the current test
692 * @param plots create gnuplots: GNUNET_YES or GNUNET_NO
695 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
696 char *test_name, int plots);
699 * Topology related functions
702 struct BenchmarkPeer *
703 GNUNET_ATS_TEST_get_peer (int src);
705 struct BenchmarkPartner *
706 GNUNET_ATS_TEST_get_partner (int src, int dest);
709 * Create a topology for ats testing
711 * @param name test name
712 * @param cfg_file configuration file to use for the peers
713 * @param num_slaves number of slaves
714 * @param num_masters number of masters
715 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
716 * @param done_cb function to call when topology is setup
717 * @param done_cb_cls cls for callback
718 * @param transport_recv_cb callback to call when data are received
719 * @param log_request_cb callback to call when logging is required
722 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
723 unsigned int num_slaves,
724 unsigned int num_masters,
726 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
728 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
729 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
735 GNUNET_ATS_TEST_shutdown_topology (void);
737 /* end of file ats-testing.h */