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/libgnunet_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
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 addresses Hashmap containing addresses
380 * @param network array of GNUNET_ATS_NetworkType with length dest_length
381 * @param out_dest array of outbound quotas
382 * @param in_dest array of outbound quota
383 * @param dest_length array length for quota arrays
384 * @param bw_changed_cb callback for changed bandwidth amounts
385 * @param bw_changed_cb_cls cls for callback
386 * @param get_preference callback to get relative preferences for a peer
387 * @param get_preference_cls cls for callback to get relative preferences for a peer
388 * @param get_properties callback to get relative properties
389 * @param get_properties_cls cls for callback to get relative properties
390 * @return struct GAS_MLP_Handle on success, NULL on fail
393 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
394 const struct GNUNET_STATISTICS_Handle *stats,
395 const struct GNUNET_CONTAINER_MultiPeerMap *addresses,
397 unsigned long long *out_dest,
398 unsigned long long *in_dest,
400 GAS_bandwidth_changed_cb bw_changed_cb,
401 void *bw_changed_cb_cls,
402 GAS_get_preferences get_preference,
403 void *get_preference_cls,
404 GAS_get_properties get_properties,
405 void *get_properties_cls);
409 * Add a single address within a network to the solver
411 * @param solver the solver Handle
412 * @param address the address to add
413 * @param network network type of this address
416 GAS_mlp_address_add (void *solver, struct ATS_Address *address,
421 * Transport properties for this address have changed
423 * @param solver solver handle
424 * @param address the address
425 * @param type the ATSI type in HBO
426 * @param abs_value the absolute value of the property
427 * @param rel_value the normalized value
430 GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address,
431 uint32_t type, uint32_t abs_value, double rel_value);
435 * Transport session for this address has changed
437 * NOTE: values in addresses are already updated
439 * @param solver solver handle
440 * @param address the address
441 * @param cur_session the current session
442 * @param new_session the new session
445 GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address,
446 uint32_t cur_session, uint32_t new_session);
450 * Usage for this address has changed
452 * NOTE: values in addresses are already updated
454 * @param solver solver handle
455 * @param address the address
456 * @param in_use usage state
459 GAS_mlp_address_inuse_changed (void *solver, struct ATS_Address *address,
463 * Network scope for this address has changed
465 * NOTE: values in addresses are already updated
467 * @param solver solver handle
468 * @param address the address
469 * @param current_network the current network
470 * @param new_network the new network
473 GAS_mlp_address_change_network (void *solver, struct ATS_Address *address,
474 uint32_t current_network, uint32_t new_network);
477 * Deletes a single address in the MLP problem
479 * The MLP problem has to be recreated and the problem has to be resolved
481 * @param solver the MLP Handle
482 * @param address the address to delete
483 * @param session_only delete only session not whole address
486 GAS_mlp_address_delete (void *solver, struct ATS_Address *address,
490 * Changes the preferences for a peer in the MLP problem
492 * @param solver the MLP Handle
493 * @param peer the peer
494 * @param kind the kind to change the preference
495 * @param pref_rel the relative score
498 GAS_mlp_address_change_preference (void *solver,
499 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
503 * Get application feedback for a peer
505 * @param solver the solver handle
506 * @param application the application
507 * @param peer the peer to change the preference for
508 * @param scope the time interval for this feedback: [now - scope .. now]
509 * @param kind the kind to change the preference
510 * @param score the score
513 GAS_mlp_address_preference_feedback (void *solver, void *application,
514 const struct GNUNET_PeerIdentity *peer,
515 const struct GNUNET_TIME_Relative scope,
516 enum GNUNET_ATS_PreferenceKind kind, double score);
519 * Start a bulk operation
521 * @param solver the solver
524 GAS_mlp_bulk_start (void *solver);
527 * Bulk operation done
530 GAS_mlp_bulk_stop (void *solver);
533 * Get the preferred address for a specific peer until
534 * GAS_mlp_stop_get_preferred_address is called
536 * @param solver the MLP Handle
537 * @param peer the peer
538 * @return suggested address
540 const struct ATS_Address *
541 GAS_mlp_get_preferred_address (void *solver,
542 const struct GNUNET_PeerIdentity *peer);
545 * Stop notifying about address and bandwidth changes for this peer
547 * @param solver the MLP handle
548 * @param peer the peer
551 GAS_mlp_stop_get_preferred_address (void *solver,
552 const struct GNUNET_PeerIdentity *peer);
555 * Shutdown the MLP problem solving component
557 * @param solver the solver handle
560 GAS_mlp_done (void *solver);
563 /* end of gnunet-service-ats_addresses_mlp.h */