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;
59 enum TrafficGeneratorType
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 GNUNET_SCHEDULER_TaskIdentifier 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 TrafficGeneratorType type;
228 struct BenchmarkPeer *src;
229 struct BenchmarkPartner *dest;
233 struct GNUNET_TIME_Relative duration_period;
235 GNUNET_SCHEDULER_TaskIdentifier send_task;
236 struct GNUNET_TIME_Absolute next_ping_transmission;
237 struct GNUNET_TIME_Absolute time_start;
242 * Information about a benchmarking partner
244 struct BenchmarkPartner
247 * The peer itself this partner belongs to
249 struct BenchmarkPeer *me;
254 struct BenchmarkPeer *dest;
257 * Core transmit handles
259 struct GNUNET_CORE_TransmitHandle *cth;
262 * Transport transmit handles
264 struct GNUNET_TRANSPORT_TransmitHandle *tth;
266 struct TrafficGenerator *tg;
269 * Timestamp to calculate communication layer delay
271 struct GNUNET_TIME_Absolute last_message_sent;
274 * Accumulated RTT for all messages
276 unsigned int total_app_rtt;
279 * Number of messages sent to this partner
281 unsigned int messages_sent;
284 * Number of bytes sent to this partner
286 unsigned int bytes_sent;
289 * Number of messages received from this partner
291 unsigned int messages_received;
294 * Number of bytes received from this partner
296 unsigned int bytes_received;
298 /* Current ATS properties */
300 uint32_t ats_distance;
304 uint32_t bandwidth_in;
306 uint32_t bandwidth_out;
308 uint32_t ats_utilization_up;
310 uint32_t ats_utilization_down;
312 uint32_t ats_network_type;
314 uint32_t ats_cost_wan;
316 uint32_t ats_cost_lan;
318 uint32_t ats_cost_wlan;
322 * Overall state of the performance benchmark
324 struct BenchmarkState
327 * Are we connected to ATS service of all peers: GNUNET_YES/NO
329 int connected_ATS_service;
332 * Are we connected to CORE service of all peers: GNUNET_YES/NO
334 int connected_COMM_service;
337 * Are we connected to all peers: GNUNET_YES/NO
342 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
347 * Are we connected to CORE service of all peers: GNUNET_YES/NO
353 struct GNUNET_ATS_TEST_Topology
358 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
363 GNUNET_SCHEDULER_TaskIdentifier progress_task;
370 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
390 * ATS preference value
395 * Number master peers
397 unsigned int num_masters;
400 * Array of master peers
402 struct BenchmarkPeer *mps;
407 unsigned int num_slaves;
410 * Array of slave peers
412 struct BenchmarkPeer *sps;
417 struct GNUNET_TIME_Relative perf_duration;
422 struct GNUNET_TIME_Relative log_frequency;
427 struct BenchmarkState state;
429 struct GNUNET_CORE_MessageHandler *handlers;
431 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
433 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
434 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
450 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
453 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
454 struct GNUNET_TIME_Relative duration,int success);
458 struct Operation *next;
459 struct Operation *prev;
460 long long unsigned int src_id;
461 long long unsigned int dest_id;
462 long long unsigned int value;
463 enum OperationType type;
469 struct Episode *next;
470 struct GNUNET_TIME_Relative duration;
472 struct Operation *head;
473 struct Operation *tail;
481 unsigned long long int num_masters;
482 unsigned long long int num_slaves;
483 struct GNUNET_TIME_Relative max_duration;
484 struct GNUNET_TIME_Relative total_duration;
485 struct GNUNET_TIME_Absolute start_time;
486 unsigned int num_episodes;
487 struct Episode *start;
489 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
490 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
493 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
494 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
498 * Experiment related functions
503 * Execute the specified experiment
505 * @param e the Experiment
506 * @param ep_done_cb a episode is completed
507 * @param e_done_cb the experiment is completed
510 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
511 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
512 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
515 * Load an experiment from a file
517 * @param filename the file
518 * @return the Experiment or NULL on failure
521 GNUNET_ATS_TEST_experimentation_load (char *filename);
527 * @param e the experiment
530 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
533 * Traffic related functions
537 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
540 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
544 * Generate between the source master and the partner and send traffic with a
547 * @param src traffic source
548 * @param dest traffic partner
549 * @param type type of traffic to generate
550 * @param base_rate traffic base rate to send data with
551 * @param max_rate traffic maximum rate to send data with
552 * @param period duration of a period of traffic generation (~ 1/frequency)
553 * @param duration how long to generate traffic
554 * @return the traffic generator
556 struct TrafficGenerator *
557 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
558 struct BenchmarkPartner *dest,
559 enum TrafficGeneratorType type,
562 struct GNUNET_TIME_Relative period,
563 struct GNUNET_TIME_Relative duration);
566 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
569 * Stop all traffic generators
572 GNUNET_ATS_TEST_generate_traffic_stop_all ();
576 * Logging related functions
582 * @param log_frequency the logging frequency
583 * @param testname the testname
584 * @param masters the master peers used for benchmarking
585 * @param num_master the number of master peers
586 * @return the logging handle or NULL on error
588 struct LoggingHandle *
589 GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
591 struct BenchmarkPeer *masters,
597 * @param l the logging handle
600 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
605 * @param l the logging handle
608 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
613 * @param l logging handle to use
616 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
620 * Write logging data to file
622 * @param l logging handle to use
623 * @param test_name name of the current test
624 * @param plots create gnuplots: GNUNET_YES or GNUNET_NO
627 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
628 char *test_name, int plots);
631 * Topology related functions
635 * Create a topology for ats testing
637 * @param name test name
638 * @param cfg_file configuration file to use for the peers
639 * @param num_slaves number of slaves
640 * @param num_masters number of masters
641 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
642 * @param done_cb function to call when topology is setup
643 * @param done_cb_cls cls for callback
644 * @param recv_cb callback to call when data are received
645 * @param perf_cb callback to call when performance info are received
648 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
649 unsigned int num_slaves,
650 unsigned int num_masters,
652 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
654 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
655 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
661 GNUNET_ATS_TEST_shutdown_topology (void);
663 /* end of file ats-testing.h */