2 This file is part of GNUnet.
3 Copyright (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 prop performance information
90 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
91 const struct GNUNET_HELLO_Address *address,
93 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
94 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
95 const struct GNUNET_ATS_Properties *prop);
98 * Information we track for a peer in the testbed.
103 * Handle with testbed.
105 struct GNUNET_TESTBED_Peer *peer;
113 * Is this peer a measter: GNUNET_YES/GNUNET_NO
120 struct GNUNET_PeerIdentity id;
123 * Testbed operation to get peer information
125 struct GNUNET_TESTBED_Operation *peer_id_op;
128 * Testbed operation to connect to ATS performance service
130 struct GNUNET_TESTBED_Operation *ats_perf_op;
133 * Testbed operation to connect to core
135 struct GNUNET_TESTBED_Operation *comm_op;
138 * ATS performance handle
140 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
144 * Testbed connect operations to connect masters to slaves
146 struct TestbedConnectOperation *core_connect_ops;
151 struct GNUNET_CORE_Handle *ch;
156 struct GNUNET_TRANSPORT_Handle *th;
160 * Peer to set ATS preferences for
162 struct BenchmarkPeer *pref_partner;
168 struct GNUNET_SCHEDULER_Task * ats_task;
177 * Array of partners with num_slaves entries (if master) or
178 * num_master entries (if slave)
180 struct BenchmarkPartner *partners;
188 * Number of core connections
190 int core_connections;
194 * Number of connections to slave peers
196 int core_slave_connections;
199 * Total number of messages this peer has sent
201 unsigned int total_messages_sent;
204 * Total number of bytes this peer has sent
206 unsigned int total_bytes_sent;
209 * Total number of messages this peer has received
211 unsigned int total_messages_received;
214 * Total number of bytes this peer has received
216 unsigned int total_bytes_received;
219 struct TrafficGenerator
221 struct TrafficGenerator *prev;
222 struct TrafficGenerator *next;
224 enum GeneratorType type;
226 struct BenchmarkPeer *src;
227 struct BenchmarkPartner *dest;
231 struct GNUNET_TIME_Relative duration_period;
233 struct GNUNET_SCHEDULER_Task * send_task;
234 struct GNUNET_TIME_Absolute next_ping_transmission;
235 struct GNUNET_TIME_Absolute time_start;
239 struct PreferenceGenerator
241 struct PreferenceGenerator *prev;
242 struct PreferenceGenerator *next;
244 enum GeneratorType type;
246 struct BenchmarkPeer *src;
247 struct BenchmarkPartner *dest;
249 enum GNUNET_ATS_PreferenceKind kind;
253 struct GNUNET_TIME_Relative duration_period;
254 struct GNUNET_TIME_Relative frequency;
256 struct GNUNET_SCHEDULER_Task * set_task;
257 struct GNUNET_TIME_Absolute next_ping_transmission;
258 struct GNUNET_TIME_Absolute time_start;
262 * Information about a benchmarking partner
264 struct BenchmarkPartner
267 * The peer itself this partner belongs to
269 struct BenchmarkPeer *me;
274 struct BenchmarkPeer *dest;
277 * Core transmit handles
279 struct GNUNET_CORE_TransmitHandle *cth;
282 * Transport transmit handles
284 struct GNUNET_TRANSPORT_TransmitHandle *tth;
286 struct TrafficGenerator *tg;
287 struct PreferenceGenerator *pg;
290 * Timestamp to calculate communication layer delay
292 struct GNUNET_TIME_Absolute last_message_sent;
295 * Accumulated RTT for all messages
297 unsigned int total_app_rtt;
300 * Number of messages sent to this partner
302 unsigned int messages_sent;
305 * Number of bytes sent to this partner
307 unsigned int bytes_sent;
310 * Number of messages received from this partner
312 unsigned int messages_received;
315 * Number of bytes received from this partner
317 unsigned int bytes_received;
319 /* Current ATS properties */
321 uint32_t ats_distance;
325 uint32_t bandwidth_in;
327 uint32_t bandwidth_out;
329 uint32_t ats_utilization_up;
331 uint32_t ats_utilization_down;
333 uint32_t ats_network_type;
335 uint32_t ats_cost_wan;
337 uint32_t ats_cost_lan;
339 uint32_t ats_cost_wlan;
341 double pref_bandwidth;
346 * Overall state of the performance benchmark
348 struct BenchmarkState
351 * Are we connected to ATS service of all peers: GNUNET_YES/NO
353 int connected_ATS_service;
356 * Are we connected to CORE service of all peers: GNUNET_YES/NO
358 int connected_COMM_service;
361 * Are we connected to all peers: GNUNET_YES/NO
366 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
371 * Are we connected to CORE service of all peers: GNUNET_YES/NO
377 struct GNUNET_ATS_TEST_Topology
382 struct GNUNET_SCHEDULER_Task * shutdown_task;
387 struct GNUNET_SCHEDULER_Task * progress_task;
394 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
414 * ATS preference value
419 * Number master peers
421 unsigned int num_masters;
424 * Array of master peers
426 struct BenchmarkPeer *mps;
431 unsigned int num_slaves;
434 * Array of slave peers
436 struct BenchmarkPeer *sps;
441 struct GNUNET_TIME_Relative perf_duration;
446 struct GNUNET_TIME_Relative log_frequency;
451 struct BenchmarkState state;
453 struct GNUNET_CORE_MessageHandler *handlers;
455 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
457 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
458 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
474 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
477 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
478 struct GNUNET_TIME_Relative duration,int success);
481 * An operation in an experiment
483 struct GNUNET_ATS_TEST_Operation
485 struct GNUNET_ATS_TEST_Operation *next;
486 struct GNUNET_ATS_TEST_Operation *prev;
488 long long unsigned int src_id;
489 long long unsigned int dest_id;
491 long long unsigned int base_rate;
492 long long unsigned int max_rate;
493 struct GNUNET_TIME_Relative period;
494 struct GNUNET_TIME_Relative frequency;
496 enum OperationType type;
497 enum GeneratorType gen_type;
498 enum GNUNET_ATS_PreferenceKind pref_type;
504 struct Episode *next;
505 struct GNUNET_TIME_Relative duration;
507 struct GNUNET_ATS_TEST_Operation *head;
508 struct GNUNET_ATS_TEST_Operation *tail;
516 unsigned long long int num_masters;
517 unsigned long long int num_slaves;
518 struct GNUNET_TIME_Relative log_freq;
519 struct GNUNET_TIME_Relative max_duration;
520 struct GNUNET_TIME_Relative total_duration;
521 struct GNUNET_TIME_Absolute start_time;
522 unsigned int num_episodes;
523 struct Episode *start;
525 struct GNUNET_SCHEDULER_Task * experiment_timeout_task;
526 struct GNUNET_SCHEDULER_Task * episode_timeout_task;
529 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
530 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
534 * Experiment related functions
536 extern struct GNUNET_CONFIGURATION_Handle *cfg;
539 * Execute the specified experiment
541 * @param e the Experiment
542 * @param ep_done_cb a episode is completed
543 * @param e_done_cb the experiment is completed
546 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
547 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
548 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
551 * Load an experiment from a file
553 * @param filename the file
554 * @return the Experiment or NULL on failure
557 GNUNET_ATS_TEST_experimentation_load (char *filename);
563 * @param e the experiment
566 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
569 * Traffic related functions
573 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
576 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
580 * Generate between the source master and the partner and send traffic with a
583 * @param src traffic source
584 * @param dest traffic partner
585 * @param type type of traffic to generate
586 * @param base_rate traffic base rate to send data with
587 * @param max_rate traffic maximum rate to send data with
588 * @param period duration of a period of traffic generation (~ 1/frequency)
589 * @param duration how long to generate traffic
590 * @return the traffic generator
592 struct TrafficGenerator *
593 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
594 struct BenchmarkPartner *dest,
595 enum GeneratorType type,
598 struct GNUNET_TIME_Relative period,
599 struct GNUNET_TIME_Relative duration);
602 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
605 * Stop all traffic generators
608 GNUNET_ATS_TEST_generate_traffic_stop_all ();
611 * Generate between the source master and the partner and set preferences with a
612 * value depending on the generator.
615 * @param dest partner
616 * @param type type of preferences to generate
617 * @param base_value traffic base rate to send data with
618 * @param value_rate traffic maximum rate to send data with
619 * @param period duration of a period of preferences generation (~ 1/frequency)
620 * @param frequency how long to generate preferences
621 * @param kind ATS preference to generate
622 * @return the traffic generator
624 struct PreferenceGenerator *
625 GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
626 struct BenchmarkPartner *dest,
627 enum GeneratorType type,
630 struct GNUNET_TIME_Relative period,
631 struct GNUNET_TIME_Relative frequency,
632 enum GNUNET_ATS_PreferenceKind kind);
635 GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
638 GNUNET_ATS_TEST_generate_preferences_stop_all ();
641 * Logging related functions
647 * @param log_frequency the logging frequency
648 * @param testname the testname
649 * @param masters the master peers used for benchmarking
650 * @param num_masters the number of master peers
651 * @param num_slaves the number of slave peers
652 * @param verbose verbose logging
653 * @return the logging handle or NULL on error
655 struct LoggingHandle *
656 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
657 char *testname, struct BenchmarkPeer *masters, int num_masters, int num_slaves,
663 * @param l the logging handle
666 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
671 * @param l the logging handle
674 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
679 * @param l logging handle to use
682 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
686 * Write logging data to file
688 * @param l logging handle to use
689 * @param test_name name of the current test
690 * @param plots create gnuplots: GNUNET_YES or GNUNET_NO
693 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
694 char *test_name, int plots);
697 * Topology related functions
700 struct BenchmarkPeer *
701 GNUNET_ATS_TEST_get_peer (int src);
703 struct BenchmarkPartner *
704 GNUNET_ATS_TEST_get_partner (int src, int dest);
707 * Create a topology for ats testing
709 * @param name test name
710 * @param cfg_file configuration file to use for the peers
711 * @param num_slaves number of slaves
712 * @param num_masters number of masters
713 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
714 * @param done_cb function to call when topology is setup
715 * @param done_cb_cls cls for callback
716 * @param transport_recv_cb callback to call when data are received
717 * @param log_request_cb callback to call when logging is required
720 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
721 unsigned int num_slaves,
722 unsigned int num_masters,
724 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
726 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
727 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
733 GNUNET_ATS_TEST_shutdown_topology (void);
735 /* end of file ats-testing.h */