GNUnet  0.10.x
ats-testing-traffic.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010-2013, 2016 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 
30 static struct TrafficGenerator *tg_head;
31 static struct TrafficGenerator *tg_tail;
32 
33 extern struct GNUNET_ATS_TEST_Topology *top;
34 
35 static struct GNUNET_TIME_Relative
37 {
38  struct GNUNET_TIME_Relative delay;
39  struct GNUNET_TIME_Relative time_delta;
40  long long int cur_rate;
41  long long int delta_rate;
42 
43  delay.rel_value_us = 0;
44 
45  /* Calculate the current transmission rate based on the type of traffic */
46  switch (tg->type)
47  {
49  if (UINT32_MAX == tg->base_rate)
50  return GNUNET_TIME_UNIT_ZERO;
51  cur_rate = tg->base_rate;
52  break;
53 
55  time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
56  /* Calculate point of time in the current period */
57  time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
58  delta_rate = ((double)time_delta.rel_value_us / tg->duration_period.rel_value_us) *
59  (tg->max_rate - tg->base_rate);
60  if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) > tg->base_rate))
61  {
62  /* This will cause an underflow */
63  GNUNET_break(0);
64  }
65  cur_rate = tg->base_rate + delta_rate;
66  break;
67 
69  cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
70  tg->max_rate - tg->base_rate);
71  break;
72 
74  time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
75  /* Calculate point of time in the current period */
76  time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
77  if ((tg->max_rate - tg->base_rate) > tg->base_rate)
78  {
79  /* This will cause an underflow for second half of sinus period,
80  * will be detected in general when experiments are loaded */
81  GNUNET_break(0);
82  }
83  delta_rate = (tg->max_rate - tg->base_rate) *
84  sin((2 * M_PI) / ((double)tg->duration_period.rel_value_us) * time_delta.rel_value_us);
85  cur_rate = tg->base_rate + delta_rate;
86  break;
87 
88  default:
89  return delay;
90  break;
91  }
92 
93  if (cur_rate < 0)
94  {
95  cur_rate = 1;
96  }
97  /* Calculate the delay for the next message based on the current delay */
98  delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate;
99 
101  "Current rate is %lld, calculated delay is %llu\n",
102  cur_rate,
103  (unsigned long long)delay.rel_value_us);
104  return delay;
105 }
106 
107 
108 static void
110 {
111  struct BenchmarkPartner *p = cls;
112  struct GNUNET_TIME_Relative delay;
113 
114  p->messages_sent++;
116  p->me->total_messages_sent++;
118 
119  if (NULL == p->tg)
120  {
121  GNUNET_break(0);
122  return;
123  }
124  delay = get_delay(p->tg);
126  "Delay for next transmission %s\n",
128  GNUNET_YES));
131  delay);
132 }
133 
134 
135 static void
137 {
138  struct BenchmarkPartner *p = cls;
139  struct TestMessage *msg;
140  struct GNUNET_MQ_Envelope *env;
141 
142  p->tg->send_task = NULL;
144  env = GNUNET_MQ_msg(msg,
146  memset(msg->padding,
147  'a',
148  sizeof(msg->padding));
151  p);
153  "Master [%u]: Sending PING to [%u]\n",
154  p->me->no,
155  p->dest->no);
156  GNUNET_MQ_send(p->mq,
157  env);
158 }
159 
160 
161 static void
163 {
164  struct BenchmarkPartner *p = cls;
165 
166  p->messages_sent++;
168  p->me->total_messages_sent++;
170 }
171 
172 
173 void
175 {
176  struct TestMessage *msg;
177  struct GNUNET_MQ_Envelope *env;
178 
180  "Slave [%u]: Received PING from [%u], sending PONG\n",
181  p->me->no,
182  p->dest->no);
183  p->messages_received++;
187 
188 
189  env = GNUNET_MQ_msg(msg,
191  memset(msg->padding,
192  'a',
193  sizeof(msg->padding));
196  p);
197  GNUNET_MQ_send(p->mq,
198  env);
199 }
200 
201 
202 void
204 {
205  struct GNUNET_TIME_Relative left;
206 
208  "Master [%u]: Received PONG from [%u], next message\n",
209  p->me->no,
210  p->dest->no);
211 
212  p->messages_received++;
218 
219  /* Schedule next send event */
220  if (NULL == p->tg)
221  return;
222 
224  if (UINT32_MAX == p->tg->base_rate)
225  {
227  }
228  else if (0 == left.rel_value_us)
229  {
231  }
232  else
233  {
234  /* Enforce minimum transmission rate 1 msg / sec */
237  "Enforcing minimum send rate between master [%u] and slave [%u]\n",
238  p->me->no, p->dest->no);
240  &comm_schedule_send, p);
241  }
242 }
243 
244 
258 struct TrafficGenerator *
260  struct BenchmarkPartner *dest,
261  enum GeneratorType type,
262  unsigned int base_rate,
263  unsigned int max_rate,
264  struct GNUNET_TIME_Relative period,
266 {
267  struct TrafficGenerator *tg;
268 
269  if (NULL != dest->tg)
270  {
271  GNUNET_break(0);
272  return NULL;
273  }
274 
275  tg = GNUNET_new(struct TrafficGenerator);
277  tg_tail,
278  tg);
279  tg->type = type;
280  tg->src = src;
281  tg->dest = dest;
282  tg->base_rate = base_rate;
283  tg->max_rate = max_rate;
284  tg->duration_period = period;
287 
288  switch (type)
289  {
292  "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
293  dest->me->no,
294  GNUNET_i2s(&dest->me->id),
295  dest->dest->no,
296  GNUNET_i2s(&dest->dest->id),
297  base_rate);
298  break;
299 
302  "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
303  dest->me->no,
304  GNUNET_i2s(&dest->me->id),
305  dest->dest->no,
306  GNUNET_i2s(&dest->dest->id),
307  base_rate,
308  max_rate);
309  break;
310 
313  "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
314  dest->me->no,
315  GNUNET_i2s(&dest->me->id),
316  dest->dest->no,
317  GNUNET_i2s(&dest->dest->id),
318  base_rate,
319  max_rate);
320  break;
321 
324  "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
325  dest->me->no,
326  GNUNET_i2s(&dest->me->id),
327  dest->dest->no,
328  GNUNET_i2s(&dest->dest->id),
329  base_rate,
330  max_rate);
331  break;
332 
333  default:
334  break;
335  }
336 
337  dest->tg = tg;
338  tg->send_task
340  dest);
341  return tg;
342 }
343 
344 
345 void
347 {
349  tg_tail,
350  tg);
351  tg->dest->tg = NULL;
352  if (NULL != tg->send_task)
353  {
355  tg->send_task = NULL;
356  }
357  GNUNET_free(tg);
358 }
359 
360 
364 void
366 {
367  struct TrafficGenerator *cur;
368  struct TrafficGenerator *next;
369 
370  next = tg_head;
371  for (cur = next; NULL != cur; cur = next)
372  {
373  next = cur->next;
375  }
376 }
377 
378 /* end of file ats-testing-traffic.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
unsigned int total_bytes_sent
Total number of bytes this peer has sent.
Definition: ats-testing.h:214
unsigned int messages_sent
Number of messages sent to this partner.
Definition: ats-testing.h:309
unsigned int total_bytes_received
Total number of bytes this peer has received.
Definition: ats-testing.h:224
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint64_t rel_value_us
The actual value.
struct TrafficGenerator * next
Definition: ats-testing.h:229
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_ATS_TEST_Topology * top
Definition: ats-testing.c:52
static void update_ping_data(void *cls)
static struct TrafficGenerator * tg_head
static void comm_schedule_send(void *cls)
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
long int max_rate
Definition: ats-testing.h:237
#define GNUNET_TIME_UNIT_SECONDS
One second.
void GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p)
unsigned int total_messages_received
Total number of messages this peer has received.
Definition: ats-testing.h:219
#define TEST_MESSAGE_TYPE_PING
Message type sent for traffic generation.
Definition: ats-testing.h:38
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
unsigned int bytes_received
Number of bytes received from this partner.
Definition: ats-testing.h:324
uint8_t padding[100 - sizeof(struct GNUNET_MessageHeader)]
Definition: ats-testing.h:54
struct GNUNET_SCHEDULER_Task * send_task
Definition: ats-testing.h:240
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:393
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct TrafficGenerator * GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src, struct BenchmarkPartner *dest, enum GeneratorType type, unsigned int base_rate, unsigned int max_rate, struct GNUNET_TIME_Relative period, struct GNUNET_TIME_Relative duration)
Generate between the source master and the partner and send traffic with a maximum rate...
struct BenchmarkPartner * dest
Definition: ats-testing.h:234
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
unsigned int total_messages_sent
Total number of messages this peer has sent.
Definition: ats-testing.h:209
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct TrafficGenerator * tg
Handle for traffic generator.
Definition: ats-testing.h:289
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
void GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p)
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
struct GNUNET_TIME_Absolute time_start
Definition: ats-testing.h:242
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:772
unsigned int total_app_rtt
Accumulated RTT for all messages.
Definition: ats-testing.h:304
static struct TrafficGenerator * tg_tail
Information we track for a peer in the testbed.
Definition: ats-testing.h:109
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
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
Information about a benchmarking partner.
Definition: ats-testing.h:270
unsigned int messages_received
Number of messages received from this partner.
Definition: ats-testing.h:319
ats testing library: setup topology and provide logging to test ats
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
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
enum GeneratorType type
Definition: ats-testing.h:231
struct GNUNET_TIME_Absolute last_message_sent
Timestamp to calculate communication layer delay.
Definition: ats-testing.h:299
struct BenchmarkPeer * src
Definition: ats-testing.h:233
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
unsigned int bytes_sent
Number of bytes sent to this partner.
Definition: ats-testing.h:314
struct GNUNET_MQ_Handle * mq
Message queue handle.
Definition: ats-testing.h:284
long int base_rate
Definition: ats-testing.h:236
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,...)
void GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg)
static struct GNUNET_TIME_Relative duration
How long do we run the test?
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_TIME_Relative duration_period
Definition: ats-testing.h:238
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void GNUNET_ATS_TEST_generate_traffic_stop_all()
Stop all traffic generators.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:353
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
static struct GNUNET_TIME_Relative get_delay(struct TrafficGenerator *tg)
static void update_pong_data(void *cls)
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
struct GNUNET_TIME_Absolute next_ping_transmission
Definition: ats-testing.h:241
#define TEST_MESSAGE_SIZE
Size of test messages.
Definition: ats-testing.h:48
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