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
57 struct GNUNET_PeerIdentity id;
59 /* Was this peer already added to the current problem? */
62 /* constraint 2: 1 address per peer*/
65 /* constraint 9: relativity */
68 /* Legacy preference value */
72 /* Array of quality preferences */
73 double f_q[GNUNET_ATS_QualityPropertiesCount];
78 struct GAS_MLP_SolutionContext
82 struct GNUNET_TIME_Relative lp_duration;
83 struct GNUNET_TIME_Relative mlp_duration;
91 * GLPK (MLP) problem object
98 /* Number of addresses in problem */
99 unsigned int num_addresses;
100 /* Number of peers in problem */
101 unsigned int num_peers;
102 /* Number of elements in problem matrix */
103 unsigned int num_elements;
105 /* Row index constraint 2: */
107 /* Row index constraint 4: minimum connections */
109 /* Row index constraint 6: maximize diversity */
111 /* Row index constraint 8: utilization*/
113 /* Row index constraint 9: relativity*/
115 /* Row indices quality metrics */
116 int r_q[GNUNET_ATS_QualityPropertiesCount];
117 /* Row indices ATS network quotas */
118 int r_quota[GNUNET_ATS_NetworkTypeCount];
120 /* Column index Diversity (D) column */
122 /* Column index Utilization (U) column */
124 /* Column index Proportionality (R) column */
126 /* Column index quality metrics */
127 int c_q[GNUNET_ATS_QualityPropertiesCount];
128 /* column index ressource costs */
129 int c_rc[GNUNET_ATS_QualityPropertiesCount];
130 /* Column indices ATS network quotas */
131 int c_quota[GNUNET_ATS_NetworkTypeCount];
136 /* Row index array */
138 /* Column index array */
140 /* Column index value */
146 /* Big M value for bandwidth capping */
149 /* ATS Quality metrics
151 * Array with GNUNET_ATS_QualityPropertiesCount elements
152 * contains mapping to GNUNET_ATS_Property*/
153 int q[GNUNET_ATS_QualityPropertiesCount];
155 /* Number of quality metrics */
158 /* Number of quality metrics */
161 /* Quality metric coefficients*/
162 double co_Q[GNUNET_ATS_QualityPropertiesCount];
164 /* Ressource costs coefficients*/
165 double co_RC[GNUNET_ATS_QualityPropertiesCount];
167 /* Diversity coefficient */
170 /* Utility coefficient */
173 /* Relativity coefficient */
176 /* Minimum bandwidth assigned to an address */
179 /* Minimum number of addresses with bandwidth assigned */
183 /* Array mapping array index to ATS network */
184 int quota_index [GNUNET_ATS_NetworkTypeCount];
185 /* Outbound quotas */
186 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
189 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
191 /* ATS ressource costs
192 * array with GNUNET_ATS_QualityPropertiesCount elements
193 * contains mapping to GNUNET_ATS_Property
195 int rc[GNUNET_ATS_QualityPropertiesCount];
203 struct GAS_MLP_Handle
208 struct GNUNET_STATISTICS_Handle *stats;
211 * Addresses' bandwidth changed callback
213 GAS_bandwidth_changed_cb bw_changed_cb;
216 * Addresses' bandwidth changed callback closure
218 void *bw_changed_cb_cls;
220 struct MLP_Problem p;
222 struct MLP_Variables pv;
225 * GLPK LP control parameter
228 glp_smcp control_param_lp;
230 void *control_param_lp;
234 * GLPK LP control parameter
237 glp_iocp control_param_mlp;
239 void *control_param_mlp;
243 * Peers with pending address requests
245 struct GNUNET_CONTAINER_MultiHashMap *peers;
248 * Was the problem updated since last solution
250 int mlp_prob_updated;
253 * Has the problem size changed since last solution
255 int mlp_prob_changed;
259 * Solve the problem automatically when updates occur?
260 * Default: GNUNET_YES
261 * Can be disabled for test and measurements
268 * Interval between scheduled problem solving
270 struct GNUNET_TIME_Relative exec_interval;
273 * Maximum execution time per problem solving
275 struct GNUNET_TIME_Relative max_exec_duration;
278 * Maximum number of LP iterations per problem solving
280 unsigned int max_iterations;
284 * Is a solution attemp running?
288 /* state information */
291 * Do we need to use the LP presolver?
293 * If the problem addresses were added or removed and the last basis was we
294 * need to use the presolver.
295 * presolver_required == GNUNET_YES
297 * If values were modified, we can reuse a valid basis
298 * presolver_required == GNUNET_NO
300 int presolver_required;
305 * Time of last execution
307 struct GNUNET_TIME_Absolute last_execution;
311 * How often was the LP problem solved
313 unsigned int lp_solved;
316 * total duration of all lp solver executions
318 uint64_t lp_total_duration;
321 * How often was the MLP problem solved
323 unsigned int mlp_solved;
326 * total duration of all mlp solver executions
328 uint64_t mlp_total_duration;
330 /* Information about the problem */
332 struct ATS_Peer *peer_head;
333 struct ATS_Peer *peer_tail;
339 * Address specific MLP information
341 struct MLP_information
347 /* bandwidth column index */
350 /* address usage column */
355 /* constraint 1: bandwidth capping */
358 /* constraint 3: minimum bandwidth */
361 /* Quality information row indices */
362 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
364 /* Quality information */
365 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
367 /* Quality information averaged */
368 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
370 /* Averaging index */
371 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
375 * Solves the MLP problem
377 * @param solver the MLP Handle
378 * @param addresses the address hashmap
379 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
382 GAS_mlp_solve_problem (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses);
386 * Init the MLP problem solving component
388 * @param cfg configuration handle
389 * @param stats the GNUNET_STATISTICS handle
390 * @param network array of GNUNET_ATS_NetworkType with length dest_length
391 * @param out_dest array of outbound quotas
392 * @param in_dest array of outbound quota
393 * @param dest_length array length for quota arrays
394 * @param bw_changed_cb callback for changed bandwidth amounts
395 * @param bw_changed_cb_cls cls for callback
396 * @return struct GAS_MLP_Handle on success, NULL on fail
399 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
400 const struct GNUNET_STATISTICS_Handle *stats,
402 unsigned long long *out_dest,
403 unsigned long long *in_dest,
405 GAS_bandwidth_changed_cb bw_changed_cb,
406 void *bw_changed_cb_cls);
410 * Add a single address to the solve
412 * @param solver the solver Handle
413 * @param addresses the address hashmap containing all addresses
414 * @param address the address to add
417 GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
420 * Updates a single address in the MLP problem
422 * If the address did not exist before in the problem:
423 * The MLP problem has to be recreated and the problem has to be resolved
425 * Otherwise the addresses' values can be updated and the existing base can
428 * @param solver the solver Handle
429 * @param addresses the address hashmap containing all addresses
430 * @param address the update address
431 * @param session the new session (if changed otherwise current)
432 * @param in_use the new address in use state (if changed otherwise current)
433 * @param atsi the latest ATS information
434 * @param atsi_count the atsi count
437 GAS_mlp_address_update (void *solver,
438 struct GNUNET_CONTAINER_MultiHashMap *addresses,
439 struct ATS_Address *address,
442 const struct GNUNET_ATS_Information *atsi,
443 uint32_t atsi_count);
447 * Deletes a single address in the MLP problem
449 * The MLP problem has to be recreated and the problem has to be resolved
451 * @param solver the MLP Handle
452 * @param addresses the address hashmap
453 * the address has to be already removed from the hashmap
454 * @param address the address to delete
455 * @param session_only delete only session not whole address
458 GAS_mlp_address_delete (void *solver,
459 struct GNUNET_CONTAINER_MultiHashMap *addresses,
460 struct ATS_Address *address,
465 * Changes the preferences for a peer in the MLP problem
467 * @param solver the MLP Handle
468 * @param client client
469 * @param peer the peer
470 * @param kind the kind to change the preference
471 * @param score the score
474 GAS_mlp_address_change_preference (void *solver,
476 const struct GNUNET_PeerIdentity *peer,
477 enum GNUNET_ATS_PreferenceKind kind,
482 * Get the preferred address for a specific peer
484 * @param solver the MLP Handle
485 * @param addresses address hashmap
486 * @param peer the peer
487 * @return suggested address
489 const struct ATS_Address *
490 GAS_mlp_get_preferred_address (void *solver,
491 struct GNUNET_CONTAINER_MultiHashMap * addresses,
492 const struct GNUNET_PeerIdentity *peer);
495 * Shutdown the MLP problem solving component
497 * @param solver the solver handle
500 GAS_mlp_done (void *solver);
503 /* end of gnunet-service-ats_addresses_mlp.h */