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_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
61 struct GNUNET_TIME_Relative build_dur;
62 struct GNUNET_TIME_Relative lp_dur;
63 struct GNUNET_TIME_Relative mip_dur;
81 struct GNUNET_PeerIdentity id;
83 /* Was this peer already added to the current problem? */
86 /* constraint 2: 1 address per peer*/
89 /* constraint 9: relativity */
92 /* Legacy preference value */
99 * GLPK (MLP) problem object
107 /* Number of addresses in problem */
108 unsigned int num_addresses;
109 /* Number of peers in problem */
110 unsigned int num_peers;
111 /* Number of elements in problem matrix */
112 unsigned int num_elements;
114 /* Row index constraint 2: */
116 /* Row index constraint 4: minimum connections */
118 /* Row index constraint 6: maximize diversity */
120 /* Row index constraint 8: utilization*/
122 /* Row index constraint 9: relativity*/
124 /* Row indices quality metrics */
125 int r_q[GNUNET_ATS_QualityPropertiesCount];
126 /* Row indices ATS network quotas */
127 int r_quota[GNUNET_ATS_NetworkTypeCount];
129 /* Column index Diversity (D) column */
131 /* Column index Utilization (U) column */
133 /* Column index Proportionality (R) column */
135 /* Column index quality metrics */
136 int c_q[GNUNET_ATS_QualityPropertiesCount];
141 /* Row index array */
143 /* Column index array */
145 /* Column index value */
152 /* Big M value for bandwidth capping */
155 /* ATS Quality metrics
157 * Array with GNUNET_ATS_QualityPropertiesCount elements
158 * contains mapping to GNUNET_ATS_Property*/
159 int q[GNUNET_ATS_QualityPropertiesCount];
161 /* Number of quality metrics */
164 /* Number of quality metrics */
167 /* Quality metric coefficients*/
168 double co_Q[GNUNET_ATS_QualityPropertiesCount];
170 /* Ressource costs coefficients*/
171 double co_RC[GNUNET_ATS_QualityPropertiesCount];
173 /* Diversity coefficient */
176 /* Utility coefficient */
179 /* Relativity coefficient */
182 /* Minimum bandwidth assigned to an address */
185 /* Minimum number of addresses with bandwidth assigned */
189 /* Array mapping array index to ATS network */
190 int quota_index[GNUNET_ATS_NetworkTypeCount];
191 /* Outbound quotas */
192 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
195 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
197 /* ATS ressource costs
198 * array with GNUNET_ATS_QualityPropertiesCount elements
199 * contains mapping to GNUNET_ATS_Property
201 int rc[GNUNET_ATS_QualityPropertiesCount];
208 struct GAS_MLP_Handle
210 struct GNUNET_ATS_PluginEnvironment *env;
215 struct GNUNET_STATISTICS_Handle *stats;
218 * Address hashmap for lookups
220 const struct GNUNET_CONTAINER_MultiPeerMap *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;
233 * ATS function to get preferences
235 GAS_get_preferences get_preferences;
238 * Closure for ATS function to get preferences
240 void *get_preferences_cls;
243 * ATS function to get properties
245 GAS_get_properties get_properties;
248 * Closure for ATS function to get properties
250 void *get_properties_cls;
253 * Exclude peer from next result propagation
255 const struct GNUNET_PeerIdentity *exclude_peer;
258 * Encapsulation for the MLP problem
260 struct MLP_Problem p;
263 * Encapsulation for the MLP problem variables
265 struct MLP_Variables pv;
268 * Encapsulation for the MLP solution
270 struct MLP_Solution ps;
279 * Number of changes while solver was locked
284 * GLPK LP control parameter
287 glp_smcp control_param_lp;
289 void *control_param_lp;
293 * GLPK LP control parameter
296 glp_iocp control_param_mlp;
298 void *control_param_mlp;
302 * Peers with pending address requests
304 struct GNUNET_CONTAINER_MultiPeerMap *requested_peers;
307 * Was the problem updated since last solution
309 int mlp_prob_updated;
312 * Has the problem size changed since last solution
314 int mlp_prob_changed;
317 * Solve the problem automatically when updates occur?
318 * Default: GNUNET_YES
319 * Can be disabled for test and measurements
324 * Write MILP problem to a MPS file
329 * Write MILP problem to a MPS file
336 * Address specific MLP information
338 struct MLP_information
341 /* Bandwidth assigned */
342 struct GNUNET_BANDWIDTH_Value32NBO b_out;
343 struct GNUNET_BANDWIDTH_Value32NBO b_in;
345 /* Address selected */
348 /* bandwidth column index */
351 /* address usage column */
356 /* constraint 1: bandwidth capping */
359 /* constraint 3: minimum bandwidth */
365 * Solves the MLP problem
367 * @param solver the MLP Handle
368 * @return #GNUNET_OK if could be solved, GNUNET_SYSERR on failure
371 GAS_mlp_solve_problem (void *solver);
375 * Init the MLP problem solving component
377 * @param cfg the GNUNET_CONFIGURATION_Handle handle
378 * @param stats the GNUNET_STATISTICS handle
379 * @param network array of GNUNET_ATS_NetworkType with length dest_length
380 * @param out_dest array of outbound quotas
381 * @param in_dest array of outbound quota
382 * @param dest_length array length for quota arrays
383 * @param bw_changed_cb callback for changed bandwidth amounts
384 * @param bw_changed_cb_cls cls for callback
385 * @param get_preference callback to get relative preferences for a peer
386 * @param get_preference callback to get relative preferences for a peer
387 * @param get_properties_cls for callback to get relative properties
388 * @param get_properties_cls cls for callback to get relative properties
389 * @return struct GAS_MLP_Handle on success, NULL on fail
392 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
393 const struct GNUNET_STATISTICS_Handle *stats,
394 const struct GNUNET_CONTAINER_MultiPeerMap *addresses, int *network,
395 unsigned long long *out_dest, unsigned long long *in_dest, int dest_length,
396 GAS_bandwidth_changed_cb bw_changed_cb, void *bw_changed_cb_cls,
397 GAS_get_preferences get_preference, void *get_preference_cls,
398 GAS_get_properties get_properties, void *get_properties_cls);
402 * Add a single address within a network to the solver
404 * @param solver the solver Handle
405 * @param address the address to add
406 * @param network network type of this address
409 GAS_mlp_address_add (void *solver, struct ATS_Address *address,
414 * Transport properties for this address have changed
416 * @param solver solver handle
417 * @param address the address
418 * @param type the ATSI type in HBO
419 * @param abs_value the absolute value of the property
420 * @param rel_value the normalized value
423 GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address,
424 uint32_t type, uint32_t abs_value, double rel_value);
428 * Transport session for this address has changed
430 * NOTE: values in addresses are already updated
432 * @param solver solver handle
433 * @param address the address
434 * @param cur_session the current session
435 * @param new_session the new session
438 GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address,
439 uint32_t cur_session, uint32_t new_session);
443 * Usage for this address has changed
445 * NOTE: values in addresses are already updated
447 * @param solver solver handle
448 * @param address the address
449 * @param in_use usage state
452 GAS_mlp_address_inuse_changed (void *solver, struct ATS_Address *address,
456 * Network scope 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 current_network the current network
463 * @param new_network the new network
466 GAS_mlp_address_change_network (void *solver, struct ATS_Address *address,
467 uint32_t current_network, uint32_t new_network);
470 * Deletes a single address in the MLP problem
472 * The MLP problem has to be recreated and the problem has to be resolved
474 * @param solver the MLP Handle
475 * @param address the address to delete
476 * @param session_only delete only session not whole address
479 GAS_mlp_address_delete (void *solver, struct ATS_Address *address,
483 * Changes the preferences for a peer in the MLP problem
485 * @param solver the MLP Handle
486 * @param peer the peer
487 * @param kind the kind to change the preference
488 * @param pref_rel the relative score
491 GAS_mlp_address_change_preference (void *solver,
492 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
496 * Get application feedback for a peer
498 * @param solver the solver handle
499 * @param application the application
500 * @param peer the peer to change the preference for
501 * @param scope the time interval for this feedback: [now - scope .. now]
502 * @param kind the kind to change the preference
503 * @param score the score
506 GAS_mlp_address_preference_feedback (void *solver, void *application,
507 const struct GNUNET_PeerIdentity *peer,
508 const struct GNUNET_TIME_Relative scope,
509 enum GNUNET_ATS_PreferenceKind kind, double score);
512 * Start a bulk operation
514 * @param solver the solver
517 GAS_mlp_bulk_start (void *solver);
520 * Bulk operation done
523 GAS_mlp_bulk_stop (void *solver);
526 * Get the preferred address for a specific peer until
527 * GAS_mlp_stop_get_preferred_address is called
529 * @param solver the MLP Handle
530 * @param peer the peer
531 * @return suggested address
533 const struct ATS_Address *
534 GAS_mlp_get_preferred_address (void *solver,
535 const struct GNUNET_PeerIdentity *peer);
538 * Stop notifying about address and bandwidth changes for this peer
540 * @param solver the MLP handle
541 * @param peer the peer
544 GAS_mlp_stop_get_preferred_address (void *solver,
545 const struct GNUNET_PeerIdentity *peer);
548 * Shutdown the MLP problem solving component
550 * @param solver the solver handle
553 GAS_mlp_done (void *solver);
556 /* end of gnunet-service-ats_addresses_mlp.h */