GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-service-ats_normalization.c File Reference

ats service address: management of ATS properties and preferences normalization More...

#include "platform.h"
#include <float.h>
#include "gnunet_ats_service.h"
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_normalization.h"
#include "gnunet-service-ats_plugins.h"
Include dependency graph for gnunet-service-ats_normalization.c:

Go to the source code of this file.

Data Structures

struct  PropertyRange
 Range information for normalization of quality properties. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from(kind, "ats-normalization", __VA_ARGS__)
 

Functions

static void update_avg (uint64_t current_val, struct GAS_NormalizationInfo *ni)
 Add the value from atsi to the running average of the given ni quality property. More...
 
static int find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
 Function called for all addresses and peers to find the minimum and maximum (averaged) values for a given quality property. More...
 
static void update_norm (uint64_t min, uint64_t max, struct GAS_NormalizationInfo *ni)
 Compute the normalized value from the given ni range data and the average value. More...
 
static int normalize_address (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Normalize the property value for a given address based on the range we know that property values have globally. More...
 
static int notify_change (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Notify about change in normalized property. More...
 
static void init_range (struct PropertyRange *pr)
 Initialize property range to the values corresponding to an empty set. More...
 
void GAS_normalization_update_property (struct ATS_Address *address)
 Update and normalize atsi performance information. More...
 
void GAS_normalization_start ()
 Start the normalization component. More...
 
void GAS_normalization_stop ()
 Stop the normalization component and free all items. More...
 

Variables

static struct PropertyRange property_range
 Range information for all quality properties we see. More...
 

Detailed Description

ats service address: management of ATS properties and preferences normalization

Author
Matthias Wachs
Christian Grothoff

Definition in file gnunet-service-ats_normalization.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from(kind, "ats-normalization", __VA_ARGS__)

Function Documentation

◆ update_avg()

static void update_avg ( uint64_t  current_val,
struct GAS_NormalizationInfo ni 
)
static

Add the value from atsi to the running average of the given ni quality property.

Parameters
current_valthe updated value
ninormalization information to update

Definition at line 67 of file gnunet-service-ats_normalization.c.

References GAS_NormalizationInfo::atsi_abs, GAS_NormalizationInfo::avg, GAS_NormalizationInfo::avg_queue_index, and GAS_normalization_queue_length.

Referenced by GAS_normalization_update_property().

69 {
70  double sum;
71  uint32_t count;
72  unsigned int c1;
73 
74  ni->atsi_abs[ni->avg_queue_index++] = current_val;
76  ni->avg_queue_index = 0;
77  count = 0;
78  sum = 0.0;
79  for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
80  {
81  if (UINT64_MAX != ni->atsi_abs[c1])
82  {
83  count++;
84  sum += (double)ni->atsi_abs[c1];
85  }
86  }
87  if (0 == count)
88  ni->avg = current_val; /* must be UINT64_MAX */
89  else
90  ni->avg = sum / count;
91 }
unsigned int avg_queue_index
Next index to use in averaging queue.
#define GAS_normalization_queue_length
uint64_t atsi_abs[3]
Averaging queue.
uint64_t avg
Averaged ATSI values from queue.
Here is the caller graph for this function:

◆ find_min_max_it()

static int find_min_max_it ( void *  cls,
const struct GNUNET_PeerIdentity h,
void *  k 
)
static

Function called for all addresses and peers to find the minimum and maximum (averaged) values for a given quality property.

Given those, we can then calculate the normalized score.

Parameters
clsthe struct PropertyRange
hwhich peer are we looking at (ignored)
kthe address for that peer
Returns
GNUNET_OK (continue to iterate)

Definition at line 105 of file gnunet-service-ats_normalization.c.

References GNUNET_ATS_Properties::delay, GNUNET_ATS_Properties::distance, GNUNET_MAX, GNUNET_MIN, GNUNET_OK, GNUNET_TIME_relative_max(), GNUNET_TIME_relative_min(), PropertyRange::max, PropertyRange::min, ATS_Address::properties, GNUNET_ATS_Properties::utilization_in, and GNUNET_ATS_Properties::utilization_out.

Referenced by GAS_normalization_update_property().

108 {
109  struct PropertyRange *pr = cls;
110  const struct ATS_Address *a = k;
111 
116  pr->max.distance = GNUNET_MAX(pr->max.distance,
117  a->properties.distance);
119  a->properties.delay);
124  pr->min.distance = GNUNET_MIN(pr->min.distance,
125  a->properties.distance);
127  a->properties.delay);
128  return GNUNET_OK;
129 }
struct GNUNET_ATS_Properties properties
ATS performance information for this address.
struct GNUNET_ATS_Properties min
Minimum value we see for this property across all addresses.
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:287
Range information for normalization of quality properties.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
struct GNUNET_TIME_Relative delay
Delay.
Address with additional information.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:272
struct GNUNET_ATS_Properties max
Maximum value we see for this property across all addresses.
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_norm()

