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 */
353 * Solves the MLP problem
355 * @param solver the MLP Handle
356 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
359 GAS_mlp_solve_problem (void *solver);
363 * Init the MLP problem solving component
365 * @param cfg the GNUNET_CONFIGURATION_Handle handle
366 * @param stats the GNUNET_STATISTICS handle
367 * @param network array of GNUNET_ATS_NetworkType with length dest_length
368 * @param out_dest array of outbound quotas
369 * @param in_dest array of outbound quota
370 * @param dest_length array length for quota arrays
371 * @param bw_changed_cb callback for changed bandwidth amounts
372 * @param bw_changed_cb_cls cls for callback
373 * @param get_preference callback to get relative preferences for a peer
374 * @param get_preference_cls cls for callback to get relative preferences
375 * @return struct GAS_MLP_Handle on success, NULL on fail
378 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
379 const struct GNUNET_STATISTICS_Handle *stats,
380 const struct GNUNET_CONTAINER_MultiHashMap *addresses,
382 unsigned long long *out_dest,
383 unsigned long long *in_dest,
385 GAS_bandwidth_changed_cb bw_changed_cb,
386 void *bw_changed_cb_cls,
387 GAS_get_preferences get_preference,
388 void *get_preference_cls,
389 GAS_get_properties get_properties,
390 void *get_properties_cls);
394 * Add a single address within a network to the solver
396 * @param solver the solver Handle
397 * @param addresses the address hashmap containing all addresses
398 * @param address the address to add
399 * @param network network type of this address
402 GAS_mlp_address_add (void *solver,
403 struct ATS_Address *address,
407 GAS_mlp_address_property_changed (void *solver,
408 struct ATS_Address *address,
415 GAS_mlp_address_session_changed (void *solver,
416 struct ATS_Address *address,
417 uint32_t cur_session,
418 uint32_t new_session);
421 GAS_mlp_address_inuse_changed (void *solver,
422 struct ATS_Address *address,
427 GAS_mlp_address_change_network (void *solver,
428 struct ATS_Address *address,
429 uint32_t current_network,
430 uint32_t new_network);
433 * Deletes a single address in the MLP problem
435 * The MLP problem has to be recreated and the problem has to be resolved
437 * @param solver the MLP Handle
438 * @param addresses the address hashmap
439 * the address has to be already removed from the hashmap
440 * @param address the address to delete
441 * @param session_only delete only session not whole address
444 GAS_mlp_address_delete (void *solver,
445 struct ATS_Address *address,
450 * Changes the preferences for a peer in the MLP problem
452 * @param solver the MLP Handle
453 * @param addresses the address hashmap
454 * @param peer the peer
455 * @param kind the kind to change the preference
456 * @param pref_rel the relative score
459 GAS_mlp_address_change_preference (void *solver,
460 const struct GNUNET_PeerIdentity *peer,
461 enum GNUNET_ATS_PreferenceKind kind,
466 * Start a bulk operation
468 * @param solver the solver
471 GAS_mlp_bulk_start (void *solver);
475 * Bulk operation done
478 GAS_mlp_bulk_stop (void *solver);
482 * Get the preferred address for a specific peer
484 * @param solver the MLP Handle
485 * @param addresses address hashmap
486 * @param peer the peer
487 * @return suggested address
489 const struct ATS_Address *
490 GAS_mlp_get_preferred_address (void *solver,
491 const struct GNUNET_PeerIdentity *peer);
495 * Stop notifying about address and bandwidth changes for this peer
497 * @param solver the MLP handle
498 * @param addresses address hashmap
499 * @param peer the peer
503 GAS_mlp_stop_get_preferred_address (void *solver,
504 const struct GNUNET_PeerIdentity *peer);
508 * Shutdown the MLP problem solving component
510 * @param solver the solver handle
513 GAS_mlp_done (void *solver);
516 /* end of gnunet-service-ats_addresses_mlp.h */