transport reliabilities checken
[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 enum OperationType
389 {
390   START_SEND,
391   STOP_SEND,
392   SET_RATE,
393   SET_PREFERENCE
394 };
395
396 struct Episode;
397
398 struct Experiment;
399
400 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
401     struct Episode *e);
402
403 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
404     struct GNUNET_TIME_Relative duration,int success);
405
406 struct Operation
407 {
408   struct Operation *next;
409   struct Operation *prev;
410   long long unsigned int src_id;
411   long long unsigned int dest_id;
412   long long unsigned int value;
413   enum OperationType type;
414 };
415
416 struct Episode
417 {
418   int id;
419   struct Episode *next;
420   struct GNUNET_TIME_Relative duration;
421
422   struct Operation *head;
423   struct Operation *tail;
424 };
425
426
427 struct Experiment
428 {
429   char *name;
430   char *cfg_file;
431   unsigned long long int num_masters;
432   unsigned long long int num_slaves;
433   struct GNUNET_TIME_Relative max_duration;
434   struct GNUNET_TIME_Relative total_duration;
435   struct GNUNET_TIME_Absolute start_time;
436   unsigned int num_episodes;
437   struct Episode *start;
438
439   GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
440   GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
441   struct Episode *cur;
442
443   GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
444   GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
445 };
446
447 void
448 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
449     GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
450     GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
451
452 struct Experiment *
453 GNUNET_ATS_TEST_experimentation_load (char *filename);
454
455 void
456 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
457
458
459 struct TrafficGenerator *
460 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
461     struct BenchmarkPartner *dest, unsigned int rate,
462     struct GNUNET_TIME_Relative duration);
463
464 void
465 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
466
467 /**
468  * Stop all traffic generators
469  */
470 void
471 GNUNET_ATS_TEST_generate_traffic_stop_all ();
472
473 /**
474  * Start logging
475  *
476  * @param log_frequency the logging frequency
477  * @param testname the testname
478  * @param masters the master peers used for benchmarking
479  * @param num_master the number of master peers
480  * @return the logging handle or NULL on error
481  */
482 struct LoggingHandle *
483 GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
484     char * testname, struct BenchmarkPeer *masters, int num_masters);
485
486 /**
487  * Stop logging
488  *
489  * @param l the logging handle
490  */
491 void
492 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
493
494 /**
495  * Log all data now
496  */
497 void
498 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *);
499
500 void
501 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *, char *test);
502
503 void
504 GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
505
506 void
507 GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
508
509
510 void
511 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
512     unsigned int num_slaves,
513     unsigned int num_masters,
514     int test_core,
515     GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
516     void *done_cb_cls,
517     GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
518     GNUNET_ATS_TEST_LogRequest ats_perf_cb);
519
520 void
521 GNUNET_ATS_TEST_shutdown_topology (void);
522
523 /* end of file ats-testing.h */