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, 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 */
95 /* Array of quality preferences */
96 double f_q[GNUNET_ATS_QualityPropertiesCount];
106 * GLPK (MLP) problem object
113 /* Number of addresses in problem */
114 unsigned int num_addresses;
115 /* Number of peers in problem */
116 unsigned int num_peers;
117 /* Number of elements in problem matrix */
118 unsigned int num_elements;
120 /* Row index constraint 2: */
122 /* Row index constraint 4: minimum connections */
124 /* Row index constraint 6: maximize diversity */
126 /* Row index constraint 8: utilization*/
128 /* Row index constraint 9: relativity*/
130 /* Row indices quality metrics */
131 int r_q[GNUNET_ATS_QualityPropertiesCount];
132 /* Row indices ATS network quotas */
133 int r_quota[GNUNET_ATS_NetworkTypeCount];
135 /* Column index Diversity (D) column */
137 /* Column index Utilization (U) column */
139 /* Column index Proportionality (R) column */
141 /* Column index quality metrics */
142 int c_q[GNUNET_ATS_QualityPropertiesCount];
147 /* Row index array */
149 /* Column index array */
151 /* Column index value */
157 /* Big M value for bandwidth capping */
160 /* ATS Quality metrics
162 * Array with GNUNET_ATS_QualityPropertiesCount elements
163 * contains mapping to GNUNET_ATS_Property*/
164 int q[GNUNET_ATS_QualityPropertiesCount];
166 /* Number of quality metrics */
169 /* Number of quality metrics */
172 /* Quality metric coefficients*/
173 double co_Q[GNUNET_ATS_QualityPropertiesCount];
175 /* Ressource costs coefficients*/
176 double co_RC[GNUNET_ATS_QualityPropertiesCount];
178 /* Diversity coefficient */
181 /* Utility coefficient */
184 /* Relativity coefficient */
187 /* Minimum bandwidth assigned to an address */
190 /* Minimum number of addresses with bandwidth assigned */
194 /* Array mapping array index to ATS network */
195 int quota_index [GNUNET_ATS_NetworkTypeCount];
196 /* Outbound quotas */
197 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
200 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
202 /* ATS ressource costs
203 * array with GNUNET_ATS_QualityPropertiesCount elements
204 * contains mapping to GNUNET_ATS_Property
206 int rc[GNUNET_ATS_QualityPropertiesCount];
214 struct GAS_MLP_Handle
219 struct GNUNET_STATISTICS_Handle *stats;
222 * Addresses' bandwidth changed callback
224 GAS_bandwidth_changed_cb bw_changed_cb;
227 * Addresses' bandwidth changed callback closure
229 void *bw_changed_cb_cls;
231 struct MLP_Problem p;
233 struct MLP_Variables pv;
235 struct MLP_Solution ps;
238 * GLPK LP control parameter
241 glp_smcp control_param_lp;
243 void *control_param_lp;
247 * GLPK LP control parameter
250 glp_iocp control_param_mlp;
252 void *control_param_mlp;
256 * Peers with pending address requests
258 struct GNUNET_CONTAINER_MultiHashMap *peers;
261 * Was the problem updated since last solution
263 int mlp_prob_updated;
266 * Has the problem size changed since last solution
268 int mlp_prob_changed;
271 * Solve the problem automatically when updates occur?
272 * Default: GNUNET_YES
273 * Can be disabled for test and measurements
278 * Write MILP problem to a MPS file
283 * Write MILP problem to a MPS file
291 * Address specific MLP information
293 struct MLP_information
296 /* Bandwidth assigned */
297 struct GNUNET_BANDWIDTH_Value32NBO b_out;
298 struct GNUNET_BANDWIDTH_Value32NBO b_in;
300 /* Address selected */
303 /* bandwidth column index */
306 /* address usage column */
311 /* constraint 1: bandwidth capping */
314 /* constraint 3: minimum bandwidth */
317 /* Quality information row indices */
318 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
320 /* Quality information */
321 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
323 /* Quality information averaged */
324 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
326 /* Averaging index */
327 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
331 * Solves the MLP problem
333 * @param solver the MLP Handle
334 * @param addresses the address hashmap
335 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
338 GAS_mlp_solve_problem (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses);
342 * Init the MLP problem solving component
344 * @param cfg configuration handle
345 * @param stats the GNUNET_STATISTICS handle
346 * @param network array of GNUNET_ATS_NetworkType with length dest_length
347 * @param out_dest array of outbound quotas
348 * @param in_dest array of outbound quota
349 * @param dest_length array length for quota arrays
350 * @param bw_changed_cb callback for changed bandwidth amounts
351 * @param bw_changed_cb_cls cls for callback
352 * @return struct GAS_MLP_Handle on success, NULL on fail
355 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
356 const struct GNUNET_STATISTICS_Handle *stats,
358 unsigned long long *out_dest,
359 unsigned long long *in_dest,
361 GAS_bandwidth_changed_cb bw_changed_cb,
362 void *bw_changed_cb_cls);
366 * Add a single address within a network to the solver
368 * @param solver the solver Handle
369 * @param addresses the address hashmap containing all addresses
370 * @param address the address to add
371 * @param network network type of this address
374 GAS_mlp_address_add (void *solver,
375 struct GNUNET_CONTAINER_MultiHashMap *addresses,
376 struct ATS_Address *address,
380 * Updates a single address in the MLP problem
382 * If the address did not exist before in the problem:
383 * The MLP problem has to be recreated and the problem has to be resolved
385 * ATS performance information in address are already updated, delta + previous
386 * values are included in atsi_prev (value GNUNET_ATS_VALUE_UNDEFINED if not existing before)
388 * Otherwise the addresses' values can be updated and the existing base can
391 * @param solver the solver Handle
392 * @param addresses the address hashmap containing all addresses
393 * @param address the update address
394 * @param session the new session (if changed otherwise current)
395 * @param in_use the new address in use state (if changed otherwise current)
396 * @param atsi_prev ATS information updated + previous values, GNUNET_ATS_VALUE_UNDEFINED if not existing before
397 * @param atsi_count_prev number of atsi values updated
400 GAS_mlp_address_update (void *solver,
401 struct GNUNET_CONTAINER_MultiHashMap *addresses,
402 struct ATS_Address *address,
405 const struct GNUNET_ATS_Information *atsi_prev,
406 uint32_t atsi_count_prev);
410 * Deletes a single address in the MLP problem
412 * The MLP problem has to be recreated and the problem has to be resolved
414 * @param solver the MLP Handle
415 * @param addresses the address hashmap
416 * the address has to be already removed from the hashmap
417 * @param address the address to delete
418 * @param session_only delete only session not whole address
421 GAS_mlp_address_delete (void *solver,
422 struct GNUNET_CONTAINER_MultiHashMap *addresses,
423 struct ATS_Address *address,
428 * Changes the preferences for a peer in the MLP problem
430 * @param solver the MLP Handle
431 * @param client client
432 * @param peer the peer
433 * @param kind the kind to change the preference
434 * @param score the score
437 GAS_mlp_address_change_preference (void *solver,
439 const struct GNUNET_PeerIdentity *peer,
440 enum GNUNET_ATS_PreferenceKind kind,
445 * Get the preferred address for a specific peer
447 * @param solver the MLP Handle
448 * @param addresses address hashmap
449 * @param peer the peer
450 * @return suggested address
452 const struct ATS_Address *
453 GAS_mlp_get_preferred_address (void *solver,
454 struct GNUNET_CONTAINER_MultiHashMap * addresses,
455 const struct GNUNET_PeerIdentity *peer);
459 * Stop notifying about address and bandwidth changes for this peer
461 * @param solver the MLP handle
462 * @param addresses address hashmap
463 * @param peer the peer
467 GAS_mlp_stop_get_preferred_address (void *solver,
468 struct GNUNET_CONTAINER_MultiHashMap *addresses,
469 const struct GNUNET_PeerIdentity *peer);
473 * Shutdown the MLP problem solving component
475 * @param solver the solver handle
478 GAS_mlp_done (void *solver);
481 /* end of gnunet-service-ats_addresses_mlp.h */