static void update_norm ( uint64_t  min,
uint64_t  max,
struct GAS_NormalizationInfo ni 
)
static

Compute the normalized value from the given ni range data and the average value.

Parameters
minminimum value
maxmaximum value
ninormalization information to update

Definition at line 141 of file gnunet-service-ats_normalization.c.

References GAS_NormalizationInfo::avg, DEFAULT_REL_QUALITY, PropertyRange::min, and GAS_NormalizationInfo::norm.

Referenced by normalize_address().

144 {
145  /* max - 2 * min + avg_value / (max - min) */
146  if (min < max)
147  ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double)(max - min);
148  else
150 }
#define DEFAULT_REL_QUALITY
Value we return for a normalized quality score if we have no data.
uint64_t avg
Averaged ATSI values from queue.
double norm
Normalized values from queue to a range of values [1.0...2.0].
Here is the caller graph for this function:

◆ normalize_address()

static int normalize_address ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Normalize the property value for a given address based on the range we know that property values have globally.

Parameters
clsNULL
keywhich peer are we looking at (ignored)
valuethe address for that peer, from where we get the original value and where we write the normalized value
Returns
GNUNET_OK (continue to iterate)

Definition at line 165 of file gnunet-service-ats_normalization.c.

References address, GNUNET_ATS_Properties::delay, GNUNET_ATS_Properties::distance, GNUNET_OK, PropertyRange::max, PropertyRange::min, ATS_Address::norm_delay, ATS_Address::norm_distance, ATS_Address::norm_utilization_in, ATS_Address::norm_utilization_out, property_range, GNUNET_TIME_Relative::rel_value_us, update_norm(), GNUNET_ATS_Properties::utilization_in, GNUNET_ATS_Properties::utilization_out, and value.

Referenced by GAS_normalization_update_property().

168 {
169  struct ATS_Address *address = value;
170 
173  &address->norm_delay);
176  &address->norm_distance);
179  &address->norm_utilization_in);
182  &address->norm_utilization_out);
183  return GNUNET_OK;
184 }
static void update_norm(uint64_t min, uint64_t max, struct GAS_NormalizationInfo *ni)
Compute the normalized value from the given ni range data and the average value.
uint64_t rel_value_us
The actual value.
struct GNUNET_ATS_Properties min
Minimum value we see for this property across all addresses.
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
static struct PropertyRange property_range
Range information for all quality properties we see.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
struct GNUNET_TIME_Relative delay
Delay.
struct GAS_NormalizationInfo norm_utilization_out
Normalized utilization outbound for this address.
Address with additional information.
struct GAS_NormalizationInfo norm_utilization_in
Normalized utilization inbound for this address.
struct GAS_NormalizationInfo norm_delay
Normalized delay information for this address.
struct GNUNET_ATS_Properties max
Maximum value we see for this property across all addresses.
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
static char * address
GNS address for this phone.
struct GAS_NormalizationInfo norm_distance
Normalized distance information for this address.
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_change()

static int notify_change ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Notify about change in normalized property.

Parameters
clsNULL
keywhich peer are we looking at (ignored)
valuethe address for that peer
Returns
GNUNET_OK (continue to iterate)

Definition at line 196 of file gnunet-service-ats_normalization.c.

References address, GAS_plugin_notify_property_changed(), GNUNET_OK, and value.

Referenced by GAS_normalization_update_property().

