Merge branch 'master' of gnunet.org:gnunet
[oweals/gnunet.git] / src / ats-tests / perf_ats.h
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010-2013 GNUnet e.V.
4
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14
15  You should have received a copy of the GNU Affero General Public License
16  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 /**
19  * @file ats/perf_ats.c
20  * @brief ats benchmark: start peers and modify preferences, monitor change over time
21  * @author Christian Grothoff
22  * @author Matthias Wachs
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26 #include "gnunet_testbed_service.h"
27 #include "gnunet_ats_service.h"
28 #include "gnunet_core_service.h"
29 #include "ats-testing.h"
30
31 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
32 #define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33 #define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
34 #define TESTNAME_PREFIX "perf_ats_"
35 #define DEFAULT_SLAVES_NUM 2
36 #define DEFAULT_MASTERS_NUM 1
37
38 #define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
39 #define TEST_ATS_PREFRENCE_START 1.0
40 #define TEST_ATS_PREFRENCE_DELTA 1.0
41
42 #define TEST_MESSAGE_TYPE_PING 12345
43 #define TEST_MESSAGE_TYPE_PONG 12346
44 #define TEST_MESSAGE_SIZE 1000
45 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
46
47 /**
48  * Information about a benchmarking partner
49  */
50 struct BenchmarkPartner
51 {
52   /**
53    * The peer itself this partner belongs to
54    */
55   struct BenchmarkPeer *me;
56
57   /**
58    * The partner peer
59    */
60   struct BenchmarkPeer *dest;
61
62   /**
63    * Core transmit handles
64    */
65   struct GNUNET_CORE_TransmitHandle *cth;
66
67   /**
68    * Transport transmit handles
69    */
70   struct GNUNET_TRANSPORT_TransmitHandle *tth;
71
72   /**
73    * Timestamp to calculate communication layer delay
74    */
75   struct GNUNET_TIME_Absolute last_message_sent;
76
77   /**
78    * Accumulated RTT for all messages
79    */
80   unsigned int total_app_rtt;
81
82   /**
83    * Number of messages sent to this partner
84    */
85   unsigned int messages_sent;
86
87   /**
88    * Number of bytes sent to this partner
89    */
90   unsigned int bytes_sent;
91
92   /**
93    * Number of messages received from this partner
94    */
95   unsigned int messages_received;
96
97   /**
98    * Number of bytes received from this partner
99    */
100   unsigned int bytes_received;
101
102   /* Current ATS properties */
103
104   uint32_t ats_distance;
105
106   uint32_t ats_delay;
107
108   uint32_t bandwidth_in;
109
110   uint32_t bandwidth_out;
111
112   uint32_t ats_utilization_up;
113
114   uint32_t ats_utilization_down;
115
116   uint32_t ats_network_type;
117
118   uint32_t ats_cost_wan;
119
120   uint32_t ats_cost_lan;
121
122   uint32_t ats_cost_wlan;
123 };
124
125
126 /**
127  * Information we track for a peer in the testbed.
128  */
129 struct BenchmarkPeer
130 {
131   /**
132    * Handle with testbed.
133    */
134   struct GNUNET_TESTBED_Peer *peer;
135
136   /**
137    * Unique identifier
138    */
139   int no;
140
141   /**
142    * Is this peer a measter: GNUNET_YES/GNUNET_NO
143    */
144   int master;
145
146   /**
147    *  Peer ID
148    */
149   struct GNUNET_PeerIdentity id;
150
151   /**
152    * Testbed operation to get peer information
153    */
154   struct GNUNET_TESTBED_Operation *peer_id_op;
155
156   /**
157    * Testbed operation to connect to ATS performance service
158    */
159   struct GNUNET_TESTBED_Operation *ats_perf_op;
160
161   /**
162    * Testbed operation to connect to core
163    */
164   struct GNUNET_TESTBED_Operation *comm_op;
165
166   /**
167    * ATS performance handle
168    */
169   struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
170
171   /**
172    * Masters only:
173    * Testbed connect operations to connect masters to slaves
174    */
175   struct TestbedConnectOperation *core_connect_ops;
176
177   /**
178    *  Core handle
179    */
180   struct GNUNET_CORE_Handle *ch;
181
182   /**
183    *  Core handle
184    */
185   struct GNUNET_TRANSPORT_Handle *th;
186
187   /**
188    * Masters only:
189    * Peer to set ATS preferences for
190    */
191   struct BenchmarkPeer *pref_partner;
192
193   /**
194    * Masters only
195    * Progress task
196    */
197   struct GNUNET_SCHEDULER_Task * ats_task;
198
199   /**
200    * Masters only
201    * Progress task
202    */
203   double pref_value;
204
205   /**
206    * Array of partners with num_slaves entries (if master) or
207    * num_master entries (if slave)
208    */
209   struct BenchmarkPartner *partners;
210
211   /**
212    * Number of partners
213    */
214   int num_partners;
215
216   /**
217    * Number of core connections
218    */
219   int core_connections;
220
221   /**
222    * Masters only:
223    * Number of connections to slave peers
224    */
225   int core_slave_connections;
226
227   /**
228    * Total number of messages this peer has sent
229    */
230   unsigned int total_messages_sent;
231
232   /**
233    * Total number of bytes this peer has sent
234    */
235   unsigned int total_bytes_sent;
236
237   /**
238    * Total number of messages this peer has received
239    */
240   unsigned int total_messages_received;
241
242   /**
243    * Total number of bytes this peer has received
244    */
245   unsigned int total_bytes_received;
246 };
247
248
249 /* end of file perf_ats.h */