GNUnet  0.10.x
gnunet-service-ats_plugins.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011-2014 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_ats_plugin.h"
36 
37 
42 
47 
51 static char *plugin;
52 
53 
61 void
63  enum GNUNET_ATS_PreferenceKind kind,
64  double pref_rel)
65 {
66  sf->s_pref (sf->cls,
67  peer,
68  kind,
69  pref_rel);
70 }
71 
72 
78 void
80 {
82  address);
83 }
84 
85 
94 static void
99 {
100  const char *add_info;
101 
102  switch (add) {
103  case GAS_INFO_NONE:
104  add_info = "GAS_INFO_NONE";
105  break;
106  case GAS_INFO_FULL:
107  add_info = "GAS_INFO_MLP_FULL";
108  break;
109  case GAS_INFO_UPDATED:
110  add_info = "GAS_INFO_MLP_UPDATED";
111  break;
112  case GAS_INFO_PROP_ALL:
113  add_info = "GAS_INFO_PROP_ALL";
114  break;
116  add_info = "GAS_INFO_PROP_SINGLE";
117  break;
118  default:
119  add_info = "INVALID";
120  break;
121  }
122  switch (op)
123  {
124  case GAS_OP_SOLVE_START:
126  "Solver notifies `%s' with result `%s' `%s'\n",
127  "GAS_OP_SOLVE_START",
128  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL",
129  add_info);
130  return;
131  case GAS_OP_SOLVE_STOP:
133  "Solver notifies `%s' with result `%s'\n",
134  "GAS_OP_SOLVE_STOP",
135  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
136  return;
139  "Solver notifies `%s' with result `%s'\n",
140  "GAS_OP_SOLVE_SETUP_START",
141  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
142  return;
145  "Solver notifies `%s' with result `%s'\n",
146  "GAS_OP_SOLVE_SETUP_STOP",
147  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
148  return;
151  "Solver notifies `%s' with result `%s'\n",
152  "GAS_OP_SOLVE_LP_START",
153  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
154  return;
157  "Solver notifies `%s' with result `%s'\n",
158  "GAS_OP_SOLVE_LP_STOP",
159  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
160  return;
163  "Solver notifies `%s' with result `%s'\n",
164  "GAS_OP_SOLVE_MLP_START",
165  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
166  return;
169  "Solver notifies `%s' with result `%s'\n",
170  "GAS_OP_SOLVE_MLP_STOP",
171  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
172  return;
175  "Solver notifies `%s' with result `%s'\n",
176  "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
177  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
178  return;
181  "Solver notifies `%s' with result `%s'\n",
182  "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
183  (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
184  return;
185  default:
186  GNUNET_break (0);
187  break;
188  }
189 }
190 
191 
198 static void
200  struct ATS_Address *address)
201 {
202  long long diff_out;
203  long long diff_in;
204 
206  "Bandwidth assignment changed for peer %s to %u/%u\n",
207  GNUNET_i2s (&address->peer),
208  (unsigned int) address->assigned_bw_in,
209  (unsigned int) address->assigned_bw_out);
212  /* Notify performance clients about changes to address */
214  address->plugin,
215  address->addr,
216  address->addr_len,
217  address->active,
218  &address->properties,
219  address->local_address_info,
222 
223  if ( (0 == address->assigned_bw_in) &&
224  (0 == address->assigned_bw_out) )
225  {
227  "Telling transport to disconnect peer `%s'\n",
228  GNUNET_i2s (&address->peer));
229 
230  /* Notify scheduling clients about suggestion */
232  address->session_id,
235  return;
236  }
237 
238  /* Do bandwidth stability check */
239  diff_out = llabs ((long long) address->assigned_bw_out -
240  (long long) address->last_notified_bw_out);
241  diff_in = llabs ((long long) address->assigned_bw_in -
242  (long long) address->last_notified_bw_in);
243  if ( (diff_out < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) &&
244  (diff_in < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) )
245  {
247  "Bandwidth change too small, not notifying client\n");
248  return;
249  }
250 
252  "Sending bandwidth update for peer `%s': %u/%u\n",
253  GNUNET_i2s (&address->peer),
254  address->assigned_bw_out,
255  address->assigned_bw_out);
256 
257  /* *Notify scheduling clients about suggestion */
259  address->session_id,
262 
263  address->last_notified_bw_out = address->assigned_bw_out;
264  address->last_notified_bw_in = address->assigned_bw_in;
265 }
266 
267 
276 static unsigned long long
277 parse_quota (const char *quota_str,
278  const char *direction,
279  enum GNUNET_NetworkType network)
280 {
281  int res;
282  unsigned long long ret;
283 
284  res = GNUNET_NO;
285  if (0 == strcmp (quota_str, GNUNET_ATS_MaxBandwidthString))
286  {
288  res = GNUNET_YES;
289  }
290  if ((GNUNET_NO == res) &&
291  (GNUNET_OK ==
293  &ret)))
294  res = GNUNET_YES;
295  if ((GNUNET_NO == res) &&
296  (1 ==
297  sscanf (quota_str,
298  "%llu",
299  &ret)))
300  res = GNUNET_YES;
301  if (GNUNET_NO == res)
302  {
304  _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
305  direction,
306  GNUNET_NT_to_string (network),
307  quota_str,
308  (unsigned long long) GNUNET_ATS_DefaultBandwidth);
310  }
311  else
312  {
314  _("%s quota configured for network `%s' is %llu\n"),
315  direction,
316  GNUNET_NT_to_string (network),
317  ret);
318  }
319  return ret;
320 }
321 
322 
332 static unsigned long long
335  const char *direction)
336 {
337  char *entry;
338  char *quota_str;
339  unsigned long long ret;
340 
341  GNUNET_asprintf (&entry,
342  "%s_QUOTA_%s",
343  GNUNET_NT_to_string (type),
344  direction);
345  if (GNUNET_OK ==
347  "ats",
348  entry,
349  &quota_str))
350  {
351  ret = parse_quota (quota_str,
352  direction,
353  type);
354  GNUNET_free (quota_str);
355  }
356  else
357  {
359  _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"),
360  direction,
361  GNUNET_NT_to_string (type),
362  (unsigned long long) GNUNET_ATS_DefaultBandwidth);
364  }
365  GNUNET_free (entry);
366  return ret;
367 }
368 
369 
379 static unsigned int
381  unsigned long long *out_dest,
382  unsigned long long *in_dest,
383  int dest_length)
384 {
385  unsigned int c;
386 
387  for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++)
388  {
389  in_dest[c] = load_quota (cfg,
390  c,
391  "out");
392  out_dest[c] = load_quota (cfg,
393  c,
394  "in");
396  "Loaded quota for network `%s' (in/out): %llu %llu\n",
398  in_dest[c],
399  out_dest[c]);
400  }
401  return c;
402 }
403 
404 
412 int
414 {
415  char *mode_str;
416 
417  /* Figure out configured solution method */
418  if (GNUNET_SYSERR ==
420  "ats",
421  "MODE",
422  &mode_str))
423  {
425  "No resource assignment method configured, using proportional approach\n");
426  mode_str = GNUNET_strdup ("proportional");
427  }
428  env.cls = NULL;
433  env.cfg = cfg;
434  env.stats = GSA_stats;
437  load_quotas (cfg,
438  env.out_quota,
439  env.in_quota,
442  "libgnunet_plugin_ats_%s",
443  mode_str);
445  "Initializing solver `%s'\n",
446  mode_str);
447  GNUNET_free (mode_str);
448  if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env)))
449  {
451  _("Failed to initialize solver `%s'!\n"),
452  plugin);
453  return GNUNET_SYSERR;
454  }
455  return GNUNET_OK;
456 }
457 
458 
462 void
464 {
466  sf);
467  sf = NULL;
469  plugin = NULL;
470 }
471 
472 
479 void
480 GAS_plugin_new_address (struct ATS_Address *new_address)
481 {
482  sf->s_add (sf->cls,
483  new_address,
484  new_address->properties.scope); /* FIXME: remove 3rd arg here! */
485 }
486 
487 
494 void
496 {
497  sf->s_del (sf->cls,
498  address);
499 }
500 
501 
512 void
514  const struct GNUNET_PeerIdentity *peer,
515  const struct GNUNET_TIME_Relative scope,
516  enum GNUNET_ATS_PreferenceKind kind,
517  float score_abs)
518 {
519  sf->s_feedback (sf->cls,
520  application,
521  peer,
522  scope,
523  kind,
524  score_abs);
525 }
526 
527 
532 void
534 {
535  sf->s_bulk_start (sf->cls);
536 }
537 
538 
542 void
544 {
545  sf->s_bulk_stop (sf->cls);
546 }
547 
548 
555 void
557 {
558  sf->s_get (sf->cls,
559  pid);
560 }
561 
562 
569 void
571 {
572  sf->s_get_stop (sf->cls,
573  pid);
574 }
575 
576 
577 /* end of gnunet-service-ats_plugins.c */
GAS_solver_stop_get_preferred_address s_get_stop
Tell solver stop notifying ATS about changes for this peers.
Solving of the LP problem was started MLP solver only.
After the problem was finished, start notifications about changes to addresses.
#define GNUNET_ATS_MaxBandwidthString
Textual equivalent for GNUNET_ATS_MaxBandwidth.
GAS_solver_address_add s_add
Add a new address for a peer to the solver.
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:43
The proportional solver had to recalculate for a single network.
uint32_t session_id
Session ID, can never be 0.
struct GNUNET_ATS_Properties properties
ATS performance information for this address.
The setup of the problem as a preparation to solve it was started.
struct GNUNET_STATISTICS_Handle * stats
Statistics handle to be used by the solver.
void GAS_plugin_delete_address(struct ATS_Address *address)
Tell the solver that the given address is no longer valid can cannot be used any longer.
void GAS_plugin_new_address(struct ATS_Address *new_address)
Tell the solver that the given address can now be used for talking to the respective peer...
int active
Is this the active address for this peer?
GAS_get_preferences get_preferences
ATS addresses function to obtain preference values.
static unsigned long long parse_quota(const char *quota_str, const char *direction, enum GNUNET_NetworkType network)
Convert quota from text to numeric value.
void GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TIME_Relative scope, enum GNUNET_ATS_PreferenceKind kind, float score_abs)
Tell the solver that the given client has expressed its appreciation for the past performance of a gi...
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
GAS_Solver_Status
Status of a GAS_Solver_Operation operation.
The proportional solver had to recalculate for all networks.
No more specific information.
const void * addr
Address (in plugin-specific binary format).
uint32_t last_notified_bw_out
Outbound bandwidth assigned by solver in NBO.
GAS_solver_address_feedback_preference s_feedback
Give feedback about the current assignment.
ats service address: management of ATS properties and preferences normalization
GAS_solver_address_property_changed s_address_update_property
Update the properties of an address in the solver.
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
int GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition: strings.c:317
ats service plugin management
#define GNUNET_NO
Definition: gnunet_common.h:81
static unsigned int load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length)
Load quotas for networks from configuration.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
A full solution process is performed Quite specific to the MLP solver.
size_t addr_len
Address length, number of bytes in addr.
char * plugin
Plugin name.
Solving of the LP problem is done MLP solver only.
static int ret
Final status code.
Definition: gnunet-arm.c:89
void GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, double pref_rel)
The preference changed for a peer, update solver.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_STATISTICS_Handle * GSA_stats
Handle for statistics.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
ats service, interaction with &#39;performance&#39; API
void GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Set the amount of bandwidth the other peer could currently transmit to us (as far as we know) to the ...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
void GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Transmit the given performance information to all performance clients.
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:258
GAS_Solver_Operation
Operation codes for solver information callback.
Handle to a client that is connected to a service.
Definition: service.c:249
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
uint32_t assigned_bw_in
Inbound bandwidth assigned by solver.
Solving of the MLP problem is done MLP solver only.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
ats service, inbound bandwidth reservation management
A solution iteration has been started.
void GAS_plugin_notify_property_changed(struct ATS_Address *address)
The relative value for a property changed.
void GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer, uint32_t session_id, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Transmit the given address suggestion and bandwidth update to all scheduling clients.
static enum GNUNET_NetworkType scope
Which network scope do we belong to?
GAS_Solver_Additional_Information
Status of the operation.
int GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize plugins subsystem.
GAS_solver_address_delete s_del
Delete an address in the solver.
Solving of the MLP problem was started MLP solver only.
uint16_t status
See PRISM_STATUS_*-constants.
static void bandwidth_changed_cb(void *cls, struct ATS_Address *address)
Callback for solver to notify about assignment changes.
#define GNUNET_ATS_DefaultBandwidth
Default bandwidth assigned to a network : 64 KB/s.
static void solver_info_cb(void *cls, enum GAS_Solver_Operation op, enum GAS_Solver_Status status, enum GAS_Solver_Additional_Information add)
Solver information callback.
unsigned int GAS_connectivity_has_peer(void *cls, const struct GNUNET_PeerIdentity *peer)
Is the given peer in the list of peers for which we have an address request?
GAS_solver_address_change_preference s_pref
Change relative preference for quality in solver.
static unsigned long long load_quota(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_NetworkType type, const char *direction)
Load quota value from the configuration cfg for the given network type and direction.
static int res
static char * plugin
Solver plugin name as string.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
#define GNUNET_ATS_MaxBandwidth
Maximum bandwidth assigned to a network : 4095 MB/s.
Address with additional information.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
void GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid)
Notify the plugin that a request to connect to a particular peer was given to us. ...
void GAS_plugin_done()
Shutdown address subsystem.
void * cls
Closure to pass to all solver functions in this struct.
struct GNUNET_CONTAINER_MultiPeerMap * GSA_addresses
A multihashmap to store all addresses.
ats service, interaction with &#39;connecivity&#39; API
manage preferences expressed by clients
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
static int add
Desired action is to add a record.
GAS_solver_get_preferred_address s_get
Tell solver to notify ATS if the address to use changes for a specific peer using the bandwidth chang...
unsigned long long in_quota[6]
Array of configured inbound quotas Order according to networks in network array.
A solution iteration has been finished.
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change...
GAS_solver_bulk_start s_bulk_start
Start a bulk operation.
The identity of the host (wraps the signing key of the peer).
#define GNUNET_BANDWIDTH_ZERO
Convenience definition to use for 0-bandwidth.
static struct GNUNET_ATS_PluginEnvironment env
Solver environment.
uint32_t assigned_bw_out
Outbound bandwidth assigned by solver.
configuration data
Definition: configuration.c:85
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle to be used by the solver.
#define GNUNET_log(kind,...)
GAS_solver_information_callback info_cb
Callback for solver to call with status information, can be NULL.
The setup of the problem as a preparation to solve is finished.
unsigned long long out_quota[6]
Array of configured outbound quotas Order according to networks in network array. ...
An existing solution was reused Quite specific to the MLP solver.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure to pass to all callbacks in this struct.
void GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid)
Notify the plugin that a request to connect to a particular peer was dropped.
#define GNUNET_YES
Definition: gnunet_common.h:80
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:210
ats service, interaction with &#39;scheduling&#39; API
static struct GNUNET_ATS_SolverFunctions * sf
Solver handle.
GNUNET_ATS_PreferenceKind
Enum defining all known preference categories.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap containing all addresses available.
The ATS plugin will pass a pointer to a struct of this type as to the initialization function of the ...
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
GAS_solver_bulk_stop s_bulk_stop
Bulk operation done.
static char * address
GNS address for this phone.
GAS_bandwidth_changed_cb bandwidth_changed_cb
ATS addresses callback to be notified about bandwidth assignment changes.
After the problem was finished, notifications about changes to addresses are done.
const double * GAS_preference_get_by_peer(void *cls, const struct GNUNET_PeerIdentity *id)
Get the normalized preference values for a specific peer or the default values if.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_NT_COUNT
unsigned int network_count
Number of networks available, size of the out_quota and in_quota arrays.
enum GNUNET_HELLO_AddressInfo local_address_info
Field to store local flags.
uint32_t last_notified_bw_in
Inbound bandwidth assigned by solver in NBO.
GAS_get_connectivity get_connectivity
ATS addresses function to obtain preference values.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.