15ff5d62a07322898ea6f03124919bcab7bdbf86
[oweals/gnunet.git] / src / ats-tests / perf_ats.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, 30)
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 3
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  * Information about a benchmarking partner
50  */
51 struct BenchmarkPartner
52 {
53   /**
54    * The peer itself this partner belongs to
55    */
56   struct BenchmarkPeer *me;
57
58   /**
59    * The partner peer
60    */
61   struct BenchmarkPeer *dest;
62
63   /**
64    * Core transmit handles
65    */
66   struct GNUNET_CORE_TransmitHandle *cth;
67
68   /**
69    * Transport transmit handles
70    */
71   struct GNUNET_TRANSPORT_TransmitHandle *tth;
72
73   /**
74    * Timestamp to calculate communication layer delay
75    */
76   struct GNUNET_TIME_Absolute last_message_sent;
77
78   /**
79    * Accumulated delay for all messages
80    */
81   unsigned int total_app_delay;
82
83   /**
84    * Number of messages sent to this partner
85    */
86   unsigned int messages_sent;
87
88   /**
89    * Number of bytes sent to this partner
90    */
91   unsigned int bytes_sent;
92
93   /**
94    * Number of messages received from this partner
95    */
96   unsigned int messages_received;
97
98   /**
99    * Number of bytes received from this partner
100    */
101   unsigned int bytes_received;
102
103   /* Current ATS properties */
104
105   uint32_t ats_distance;
106
107   uint32_t ats_delay;
108
109   uint32_t bandwidth_in;
110
111   uint32_t bandwidth_out;
112 };
113
114
115 /**
116  * Information we track for a peer in the testbed.
117  */
118 struct BenchmarkPeer
119 {
120   /**
121    * Handle with testbed.
122    */
123   struct GNUNET_TESTBED_Peer *peer;
124
125   /**
126    * Unique identifier
127    */
128   int no;
129
130   /**
131    * Is this peer a measter: GNUNET_YES/GNUNET_NO
132    */
133   int master;
134
135   /**
136    *  Peer ID
137    */
138   struct GNUNET_PeerIdentity id;
139
140   /**
141    * Testbed operation to get peer information
142    */
143   struct GNUNET_TESTBED_Operation *peer_id_op;
144
145   /**
146    * Testbed operation to connect to ATS performance service
147    */
148   struct GNUNET_TESTBED_Operation *ats_perf_op;
149
150   /**
151    * Testbed operation to connect to core
152    */
153   struct GNUNET_TESTBED_Operation *comm_op;
154
155   /**
156    * ATS performance handle
157    */
158   struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
159
160   /**
161    * Masters only:
162    * Testbed connect operations to connect masters to slaves
163    */
164   struct TestbedConnectOperation *core_connect_ops;
165
166   /**
167    *  Core handle
168    */
169   struct GNUNET_CORE_Handle *ch;
170
171   /**
172    *  Core handle
173    */
174   struct GNUNET_TRANSPORT_Handle *th;
175
176   /**
177    * Masters only:
178    * Peer to set ATS preferences for
179    */
180   struct BenchmarkPeer *pref_partner;
181
182   /**
183    * Masters only
184    * Progress task
185    */
186   GNUNET_SCHEDULER_TaskIdentifier ats_task;
187
188   /**
189    * Masters only
190    * Progress task
191    */
192   double pref_value;
193
194   /**
195    * Array of partners with num_slaves entries (if master) or
196    * num_master entries (if slave)
197    */
198   struct BenchmarkPartner *partners;
199
200   /**
201    * Number of partners
202    */
203   int num_partners;
204
205   /**
206    * Number of core connections
207    */
208   int core_connections;
209
210   /**
211    * Masters only:
212    * Number of connections to slave peers
213    */
214   int core_slave_connections;
215
216   /**
217    * Total number of messages this peer has sent
218    */
219   unsigned int total_messages_sent;
220
221   /**
222    * Total number of bytes this peer has sent
223    */
224   unsigned int total_bytes_sent;
225
226   /**
227    * Total number of messages this peer has received
228    */
229   unsigned int total_messages_received;
230
231   /**
232    * Total number of bytes this peer has received
233    */
234   unsigned int total_bytes_received;
235 };
236
237
238 void
239 perf_logging_stop ();
240
241 void
242 perf_logging_start (struct GNUNET_TIME_Relative log_frequency,
243     char * testname, struct BenchmarkPeer *masters, int num_masters);
244
245
246 /* end of file perf_ats.h */