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)
71 (struct ATS_peer ** peers,
72 int *c_p, struct ATS_mechanism ** mechanisms, int *c_m);
74 typedef void (*GNUNET_TRANSPORT_ATS_ResultCallback) (void);
76 enum ATS_problem_state
84 * Problem quality properties were modified
86 ATS_QUALITY_UPDATED = 1,
89 * Problem ressource properties were modified
94 * Problem quality and ressource properties were modified
96 ATS_QUALITY_COST_UPDATED = 3,
99 * Problem is modified and needs to be completely recalculated
100 * due to e.g. connecting or disconnecting peers
105 * Problem is unmodified
111 * ATS data structures
117 * result of last GLPK run
123 * Ressource costs or quality metrics changed
124 * update problem before solving
126 int modified_resources;
129 * Ressource costs or quality metrics changed, update matrix
130 * update problem before solving
132 int modified_quality;
135 * Peers have connected or disconnected
136 * problem has to be recreated
138 int recreate_problem;
141 * Was the available basis invalid and we needed to rerun simplex?
143 int simplex_rerun_required;
146 * is problem currently valid and can it be solved
151 * Number of transport mechanisms in the problem
156 * Number of transport mechanisms in the problem
161 * row index where quality related rows start
166 * row index where quality related rows end
171 * row index where ressource cost related rows start
176 * row index where ressource cost related rows end
181 * column index for objective function value d
186 * column index for objective function value u
191 * column index for objective function value r
196 * column index for objective function value quality metrics
201 * column index for objective function value cost ressources
212 GNUNET_TRANSPORT_ATS_AddressNotification addr_notification;
214 GNUNET_TRANSPORT_ATS_ResultCallback result_cb;
220 struct GNUNET_STATISTICS_Handle *stats;
223 * Maximum execution time per calculation
225 struct GNUNET_TIME_Relative max_exec_duration;
228 * GLPK (MLP) problem object
238 * Internal information state of the GLPK problem
240 struct ATS_internals internal;
243 * mechanisms used in current problem
244 * needed for problem modification
246 struct ATS_mechanism *mechanisms;
249 * peers used in current problem
250 * needed for problem modification
252 struct ATS_peer *peers;
255 * State of the MLP problem
256 * value of ATS_problem_state
262 * number of successful executions
264 int successful_executions;
267 * number with an invalid result
269 int invalid_executions;
272 * Maximum number of LP iterations per calculation
298 * Minimum bandwidth per peer
303 * Minimum number of connections per peer
309 * Logging related variables
314 * Dump problem to a file?
319 * Dump solution to a file
324 * Dump solution when minimum peers:
329 * Dump solution when minimum addresses:
334 * Dump solution overwrite file:
341 struct ATS_mechanism *prev;
342 struct ATS_mechanism *next;
343 struct ForeignAddressList *addr;
344 struct ATS_quality_entry *quality;
345 struct ATS_ressource_entry *ressources;
346 struct TransportPlugin *plugin;
347 struct ATS_peer *peer;
350 struct ATS_ressource_cost *rc;
355 struct GNUNET_PeerIdentity peer;
357 struct ATS_mechanism *m_head;
358 struct ATS_mechanism *m_tail;
360 /* preference value f */
363 //struct NeighbourList * n;
368 /* index in ressources array */
370 /* depending ATSi parameter to calculcate limits */
372 /* cfg option to load limits */
379 /* cofficients for the specific plugins */
390 struct ATS_ressource_entry
392 /* index in ressources array */
394 /* depending ATSi parameter to calculcate limits */
401 struct ATS_quality_metric
408 struct ATS_quality_entry
421 static struct ATS_ressource ressources[] = {
422 /* FIXME: the coefficients for the specific plugins */
423 {1, 7, "LAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 1, 3},
424 {2, 7, "WAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 2, 3},
425 {3, 4, "WLAN_ENERGY_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 0, 0, 0, 0, 2, 1}
427 {4, 4, "COST_ENERGY_CONSUMPTION", VERY_BIG_DOUBLE_VALUE},
428 {5, 5, "COST_CONNECT", VERY_BIG_DOUBLE_VALUE},
429 {6, 6, "COST_BANDWITH_AVAILABLE", VERY_BIG_DOUBLE_VALUE},
430 {7, 7, "COST_NETWORK_OVERHEAD", VERY_BIG_DOUBLE_VALUE},*/
433 #define available_ressources (sizeof(ressources)/sizeof(*ressources))
436 * ATS quality metrics
439 static struct ATS_quality_metric qm[] = {
440 {1, 1028, "QUALITY_NET_DISTANCE"},
441 {2, 1034, "QUALITY_NET_DELAY"},
444 #define available_quality_metrics (sizeof(qm)/sizeof(*qm))
450 struct ATS_Handle *ats_init (double D,
456 struct GNUNET_TIME_Relative max_duration,
457 GNUNET_TRANSPORT_ATS_AddressNotification
459 GNUNET_TRANSPORT_ATS_ResultCallback res_cb);
461 void ats_shutdown (struct ATS_Handle *ats);
463 void ats_delete_problem (struct ATS_Handle *ats);
466 ats_create_problem (struct ATS_Handle *ats,
467 struct ATS_internals *stat,
468 struct ATS_peer *peers,
469 int c_p, struct ATS_mechanism *mechanisms, int c_m);
471 void ats_modify_problem_state (struct ATS_Handle *ats,
472 enum ATS_problem_state s);
474 void ats_calculate_bandwidth_distribution (struct ATS_Handle *ats);
477 ats_solve_problem (struct ATS_Handle *ats,
479 unsigned int max_dur,
480 unsigned int c_peers,
481 unsigned int c_mechs, struct ATS_internals *stat);
483 int ats_evaluate_results (int result, int solution, char *problem);
485 void ats_update_problem_qm (struct ATS_Handle *ats);
487 void ats_update_problem_cr (struct ATS_Handle *ats);
491 ats_set_logging_options (struct ATS_Handle *ats,
492 struct GNUNET_STATISTICS_Handle *stats,
493 const struct GNUNET_CONFIGURATION_Handle *cfg);
496 /* end of file gnunet-service-transport_ats.h */