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_EXTRA_LOGGING
45 #define VERBOSE_ATS GNUNET_EXTRA_LOGGING
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_ATS_AddressNotification) (struct ATS_peer ** peers,
72 struct ATS_mechanism **
73 mechanisms, int *c_m);
75 typedef void (*GNUNET_ATS_ResultCallback) (void);
77 enum ATS_problem_state
85 * Problem quality properties were modified
87 ATS_QUALITY_UPDATED = 1,
90 * Problem ressource properties were modified
95 * Problem quality and ressource properties were modified
97 ATS_QUALITY_COST_UPDATED = 3,
100 * Problem is modified and needs to be completely recalculated
101 * due to e.g. connecting or disconnecting peers
106 * Problem is unmodified
112 * ATS data structures
118 * result of last GLPK run
124 * Ressource costs or quality metrics changed
125 * update problem before solving
127 int modified_resources;
130 * Ressource costs or quality metrics changed, update matrix
131 * update problem before solving
133 int modified_quality;
136 * Peers have connected or disconnected
137 * problem has to be recreated
139 int recreate_problem;
142 * Was the available basis invalid and we needed to rerun simplex?
144 int simplex_rerun_required;
147 * is problem currently valid and can it be solved
152 * Number of transport mechanisms in the problem
157 * Number of transport mechanisms in the problem
162 * row index where quality related rows start
167 * row index where quality related rows end
172 * row index where ressource cost related rows start
177 * row index where ressource cost related rows end
182 * column index for objective function value d
187 * column index for objective function value u
192 * column index for objective function value r
197 * column index for objective function value quality metrics
202 * column index for objective function value cost ressources
213 GNUNET_ATS_AddressNotification addr_notification;
215 GNUNET_ATS_ResultCallback result_cb;
221 struct GNUNET_STATISTICS_Handle *stats;
224 * Maximum execution time per calculation
226 struct GNUNET_TIME_Relative max_exec_duration;
229 * GLPK (MLP) problem object
239 * Internal information state of the GLPK problem
241 struct ATS_internals internal;
244 * mechanisms used in current problem
245 * needed for problem modification
247 struct ATS_mechanism *mechanisms;
250 * peers used in current problem
251 * needed for problem modification
253 struct ATS_peer *peers;
256 * State of the MLP problem
257 * value of ATS_problem_state
263 * number of successful executions
265 int successful_executions;
268 * number with an invalid result
270 int invalid_executions;
273 * Maximum number of LP iterations per calculation
299 * Minimum bandwidth per peer
304 * Minimum number of connections per peer
310 * Logging related variables
315 * Dump problem to a file?
320 * Dump solution to a file
325 * Dump solution when minimum peers:
330 * Dump solution when minimum addresses:
335 * Dump solution overwrite file:
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;
351 struct ATS_ressource_cost *rc;
356 struct GNUNET_PeerIdentity peer;
358 struct ATS_mechanism *m_head;
359 struct ATS_mechanism *m_tail;
361 /* preference value f */
364 //struct NeighbourList * n;
369 /* index in ressources array */
371 /* depending ATSi parameter to calculcate limits */
373 /* cfg option to load limits */
380 /* cofficients for the specific plugins */
391 struct ATS_ressource_entry
393 /* index in ressources array */
395 /* depending ATSi parameter to calculcate limits */
402 struct ATS_quality_metric
409 struct ATS_quality_entry
422 static 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}
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},*/
434 #define available_ressources (sizeof(ressources)/sizeof(*ressources))
437 * ATS quality metrics
440 static struct ATS_quality_metric qm[] = {
441 {1, 1028, "QUALITY_NET_DISTANCE"},
442 {2, 1034, "QUALITY_NET_DELAY"},
445 #define available_quality_metrics (sizeof(qm)/sizeof(*qm))
452 ats_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);
458 ats_shutdown (struct ATS_Handle *ats);
461 ats_delete_problem (struct ATS_Handle *ats);
464 ats_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);
469 ats_modify_problem_state (struct ATS_Handle *ats, enum ATS_problem_state s);
472 ats_calculate_bandwidth_distribution (struct ATS_Handle *ats);
475 ats_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);
480 ats_evaluate_results (int result, int solution, char *problem);
483 ats_update_problem_qm (struct ATS_Handle *ats);
486 ats_update_problem_cr (struct ATS_Handle *ats);
490 ats_set_logging_options (struct ATS_Handle *ats,
491 struct GNUNET_STATISTICS_Handle *stats,
492 const struct GNUNET_CONFIGURATION_Handle *cfg);
495 /* end of file gnunet-service-transport_ats.h */