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/gnunet-service-ats-solver_mlp.h
22 * @brief ats MLP problem solver
23 * @author Matthias Wachs
24 * @author Christian Grothoff
27 #include "gnunet_statistics_service.h"
28 #include "gnunet-service-ats_addresses.h"
33 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
34 #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
36 #define BIG_M_VALUE (UINT32_MAX) /10
37 #define BIG_M_STRING "unlimited"
39 #define MLP_AVERAGING_QUEUE_LENGTH 3
41 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
42 #define MLP_MAX_ITERATIONS 4096
47 #define DEFAULT_QUALITY 1.0
48 #define DEFAULT_MIN_CONNECTIONS 4
49 #define DEFAULT_PEER_PREFERENCE 1.0
52 #define MLP_UNDEFINED 0
58 struct GNUNET_TIME_Relative build_dur;
59 struct GNUNET_TIME_Relative lp_dur;
60 struct GNUNET_TIME_Relative mip_dur;
78 struct GNUNET_PeerIdentity id;
80 /* Was this peer already added to the current problem? */
83 /* constraint 2: 1 address per peer*/
86 /* constraint 9: relativity */
89 /* Legacy preference value */
96 * GLPK (MLP) problem object
104 /* Number of addresses in problem */
105 unsigned int num_addresses;
106 /* Number of peers in problem */
107 unsigned int num_peers;
108 /* Number of elements in problem matrix */
109 unsigned int num_elements;
111 /* Row index constraint 2: */
113 /* Row index constraint 4: minimum connections */
115 /* Row index constraint 6: maximize diversity */
117 /* Row index constraint 8: utilization*/
119 /* Row index constraint 9: relativity*/
121 /* Row indices quality metrics */
122 int r_q[GNUNET_ATS_QualityPropertiesCount];
123 /* Row indices ATS network quotas */
124 int r_quota[GNUNET_ATS_NetworkTypeCount];
126 /* Column index Diversity (D) column */
128 /* Column index Utilization (U) column */
130 /* Column index Proportionality (R) column */
132 /* Column index quality metrics */
133 int c_q[GNUNET_ATS_QualityPropertiesCount];
138 /* Row index array */
140 /* Column index array */
142 /* Column index value */
149 /* Big M value for bandwidth capping */
152 /* ATS Quality metrics
154 * Array with GNUNET_ATS_QualityPropertiesCount elements
155 * contains mapping to GNUNET_ATS_Property*/
156 int q[GNUNET_ATS_QualityPropertiesCount];
158 /* Number of quality metrics */
161 /* Number of quality metrics */
164 /* Quality metric coefficients*/
165 double co_Q[GNUNET_ATS_QualityPropertiesCount];
167 /* Ressource costs coefficients*/
168 double co_RC[GNUNET_ATS_QualityPropertiesCount];
170 /* Diversity coefficient */
173 /* Utility coefficient */
176 /* Relativity coefficient */
179 /* Minimum bandwidth assigned to an address */
182 /* Minimum number of addresses with bandwidth assigned */
186 /* Array mapping array index to ATS network */
187 int quota_index[GNUNET_ATS_NetworkTypeCount];
188 /* Outbound quotas */
189 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
192 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
194 /* ATS ressource costs
195 * array with GNUNET_ATS_QualityPropertiesCount elements
196 * contains mapping to GNUNET_ATS_Property
198 int rc[GNUNET_ATS_QualityPropertiesCount];
205 struct GAS_MLP_Handle
210 struct GNUNET_STATISTICS_Handle *stats;
213 * Address hashmap for lookups
215 const struct GNUNET_CONTAINER_MultiHashMap *addresses;
218 * Addresses' bandwidth changed callback
220 GAS_bandwidth_changed_cb bw_changed_cb;
223 * Addresses' bandwidth changed callback closure
225 void *bw_changed_cb_cls;
228 * ATS function to get preferences
230 GAS_get_preferences get_preferences;
233 * Closure for ATS function to get preferences
235 void *get_preferences_cls;
238 * ATS function to get properties
240 GAS_get_properties get_properties;
243 * Closure for ATS function to get properties
245 void *get_properties_cls;
248 * Exclude peer from next result propagation
250 const struct GNUNET_PeerIdentity *exclude_peer;
253 * Encapsulation for the MLP problem
255 struct MLP_Problem p;
258 * Encapsulation for the MLP problem variables
260 struct MLP_Variables pv;
263 * Encapsulation for the MLP solution
265 struct MLP_Solution ps;
274 * Number of changes while solver was locked
279 * GLPK LP control parameter
282 glp_smcp control_param_lp;
284 void *control_param_lp;
288 * GLPK LP control parameter
291 glp_iocp control_param_mlp;
293 void *control_param_mlp;
297 * Peers with pending address requests
299 struct GNUNET_CONTAINER_MultiHashMap *requested_peers;
302 * Was the problem updated since last solution
304 int mlp_prob_updated;
307 * Has the problem size changed since last solution
309 int mlp_prob_changed;
312 * Solve the problem automatically when updates occur?
313 * Default: GNUNET_YES
314 * Can be disabled for test and measurements
319 * Write MILP problem to a MPS file
324 * Write MILP problem to a MPS file
331 * Address specific MLP information
333 struct MLP_information
336 /* Bandwidth assigned */
337 struct GNUNET_BANDWIDTH_Value32NBO b_out;
338 struct GNUNET_BANDWIDTH_Value32NBO b_in;
340 /* Address selected */
343 /* bandwidth column index */
346 /* address usage column */
351 /* constraint 1: bandwidth capping */
354 /* constraint 3: minimum bandwidth */
359 * Solves the MLP problem
361 * @param solver the MLP Handle
362 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
365 GAS_mlp_solve_problem (void *solver);
368 * Init the MLP problem solving component
370 * @param cfg the GNUNET_CONFIGURATION_Handle handle
371 * @param stats the GNUNET_STATISTICS handle
372 * @param network array of GNUNET_ATS_NetworkType with length dest_length
373 * @param out_dest array of outbound quotas
374 * @param in_dest array of outbound quota
375 * @param dest_length array length for quota arrays
376 * @param bw_changed_cb callback for changed bandwidth amounts
377 * @param bw_changed_cb_cls cls for callback
378 * @param get_preference callback to get relative preferences for a peer
379 * @param get_preference callback to get relative preferences for a peer
380 * @param get_properties_cls for callback to get relative properties
381 * @param get_properties_cls cls for callback to get relative properties
382 * @return struct GAS_MLP_Handle on success, NULL on fail
385 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
386 const struct GNUNET_STATISTICS_Handle *stats,
387 const struct GNUNET_CONTAINER_MultiHashMap *addresses, int *network,
388 unsigned long long *out_dest, unsigned long long *in_dest, int dest_length,
389 GAS_bandwidth_changed_cb bw_changed_cb, void *bw_changed_cb_cls,
390 GAS_get_preferences get_preference, void *get_preference_cls,
391 GAS_get_properties get_properties, void *get_properties_cls);
394 * Add a single address within a network to the solver
396 * @param solver the solver Handle
397 * @param address the address to add
398 * @param network network type of this address
401 GAS_mlp_address_add (void *solver, struct ATS_Address *address,
405 * Transport properties for this address have changed
407 * @param solver solver handle
408 * @param address the address
409 * @param type the ATSI type in HBO
410 * @param abs_value the absolute value of the property
411 * @param rel_value the normalized value
414 GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address,
415 uint32_t type, uint32_t abs_value, double rel_value);
418 * Transport session for this address has changed
420 * NOTE: values in addresses are already updated
422 * @param solver solver handle
423 * @param address the address
424 * @param cur_session the current session
425 * @param new_session the new session
428 GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address,
429 uint32_t cur_session, uint32_t new_session);
432 * Usage for this address has changed
434 * NOTE: values in addresses are already updated
436 * @param solver solver handle
437 * @param address the address
438 * @param in_use usage state
441 GAS_mlp_address_inuse_changed (void *solver, struct ATS_Address *address,
445 * Network scope for this address has changed
447 * NOTE: values in addresses are already updated
449 * @param solver solver handle
450 * @param address the address
451 * @param current_network the current network
452 * @param new_network the new network
455 GAS_mlp_address_change_network (void *solver, struct ATS_Address *address,
456 uint32_t current_network, uint32_t new_network);
459 * Deletes a single address in the MLP problem
461 * The MLP problem has to be recreated and the problem has to be resolved
463 * @param solver the MLP Handle
464 * @param address the address to delete
465 * @param session_only delete only session not whole address
468 GAS_mlp_address_delete (void *solver, struct ATS_Address *address,
472 * Changes the preferences for a peer in the MLP problem
474 * @param solver the MLP Handle
475 * @param peer the peer
476 * @param kind the kind to change the preference
477 * @param pref_rel the relative score
480 GAS_mlp_address_change_preference (void *solver,
481 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
485 * Get application feedback for a peer
487 * @param solver the solver handle
488 * @param application the application
489 * @param peer the peer to change the preference for
490 * @param scope the time interval for this feedback: [now - scope .. now]
491 * @param kind the kind to change the preference
492 * @param score the score
495 GAS_mlp_address_preference_feedback (void *solver, void *application,
496 const struct GNUNET_PeerIdentity *peer,
497 const struct GNUNET_TIME_Relative scope,
498 enum GNUNET_ATS_PreferenceKind kind, double score);
501 * Start a bulk operation
503 * @param solver the solver
506 GAS_mlp_bulk_start (void *solver);
509 * Bulk operation done
512 GAS_mlp_bulk_stop (void *solver);
515 * Get the preferred address for a specific peer until
516 * GAS_mlp_stop_get_preferred_address is called
518 * @param solver the MLP Handle
519 * @param peer the peer
520 * @return suggested address
522 const struct ATS_Address *
523 GAS_mlp_get_preferred_address (void *solver,
524 const struct GNUNET_PeerIdentity *peer);
527 * Stop notifying about address and bandwidth changes for this peer
529 * @param solver the MLP handle
530 * @param peer the peer
533 GAS_mlp_stop_get_preferred_address (void *solver,
534 const struct GNUNET_PeerIdentity *peer);
537 * Shutdown the MLP problem solving component
539 * @param solver the solver handle
542 GAS_mlp_done (void *solver);
545 /* end of gnunet-service-ats_addresses_mlp.h */