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;
91 struct GNUNET_STATISTICS_Handle *stats;
94 * Addresses' bandwidth changed callback
96 GAS_bandwidth_changed_cb bw_changed_cb;
99 * Addresses' bandwidth changed callback closure
101 void *bw_changed_cb_cls;
104 * GLPK (MLP) problem object
115 * GLPK LP control parameter
118 glp_smcp control_param_lp;
120 void *control_param_lp;
124 * GLPK LP control parameter
127 glp_iocp control_param_mlp;
129 void *control_param_mlp;
133 * Solves the task in an regular interval
135 GNUNET_SCHEDULER_TaskIdentifier mlp_task;
138 * Interval between scheduled problem solving
140 struct GNUNET_TIME_Relative exec_interval;
143 * Maximum execution time per problem solving
145 struct GNUNET_TIME_Relative max_exec_duration;
148 * Maximum number of LP iterations per problem solving
150 unsigned int max_iterations;
153 * Solve the problem automatically when updates occur?
154 * Default: GNUNET_YES
155 * Can be disabled for test and measurements
160 * Is a solution attemp running?
164 /* state information */
167 * Do we need to use the LP presolver?
169 * If the problem addresses were added or removed and the last basis was we
170 * need to use the presolver.
171 * presolver_required == GNUNET_YES
173 * If values were modified, we can reuse a valid basis
174 * presolver_required == GNUNET_NO
176 int presolver_required;
181 * Time of last execution
183 struct GNUNET_TIME_Absolute last_execution;
187 * How often was the LP problem solved
189 unsigned int lp_solved;
192 * total duration of all lp solver executions
194 uint64_t lp_total_duration;
197 * How often was the MLP problem solved
199 unsigned int mlp_solved;
202 * total duration of all mlp solver executions
204 uint64_t mlp_total_duration;
206 unsigned int addr_in_problem;
208 /* Information about the problem */
210 struct ATS_Peer *peer_head;
211 struct ATS_Peer *peer_tail;
213 /* Number of peers */
216 /* current problem matrix */
217 /* row index array */
219 /* column index array */
221 /* column index array */
223 /* current size of the constraint matrix |indices| */
224 unsigned int cm_size;
227 /* Row index constraint 2: */
229 /* Row index constraint 4: minimum connections */
231 /* Row index constraint 6: maximize diversity */
233 /* Row index constraint 8: utilization*/
235 /* Row index constraint 9: relativity*/
238 /* column index Diversity (D) column */
242 /* column index Utilization (U) column */
246 /* column index Proportionality (R) column */
250 /* ATS Quality metrics
252 * array with GNUNET_ATS_QualityPropertiesCount elements
253 * contains mapping to GNUNET_ATS_Property*/
254 int q[GNUNET_ATS_QualityPropertiesCount];
256 /* column index quality metrics */
257 int c_q[GNUNET_ATS_QualityPropertiesCount];
259 /* column index quality metrics */
260 int r_q[GNUNET_ATS_QualityPropertiesCount];
262 /* quality metric coefficients*/
263 double co_Q[GNUNET_ATS_QualityPropertiesCount];
265 /* number of quality metrics */
268 /* ATS network quotas */
269 int c_quota[GNUNET_ATS_NetworkTypeCount];
270 int r_quota[GNUNET_ATS_NetworkTypeCount];
271 int quota_index [GNUNET_ATS_NetworkTypeCount];
272 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
273 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
275 /* ATS ressource costs
277 * array with GNUNET_ATS_QualityPropertiesCount elements
278 * contains mapping to GNUNET_ATS_Property*/
279 int rc[GNUNET_ATS_QualityPropertiesCount];
281 /* column index ressource costs */
282 int c_rc[GNUNET_ATS_QualityPropertiesCount];
284 /* ressource costs coefficients*/
285 double co_RC[GNUNET_ATS_QualityPropertiesCount];
287 /* number of quality metrics */
290 /* minimum bandwidth assigned to an address */
293 /* minimum number of addresses with bandwidth assigned */
299 * Address specific MLP information
301 struct MLP_information
307 /* bandwidth column index */
310 /* address usage column */
315 /* constraint 1: bandwidth capping */
318 /* constraint 3: minimum bandwidth */
321 /* Quality information row indices */
322 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
324 /* Quality information */
325 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
327 /* Quality information averaged */
328 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
330 /* Averaging index */
331 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
336 * Init the MLP problem solving component
338 * @param cfg configuration handle
339 * @param stats the GNUNET_STATISTICS handle
340 * @param network array of GNUNET_ATS_NetworkType with length dest_length
341 * @param out_dest array of outbound quotas
342 * @param in_dest array of outbound quota
343 * @param dest_length array length for quota arrays
344 * @param bw_changed_cb callback for changed bandwidth amounts
345 * @param bw_changed_cb_cls cls for callback
346 * @return struct GAS_MLP_Handle on success, NULL on fail
349 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
350 const struct GNUNET_STATISTICS_Handle *stats,
352 unsigned long long *out_dest,
353 unsigned long long *in_dest,
355 GAS_bandwidth_changed_cb bw_changed_cb,
356 void *bw_changed_cb_cls);
360 * Add a single address to the solve
362 * @param solver the solver Handle
363 * @param addresses the address hashmap containing all addresses
364 * @param address the address to add
367 GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
370 * Updates a single address in the MLP problem
372 * If the address did not exist before in the problem:
373 * The MLP problem has to be recreated and the problem has to be resolved
375 * Otherwise the addresses' values can be updated and the existing base can
378 * @param solver the solver Handle
379 * @param addresses the address hashmap containing all addresses
380 * @param address the update address
381 * @param session the new session (if changed otherwise current)
382 * @param in_use the new address in use state (if changed otherwise current)
383 * @param atsi the latest ATS information
384 * @param atsi_count the atsi count
387 GAS_mlp_address_update (void *solver,
388 struct GNUNET_CONTAINER_MultiHashMap *addresses,
389 struct ATS_Address *address,
392 const struct GNUNET_ATS_Information *atsi,
393 uint32_t atsi_count);
397 * Deletes a single address in the MLP problem
399 * The MLP problem has to be recreated and the problem has to be resolved
401 * @param solver the MLP Handle
402 * @param addresses the address hashmap
403 * the address has to be already removed from the hashmap
404 * @param address the address to delete
405 * @param session_only delete only session not whole address
408 GAS_mlp_address_delete (void *solver,
409 struct GNUNET_CONTAINER_MultiHashMap *addresses,
410 struct ATS_Address *address,
415 * Changes the preferences for a peer in the MLP problem
417 * @param solver the MLP Handle
418 * @param client client
419 * @param peer the peer
420 * @param kind the kind to change the preference
421 * @param score the score
424 GAS_mlp_address_change_preference (void *solver,
426 const struct GNUNET_PeerIdentity *peer,
427 enum GNUNET_ATS_PreferenceKind kind,
432 * Get the preferred address for a specific peer
434 * @param solver the MLP Handle
435 * @param addresses address hashmap
436 * @param peer the peer
437 * @return suggested address
439 const struct ATS_Address *
440 GAS_mlp_get_preferred_address (void *solver,
441 struct GNUNET_CONTAINER_MultiHashMap * addresses,
442 const struct GNUNET_PeerIdentity *peer);
445 * Shutdown the MLP problem solving component
447 * @param solver the solver handle
450 GAS_mlp_done (void *solver);
453 /* end of gnunet-service-ats_addresses_mlp.h */