ce336511ece8171acc3c74928a4f63f32056fc72
[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/perf_ats.c
22  * @brief ats benchmark: start peers and modify preferences, monitor change over time
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_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
33 #define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
34 #define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
35 #define TESTNAME_PREFIX "perf_ats_"
36 #define DEFAULT_SLAVES_NUM 2
37 #define DEFAULT_MASTERS_NUM 1
38
39 #define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
40 #define TEST_ATS_PREFRENCE_START 1.0
41 #define TEST_ATS_PREFRENCE_DELTA 1.0
42
43 #define TEST_MESSAGE_TYPE_PING 12345
44 #define TEST_MESSAGE_TYPE_PONG 12346
45 #define TEST_MESSAGE_SIZE 1000
46 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
47
48 /**
49  * Overall state of the performance benchmark
50  */
51 struct BenchmarkState
52 {
53   /**
54    * Are we connected to ATS service of all peers: GNUNET_YES/NO
55    */
56   int connected_ATS_service;
57
58   /**
59    * Are we connected to CORE service of all peers: GNUNET_YES/NO
60    */
61   int connected_COMM_service;
62
63   /**
64    * Are we connected to all peers: GNUNET_YES/NO
65    */
66   int connected_PEERS;
67
68   /**
69    * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
70    */
71   int connected_CORE;
72
73   /**
74    * Are we connected to CORE service of all peers: GNUNET_YES/NO
75    */
76   int benchmarking;
77 };
78
79
80 /**
81  * Information about a benchmarking partner
82  */
83 struct BenchmarkPartner
84 {
85   /**
86    * The peer itself this partner belongs to
87    */
88   struct BenchmarkPeer *me;
89
90   /**
91    * The partner peer
92    */
93   struct BenchmarkPeer *dest;
94
95   /**
96    * Core transmit handles
97    */
98   struct GNUNET_CORE_TransmitHandle *cth;
99
100   /**
101    * Transport transmit handles
102    */
103   struct GNUNET_TRANSPORT_TransmitHandle *tth;
104
105   /**
106    * Timestamp to calculate communication layer delay
107    */
108   struct GNUNET_TIME_Absolute last_message_sent;
109
110   /**
111    * Accumulated RTT for all messages
112    */
113   unsigned int total_app_rtt;
114
115   /**
116    * Number of messages sent to this partner
117    */
118   unsigned int messages_sent;
119
120   /**
121    * Number of bytes sent to this partner
122    */
123   unsigned int bytes_sent;
124
125   /**
126    * Number of messages received from this partner
127    */
128   unsigned int messages_received;
129
130   /**
131    * Number of bytes received from this partner
132    */
133   unsigned int bytes_received;
134
135   /* Current ATS properties */
136
137   uint32_t ats_distance;
138
139   uint32_t ats_delay;
140
141   uint32_t bandwidth_in;
142
143   uint32_t bandwidth_out;
144
145   uint32_t ats_utilization_up;
146
147   uint32_t ats_utilization_down;
148
149   uint32_t ats_network_type;
150
151   uint32_t ats_cost_wan;
152
153   uint32_t ats_cost_lan;
154
155   uint32_t ats_cost_wlan;
156 };
157
158
159 /**
160  * Information we track for a peer in the testbed.
161  */
162 struct BenchmarkPeer
163 {
164   /**
165    * Handle with testbed.
166    */
167   struct GNUNET_TESTBED_Peer *peer;
168
169   /**
170    * Unique identifier
171    */
172   int no;
173
174   /**
175    * Is this peer a measter: GNUNET_YES/GNUNET_NO
176    */
177   int master;
178
179   /**
180    *  Peer ID
181    */
182   struct GNUNET_PeerIdentity id;
183
184   /**
185    * Testbed operation to get peer information
186    */
187   struct GNUNET_TESTBED_Operation *peer_id_op;
188
189   /**
190    * Testbed operation to connect to ATS performance service
191    */
192   struct GNUNET_TESTBED_Operation *ats_perf_op;
193
194   /**
195    * Testbed operation to connect to core
196    */
197   struct GNUNET_TESTBED_Operation *comm_op;
198
199   /**
200    * ATS performance handle
201    */
202   struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
203
204   /**
205    * Masters only:
206    * Testbed connect operations to connect masters to slaves
207    */
208   struct TestbedConnectOperation *core_connect_ops;
209
210   /**
211    *  Core handle
212    */
213   struct GNUNET_CORE_Handle *ch;
214
215   /**
216    *  Core handle
217    */
218   struct GNUNET_TRANSPORT_Handle *th;
219
220   /**
221    * Masters only:
222    * Peer to set ATS preferences for
223    */
224   struct BenchmarkPeer *pref_partner;
225
226   /**
227    * Masters only
228    * Progress task
229    */
230   GNUNET_SCHEDULER_TaskIdentifier ats_task;
231
232   /**
233    * Masters only
234    * Progress task
235    */
236   double pref_value;
237
238   /**
239    * Array of partners with num_slaves entries (if master) or
240    * num_master entries (if slave)
241    */
242   struct BenchmarkPartner *partners;
243
244   /**
245    * Number of partners
246    */
247   int num_partners;
248
249   /**
250    * Number of core connections
251    */
252   int core_connections;
253
254   /**
255    * Masters only:
256    * Number of connections to slave peers
257    */
258   int core_slave_connections;
259
260   /**
261    * Total number of messages this peer has sent
262    */
263   unsigned int total_messages_sent;
264
265   /**
266    * Total number of bytes this peer has sent
267    */
268   unsigned int total_bytes_sent;
269
270   /**
271    * Total number of messages this peer has received
272    */
273   unsigned int total_messages_received;
274
275   /**
276    * Total number of bytes this peer has received
277    */
278   unsigned int total_bytes_received;
279 };
280
281 /**
282  * Connect peers with testbed
283  */
284 struct TestbedConnectOperation
285 {
286   /**
287    * The benchmarking master initiating this connection
288    */
289   struct BenchmarkPeer *master;
290
291   /**
292    * The benchmarking slave to connect to
293    */
294   struct BenchmarkPeer *slave;
295
296   /**
297    * Testbed operation to connect peers
298    */
299   struct GNUNET_TESTBED_Operation *connect_op;
300 };
301
302 typedef void (*GNUNET_ATS_TESTING_TopologySetupDoneCallback) (void *cls,
303     struct BenchmarkPeer *masters,
304     struct BenchmarkPeer *slaves);
305
306 struct GNUNET_ATS_TEST_Topology
307 {
308   /**
309    * Shutdown task
310    */
311   GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
312
313   /**
314    * Progress task
315    */
316   GNUNET_SCHEDULER_TaskIdentifier progress_task;
317
318   /**
319    * Test result
320    */
321   int result;
322
323   /**
324    * Test result logging
325    */
326   int logging;
327
328   /**Test core (GNUNET_YES) or transport (GNUNET_NO)
329    */
330   int test_core;
331
332   /**
333    * Solver string
334    */
335   char *solver;
336
337   /**
338    * Preference string
339    */
340   char *testname;
341
342   /**
343    * Preference string
344    */
345   char *pref_str;
346
347   /**
348    * ATS preference value
349    */
350   int pref_val;
351
352   /**
353    * Number master peers
354    */
355   unsigned int num_masters;
356
357   /**
358    * Array of master peers
359    */
360   struct BenchmarkPeer *mps;
361
362   /**
363    * Number slave peers
364    */
365   unsigned int num_slaves;
366
367   /**
368    * Array of slave peers
369    */
370   struct BenchmarkPeer *sps;
371
372   /**
373    * Benchmark duration
374    */
375   struct GNUNET_TIME_Relative perf_duration;
376
377   /**
378    * Logging frequency
379    */
380   struct GNUNET_TIME_Relative log_frequency;
381
382   /**
383    * Benchmark state
384    */
385   struct BenchmarkState state;
386
387   struct GNUNET_CORE_MessageHandler *handlers;
388
389   GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
390
391   GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb;
392   GNUNET_ATS_AddressInformationCallback ats_perf_cb;
393   void *done_cb_cls;
394 };
395
396 void
397 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
398     unsigned int num_slaves,
399     unsigned int num_masters,
400     int test_core,
401     GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb,
402     void *done_cb_cls,
403     struct GNUNET_CORE_MessageHandler *handlers,
404     GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
405     GNUNET_ATS_AddressInformationCallback ats_perf_cb);
406
407 void
408 GNUNET_ATS_TEST_shutdown_topology (void);
409
410 /* end of file perf_ats.c */