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 callback to get relative preferences for a peer
375 * @param get_properties_cls for callback to get relative properties
376 * @param get_properties_cls cls for callback to get relative properties
377 * @return struct GAS_MLP_Handle on success, NULL on fail
380 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
381 const struct GNUNET_STATISTICS_Handle *stats,
382 const struct GNUNET_CONTAINER_MultiHashMap *addresses,
384 unsigned long long *out_dest,
385 unsigned long long *in_dest,
387 GAS_bandwidth_changed_cb bw_changed_cb,
388 void *bw_changed_cb_cls,
389 GAS_get_preferences get_preference,
390 void *get_preference_cls,
391 GAS_get_properties get_properties,
392 void *get_properties_cls);
396 * Add a single address within a network to the solver
398 * @param solver the solver Handle
399 * @param address the address to add
400 * @param network network type of this address
403 GAS_mlp_address_add (void *solver,
404 struct ATS_Address *address,
409 * Transport properties for this address have changed
411 * @param solver solver handle
412 * @param address the address
413 * @param type the ATSI type in HBO
414 * @param abs_value the absolute value of the property
415 * @param rel_value the normalized value
418 GAS_mlp_address_property_changed (void *solver,
419 struct ATS_Address *address,
426 * Transport session for this address has changed
428 * NOTE: values in addresses are already updated
430 * @param solver solver handle
431 * @param address the address
432 * @param cur_session the current session
433 * @param new_session the new session
436 GAS_mlp_address_session_changed (void *solver,
437 struct ATS_Address *address,
438 uint32_t cur_session,
439 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,
453 struct ATS_Address *address,
458 * Network scope for this address has changed
460 * NOTE: values in addresses are already updated
462 * @param solver solver handle
463 * @param address the address
464 * @param current_network the current network
465 * @param new_network the new network
468 GAS_mlp_address_change_network (void *solver,
469 struct ATS_Address *address,
470 uint32_t current_network,
471 uint32_t new_network);
474 * Deletes a single address in the MLP problem
476 * The MLP problem has to be recreated and the problem has to be resolved
478 * @param solver the MLP Handle
479 * @param address the address to delete
480 * @param session_only delete only session not whole address
483 GAS_mlp_address_delete (void *solver,
484 struct ATS_Address *address,
489 * Changes the preferences for a peer in the MLP problem
491 * @param solver the MLP Handle
492 * @param peer the peer
493 * @param kind the kind to change the preference
494 * @param pref_rel the relative score
497 GAS_mlp_address_change_preference (void *solver,
498 const struct GNUNET_PeerIdentity *peer,
499 enum GNUNET_ATS_PreferenceKind kind,
504 * Get application feedback for a peer
506 * @param solver the solver handle
507 * @param application the application
508 * @param peer the peer to change the preference for
509 * @param kind the kind to change the preference
510 * @param score the score
513 GAS_mlp_address_preference_feedback (void *solver,
515 const struct GNUNET_PeerIdentity *peer,
516 enum GNUNET_ATS_PreferenceKind kind,
522 * Start a bulk operation
524 * @param solver the solver
527 GAS_mlp_bulk_start (void *solver);
531 * Bulk operation done
534 GAS_mlp_bulk_stop (void *solver);
538 * Get the preferred address for a specific peer until
539 * GAS_mlp_stop_get_preferred_address is called
541 * @param solver the MLP Handle
542 * @param peer the peer
543 * @return suggested address
545 const struct ATS_Address *
546 GAS_mlp_get_preferred_address (void *solver,
547 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);
562 * Shutdown the MLP problem solving component
564 * @param solver the solver handle
567 GAS_mlp_done (void *solver);
570 /* end of gnunet-service-ats_addresses_mlp.h */