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 * Callback to call when topology setup is completed
63 * @param cls the closure
64 * @param masters array of master peers
65 * @param slaves array of master peers
67 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
68 struct BenchmarkPeer *masters,
69 struct BenchmarkPeer *slaves);
72 * Callback called when logging is required for the data contained
74 * @param cls the closure
75 * @param address an address
76 * @param address_active is address active
77 * @param bandwidth_out bandwidth outbound
78 * @param bandwidth_in bandwidth inbound
79 * @param ats ats information
80 * @param ats_count number of ats inforation
83 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
84 const struct GNUNET_HELLO_Address *address,
86 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
87 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
88 const struct GNUNET_ATS_Information *ats,
92 * Information we track for a peer in the testbed.
97 * Handle with testbed.
99 struct GNUNET_TESTBED_Peer *peer;
107 * Is this peer a measter: GNUNET_YES/GNUNET_NO
114 struct GNUNET_PeerIdentity id;
117 * Testbed operation to get peer information
119 struct GNUNET_TESTBED_Operation *peer_id_op;
122 * Testbed operation to connect to ATS performance service
124 struct GNUNET_TESTBED_Operation *ats_perf_op;
127 * Testbed operation to connect to core
129 struct GNUNET_TESTBED_Operation *comm_op;
132 * ATS performance handle
134 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
138 * Testbed connect operations to connect masters to slaves
140 struct TestbedConnectOperation *core_connect_ops;
145 struct GNUNET_CORE_Handle *ch;
150 struct GNUNET_TRANSPORT_Handle *th;
154 * Peer to set ATS preferences for
156 struct BenchmarkPeer *pref_partner;
162 GNUNET_SCHEDULER_TaskIdentifier ats_task;
171 * Array of partners with num_slaves entries (if master) or
172 * num_master entries (if slave)
174 struct BenchmarkPartner *partners;
182 * Number of core connections
184 int core_connections;
188 * Number of connections to slave peers
190 int core_slave_connections;
193 * Total number of messages this peer has sent
195 unsigned int total_messages_sent;
198 * Total number of bytes this peer has sent
200 unsigned int total_bytes_sent;
203 * Total number of messages this peer has received
205 unsigned int total_messages_received;
208 * Total number of bytes this peer has received
210 unsigned int total_bytes_received;
213 struct TrafficGenerator
215 struct TrafficGenerator *prev;
216 struct TrafficGenerator *next;
218 struct BenchmarkPeer *src;
219 struct BenchmarkPartner *dest;
221 GNUNET_SCHEDULER_TaskIdentifier send_task;
222 struct GNUNET_TIME_Absolute next_ping_transmission;
223 struct GNUNET_TIME_Relative delta;
228 * Information about a benchmarking partner
230 struct BenchmarkPartner
233 * The peer itself this partner belongs to
235 struct BenchmarkPeer *me;
240 struct BenchmarkPeer *dest;
243 * Core transmit handles
245 struct GNUNET_CORE_TransmitHandle *cth;
248 * Transport transmit handles
250 struct GNUNET_TRANSPORT_TransmitHandle *tth;
252 struct TrafficGenerator *tg;
255 * Timestamp to calculate communication layer delay
257 struct GNUNET_TIME_Absolute last_message_sent;
260 * Accumulated RTT for all messages
262 unsigned int total_app_rtt;
265 * Number of messages sent to this partner
267 unsigned int messages_sent;
270 * Number of bytes sent to this partner
272 unsigned int bytes_sent;
275 * Number of messages received from this partner
277 unsigned int messages_received;
280 * Number of bytes received from this partner
282 unsigned int bytes_received;
284 /* Current ATS properties */
286 uint32_t ats_distance;
290 uint32_t bandwidth_in;
292 uint32_t bandwidth_out;
294 uint32_t ats_utilization_up;
296 uint32_t ats_utilization_down;
298 uint32_t ats_network_type;
300 uint32_t ats_cost_wan;
302 uint32_t ats_cost_lan;
304 uint32_t ats_cost_wlan;
308 * Overall state of the performance benchmark
310 struct BenchmarkState
313 * Are we connected to ATS service of all peers: GNUNET_YES/NO
315 int connected_ATS_service;
318 * Are we connected to CORE service of all peers: GNUNET_YES/NO
320 int connected_COMM_service;
323 * Are we connected to all peers: GNUNET_YES/NO
328 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
333 * Are we connected to CORE service of all peers: GNUNET_YES/NO
339 struct GNUNET_ATS_TEST_Topology
344 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
349 GNUNET_SCHEDULER_TaskIdentifier progress_task;
356 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
376 * ATS preference value
381 * Number master peers
383 unsigned int num_masters;
386 * Array of master peers
388 struct BenchmarkPeer *mps;
393 unsigned int num_slaves;
396 * Array of slave peers
398 struct BenchmarkPeer *sps;
403 struct GNUNET_TIME_Relative perf_duration;
408 struct GNUNET_TIME_Relative log_frequency;
413 struct BenchmarkState state;
415 struct GNUNET_CORE_MessageHandler *handlers;
417 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
419 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
420 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
436 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
439 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
440 struct GNUNET_TIME_Relative duration,int success);
444 struct Operation *next;
445 struct Operation *prev;
446 long long unsigned int src_id;
447 long long unsigned int dest_id;
448 long long unsigned int value;
449 enum OperationType type;
455 struct Episode *next;
456 struct GNUNET_TIME_Relative duration;
458 struct Operation *head;
459 struct Operation *tail;
467 unsigned long long int num_masters;
468 unsigned long long int num_slaves;
469 struct GNUNET_TIME_Relative max_duration;
470 struct GNUNET_TIME_Relative total_duration;
471 struct GNUNET_TIME_Absolute start_time;
472 unsigned int num_episodes;
473 struct Episode *start;
475 GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
476 GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
479 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
480 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
484 * Experiment related functions
489 * Execute the specified experiment
491 * @param e the Experiment
492 * @param ep_done_cb a episode is completed
493 * @param e_done_cb the experiment is completed
496 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
497 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
498 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
501 * Load an experiment from a file
503 * @param filename the file
504 * @return the Experiment or NULL on failure
507 GNUNET_ATS_TEST_experimentation_load (char *filename);
513 * @param e the experiment
516 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
519 * Traffic related functions
523 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
526 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
529 struct TrafficGenerator *
530 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
531 struct BenchmarkPartner *dest,
533 struct GNUNET_TIME_Relative duration);
536 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
539 * Stop all traffic generators
542 GNUNET_ATS_TEST_generate_traffic_stop_all ();
546 * Logging related functions
552 * @param log_frequency the logging frequency
553 * @param testname the testname
554 * @param masters the master peers used for benchmarking
555 * @param num_master the number of master peers
556 * @return the logging handle or NULL on error
558 struct LoggingHandle *
559 GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
561 struct BenchmarkPeer *masters,
567 * @param l the logging handle
570 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
575 * @param l the logging handle
578 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
583 * @param llogging handle to use
586 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
590 * Write logging data to file
592 * @param l logging handle to use
593 * @param test_name name of the current test
596 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *h,
600 * Topology related functions
604 * Create a topology for ats testing
606 * @param name test name
607 * @param cfg_file configuration file to use for the peers
608 * @param num_slaves number of slaves
609 * @param num_masters number of masters
610 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
611 * @param done_cb function to call when topology is setup
612 * @param done_cb_cls cls for callback
613 * @param recv_cb callback to call when data are received
614 * @param perf_cb callback to call when performance info are received
617 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
618 unsigned int num_slaves,
619 unsigned int num_masters,
621 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
623 GNUNET_TRANSPORT_ReceiveCallback recv_cb,
624 GNUNET_ATS_TEST_LogRequest ats_perf_cb);
630 GNUNET_ATS_TEST_shutdown_topology (void);
632 /* end of file ats-testing.h */