199 {
200  struct ATS_Address *address = value;
201 
203  return GNUNET_OK;
204 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GAS_plugin_notify_property_changed(struct ATS_Address *address)
The relative value for a property changed.
static char * value
Value of the record to add/remove.
Address with additional information.
static char * address
GNS address for this phone.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_range()

static void init_range ( struct PropertyRange pr)
static

Initialize property range to the values corresponding to an empty set.

Parameters
prrange to initialize

Definition at line 214 of file gnunet-service-ats_normalization.c.

References GNUNET_ATS_Properties::delay, GNUNET_ATS_Properties::distance, GNUNET_TIME_UNIT_FOREVER_REL, PropertyRange::min, GNUNET_ATS_Properties::utilization_in, and GNUNET_ATS_Properties::utilization_out.

Referenced by GAS_normalization_start(), and GAS_normalization_update_property().

215 {
216  memset(pr, 0, sizeof(struct PropertyRange));
217  pr->min.utilization_out = UINT32_MAX;
218  pr->min.utilization_in = UINT32_MAX;
219  pr->min.distance = UINT32_MAX;
221 }
struct GNUNET_ATS_Properties min
Minimum value we see for this property across all addresses.
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
Range information for normalization of quality properties.
struct GNUNET_TIME_Relative delay
Delay.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
Here is the caller graph for this function:

◆ GAS_normalization_update_property()

void GAS_normalization_update_property ( struct ATS_Address address)

Update and normalize atsi performance information.

Update and normalize a prop performance information.

Parameters
addressthe address to update

Definition at line 230 of file gnunet-service-ats_normalization.c.

References GNUNET_ATS_Properties::delay, GNUNET_ATS_Properties::distance, find_min_max_it(), GAS_plugin_solver_lock(), GAS_plugin_solver_unlock(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcmp, GSA_addresses, init_range(), LOG, ATS_Address::norm_delay, ATS_Address::norm_distance, ATS_Address::norm_utilization_in, ATS_Address::norm_utilization_out, normalize_address(), notify_change(), ATS_Address::peer, ATS_Address::properties, property_range, GNUNET_TIME_Relative::rel_value_us, update_avg(), and GNUNET_ATS_Properties::utilization_in.

Referenced by GAS_addresses_add(), GAS_addresses_update(), and set_prop_task().

231 {
232  const struct GNUNET_ATS_Properties *prop = &address->properties;
233  struct PropertyRange range;
234 
236  "Updating properties for peer `%s'\n",
237  GNUNET_i2s(&address->peer));
240  &address->norm_delay);
241  update_avg(prop->distance,
242  &address->norm_distance);
244  &address->norm_utilization_in);
246  &address->norm_utilization_out);
247 
248  init_range(&range);
251  &range);
252  if (0 != GNUNET_memcmp(&range,
253  &property_range))
254  {
255  /* limits changed, (re)normalize all addresses */
256  property_range = range;
259  NULL);
261  &notify_change,
262  NULL);
263  }
264  else
265  {
266  /* renormalize just this one address */
267  normalize_address(NULL,
268  &address->peer,
269  address);
270  notify_change(NULL,
271  &address->peer,
272  address);
273  }
275 }
uint64_t rel_value_us
The actual value.
struct GNUNET_ATS_Properties properties
ATS performance information for this address.
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
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.
static int find_min_max_it(void *cls, const struct GNUNET_PeerIdentity *h, void *k)
Function called for all addresses and peers to find the minimum and maximum (averaged) values for a g...
Range information for normalization of quality properties.
static struct PropertyRange property_range
Range information for all quality properties we see.
static void update_avg(uint64_t current_val, struct GAS_NormalizationInfo *ni)
Add the value from atsi to the running average of the given ni quality property.
ATS performance characteristics for an address.
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
static int notify_change(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Notify about change in normalized property.
struct GNUNET_TIME_Relative delay
Delay.
struct GAS_NormalizationInfo norm_utilization_out
Normalized utilization outbound for this address.
struct GNUNET_CONTAINER_MultiPeerMap * GSA_addresses
A multihashmap to store all addresses.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GAS_NormalizationInfo norm_utilization_in
Normalized utilization inbound for this address.
static void init_range(struct PropertyRange *pr)
Initialize property range to the values corresponding to an empty set.
static int normalize_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Normalize the property value for a given address based on the range we know that property values have...
#define LOG(kind,...)
struct GAS_NormalizationInfo norm_delay
Normalized delay information for this address.
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GAS_NormalizationInfo norm_distance
Normalized distance information for this address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_normalization_start()

void GAS_normalization_start ( void  )

Start the normalization component.

Definition at line 282 of file gnunet-service-ats_normalization.c.

References init_range(), and property_range.

Referenced by GNUNET_ATS_solvers_solver_start(), and run().

283 {
285 }
static struct PropertyRange property_range
Range information for all quality properties we see.
static void init_range(struct PropertyRange *pr)
Initialize property range to the values corresponding to an empty set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_normalization_stop()

void GAS_normalization_stop ( void  )

Stop the normalization component and free all items.

Definition at line 292 of file gnunet-service-ats_normalization.c.

Referenced by cleanup_task(), GNUNET_ATS_solvers_solver_stop(), and run().

293 {
294  /* nothing to do */
295 }
Here is the caller graph for this function:

Variable Documentation

◆ property_range

struct PropertyRange property_range
static

Range information for all quality properties we see.

Definition at line 56 of file gnunet-service-ats_normalization.c.

Referenced by GAS_normalization_start(), GAS_normalization_update_property(), and normalize_address().