file logging
[oweals/gnunet.git] / src / ats / gnunet-ats-solver-eval.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-experiment.c
22  * @brief ats benchmark: controlled experiment execution
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  */
26 #ifndef GNUNET_ATS_SOLVER_EVAL_H
27 #define GNUNET_ATS_SOLVER_EVAL_H
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_ats_plugin.h"
32 #include "gnunet_ats_service.h"
33 #include "gnunet-service-ats_addresses.h"
34 #include "gnunet-service-ats_normalization.h"
35 #include "test_ats_api_common.h"
36
37 enum GeneratorType
38 {
39   GNUNET_ATS_TEST_TG_LINEAR,
40   GNUNET_ATS_TEST_TG_CONSTANT,
41   GNUNET_ATS_TEST_TG_RANDOM,
42   GNUNET_ATS_TEST_TG_SINUS
43 };
44
45
46 enum OperationType
47 {
48   SOLVER_OP_ADD_ADDRESS,
49   SOLVER_OP_DEL_ADDRESS,
50   SOLVER_OP_START_SET_PROPERTY,
51   SOLVER_OP_STOP_SET_PROPERTY,
52   SOLVER_OP_START_SET_PREFERENCE,
53   SOLVER_OP_STOP_SET_PREFERENCE,
54   SOLVER_OP_START_REQUEST,
55   SOLVER_OP_STOP_REQUEST,
56 };
57
58 struct SolverHandle
59 {
60   /**
61    * Solver plugin name
62    */
63   char *plugin;
64
65   /**
66    * Solver environment
67    */
68   struct GNUNET_ATS_PluginEnvironment env;
69
70   /**
71    * Solver handle
72    */
73   void *solver;
74
75   /**
76    * Address hashmap
77    */
78   struct GNUNET_CONTAINER_MultiPeerMap *addresses;
79 };
80
81 enum GNUNET_ATS_Solvers
82 {
83   GNUNET_ATS_SOLVER_PROPORTIONAL,
84   GNUNET_ATS_SOLVER_MLP,
85   GNUNET_ATS_SOLVER_RIL,
86 };
87
88 struct LoggingFileHandle
89 {
90   /* DLL list for logging time steps */
91   struct LoggingFileHandle *next;
92   struct LoggingFileHandle *prev;
93
94   /* peer id */
95   int pid;
96
97   /* address id */
98   int aid;
99
100   struct GNUNET_DISK_FileHandle *f_hd;
101
102 };
103
104 struct LoggingTimeStep
105 {
106   struct LoggingTimeStep *prev;
107   struct LoggingTimeStep *next;
108
109   struct LoggingPeer *head;
110   struct LoggingPeer *tail;
111
112   struct GNUNET_TIME_Absolute timestamp;
113   struct GNUNET_TIME_Relative delta;
114 };
115
116 struct LoggingPeer
117 {
118   struct LoggingPeer *prev;
119   struct LoggingPeer *next;
120
121   int id;
122   struct GNUNET_PeerIdentity peer_id;
123   double pref_abs[GNUNET_ATS_PreferenceCount];
124   double pref_norm[GNUNET_ATS_PreferenceCount];
125
126   struct LoggingAddress *addr_head;
127   struct LoggingAddress *addr_tail;
128 };
129
130 struct LoggingAddress
131 {
132   struct LoggingAddress *next;
133   struct LoggingAddress *prev;
134
135   int aid;
136   int active;
137   int used;
138   struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
139   struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
140
141   double prop_abs[GNUNET_ATS_PropertyCount];
142   double prop_norm[GNUNET_ATS_PropertyCount];
143 };
144
145
146 struct TestPeer
147 {
148   struct TestPeer *prev;
149   struct TestPeer *next;
150
151   int id;
152   struct GNUNET_PeerIdentity peer_id;
153
154   double pref_abs[GNUNET_ATS_PreferenceCount];
155   double pref_norm[GNUNET_ATS_PreferenceCount];
156
157   struct TestAddress *addr_head;
158   struct TestAddress *addr_tail;
159 };
160
161
162 struct TestAddress
163 {
164   struct TestAddress *next;
165   struct TestAddress *prev;
166
167   int aid;
168   struct ATS_Address *ats_addr;
169
170   double prop_abs[GNUNET_ATS_PropertyCount];
171   double prop_norm[GNUNET_ATS_PropertyCount];
172 };
173
174 struct Episode;
175
176 struct Experiment;
177
178 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
179     struct Episode *e);
180
181 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
182     struct GNUNET_TIME_Relative duration,int success);
183
184 /**
185  * An operation in an experiment
186  */
187 struct GNUNET_ATS_TEST_Operation
188 {
189   struct GNUNET_ATS_TEST_Operation *next;
190   struct GNUNET_ATS_TEST_Operation *prev;
191
192   long long unsigned int address_id;
193   long long unsigned int peer_id;
194   long long unsigned int client_id;
195   long long unsigned int address_session;
196   long long unsigned int address_network;
197   char*address;
198   char*plugin;
199
200
201   long long unsigned int base_rate;
202   long long unsigned int max_rate;
203   struct GNUNET_TIME_Relative period;
204   struct GNUNET_TIME_Relative frequency;
205
206   enum OperationType type;
207   enum GeneratorType gen_type;
208   enum GNUNET_ATS_PreferenceKind pref_type;
209   enum GNUNET_ATS_Property prop_type;
210 };
211
212 struct Episode
213 {
214   int id;
215   struct Episode *next;
216   struct GNUNET_TIME_Relative duration;
217
218   struct GNUNET_ATS_TEST_Operation *head;
219   struct GNUNET_ATS_TEST_Operation *tail;
220 };
221
222 struct LoggingHandle
223 {
224   GNUNET_SCHEDULER_TaskIdentifier logging_task;
225   struct GNUNET_TIME_Relative log_freq;
226
227   /* DLL list for logging time steps */
228   struct LoggingTimeStep *head;
229   struct LoggingTimeStep *tail;
230 };
231
232 struct Experiment
233 {
234   char *name;
235   char *log_prefix;
236   char *cfg_file;
237   struct GNUNET_TIME_Relative log_freq;
238   struct GNUNET_TIME_Relative max_duration;
239   struct GNUNET_TIME_Relative total_duration;
240   struct GNUNET_TIME_Absolute start_time;
241   unsigned int num_episodes;
242   struct Episode *start;
243
244   struct GNUNET_CONFIGURATION_Handle *cfg;
245
246   GNUNET_SCHEDULER_TaskIdentifier experiment_timeout_task;
247   GNUNET_SCHEDULER_TaskIdentifier episode_timeout_task;
248   struct Episode *cur;
249
250   GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
251   GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
252 };
253
254 struct PreferenceGenerator
255 {
256   struct PreferenceGenerator *prev;
257   struct PreferenceGenerator *next;
258
259   enum GeneratorType type;
260
261   unsigned int peer;
262   unsigned int client_id;
263
264   enum GNUNET_ATS_PreferenceKind kind;
265
266   long int base_value;
267   long int max_value;
268   struct GNUNET_TIME_Relative duration_period;
269   struct GNUNET_TIME_Relative frequency;
270
271   GNUNET_SCHEDULER_TaskIdentifier set_task;
272   struct GNUNET_TIME_Absolute next_ping_transmission;
273   struct GNUNET_TIME_Absolute time_start;
274 };
275
276
277 struct PropertyGenerator
278 {
279   struct PropertyGenerator *prev;
280   struct PropertyGenerator *next;
281
282   enum GeneratorType type;
283
284   unsigned int peer;
285   unsigned int address_id;
286
287   struct TestPeer *test_peer;
288   struct TestAddress *test_address;
289   uint32_t ats_property;
290
291   long int base_value;
292   long int max_value;
293   struct GNUNET_TIME_Relative duration_period;
294   struct GNUNET_TIME_Relative frequency;
295
296   GNUNET_SCHEDULER_TaskIdentifier set_task;
297   struct GNUNET_TIME_Absolute next_ping_transmission;
298   struct GNUNET_TIME_Absolute time_start;
299 };
300
301 #endif /* #ifndef GNUNET_ATS_SOLVER_EVAL_H */
302 /* end of file ats-testing.h */