028789d69af663a3eea7b9836fec69852d20423a
[oweals/gnunet.git] / src / ats-tests / ats-testing.h
1 /*
2  This file is part of GNUnet.
3  (C) 2010-2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19  */
20 /**
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
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testbed_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet_core_service.h"
31
32 #define TEST_ATS_PREFERENCE_DEFAULT 1.0
33
34 #define TEST_MESSAGE_TYPE_PING 12345
35 #define TEST_MESSAGE_TYPE_PONG 12346
36 #define TEST_MESSAGE_SIZE 100
37
38 struct BenchmarkPartner;
39 struct BenchmarkPeer;
40 struct GNUNET_ATS_TEST_Topology;
41 struct TrafficGenerator;
42 struct LoggingHandle;
43
44 typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
45     struct BenchmarkPeer *masters,
46     struct BenchmarkPeer *slaves);
47
48 typedef void
49 (*GNUNET_ATS_TEST_LogRequest) (void *cls,
50     const struct GNUNET_HELLO_Address *address, int address_active,
51     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
52     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
53     const struct GNUNET_ATS_Information *ats, uint32_t ats_count);
54
55 /**
56  * Information we track for a peer in the testbed.
57  */
58 struct BenchmarkPeer
59 {
60   /**
61    * Handle with testbed.
62    */
63   struct GNUNET_TESTBED_Peer *peer;
64
65   /**
66    * Unique identifier
67    */
68   int no;
69
70   /**
71    * Is this peer a measter: GNUNET_YES/GNUNET_NO
72    */
73   int master;
74
75   /**
76    *  Peer ID
77    */
78   struct GNUNET_PeerIdentity id;
79
80   /**
81    * Testbed operation to get peer information
82    */
83   struct GNUNET_TESTBED_Operation *peer_id_op;
84
85   /**
86    * Testbed operation to connect to ATS performance service
87    */
88   struct GNUNET_TESTBED_Operation *ats_perf_op;
89
90   /**
91    * Testbed operation to connect to core
92    */
93   struct GNUNET_TESTBED_Operation *comm_op;
94
95   /**
96    * ATS performance handle
97    */
98   struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
99
100   /**
101    * Masters only:
102    * Testbed connect operations to connect masters to slaves
103    */
104   struct TestbedConnectOperation *core_connect_ops;
105
106   /**
107    *  Core handle
108    */
109   struct GNUNET_CORE_Handle *ch;
110
111   /**
112    *  Core handle
113    */
114   struct GNUNET_TRANSPORT_Handle *th;
115
116   /**
117    * Masters only:
118    * Peer to set ATS preferences for
119    */
120   struct BenchmarkPeer *pref_partner;
121
122   /**
123    * Masters only
124    * Progress task
125    */
126   GNUNET_SCHEDULER_TaskIdentifier ats_task;
127
128   /**
129    * Masters only
130    * Progress task
131    */
132   double pref_value;
133
134   /**
135    * Array of partners with num_slaves entries (if master) or
136    * num_master entries (if slave)
137    */
138   struct BenchmarkPartner *partners;
139
140   /**
141    * Number of partners
142    */
143   int num_partners;
144
145   /**
146    * Number of core connections
147    */
148   int core_connections;
149
150   /**
151    * Masters only:
152    * Number of connections to slave peers
153    */
154   int core_slave_connections;
155
156   /**
157    * Total number of messages this peer has sent
158    */
159   unsigned int total_messages_sent;
160
161   /**
162    * Total number of bytes this peer has sent
163    */
164   unsigned int total_bytes_sent;
165
166   /**
167    * Total number of messages this peer has received
168    */
169   unsigned int total_messages_received;
170
171   /**
172    * Total number of bytes this peer has received
173    */
174   unsigned int total_bytes_received;
175 };
176
177 struct TrafficGenerator
178 {
179   struct TrafficGenerator *prev;
180   struct TrafficGenerator *next;
181
182   struct BenchmarkPeer *src;
183   struct BenchmarkPartner *dest;
184   unsigned int rate;
185   GNUNET_SCHEDULER_TaskIdentifier send_task;
186   struct GNUNET_TIME_Absolute next_ping_transmission;
187   struct GNUNET_TIME_Relative delta;
188 };
189
190
191 /**
192  * Information about a benchmarking partner
193  */
194 struct BenchmarkPartner
195 {
196   /**
197    * The peer itself this partner belongs to
198    */
199   struct BenchmarkPeer *me;
200
201   /**
202    * The partner peer
203    */
204   struct BenchmarkPeer *dest;
205
206   /**
207    * Core transmit handles
208    */
209   struct GNUNET_CORE_TransmitHandle *cth;
210
211   /**
212    * Transport transmit handles
213    */
214   struct GNUNET_TRANSPORT_TransmitHandle *tth;
215
216   struct TrafficGenerator *tg;
217
218   /**
219    * Timestamp to calculate communication layer delay
220    */
221   struct GNUNET_TIME_Absolute last_message_sent;
222
223   /**
224    * Accumulated RTT for all messages
225    */
226   unsigned int total_app_rtt;
227
228   /**
229    * Number of messages sent to this partner
230    */
231   unsigned int messages_sent;
232
233   /**
234    * Number of bytes sent to this partner
235    */
236   unsigned int bytes_sent;
237
238   /**
239    * Number of messages received from this partner
240    */
241   unsigned int messages_received;
242
243   /**
244    * Number of bytes received from this partner
245    */
246   unsigned int bytes_received;
247
248   /* Current ATS properties */
249
250   uint32_t ats_distance;
251
252   uint32_t ats_delay;
253
254   uint32_t bandwidth_in;
255
256   uint32_t bandwidth_out;
257
258   uint32_t ats_utilization_up;
259
260   uint32_t ats_utilization_down;
261
262   uint32_t ats_network_type;
263
264   uint32_t ats_cost_wan;
265
266   uint32_t ats_cost_lan;
267
268   uint32_t ats_cost_wlan;
269 };
270
271 /**
272  * Overall state of the performance benchmark
273  */
274 struct BenchmarkState
275 {
276   /**
277    * Are we connected to ATS service of all peers: GNUNET_YES/NO
278    */
279   int connected_ATS_service;
280
281   /**
282    * Are we connected to CORE service of all peers: GNUNET_YES/NO
283    */
284   int connected_COMM_service;
285
286   /**
287    * Are we connected to all peers: GNUNET_YES/NO
288    */
289   int connected_PEERS;
290
291   /**
292    * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
293    */
294   int connected_CORE;
295
296   /**
297    * Are we connected to CORE service of all peers: GNUNET_YES/NO
298    */
299   int benchmarking;
300 };
301
302
303 struct GNUNET_ATS_TEST_Topology
304 {
305   /**
306    * Shutdown task
307    */
308   GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
309
310   /**
311    * Progress task
312    */
313   GNUNET_SCHEDULER_TaskIdentifier progress_task;
314
315   /**
316    * Test result
317    */
318   int result;
319
320   /**Test core (GNUNET_YES) or transport (GNUNET_NO)
321    */
322   int test_core;
323
324   /**
325    * Solver string
326    */
327   char *solver;
328
329   /**
330    * Preference string
331    */
332   char *testname;
333
334   /**
335    * Preference string
336    */
337   char *pref_str;
338
339   /**
340    * ATS preference value
341    */
342   int pref_val;
343
344   /**
345    * Number master peers
346    */
347   unsigned int num_masters;
348
349   /**
350    * Array of master peers
351    */
352   struct BenchmarkPeer *mps;
353
354   /**
355    * Number slave peers
356    */
357   unsigned int num_slaves;
358
359   /**
360    * Array of slave peers
361    */
362   struct BenchmarkPeer *sps;
363
364   /**
365    * Benchmark duration
366    */
367   struct GNUNET_TIME_Relative perf_duration;
368
369   /**
370    * Logging frequency
371    */
372   struct GNUNET_TIME_Relative log_frequency;
373
374   /**
375    * Benchmark state
376    */
377   struct BenchmarkState state;
378
379   struct GNUNET_CORE_MessageHandler *handlers;
380
381   GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
382
383   GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb;
384   GNUNET_ATS_AddressInformationCallback ats_perf_cb;
385   void *done_cb_cls;
386 };
387
388 struct Experiment;
389
390 struct Episode;
391
392 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
393     struct Episode *e);
394
395 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (
396     struct Experiment *e, int success);
397
398
399 struct Experiment
400 {
401   char *name;
402   char *cfg_file;
403   unsigned long long int num_masters;
404   unsigned long long int num_slaves;
405   struct GNUNET_TIME_Relative max_duration;
406   struct GNUNET_TIME_Relative total_duration;
407   struct GNUNET_TIME_Absolute start_time;
408   unsigned int num_episodes;
409   struct Episode *start;
410
411   GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
412   GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
413   struct Episode *cur;
414
415   GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
416   GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
417 };
418
419 struct Episode
420 {
421   int id;
422   struct Episode *next;
423   struct GNUNET_TIME_Relative duration;
424 };
425
426 void
427 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
428     GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
429     GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
430
431 struct Experiment *
432 GNUNET_ATS_TEST_experimentation_load (char *filename);
433
434 void
435 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
436
437
438 struct TrafficGenerator *
439 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
440     struct BenchmarkPartner *dest, unsigned int rate,
441     struct GNUNET_TIME_Relative duration);
442
443 void
444 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
445
446 /**
447  * Stop all traffic generators
448  */
449 void
450 GNUNET_ATS_TEST_generate_traffic_stop_all ();
451
452 /**
453  * Start logging
454  */
455 struct LoggingHandle *
456 GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
457     char * testname, struct BenchmarkPeer *masters, int num_masters);
458
459 /**
460  * Stop logging
461  */
462 void
463 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *);
464
465 /**
466  * Log all data now
467  */
468 void
469 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *);
470
471 void
472 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *, char *test);
473
474 void
475 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
476
477 void
478 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
479
480
481 void
482 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
483     unsigned int num_slaves,
484     unsigned int num_masters,
485     int test_core,
486     GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
487     void *done_cb_cls,
488     GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
489     GNUNET_ATS_TEST_LogRequest ats_perf_cb);
490
491 void
492 GNUNET_ATS_TEST_shutdown_topology (void);
493
494 /* end of file ats-testing.h */