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 ATS_PreferedAddress
69 uint32_t bandwidth_out;
70 uint32_t bandwidth_in;
71 struct ATS_Address *address;
74 struct GAS_MLP_SolutionContext
78 struct GNUNET_TIME_Relative lp_duration;
79 struct GNUNET_TIME_Relative mlp_duration;
90 struct GNUNET_STATISTICS_Handle *stats;
93 * GLPK (MLP) problem object
104 * GLPK LP control parameter
106 glp_smcp control_param_lp;
109 * GLPK LP control parameter
111 glp_iocp control_param_mlp;
114 * Solves the task in an regular interval
116 GNUNET_SCHEDULER_TaskIdentifier mlp_task;
119 * Interval between scheduled problem solving
121 struct GNUNET_TIME_Relative exec_interval;
124 * Maximum execution time per problem solving
126 struct GNUNET_TIME_Relative max_exec_duration;
129 * Maximum number of LP iterations per problem solving
131 unsigned int max_iterations;
134 * Solve the problem automatically when updates occur?
135 * Default: GNUNET_YES
136 * Can be disabled for test and measurements
142 /* state information */
145 * Do we need to use the LP presolver?
147 * If the problem addresses were added or removed and the last basis was we
148 * need to use the presolver.
149 * presolver_required == GNUNET_YES
151 * If values were modified, we can reuse a valid basis
152 * presolver_required == GNUNET_NO
154 int presolver_required;
159 * Time of last execution
161 struct GNUNET_TIME_Absolute last_execution;
165 * How often was the LP problem solved
167 unsigned int lp_solved;
170 * total duration of all lp solver executions
172 uint64_t lp_total_duration;
175 * How often was the MLP problem solved
177 unsigned int mlp_solved;
180 * total duration of all mlp solver executions
182 uint64_t mlp_total_duration;
184 unsigned int addr_in_problem;
186 /* Information about the problem */
188 struct ATS_Peer *peer_head;
189 struct ATS_Peer *peer_tail;
191 /* Number of peers */
194 /* current problem matrix */
195 /* row index array */
197 /* column index array */
199 /* column index array */
201 /* current size of the constraint matrix |indices| */
202 unsigned int cm_size;
205 /* Row index constraint 2: */
207 /* Row index constraint 4: minimum connections */
209 /* Row index constraint 6: maximize diversity */
211 /* Row index constraint 8: utilization*/
213 /* Row index constraint 9: relativity*/
216 /* column index Diversity (D) column */
220 /* column index Utilization (U) column */
224 /* column index Proportionality (R) column */
228 /* ATS Quality metrics
230 * array with GNUNET_ATS_QualityPropertiesCount elements
231 * contains mapping to GNUNET_ATS_Property*/
232 int q[GNUNET_ATS_QualityPropertiesCount];
234 /* column index quality metrics */
235 int c_q[GNUNET_ATS_QualityPropertiesCount];
237 /* column index quality metrics */
238 int r_q[GNUNET_ATS_QualityPropertiesCount];
240 /* quality metric coefficients*/
241 double co_Q[GNUNET_ATS_QualityPropertiesCount];
243 /* number of quality metrics */
246 /* ATS network quotas */
247 int c_quota[GNUNET_ATS_NetworkTypeCount];
248 int r_quota[GNUNET_ATS_NetworkTypeCount];
249 int quota_index [GNUNET_ATS_NetworkTypeCount];
250 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
251 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
253 /* ATS ressource costs
255 * array with GNUNET_ATS_QualityPropertiesCount elements
256 * contains mapping to GNUNET_ATS_Property*/
257 int rc[GNUNET_ATS_QualityPropertiesCount];
259 /* column index ressource costs */
260 int c_rc[GNUNET_ATS_QualityPropertiesCount];
262 /* ressource costs coefficients*/
263 double co_RC[GNUNET_ATS_QualityPropertiesCount];
265 /* number of quality metrics */
268 /* minimum bandwidth assigned to an address */
271 /* minimum number of addresses with bandwidth assigned */
277 * Address specific MLP information
279 struct MLP_information
285 /* bandwidth column index */
288 /* address usage column */
293 /* constraint 1: bandwidth capping */
296 /* constraint 3: minimum bandwidth */
299 /* Quality information row indices */
300 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
302 /* Quality information */
303 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
305 /* Quality information averaged */
306 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
308 /* Averaging index */
309 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
314 * Init the MLP problem solving component
316 * @param cfg configuration handle
317 * @param stats the GNUNET_STATISTICS handle
318 * @return struct GAS_MLP_Handle on success, NULL on fail
321 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
322 const struct GNUNET_STATISTICS_Handle *stats,
324 unsigned long long *out_dest, unsigned long long *in_dest, int dest_length);
328 * Updates a single address in the MLP problem
330 * If the address did not exist before in the problem:
331 * The MLP problem has to be recreated and the problem has to be resolved
333 * Otherwise the addresses' values can be updated and the existing base can
336 * @param solver the MLP Handle
337 * @param addresses the address hashmap
338 * the address has to be already added from the hashmap
339 * @param address the address to update
342 GAS_mlp_address_update (void *solver,
343 struct GNUNET_CONTAINER_MultiHashMap * addresses,
344 struct ATS_Address *address);
348 * Deletes a single address in the MLP problem
350 * The MLP problem has to be recreated and the problem has to be resolved
352 * @param solver the MLP Handle
353 * @param addresses the address hashmap
354 * the address has to be already removed from the hashmap
355 * @param address the address to delete
358 GAS_mlp_address_delete (void *solver,
359 struct GNUNET_CONTAINER_MultiHashMap *addresses,
360 struct ATS_Address *address);
364 * Changes the preferences for a peer in the MLP problem
366 * @param solver the MLP Handle
367 * @param peer the peer
368 * @param kind the kind to change the preference
369 * @param score the score
372 GAS_mlp_address_change_preference (void *solver,
373 const struct GNUNET_PeerIdentity *peer,
374 enum GNUNET_ATS_PreferenceKind kind,
379 * Get the preferred address for a specific peer
381 * @param solver the MLP Handle
382 * @param addresses address hashmap
383 * @param peer the peer
384 * @return suggested address
387 GAS_mlp_get_preferred_address (void *solver,
388 struct GNUNET_CONTAINER_MultiHashMap * addresses,
389 const struct GNUNET_PeerIdentity *peer);
392 * Shutdown the MLP problem solving component
394 * @param solver the solver handle
397 GAS_mlp_done (void *solver);
400 /* end of gnunet-service-ats_addresses_mlp.h */