-fix (C) notices
[oweals/gnunet.git] / src / ats / gnunet-ats-solver-eval.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
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., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, 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   struct GNUNET_ATS_SolverFunctions *sf;
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   long long unsigned int pid;
96
97   /* address id */
98   long long unsigned 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   long long unsigned int id;
122   struct GNUNET_PeerIdentity peer_id;
123   double pref_abs[GNUNET_ATS_PREFERENCE_END];
124   double pref_norm[GNUNET_ATS_PREFERENCE_END];
125   int is_requested;
126
127   struct LoggingAddress *addr_head;
128   struct LoggingAddress *addr_tail;
129 };
130
131 struct LoggingAddress
132 {
133   struct LoggingAddress *next;
134   struct LoggingAddress *prev;
135
136   long long unsigned int aid;
137   int active;
138   uint32_t network;
139   uint32_t assigned_bw_in;
140   uint32_t assigned_bw_out;
141
142   double prop_abs[GNUNET_ATS_PropertyCount];
143   double prop_norm[GNUNET_ATS_PropertyCount];
144 };
145
146
147 struct TestPeer
148 {
149   struct TestPeer *prev;
150   struct TestPeer *next;
151
152
153   long long unsigned int id;
154   int is_requested;
155   struct GNUNET_PeerIdentity peer_id;
156
157   double pref_abs[GNUNET_ATS_PreferenceCount];
158   double pref_norm[GNUNET_ATS_PreferenceCount];
159
160   uint32_t assigned_bw_in;
161   uint32_t assigned_bw_out;
162
163   struct TestAddress *addr_head;
164   struct TestAddress *addr_tail;
165 };
166
167
168 struct TestAddress
169 {
170   struct TestAddress *next;
171   struct TestAddress *prev;
172
173   long long unsigned int aid;
174   struct ATS_Address *ats_addr;
175   uint32_t network;
176
177   double prop_abs[GNUNET_ATS_PropertyCount];
178   double prop_norm[GNUNET_ATS_PropertyCount];
179 };
180
181 struct Episode;
182
183 struct Experiment;
184
185 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
186     struct Episode *e);
187
188 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
189     struct GNUNET_TIME_Relative duration,int success);
190
191 /**
192  * An operation in an experiment
193  */
194 struct GNUNET_ATS_TEST_Operation
195 {
196   struct GNUNET_ATS_TEST_Operation *next;
197   struct GNUNET_ATS_TEST_Operation *prev;
198
199   long long unsigned int address_id;
200   long long unsigned int peer_id;
201   long long unsigned int client_id;
202
203   long long unsigned int address_session;
204   unsigned int address_network;
205   char*address;
206   char*plugin;
207
208
209   long long unsigned int base_rate;
210   long long unsigned int max_rate;
211   struct GNUNET_TIME_Relative period;
212   struct GNUNET_TIME_Relative frequency;
213   struct GNUNET_TIME_Relative feedback_delay;
214
215   enum OperationType type;
216   enum GeneratorType gen_type;
217   enum GNUNET_ATS_PreferenceKind pref_type;
218   // enum GNUNET_ATS_Property prop_type;
219 };
220
221 struct Episode
222 {
223   int id;
224   struct Episode *next;
225   struct GNUNET_TIME_Relative duration;
226
227   struct GNUNET_ATS_TEST_Operation *head;
228   struct GNUNET_ATS_TEST_Operation *tail;
229 };
230
231 struct LoggingHandle
232 {
233   struct GNUNET_SCHEDULER_Task * logging_task;
234   struct GNUNET_TIME_Relative log_freq;
235
236   /* DLL list for logging time steps */
237   struct LoggingTimeStep *head;
238   struct LoggingTimeStep *tail;
239 };
240
241 struct Experiment
242 {
243   char *name;
244   char *log_prefix;
245   char *cfg_file;
246   char *log_output_dir;
247   int log_append_time_stamp;
248
249   struct GNUNET_TIME_Relative log_freq;
250   struct GNUNET_TIME_Relative max_duration;
251   struct GNUNET_TIME_Relative total_duration;
252   struct GNUNET_TIME_Absolute start_time;
253   unsigned int num_episodes;
254   struct Episode *start;
255
256   struct GNUNET_CONFIGURATION_Handle *cfg;
257
258   struct GNUNET_SCHEDULER_Task * experiment_timeout_task;
259   struct GNUNET_SCHEDULER_Task * episode_timeout_task;
260   struct Episode *cur;
261
262   GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
263   GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
264 };
265
266 struct PreferenceGenerator
267 {
268   struct PreferenceGenerator *prev;
269   struct PreferenceGenerator *next;
270
271   enum GeneratorType type;
272
273   long long unsigned int peer;
274   unsigned int client_id;
275
276   enum GNUNET_ATS_PreferenceKind kind;
277
278   long int base_value;
279   long int max_value;
280   struct GNUNET_TIME_Relative duration_period;
281   struct GNUNET_TIME_Relative frequency;
282   struct GNUNET_TIME_Relative feedback_frequency;
283
284   struct GNUNET_SCHEDULER_Task * set_task;
285   struct GNUNET_SCHEDULER_Task * feedback_task;
286   struct GNUNET_TIME_Absolute next_ping_transmission;
287   struct GNUNET_TIME_Absolute time_start;
288
289
290   /* Feedback */
291   uint32_t feedback_bw_out_acc;
292   uint32_t feedback_bw_in_acc;
293   uint32_t feedback_delay_acc;
294
295   double pref_bw_old;
296   double pref_latency_old;
297
298   struct GNUNET_TIME_Absolute feedback_last;
299
300   struct GNUNET_TIME_Absolute feedback_last_bw_update;
301   struct GNUNET_TIME_Absolute feedback_last_delay_update;
302   uint32_t last_assigned_bw_in;
303   uint32_t last_assigned_bw_out;
304   double last_delay_value;
305
306 };
307
308
309 struct PropertyGenerator
310 {
311   struct PropertyGenerator *prev;
312   struct PropertyGenerator *next;
313
314   enum GeneratorType type;
315
316   long long unsigned int peer;
317   long long unsigned int address_id;
318
319   struct TestPeer *test_peer;
320   struct TestAddress *test_address;
321   uint32_t ats_property;
322
323   long int base_value;
324   long int max_value;
325   struct GNUNET_TIME_Relative duration_period;
326   struct GNUNET_TIME_Relative frequency;
327
328   struct GNUNET_SCHEDULER_Task * set_task;
329   struct GNUNET_TIME_Absolute next_ping_transmission;
330   struct GNUNET_TIME_Absolute time_start;
331 };
332
333 #endif /* #ifndef GNUNET_ATS_SOLVER_EVAL_H */
334 /* end of file ats-testing.h */