2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file transport/gnunet-service-transport_ats.h
23 * @brief common internal definitions for transport service's ats code
24 * @author Matthias Wachs
26 #ifndef GNUNET_SERVICE_TRANSPORT_ATS_H
27 #define GNUNET_SERVICE_TRANSPORT_ATS_H
30 #include "gnunet_constants.h"
31 #include "gnunet_scheduler_lib.h"
32 #include "gnunet_statistics_service.h"
33 #include "gnunet_time_lib.h"
44 #define DEBUG_ATS GNUNET_NO
45 #define VERBOSE_ATS GNUNET_NO
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
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
60 #define VERY_BIG_DOUBLE_VALUE 100000000000LL
70 typedef void (*GNUNET_TRANSPORT_ATS_AddressNotification) (struct ATS_peer **
76 typedef void (*GNUNET_TRANSPORT_ATS_ResultCallback) (void);
78 enum ATS_problem_state
86 * Problem quality properties were modified
88 ATS_QUALITY_UPDATED = 1,
91 * Problem ressource properties were modified
96 * Problem quality and ressource properties were modified
98 ATS_QUALITY_COST_UPDATED = 3,
101 * Problem is modified and needs to be completely recalculated
102 * due to e.g. connecting or disconnecting peers
107 * Problem is unmodified
113 * ATS data structures
119 * result of last GLPK run
125 * Ressource costs or quality metrics changed
126 * update problem before solving
128 int modified_resources;
131 * Ressource costs or quality metrics changed, update matrix
132 * update problem before solving
134 int modified_quality;
137 * Peers have connected or disconnected
138 * problem has to be recreated
140 int recreate_problem;
143 * Was the available basis invalid and we needed to rerun simplex?
145 int simplex_rerun_required;
148 * is problem currently valid and can it be solved
153 * Number of transport mechanisms in the problem
158 * Number of transport mechanisms in the problem
163 * row index where quality related rows start
168 * row index where quality related rows end
173 * row index where ressource cost related rows start
178 * row index where ressource cost related rows end
183 * column index for objective function value d
188 * column index for objective function value u
193 * column index for objective function value r
198 * column index for objective function value quality metrics
203 * column index for objective function value cost ressources
214 GNUNET_TRANSPORT_ATS_AddressNotification addr_notification;
216 GNUNET_TRANSPORT_ATS_ResultCallback result_cb;
222 struct GNUNET_STATISTICS_Handle *stats;
225 * Maximum execution time per calculation
227 struct GNUNET_TIME_Relative max_exec_duration;
230 * GLPK (MLP) problem object
240 * Internal information state of the GLPK problem
242 struct ATS_internals internal;
245 * mechanisms used in current problem
246 * needed for problem modification
248 struct ATS_mechanism *mechanisms;
251 * peers used in current problem
252 * needed for problem modification
254 struct ATS_peer *peers;
257 * State of the MLP problem
258 * value of ATS_problem_state
264 * number of successful executions
266 int successful_executions;
269 * number with an invalid result
271 int invalid_executions;
274 * Maximum number of LP iterations per calculation
300 * Minimum bandwidth per peer
305 * Minimum number of connections per peer
311 * Logging related variables
316 * Dump problem to a file?
321 * Dump solution to a file
326 * Dump solution when minimum peers:
331 * Dump solution when minimum addresses:
336 * Dump solution overwrite file:
343 struct ATS_mechanism *prev;
344 struct ATS_mechanism *next;
345 struct ForeignAddressList *addr;
346 struct ATS_quality_entry *quality;
347 struct ATS_ressource_entry *ressources;
348 struct TransportPlugin *plugin;
349 struct ATS_peer *peer;
352 struct ATS_ressource_cost *rc;
357 struct GNUNET_PeerIdentity peer;
359 struct ATS_mechanism *m_head;
360 struct ATS_mechanism *m_tail;
362 /* preference value f */
365 //struct NeighbourList * n;
370 /* index in ressources array */
372 /* depending ATSi parameter to calculcate limits */
374 /* cfg option to load limits */
381 /* cofficients for the specific plugins */
392 struct ATS_ressource_entry
394 /* index in ressources array */
396 /* depending ATSi parameter to calculcate limits */
403 struct ATS_quality_metric
410 struct ATS_quality_entry
423 static struct ATS_ressource ressources[] = {
424 /* FIXME: the coefficients for the specific plugins */
425 {1, 7, "LAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 1, 3},
426 {2, 7, "WAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 2, 3},
427 {3, 4, "WLAN_ENERGY_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 0, 0, 0, 0, 2, 1}
429 {4, 4, "COST_ENERGY_CONSUMPTION", VERY_BIG_DOUBLE_VALUE},
430 {5, 5, "COST_CONNECT", VERY_BIG_DOUBLE_VALUE},
431 {6, 6, "COST_BANDWITH_AVAILABLE", VERY_BIG_DOUBLE_VALUE},
432 {7, 7, "COST_NETWORK_OVERHEAD", VERY_BIG_DOUBLE_VALUE},*/
435 #define available_ressources (sizeof(ressources)/sizeof(*ressources))
438 * ATS quality metrics
441 static struct ATS_quality_metric qm[] = {
442 {1, 1028, "QUALITY_NET_DISTANCE"},
443 {2, 1034, "QUALITY_NET_DELAY"},
446 #define available_quality_metrics (sizeof(qm)/sizeof(*qm))
452 struct ATS_Handle *ats_init (double D, double U, double R, int v_b_min,
453 int v_n_min, int max_iterations,
454 struct GNUNET_TIME_Relative max_duration,
455 GNUNET_TRANSPORT_ATS_AddressNotification
457 GNUNET_TRANSPORT_ATS_ResultCallback res_cb);
459 void ats_shutdown (struct ATS_Handle *ats);
461 void ats_delete_problem (struct ATS_Handle *ats);
463 int ats_create_problem (struct ATS_Handle *ats, struct ATS_internals *stat,
464 struct ATS_peer *peers, int c_p,
465 struct ATS_mechanism *mechanisms, int c_m);
467 void ats_modify_problem_state (struct ATS_Handle *ats,
468 enum ATS_problem_state s);
470 void ats_calculate_bandwidth_distribution (struct ATS_Handle *ats);
472 void ats_solve_problem (struct ATS_Handle *ats, unsigned int max_it,
473 unsigned int max_dur, unsigned int c_peers,
474 unsigned int c_mechs, struct ATS_internals *stat);
476 int ats_evaluate_results (int result, int solution, char *problem);
478 void ats_update_problem_qm (struct ATS_Handle *ats);
480 void ats_update_problem_cr (struct ATS_Handle *ats);
483 void ats_set_logging_options (struct ATS_Handle *ats,
484 struct GNUNET_STATISTICS_Handle *stats,
485 const struct GNUNET_CONFIGURATION_Handle *cfg);
488 /* end of file gnunet-service-transport_ats.h */