GNUnet  0.10.x
Functions | Variables
ats-testing-preferences.c File Reference

ats benchmark: preference generator More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "ats-testing.h"
Include dependency graph for ats-testing-preferences.c:

Go to the source code of this file.

Functions

static double get_preference (struct PreferenceGenerator *pg)
 
static void set_pref_task (void *cls)
 
struct PreferenceGeneratorGNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src, struct BenchmarkPartner *dest, enum GeneratorType type, unsigned int base_value, unsigned int value_rate, struct GNUNET_TIME_Relative period, struct GNUNET_TIME_Relative frequency, enum GNUNET_ATS_PreferenceKind kind)
 Generate between the source master and the partner and set preferences with a value depending on the generator. More...
 
void GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg)
 
void GNUNET_ATS_TEST_generate_preferences_stop_all ()
 Stop all preferences generators. More...
 

Variables

static struct PreferenceGeneratorpg_head
 
static struct PreferenceGeneratorpg_tail
 
struct GNUNET_ATS_TEST_Topologytop
 

Detailed Description

ats benchmark: preference generator

Author
Christian Grothoff
Matthias Wachs

Definition in file ats-testing-preferences.c.

Function Documentation

◆ get_preference()

static double get_preference ( struct PreferenceGenerator pg)
static

Definition at line 36 of file ats-testing-preferences.c.

References PreferenceGenerator::base_value, PreferenceGenerator::duration_period, GNUNET_ATS_TEST_TG_CONSTANT, GNUNET_ATS_TEST_TG_LINEAR, GNUNET_ATS_TEST_TG_RANDOM, GNUNET_ATS_TEST_TG_SINUS, GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_TIME_absolute_get_duration(), PreferenceGenerator::max_value, GNUNET_TIME_Relative::rel_value_us, PreferenceGenerator::time_start, and PreferenceGenerator::type.

Referenced by set_pref_task().

37 {
38  struct GNUNET_TIME_Relative time_delta;
39  double delta_value;
40  double pref_value;
41 
42  /* Calculate the current preference value */
43  switch (pg->type) {
45  pref_value = pg->base_value;
46  break;
49  /* Calculate point of time in the current period */
50  time_delta.rel_value_us = time_delta.rel_value_us %
52  delta_value = ((double) time_delta.rel_value_us /
54  if ((pg->max_value < pg->base_value) &&
55  ((pg->max_value - pg->base_value) > pg->base_value))
56  {
57  /* This will cause an underflow */
58  GNUNET_break (0);
59  }
60  pref_value = pg->base_value + delta_value;
61  break;
64  10000 * (pg->max_value - pg->base_value)) / 10000;
65  pref_value = pg->base_value + delta_value;
66  break;
69  /* Calculate point of time in the current period */
70  time_delta.rel_value_us = time_delta.rel_value_us %
72  if ((pg->max_value - pg->base_value) > pg->base_value)
73  {
74  /* This will cause an underflow for second half of sinus period,
75  * will be detected in general when experiments are loaded */
76  GNUNET_break (0);
77  }
78  delta_value = (pg->max_value - pg->base_value) *
79  sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
80  time_delta.rel_value_us);
81  pref_value = pg->base_value + delta_value;
82  break;
83  default:
84  pref_value = 0.0;
85  break;
86  }
87  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
88  pref_value);
89  return pref_value;
90 }
struct GNUNET_TIME_Absolute time_start
uint64_t rel_value_us
The actual value.
struct GNUNET_TIME_Relative duration_period
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
#define GNUNET_log(kind,...)
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_pref_task()

static void set_pref_task ( void *  cls)
static

Definition at line 94 of file ats-testing-preferences.c.

References BenchmarkPeer::ats_perf_handle, BenchmarkPartner::dest, PreferenceGenerator::frequency, get_preference(), GNUNET_ATS_performance_change_preference(), GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_LATENCY, GNUNET_ATS_print_preference_type(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), BenchmarkPeer::id, PreferenceGenerator::kind, BenchmarkPartner::me, BenchmarkPeer::no, p, BenchmarkPartner::pg, BenchmarkPartner::pref_bandwidth, BenchmarkPartner::pref_delay, and PreferenceGenerator::set_task.

