2 This file is part of GNUnet.
3 (C) 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 ats/gnunet-service-ats_addresses_mlp.h
23 * @brief ats MLP problem solver
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet_statistics_service.h"
29 #include "gnunet-service-ats_addresses.h"
34 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
35 #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
37 #define BIG_M_VALUE (UINT32_MAX) /10
38 #define BIG_M_STRING "unlimited"
40 #define MLP_AVERAGING_QUEUE_LENGTH 3
42 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
43 #define MLP_MAX_ITERATIONS 1024
48 #define DEFAULT_QUALITY 1.0
49 #define DEFAULT_MIN_CONNECTIONS 4
55 struct ATS_Peer *next;
56 struct ATS_Peer *prev;
58 struct GNUNET_PeerIdentity id;
60 /* Array of quality preferences */
61 double f_q[GNUNET_ATS_QualityPropertiesCount];
62 /* Legacy preference value */
65 /* constraint 2: 1 address per peer*/
68 /* constraint 9: relativity */
71 struct ATS_Address *head;
72 struct ATS_Address *tail;
75 struct GAS_MLP_SolutionContext
79 struct GNUNET_TIME_Relative lp_duration;
80 struct GNUNET_TIME_Relative mlp_duration;
88 * GLPK (MLP) problem object
95 /* Number of addresses in problem */
96 unsigned int num_addresses;
97 /* Number of peers in problem */
98 unsigned int num_peers;
100 /* Row index constraint 2: */
102 /* Row index constraint 4: minimum connections */
104 /* Row index constraint 6: maximize diversity */
106 /* Row index constraint 8: utilization*/
108 /* Row index constraint 9: relativity*/
110 /* Row indices quality metrics */
111 int r_q[GNUNET_ATS_QualityPropertiesCount];
112 /* Row indices ATS network quotas */
113 int r_quota[GNUNET_ATS_NetworkTypeCount];
115 /* Column index Diversity (D) column */
117 /* Column index Utilization (U) column */
119 /* Column index Proportionality (R) column */
121 /* Column index quality metrics */
122 int c_q[GNUNET_ATS_QualityPropertiesCount];
123 /* column index ressource costs */
124 int c_rc[GNUNET_ATS_QualityPropertiesCount];
125 /* Column indices ATS network quotas */
126 int c_quota[GNUNET_ATS_NetworkTypeCount];
131 /* Row index array */
133 /* Column index array */
135 /* Column index value */
141 /* Big M value for bandwidth capping */
144 /* ATS Quality metrics
146 * Array with GNUNET_ATS_QualityPropertiesCount elements
147 * contains mapping to GNUNET_ATS_Property*/
148 int q[GNUNET_ATS_QualityPropertiesCount];
150 /* Number of quality metrics */
153 /* Number of quality metrics */
156 /* Quality metric coefficients*/
157 double co_Q[GNUNET_ATS_QualityPropertiesCount];
159 /* Ressource costs coefficients*/
160 double co_RC[GNUNET_ATS_QualityPropertiesCount];
162 /* Diversity coefficient */
165 /* Utility coefficient */
168 /* Relativity coefficient */
171 /* Minimum bandwidth assigned to an address */
174 /* Minimum number of addresses with bandwidth assigned */
178 /* Array mapping array index to ATS network */
179 int quota_index [GNUNET_ATS_NetworkTypeCount];
180 /* Outbound quotas */
181 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
184 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
186 /* ATS ressource costs
187 * array with GNUNET_ATS_QualityPropertiesCount elements
188 * contains mapping to GNUNET_ATS_Property
190 int rc[GNUNET_ATS_QualityPropertiesCount];
198 struct GAS_MLP_Handle
203 struct GNUNET_STATISTICS_Handle *stats;
206 * Addresses' bandwidth changed callback
208 GAS_bandwidth_changed_cb bw_changed_cb;
211 * Addresses' bandwidth changed callback closure
213 void *bw_changed_cb_cls;
215 struct MLP_Problem p;
217 struct MLP_Variables pv;
222 * GLPK LP control parameter
225 glp_smcp control_param_lp;
227 void *control_param_lp;
231 * GLPK LP control parameter
234 glp_iocp control_param_mlp;
236 void *control_param_mlp;
240 * Peers with pending address requests
242 struct GNUNET_CONTAINER_MultiHashMap *peers;
245 * Was the problem updated since last solution
247 int mlp_prob_updated;
250 * Has the problem size changed since last solution
252 int mlp_prob_changed;
255 * Solves the task in an regular interval
257 GNUNET_SCHEDULER_TaskIdentifier mlp_task;
260 * Interval between scheduled problem solving
262 struct GNUNET_TIME_Relative exec_interval;
265 * Maximum execution time per problem solving
267 struct GNUNET_TIME_Relative max_exec_duration;
270 * Maximum number of LP iterations per problem solving
272 unsigned int max_iterations;
275 * Solve the problem automatically when updates occur?
276 * Default: GNUNET_YES
277 * Can be disabled for test and measurements
282 * Is a solution attemp running?
286 /* state information */
289 * Do we need to use the LP presolver?
291 * If the problem addresses were added or removed and the last basis was we
292 * need to use the presolver.
293 * presolver_required == GNUNET_YES
295 * If values were modified, we can reuse a valid basis
296 * presolver_required == GNUNET_NO
298 int presolver_required;
303 * Time of last execution
305 struct GNUNET_TIME_Absolute last_execution;
309 * How often was the LP problem solved
311 unsigned int lp_solved;
314 * total duration of all lp solver executions
316 uint64_t lp_total_duration;
319 * How often was the MLP problem solved
321 unsigned int mlp_solved;
324 * total duration of all mlp solver executions
326 uint64_t mlp_total_duration;
328 /* Information about the problem */
330 struct ATS_Peer *peer_head;
331 struct ATS_Peer *peer_tail;
336 * Address specific MLP information
338 struct MLP_information
344 /* bandwidth column index */
347 /* address usage column */
352 /* constraint 1: bandwidth capping */
355 /* constraint 3: minimum bandwidth */
358 /* Quality information row indices */
359 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
361 /* Quality information */
362 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
364 /* Quality information averaged */
365 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
367 /* Averaging index */
368 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
372 * Solves the MLP problem
374 * @param solver the MLP Handle
375 * @param addresses the address hashmap
376 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
379 GAS_mlp_solve_problem (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses);
383 * Init the MLP problem solving component
385 * @param cfg configuration handle
386 * @param stats the GNUNET_STATISTICS handle
387 * @param network array of GNUNET_ATS_NetworkType with length dest_length
388 * @param out_dest array of outbound quotas
389 * @param in_dest array of outbound quota
390 * @param dest_length array length for quota arrays
391 * @param bw_changed_cb callback for changed bandwidth amounts
392 * @param bw_changed_cb_cls cls for callback
393 * @return struct GAS_MLP_Handle on success, NULL on fail
396 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
397 const struct GNUNET_STATISTICS_Handle *stats,
399 unsigned long long *out_dest,
400 unsigned long long *in_dest,
402 GAS_bandwidth_changed_cb bw_changed_cb,
403 void *bw_changed_cb_cls);
407 * Add a single address to the solve
409 * @param solver the solver Handle
410 * @param addresses the address hashmap containing all addresses
411 * @param address the address to add
414 GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
417 * Updates a single address in the MLP problem
419 * If the address did not exist before in the problem:
420 * The MLP problem has to be recreated and the problem has to be resolved
422 * Otherwise the addresses' values can be updated and the existing base can
425 * @param solver the solver Handle
426 * @param addresses the address hashmap containing all addresses
427 * @param address the update address
428 * @param session the new session (if changed otherwise current)
429 * @param in_use the new address in use state (if changed otherwise current)
430 * @param atsi the latest ATS information
431 * @param atsi_count the atsi count
434 GAS_mlp_address_update (void *solver,
435 struct GNUNET_CONTAINER_MultiHashMap *addresses,
436 struct ATS_Address *address,
439 const struct GNUNET_ATS_Information *atsi,
440 uint32_t atsi_count);
444 * Deletes a single address in the MLP problem
446 * The MLP problem has to be recreated and the problem has to be resolved
448 * @param solver the MLP Handle
449 * @param addresses the address hashmap
450 * the address has to be already removed from the hashmap
451 * @param address the address to delete
452 * @param session_only delete only session not whole address
455 GAS_mlp_address_delete (void *solver,
456 struct GNUNET_CONTAINER_MultiHashMap *addresses,
457 struct ATS_Address *address,
462 * Changes the preferences for a peer in the MLP problem
464 * @param solver the MLP Handle
465 * @param client client
466 * @param peer the peer
467 * @param kind the kind to change the preference
468 * @param score the score
471 GAS_mlp_address_change_preference (void *solver,
473 const struct GNUNET_PeerIdentity *peer,
474 enum GNUNET_ATS_PreferenceKind kind,
479 * Get the preferred address for a specific peer
481 * @param solver the MLP Handle
482 * @param addresses address hashmap
483 * @param peer the peer
484 * @return suggested address
486 const struct ATS_Address *
487 GAS_mlp_get_preferred_address (void *solver,
488 struct GNUNET_CONTAINER_MultiHashMap * addresses,
489 const struct GNUNET_PeerIdentity *peer);
492 * Shutdown the MLP problem solving component
494 * @param solver the solver handle
497 GAS_mlp_done (void *solver);
500 /* end of gnunet-service-ats_addresses_mlp.h */