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 INT_MAX
47 struct ATS_Peer *next;
48 struct ATS_Peer *prev;
50 struct GNUNET_PeerIdentity id;
52 /* Array of quality preferences */
53 double f_q[GNUNET_ATS_QualityPropertiesCount];
54 /* Legacy preference value */
57 /* constraint 2: 1 address per peer*/
60 /* constraint 9: relativity */
63 struct ATS_Address *head;
64 struct ATS_Address *tail;
67 struct GAS_MLP_SolutionContext
71 struct GNUNET_TIME_Relative lp_duration;
72 struct GNUNET_TIME_Relative mlp_duration;
83 struct GNUNET_STATISTICS_Handle *stats;
86 * GLPK (MLP) problem object
97 * GLPK LP control parameter
100 glp_smcp control_param_lp;
102 void *control_param_lp;
106 * GLPK LP control parameter
109 glp_iocp control_param_mlp;
111 void *control_param_mlp;
115 * Solves the task in an regular interval
117 GNUNET_SCHEDULER_TaskIdentifier mlp_task;
120 * Interval between scheduled problem solving
122 struct GNUNET_TIME_Relative exec_interval;
125 * Maximum execution time per problem solving
127 struct GNUNET_TIME_Relative max_exec_duration;
130 * Maximum number of LP iterations per problem solving
132 unsigned int max_iterations;
135 * Solve the problem automatically when updates occur?
136 * Default: GNUNET_YES
137 * Can be disabled for test and measurements
143 /* state information */
146 * Do we need to use the LP presolver?
148 * If the problem addresses were added or removed and the last basis was we
149 * need to use the presolver.
150 * presolver_required == GNUNET_YES
152 * If values were modified, we can reuse a valid basis
153 * presolver_required == GNUNET_NO
155 int presolver_required;
160 * Time of last execution
162 struct GNUNET_TIME_Absolute last_execution;
166 * How often was the LP problem solved
168 unsigned int lp_solved;
171 * total duration of all lp solver executions
173 uint64_t lp_total_duration;
176 * How often was the MLP problem solved
178 unsigned int mlp_solved;
181 * total duration of all mlp solver executions
183 uint64_t mlp_total_duration;
185 unsigned int addr_in_problem;
187 /* Information about the problem */
189 struct ATS_Peer *peer_head;
190 struct ATS_Peer *peer_tail;
192 /* Number of peers */
195 /* current problem matrix */
196 /* row index array */
198 /* column index array */
200 /* column index array */
202 /* current size of the constraint matrix |indices| */
203 unsigned int cm_size;
206 /* Row index constraint 2: */
208 /* Row index constraint 4: minimum connections */
210 /* Row index constraint 6: maximize diversity */
212 /* Row index constraint 8: utilization*/
214 /* Row index constraint 9: relativity*/
217 /* column index Diversity (D) column */
221 /* column index Utilization (U) column */
225 /* column index Proportionality (R) column */
229 /* ATS Quality metrics
231 * array with GNUNET_ATS_QualityPropertiesCount elements
232 * contains mapping to GNUNET_ATS_Property*/
233 int q[GNUNET_ATS_QualityPropertiesCount];
235 /* column index quality metrics */
236 int c_q[GNUNET_ATS_QualityPropertiesCount];
238 /* column index quality metrics */
239 int r_q[GNUNET_ATS_QualityPropertiesCount];
241 /* quality metric coefficients*/
242 double co_Q[GNUNET_ATS_QualityPropertiesCount];
244 /* number of quality metrics */
247 /* ATS network quotas */
248 int c_quota[GNUNET_ATS_NetworkTypeCount];
249 int r_quota[GNUNET_ATS_NetworkTypeCount];
250 int quota_index [GNUNET_ATS_NetworkTypeCount];
251 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
252 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
254 /* ATS ressource costs
256 * array with GNUNET_ATS_QualityPropertiesCount elements
257 * contains mapping to GNUNET_ATS_Property*/
258 int rc[GNUNET_ATS_QualityPropertiesCount];
260 /* column index ressource costs */
261 int c_rc[GNUNET_ATS_QualityPropertiesCount];
263 /* ressource costs coefficients*/
264 double co_RC[GNUNET_ATS_QualityPropertiesCount];
266 /* number of quality metrics */
269 /* minimum bandwidth assigned to an address */
272 /* minimum number of addresses with bandwidth assigned */
278 * Address specific MLP information
280 struct MLP_information
286 /* bandwidth column index */
289 /* address usage column */
294 /* constraint 1: bandwidth capping */
297 /* constraint 3: minimum bandwidth */
300 /* Quality information row indices */
301 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
303 /* Quality information */
304 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
306 /* Quality information averaged */
307 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
309 /* Averaging index */
310 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
315 * Init the MLP problem solving component
317 * @param cfg configuration handle
318 * @param stats the GNUNET_STATISTICS handle
319 * @param bw_changed_cb callback to call when assigned changes
320 * @return struct GAS_MLP_Handle on success, NULL on fail
323 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
324 const struct GNUNET_STATISTICS_Handle *stats,
326 unsigned long long *out_dest,
327 unsigned long long *in_dest,
329 GAS_bandwidth_changed_cb bw_changed_cb);
333 * Add a single address to the solve
335 * @param solver the solver Handle
336 * @param addresses the address hashmap containing all addresses
337 * @param address the address to add
340 GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
343 * Updates a single address in the MLP problem
345 * If the address did not exist before in the problem:
346 * The MLP problem has to be recreated and the problem has to be resolved
348 * Otherwise the addresses' values can be updated and the existing base can
351 * @param solver the MLP Handle
352 * @param addresses the address hashmap
353 * the address has to be already added from the hashmap
354 * @param address the address to update
357 GAS_mlp_address_update (void *solver,
358 struct GNUNET_CONTAINER_MultiHashMap * addresses,
359 struct ATS_Address *address);
363 * Deletes a single address in the MLP problem
365 * The MLP problem has to be recreated and the problem has to be resolved
367 * @param solver the MLP Handle
368 * @param addresses the address hashmap
369 * the address has to be already removed from the hashmap
370 * @param address the address to delete
371 * @param session_only delete only session not whole address
374 GAS_mlp_address_delete (void *solver,
375 struct GNUNET_CONTAINER_MultiHashMap *addresses,
376 struct ATS_Address *address,
381 * Changes the preferences for a peer in the MLP problem
383 * @param solver the MLP Handle
384 * @param peer the peer
385 * @param kind the kind to change the preference
386 * @param score the score
389 GAS_mlp_address_change_preference (void *solver,
390 const struct GNUNET_PeerIdentity *peer,
391 enum GNUNET_ATS_PreferenceKind kind,
396 * Get the preferred address for a specific peer
398 * @param solver the MLP Handle
399 * @param addresses address hashmap
400 * @param peer the peer
401 * @return suggested address
403 const struct ATS_Address *
404 GAS_mlp_get_preferred_address (void *solver,
405 struct GNUNET_CONTAINER_MultiHashMap * addresses,
406 const struct GNUNET_PeerIdentity *peer);
409 * Shutdown the MLP problem solving component
411 * @param solver the solver handle
414 GAS_mlp_done (void *solver);
417 /* end of gnunet-service-ats_addresses_mlp.h */