2 (C) 2011 Christian Grothoff (and other contributing authors)
4 GNUnet is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3, or (at your
7 option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GNUnet; see the file COPYING. If not, write to the
16 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
21 * @file ats/plugin_ats_mlp.h
22 * @brief ats MLP problem solver
23 * @author Matthias Wachs
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_ats_service.h"
29 #include "gnunet_ats_plugin.h"
30 #include "gnunet-service-ats_addresses.h"
31 #include "gnunet_statistics_service.h"
36 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
37 #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
39 #define BIG_M_VALUE (UINT32_MAX) /10
40 #define BIG_M_STRING "unlimited"
42 #define MLP_AVERAGING_QUEUE_LENGTH 3
44 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
45 #define MLP_MAX_ITERATIONS 4096
50 #define DEFAULT_QUALITY 1.0
51 #define DEFAULT_MIN_CONNECTIONS 4
52 #define DEFAULT_PEER_PREFERENCE 1.0
55 #define MLP_UNDEFINED 0
77 struct GNUNET_PeerIdentity id;
79 /* Was this peer already added to the current problem? */
82 /* constraint 2: 1 address per peer*/
85 /* constraint 9: relativity */
88 /* Legacy preference value */
95 * GLPK (MLP) problem object
103 /* Number of addresses in problem */
104 unsigned int num_addresses;
105 /* Number of peers in problem */
106 unsigned int num_peers;
107 /* Number of elements in problem matrix */
108 unsigned int num_elements;
110 /* Row index constraint 2: */
112 /* Row index constraint 4: minimum connections */
114 /* Row index constraint 6: maximize diversity */
116 /* Row index constraint 8: utilization*/
118 /* Row index constraint 9: relativity*/
120 /* Row indices quality metrics */
121 int r_q[GNUNET_ATS_QualityPropertiesCount];
122 /* Row indices ATS network quotas */
123 int r_quota[GNUNET_ATS_NetworkTypeCount];
125 /* Column index Diversity (D) column */
127 /* Column index Utilization (U) column */
129 /* Column index Proportionality (R) column */
131 /* Column index quality metrics */
132 int c_q[GNUNET_ATS_QualityPropertiesCount];
137 /* Row index array */
139 /* Column index array */
141 /* Column index value */
148 /* Big M value for bandwidth capping */
151 /* ATS Quality metrics
153 * Array with GNUNET_ATS_QualityPropertiesCount elements
154 * contains mapping to GNUNET_ATS_Property*/
155 int q[GNUNET_ATS_QualityPropertiesCount];
157 /* Number of quality metrics */
160 /* Number of quality metrics */
163 /* Quality metric coefficients*/
164 double co_Q[GNUNET_ATS_QualityPropertiesCount];
166 /* Ressource costs coefficients*/
167 double co_RC[GNUNET_ATS_QualityPropertiesCount];
169 /* Diversity coefficient */
172 /* Utility coefficient */
175 /* Relativity coefficient */
178 /* Minimum bandwidth assigned to an address */
181 /* Minimum number of addresses with bandwidth assigned */
185 /* Array mapping array index to ATS network */
186 int quota_index[GNUNET_ATS_NetworkTypeCount];
187 /* Outbound quotas */
188 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
191 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
193 /* ATS ressource costs
194 * array with GNUNET_ATS_QualityPropertiesCount elements
195 * contains mapping to GNUNET_ATS_Property
197 int rc[GNUNET_ATS_QualityPropertiesCount];
204 struct GAS_MLP_Handle
206 struct GNUNET_ATS_PluginEnvironment *env;
211 struct GNUNET_STATISTICS_Handle *stats;
214 * Address hashmap for lookups
216 const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
219 * Addresses' bandwidth changed callback
221 GAS_bandwidth_changed_cb bw_changed_cb;
224 * Addresses' bandwidth changed callback closure
226 void *bw_changed_cb_cls;
229 * ATS function to get preferences
231 GAS_get_preferences get_preferences;
234 * Closure for ATS function to get preferences
236 void *get_preferences_cls;
239 * ATS function to get properties
241 GAS_get_properties get_properties;
244 * Closure for ATS function to get properties
246 void *get_properties_cls;
249 * Exclude peer from next result propagation
251 const struct GNUNET_PeerIdentity *exclude_peer;
254 * Encapsulation for the MLP problem
256 struct MLP_Problem p;
259 * Encapsulation for the MLP problem variables
261 struct MLP_Variables pv;
264 * Encapsulation for the MLP solution
266 struct MLP_Solution ps;
275 * Number of changes while solver was locked
280 * GLPK LP control parameter
283 glp_smcp control_param_lp;
285 void *control_param_lp;
289 * GLPK LP control parameter
292 glp_iocp control_param_mlp;
294 void *control_param_mlp;
298 * Peers with pending address requests
300 struct GNUNET_CONTAINER_MultiPeerMap *requested_peers;
303 * Was the problem updated since last solution
305 int mlp_prob_updated;
308 * Has the problem size changed since last solution
310 int mlp_prob_changed;
313 * Solve the problem automatically when updates occur?
314 * Default: GNUNET_YES
315 * Can be disabled for test and measurements
320 * Write MILP problem to a MPS file
325 * Write MILP problem to a MPS file
332 * Address specific MLP information
334 struct MLP_information
337 /* Bandwidth assigned */
338 struct GNUNET_BANDWIDTH_Value32NBO b_out;
339 struct GNUNET_BANDWIDTH_Value32NBO b_in;
341 /* Address selected */
344 /* bandwidth column index */
347 /* address usage column */
352 /* constraint 1: bandwidth capping */
355 /* constraint 3: minimum bandwidth */
361 * Solves the MLP problem
363 * @param solver the MLP Handle
364 * @return #GNUNET_OK if could be solved, GNUNET_SYSERR on failure
367 GAS_mlp_solve_problem (void *solver);
371 * Init the MLP problem solving component
373 * @param cfg the GNUNET_CONFIGURATION_Handle handle
374 * @param stats the GNUNET_STATISTICS handle
375 * @param addresses Hashmap containing addresses
376 * @param network array of GNUNET_ATS_NetworkType with length dest_length
377 * @param out_dest array of outbound quotas
378 * @param in_dest array of outbound quota
379 * @param dest_length array length for quota arrays
380 * @param bw_changed_cb callback for changed bandwidth amounts
381 * @param bw_changed_cb_cls cls for callback
382 * @param get_preference callback to get relative preferences for a peer
383 * @param get_preference_cls cls for callback to get relative preferences for a peer
384 * @param get_properties callback to get relative properties
385 * @param get_properties_cls cls for callback to get relative properties
386 * @return struct GAS_MLP_Handle on success, NULL on fail
389 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
390 const struct GNUNET_STATISTICS_Handle *stats,
391 const struct GNUNET_CONTAINER_MultiPeerMap *addresses,
393 unsigned long long *out_dest,
394 unsigned long long *in_dest,
396 GAS_bandwidth_changed_cb bw_changed_cb,
397 void *bw_changed_cb_cls,
398 GAS_get_preferences get_preference,
399 void *get_preference_cls,
400 GAS_get_properties get_properties,
401 void *get_properties_cls);
405 * Add a single address within a network to the solver
407 * @param solver the solver Handle
408 * @param address the address to add
409 * @param network network type of this address
412 GAS_mlp_address_add (void *solver, struct ATS_Address *address,
417 * Transport properties for this address have changed
419 * @param solver solver handle
420 * @param address the address
421 * @param type the ATSI type in HBO
422 * @param abs_value the absolute value of the property
423 * @param rel_value the normalized value
426 GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address,
427 uint32_t type, uint32_t abs_value, double rel_value);
431 * Transport session for this address has changed
433 * NOTE: values in addresses are already updated
435 * @param solver solver handle
436 * @param address the address
437 * @param cur_session the current session
438 * @param new_session the new session
441 GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address,
442 uint32_t cur_session, uint32_t new_session);
446 * Usage for this address has changed
448 * NOTE: values in addresses are already updated
450 * @param solver solver handle
451 * @param address the address
452 * @param in_use usage state
455 GAS_mlp_address_inuse_changed (void *solver, struct ATS_Address *address,
459 * Network scope for this address has changed
461 * NOTE: values in addresses are already updated
463 * @param solver solver handle
464 * @param address the address
465 * @param current_network the current network
466 * @param new_network the new network
469 GAS_mlp_address_change_network (void *solver, struct ATS_Address *address,
470 uint32_t current_network, uint32_t new_network);
473 * Deletes a single address in the MLP problem
475 * The MLP problem has to be recreated and the problem has to be resolved
477 * @param solver the MLP Handle
478 * @param address the address to delete
479 * @param session_only delete only session not whole address
482 GAS_mlp_address_delete (void *solver, struct ATS_Address *address,
486 * Changes the preferences for a peer in the MLP problem
488 * @param solver the MLP Handle
489 * @param peer the peer
490 * @param kind the kind to change the preference
491 * @param pref_rel the relative score
494 GAS_mlp_address_change_preference (void *solver,
495 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
499 * Get application feedback for a peer
501 * @param solver the solver handle
502 * @param application the application
503 * @param peer the peer to change the preference for
504 * @param scope the time interval for this feedback: [now - scope .. now]
505 * @param kind the kind to change the preference
506 * @param score the score
509 GAS_mlp_address_preference_feedback (void *solver, void *application,
510 const struct GNUNET_PeerIdentity *peer,
511 const struct GNUNET_TIME_Relative scope,
512 enum GNUNET_ATS_PreferenceKind kind, double score);
515 * Start a bulk operation
517 * @param solver the solver
520 GAS_mlp_bulk_start (void *solver);
523 * Bulk operation done
526 GAS_mlp_bulk_stop (void *solver);
529 * Get the preferred address for a specific peer until
530 * GAS_mlp_stop_get_preferred_address is called
532 * @param solver the MLP Handle
533 * @param peer the peer
534 * @return suggested address
536 const struct ATS_Address *
537 GAS_mlp_get_preferred_address (void *solver,
538 const struct GNUNET_PeerIdentity *peer);
541 * Stop notifying about address and bandwidth changes for this peer
543 * @param solver the MLP handle
544 * @param peer the peer
547 GAS_mlp_stop_get_preferred_address (void *solver,
548 const struct GNUNET_PeerIdentity *peer);
551 * Shutdown the MLP problem solving component
553 * @param solver the solver handle
556 GAS_mlp_done (void *solver);
559 /* end of plugin_ats_mlp.h */