aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_math.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_math.h')
-rw-r--r--src/ats/gnunet-service-ats_math.h495
1 files changed, 0 insertions, 495 deletions
diff --git a/src/ats/gnunet-service-ats_math.h b/src/ats/gnunet-service-ats_math.h
deleted file mode 100644
index 2fdceb2c2..000000000
--- a/src/ats/gnunet-service-ats_math.h
+++ /dev/null
@@ -1,495 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 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/**
22 * @file ats/gnunet-service-ats_math.h
23 * @brief common internal definitions for transport service's ats code
24 * @author Matthias Wachs
25 */
26#ifndef GNUNET_SERVICE_TRANSPORT_MATH_H
27#define GNUNET_SERVICE_TRANSPORT_MATH_H
28
29#include "platform.h"
30#include "gnunet_constants.h"
31#include "gnunet_scheduler_lib.h"
32#include "gnunet_statistics_service.h"
33#include "gnunet_time_lib.h"
34
35
36#if HAVE_LIBGLPK
37#include <glpk.h>
38#endif
39
40/*
41 * ATS defines
42 */
43
44#define DEBUG_ATS GNUNET_EXTRA_LOGGING
45#define VERBOSE_ATS GNUNET_EXTRA_LOGGING
46
47
48/* Minimum time between to calculations*/
49#define ATS_MIN_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
50#define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
51#define ATS_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
52#define ATS_MAX_ITERATIONS INT_MAX
53
54#define ATS_DEFAULT_D 1.0
55#define ATS_DEFAULT_U 1.0
56#define ATS_DEFAULT_R 1.0
57#define ATS_DEFAULT_B_MIN 64000
58#define ATS_DEFAULT_N_MIN 10
59
60#define VERY_BIG_DOUBLE_VALUE 100000000000LL
61
62
63/*
64 * Callback Functions
65 */
66
67struct ATS_mechanism;
68struct ATS_peer;
69
70typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** peers,
71 int *c_p,
72 struct ATS_mechanism **
73 mechanisms, int *c_m);
74
75typedef void (*GNUNET_ATS_ResultCallback) (void);
76
77enum ATS_problem_state
78{
79 /**
80 * Problem is new
81 */
82 ATS_NEW = 0,
83
84 /**
85 * Problem quality properties were modified
86 */
87 ATS_QUALITY_UPDATED = 1,
88
89 /**
90 * Problem ressource properties were modified
91 */
92 ATS_COST_UPDATED = 2,
93
94 /**
95 * Problem quality and ressource properties were modified
96 */
97 ATS_QUALITY_COST_UPDATED = 3,
98
99 /**
100 * Problem is modified and needs to be completely recalculated
101 * due to e.g. connecting or disconnecting peers
102 */
103 ATS_MODIFIED = 4,
104
105 /**
106 * Problem is unmodified
107 */
108 ATS_UNMODIFIED = 8
109};
110
111/*
112* ATS data structures
113*/
114
115struct ATS_internals
116{
117 /**
118 * result of last GLPK run
119 * 5 == OPTIMAL
120 */
121 int solution;
122
123 /**
124 * Ressource costs or quality metrics changed
125 * update problem before solving
126 */
127 int modified_resources;
128
129 /**
130 * Ressource costs or quality metrics changed, update matrix
131 * update problem before solving
132 */
133 int modified_quality;
134
135 /**
136 * Peers have connected or disconnected
137 * problem has to be recreated
138 */
139 int recreate_problem;
140
141 /**
142 * Was the available basis invalid and we needed to rerun simplex?
143 */
144 int simplex_rerun_required;
145
146 /**
147 * is problem currently valid and can it be solved
148 */
149 int valid;
150
151 /**
152 * Number of transport mechanisms in the problem
153 */
154 int c_mechs;
155
156 /**
157 * Number of transport mechanisms in the problem
158 */
159 int c_peers;
160
161 /**
162 * row index where quality related rows start
163 */
164 int begin_qm;
165
166 /**
167 * row index where quality related rows end
168 */
169 int end_qm;
170
171 /**
172 * row index where ressource cost related rows start
173 */
174 int begin_cr;
175
176 /**
177 * row index where ressource cost related rows end
178 */
179 int end_cr;
180
181 /**
182 * column index for objective function value d
183 */
184 int col_d;
185
186 /**
187 * column index for objective function value u
188 */
189 int col_u;
190
191 /**
192 * column index for objective function value r
193 */
194 int col_r;
195
196 /**
197 * column index for objective function value quality metrics
198 */
199 int col_qm;
200
201 /**
202 * column index for objective function value cost ressources
203 */
204 int col_cr;
205};
206
207struct ATS_Handle
208{
209 /*
210 * Callback functions
211 */
212
213 GNUNET_ATS_AddressNotification addr_notification;
214
215 GNUNET_ATS_ResultCallback result_cb;
216
217
218 /**
219 * Statistics handle
220 */
221 struct GNUNET_STATISTICS_Handle *stats;
222
223 /**
224 * Maximum execution time per calculation
225 */
226 struct GNUNET_TIME_Relative max_exec_duration;
227
228 /**
229 * GLPK (MLP) problem object
230 */
231#if HAVE_LIBGLPK
232
233 glp_prob *prob;
234#else
235 void *prob;
236#endif
237
238 /**
239 * Internal information state of the GLPK problem
240 */
241 struct ATS_internals internal;
242
243 /**
244 * mechanisms used in current problem
245 * needed for problem modification
246 */
247 struct ATS_mechanism *mechanisms;
248
249 /**
250 * peers used in current problem
251 * needed for problem modification
252 */
253 struct ATS_peer *peers;
254
255 /**
256 * State of the MLP problem
257 * value of ATS_problem_state
258 *
259 */
260 int state;
261
262 /**
263 * number of successful executions
264 */
265 int successful_executions;
266
267 /**
268 * number with an invalid result
269 */
270 int invalid_executions;
271
272 /**
273 * Maximum number of LP iterations per calculation
274 */
275 int max_iterations;
276
277
278 /*
279 * ATS configuration
280 */
281
282
283 /**
284 * Diversity weight
285 */
286 double D;
287
288 /**
289 * Utility weight
290 */
291 double U;
292
293 /**
294 * Relativity weight
295 */
296 double R;
297
298 /**
299 * Minimum bandwidth per peer
300 */
301 int v_b_min;
302
303 /**
304 * Minimum number of connections per peer
305 */
306 int v_n_min;
307
308
309 /**
310 * Logging related variables
311 */
312
313
314 /**
315 * Dump problem to a file?
316 */
317 int save_mlp;
318
319 /**
320 * Dump solution to a file
321 */
322 int save_solution;
323
324 /**
325 * Dump solution when minimum peers:
326 */
327 int dump_min_peers;
328
329 /**
330 * Dump solution when minimum addresses:
331 */
332 int dump_min_addr;
333
334 /**
335 * Dump solution overwrite file:
336 */
337 int dump_overwrite;
338};
339
340struct ATS_mechanism
341{
342 struct ATS_mechanism *prev;
343 struct ATS_mechanism *next;
344 struct ForeignAddressList *addr;
345 struct ATS_quality_entry *quality;
346 struct ATS_ressource_entry *ressources;
347 struct TransportPlugin *plugin;
348 struct ATS_peer *peer;
349 int col_index;
350 int id;
351 struct ATS_ressource_cost *rc;
352};
353
354struct ATS_peer
355{
356 struct GNUNET_PeerIdentity peer;
357
358 struct ATS_mechanism *m_head;
359 struct ATS_mechanism *m_tail;
360
361 /* preference value f */
362 double f;
363
364 //struct NeighbourList * n;
365};
366
367struct ATS_ressource
368{
369 /* index in ressources array */
370 int index;
371 /* depending ATSi parameter to calculcate limits */
372 int atis_index;
373 /* cfg option to load limits */
374 char *cfg_param;
375 /* lower bound */
376 double c_min;
377 /* upper bound */
378 double c_max;
379
380 /* cofficients for the specific plugins */
381 double c_unix;
382 double c_tcp;
383 double c_udp;
384 double c_http;
385 double c_https;
386 double c_wlan;
387 double c_default;
388};
389
390
391struct ATS_ressource_entry
392{
393 /* index in ressources array */
394 int index;
395 /* depending ATSi parameter to calculcate limits */
396 int atis_index;
397 /* lower bound */
398 double c;
399};
400
401
402struct ATS_quality_metric
403{
404 int index;
405 int atis_index;
406 char *name;
407};
408
409struct ATS_quality_entry
410{
411 int index;
412 int atsi_index;
413 uint32_t values[3];
414 int current;
415};
416
417/*
418 * ATS ressources
419 */
420
421
422static struct ATS_ressource ressources[] = {
423 /* FIXME: the coefficients for the specific plugins */
424 {1, 7, "LAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 1, 3},
425 {2, 7, "WAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 2, 3},
426 {3, 4, "WLAN_ENERGY_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 0, 0, 0, 0, 2, 1}
427/*
428 {4, 4, "COST_ENERGY_CONSUMPTION", VERY_BIG_DOUBLE_VALUE},
429 {5, 5, "COST_CONNECT", VERY_BIG_DOUBLE_VALUE},
430 {6, 6, "COST_BANDWITH_AVAILABLE", VERY_BIG_DOUBLE_VALUE},
431 {7, 7, "COST_NETWORK_OVERHEAD", VERY_BIG_DOUBLE_VALUE},*/
432};
433
434#define available_ressources (sizeof(ressources)/sizeof(*ressources))
435
436/*
437 * ATS quality metrics
438 */
439
440static struct ATS_quality_metric qm[] = {
441 {1, 1028, "QUALITY_NET_DISTANCE"},
442 {2, 1034, "QUALITY_NET_DELAY"},
443};
444
445#define available_quality_metrics (sizeof(qm)/sizeof(*qm))
446
447
448/*
449 * ATS functions
450 */
451struct ATS_Handle *
452ats_init (double D, double U, double R, int v_b_min, int v_n_min,
453 int max_iterations, struct GNUNET_TIME_Relative max_duration,
454 GNUNET_ATS_AddressNotification address_not,
455 GNUNET_ATS_ResultCallback res_cb);
456
457void
458ats_shutdown (struct ATS_Handle *ats);
459
460void
461ats_delete_problem (struct ATS_Handle *ats);
462
463int
464ats_create_problem (struct ATS_Handle *ats, struct ATS_internals *stat,
465 struct ATS_peer *peers, int c_p,
466 struct ATS_mechanism *mechanisms, int c_m);
467
468void
469ats_modify_problem_state (struct ATS_Handle *ats, enum ATS_problem_state s);
470
471void
472ats_calculate_bandwidth_distribution (struct ATS_Handle *ats);
473
474void
475ats_solve_problem (struct ATS_Handle *ats, unsigned int max_it,
476 unsigned int max_dur, unsigned int c_peers,
477 unsigned int c_mechs, struct ATS_internals *stat);
478
479int
480ats_evaluate_results (int result, int solution, char *problem);
481
482void
483ats_update_problem_qm (struct ATS_Handle *ats);
484
485void
486ats_update_problem_cr (struct ATS_Handle *ats);
487
488
489void
490ats_set_logging_options (struct ATS_Handle *ats,
491 struct GNUNET_STATISTICS_Handle *stats,
492 const struct GNUNET_CONFIGURATION_Handle *cfg);
493
494#endif
495/* end of file gnunet-service-transport_ats.h */