Referenced by GNUNET_ATS_TEST_generate_preferences_start().

95 {
96  struct BenchmarkPartner *p = cls;
97  double pref_value;
98  p->pg->set_task = NULL;
99 
100  pref_value = get_preference (p->pg);
101 
103  "Setting preference for master [%u] and slave [%u] for %s to %f\n",
104  p->me->no, p->dest->no,
105  GNUNET_ATS_print_preference_type (p->pg->kind), pref_value);
106 
108  &p->dest->id,
109  p->pg->kind,
110  pref_value,
112 
113  switch (p->pg->kind) {
115  p->pref_bandwidth = pref_value;
116  break;
118  p->pref_delay = pref_value;
119  break;
120  default:
121  break;
122  }
123 
125  set_pref_task, p);
126 
127 }
double pref_bandwidth
Current preference values for bandwidth.
Definition: ats-testing.h:350
struct PreferenceGenerator * pg
Handle for preference generator.
Definition: ats-testing.h:300
End of preference list.
enum GNUNET_ATS_PreferenceKind kind
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
int no
Unique identifier.
Definition: ats-testing.h:121
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
double pref_delay
Current preference values for delay.
Definition: ats-testing.h:355
static void set_pref_task(void *cls)
Information about a benchmarking partner.
Definition: ats-testing.h:275
struct GNUNET_ATS_PerformanceHandle * ats_perf_handle
ATS performance handle.
Definition: ats-testing.h:151
const char * GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type)
Convert a enum GNUNET_ATS_PreferenceType to a string.
struct GNUNET_SCHEDULER_Task * set_task
Change the peer&#39;s latency value to the given amount.
static double get_preference(struct PreferenceGenerator *pg)
void GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer,...)
Change preferences for the given peer.
struct GNUNET_TIME_Relative frequency
#define GNUNET_log(kind,...)
Change the peer&#39;s bandwidth value (value per byte of bandwidth in the goal function) to the given amo...
struct BenchmarkPeer * me
The peer itself this partner belongs to.
Definition: ats-testing.h:280
struct BenchmarkPeer * dest
The partner peer.
Definition: ats-testing.h:285
struct GNUNET_PeerIdentity id
Peer ID.
Definition: ats-testing.h:131
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ATS_TEST_generate_preferences_start()

struct PreferenceGenerator* GNUNET_ATS_TEST_generate_preferences_start ( struct BenchmarkPeer src,
struct BenchmarkPartner dest,
enum GeneratorType  type,
unsigned int  base_value,
unsigned int  value_rate,
struct GNUNET_TIME_Relative  period,
struct GNUNET_TIME_Relative  frequency,
enum GNUNET_ATS_PreferenceKind  kind 
)

Generate between the source master and the partner and set preferences with a value depending on the generator.

Parameters
srcsource
destpartner
typetype of preferences to generate
base_valuetraffic base rate to send data with
value_ratetraffic maximum rate to send data with
periodduration of a period of preferences generation (~ 1/frequency)
frequencyhow long to generate preferences
kindATS preference to generate
Returns
the preference generator

Definition at line 145 of file ats-testing-preferences.c.

References PreferenceGenerator::base_value, PreferenceGenerator::dest, BenchmarkPartner::dest, PreferenceGenerator::duration_period, PreferenceGenerator::frequency, GNUNET_ATS_TEST_TG_CONSTANT, GNUNET_ATS_TEST_TG_LINEAR, GNUNET_ATS_TEST_TG_RANDOM, GNUNET_ATS_TEST_TG_SINUS, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_SCHEDULER_add_now(), GNUNET_TIME_absolute_get(), BenchmarkPeer::id, PreferenceGenerator::kind, PreferenceGenerator::max_value, BenchmarkPartner::me, BenchmarkPeer::no, BenchmarkPartner::pg, set_pref_task(), PreferenceGenerator::set_task, PreferenceGenerator::src, PreferenceGenerator::time_start, type, and PreferenceGenerator::type.

Referenced by enforce_start_preference().

