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-solver_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, 10)
43 #define MLP_MAX_ITERATIONS 4096
48 #define DEFAULT_QUALITY 1.0
49 #define DEFAULT_MIN_CONNECTIONS 4
50 #define DEFAULT_PEER_PREFERENCE 1.0
53 #define MLP_UNDEFINED 0
60 struct GNUNET_TIME_Relative build_dur;
61 struct GNUNET_TIME_Relative lp_dur;
62 struct GNUNET_TIME_Relative mip_dur;
80 struct GNUNET_PeerIdentity id;
82 /* Was this peer already added to the current problem? */
85 /* constraint 2: 1 address per peer*/
88 /* constraint 9: relativity */
91 /* Legacy preference value */
100 * GLPK (MLP) problem object
108 /* Number of addresses in problem */
109 unsigned int num_addresses;
110 /* Number of peers in problem */
111 unsigned int num_peers;
112 /* Number of elements in problem matrix */
113 unsigned int num_elements;
115 /* Row index constraint 2: */
117 /* Row index constraint 4: minimum connections */
119 /* Row index constraint 6: maximize diversity */
121 /* Row index constraint 8: utilization*/
123 /* Row index constraint 9: relativity*/
125 /* Row indices quality metrics */
126 int r_q[GNUNET_ATS_QualityPropertiesCount];
127 /* Row indices ATS network quotas */
128 int r_quota[GNUNET_ATS_NetworkTypeCount];
130 /* Column index Diversity (D) column */
132 /* Column index Utilization (U) column */
134 /* Column index Proportionality (R) column */
136 /* Column index quality metrics */
137 int c_q[GNUNET_ATS_QualityPropertiesCount];
142 /* Row index array */
144 /* Column index array */
146 /* Column index value */
153 /* Big M value for bandwidth capping */
156 /* ATS Quality metrics
158 * Array with GNUNET_ATS_QualityPropertiesCount elements
159 * contains mapping to GNUNET_ATS_Property*/
160 int q[GNUNET_ATS_QualityPropertiesCount];
162 /* Number of quality metrics */
165 /* Number of quality metrics */
168 /* Quality metric coefficients*/
169 double co_Q[GNUNET_ATS_QualityPropertiesCount];
171 /* Ressource costs coefficients*/
172 double co_RC[GNUNET_ATS_QualityPropertiesCount];
174 /* Diversity coefficient */
177 /* Utility coefficient */
180 /* Relativity coefficient */
183 /* Minimum bandwidth assigned to an address */
186 /* Minimum number of addresses with bandwidth assigned */
190 /* Array mapping array index to ATS network */
191 int quota_index [GNUNET_ATS_NetworkTypeCount];
192 /* Outbound quotas */
193 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
196 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
198 /* ATS ressource costs
199 * array with GNUNET_ATS_QualityPropertiesCount elements
200 * contains mapping to GNUNET_ATS_Property
202 int rc[GNUNET_ATS_QualityPropertiesCount];
210 struct GAS_MLP_Handle
215 struct GNUNET_STATISTICS_Handle *stats;
218 * Address hashmap for lookups
220 const struct GNUNET_CONTAINER_MultiHashMap *addresses;
223 * Addresses' bandwidth changed callback
225 GAS_bandwidth_changed_cb bw_changed_cb;
228 * Addresses' bandwidth changed callback closure
230 void *bw_changed_cb_cls;
235 * ATS function to get preferences
237 GAS_get_preferences get_preferences;
240 * Closure for ATS function to get preferences
242 void *get_preferences_cls;
245 * ATS function to get properties
247 GAS_get_properties get_properties;
250 * Closure for ATS function to get properties
252 void *get_properties_cls;
254 struct MLP_Problem p;
256 struct MLP_Variables pv;
258 struct MLP_Solution ps;
267 * Number of changes while solver was locked
272 * GLPK LP control parameter
275 glp_smcp control_param_lp;
277 void *control_param_lp;
281 * GLPK LP control parameter
284 glp_iocp control_param_mlp;
286 void *control_param_mlp;
290 * Peers with pending address requests
292 struct GNUNET_CONTAINER_MultiHashMap *requested_peers;
295 * Was the problem updated since last solution
297 int mlp_prob_updated;
300 * Has the problem size changed since last solution
302 int mlp_prob_changed;
305 * Solve the problem automatically when updates occur?
306 * Default: GNUNET_YES
307 * Can be disabled for test and measurements
312 * Write MILP problem to a MPS file
317 * Write MILP problem to a MPS file
325 * Address specific MLP information
327 struct MLP_information
330 /* Bandwidth assigned */
331 struct GNUNET_BANDWIDTH_Value32NBO b_out;
332 struct GNUNET_BANDWIDTH_Value32NBO b_in;
334 /* Address selected */
337 /* bandwidth column index */
340 /* address usage column */
345 /* constraint 1: bandwidth capping */
348 /* constraint 3: minimum bandwidth */
351 /* Quality information row indices */
352 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
354 /* Quality information */
355 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
357 /* Quality information averaged */
358 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
360 /* Averaging index */
361 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
365 * Solves the MLP problem
367 * @param solver the MLP Handle
368 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
371 GAS_mlp_solve_problem (void *solver);
375 * Init the MLP problem solving component
377 * @param cfg the GNUNET_CONFIGURATION_Handle handle
378 * @param stats the GNUNET_STATISTICS handle
379 * @param network array of GNUNET_ATS_NetworkType with length dest_length
380 * @param out_dest array of outbound quotas
381 * @param in_dest array of outbound quota
382 * @param dest_length array length for quota arrays
383 * @param bw_changed_cb callback for changed bandwidth amounts
384 * @param bw_changed_cb_cls cls for callback
385 * @param get_preference callback to get relative preferences for a peer
386 * @param get_preference_cls cls for callback to get relative preferences
387 * @return struct GAS_MLP_Handle on success, NULL on fail
390 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
391 const struct GNUNET_STATISTICS_Handle *stats,
392 const struct GNUNET_CONTAINER_MultiHashMap *addresses,
394 unsigned long long *out_dest,
395 unsigned long long *in_dest,
397 GAS_bandwidth_changed_cb bw_changed_cb,
398 void *bw_changed_cb_cls,
399 GAS_get_preferences get_preference,
400 void *get_preference_cls,
401 GAS_get_properties get_properties,
402 void *get_properties_cls);
406 * Add a single address within a network to the solver
408 * @param solver the solver Handle
409 * @param addresses the address hashmap containing all addresses
410 * @param address the address to add
411 * @param network network type of this address
414 GAS_mlp_address_add (void *solver,
415 struct ATS_Address *address,
419 * Updates a single address in the MLP problem
421 * If the address did not exist before in the problem:
422 * The MLP problem has to be recreated and the problem has to be resolved
424 * ATS performance information in address are already updated, delta + previous
425 * values are included in atsi_prev (value GNUNET_ATS_VALUE_UNDEFINED if not existing before)
427 * Otherwise the addresses' values can be updated and the existing base can
430 * @param solver the solver Handle
431 * @param addresses the address hashmap containing all addresses
432 * @param address the update address
433 * @param prev_session the new session (if changed otherwise current)
434 * @param prev_in_use the new address in use state (if changed otherwise current)
435 * @param prev_atsi ATS information updated + previous values, GNUNET_ATS_VALUE_UNDEFINED if not existing before
436 * @param prev_atsi_count number of atsi values updated
439 GAS_mlp_address_update (void *solver,
440 struct ATS_Address *address,
441 uint32_t prev_session,
443 const struct GNUNET_ATS_Information *prev_atsi,
444 uint32_t prev_atsi_count);
448 * Deletes a single address in the MLP problem
450 * The MLP problem has to be recreated and the problem has to be resolved
452 * @param solver the MLP Handle
453 * @param addresses the address hashmap
454 * the address has to be already removed from the hashmap
455 * @param address the address to delete
456 * @param session_only delete only session not whole address
459 GAS_mlp_address_delete (void *solver,
460 struct ATS_Address *address,
465 * Changes the preferences for a peer in the MLP problem
467 * @param solver the MLP Handle
468 * @param addresses the address hashmap
469 * @param peer the peer
470 * @param kind the kind to change the preference
471 * @param pref_rel the relative score
474 GAS_mlp_address_change_preference (void *solver,
475 const struct GNUNET_PeerIdentity *peer,
476 enum GNUNET_ATS_PreferenceKind kind,
481 * Start a bulk operation
483 * @param solver the solver
486 GAS_mlp_bulk_start (void *solver);
490 * Bulk operation done
493 GAS_mlp_bulk_stop (void *solver);
497 * Get the preferred address for a specific peer
499 * @param solver the MLP Handle
500 * @param addresses address hashmap
501 * @param peer the peer
502 * @return suggested address
504 const struct ATS_Address *
505 GAS_mlp_get_preferred_address (void *solver,
506 const struct GNUNET_PeerIdentity *peer);
510 * Stop notifying about address and bandwidth changes for this peer
512 * @param solver the MLP handle
513 * @param addresses address hashmap
514 * @param peer the peer
518 GAS_mlp_stop_get_preferred_address (void *solver,
519 const struct GNUNET_PeerIdentity *peer);
523 * Shutdown the MLP problem solving component
525 * @param solver the solver handle
528 GAS_mlp_done (void *solver);
531 /* end of gnunet-service-ats_addresses_mlp.h */