GNUnet  0.10.x
ats-testing-preferences.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010-2013 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  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "ats-testing.h"
29 
32 
33 extern struct GNUNET_ATS_TEST_Topology *top;
34 
35 static double
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)
44  {
46  pref_value = pg->base_value;
47  break;
48 
51  /* Calculate point of time in the current period */
52  time_delta.rel_value_us = time_delta.rel_value_us %
54  delta_value = ((double)time_delta.rel_value_us /
56  if ((pg->max_value < pg->base_value) &&
57  ((pg->max_value - pg->base_value) > pg->base_value))
58  {
59  /* This will cause an underflow */
60  GNUNET_break(0);
61  }
62  pref_value = pg->base_value + delta_value;
63  break;
64 
67  10000 * (pg->max_value - pg->base_value)) / 10000;
68  pref_value = pg->base_value + delta_value;
69  break;
70 
73  /* Calculate point of time in the current period */
74  time_delta.rel_value_us = time_delta.rel_value_us %
76  if ((pg->max_value - pg->base_value) > pg->base_value)
77  {
78  /* This will cause an underflow for second half of sinus period,
79  * will be detected in general when experiments are loaded */
80  GNUNET_break(0);
81  }
82  delta_value = (pg->max_value - pg->base_value) *
83  sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) *
84  time_delta.rel_value_us);
85  pref_value = pg->base_value + delta_value;
86  break;
87 
88  default:
89  pref_value = 0.0;
90  break;
91  }
92  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
93  pref_value);
94  return pref_value;
95 }
96 
97 
98 static void
99 set_pref_task(void *cls)
100 {
101  struct BenchmarkPartner *p = cls;
102  double pref_value;
103 
104  p->pg->set_task = NULL;
105 
106  pref_value = get_preference(p->pg);
107 
109  "Setting preference for master [%u] and slave [%u] for %s to %f\n",
110  p->me->no, p->dest->no,
111  GNUNET_ATS_print_preference_type(p->pg->kind), pref_value);
112 
114  &p->dest->id,
115  p->pg->kind,
116  pref_value,
118 
119  switch (p->pg->kind)
120  {
122  p->pref_bandwidth = pref_value;
123  break;
124 
126  p->pref_delay = pref_value;
127  break;
128 
129  default:
130  break;
131  }
132 
134  set_pref_task, p);
135 }
136 
137 
152 struct PreferenceGenerator *
154  struct BenchmarkPartner *dest,
155  enum GeneratorType type,
156  unsigned int base_value,
157  unsigned int value_rate,
158  struct GNUNET_TIME_Relative period,
161 {
162  struct PreferenceGenerator *pg;
163 
164  if (NULL != dest->pg)
165  {
166  GNUNET_break(0);
167  return NULL;
168  }
169 
170  pg = GNUNET_new(struct PreferenceGenerator);
171  GNUNET_CONTAINER_DLL_insert(pg_head, pg_tail, pg);
172  pg->type = type;
173  pg->src = src;
174  pg->dest = dest;
175  pg->kind = kind;
176  pg->base_value = base_value;
177  pg->max_value = value_rate;
178  pg->duration_period = period;
179  pg->frequency = frequency;
181 
182  switch (type)
183  {
186  "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
187  dest->me->no, GNUNET_i2s(&dest->me->id),
188  dest->dest->no, GNUNET_i2s(&dest->dest->id),
189  base_value);
190  break;
191 
194  "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
195  dest->me->no, GNUNET_i2s(&dest->me->id),
196  dest->dest->no, GNUNET_i2s(&dest->dest->id),
197  base_value, value_rate);
198  break;
199 
202  "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
203  dest->me->no, GNUNET_i2s(&dest->me->id),
204  dest->dest->no, GNUNET_i2s(&dest->dest->id),
205  base_value, value_rate);
206  break;
207 
210  "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
211  dest->me->no, GNUNET_i2s(&dest->me->id),
212  dest->dest->no, GNUNET_i2s(&dest->dest->id),
213  base_value, value_rate);
214  break;
215 
216  default:
217  break;
218  }
219 
220  dest->pg = pg;
222  return pg;
223 }
224 
225 
226 void
228 {
229  GNUNET_CONTAINER_DLL_remove(pg_head, pg_tail, pg);
230  pg->dest->pg = NULL;
231 
232  if (NULL != pg->set_task)
233  {
235  pg->set_task = NULL;
236  }
237 
238  GNUNET_free(pg);
239 }
240 
241 
245 void
247 {
248  struct PreferenceGenerator *cur;
249  struct PreferenceGenerator *next;
250 
251  next = pg_head;
252  for (cur = next; NULL != cur; cur = next)
253  {
254  next = cur->next;
256  }
257 }
258 
259 /* end of file ats-testing-preferences.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct PreferenceGenerator * next
struct GNUNET_TIME_Absolute time_start
uint64_t rel_value_us
The actual value.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_TIME_Relative duration_period
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
double pref_bandwidth
Current preference values for bandwidth.
Definition: ats-testing.h:344
struct PreferenceGenerator * pg
Handle for preference generator.
Definition: ats-testing.h:294
struct GNUNET_ATS_TEST_Topology * top
Definition: ats-testing.c:52
#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...
End of preference list.
enum GNUNET_ATS_PreferenceKind kind
struct BenchmarkPartner * dest
Definition: ats-testing.h:253
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:1237
int no
Unique identifier.
Definition: ats-testing.h:118
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
Information we track for a peer in the testbed.
Definition: ats-testing.h:109
double pref_delay
Current preference values for delay.
Definition: ats-testing.h:349
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:1264
Information about a benchmarking partner.
Definition: ats-testing.h:270
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 ...
struct GNUNET_ATS_PerformanceHandle * ats_perf_handle
ATS performance handle.
Definition: ats-testing.h:148
static struct PreferenceGenerator * pg_head
ats testing library: setup topology and provide logging to test ats
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
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
void GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg)
struct BenchmarkPeer * src
Definition: ats-testing.h:252
Change the peer&#39;s latency value to the given amount.
static double get_preference(struct PreferenceGenerator *pg)
void GNUNET_ATS_TEST_generate_preferences_stop_all()
Stop all preferences generators.
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
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...
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static struct PreferenceGenerator * pg_tail
GNUNET_ATS_PreferenceKind
Enum defining all known preference categories.
struct BenchmarkPeer * me
The peer itself this partner belongs to.
Definition: ats-testing.h:274
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:279
struct GNUNET_PeerIdentity id
Peer ID.
Definition: ats-testing.h:128
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956