153 {
154  struct PreferenceGenerator *pg;
155 
156  if (NULL != dest->pg)
157  {
158  GNUNET_break (0);
159  return NULL;
160  }
161 
162  pg = GNUNET_new (struct PreferenceGenerator);
164  pg->type = type;
165  pg->src = src;
166  pg->dest = dest;
167  pg->kind = kind;
168  pg->base_value = base_value;
169  pg->max_value = value_rate;
170  pg->duration_period = period;
171  pg->frequency = frequency;
173 
174  switch (type) {
177  "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
178  dest->me->no, GNUNET_i2s (&dest->me->id),
179  dest->dest->no, GNUNET_i2s (&dest->dest->id),
180  base_value);
181  break;
184  "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
185  dest->me->no, GNUNET_i2s (&dest->me->id),
186  dest->dest->no, GNUNET_i2s (&dest->dest->id),
187  base_value, value_rate);
188  break;
191  "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
192  dest->me->no, GNUNET_i2s (&dest->me->id),
193  dest->dest->no, GNUNET_i2s (&dest->dest->id),
194  base_value, value_rate);
195  break;
198  "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
199  dest->me->no, GNUNET_i2s (&dest->me->id),
200  dest->dest->no, GNUNET_i2s (&dest->dest->id),
201  base_value, value_rate);
202  break;
203  default:
204  break;
205  }
206 
207  dest->pg = pg;
209  return pg;
210 }
struct GNUNET_TIME_Absolute time_start
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_TIME_Relative duration_period
struct PreferenceGenerator * pg
Handle for preference generator.
Definition: ats-testing.h:300
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
enum GNUNET_ATS_PreferenceKind kind
struct BenchmarkPartner * dest
Definition: ats-testing.h:258
int no
Unique identifier.
Definition: ats-testing.h:121
static void set_pref_task(void *cls)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
static struct PreferenceGenerator * pg_head
struct GNUNET_SCHEDULER_Task * set_task
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct BenchmarkPeer * src
Definition: ats-testing.h:257
struct GNUNET_TIME_Relative frequency
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static struct PreferenceGenerator * pg_tail
struct BenchmarkPeer * me
The peer itself this partner belongs to.
Definition: ats-testing.h:280
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct BenchmarkPeer * dest
The partner peer.
Definition: ats-testing.h:285
struct GNUNET_PeerIdentity id
Peer ID.
Definition: ats-testing.h:131
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ATS_TEST_generate_preferences_stop()

void GNUNET_ATS_TEST_generate_preferences_stop ( struct PreferenceGenerator pg)

Definition at line 214 of file ats-testing-preferences.c.

References PreferenceGenerator::dest, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SCHEDULER_cancel(), BenchmarkPartner::pg, and PreferenceGenerator::set_task.

Referenced by enforce_start_preference(), enforce_stop_preference(), and GNUNET_ATS_TEST_generate_preferences_stop_all().

215 {
217  pg->dest->pg = NULL;
218 
219  if (NULL != pg->set_task)
220  {
222  pg->set_task = NULL;
223  }
224 
225  GNUNET_free (pg);
226 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct PreferenceGenerator * pg
Handle for preference generator.
Definition: ats-testing.h:300
struct BenchmarkPartner * dest
Definition: ats-testing.h:258
static struct PreferenceGenerator * pg_head
struct GNUNET_SCHEDULER_Task * set_task
static struct PreferenceGenerator * pg_tail
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ATS_TEST_generate_preferences_stop_all()

void GNUNET_ATS_TEST_generate_preferences_stop_all ( void  )

Stop all preferences generators.

Definition at line 233 of file ats-testing-preferences.c.

References GNUNET_ATS_TEST_generate_preferences_stop(), PreferenceGenerator::next, and pg_head.

Referenced by do_shutdown(), and experiment_done_cb().

234 {
235  struct PreferenceGenerator *cur;
236  struct PreferenceGenerator *next;
237  next = pg_head;
238  for (cur = next; NULL != cur; cur = next)
239  {
240  next = cur->next;
242  }
243 }
struct PreferenceGenerator * next
static struct PreferenceGenerator * pg_head
void GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ pg_head

struct PreferenceGenerator* pg_head
static

◆ pg_tail

struct PreferenceGenerator* pg_tail
static

Definition at line 31 of file ats-testing-preferences.c.

◆ top

Definition at line 53 of file ats-testing.c.

Referenced by exchange().