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 all MILP problems to a MPS file
322 int dump_problem_all;
325 * Write all MILP problem solutions to a file
327 int dump_solution_all;
330 * Write MILP problems to a MPS file when solver fails
332 int dump_problem_on_fail;
335 * Write MILP problem solutions to a file when solver fails
337 int dump_solution_on_fail;
342 * Address specific MLP information
344 struct MLP_information
347 /* Bandwidth assigned */
348 struct GNUNET_BANDWIDTH_Value32NBO b_out;
349 struct GNUNET_BANDWIDTH_Value32NBO b_in;
351 /* Address selected */
354 /* bandwidth column index */
357 /* address usage column */
362 /* constraint 1: bandwidth capping */
365 /* constraint 3: minimum bandwidth */
371 * Solves the MLP problem
373 * @param solver the MLP Handle
374 * @return #GNUNET_OK if could be solved, GNUNET_SYSERR on failure
377 GAS_mlp_solve_problem (void *solver);
381 * Init the MLP problem solving component
383 * @param cfg the GNUNET_CONFIGURATION_Handle handle
384 * @param stats the GNUNET_STATISTICS handle
385 * @param addresses Hashmap containing addresses
386 * @param network array of GNUNET_ATS_NetworkType with length dest_length
387 * @param out_dest array of outbound quotas
388 * @param in_dest array of outbound quota
389 * @param dest_length array length for quota arrays
390 * @param bw_changed_cb callback for changed bandwidth amounts
391 * @param bw_changed_cb_cls cls for callback
392 * @param get_preference callback to get relative preferences for a peer
393 * @param get_preference_cls cls for callback to get relative preferences for a peer
394 * @param get_properties callback to get relative properties
395 * @param get_properties_cls cls for callback to get relative properties
396 * @return struct GAS_MLP_Handle on success, NULL on fail
399 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
400 const struct GNUNET_STATISTICS_Handle *stats,
401 const struct GNUNET_CONTAINER_MultiPeerMap *addresses,
403 unsigned long long *out_dest,
404 unsigned long long *in_dest,
406 GAS_bandwidth_changed_cb bw_changed_cb,
407 void *bw_changed_cb_cls,
408 GAS_get_preferences get_preference,
409 void *get_preference_cls,
410 GAS_get_properties get_properties,
411 void *get_properties_cls);
415 * Add a single address within a network to the solver
417 * @param solver the solver Handle
418 * @param address the address to add
419 * @param network network type of this address
422 GAS_mlp_address_add (void *solver, struct ATS_Address *address,
427 * Transport properties for this address have changed
429 * @param solver solver handle
430 * @param address the address
431 * @param type the ATSI type in HBO
432 * @param abs_value the absolute value of the property
433 * @param rel_value the normalized value
436 GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address,
437 uint32_t type, uint32_t abs_value, double rel_value);
441 * Transport session for this address has changed
443 * NOTE: values in addresses are already updated
445 * @param solver solver handle
446 * @param address the address
447 * @param cur_session the current session
448 * @param new_session the new session
451 GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address,
452 uint32_t cur_session, uint32_t new_session);
456 * Usage for this address has changed
458 * NOTE: values in addresses are already updated
460 * @param solver solver handle
461 * @param address the address
462 * @param in_use usage state
465 GAS_mlp_address_inuse_changed (void *solver, struct ATS_Address *address,
469 * Network scope for this address has changed
471 * NOTE: values in addresses are already updated
473 * @param solver solver handle
474 * @param address the address
475 * @param current_network the current network
476 * @param new_network the new network
479 GAS_mlp_address_change_network (void *solver, struct ATS_Address *address,
480 uint32_t current_network, uint32_t new_network);
483 * Deletes a single address in the MLP problem
485 * The MLP problem has to be recreated and the problem has to be resolved
487 * @param solver the MLP Handle
488 * @param address the address to delete
489 * @param session_only delete only session not whole address
492 GAS_mlp_address_delete (void *solver, struct ATS_Address *address,
496 * Changes the preferences for a peer in the MLP problem
498 * @param solver the MLP Handle
499 * @param peer the peer
500 * @param kind the kind to change the preference
501 * @param pref_rel the relative score
504 GAS_mlp_address_change_preference (void *solver,
505 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
509 * Get application feedback for a peer
511 * @param solver the solver handle
512 * @param application the application
513 * @param peer the peer to change the preference for
514 * @param scope the time interval for this feedback: [now - scope .. now]
515 * @param kind the kind to change the preference
516 * @param score the score
519 GAS_mlp_address_preference_feedback (void *solver, void *application,
520 const struct GNUNET_PeerIdentity *peer,
521 const struct GNUNET_TIME_Relative scope,
522 enum GNUNET_ATS_PreferenceKind kind, double score);
525 * Start a bulk operation
527 * @param solver the solver
530 GAS_mlp_bulk_start (void *solver);
533 * Bulk operation done
536 GAS_mlp_bulk_stop (void *solver);
539 * Get the preferred address for a specific peer until
540 * GAS_mlp_stop_get_preferred_address is called
542 * @param solver the MLP Handle
543 * @param peer the peer
544 * @return suggested address
546 const struct ATS_Address *
547 GAS_mlp_get_preferred_address (void *solver,
548 const struct GNUNET_PeerIdentity *peer);
551 * Stop notifying about address and bandwidth changes for this peer
553 * @param solver the MLP handle
554 * @param peer the peer
557 GAS_mlp_stop_get_preferred_address (void *solver,
558 const struct GNUNET_PeerIdentity *peer);
561 * Shutdown the MLP problem solving component
563 * @param solver the solver handle
566 GAS_mlp_done (void *solver);
569 /* end of plugin_ats_mlp.h */